The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

319 lines
12KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. class GlobalPathsWindowComponent : public Component,
  22. private Timer
  23. {
  24. public:
  25. GlobalPathsWindowComponent()
  26. {
  27. addLabelsAndSetProperties();
  28. addAndMakeVisible (info);
  29. info.setInfoToDisplay ("Use this dropdown to set the global paths for different OSes. "
  30. "\nN.B. These paths are stored locally and will only be used when "
  31. "saving a project on this machine. Other machines will have their own "
  32. "locally stored paths.");
  33. addAndMakeVisible (osSelector);
  34. osSelector.addItem ("OSX", 1);
  35. osSelector.addItem ("Windows", 2);
  36. osSelector.addItem ("Linux", 3);
  37. osSelector.onChange = [this]
  38. {
  39. addLabelsAndSetProperties();
  40. updateValues();
  41. updateFilePathPropertyComponents();
  42. };
  43. auto os = TargetOS::getThisOS();
  44. if (os == TargetOS::osx) osSelector.setSelectedId (1);
  45. else if (os == TargetOS::windows) osSelector.setSelectedId (2);
  46. else if (os == TargetOS::linux) osSelector.setSelectedId (3);
  47. addChildComponent (rescanJUCEPathButton);
  48. rescanJUCEPathButton.onClick = [] { ProjucerApplication::getApp().rescanJUCEPathModules(); };
  49. addChildComponent (rescanUserPathButton);
  50. rescanUserPathButton.onClick = [] { ProjucerApplication::getApp().rescanUserPathModules(); };
  51. addAndMakeVisible (resetToDefaultsButton);
  52. resetToDefaultsButton.onClick = [this] { resetCurrentOSPathsToDefaults(); };
  53. updateValues();
  54. updateFilePathPropertyComponents();
  55. }
  56. void paint (Graphics& g) override
  57. {
  58. g.fillAll (findColour (backgroundColourId));
  59. }
  60. void paintOverChildren (Graphics& g) override
  61. {
  62. g.setColour (findColour (defaultHighlightColourId).withAlpha (flashAlpha));
  63. g.fillRect (boundsToHighlight);
  64. }
  65. void resized() override
  66. {
  67. auto b = getLocalBounds().reduced (10);
  68. auto topSlice = b.removeFromTop (25);
  69. osSelector.setSize (200, 25);
  70. osSelector.setCentrePosition (topSlice.getCentre());
  71. info.setBounds (osSelector.getBounds().withWidth (osSelector.getHeight()).translated ((osSelector.getWidth() + 5), 0).reduced (2));
  72. int labelIndex = 0;
  73. bool isFirst = true;
  74. bool showRescanButtons = (rescanJUCEPathButton.isVisible() && rescanUserPathButton.isVisible());
  75. for (auto* pathComp : pathPropertyComponents)
  76. {
  77. if (pathComp == nullptr)
  78. {
  79. b.removeFromTop (15);
  80. pathPropertyLabels.getUnchecked (labelIndex++)->setBounds (b.removeFromTop (20));
  81. b.removeFromTop (20);
  82. }
  83. else
  84. {
  85. if (isFirst)
  86. b.removeFromTop (20);
  87. auto compBounds = b.removeFromTop (pathComp->getPreferredHeight());
  88. if (showRescanButtons)
  89. {
  90. auto propName = pathComp->getName();
  91. if (propName == "JUCE Modules")
  92. rescanJUCEPathButton.setBounds (compBounds.removeFromRight (75).reduced (5, 0));
  93. else if (propName == "User Modules")
  94. rescanUserPathButton.setBounds (compBounds.removeFromRight (75).reduced (5, 0));
  95. }
  96. pathComp->setBounds (compBounds);
  97. b.removeFromTop (5);
  98. }
  99. isFirst = false;
  100. }
  101. resetToDefaultsButton.setBounds (b.removeFromBottom (35).reduced (150, 0));
  102. }
  103. void highlightJUCEPath()
  104. {
  105. if (! isTimerRunning() && isSelectedOSThisOS())
  106. {
  107. if (auto* jucePathComp = pathPropertyComponents.getFirst())
  108. boundsToHighlight = jucePathComp->getBounds();
  109. flashAlpha = 0.0f;
  110. hasFlashed = false;
  111. startTimer (25);
  112. }
  113. }
  114. private:
  115. ValueWithDefault jucePathValue, juceModulePathValue, userModulePathValue, vst3PathValue, rtasPathValue, aaxPathValue,
  116. androidSDKPathValue, androidNDKPathValue, clionExePathValue, androidStudioExePathValue;
  117. OwnedArray<Label> pathPropertyLabels;
  118. OwnedArray<PropertyComponent> pathPropertyComponents;
  119. TextButton rescanJUCEPathButton { "Re-scan" },
  120. rescanUserPathButton { "Re-scan" },
  121. resetToDefaultsButton { "Reset to Defaults" };
  122. ComboBox osSelector;
  123. InfoButton info;
  124. Rectangle<int> boundsToHighlight;
  125. float flashAlpha = 0.0f;
  126. bool hasFlashed = false;
  127. //==============================================================================
  128. void timerCallback() override
  129. {
  130. flashAlpha += (hasFlashed ? -0.05f : 0.05f);
  131. if (flashAlpha > 0.75f)
  132. {
  133. hasFlashed = true;
  134. }
  135. else if (flashAlpha < 0.0f)
  136. {
  137. flashAlpha = 0.0f;
  138. boundsToHighlight = {};
  139. stopTimer();
  140. }
  141. repaint();
  142. }
  143. //==============================================================================
  144. bool isSelectedOSThisOS() { return TargetOS::getThisOS() == getSelectedOS(); }
  145. TargetOS::OS getSelectedOS() const
  146. {
  147. auto selectedOS = TargetOS::unknown;
  148. switch (osSelector.getSelectedId())
  149. {
  150. case 1: selectedOS = TargetOS::osx; break;
  151. case 2: selectedOS = TargetOS::windows; break;
  152. case 3: selectedOS = TargetOS::linux; break;
  153. default: break;
  154. }
  155. return selectedOS;
  156. }
  157. void updateFilePathPropertyComponents()
  158. {
  159. pathPropertyComponents.clear();
  160. auto isThisOS = isSelectedOSThisOS();
  161. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (jucePathValue, "Path to JUCE", true, isThisOS)));
  162. pathPropertyComponents.add (nullptr);
  163. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (juceModulePathValue, "JUCE Modules", true, isThisOS)));
  164. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (userModulePathValue, "User Modules", true, isThisOS, {}, {}, true)));
  165. pathPropertyComponents.add (nullptr);
  166. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (vst3PathValue, "Custom VST3 SDK", true, isThisOS)));
  167. if (getSelectedOS() == TargetOS::linux)
  168. {
  169. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (Value(), "AAX SDK", true, isThisOS)));
  170. pathPropertyComponents.getLast()->setEnabled (false);
  171. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (Value(), "RTAS SDK", true, isThisOS)));
  172. pathPropertyComponents.getLast()->setEnabled (false);
  173. }
  174. else
  175. {
  176. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (aaxPathValue, "AAX SDK", true, isThisOS)));
  177. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (rtasPathValue, "RTAS SDK", true, isThisOS)));
  178. }
  179. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (androidSDKPathValue, "Android SDK", true, isThisOS)));
  180. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (androidNDKPathValue, "Android NDK", true, isThisOS)));
  181. if (isThisOS)
  182. {
  183. pathPropertyComponents.add (nullptr);
  184. #if JUCE_MAC
  185. String exeLabel ("app");
  186. #elif JUCE_WINDOWS
  187. String exeLabel ("executable");
  188. #else
  189. String exeLabel ("startup script");
  190. #endif
  191. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (clionExePathValue, "CLion " + exeLabel, false, isThisOS)));
  192. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (androidStudioExePathValue, "Android Studio " + exeLabel, false, isThisOS)));
  193. rescanJUCEPathButton.setVisible (true);
  194. rescanUserPathButton.setVisible (true);
  195. }
  196. else
  197. {
  198. rescanJUCEPathButton.setVisible (false);
  199. rescanUserPathButton.setVisible (false);
  200. }
  201. resized();
  202. }
  203. void updateValues()
  204. {
  205. auto& settings = getAppSettings();
  206. auto os = getSelectedOS();
  207. jucePathValue = settings.getStoredPath (Ids::jucePath, os);
  208. juceModulePathValue = settings.getStoredPath (Ids::defaultJuceModulePath, os);
  209. userModulePathValue = settings.getStoredPath (Ids::defaultUserModulePath, os);
  210. vst3PathValue = settings.getStoredPath (Ids::vst3Path, os);
  211. rtasPathValue = settings.getStoredPath (Ids::rtasPath, os);
  212. aaxPathValue = settings.getStoredPath (Ids::aaxPath, os);
  213. androidSDKPathValue = settings.getStoredPath (Ids::androidSDKPath, os);
  214. androidNDKPathValue = settings.getStoredPath (Ids::androidNDKPath, os);
  215. clionExePathValue = settings.getStoredPath (Ids::clionExePath, os);
  216. androidStudioExePathValue = settings.getStoredPath (Ids::androidStudioExePath, os);
  217. }
  218. void addLabelsAndSetProperties()
  219. {
  220. pathPropertyLabels.clear();
  221. pathPropertyLabels.add (new Label ("modulesLabel", "Modules"));
  222. pathPropertyLabels.add (new Label ("sdksLabel", "SDKs"));
  223. pathPropertyLabels.add (new Label ("otherLabel", "Other"));
  224. for (auto* l : pathPropertyLabels)
  225. {
  226. addAndMakeVisible (l);
  227. l->setFont (Font (18.0f, Font::FontStyleFlags::bold));
  228. l->setJustificationType (Justification::centredLeft);
  229. }
  230. }
  231. void resetCurrentOSPathsToDefaults()
  232. {
  233. jucePathValue .resetToDefault();
  234. juceModulePathValue .resetToDefault();
  235. userModulePathValue .resetToDefault();
  236. vst3PathValue .resetToDefault();
  237. rtasPathValue .resetToDefault();
  238. aaxPathValue .resetToDefault();
  239. androidSDKPathValue .resetToDefault();
  240. androidNDKPathValue .resetToDefault();
  241. clionExePathValue .resetToDefault();
  242. androidStudioExePathValue.resetToDefault();
  243. repaint();
  244. }
  245. //==============================================================================
  246. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlobalPathsWindowComponent)
  247. };