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.

297 lines
11KB

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