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.

615 lines
26KB

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