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.

121 lines
4.2KB

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