Skip to content

Commit

Permalink
Add discovery/store panel
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Dec 3, 2024
1 parent f555bc7 commit 80d3292
Show file tree
Hide file tree
Showing 9 changed files with 996 additions and 18 deletions.
Binary file modified Resources/Fonts/IconFont.ttf
Binary file not shown.
48 changes: 37 additions & 11 deletions Source/Components/WelcomePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class WelcomePanel : public Component
}
};

class NewOpenTile : public Component
class MainActionTile : public Component
{
NVGImage shadowImage;
bool isHovered = false;
Expand All @@ -91,11 +91,12 @@ class WelcomePanel : public Component
enum TileType
{
New,
Open
Open,
Store
};
TileType type;

NewOpenTile(TileType type) : type(type)
MainActionTile(TileType type) : type(type)
{
}

Expand Down Expand Up @@ -175,6 +176,22 @@ class WelcomePanel : public Component
nvgText(nvg, 92, 63, "Browse for a patch to open", NULL);
break;
}
case Store: {
nvgFontFace(nvg, "icon_font-Regular");
nvgFillColor(nvg, bgCol);
nvgFontSize(nvg, 30);
nvgTextAlign(nvg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
nvgText(nvg, circleBounds.getCentreX(), circleBounds.getCentreY() - 4, Icons::Sparkle.toRawUTF8(), nullptr);

nvgFontFace(nvg, "Inter-Bold");
nvgFontSize(nvg, 12);
nvgTextAlign(nvg, NVG_ALIGN_CENTER | NVG_ALIGN_LEFT);
nvgFillColor(nvg, NVGComponent::convertColour(findColour(PlugDataColour::panelTextColourId)));
nvgText(nvg, 92, 45, "Discover...", NULL);

nvgFontFace(nvg, "Inter-Regular");
nvgText(nvg, 92, 63, "Browse online patch store", NULL);
}
default:
break;
}
Expand Down Expand Up @@ -561,12 +578,14 @@ class WelcomePanel : public Component

setCachedComponentImage(new NVGSurface::InvalidationListener(editor->nvgSurface, this));

newPatchTile = std::make_unique<NewOpenTile>(NewOpenTile::New);
openPatchTile = std::make_unique<NewOpenTile>(NewOpenTile::Open);
newPatchTile = std::make_unique<MainActionTile>(MainActionTile::New);
openPatchTile = std::make_unique<MainActionTile>(MainActionTile::Open);
storeTile = std::make_unique<MainActionTile>(MainActionTile::Store);

newPatchTile->onClick = [this]() { editor->getTabComponent().newPatch(); };
openPatchTile->onClick = [this]() { editor->getTabComponent().openPatch(); };

storeTile->onClick = [this]() { Dialogs::showStore(editor); };

triggerAsyncUpdate();
}

Expand All @@ -590,6 +609,7 @@ class WelcomePanel : public Component
searchQuery = newSearchQuery;
if(newPatchTile) newPatchTile->setVisible(searchQuery.isEmpty());
if(openPatchTile) openPatchTile->setVisible(searchQuery.isEmpty());
if(storeTile) storeTile->setVisible(searchQuery.isEmpty());

auto& tiles = currentTab == Home ? recentlyOpenedTiles : libraryTiles;
for (auto* tile : tiles) {
Expand All @@ -612,8 +632,7 @@ class WelcomePanel : public Component
// Adjust the tile width to fit within the available width
int actualTileWidth = (totalWidth - (numColumns - 1) * tileSpacing) / numColumns;

auto showNewOpenTiles = newPatchTile && openPatchTile && currentTab == Home && searchQuery.isEmpty();
if (showNewOpenTiles) {
if (searchQuery.isEmpty()) {
rowBounds = bounds.removeFromTop(100);
// Position buttons centre if there are no recent items
if (recentlyOpenedTiles.size() == 0) {
Expand All @@ -628,7 +647,9 @@ class WelcomePanel : public Component
newPatchTile->setBounds(rowBounds.withX(startX).withWidth(buttonWidth).withY(buttonY));
openPatchTile->setBounds(rowBounds.withX(startX + buttonWidth + tileSpacing).withWidth(buttonWidth).withY(buttonY));
} else {
newPatchTile->setBounds(rowBounds.removeFromLeft(actualTileWidth * 1.5f));
auto firstTileBounds = rowBounds.removeFromLeft(actualTileWidth * 1.5f);
newPatchTile->setBounds(firstTileBounds);
storeTile->setBounds(firstTileBounds);
rowBounds.removeFromLeft(4);
openPatchTile->setBounds(rowBounds.withWidth(actualTileWidth * 1.5f + 4));
}
Expand All @@ -641,7 +662,7 @@ class WelcomePanel : public Component
int numRows = (tiles.size() + numColumns - 1) / numColumns;
int totalHeight = (numRows * 160) + 200;

auto tilesBounds = Rectangle<int>(24, showNewOpenTiles ? 146 : 24, totalWidth + 24, totalHeight + 24);
auto tilesBounds = Rectangle<int>(24, searchQuery.isEmpty() ? 146 : 24, totalWidth + 24, totalHeight + 24);

contentComponent.setBounds(tiles.size() ? tilesBounds : getLocalBounds());

Expand Down Expand Up @@ -680,6 +701,7 @@ class WelcomePanel : public Component
{
newPatchTile->setVisible(true);
openPatchTile->setVisible(true);
storeTile->setVisible(false);
for(auto* tile : recentlyOpenedTiles)
{
tile->setVisible(true);
Expand All @@ -692,6 +714,7 @@ class WelcomePanel : public Component
else {
newPatchTile->setVisible(false);
openPatchTile->setVisible(false);
storeTile->setVisible(true);
for(auto* tile : recentlyOpenedTiles)
{
tile->setVisible(false);
Expand All @@ -718,6 +741,9 @@ class WelcomePanel : public Component
contentComponent.addAndMakeVisible(*newPatchTile);
contentComponent.addAndMakeVisible(*openPatchTile);
}
else {
contentComponent.addAndMakeVisible(*storeTile);
}

if (recentlyOpenedTree.isValid()) {
// Place favourited patches at the top
Expand Down Expand Up @@ -903,7 +929,7 @@ class WelcomePanel : public Component
"<rect x=\"30\" y=\"30\" width=\"804\" height=\"804\" rx=\"172\" stroke=\"black\" stroke-width=\"8\"/>\n"
"</svg>\n";

std::unique_ptr<NewOpenTile> newPatchTile, openPatchTile;
std::unique_ptr<MainActionTile> newPatchTile, openPatchTile, storeTile;
ContentComponent contentComponent = ContentComponent(*this);
BouncingViewport viewport;

Expand Down
5 changes: 3 additions & 2 deletions Source/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ struct Icons {
inline static String const Duplicate = "2";
inline static String const Cut = "3";

inline static String const Store = CharPointer_UTF8 ("\xc3\x8f");
inline static String const PanelExpand = CharPointer_UTF8("\xc3\x8d");
inline static String const PanelContract = CharPointer_UTF8("\xc3\x8c");
inline static String const ItemGrid = " ";

inline static String const AlignLeft = "4";
inline static String const AlignRight = "5";
inline static String const AlignHCentre = "6";
Expand Down Expand Up @@ -441,4 +442,4 @@ namespace PlatformStrings {
return "Reveal in file browser";
#endif
}
}
}
14 changes: 14 additions & 0 deletions Source/Dialogs/Dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "Connection.h"
#include "Deken.h"
#include "Standalone/PlugDataWindow.h"
#include "PatchStore.h"

Dialog::Dialog(std::unique_ptr<Dialog>* ownerPtr, Component* editor, int childWidth, int childHeight, bool showCloseButton, int margin)
: height(childHeight)
Expand Down Expand Up @@ -217,6 +218,10 @@ void Dialogs::showMainMenu(PluginEditor* editor, Component* centre)
Dialogs::showDeken(editor);
break;
}
case MainMenu::MenuItem::Discover: {
Dialogs::showStore(editor);
break;
}
case MainMenu::MenuItem::Settings: {
Dialogs::showSettingsDialog(editor);
break;
Expand Down Expand Up @@ -363,6 +368,15 @@ void Dialogs::showDeken(PluginEditor* editor)
editor->openedDialog.reset(dialog);
}

void Dialogs::showStore(PluginEditor* editor)
{
auto* dialog = new Dialog(&editor->openedDialog, editor, 850, 550, true);
auto* dialogContent = new PatchStore();
dialog->setViewedComponent(dialogContent);
editor->openedDialog.reset(dialog);
}


StringArray DekenInterface::getExternalPaths()
{
StringArray searchPaths;
Expand Down
1 change: 1 addition & 0 deletions Source/Dialogs/Dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ struct Dialogs {
static void showObjectMenu(PluginEditor* parent, Component* target);

static void showDeken(PluginEditor* editor);
static void showStore(PluginEditor* editor);

static void dismissFileDialog();

Expand Down
6 changes: 4 additions & 2 deletions Source/Dialogs/MainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class MainMenu : public PopupMenu {

addCustomItem(getMenuItemID(MenuItem::FindExternals), std::unique_ptr<IconMenuItem>(menuItems[getMenuItemIndex(MenuItem::FindExternals)]), nullptr, "Find externals...");

// addCustomItem(getMenuItemID(MenuItem::Discover), std::unique_ptr<IconMenuItem>(menuItems[getMenuItemIndex(MenuItem::Discover)]), nullptr, "Discover...");
addCustomItem(getMenuItemID(MenuItem::Discover), std::unique_ptr<IconMenuItem>(menuItems[getMenuItemIndex(MenuItem::Discover)]), nullptr, "Discover...");

addCustomItem(getMenuItemID(MenuItem::Settings), std::unique_ptr<IconMenuItem>(menuItems[getMenuItemIndex(MenuItem::Settings)]), nullptr, "Settings...");
addCustomItem(getMenuItemID(MenuItem::About), std::unique_ptr<IconMenuItem>(menuItems[getMenuItemIndex(MenuItem::About)]), nullptr, "About...");
Expand Down Expand Up @@ -280,6 +280,7 @@ class MainMenu : public PopupMenu {
CompiledMode,
Compile,
FindExternals,
Discover,
Settings,
About
};
Expand All @@ -297,7 +298,7 @@ class MainMenu : public PopupMenu {
return item - 1;
}

StackArray<IconMenuItem*, 11> menuItems = {
StackArray<IconMenuItem*, 12> menuItems = {
new IconMenuItem(Icons::New, "New patch", false, false),
new IconMenuItem(Icons::Open, "Open patch...", false, false),
new IconMenuItem(Icons::History, "Recently opened", true, false),
Expand All @@ -311,6 +312,7 @@ class MainMenu : public PopupMenu {
new IconMenuItem(Icons::DevTools, "Compile...", false, false),

new IconMenuItem(Icons::Externals, "Find externals...", false, false),
new IconMenuItem(Icons::Sparkle, "Discover...", false, false),
new IconMenuItem(Icons::Settings, "Settings...", false, false),
new IconMenuItem(Icons::Info, "About...", false, false),
};
Expand Down
Loading

0 comments on commit 80d3292

Please sign in to comment.