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.

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