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.

271 lines
9.3KB

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