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.

280 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. {
  25. addAndMakeVisible (&group);
  26. PropertyListBuilder props;
  27. p.getCompileEngineSettings().getLiveSettings (props);
  28. group.setProperties (props);
  29. group.setName ("Live Build Settings");
  30. }
  31. void resized() override
  32. {
  33. group.updateSize (12, 0, getWidth() - 24);
  34. group.setBounds (getLocalBounds().reduced (12, 0));
  35. }
  36. void parentSizeChanged() override
  37. {
  38. auto width = jmax (550, getParentWidth());
  39. auto y = group.updateSize (12, 0, width - 12);
  40. y = jmax (getParentHeight(), y);
  41. setSize (width, y);
  42. }
  43. PropertyGroupComponent group { "Live Build Settings", Icon (getIcons().settings, Colours::transparentBlack) };
  44. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveBuildSettingsComponent)
  45. };
  46. //==============================================================================
  47. class LiveBuildTab : public Component,
  48. private ChangeListener
  49. {
  50. public:
  51. LiveBuildTab (const CompileEngineChildProcess::Ptr& child, String lastErrorMessage)
  52. {
  53. settingsButton.reset (new IconButton ("Settings", &getIcons().settings));
  54. addAndMakeVisible (settingsButton.get());
  55. settingsButton->onClick = [this]
  56. {
  57. if (auto* pcc = findParentComponentOfClass<ProjectContentComponent>())
  58. pcc->showLiveBuildSettings();
  59. };
  60. if (child != nullptr)
  61. {
  62. addAndMakeVisible (concertinaPanel);
  63. buildConcertina (*child);
  64. isEnabled = true;
  65. }
  66. else
  67. {
  68. errorMessage = getErrorMessage();
  69. errorMessageLabel.reset (new Label ("Error", errorMessage));
  70. errorMessageLabel->setJustificationType (Justification::centred);
  71. errorMessageLabel->setFont (Font (12.0f));
  72. errorMessageLabel->setMinimumHorizontalScale (1.0f);
  73. addAndMakeVisible (errorMessageLabel.get());
  74. if (showDownloadButton)
  75. {
  76. downloadButton.reset (new TextButton ("Download"));
  77. addAndMakeVisible (downloadButton.get());
  78. downloadButton->onClick = [this] { downloadDLL(); };
  79. }
  80. if (showEnableButton)
  81. {
  82. String buttonText ("Enable Now");
  83. if (! lastErrorMessage.isEmpty())
  84. {
  85. errorMessageLabel->setText (lastErrorMessage, dontSendNotification);
  86. buttonText = "Re-enable";
  87. }
  88. enableButton.reset (new TextButton (buttonText));
  89. addAndMakeVisible (enableButton.get());
  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 = false;
  126. String errorMessage;
  127. Component::SafePointer<ProjucerAppClasses::ErrorListComp> errorListComp;
  128. private:
  129. OwnedArray<ConcertinaHeader> headers;
  130. ConcertinaPanel concertinaPanel;
  131. std::unique_ptr<IconButton> settingsButton;
  132. std::unique_ptr<TextButton> downloadButton, enableButton;
  133. std::unique_ptr<Label> errorMessageLabel;
  134. bool showDownloadButton;
  135. bool showEnableButton;
  136. Rectangle<int> textBounds;
  137. //==========================================================================
  138. String getErrorMessage()
  139. {
  140. showDownloadButton = false;
  141. showEnableButton = false;
  142. auto osType = SystemStats::getOperatingSystemType();
  143. auto isMac = (osType & SystemStats::MacOSX) != 0;
  144. auto isWin = (osType & SystemStats::Windows) != 0;
  145. auto isLinux = (osType & SystemStats::Linux) != 0;
  146. if (! isMac && ! isWin && ! isLinux)
  147. return "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 "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 "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 "Live-build features are available only on 64-Bit Windows 8 or higher.";
  158. auto& compileEngineDll = *CompileEngineDLL::getInstance();
  159. auto dllPresent = compileEngineDll.isLoaded();
  160. if (! dllPresent)
  161. {
  162. showDownloadButton = true;
  163. return "Download the live-build engine to get started";
  164. }
  165. showEnableButton = true;
  166. return "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 (auto 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. };