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.

272 lines
9.3KB

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