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.

630 lines
26KB

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