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.

246 lines
8.1KB

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