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.

134 lines
4.8KB

  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: LiveConstantDemo
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: Demonstrates the live constant macro.
  24. dependencies: juce_core, juce_data_structures, juce_events, juce_graphics,
  25. juce_gui_basics, juce_gui_extra
  26. exporters: xcode_mac, vs2022, linux_make, androidstudio, xcode_iphone
  27. moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
  28. type: Component
  29. mainClass: LiveConstantDemo
  30. useLocalCopy: 1
  31. END_JUCE_PIP_METADATA
  32. *******************************************************************************/
  33. #pragma once
  34. #include "../Assets/DemoUtilities.h"
  35. //==============================================================================
  36. struct LiveConstantDemoComponent final : public Component
  37. {
  38. LiveConstantDemoComponent() {}
  39. void paint (Graphics& g) override
  40. {
  41. g.fillAll (JUCE_LIVE_CONSTANT (Colour (0xffe5e7a7)));
  42. g.setColour (JUCE_LIVE_CONSTANT (Colours::red.withAlpha (0.2f)));
  43. auto blockWidth = JUCE_LIVE_CONSTANT (0x120);
  44. auto blockHeight = JUCE_LIVE_CONSTANT (200);
  45. g.fillRect ((getWidth() - blockWidth) / 2, (getHeight() - blockHeight) / 2, blockWidth, blockHeight);
  46. auto fontColour = JUCE_LIVE_CONSTANT (Colour (0xff000a55));
  47. auto fontSize = JUCE_LIVE_CONSTANT (30.0f);
  48. g.setColour (fontColour);
  49. g.setFont (fontSize);
  50. g.drawFittedText (getDemoText(), getLocalBounds(), Justification::centred, 2);
  51. }
  52. static String getDemoText()
  53. {
  54. return JUCE_LIVE_CONSTANT ("Hello world!");
  55. }
  56. };
  57. //==============================================================================
  58. class LiveConstantDemo final : public Component
  59. {
  60. public:
  61. LiveConstantDemo()
  62. {
  63. descriptionLabel.setMinimumHorizontalScale (1.0f);
  64. descriptionLabel.setText ("This demonstrates the JUCE_LIVE_CONSTANT macro, which allows you to quickly "
  65. "adjust primitive values at runtime by just wrapping them in a macro.\n\n"
  66. "Editing JUCE_LIVE_CONSTANT values is only enabled in debug builds.\n\n"
  67. "To understand what's going on in this demo, you should have a look at the "
  68. "LiveConstantDemoComponent class, where you can see the code that's invoking the demo below.",
  69. dontSendNotification);
  70. addAndMakeVisible (descriptionLabel);
  71. addAndMakeVisible (startButton);
  72. addChildComponent (demoComp);
  73. startButton.onClick = [this] { start(); };
  74. setSize (500, 500);
  75. }
  76. void paint (Graphics& g) override
  77. {
  78. g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground));
  79. }
  80. void resized() override
  81. {
  82. auto r = getLocalBounds().reduced (10);
  83. descriptionLabel.setBounds (r.removeFromTop (200));
  84. startButton .setBounds (r.removeFromTop (22).removeFromLeft (250));
  85. demoComp .setBounds (r.withTrimmedTop (10));
  86. }
  87. void start()
  88. {
  89. startButton.setVisible (false);
  90. demoComp .setVisible (true);
  91. descriptionLabel.setText ("Tweak some of the colours and values in the pop-up window to see what "
  92. "the effect of your changes would be on the component below...",
  93. dontSendNotification);
  94. }
  95. private:
  96. Label descriptionLabel;
  97. TextButton startButton { "Begin Demo" };
  98. LiveConstantDemoComponent demoComp;
  99. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveConstantDemo)
  100. };