Skip to content

Commit

Permalink
Display an icon in Patch browser for Favorites (#5866)
Browse files Browse the repository at this point in the history
If a patch is favorited, when you menu dive it gets
a little heart to remind you that you liked it.
Awwwwww.

Closes #5820
  • Loading branch information
baconpaul authored Feb 7, 2022
1 parent 0ee3b2b commit e28f367
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
12 changes: 12 additions & 0 deletions resources/classic-skin-svgs/bmp00188.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/common/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#define IDB_MODMENU_ICONS 185
#define IDB_FAVORITE_BUTTON 186
#define IDB_SEARCH_BUTTON 187
#define IDB_FAVORITE_MENU_ICON 188

// == SVG == Do not remove this comment - it indicates the start of the automated SVG adding block
#define IDB_MSEG_NODES 301
Expand Down
1 change: 1 addition & 0 deletions src/surge-xt/gui/SurgeImageStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void SurgeImageStore::setupBuiltinBitmaps()
addEntry(IDB_MODMENU_ICONS);
addEntry(IDB_FAVORITE_BUTTON);
addEntry(IDB_SEARCH_BUTTON);
addEntry(IDB_FAVORITE_MENU_ICON);

// == SVG == Do not remove this comment - it indicates the start of the automated SVG adding
// block
Expand Down
9 changes: 7 additions & 2 deletions src/surge-xt/gui/SurgeJUCELookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ Button *SurgeJUCELookAndFeel::createDocumentWindowButton(int buttonType)
return nullptr;
}

juce::Font SurgeJUCELookAndFeel::getPopupMenuFont()
{
// return Surge::GUI::getFontManager()->getLatoAtSize(15);
return juce::LookAndFeel_V4::getPopupMenuFont();
}
// overridden here just to make the shortcut text same size as normal menu entry text
void SurgeJUCELookAndFeel::drawPopupMenuItem(Graphics &g, const Rectangle<int> &area,
const bool isSeparator, const bool isActive,
Expand Down Expand Up @@ -342,10 +347,10 @@ void SurgeJUCELookAndFeel::drawPopupMenuItem(Graphics &g, const Rectangle<int> &

if (icon != nullptr)
{
icon->drawWithin(g, iconArea,
icon->drawWithin(g, iconArea.translated(-2, 0),
RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
1.0f);
r.removeFromLeft(roundToInt(maxFontHeight * 0.5f));
// r.removeFromLeft(roundToInt(maxFontHeight * 0.5f));
}
else if (isTicked)
{
Expand Down
1 change: 1 addition & 0 deletions src/surge-xt/gui/SurgeJUCELookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SurgeJUCELookAndFeel : public juce::LookAndFeel_V4, public Surge::GUI::Ski

void onSkinChanged() override;

juce::Font getPopupMenuFont() override;
void drawPopupMenuBackgroundWithOptions(juce::Graphics &g, int w, int h,
const juce::PopupMenu::Options &o) override;
void drawPopupMenuItem(juce::Graphics &g, const juce::Rectangle<int> &area,
Expand Down
12 changes: 11 additions & 1 deletion src/surge-xt/gui/widgets/PatchSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,17 @@ bool PatchSelector::populatePatchMenuForCategory(int c, juce::PopupMenu &context
amIChecked = true;
}

subMenu->addItem(name, true, thisCheck, [this, p]() { this->loadPatch(p); });
bool isFav = storage->patch_list[p].isFavorite;
auto item = juce::PopupMenu::Item(name).setEnabled(true).setTicked(thisCheck).setAction(
[this, p]() { this->loadPatch(p); });

if (isFav && associatedBitmapStore)
{
auto img = associatedBitmapStore->getImage(IDB_FAVORITE_MENU_ICON);
if (img && img->getDrawableButUseWithCaution())
item.setImage(img->getDrawableButUseWithCaution()->createCopy());
}
subMenu->addItem(item);
sub++;

if (sub != 0 && sub % 32 == 0)
Expand Down

0 comments on commit e28f367

Please sign in to comment.