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.

321 lines
13KB

  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. updateFilePathPropertyComponents();
  41. };
  42. auto os = TargetOS::getThisOS();
  43. if (os == TargetOS::osx) osSelector.setSelectedId (1);
  44. else if (os == TargetOS::windows) osSelector.setSelectedId (2);
  45. else if (os == TargetOS::linux) osSelector.setSelectedId (3);
  46. addChildComponent (rescanJUCEPathButton);
  47. rescanJUCEPathButton.onClick = [] { ProjucerApplication::getApp().rescanJUCEPathModules(); };
  48. addChildComponent (rescanUserPathButton);
  49. rescanUserPathButton.onClick = [] { ProjucerApplication::getApp().rescanUserPathModules(); };
  50. updateFilePathPropertyComponents();
  51. }
  52. void paint (Graphics& g) override
  53. {
  54. g.fillAll (findColour (backgroundColourId));
  55. }
  56. void paintOverChildren (Graphics& g) override
  57. {
  58. g.setColour (findColour (defaultHighlightColourId).withAlpha (flashAlpha));
  59. g.fillRect (boundsToHighlight);
  60. }
  61. void resized() override
  62. {
  63. auto b = getLocalBounds().reduced (10);
  64. auto topSlice = b.removeFromTop (25);
  65. osSelector.setSize (200, 25);
  66. osSelector.setCentrePosition (topSlice.getCentre());
  67. info.setBounds (osSelector.getBounds().withWidth (osSelector.getHeight()).translated ((osSelector.getWidth() + 5), 0).reduced (2));
  68. int labelIndex = 0;
  69. bool isFirst = true;
  70. bool showRescanButtons = (rescanJUCEPathButton.isVisible() && rescanUserPathButton.isVisible());
  71. for (auto* pathComp : pathPropertyComponents)
  72. {
  73. if (pathComp == nullptr)
  74. {
  75. b.removeFromTop (15);
  76. pathPropertyLabels.getUnchecked (labelIndex++)->setBounds (b.removeFromTop (20));
  77. b.removeFromTop (20);
  78. }
  79. else
  80. {
  81. if (isFirst)
  82. b.removeFromTop (20);
  83. auto compBounds = b.removeFromTop (pathComp->getPreferredHeight());
  84. if (showRescanButtons)
  85. {
  86. auto propName = pathComp->getName();
  87. if (propName == "JUCE Modules")
  88. rescanJUCEPathButton.setBounds (compBounds.removeFromRight (75).reduced (5, 0));
  89. else if (propName == "User Modules")
  90. rescanUserPathButton.setBounds (compBounds.removeFromRight (75).reduced (5, 0));
  91. }
  92. pathComp->setBounds (compBounds);
  93. b.removeFromTop (5);
  94. }
  95. isFirst = false;
  96. }
  97. }
  98. void highlightJUCEPath()
  99. {
  100. if (! isTimerRunning() && isSelectedOSThisOS())
  101. {
  102. if (auto* jucePathComp = pathPropertyComponents.getFirst())
  103. boundsToHighlight = jucePathComp->getBounds();
  104. flashAlpha = 0.0f;
  105. hasFlashed = false;
  106. startTimer (25);
  107. }
  108. }
  109. private:
  110. OwnedArray<Label> pathPropertyLabels;
  111. OwnedArray<PropertyComponent> pathPropertyComponents;
  112. TextButton rescanJUCEPathButton { "Re-scan" },
  113. rescanUserPathButton { "Re-scan" };
  114. ComboBox osSelector;
  115. InfoButton info;
  116. Rectangle<int> boundsToHighlight;
  117. float flashAlpha = 0.0f;
  118. bool hasFlashed = false;
  119. //==============================================================================
  120. void timerCallback() override
  121. {
  122. flashAlpha += (hasFlashed ? -0.05f : 0.05f);
  123. if (flashAlpha > 0.75f)
  124. {
  125. hasFlashed = true;
  126. }
  127. else if (flashAlpha < 0.0f)
  128. {
  129. flashAlpha = 0.0f;
  130. boundsToHighlight = {};
  131. stopTimer();
  132. }
  133. repaint();
  134. }
  135. //==============================================================================
  136. bool isSelectedOSThisOS() { return TargetOS::getThisOS() == getSelectedOS(); }
  137. TargetOS::OS getSelectedOS() const
  138. {
  139. auto selectedOS = TargetOS::unknown;
  140. switch (osSelector.getSelectedId())
  141. {
  142. case 1: selectedOS = TargetOS::osx; break;
  143. case 2: selectedOS = TargetOS::windows; break;
  144. case 3: selectedOS = TargetOS::linux; break;
  145. default: break;
  146. }
  147. return selectedOS;
  148. }
  149. void updateFilePathPropertyComponents()
  150. {
  151. pathPropertyComponents.clear();
  152. auto& settings = getAppSettings();
  153. if (isSelectedOSThisOS())
  154. {
  155. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::jucePath),
  156. "Path to JUCE", true)));
  157. pathPropertyComponents.add (nullptr);
  158. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::defaultJuceModulePath),
  159. "JUCE Modules", true)));
  160. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::defaultUserModulePath),
  161. "User Modules", true, {}, {}, true)));
  162. pathPropertyComponents.add (nullptr);
  163. if (getSelectedOS() == TargetOS::linux)
  164. {
  165. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent ({}, "RTAS SDK", true)));
  166. pathPropertyComponents.getLast()->setEnabled (false);
  167. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent ({}, "AAX SDK", true)));
  168. pathPropertyComponents.getLast()->setEnabled (false);
  169. }
  170. else
  171. {
  172. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::rtasPath),
  173. "RTAS SDK", true)));
  174. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::aaxPath),
  175. "AAX SDK", true)));
  176. }
  177. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::androidSDKPath),
  178. "Android SDK", true)));
  179. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::androidNDKPath),
  180. "Android NDK", true)));
  181. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::vst3Path),
  182. "Custom VST3 SDK", true)));
  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 (settings.getStoredPath (Ids::clionExePath),
  192. "CLion " + exeLabel, false)));
  193. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::androidStudioExePath),
  194. "Android Studio " + exeLabel, false)));
  195. rescanJUCEPathButton.setVisible (true);
  196. rescanUserPathButton.setVisible (true);
  197. }
  198. else
  199. {
  200. auto selectedOS = getSelectedOS();
  201. auto maxChars = 1024;
  202. pathPropertyComponents.add (nullptr);
  203. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::defaultJuceModulePath, selectedOS),
  204. "JUCE Modules", maxChars, false)));
  205. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::defaultUserModulePath, selectedOS),
  206. "User Modules", maxChars, false)));
  207. pathPropertyComponents.add (nullptr);
  208. if (selectedOS == TargetOS::linux)
  209. {
  210. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (Value(), "RTAS SDK", maxChars, false)));
  211. pathPropertyComponents.getLast()->setEnabled (false);
  212. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (Value(), "AAX SDK", maxChars, false)));
  213. pathPropertyComponents.getLast()->setEnabled (false);
  214. }
  215. else
  216. {
  217. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::rtasPath, selectedOS),
  218. "RTAS SDK", maxChars, false)));
  219. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::aaxPath, selectedOS),
  220. "AAX SDK", maxChars, false)));
  221. }
  222. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::androidSDKPath, selectedOS),
  223. "Android SDK", maxChars, false)));
  224. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::androidNDKPath, selectedOS),
  225. "Android NDK", maxChars, false)));
  226. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::vst3Path, selectedOS),
  227. "Custom VST3 SDK", maxChars, false)));
  228. rescanJUCEPathButton.setVisible (false);
  229. rescanUserPathButton.setVisible (false);
  230. }
  231. resized();
  232. }
  233. void addLabelsAndSetProperties()
  234. {
  235. pathPropertyLabels.clear();
  236. pathPropertyLabels.add (new Label ("modulesLabel", "Modules"));
  237. pathPropertyLabels.add (new Label ("sdksLabel", "SDKs"));
  238. pathPropertyLabels.add (new Label ("otherLabel", "Other"));
  239. for (auto* l : pathPropertyLabels)
  240. {
  241. addAndMakeVisible (l);
  242. l->setFont (Font (18.0f, Font::FontStyleFlags::bold));
  243. l->setJustificationType (Justification::centredLeft);
  244. }
  245. }
  246. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlobalPathsWindowComponent)
  247. };