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.

120 lines
4.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-12 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "../JuceDemoHeader.h"
  19. //==============================================================================
  20. struct LiveConstantDemoComponent : public Component
  21. {
  22. LiveConstantDemoComponent() {}
  23. void paint (Graphics& g)
  24. {
  25. g.fillAll (JUCE_LIVE_CONSTANT (Colour (0xffe5e7a7)));
  26. g.setColour (JUCE_LIVE_CONSTANT (Colours::red.withAlpha (0.2f)));
  27. int blockWidth = JUCE_LIVE_CONSTANT (0x120);
  28. int blockHeight = JUCE_LIVE_CONSTANT (200);
  29. g.fillRect ((getWidth() - blockWidth) / 2, (getHeight() - blockHeight) / 2, blockWidth, blockHeight);
  30. Colour fontColour = JUCE_LIVE_CONSTANT (Colour (0xff000a55));
  31. float fontSize = JUCE_LIVE_CONSTANT (30.0f);
  32. g.setColour (fontColour);
  33. g.setFont (fontSize);
  34. g.drawFittedText (getDemoText(), getLocalBounds(), Justification::centred, 2);
  35. }
  36. static String getDemoText()
  37. {
  38. return JUCE_LIVE_CONSTANT ("Hello world!");
  39. }
  40. };
  41. //==============================================================================
  42. class LiveConstantEditorDemo : public Component,
  43. private ButtonListener
  44. {
  45. public:
  46. LiveConstantEditorDemo()
  47. : startButton ("Begin Demo")
  48. {
  49. descriptionLabel.setMinimumHorizontalScale (1.0f);
  50. descriptionLabel.setText ("This demonstrates the JUCE_LIVE_CONSTANT macro, which allows you to quickly "
  51. "adjust primitive values at runtime by just wrapping them in a macro.\n\n"
  52. "To understand what's going on in this demo, you should have a look at the "
  53. "LiveConstantDemoComponent class in LiveConstantDemo.cpp, where you can see "
  54. "the code that's invoking the demo below...",
  55. dontSendNotification);
  56. addAndMakeVisible (descriptionLabel);
  57. addAndMakeVisible (startButton);
  58. addChildComponent (demoComp);
  59. startButton.addListener (this);
  60. }
  61. void paint (Graphics& g) override
  62. {
  63. fillTiledBackground (g);
  64. }
  65. void resized() override
  66. {
  67. Rectangle<int> r (getLocalBounds().reduced (10));
  68. demoComp.setBounds (r);
  69. descriptionLabel.setBounds (r.removeFromTop (200));
  70. startButton.setBounds (r.removeFromTop (22).removeFromLeft (250));
  71. demoComp.setBounds (r.withTrimmedTop (10));
  72. }
  73. private:
  74. Label descriptionLabel;
  75. TextButton startButton;
  76. LiveConstantDemoComponent demoComp;
  77. void buttonClicked (Button*) override
  78. {
  79. startButton.setVisible (false);
  80. demoComp.setVisible (true);
  81. descriptionLabel.setText ("Tweak some of the colours and values in the pop-up window to see what "
  82. "the effect of your changes would be on the component below...",
  83. dontSendNotification);
  84. }
  85. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveConstantEditorDemo);
  86. };
  87. #if ! (JUCE_IOS || JUCE_ANDROID)
  88. // This static object will register this demo type in a global list of demos..
  89. static JuceDemoType<LiveConstantEditorDemo> demo ("10 Components: Live Constants");
  90. #endif