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.

281 lines
9.6KB

  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. struct LiveBuildSettingsComponent : public Component
  22. {
  23. LiveBuildSettingsComponent (Project& p)
  24. : group ("Live Build Settings",
  25. Icon (getIcons().settings, Colours::transparentBlack))
  26. {
  27. addAndMakeVisible (&group);
  28. PropertyListBuilder props;
  29. LiveBuildProjectSettings::getLiveSettings (p, props);
  30. group.setProperties (props);
  31. group.setName ("Live Build Settings");
  32. }
  33. void resized() override
  34. {
  35. group.updateSize (12, 0, getWidth() - 24);
  36. group.setBounds (getLocalBounds().reduced (12, 0));
  37. }
  38. void parentSizeChanged() override
  39. {
  40. const auto width = jmax (550, getParentWidth());
  41. auto y = group.updateSize (12, 0, width - 12);
  42. y = jmax (getParentHeight(), y);
  43. setSize (width, y);
  44. }
  45. PropertyGroupComponent group;
  46. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveBuildSettingsComponent)
  47. };
  48. //==============================================================================
  49. class LiveBuildTab : public Component,
  50. private ChangeListener
  51. {
  52. public:
  53. LiveBuildTab (CompileEngineChildProcess* child, String lastErrorMessage)
  54. {
  55. addAndMakeVisible (settingsButton = new IconButton ("Settings", &getIcons().settings));
  56. settingsButton->onClick = [this]
  57. {
  58. if (auto* pcc = findParentComponentOfClass<ProjectContentComponent>())
  59. pcc->showLiveBuildSettings();
  60. };
  61. if (child != nullptr)
  62. {
  63. addAndMakeVisible (concertinaPanel);
  64. buildConcertina (child);
  65. isEnabled = true;
  66. }
  67. else
  68. {
  69. isEnabled = false;
  70. errorMessage = getErrorMessage();
  71. errorMessageLabel = new Label ("Error", errorMessage);
  72. errorMessageLabel->setJustificationType (Justification::centred);
  73. errorMessageLabel->setFont (Font (12.0f));
  74. errorMessageLabel->setMinimumHorizontalScale (1.0f);
  75. addAndMakeVisible (errorMessageLabel);
  76. if (showDownloadButton)
  77. {
  78. addAndMakeVisible (downloadButton = new TextButton ("Download"));
  79. downloadButton->onClick = [this] { downloadDLL(); };
  80. }
  81. if (showEnableButton)
  82. {
  83. auto buttonText = "Enable Now";
  84. if (! lastErrorMessage.isEmpty())
  85. {
  86. errorMessageLabel->setText (lastErrorMessage, dontSendNotification);
  87. buttonText = "Re-enable";
  88. }
  89. addAndMakeVisible (enableButton = new TextButton (buttonText));
  90. enableButton->onClick = [this]
  91. {
  92. if (auto* pcc = findParentComponentOfClass<ProjectContentComponent>())
  93. pcc->setBuildEnabled (true);
  94. };
  95. }
  96. }
  97. }
  98. void paint (Graphics& g) override
  99. {
  100. g.fillAll (findColour (secondaryBackgroundColourId));
  101. }
  102. void resized() override
  103. {
  104. auto bounds = getLocalBounds();
  105. settingsButton->setBounds (bounds.removeFromBottom (25)
  106. .removeFromRight (25)
  107. .reduced (3));
  108. if (errorMessageLabel != nullptr)
  109. {
  110. bounds.removeFromTop ((bounds.getHeight() / 2) - 40);
  111. errorMessageLabel->setBounds (bounds.removeFromTop (80));
  112. if (downloadButton != nullptr)
  113. downloadButton->setBounds (bounds.removeFromTop (20).reduced (20, 0));
  114. if (enableButton != nullptr)
  115. enableButton->setBounds (bounds.removeFromTop (20).reduced (20, 0));
  116. }
  117. else
  118. {
  119. concertinaPanel.setBounds (bounds);
  120. for (auto h : headers)
  121. if (h->getName() == "Activities")
  122. h->yPosition = getHeight() - CurrentActivitiesComp::getMaxPanelHeight() - 55;
  123. }
  124. }
  125. bool isEnabled;
  126. String errorMessage;
  127. Component::SafePointer<ProjucerAppClasses::ErrorListComp> errorListComp;
  128. private:
  129. OwnedArray<ConcertinaHeader> headers;
  130. ConcertinaPanel concertinaPanel;
  131. ScopedPointer<IconButton> settingsButton;
  132. ScopedPointer<TextButton> downloadButton, enableButton;
  133. ScopedPointer<Label> errorMessageLabel;
  134. bool showDownloadButton;
  135. bool showEnableButton;
  136. Rectangle<int> textBounds;
  137. //==========================================================================
  138. String getErrorMessage()
  139. {
  140. showDownloadButton = false;
  141. showEnableButton = false;
  142. const auto osType = SystemStats::getOperatingSystemType();
  143. const bool isMac = (osType & SystemStats::MacOSX) != 0;
  144. const bool isWin = (osType & SystemStats::Windows) != 0;
  145. const bool isLinux = (osType & SystemStats::Linux) != 0;
  146. if (! isMac && ! isWin && ! isLinux)
  147. return String ("Live-build features are not supported on your system.\n\n"
  148. "Please check supported platforms at www.juce.com!");
  149. if (isLinux)
  150. return String ("Live-build features for Linux are under development.\n\n"
  151. "Please check for updates at www.juce.com!");
  152. if (isMac)
  153. if (osType < SystemStats::MacOSX_10_9)
  154. return String ("Live-build features are available only on MacOSX 10.9 or higher.");
  155. if (isWin)
  156. if (! SystemStats::isOperatingSystem64Bit() || osType < SystemStats::Windows8_0)
  157. return String ("Live-build features are available only on 64-Bit Windows 8 or higher.");
  158. const auto& compileEngineDll = *CompileEngineDLL::getInstance();
  159. const auto dllPresent = compileEngineDll.isLoaded();
  160. if (! dllPresent)
  161. {
  162. showDownloadButton = true;
  163. return String ("Download the live-build engine to get started");
  164. }
  165. showEnableButton = true;
  166. return String ("Enable compilation to use the live-build engine");
  167. }
  168. void downloadDLL()
  169. {
  170. if (DownloadCompileEngineThread::downloadAndInstall())
  171. {
  172. if (! CompileEngineDLL::getInstance()->tryLoadDll())
  173. {
  174. AlertWindow::showMessageBox(AlertWindow::WarningIcon,
  175. "Download and install",
  176. "Loading the live-build engine failed");
  177. return;
  178. }
  179. if (auto* pcc = findParentComponentOfClass<ProjectContentComponent>())
  180. pcc->rebuildProjectTabs();
  181. }
  182. }
  183. void buildConcertina (CompileEngineChildProcess* child)
  184. {
  185. for (int i = concertinaPanel.getNumPanels() - 1; i >= 0 ; --i)
  186. concertinaPanel.removePanel (concertinaPanel.getPanel (i));
  187. headers.clear();
  188. errorListComp = new ProjucerAppClasses::ErrorListComp (child->errorList);
  189. auto* activities = new CurrentActivitiesComp (child->activityList);
  190. auto* comps = new ComponentListComp (*child);
  191. concertinaPanel.addPanel (-1, errorListComp, true);
  192. concertinaPanel.addPanel (-1, comps, true);
  193. concertinaPanel.addPanel (-1, activities, true);
  194. headers.add (new ConcertinaHeader ("Errors", getIcons().bug));
  195. headers.add (new ConcertinaHeader ("Components", getIcons().modules));
  196. headers.add (new ConcertinaHeader ("Activities", getIcons().buildTab));
  197. for (int i = 0; i < concertinaPanel.getNumPanels(); ++i)
  198. {
  199. auto* p = concertinaPanel.getPanel (i);
  200. auto* h = headers.getUnchecked (i);
  201. h->addChangeListener (this);
  202. h->yPosition = i * 30;
  203. concertinaPanel.setCustomPanelHeader (p, h, false);
  204. concertinaPanel.setPanelHeaderSize (p, 30);
  205. }
  206. concertinaPanel.setMaximumPanelSize (activities, CurrentActivitiesComp::getMaxPanelHeight());
  207. concertinaPanel.setPanelSize (errorListComp, 200, false);
  208. concertinaPanel.setPanelSize (comps, 300, false);
  209. }
  210. void changeListenerCallback (ChangeBroadcaster* source) override
  211. {
  212. if (auto* header = dynamic_cast<ConcertinaHeader*> (source))
  213. {
  214. auto index = headers.indexOf (header);
  215. concertinaPanel.expandPanelFully (concertinaPanel.getPanel (index), true);
  216. }
  217. }
  218. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveBuildTab)
  219. };