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.

245 lines
7.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. #include "../JuceDemoHeader.h"
  18. //==============================================================================
  19. class DemoButtonPropertyComponent : public ButtonPropertyComponent
  20. {
  21. public:
  22. DemoButtonPropertyComponent (const String& propertyName)
  23. : ButtonPropertyComponent (propertyName, true),
  24. counter (0)
  25. {
  26. refresh();
  27. }
  28. void buttonClicked() override
  29. {
  30. ++counter;
  31. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon, "Action Button Pressed",
  32. "Pressing this type of property component can trigger an action such as showing an alert window!");
  33. refresh();
  34. }
  35. String getButtonText() const override
  36. {
  37. String text ("Button clicked ");
  38. text << counter << " times";
  39. return text;
  40. }
  41. private:
  42. int counter;
  43. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DemoButtonPropertyComponent)
  44. };
  45. //==============================================================================
  46. class DemoSliderPropertyComponent : public SliderPropertyComponent
  47. {
  48. public:
  49. DemoSliderPropertyComponent (const String& propertyName)
  50. : SliderPropertyComponent (propertyName, 0.0, 100.0, 0.001)
  51. {
  52. setValue (Random::getSystemRandom().nextDouble() * 42.0);
  53. }
  54. void setValue (double newValue) override
  55. {
  56. slider.setValue (newValue);
  57. }
  58. private:
  59. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DemoSliderPropertyComponent)
  60. };
  61. //==============================================================================
  62. static Array<PropertyComponent*> createTextEditors()
  63. {
  64. Array<PropertyComponent*> comps;
  65. comps.add (new TextPropertyComponent (Value (var ("This is a single-line Text Property")), "Text 1", 200, false));
  66. comps.add (new TextPropertyComponent (Value (var ("Another one")), "Text 2", 200, false));
  67. comps.add (new TextPropertyComponent (Value (var (
  68. "Lorem ipsum dolor sit amet, cu mei labore admodum facilisi. Iriure iuvaret invenire ea vim, cum quod"
  69. "si intellegat delicatissimi an. Cetero recteque ei eos, his an scripta fastidii placerat. Nec et anc"
  70. "illae nominati corrumpit. Vis dictas audire accumsan ad, elit fabulas saperet mel eu.\n"
  71. "\n"
  72. "Dicam utroque ius ne, eum choro phaedrum eu. Ut mel omnes virtute appareat, semper quodsi labitur in"
  73. " cum. Est aeque eripuit deleniti in, amet ferri recusabo ea nec. Cu persius maiorum corrumpit mei, i"
  74. "n ridens perpetua mea, pri nobis tation inermis an. Vis alii autem cotidieque ut, ius harum salutatu"
  75. "s ut. Mel eu purto veniam dissentias, malis doctus bonorum ne vel, mundi aperiam adversarium cu eum."
  76. " Mei quando graeci te, dolore accusata mei te.")),
  77. "Multi-line text",
  78. 1000, true));
  79. return comps;
  80. }
  81. static Array<PropertyComponent*> createSliders (int howMany)
  82. {
  83. Array<PropertyComponent*> comps;
  84. for (int i = 0; i < howMany; ++i)
  85. comps.add (new DemoSliderPropertyComponent ("Slider " + String (i + 1)));
  86. return comps;
  87. }
  88. static Array<PropertyComponent*> createButtons (int howMany)
  89. {
  90. Array<PropertyComponent*> comps;
  91. for (int i = 0; i < howMany; ++i)
  92. comps.add (new DemoButtonPropertyComponent ("Button " + String (i + 1)));
  93. for (int i = 0; i < howMany; ++i)
  94. comps.add (new BooleanPropertyComponent (Value (Random::getSystemRandom().nextBool()), "Toggle " + String (i + 1), "Description of toggleable thing"));
  95. return comps;
  96. }
  97. static Array<PropertyComponent*> createChoices (int howMany)
  98. {
  99. Array<PropertyComponent*> comps;
  100. StringArray choices;
  101. Array<var> choiceVars;
  102. for (int i = 0; i < howMany; ++i)
  103. {
  104. choices.add ("Item " + String (i));
  105. choiceVars.add (i);
  106. }
  107. for (int i = 0; i < howMany; ++i)
  108. comps.add (new ChoicePropertyComponent (Value (Random::getSystemRandom().nextInt (6)), "Choice Property " + String (i + 1), choices, choiceVars));
  109. return comps;
  110. }
  111. //==============================================================================
  112. class PropertiesDemo : public Component
  113. {
  114. public:
  115. PropertiesDemo()
  116. {
  117. setOpaque (true);
  118. addAndMakeVisible (propertyPanel);
  119. propertyPanel.addSection ("Text Editors", createTextEditors());
  120. propertyPanel.addSection ("Sliders", createSliders (3));
  121. propertyPanel.addSection ("Choice Properties", createChoices (6));
  122. propertyPanel.addSection ("Buttons & Toggles", createButtons (3));
  123. }
  124. void paint (Graphics& g) override
  125. {
  126. g.fillAll (Colour::greyLevel (0.8f));
  127. }
  128. void resized() override
  129. {
  130. propertyPanel.setBounds (getLocalBounds().reduced (4));
  131. }
  132. private:
  133. PropertyPanel propertyPanel;
  134. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertiesDemo)
  135. };
  136. //==============================================================================
  137. class ConcertinaDemo : public Component,
  138. private Timer
  139. {
  140. public:
  141. ConcertinaDemo()
  142. {
  143. setOpaque (true);
  144. addAndMakeVisible (concertinaPanel);
  145. {
  146. PropertyPanel* panel = new PropertyPanel ("Text Editors");
  147. panel->addProperties (createTextEditors());
  148. addPanel (panel);
  149. }
  150. {
  151. PropertyPanel* panel = new PropertyPanel ("Sliders");
  152. panel->addSection ("Section 1", createSliders (4), true);
  153. panel->addSection ("Section 2", createSliders (3), true);
  154. addPanel (panel);
  155. }
  156. {
  157. PropertyPanel* panel = new PropertyPanel ("Choice Properties");
  158. panel->addProperties (createChoices (12));
  159. addPanel (panel);
  160. }
  161. {
  162. PropertyPanel* panel = new PropertyPanel ("Buttons & Toggles");
  163. panel->addProperties (createButtons (6));
  164. addPanel (panel);
  165. }
  166. startTimer (300);
  167. }
  168. void paint (Graphics& g) override
  169. {
  170. g.fillAll (Colour::greyLevel (0.8f));
  171. }
  172. void resized() override
  173. {
  174. concertinaPanel.setBounds (getLocalBounds().reduced (4));
  175. }
  176. void timerCallback() override
  177. {
  178. stopTimer();
  179. concertinaPanel.expandPanelFully (concertinaPanel.getPanel(0), true);
  180. }
  181. private:
  182. ConcertinaPanel concertinaPanel;
  183. void addPanel (PropertyPanel* panel)
  184. {
  185. concertinaPanel.addPanel (-1, panel, true);
  186. concertinaPanel.setMaximumPanelSize (panel, panel->getTotalContentHeight());
  187. }
  188. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConcertinaDemo)
  189. };
  190. // This static object will register this demo type in a global list of demos..
  191. static JuceDemoType <PropertiesDemo> demo1 ("10 Components: Property Panels");
  192. static JuceDemoType <ConcertinaDemo> demo2 ("10 Components: Concertina Panels");