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.

227 lines
8.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. The code included in this file is provided under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  7. To use, copy, modify, and/or distribute this software for any purpose with or
  8. without fee is hereby granted provided that the above copyright notice and
  9. this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
  11. WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
  12. PURPOSE, ARE DISCLAIMED.
  13. ==============================================================================
  14. */
  15. /*******************************************************************************
  16. The block below describes the properties of this PIP. A PIP is a short snippet
  17. of code that can be read by the Projucer and used to generate a JUCE project.
  18. BEGIN_JUCE_PIP_METADATA
  19. name: PropertiesDemo
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: Displays various property components.
  24. dependencies: juce_core, juce_data_structures, juce_events, juce_graphics,
  25. juce_gui_basics
  26. exporters: xcode_mac, vs2017, linux_make, androidstudio, xcode_iphone
  27. type: Component
  28. mainClass: PropertiesDemo
  29. useLocalCopy: 1
  30. END_JUCE_PIP_METADATA
  31. *******************************************************************************/
  32. #pragma once
  33. #include "../Assets/DemoUtilities.h"
  34. //==============================================================================
  35. class DemoButtonPropertyComponent : public ButtonPropertyComponent
  36. {
  37. public:
  38. DemoButtonPropertyComponent (const String& propertyName)
  39. : ButtonPropertyComponent (propertyName, true)
  40. {
  41. refresh();
  42. }
  43. void buttonClicked() override
  44. {
  45. ++counter;
  46. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon, "Action Button Pressed",
  47. "Pressing this type of property component can trigger an action such as showing an alert window!");
  48. refresh();
  49. }
  50. String getButtonText() const override
  51. {
  52. return "Button clicked " + String (counter) + " times";
  53. }
  54. private:
  55. int counter = 0;
  56. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DemoButtonPropertyComponent)
  57. };
  58. //==============================================================================
  59. class DemoSliderPropertyComponent : public SliderPropertyComponent
  60. {
  61. public:
  62. DemoSliderPropertyComponent (const String& propertyName)
  63. : SliderPropertyComponent (propertyName, 0.0, 100.0, 0.001)
  64. {
  65. setValue (Random::getSystemRandom().nextDouble() * 42.0);
  66. }
  67. void setValue (double newValue) override
  68. {
  69. slider.setValue (newValue);
  70. }
  71. private:
  72. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DemoSliderPropertyComponent)
  73. };
  74. //==============================================================================
  75. static Array<PropertyComponent*> createTextEditors()
  76. {
  77. return { new TextPropertyComponent (Value (var ("This is a single-line Text Property")), "Text 1", 200, false),
  78. new TextPropertyComponent (Value (var ("Another one")), "Text 2", 200, false),
  79. new TextPropertyComponent (Value (var ( "Lorem ipsum dolor sit amet, cu mei labore admodum facilisi. Iriure iuvaret invenire ea vim, cum quod"
  80. "si intellegat delicatissimi an. Cetero recteque ei eos, his an scripta fastidii placerat. Nec et anc"
  81. "illae nominati corrumpit. Vis dictas audire accumsan ad, elit fabulas saperet mel eu.\n"
  82. "\n"
  83. "Dicam utroque ius ne, eum choro phaedrum eu. Ut mel omnes virtute appareat, semper quodsi labitur in"
  84. " cum. Est aeque eripuit deleniti in, amet ferri recusabo ea nec. Cu persius maiorum corrumpit mei, i"
  85. "n ridens perpetua mea, pri nobis tation inermis an. Vis alii autem cotidieque ut, ius harum salutatu"
  86. "s ut. Mel eu purto veniam dissentias, malis doctus bonorum ne vel, mundi aperiam adversarium cu eum."
  87. " Mei quando graeci te, dolore accusata mei te.")),
  88. "Multi-line text",
  89. 1000, true) };
  90. }
  91. static Array<PropertyComponent*> createSliders (int howMany)
  92. {
  93. Array<PropertyComponent*> comps;
  94. for (int i = 0; i < howMany; ++i)
  95. comps.add (new DemoSliderPropertyComponent ("Slider " + String (i + 1)));
  96. return comps;
  97. }
  98. static Array<PropertyComponent*> createButtons (int howMany)
  99. {
  100. Array<PropertyComponent*> comps;
  101. for (int i = 0; i < howMany; ++i)
  102. comps.add (new DemoButtonPropertyComponent ("Button " + String (i + 1)));
  103. for (int i = 0; i < howMany; ++i)
  104. comps.add (new BooleanPropertyComponent (Value (Random::getSystemRandom().nextBool()), "Toggle " + String (i + 1), "Description of toggleable thing"));
  105. return comps;
  106. }
  107. static Array<PropertyComponent*> createChoices (int howMany)
  108. {
  109. Array<PropertyComponent*> comps;
  110. StringArray choices;
  111. Array<var> choiceVars;
  112. for (int i = 0; i < 12; ++i)
  113. {
  114. choices.add ("Item " + String (i));
  115. choiceVars.add (i);
  116. }
  117. for (int i = 0; i < howMany; ++i)
  118. comps.add (new ChoicePropertyComponent (Value (Random::getSystemRandom().nextInt (12)), "Choice Property " + String (i + 1), choices, choiceVars));
  119. for (int i = 0; i < howMany; ++i)
  120. comps.add (new MultiChoicePropertyComponent (Value (Array<var>()), "Multi-Choice Property " + String (i + 1), choices, choiceVars));
  121. return comps;
  122. }
  123. //==============================================================================
  124. class PropertiesDemo : public Component,
  125. private Timer
  126. {
  127. public:
  128. PropertiesDemo()
  129. {
  130. setOpaque (true);
  131. addAndMakeVisible (concertinaPanel);
  132. {
  133. auto* panel = new PropertyPanel ("Text Editors");
  134. panel->addProperties (createTextEditors());
  135. addPanel (panel);
  136. }
  137. {
  138. auto* panel = new PropertyPanel ("Sliders");
  139. panel->addSection ("Section 1", createSliders (4), true);
  140. panel->addSection ("Section 2", createSliders (3), true);
  141. addPanel (panel);
  142. }
  143. {
  144. auto* panel = new PropertyPanel ("Choice Properties");
  145. panel->addProperties (createChoices (3));
  146. addPanel (panel);
  147. }
  148. {
  149. auto* panel = new PropertyPanel ("Buttons & Toggles");
  150. panel->addProperties (createButtons (6));
  151. addPanel (panel);
  152. }
  153. setSize (750, 650);
  154. startTimer (300);
  155. }
  156. void paint (Graphics& g) override
  157. {
  158. g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground,
  159. Colour::greyLevel (0.8f)));
  160. }
  161. void resized() override
  162. {
  163. concertinaPanel.setBounds (getLocalBounds().reduced (4));
  164. }
  165. void timerCallback() override
  166. {
  167. stopTimer();
  168. concertinaPanel.expandPanelFully (concertinaPanel.getPanel (0), true);
  169. }
  170. private:
  171. ConcertinaPanel concertinaPanel;
  172. void addPanel (PropertyPanel* panel)
  173. {
  174. concertinaPanel.addPanel (-1, panel, true);
  175. concertinaPanel.setMaximumPanelSize (panel, panel->getTotalContentHeight());
  176. }
  177. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertiesDemo)
  178. };