SettingsButton.cpp (3895B)
1 #include "SettingsButton.h" 2 3 namespace 4 { 5 const Colour onColour = Colour (0xFFEAA92C); 6 const Colour offColour = Colours::white; 7 } // namespace 8 9 SettingsButton::SettingsButton (const ChowtapeModelAudioProcessor& processor, chowdsp::OpenGLHelper* oglHelper) : DrawableButton ("Settings", DrawableButton::ImageFitted), 10 proc (processor), 11 openGLHelper (oglHelper) 12 { 13 Logger::writeToLog ("Checking OpenGL availability..."); 14 const auto shouldUseOpenGLByDefault = openGLHelper != nullptr && openGLHelper->isOpenGLAvailable(); 15 #if CHOWDSP_OPENGL_IS_AVAILABLE 16 Logger::writeToLog ("OpenGL is available on this system: " + String (shouldUseOpenGLByDefault ? "TRUE" : "FALSE")); 17 #else 18 Logger::writeToLog ("Plugin was built without linking to OpenGL!"); 19 #endif 20 pluginSettings->addProperties<&SettingsButton::globalSettingChanged> ({ { openglID, shouldUseOpenGLByDefault } }, *this); 21 globalSettingChanged (openglID); 22 23 auto cog = Drawable::createFromImageData (BinaryData::cogsolid_svg, BinaryData::cogsolid_svgSize); 24 setImages (cog.get()); 25 26 onClick = [this] 27 { showSettingsMenu(); }; 28 } 29 30 void SettingsButton::globalSettingChanged (SettingID settingID) 31 { 32 if (settingID != openglID) 33 return; 34 35 if (openGLHelper != nullptr && openGLHelper->isOpenGLAvailable()) 36 { 37 const auto shouldUseOpenGL = pluginSettings->getProperty<bool> (openglID); 38 if (shouldUseOpenGL == openGLHelper->isAttached()) 39 return; // no change 40 41 Logger::writeToLog ("Using OpenGL: " + String (shouldUseOpenGL ? "TRUE" : "FALSE")); 42 shouldUseOpenGL ? openGLHelper->attach() : openGLHelper->detach(); 43 } 44 } 45 46 void SettingsButton::showSettingsMenu() 47 { 48 PopupMenu menu; 49 50 openGLMenu (menu, 100); 51 52 menu.addSeparator(); 53 menu.addItem ("View Source Code", [] 54 { URL ("https://github.com/jatinchowdhury18/AnalogTapeModel").launchInDefaultBrowser(); }); 55 menu.addItem ("Copy Diagnostic Info", [this] 56 { copyDiagnosticInfo(); }); 57 menu.addItem ("View User Manual", [] 58 { URL ("https://chowdsp.com/manuals/ChowTapeManual.pdf").launchInDefaultBrowser(); }); 59 60 // get top level component that is big enough 61 Component* parentComp = this; 62 int iters = 0; 63 while (true) 64 { 65 if (parentComp->getWidth() > 80 && parentComp->getHeight() > 100) 66 break; 67 68 parentComp = parentComp->getParentComponent(); 69 70 if (iters > 5 || parentComp == nullptr) 71 { 72 jassertfalse; // unable to find component large enough! 73 return; 74 } 75 } 76 77 auto options = PopupMenu::Options() 78 .withParentComponent (parentComp) 79 .withPreferredPopupDirection (PopupMenu::Options::PopupDirection::upwards) 80 .withStandardItemHeight (27); 81 menu.setLookAndFeel (lnfAllocator->getLookAndFeel<ComboBoxLNF>()); 82 menu.showMenuAsync (options); 83 } 84 85 void SettingsButton::openGLMenu (PopupMenu& menu, int itemID) 86 { 87 if (openGLHelper == nullptr || ! openGLHelper->isOpenGLAvailable()) 88 return; 89 90 const auto isCurrentlyOn = pluginSettings->getProperty<bool> (openglID); 91 92 PopupMenu::Item item; 93 item.itemID = ++itemID; 94 item.text = "Use OpenGL"; 95 item.action = [this, isCurrentlyOn] 96 { pluginSettings->setProperty (openglID, ! isCurrentlyOn); }; 97 item.colour = isCurrentlyOn ? onColour : offColour; 98 99 menu.addItem (item); 100 } 101 102 void SettingsButton::copyDiagnosticInfo() 103 { 104 Logger::writeToLog ("Copying diagnostic info..."); 105 SystemClipboard::copyTextToClipboard (chowdsp::PluginDiagnosticInfo::getDiagnosticsString (proc)); 106 }