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.

295 lines
12KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. #include "../../Utility/UI/PropertyComponents/jucer_LabelPropertyComponent.h"
  15. //==============================================================================
  16. class GlobalPathsWindowComponent : public Component,
  17. private Timer,
  18. private Value::Listener
  19. {
  20. public:
  21. GlobalPathsWindowComponent()
  22. {
  23. addChildComponent (rescanJUCEPathButton);
  24. rescanJUCEPathButton.onClick = [this]
  25. {
  26. ProjucerApplication::getApp().rescanJUCEPathModules();
  27. lastJUCEModulePath = getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS()).get();
  28. };
  29. addChildComponent (rescanUserPathButton);
  30. rescanUserPathButton.onClick = [this]
  31. {
  32. ProjucerApplication::getApp().rescanUserPathModules();
  33. lastUserModulePath = getAppSettings().getStoredPath (Ids::defaultUserModulePath, TargetOS::getThisOS()).get();
  34. };
  35. addAndMakeVisible (resetToDefaultsButton);
  36. resetToDefaultsButton.onClick = [this] { resetCurrentOSPathsToDefaults(); };
  37. addAndMakeVisible (propertyViewport);
  38. propertyViewport.setViewedComponent (&propertyGroup, false);
  39. auto os = TargetOS::getThisOS();
  40. if (os == TargetOS::osx) selectedOSValue = "osx";
  41. else if (os == TargetOS::windows) selectedOSValue = "windows";
  42. else if (os == TargetOS::linux) selectedOSValue = "linux";
  43. selectedOSValue.addListener (this);
  44. buildProps();
  45. lastJUCEModulePath = getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS()).get();
  46. lastUserModulePath = getAppSettings().getStoredPath (Ids::defaultUserModulePath, TargetOS::getThisOS()).get();
  47. }
  48. ~GlobalPathsWindowComponent() override
  49. {
  50. auto juceValue = getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS());
  51. auto userValue = getAppSettings().getStoredPath (Ids::defaultUserModulePath, TargetOS::getThisOS());
  52. if (juceValue.get() != lastJUCEModulePath) ProjucerApplication::getApp().rescanJUCEPathModules();
  53. if (userValue.get() != lastUserModulePath) ProjucerApplication::getApp().rescanUserPathModules();
  54. }
  55. void paint (Graphics& g) override
  56. {
  57. g.fillAll (findColour (backgroundColourId));
  58. }
  59. void paintOverChildren (Graphics& g) override
  60. {
  61. g.setColour (findColour (defaultHighlightColourId).withAlpha (flashAlpha));
  62. g.fillRect (boundsToHighlight);
  63. }
  64. void resized() override
  65. {
  66. auto b = getLocalBounds().reduced (10);
  67. auto buttonBounds = b.removeFromBottom (50);
  68. rescanJUCEPathButton.setBounds (buttonBounds.removeFromLeft (150).reduced (5, 10));
  69. rescanUserPathButton.setBounds (buttonBounds.removeFromLeft (150).reduced (5, 10));
  70. resetToDefaultsButton.setBounds (buttonBounds.removeFromRight (150).reduced (5, 10));
  71. propertyGroup.updateSize (0, 0, getWidth() - 20 - propertyViewport.getScrollBarThickness());
  72. propertyViewport.setBounds (b);
  73. }
  74. void highlightJUCEPath()
  75. {
  76. if (isTimerRunning() || ! isSelectedOSThisOS())
  77. return;
  78. PropertyComponent* jucePathPropertyComponent = nullptr;
  79. for (auto* prop : propertyGroup.properties)
  80. if (prop->getName() == "Path to JUCE")
  81. jucePathPropertyComponent = prop;
  82. if (jucePathPropertyComponent != nullptr)
  83. {
  84. boundsToHighlight = getLocalArea (&propertyGroup, jucePathPropertyComponent->getBounds());
  85. flashAlpha = 0.0f;
  86. hasFlashed = false;
  87. startTimer (25);
  88. }
  89. }
  90. private:
  91. //==============================================================================
  92. void timerCallback() override
  93. {
  94. flashAlpha += (hasFlashed ? -0.05f : 0.05f);
  95. if (flashAlpha > 0.75f)
  96. {
  97. hasFlashed = true;
  98. }
  99. else if (flashAlpha < 0.0f)
  100. {
  101. flashAlpha = 0.0f;
  102. boundsToHighlight = {};
  103. stopTimer();
  104. }
  105. repaint();
  106. }
  107. void valueChanged (Value&) override
  108. {
  109. buildProps();
  110. resized();
  111. }
  112. //==============================================================================
  113. bool isSelectedOSThisOS() { return TargetOS::getThisOS() == getSelectedOS(); }
  114. TargetOS::OS getSelectedOS() const
  115. {
  116. auto val = selectedOSValue.getValue();
  117. if (val == "osx") return TargetOS::osx;
  118. else if (val == "windows") return TargetOS::windows;
  119. else if (val == "linux") return TargetOS::linux;
  120. jassertfalse;
  121. return TargetOS::unknown;
  122. }
  123. //==============================================================================
  124. void buildProps()
  125. {
  126. updateValues();
  127. PropertyListBuilder builder;
  128. auto isThisOS = isSelectedOSThisOS();
  129. builder.add (new ChoicePropertyComponent (selectedOSValue, "OS", { "OSX", "Windows", "Linux" }, { "osx", "windows", "linux" }),
  130. "Use this dropdown to set the global paths for different OSes. "
  131. "\nN.B. These paths are stored locally and will only be used when "
  132. "saving a project on this machine. Other machines will have their own "
  133. "locally stored paths.");
  134. builder.add (new LabelPropertyComponent ("JUCE"), {});
  135. builder.add (new FilePathPropertyComponent (jucePathValue, "Path to JUCE", true, isThisOS),
  136. "This should be the path to the top-level directory of your JUCE folder. "
  137. "This path will be used when searching for the JUCE examples and DemoRunner application.");
  138. builder.add (new FilePathPropertyComponent (juceModulePathValue, "JUCE Modules", true, isThisOS),
  139. String ("This should be the path to the folder containing the JUCE modules that you wish to use, typically the \"modules\" directory of your JUCE folder.")
  140. + (isThisOS ? " Use the button below to re-scan a new path." : ""));
  141. builder.add (new FilePathPropertyComponent (userModulePathValue, "User Modules", true, isThisOS),
  142. String ("A path to a folder containing any custom modules that you wish to use.")
  143. + (isThisOS ? " Use the button below to re-scan new paths." : ""));
  144. builder.add (new LabelPropertyComponent ("SDKs"), {});
  145. builder.add (new FilePathPropertyComponent (vstPathValue, "VST (Legacy) SDK", true, isThisOS),
  146. "If you are building a legacy VST plug-in then this path should point to a VST2 SDK. "
  147. "The VST2 SDK can be obtained from the vstsdk3610_11_06_2018_build_37 (or older) VST3 SDK or JUCE version 5.3.2. "
  148. "You also need a VST2 license from Steinberg to distribute VST2 plug-ins.");
  149. if (getSelectedOS() != TargetOS::linux)
  150. {
  151. builder.add (new FilePathPropertyComponent (aaxPathValue, "AAX SDK", true, isThisOS),
  152. "If you are building AAX plug-ins, this should be the path to the AAX SDK folder.");
  153. builder.add (new FilePathPropertyComponent (rtasPathValue, "RTAS SDK (deprecated)", true, isThisOS),
  154. "If you are building RTAS plug-ins, this should be the path to the RTAS SDK folder.");
  155. }
  156. builder.add (new FilePathPropertyComponent (androidSDKPathValue, "Android SDK", true, isThisOS),
  157. "This path will be used when writing the local.properties file of an Android project and should point to the Android SDK folder.");
  158. builder.add (new FilePathPropertyComponent (androidNDKPathValue, "Android NDK", true, isThisOS),
  159. "This path will be used when writing the local.properties file of an Android project and should point to the Android NDK folder.");
  160. if (isThisOS)
  161. {
  162. builder.add (new LabelPropertyComponent ("Other"), {});
  163. #if JUCE_MAC
  164. String exeLabel ("app");
  165. #elif JUCE_WINDOWS
  166. String exeLabel ("executable");
  167. #else
  168. String exeLabel ("startup script");
  169. #endif
  170. builder.add (new FilePathPropertyComponent (clionExePathValue, "CLion " + exeLabel, false, isThisOS),
  171. "This path will be used for the \"Save Project and Open in IDE...\" option of the CLion exporter.");
  172. builder.add (new FilePathPropertyComponent (androidStudioExePathValue, "Android Studio " + exeLabel, false, isThisOS),
  173. "This path will be used for the \"Save Project and Open in IDE...\" option of the Android Studio exporter.");
  174. rescanJUCEPathButton.setVisible (true);
  175. rescanUserPathButton.setVisible (true);
  176. }
  177. else
  178. {
  179. rescanJUCEPathButton.setVisible (false);
  180. rescanUserPathButton.setVisible (false);
  181. }
  182. propertyGroup.setProperties (builder);
  183. }
  184. void updateValues()
  185. {
  186. auto& settings = getAppSettings();
  187. auto os = getSelectedOS();
  188. jucePathValue = settings.getStoredPath (Ids::jucePath, os);
  189. juceModulePathValue = settings.getStoredPath (Ids::defaultJuceModulePath, os);
  190. userModulePathValue = settings.getStoredPath (Ids::defaultUserModulePath, os);
  191. vstPathValue = settings.getStoredPath (Ids::vstLegacyPath, os);
  192. rtasPathValue = settings.getStoredPath (Ids::rtasPath, os);
  193. aaxPathValue = settings.getStoredPath (Ids::aaxPath, os);
  194. androidSDKPathValue = settings.getStoredPath (Ids::androidSDKPath, os);
  195. androidNDKPathValue = settings.getStoredPath (Ids::androidNDKPath, os);
  196. clionExePathValue = settings.getStoredPath (Ids::clionExePath, os);
  197. androidStudioExePathValue = settings.getStoredPath (Ids::androidStudioExePath, os);
  198. }
  199. void resetCurrentOSPathsToDefaults()
  200. {
  201. jucePathValue .resetToDefault();
  202. juceModulePathValue .resetToDefault();
  203. userModulePathValue .resetToDefault();
  204. vstPathValue .resetToDefault();
  205. rtasPathValue .resetToDefault();
  206. aaxPathValue .resetToDefault();
  207. androidSDKPathValue .resetToDefault();
  208. androidNDKPathValue .resetToDefault();
  209. clionExePathValue .resetToDefault();
  210. androidStudioExePathValue.resetToDefault();
  211. repaint();
  212. }
  213. //==============================================================================
  214. Value selectedOSValue;
  215. ValueWithDefault jucePathValue, juceModulePathValue, userModulePathValue,
  216. vstPathValue, rtasPathValue, aaxPathValue, androidSDKPathValue, androidNDKPathValue,
  217. clionExePathValue, androidStudioExePathValue;
  218. Viewport propertyViewport;
  219. PropertyGroupComponent propertyGroup { "Global Paths", { getIcons().openFolder, Colours::transparentBlack } };
  220. TextButton rescanJUCEPathButton { "Re-scan JUCE Modules" },
  221. rescanUserPathButton { "Re-scan User Modules" },
  222. resetToDefaultsButton { "Reset to Defaults" };
  223. Rectangle<int> boundsToHighlight;
  224. float flashAlpha = 0.0f;
  225. bool hasFlashed = false;
  226. var lastJUCEModulePath, lastUserModulePath;
  227. //==============================================================================
  228. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlobalPathsWindowComponent)
  229. };