From e2ce3e4c68a5dd0d3436d6a9e17634ebfff5cf9c Mon Sep 17 00:00:00 2001 From: Rolando Islas Date: Fri, 27 May 2016 15:43:01 -0700 Subject: [PATCH] Change default icon color in Windows and allow toggling --- Source/IconMenu.cpp | 46 ++++++++++++++++++++++++++++++++++++--------- Source/IconMenu.hpp | 1 + 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Source/IconMenu.cpp b/Source/IconMenu.cpp index 1041b2d..ac66b44 100644 --- a/Source/IconMenu.cpp +++ b/Source/IconMenu.cpp @@ -83,15 +83,7 @@ IconMenu::IconMenu() : INDEX_EDIT(1000000), INDEX_BYPASS(2000000), INDEX_DELETE( activePluginList.recreateFromXml(*savedPluginListActive); loadActivePlugins(); activePluginList.addChangeListener(this); - // Set menu icon - #if JUCE_MAC - if (exec("defaults read -g AppleInterfaceStyle").compare("Dark") == 1) - setIconImage(ImageFileFormat::loadFrom(BinaryData::menu_icon_white_png, BinaryData::menu_icon_white_pngSize)); - else - setIconImage(ImageFileFormat::loadFrom(BinaryData::menu_icon_png, BinaryData::menu_icon_pngSize)); - #else - setIconImage(ImageFileFormat::loadFrom(BinaryData::menu_icon_png, BinaryData::menu_icon_pngSize)); - #endif + setIcon(); setIconTooltip(JUCEApplication::getInstance()->getApplicationName()); }; @@ -100,6 +92,33 @@ IconMenu::~IconMenu() savePluginStates(); } +void IconMenu::setIcon() +{ + // Set menu icon + #if JUCE_MAC + if (exec("defaults read -g AppleInterfaceStyle").compare("Dark") == 1) + setIconImage(ImageFileFormat::loadFrom(BinaryData::menu_icon_white_png, BinaryData::menu_icon_white_pngSize)); + else + setIconImage(ImageFileFormat::loadFrom(BinaryData::menu_icon_png, BinaryData::menu_icon_pngSize)); + #else + String defaultColor; + #if JUCE_WINDOWS + defaultColor = "white"; + #elif JUCE_LINUX + defaultColor = "black"; + #endif + if (!getAppProperties().getUserSettings()->containsKey("icon")) + getAppProperties().getUserSettings()->setValue("icon", defaultColor); + String color = getAppProperties().getUserSettings()->getValue("icon"); + Image icon; + if (color.equalsIgnoreCase("white")) + icon = ImageFileFormat::loadFrom(BinaryData::menu_icon_white_png, BinaryData::menu_icon_white_pngSize); + else if (color.equalsIgnoreCase("black")) + icon = ImageFileFormat::loadFrom(BinaryData::menu_icon_png, BinaryData::menu_icon_pngSize); + setIconImage(icon); + #endif +} + void IconMenu::loadActivePlugins() { const int INPUT = 1000000; @@ -253,6 +272,9 @@ void IconMenu::timerCallback() menu.addItem(1, "Quit"); menu.addSeparator(); menu.addItem(2, "Delete Plugin States"); + #if !JUCE_MAC + menu.addItem(3, "Invert Icon Color"); + #endif } #if JUCE_MAC || JUCE_LINUX menu.showMenuAsync(PopupMenu::Options().withTargetComponent(this), ModalCallbackFunction::forComponent(menuInvocationCallback, this)); @@ -296,6 +318,12 @@ void IconMenu::menuInvocationCallback(int id, IconMenu* im) im->deletePluginStates(); return im->loadActivePlugins(); } + if (id == 3) + { + String color = getAppProperties().getUserSettings()->getValue("icon"); + getAppProperties().getUserSettings()->setValue("icon", color.equalsIgnoreCase("black") ? "white" : "black"); + return im->setIcon(); + } } #if JUCE_MAC // Click elsewhere diff --git a/Source/IconMenu.hpp b/Source/IconMenu.hpp index 98ea96c..f16c0ed 100644 --- a/Source/IconMenu.hpp +++ b/Source/IconMenu.hpp @@ -35,6 +35,7 @@ class IconMenu : public SystemTrayIconComponent, private Timer, public ChangeLis PluginDescription getNextPluginOlderThanTime(int &time); void removePluginsLackingInputOutput(); std::vector getTimeSortedList(); + void setIcon(); AudioDeviceManager deviceManager; AudioPluginFormatManager formatManager;