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.

289 lines
12KB

  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. explicit 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. if (isMouseOverButton)
  44. {
  45. if (getStyle() == ButtonStyle::ImageFitted)
  46. {
  47. hoverBackground->drawWithin (g, getLocalBounds().toFloat(), RectanglePlacement::centred, 1.0);
  48. thumb->drawWithin (g, getLocalBounds().toFloat(), RectanglePlacement::centred, 1.0);
  49. }
  50. else
  51. {
  52. g.setColour (Colour (243, 146, 0).withAlpha (0.3f));
  53. g.fillRoundedRectangle (getLocalBounds().toFloat().reduced (2, 2), 10.0f);
  54. g.setColour (Colour (243, 146, 0).withAlpha (1.0f));
  55. g.drawRoundedRectangle (getLocalBounds().toFloat().reduced (2, 2), 10.0f, 2.0f);
  56. }
  57. }
  58. else
  59. {
  60. if (getStyle() == ButtonStyle::ImageFitted)
  61. {
  62. thumb->drawWithin (g, getLocalBounds().toFloat(), RectanglePlacement::centred, 1.0);
  63. }
  64. else
  65. {
  66. g.setColour (Colour (243, 146, 0).withAlpha (1.0f));
  67. g.drawRoundedRectangle (getLocalBounds().toFloat().reduced (2,2), 10.0f, 2.0f);
  68. }
  69. }
  70. Rectangle<float> textTarget;
  71. // center the text for the text buttons or position the text in the image buttons
  72. if (getStyle() != ButtonStyle::ImageFitted)
  73. {
  74. textTarget = getLocalBounds().toFloat();
  75. }
  76. else
  77. {
  78. textTarget = RectanglePlacement (RectanglePlacement::centred).appliedTo(thumb->getDrawableBounds(), getLocalBounds().toFloat());
  79. textTarget = textTarget.removeFromBottom(textTarget.getHeight() * 0.3);
  80. }
  81. g.setColour (Colours::white);
  82. g.drawText (name, textTarget, Justification::centred, true);
  83. }
  84. void resized()
  85. {
  86. thumb->setBoundsToFit (0, 0, getWidth(), getHeight(), Justification::centred, false);
  87. }
  88. void setDescription (String descript)
  89. {
  90. description = descript;
  91. }
  92. String getDescription()
  93. {
  94. return description;
  95. }
  96. private:
  97. ScopedPointer<Drawable> thumb;
  98. ScopedPointer<Drawable> hoverBackground;
  99. String name;
  100. String 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 (NewProjectWizardComponents::WizardComp* projectWizard)
  113. {
  114. addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("GUI Application", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconGui_svg)));
  115. addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Audio Application", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconAudio_svg)));
  116. addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Audio Plug-in", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconPlugin_svg)));
  117. addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Animated Application", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconAnimation_svg)));
  118. addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Opengl Application", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconOpengl_svg)));
  119. addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Console Application", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconConsole_svg)));
  120. addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Static Library", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconStatic_svg)));
  121. addAndMakeVisible (optionButtons.add (new TemplateOptionButton ("Dynamic Library", TemplateOptionButton::ButtonStyle::ImageFitted, BinaryData::iconDynamic_svg)));
  122. // Add the descriptions for each button
  123. optionButtons.getUnchecked(0)->setDescription ("Creates a blank JUCE application with a single window component.");
  124. optionButtons.getUnchecked(1)->setDescription ("Creates a blank JUCE application with a single window component and Audio and MIDI in/out functions.");
  125. optionButtons.getUnchecked(2)->setDescription ("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");
  126. optionButtons.getUnchecked(3)->setDescription ("Creates a blank JUCE application with a single window component that updates and draws at 60fps.");
  127. optionButtons.getUnchecked(4)->setDescription ("Creates a blank JUCE application with a single window component. This component supports all OPENGL drawing features including 3D model import and glsl shaders.");
  128. optionButtons.getUnchecked(5)->setDescription ("Creates a blank console application with support for all JUCE features.");
  129. optionButtons.getUnchecked(6)->setDescription ("Creates a Static Library template with support for all JUCE features");
  130. optionButtons.getUnchecked(7)->setDescription ("Creates a Dynamic Library template with support for all JUCE features");
  131. // Handle Open Project button functionality
  132. ApplicationCommandManager& commandManager = IntrojucerApp::getCommandManager();
  133. blankProjectButton = new TemplateOptionButton ("Create Blank Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::iconOpenfile_svg);
  134. openProjectButton = new TemplateOptionButton ("Open Existing Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::iconOpenfile_svg);
  135. openProjectButton->setCommandToTrigger (&commandManager, CommandIDs::open, true);
  136. exampleProjectButton = new TemplateOptionButton ("Open Example Project", TemplateOptionButton::ButtonStyle::ImageOnButtonBackground, BinaryData::iconOpenfile_svg);
  137. exampleProjectButton->setCommandToTrigger (&commandManager, CommandIDs::open, true);
  138. addAndMakeVisible (blankProjectButton);
  139. addAndMakeVisible (openProjectButton);
  140. addAndMakeVisible (exampleProjectButton);
  141. for (TemplateOptionButton* t : optionButtons)
  142. {
  143. t->addListener (this);
  144. }
  145. newProjectWizard = projectWizard;
  146. }
  147. void paint (Graphics& g) override
  148. {
  149. g.setColour (Colours::black.withAlpha (0.2f));
  150. g.fillRect (0, 0, getWidth(), 60);
  151. g.setColour (Colours::white);
  152. g.setFont (20);
  153. g.drawText ("Create New Project", 0, 0, getWidth(), 60, Justification::centred, true);
  154. // draw the descriptions of each template if hovered;
  155. // (repaint is called by the button listener on change state)
  156. Rectangle<int> descriptionBox = getBounds().reduced (30, 30);
  157. descriptionBox = descriptionBox.removeFromBottom (50);
  158. g.setColour (Colours::white.withAlpha (0.4f));
  159. g.setFont(15);
  160. for ( int i = 0; i < 8; i++ )
  161. {
  162. if (optionButtons.getUnchecked (i)->getState() == TemplateOptionButton::ButtonState::buttonOver)
  163. {
  164. g.drawFittedText (optionButtons.getUnchecked (i)->getDescription(), descriptionBox, Justification::centred, 5, 1.0f);
  165. }
  166. }
  167. }
  168. void resized()
  169. {
  170. Rectangle<int> allOpts = getBounds().reduced (40, 60);
  171. allOpts.removeFromBottom (allOpts.getHeight() * 0.25);
  172. int numHorizIcons = 4;
  173. int optStep = allOpts.getWidth()/numHorizIcons;
  174. for (int i = 0; i < 8; i++)
  175. {
  176. int yShift = i < numHorizIcons ? 0 : 1;
  177. Rectangle<int> bounds;
  178. bounds = Rectangle<int> (allOpts.getX() + i%numHorizIcons*optStep, allOpts.getY() + yShift * allOpts.getHeight() / 2, optStep, allOpts.getHeight() / 2);
  179. bounds.reduce (10, 10);
  180. optionButtons.getUnchecked (i)->setBounds (bounds);
  181. }
  182. Rectangle<int> openButtonBounds = getBounds();
  183. openButtonBounds.removeFromBottom (getHeight() * 0.12);
  184. openButtonBounds = openButtonBounds.removeFromBottom (120);
  185. openButtonBounds.reduce (50, 40);
  186. blankProjectButton->setBounds (openButtonBounds.removeFromLeft (optStep - 20));
  187. exampleProjectButton->setBounds (openButtonBounds.removeFromRight (optStep - 20));
  188. openProjectButton->setBounds (openButtonBounds.reduced (18, 0));
  189. }
  190. void buttonClicked (Button* b) override
  191. {
  192. if (b->getButtonText() == "GUI Application") newProjectWizard->projectType.setSelectedItemIndex (0);
  193. if (b->getButtonText() == "Console Application") newProjectWizard->projectType.setSelectedItemIndex (1);
  194. if (b->getButtonText() == "Audio Plug-in") newProjectWizard->projectType.setSelectedItemIndex (2);
  195. if (b->getButtonText() == "Static Library") newProjectWizard->projectType.setSelectedItemIndex (3);
  196. if (b->getButtonText() == "Dynamic Library") newProjectWizard->projectType.setSelectedItemIndex (4);
  197. //new templates without actual templates yet
  198. if (b->getButtonText() == "Animated Application") newProjectWizard->projectType.setSelectedItemIndex (0);
  199. if (b->getButtonText() == "Audio Application") newProjectWizard->projectType.setSelectedItemIndex (0);
  200. if (b->getButtonText() == "Opengl Application") newProjectWizard->projectType.setSelectedItemIndex (0);
  201. SlidingPanelComponent* parent = findParentComponentOfClass<SlidingPanelComponent>();
  202. jassert (parent != nullptr);
  203. if (parent->getNumTabs() > 0 && b->getButtonText() != "Open Existing Project") parent->goToTab (parent->getCurrentTabIndex() + 1);
  204. }
  205. void buttonStateChanged (Button*)
  206. {
  207. repaint();
  208. }
  209. private:
  210. OwnedArray<TemplateOptionButton> optionButtons;
  211. NewProjectWizardComponents::WizardComp* newProjectWizard;
  212. ScopedPointer<TemplateOptionButton> blankProjectButton;
  213. ScopedPointer<TemplateOptionButton> openProjectButton;
  214. ScopedPointer<TemplateOptionButton> exampleProjectButton;
  215. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TemplateTileBrowser)
  216. };
  217. #endif // JUCER_TEMPLATETHUMBNAILSCOMPONENT_H_INCLUDED