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.

251 lines
9.5KB

  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::wizard_Highlight_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 (WizardComp* projectWizard)
  113. {
  114. for (int i = 0; i < getNumWizards(); ++i)
  115. {
  116. ScopedPointer<NewProjectWizard> wizard (createWizardType (i));
  117. TemplateOptionButton* b = new TemplateOptionButton (wizard->getName(),
  118. TemplateOptionButton::ButtonStyle::ImageFitted,
  119. wizard->getIcon());
  120. optionButtons.add (b);
  121. addAndMakeVisible (b);
  122. b->setDescription (wizard->getDescription());
  123. b->addListener (this);
  124. }
  125. // Handle Open Project button functionality
  126. ApplicationCommandManager& commandManager = IntrojucerApp::getCommandManager();
  127. blankProjectButton = new TemplateOptionButton ("Create Blank Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::wizard_Openfile_svg);
  128. openProjectButton = new TemplateOptionButton ("Open Existing Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::wizard_Openfile_svg);
  129. openProjectButton->setCommandToTrigger (&commandManager, CommandIDs::open, true);
  130. exampleProjectButton = new TemplateOptionButton ("Open Example Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::wizard_Openfile_svg);
  131. exampleProjectButton->setCommandToTrigger (&commandManager, CommandIDs::open, true);
  132. addAndMakeVisible (blankProjectButton);
  133. addAndMakeVisible (openProjectButton);
  134. addAndMakeVisible (exampleProjectButton);
  135. newProjectWizard = projectWizard;
  136. }
  137. void paint (Graphics& g) override
  138. {
  139. g.setColour (Colours::black.withAlpha (0.2f));
  140. g.fillRect (0, 0, getWidth(), 60);
  141. g.setColour (Colours::white);
  142. g.setFont (20);
  143. g.drawText ("Create New Project", 0, 0, getWidth(), 60, Justification::centred, true);
  144. // draw the descriptions of each template if hovered;
  145. // (repaint is called by the button listener on change state)
  146. Rectangle<int> descriptionBox = getBounds().reduced (30, 30);
  147. descriptionBox = descriptionBox.removeFromBottom (50);
  148. g.setColour (Colours::white.withAlpha (0.4f));
  149. g.setFont (15);
  150. for (int i = 0; i < 8; ++i)
  151. if (optionButtons.getUnchecked(i)->getState() == TemplateOptionButton::ButtonState::buttonOver)
  152. g.drawFittedText (optionButtons.getUnchecked(i)->getDescription(), descriptionBox, Justification::centred, 5, 1.0f);
  153. }
  154. void resized() override
  155. {
  156. Rectangle<int> allOpts = getBounds().reduced (40, 60);
  157. allOpts.removeFromBottom (allOpts.getHeight() * 0.25);
  158. const int numHorizIcons = 4;
  159. const int optStep = allOpts.getWidth()/numHorizIcons;
  160. for (int i = 0; i < optionButtons.size(); ++i)
  161. {
  162. const int yShift = i < numHorizIcons ? 0 : 1;
  163. optionButtons.getUnchecked(i)->setBounds (Rectangle<int> (allOpts.getX() + (i % numHorizIcons) * optStep,
  164. allOpts.getY() + yShift * allOpts.getHeight() / 2,
  165. optStep, allOpts.getHeight() / 2)
  166. .reduced (10, 10));
  167. }
  168. Rectangle<int> openButtonBounds = getBounds();
  169. openButtonBounds.removeFromBottom (proportionOfHeight (0.12f));
  170. openButtonBounds = openButtonBounds.removeFromBottom (120);
  171. openButtonBounds.reduce (50, 40);
  172. blankProjectButton->setBounds (openButtonBounds.removeFromLeft (optStep - 20));
  173. exampleProjectButton->setBounds (openButtonBounds.removeFromRight (optStep - 20));
  174. openProjectButton->setBounds (openButtonBounds.reduced (18, 0));
  175. }
  176. void buttonClicked (Button* b) override
  177. {
  178. newProjectWizard->projectType.setText (b->getButtonText());
  179. if (SlidingPanelComponent* parent = findParentComponentOfClass<SlidingPanelComponent>())
  180. {
  181. if (parent->getNumTabs() > 0 && b->getButtonText() != "Open Existing Project")
  182. parent->goToTab (parent->getCurrentTabIndex() + 1);
  183. }
  184. else
  185. {
  186. jassertfalse;
  187. }
  188. }
  189. void buttonStateChanged (Button*) override
  190. {
  191. repaint();
  192. }
  193. private:
  194. OwnedArray<TemplateOptionButton> optionButtons;
  195. NewProjectWizardClasses::WizardComp* newProjectWizard;
  196. ScopedPointer<TemplateOptionButton> blankProjectButton, openProjectButton, exampleProjectButton;
  197. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TemplateTileBrowser)
  198. };
  199. #endif // JUCER_TEMPLATETHUMBNAILSCOMPONENT_H_INCLUDED