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.

119 lines
4.2KB

  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. struct LiveConstantDemoComponent : public Component
  20. {
  21. LiveConstantDemoComponent() {}
  22. void paint (Graphics& g) override
  23. {
  24. g.fillAll (JUCE_LIVE_CONSTANT (Colour (0xffe5e7a7)));
  25. g.setColour (JUCE_LIVE_CONSTANT (Colours::red.withAlpha (0.2f)));
  26. int blockWidth = JUCE_LIVE_CONSTANT (0x120);
  27. int blockHeight = JUCE_LIVE_CONSTANT (200);
  28. g.fillRect ((getWidth() - blockWidth) / 2, (getHeight() - blockHeight) / 2, blockWidth, blockHeight);
  29. Colour fontColour = JUCE_LIVE_CONSTANT (Colour (0xff000a55));
  30. float fontSize = JUCE_LIVE_CONSTANT (30.0f);
  31. g.setColour (fontColour);
  32. g.setFont (fontSize);
  33. g.drawFittedText (getDemoText(), getLocalBounds(), Justification::centred, 2);
  34. }
  35. static String getDemoText()
  36. {
  37. return JUCE_LIVE_CONSTANT ("Hello world!");
  38. }
  39. };
  40. //==============================================================================
  41. class LiveConstantEditorDemo : public Component,
  42. private ButtonListener
  43. {
  44. public:
  45. LiveConstantEditorDemo()
  46. : startButton ("Begin Demo")
  47. {
  48. descriptionLabel.setMinimumHorizontalScale (1.0f);
  49. descriptionLabel.setText ("This demonstrates the JUCE_LIVE_CONSTANT macro, which allows you to quickly "
  50. "adjust primitive values at runtime by just wrapping them in a macro.\n\n"
  51. "To understand what's going on in this demo, you should have a look at the "
  52. "LiveConstantDemoComponent class in LiveConstantDemo.cpp, where you can see "
  53. "the code that's invoking the demo below...",
  54. dontSendNotification);
  55. addAndMakeVisible (descriptionLabel);
  56. addAndMakeVisible (startButton);
  57. addChildComponent (demoComp);
  58. startButton.addListener (this);
  59. }
  60. void paint (Graphics& g) override
  61. {
  62. fillStandardDemoBackground (g);
  63. }
  64. void resized() override
  65. {
  66. Rectangle<int> r (getLocalBounds().reduced (10));
  67. demoComp.setBounds (r);
  68. descriptionLabel.setBounds (r.removeFromTop (200));
  69. startButton.setBounds (r.removeFromTop (22).removeFromLeft (250));
  70. demoComp.setBounds (r.withTrimmedTop (10));
  71. }
  72. private:
  73. Label descriptionLabel;
  74. TextButton startButton;
  75. LiveConstantDemoComponent demoComp;
  76. void buttonClicked (Button*) override
  77. {
  78. startButton.setVisible (false);
  79. demoComp.setVisible (true);
  80. descriptionLabel.setText ("Tweak some of the colours and values in the pop-up window to see what "
  81. "the effect of your changes would be on the component below...",
  82. dontSendNotification);
  83. }
  84. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveConstantEditorDemo)
  85. };
  86. #if ! (JUCE_IOS || JUCE_ANDROID)
  87. // This static object will register this demo type in a global list of demos..
  88. static JuceDemoType<LiveConstantEditorDemo> demo ("10 Components: Live Constants");
  89. #endif