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.

273 lines
11KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCER_TEMPLATETHUMBNAILSCOMPONENT_H_INCLUDED
  18. #define JUCER_TEMPLATETHUMBNAILSCOMPONENT_H_INCLUDED
  19. //=====================================================================================================
  20. /**
  21. Template option tile button.
  22. The drawable button object class for the tile icons and buttons in the TemplateTileBrowser
  23. */
  24. class TemplateOptionButton : public DrawableButton
  25. {
  26. public:
  27. TemplateOptionButton (const String& buttonName, ButtonStyle buttonStyle, const char* thumbSvg)
  28. : DrawableButton (buttonName, buttonStyle)
  29. {
  30. // svg for thumbnail icon
  31. ScopedPointer<XmlElement> svg (XmlDocument::parse (thumbSvg));
  32. assert (svg != nullptr);
  33. thumb = Drawable::createFromSVG (*svg);
  34. // svg for thumbnail background highlight
  35. ScopedPointer<XmlElement> backSvg (XmlDocument::parse (BinaryData::iconHighlight_svg));
  36. assert (backSvg != nullptr);
  37. hoverBackground = Drawable::createFromSVG (*backSvg);
  38. name = buttonName;
  39. description = "<insert description>";
  40. }
  41. void paintButton (Graphics& g, bool isMouseOverButton, bool /*isButtonDown*/) override
  42. {
  43. const Rectangle<float> bounds (getLocalBounds().toFloat());
  44. const Colour buttonColour (0xfff29300);
  45. if (isMouseOverButton)
  46. {
  47. if (getStyle() == ButtonStyle::ImageFitted)
  48. {
  49. hoverBackground->drawWithin (g, bounds, RectanglePlacement::centred, 1.0);
  50. thumb->drawWithin (g, bounds, RectanglePlacement::centred, 1.0);
  51. }
  52. else
  53. {
  54. g.setColour (buttonColour.withAlpha (0.3f));
  55. g.fillRoundedRectangle (bounds.reduced (2.0f, 2.0f), 10.0f);
  56. g.setColour (buttonColour);
  57. g.drawRoundedRectangle (bounds.reduced (2.0f, 2.0f), 10.0f, 2.0f);
  58. }
  59. }
  60. else
  61. {
  62. if (getStyle() == ButtonStyle::ImageFitted)
  63. {
  64. thumb->drawWithin (g, bounds, RectanglePlacement::centred, 1.0);
  65. }
  66. else
  67. {
  68. g.setColour (buttonColour);
  69. g.drawRoundedRectangle (bounds.reduced (2.0f, 2.0f), 10.0f, 2.0f);
  70. }
  71. }
  72. Rectangle<float> textTarget;
  73. // center the text for the text buttons or position the text in the image buttons
  74. if (getStyle() != ButtonStyle::ImageFitted)
  75. {
  76. textTarget = getLocalBounds().toFloat();
  77. }
  78. else
  79. {
  80. textTarget = RectanglePlacement (RectanglePlacement::centred).appliedTo (thumb->getDrawableBounds(), bounds);
  81. textTarget = textTarget.removeFromBottom (textTarget.getHeight() * 0.3f);
  82. }
  83. g.setColour (Colours::white);
  84. g.drawText (name, textTarget, Justification::centred, true);
  85. }
  86. void resized() override
  87. {
  88. thumb->setBoundsToFit (0, 0, getWidth(), getHeight(), Justification::centred, false);
  89. }
  90. void setDescription (String descript) noexcept
  91. {
  92. description = descript;
  93. }
  94. String getDescription() const noexcept
  95. {
  96. return description;
  97. }
  98. private:
  99. ScopedPointer<Drawable> thumb, hoverBackground;
  100. String name, description;
  101. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TemplateOptionButton)
  102. };
  103. //=====================================================================================================
  104. /**
  105. Project Template Component for front page.
  106. Features multiple icon buttons to select the type of project template
  107. */
  108. class TemplateTileBrowser : public Component,
  109. private Button::Listener
  110. {
  111. public:
  112. TemplateTileBrowser (NewProjectWizardClasses::WizardComp* projectWizard)
  113. {
  114. addOptionButton ("GUI Application", BinaryData::iconGui_svg, "Creates a blank JUCE application with a single window component.");
  115. addOptionButton ("Audio Application", BinaryData::iconAudio_svg, "Creates a blank JUCE application with a single window component and Audio and MIDI in/out functions.");
  116. addOptionButton ("Audio Plug-in", BinaryData::iconPlugin_svg, "Creates a VST or AU audio plug-in for use within a host program. This template features a single window component and Audio/MIDI IO functions");
  117. addOptionButton ("Animated Application", BinaryData::iconAnimation_svg, "Creates a blank JUCE application with a single window component that updates and draws at 60fps.");
  118. addOptionButton ("Opengl Application", BinaryData::iconOpengl_svg, "Creates a blank JUCE application with a single window component. This component supports all OPENGL drawing features including 3D model import and glsl shaders.");
  119. addOptionButton ("Console Application", BinaryData::iconConsole_svg, "Creates a blank console application with support for all JUCE features.");
  120. addOptionButton ("Static Library", BinaryData::iconStatic_svg, "Creates a Static Library template with support for all JUCE features");
  121. addOptionButton ("Dynamic Library", BinaryData::iconDynamic_svg, "Creates a Dynamic Library template with support for all JUCE features");
  122. // Handle Open Project button functionality
  123. ApplicationCommandManager& commandManager = IntrojucerApp::getCommandManager();
  124. blankProjectButton = new TemplateOptionButton ("Create Blank Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::iconOpenfile_svg);
  125. openProjectButton = new TemplateOptionButton ("Open Existing Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::iconOpenfile_svg);
  126. openProjectButton->setCommandToTrigger (&commandManager, CommandIDs::open, true);
  127. exampleProjectButton = new TemplateOptionButton ("Open Example Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::iconOpenfile_svg);
  128. exampleProjectButton->setCommandToTrigger (&commandManager, CommandIDs::open, true);
  129. addAndMakeVisible (blankProjectButton);
  130. addAndMakeVisible (openProjectButton);
  131. addAndMakeVisible (exampleProjectButton);
  132. newProjectWizard = projectWizard;
  133. }
  134. void addOptionButton (const char* name, const char* svg, const char* desc)
  135. {
  136. TemplateOptionButton* b = new TemplateOptionButton (name, TemplateOptionButton::ButtonStyle::ImageFitted, svg);
  137. optionButtons.add (b);
  138. addAndMakeVisible (b);
  139. b->setDescription (desc);
  140. b->addListener (this);
  141. }
  142. void paint (Graphics& g) override
  143. {
  144. g.setColour (Colours::black.withAlpha (0.2f));
  145. g.fillRect (0, 0, getWidth(), 60);
  146. g.setColour (Colours::white);
  147. g.setFont (20);
  148. g.drawText ("Create New Project", 0, 0, getWidth(), 60, Justification::centred, true);
  149. // draw the descriptions of each template if hovered;
  150. // (repaint is called by the button listener on change state)
  151. Rectangle<int> descriptionBox = getBounds().reduced (30, 30);
  152. descriptionBox = descriptionBox.removeFromBottom (50);
  153. g.setColour (Colours::white.withAlpha (0.4f));
  154. g.setFont (15);
  155. for (int i = 0; i < 8; ++i)
  156. if (optionButtons.getUnchecked(i)->getState() == TemplateOptionButton::ButtonState::buttonOver)
  157. g.drawFittedText (optionButtons.getUnchecked(i)->getDescription(), descriptionBox, Justification::centred, 5, 1.0f);
  158. }
  159. void resized() override
  160. {
  161. Rectangle<int> allOpts = getBounds().reduced (40, 60);
  162. allOpts.removeFromBottom (allOpts.getHeight() * 0.25);
  163. const int numHorizIcons = 4;
  164. const int optStep = allOpts.getWidth()/numHorizIcons;
  165. for (int i = 0; i < optionButtons.size(); ++i)
  166. {
  167. const int yShift = i < numHorizIcons ? 0 : 1;
  168. optionButtons.getUnchecked(i)->setBounds (Rectangle<int> (allOpts.getX() + (i % numHorizIcons) * optStep,
  169. allOpts.getY() + yShift * allOpts.getHeight() / 2,
  170. optStep, allOpts.getHeight() / 2)
  171. .reduced (10, 10));
  172. }
  173. Rectangle<int> openButtonBounds = getBounds();
  174. openButtonBounds.removeFromBottom (proportionOfHeight (0.12f));
  175. openButtonBounds = openButtonBounds.removeFromBottom (120);
  176. openButtonBounds.reduce (50, 40);
  177. blankProjectButton->setBounds (openButtonBounds.removeFromLeft (optStep - 20));
  178. exampleProjectButton->setBounds (openButtonBounds.removeFromRight (optStep - 20));
  179. openProjectButton->setBounds (openButtonBounds.reduced (18, 0));
  180. }
  181. static int getIndexOfButton (const String& buttonText)
  182. {
  183. if (buttonText == "GUI Application") return 0;
  184. if (buttonText == "Console Application") return 1;
  185. if (buttonText == "Audio Plug-in") return 2;
  186. if (buttonText == "Static Library") return 3;
  187. if (buttonText == "Dynamic Library") return 4;
  188. // new templates without actual templates yet
  189. if (buttonText == "Animated Application") return 0;
  190. if (buttonText == "Audio Application") return 0;
  191. if (buttonText == "Opengl Application") return 0;
  192. jassertfalse;
  193. return 0;
  194. }
  195. void buttonClicked (Button* b) override
  196. {
  197. newProjectWizard->projectType.setSelectedItemIndex (getIndexOfButton (b->getButtonText()));
  198. if (SlidingPanelComponent* parent = findParentComponentOfClass<SlidingPanelComponent>())
  199. {
  200. if (parent->getNumTabs() > 0 && b->getButtonText() != "Open Existing Project")
  201. parent->goToTab (parent->getCurrentTabIndex() + 1);
  202. }
  203. else
  204. {
  205. jassertfalse;
  206. }
  207. }
  208. void buttonStateChanged (Button*) override
  209. {
  210. repaint();
  211. }
  212. private:
  213. OwnedArray<TemplateOptionButton> optionButtons;
  214. NewProjectWizardClasses::WizardComp* newProjectWizard;
  215. ScopedPointer<TemplateOptionButton> blankProjectButton, openProjectButton, exampleProjectButton;
  216. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TemplateTileBrowser)
  217. };
  218. #endif // JUCER_TEMPLATETHUMBNAILSCOMPONENT_H_INCLUDED