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.

232 lines
8.3KB

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