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.

632 lines
26KB

  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: LookAndFeelDemo
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: Showcases custom look and feel 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: LookAndFeelDemo
  30. useLocalCopy: 1
  31. END_JUCE_PIP_METADATA
  32. *******************************************************************************/
  33. #pragma once
  34. #include "../Assets/DemoUtilities.h"
  35. //==============================================================================
  36. /** Custom Look And Feel subclasss.
  37. Simply override the methods you need to, anything else will be inherited from the base class.
  38. It's a good idea not to hard code your colours, use the findColour method along with appropriate
  39. ColourIds so you can set these on a per-component basis.
  40. */
  41. struct CustomLookAndFeel : public LookAndFeel_V4
  42. {
  43. void drawRoundThumb (Graphics& g, float x, float y, float diameter, Colour colour, float outlineThickness)
  44. {
  45. auto halfThickness = outlineThickness * 0.5f;
  46. Path p;
  47. p.addEllipse (x + halfThickness,
  48. y + halfThickness,
  49. diameter - outlineThickness,
  50. diameter - outlineThickness);
  51. DropShadow (Colours::black, 1, {}).drawForPath (g, p);
  52. g.setColour (colour);
  53. g.fillPath (p);
  54. g.setColour (colour.brighter());
  55. g.strokePath (p, PathStrokeType (outlineThickness));
  56. }
  57. void drawButtonBackground (Graphics& g, Button& button, const Colour& backgroundColour,
  58. bool isMouseOverButton, bool isButtonDown) override
  59. {
  60. auto baseColour = backgroundColour.withMultipliedSaturation (button.hasKeyboardFocus (true) ? 1.3f : 0.9f)
  61. .withMultipliedAlpha (button.isEnabled() ? 0.9f : 0.5f);
  62. if (isButtonDown || isMouseOverButton)
  63. baseColour = baseColour.contrasting (isButtonDown ? 0.2f : 0.1f);
  64. auto flatOnLeft = button.isConnectedOnLeft();
  65. auto flatOnRight = button.isConnectedOnRight();
  66. auto flatOnTop = button.isConnectedOnTop();
  67. auto flatOnBottom = button.isConnectedOnBottom();
  68. auto width = (float) button.getWidth() - 1.0f;
  69. auto height = (float) button.getHeight() - 1.0f;
  70. if (width > 0 && height > 0)
  71. {
  72. auto cornerSize = jmin (15.0f, jmin (width, height) * 0.45f);
  73. auto lineThickness = cornerSize * 0.1f;
  74. auto halfThickness = lineThickness * 0.5f;
  75. Path outline;
  76. outline.addRoundedRectangle (0.5f + halfThickness, 0.5f + halfThickness, width - lineThickness, height - lineThickness,
  77. cornerSize, cornerSize,
  78. ! (flatOnLeft || flatOnTop),
  79. ! (flatOnRight || flatOnTop),
  80. ! (flatOnLeft || flatOnBottom),
  81. ! (flatOnRight || flatOnBottom));
  82. auto outlineColour = button.findColour (button.getToggleState() ? TextButton::textColourOnId
  83. : TextButton::textColourOffId);
  84. g.setColour (baseColour);
  85. g.fillPath (outline);
  86. if (! button.getToggleState())
  87. {
  88. g.setColour (outlineColour);
  89. g.strokePath (outline, PathStrokeType (lineThickness));
  90. }
  91. }
  92. }
  93. void drawTickBox (Graphics& g, Component& component,
  94. float x, float y, float w, float h,
  95. bool ticked,
  96. bool isEnabled,
  97. bool isMouseOverButton,
  98. bool isButtonDown) override
  99. {
  100. auto boxSize = w * 0.7f;
  101. auto isDownOrDragging = component.isEnabled() && (component.isMouseOverOrDragging() || component.isMouseButtonDown());
  102. auto colour = component.findColour (TextButton::buttonColourId)
  103. .withMultipliedSaturation ((component.hasKeyboardFocus (false) || isDownOrDragging) ? 1.3f : 0.9f)
  104. .withMultipliedAlpha (component.isEnabled() ? 1.0f : 0.7f);
  105. drawRoundThumb (g, x, y + (h - boxSize) * 0.5f, boxSize, colour,
  106. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  107. if (ticked)
  108. {
  109. g.setColour (isEnabled ? findColour (TextButton::buttonOnColourId) : Colours::grey);
  110. auto scale = 9.0f;
  111. auto trans = AffineTransform::scale (w / scale, h / scale).translated (x - 2.5f, y + 1.0f);
  112. g.fillPath (LookAndFeel_V4::getTickShape (6.0f), trans);
  113. }
  114. }
  115. void drawLinearSliderThumb (Graphics& g, int x, int y, int width, int height,
  116. float sliderPos, float minSliderPos, float maxSliderPos,
  117. Slider::SliderStyle style, Slider& slider) override
  118. {
  119. auto sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  120. auto isDownOrDragging = slider.isEnabled() && (slider.isMouseOverOrDragging() || slider.isMouseButtonDown());
  121. auto knobColour = slider.findColour (Slider::thumbColourId)
  122. .withMultipliedSaturation ((slider.hasKeyboardFocus (false) || isDownOrDragging) ? 1.3f : 0.9f)
  123. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.7f);
  124. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  125. {
  126. float kx, ky;
  127. if (style == Slider::LinearVertical)
  128. {
  129. kx = (float) x + (float) width * 0.5f;
  130. ky = sliderPos;
  131. }
  132. else
  133. {
  134. kx = sliderPos;
  135. ky = (float) y + (float) height * 0.5f;
  136. }
  137. auto outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  138. drawRoundThumb (g,
  139. kx - sliderRadius,
  140. ky - sliderRadius,
  141. sliderRadius * 2.0f,
  142. knobColour, outlineThickness);
  143. }
  144. else
  145. {
  146. // Just call the base class for the demo
  147. LookAndFeel_V2::drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  148. }
  149. }
  150. void drawLinearSlider (Graphics& g, int x, int y, int width, int height,
  151. float sliderPos, float minSliderPos, float maxSliderPos,
  152. Slider::SliderStyle style, Slider& slider) override
  153. {
  154. g.fillAll (slider.findColour (Slider::backgroundColourId));
  155. if (style == Slider::LinearBar || style == Slider::LinearBarVertical)
  156. {
  157. Path p;
  158. if (style == Slider::LinearBarVertical)
  159. p.addRectangle ((float) x, sliderPos, (float) width, 1.0f + (float) height - sliderPos);
  160. else
  161. p.addRectangle ((float) x, (float) y, sliderPos - (float) x, (float) height);
  162. auto baseColour = slider.findColour (Slider::rotarySliderFillColourId)
  163. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f)
  164. .withMultipliedAlpha (0.8f);
  165. g.setColour (baseColour);
  166. g.fillPath (p);
  167. auto lineThickness = jmin (15.0f, (float) jmin (width, height) * 0.45f) * 0.1f;
  168. g.drawRect (slider.getLocalBounds().toFloat(), lineThickness);
  169. }
  170. else
  171. {
  172. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  173. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  174. }
  175. }
  176. void drawLinearSliderBackground (Graphics& g, int x, int y, int width, int height,
  177. float /*sliderPos*/,
  178. float /*minSliderPos*/,
  179. float /*maxSliderPos*/,
  180. const Slider::SliderStyle /*style*/, Slider& slider) override
  181. {
  182. auto sliderRadius = (float) getSliderThumbRadius (slider) - 5.0f;
  183. Path on, off;
  184. if (slider.isHorizontal())
  185. {
  186. auto iy = (float) y + (float) height * 0.5f - sliderRadius * 0.5f;
  187. Rectangle<float> r ((float) x - sliderRadius * 0.5f, iy, (float) width + sliderRadius, sliderRadius);
  188. auto onW = r.getWidth() * ((float) slider.valueToProportionOfLength (slider.getValue()));
  189. on.addRectangle (r.removeFromLeft (onW));
  190. off.addRectangle (r);
  191. }
  192. else
  193. {
  194. auto ix = (float) x + (float) width * 0.5f - sliderRadius * 0.5f;
  195. Rectangle<float> r (ix, (float) y - sliderRadius * 0.5f, sliderRadius, (float) height + sliderRadius);
  196. auto onH = r.getHeight() * ((float) slider.valueToProportionOfLength (slider.getValue()));
  197. on.addRectangle (r.removeFromBottom (onH));
  198. off.addRectangle (r);
  199. }
  200. g.setColour (slider.findColour (Slider::rotarySliderFillColourId));
  201. g.fillPath (on);
  202. g.setColour (slider.findColour (Slider::trackColourId));
  203. g.fillPath (off);
  204. }
  205. void drawRotarySlider (Graphics& g, int x, int y, int width, int height, float sliderPos,
  206. float rotaryStartAngle, float rotaryEndAngle, Slider& slider) override
  207. {
  208. auto radius = (float) jmin (width / 2, height / 2) - 2.0f;
  209. auto centreX = (float) x + (float) width * 0.5f;
  210. auto centreY = (float) y + (float) height * 0.5f;
  211. auto rx = centreX - radius;
  212. auto ry = centreY - radius;
  213. auto rw = radius * 2.0f;
  214. auto angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  215. auto isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  216. if (slider.isEnabled())
  217. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  218. else
  219. g.setColour (Colour (0x80808080));
  220. {
  221. Path filledArc;
  222. filledArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, angle, 0.0);
  223. g.fillPath (filledArc);
  224. }
  225. {
  226. auto lineThickness = jmin (15.0f, (float) jmin (width, height) * 0.45f) * 0.1f;
  227. Path outlineArc;
  228. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, 0.0);
  229. g.strokePath (outlineArc, PathStrokeType (lineThickness));
  230. }
  231. }
  232. };
  233. //==============================================================================
  234. /** Another really simple look and feel that is very flat and square.
  235. This inherits from CustomLookAndFeel above for the linear bar and slider backgrounds.
  236. */
  237. struct SquareLookAndFeel final : public CustomLookAndFeel
  238. {
  239. void drawButtonBackground (Graphics& g, Button& button, const Colour& backgroundColour,
  240. bool isMouseOverButton, bool isButtonDown) override
  241. {
  242. auto baseColour = backgroundColour.withMultipliedSaturation (button.hasKeyboardFocus (true) ? 1.3f : 0.9f)
  243. .withMultipliedAlpha (button.isEnabled() ? 0.9f : 0.5f);
  244. if (isButtonDown || isMouseOverButton)
  245. baseColour = baseColour.contrasting (isButtonDown ? 0.2f : 0.1f);
  246. auto width = (float) button.getWidth() - 1.0f;
  247. auto height = (float) button.getHeight() - 1.0f;
  248. if (width > 0 && height > 0)
  249. {
  250. g.setGradientFill (ColourGradient::vertical (baseColour, 0.0f,
  251. baseColour.darker (0.1f), height));
  252. g.fillRect (button.getLocalBounds());
  253. }
  254. }
  255. void drawTickBox (Graphics& g, Component& component,
  256. float x, float y, float w, float h,
  257. bool ticked,
  258. bool isEnabled,
  259. bool /*isMouseOverButton*/,
  260. bool /*isButtonDown*/) override
  261. {
  262. auto boxSize = w * 0.7f;
  263. auto isDownOrDragging = component.isEnabled() && (component.isMouseOverOrDragging() || component.isMouseButtonDown());
  264. auto colour = component.findColour (TextButton::buttonOnColourId)
  265. .withMultipliedSaturation ((component.hasKeyboardFocus (false) || isDownOrDragging) ? 1.3f : 0.9f)
  266. .withMultipliedAlpha (component.isEnabled() ? 1.0f : 0.7f);
  267. g.setColour (colour);
  268. Rectangle<float> r (x, y + (h - boxSize) * 0.5f, boxSize, boxSize);
  269. g.fillRect (r);
  270. if (ticked)
  271. {
  272. auto tickPath = LookAndFeel_V4::getTickShape (6.0f);
  273. g.setColour (isEnabled ? findColour (TextButton::buttonColourId) : Colours::grey);
  274. auto transform = RectanglePlacement (RectanglePlacement::centred)
  275. .getTransformToFit (tickPath.getBounds(),
  276. r.reduced (r.getHeight() * 0.05f));
  277. g.fillPath (tickPath, transform);
  278. }
  279. }
  280. void drawLinearSliderThumb (Graphics& g, int x, int y, int width, int height,
  281. float sliderPos, float minSliderPos, float maxSliderPos,
  282. Slider::SliderStyle style, Slider& slider) override
  283. {
  284. auto sliderRadius = (float) getSliderThumbRadius (slider);
  285. bool isDownOrDragging = slider.isEnabled() && (slider.isMouseOverOrDragging() || slider.isMouseButtonDown());
  286. auto knobColour = slider.findColour (Slider::rotarySliderFillColourId)
  287. .withMultipliedSaturation ((slider.hasKeyboardFocus (false) || isDownOrDragging) ? 1.3f : 0.9f)
  288. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.7f);
  289. g.setColour (knobColour);
  290. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  291. {
  292. float kx, ky;
  293. if (style == Slider::LinearVertical)
  294. {
  295. kx = (float) x + (float) width * 0.5f;
  296. ky = sliderPos;
  297. g.fillRect (Rectangle<float> (kx - sliderRadius, ky - 2.5f, sliderRadius * 2.0f, 5.0f));
  298. }
  299. else
  300. {
  301. kx = sliderPos;
  302. ky = (float) y + (float) height * 0.5f;
  303. g.fillRect (Rectangle<float> (kx - 2.5f, ky - sliderRadius, 5.0f, sliderRadius * 2.0f));
  304. }
  305. }
  306. else
  307. {
  308. // Just call the base class for the demo
  309. LookAndFeel_V2::drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  310. }
  311. }
  312. void drawRotarySlider (Graphics& g, int x, int y, int width, int height, float sliderPos,
  313. float rotaryStartAngle, float rotaryEndAngle, Slider& slider) override
  314. {
  315. auto diameter = (float) jmin (width, height) - 4.0f;
  316. auto radius = (diameter / 2.0f) * std::cos (MathConstants<float>::pi / 4.0f);
  317. auto centreX = (float) x + (float) width * 0.5f;
  318. auto centreY = (float) y + (float) height * 0.5f;
  319. auto rx = centreX - radius;
  320. auto ry = centreY - radius;
  321. auto rw = radius * 2.0f;
  322. auto angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  323. bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  324. auto baseColour = slider.isEnabled() ? slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 0.8f : 1.0f)
  325. : Colour (0x80808080);
  326. Rectangle<float> r (rx, ry, rw, rw);
  327. auto transform = AffineTransform::rotation (angle, r.getCentreX(), r.getCentreY());
  328. auto x1 = r.getTopLeft() .getX();
  329. auto y1 = r.getTopLeft() .getY();
  330. auto x2 = r.getBottomLeft().getX();
  331. auto y2 = r.getBottomLeft().getY();
  332. transform.transformPoints (x1, y1, x2, y2);
  333. g.setGradientFill (ColourGradient (baseColour, x1, y1,
  334. baseColour.darker (0.1f), x2, y2,
  335. false));
  336. Path knob;
  337. knob.addRectangle (r);
  338. g.fillPath (knob, transform);
  339. Path needle;
  340. auto r2 = r * 0.1f;
  341. needle.addRectangle (r2.withPosition ({ r.getCentreX() - (r2.getWidth() / 2.0f), r.getY() }));
  342. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  343. g.fillPath (needle, AffineTransform::rotation (angle, r.getCentreX(), r.getCentreY()));
  344. }
  345. };
  346. //==============================================================================
  347. struct LookAndFeelDemoComponent final : public Component
  348. {
  349. LookAndFeelDemoComponent()
  350. {
  351. addAndMakeVisible (rotarySlider);
  352. rotarySlider.setValue (2.5);
  353. addAndMakeVisible (verticalSlider);
  354. verticalSlider.setValue (6.2);
  355. addAndMakeVisible (barSlider);
  356. barSlider.setValue (4.5);
  357. addAndMakeVisible (incDecSlider);
  358. incDecSlider.setRange (0.0, 10.0, 1.0);
  359. incDecSlider.setIncDecButtonsMode (Slider::incDecButtonsDraggable_Horizontal);
  360. addAndMakeVisible (button1);
  361. addAndMakeVisible (button2);
  362. button2.setClickingTogglesState (true);
  363. button2.setToggleState (true, dontSendNotification);
  364. addAndMakeVisible (button3);
  365. addAndMakeVisible (button4);
  366. button4.setToggleState (true, dontSendNotification);
  367. for (int i = 0; i < 3; ++i)
  368. {
  369. auto* b = radioButtons.add (new TextButton ("Button " + String (i + 1)));
  370. addAndMakeVisible (b);
  371. b->setRadioGroupId (42);
  372. b->setClickingTogglesState (true);
  373. switch (i)
  374. {
  375. case 0: b->setConnectedEdges (Button::ConnectedOnRight); break;
  376. case 1: b->setConnectedEdges (Button::ConnectedOnRight + Button::ConnectedOnLeft); break;
  377. case 2: b->setConnectedEdges (Button::ConnectedOnLeft); break;
  378. default: break;
  379. }
  380. }
  381. radioButtons.getUnchecked (2)->setToggleState (true, dontSendNotification);
  382. }
  383. void resized() override
  384. {
  385. auto area = getLocalBounds().reduced (10);
  386. auto row = area.removeFromTop (100);
  387. rotarySlider .setBounds (row.removeFromLeft (100).reduced (5));
  388. verticalSlider.setBounds (row.removeFromLeft (100).reduced (5));
  389. barSlider .setBounds (row.removeFromLeft (100).reduced (5, 25));
  390. incDecSlider .setBounds (row.removeFromLeft (100).reduced (5, 28));
  391. row = area.removeFromTop (100);
  392. button1.setBounds (row.removeFromLeft (100).reduced (5));
  393. auto row2 = row.removeFromTop (row.getHeight() / 2).reduced (0, 10);
  394. button2.setBounds (row2.removeFromLeft (100).reduced (5, 0));
  395. button3.setBounds (row2.removeFromLeft (100).reduced (5, 0));
  396. button4.setBounds (row2.removeFromLeft (100).reduced (5, 0));
  397. row2 = (row.removeFromTop (row2.getHeight() + 20).reduced (5, 10));
  398. for (auto* b : radioButtons)
  399. b->setBounds (row2.removeFromLeft (100));
  400. }
  401. Slider rotarySlider { Slider::RotaryHorizontalVerticalDrag, Slider::NoTextBox},
  402. verticalSlider { Slider::LinearVertical, Slider::NoTextBox },
  403. barSlider { Slider::LinearBar, Slider::NoTextBox },
  404. incDecSlider { Slider::IncDecButtons, Slider::TextBoxBelow };
  405. TextButton button1 { "Hello World!" },
  406. button2 { "Hello World!" },
  407. button3 { "Hello World!" };
  408. ToggleButton button4 { "Toggle Me" };
  409. OwnedArray<TextButton> radioButtons;
  410. };
  411. //==============================================================================
  412. class LookAndFeelDemo final : public Component
  413. {
  414. public:
  415. LookAndFeelDemo()
  416. {
  417. descriptionLabel.setMinimumHorizontalScale (1.0f);
  418. descriptionLabel.setText ("This demonstrates how to create a custom look and feel by overriding only the desired methods.\n\n"
  419. "Components can have their look and feel individually assigned or they will inherit it from their parent. "
  420. "Colours work in a similar way, they can be set for individual components or a look and feel as a whole.",
  421. dontSendNotification);
  422. addAndMakeVisible (descriptionLabel);
  423. addAndMakeVisible (lafBox);
  424. addAndMakeVisible (demoComp);
  425. addLookAndFeel (new LookAndFeel_V1(), "LookAndFeel_V1");
  426. addLookAndFeel (new LookAndFeel_V2(), "LookAndFeel_V2");
  427. addLookAndFeel (new LookAndFeel_V3(), "LookAndFeel_V3");
  428. addLookAndFeel (new LookAndFeel_V4(), "LookAndFeel_V4 (Dark)");
  429. addLookAndFeel (new LookAndFeel_V4 (LookAndFeel_V4::getMidnightColourScheme()), "LookAndFeel_V4 (Midnight)");
  430. addLookAndFeel (new LookAndFeel_V4 (LookAndFeel_V4::getGreyColourScheme()), "LookAndFeel_V4 (Grey)");
  431. addLookAndFeel (new LookAndFeel_V4 (LookAndFeel_V4::getLightColourScheme()), "LookAndFeel_V4 (Light)");
  432. auto* claf = new CustomLookAndFeel();
  433. addLookAndFeel (claf, "Custom Look And Feel");
  434. setupCustomLookAndFeelColours (*claf);
  435. auto* slaf = new SquareLookAndFeel();
  436. addLookAndFeel (slaf, "Square Look And Feel");
  437. setupSquareLookAndFeelColours (*slaf);
  438. lafBox.onChange = [this] { setAllLookAndFeels (lookAndFeels[lafBox.getSelectedItemIndex()]); };
  439. lafBox.setSelectedItemIndex (3);
  440. addAndMakeVisible (randomButton);
  441. randomButton.onClick = [this] { lafBox.setSelectedItemIndex (Random().nextInt (lafBox.getNumItems())); };
  442. setSize (500, 500);
  443. }
  444. void paint (Graphics& g) override
  445. {
  446. g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground,
  447. Colour::greyLevel (0.4f)));
  448. }
  449. void resized() override
  450. {
  451. auto r = getLocalBounds().reduced (10);
  452. descriptionLabel.setBounds (r.removeFromTop (150));
  453. lafBox .setBounds (r.removeFromTop (22).removeFromLeft (250));
  454. randomButton .setBounds (lafBox.getBounds().withX (lafBox.getRight() + 20).withWidth (140));
  455. demoComp .setBounds (r.withTrimmedTop (10));
  456. }
  457. private:
  458. Label descriptionLabel;
  459. ComboBox lafBox;
  460. TextButton randomButton { "Assign Randomly" };
  461. OwnedArray<LookAndFeel> lookAndFeels;
  462. LookAndFeelDemoComponent demoComp;
  463. void addLookAndFeel (LookAndFeel* laf, const String& name)
  464. {
  465. lookAndFeels.add (laf);
  466. lafBox.addItem (name, lafBox.getNumItems() + 1);
  467. }
  468. void setupCustomLookAndFeelColours (LookAndFeel& laf)
  469. {
  470. laf.setColour (Slider::thumbColourId, Colour::greyLevel (0.95f));
  471. laf.setColour (Slider::textBoxOutlineColourId, Colours::transparentWhite);
  472. laf.setColour (Slider::rotarySliderFillColourId, Colour (0xff00b5f6));
  473. laf.setColour (Slider::rotarySliderOutlineColourId, Colours::white);
  474. laf.setColour (TextButton::buttonColourId, Colours::white);
  475. laf.setColour (TextButton::textColourOffId, Colour (0xff00b5f6));
  476. laf.setColour (TextButton::buttonOnColourId, laf.findColour (TextButton::textColourOffId));
  477. laf.setColour (TextButton::textColourOnId, laf.findColour (TextButton::buttonColourId));
  478. }
  479. void setupSquareLookAndFeelColours (LookAndFeel& laf)
  480. {
  481. auto baseColour = Colours::red;
  482. laf.setColour (Slider::thumbColourId, Colour::greyLevel (0.95f));
  483. laf.setColour (Slider::textBoxOutlineColourId, Colours::transparentWhite);
  484. laf.setColour (Slider::rotarySliderFillColourId, baseColour);
  485. laf.setColour (Slider::rotarySliderOutlineColourId, Colours::white);
  486. laf.setColour (Slider::trackColourId, Colours::black);
  487. laf.setColour (TextButton::buttonColourId, Colours::white);
  488. laf.setColour (TextButton::textColourOffId, baseColour);
  489. laf.setColour (TextButton::buttonOnColourId, laf.findColour (TextButton::textColourOffId));
  490. laf.setColour (TextButton::textColourOnId, laf.findColour (TextButton::buttonColourId));
  491. }
  492. void setAllLookAndFeels (LookAndFeel* laf)
  493. {
  494. for (auto* child : demoComp.getChildren())
  495. child->setLookAndFeel (laf);
  496. }
  497. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LookAndFeelDemo)
  498. };