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.

249 lines
8.1KB

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