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.

1468 lines
67KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. Colour LookAndFeel_V4::ColourScheme::getUIColour (UIColour index) const noexcept
  22. {
  23. if (isPositiveAndBelow (index, numColours))
  24. return palette[index];
  25. jassertfalse;
  26. return {};
  27. }
  28. void LookAndFeel_V4::ColourScheme::setUIColour (UIColour index, Colour newColour) noexcept
  29. {
  30. if (isPositiveAndBelow (index, numColours))
  31. palette[index] = newColour;
  32. else
  33. jassertfalse;
  34. }
  35. bool LookAndFeel_V4::ColourScheme::operator== (const ColourScheme& other) const noexcept
  36. {
  37. for (auto i = 0; i < numColours; ++i)
  38. if (palette[i] != other.palette[i])
  39. return false;
  40. return true;
  41. }
  42. bool LookAndFeel_V4::ColourScheme::operator!= (const ColourScheme& other) const noexcept
  43. {
  44. return ! operator== (other);
  45. }
  46. //==============================================================================
  47. LookAndFeel_V4::LookAndFeel_V4() : currentColourScheme (getDarkColourScheme())
  48. {
  49. initialiseColours();
  50. }
  51. LookAndFeel_V4::LookAndFeel_V4 (ColourScheme scheme) : currentColourScheme (scheme)
  52. {
  53. initialiseColours();
  54. }
  55. LookAndFeel_V4::~LookAndFeel_V4() {}
  56. //==============================================================================
  57. void LookAndFeel_V4::setColourScheme (ColourScheme newColourScheme)
  58. {
  59. currentColourScheme = newColourScheme;
  60. initialiseColours();
  61. }
  62. LookAndFeel_V4::ColourScheme LookAndFeel_V4::getDarkColourScheme()
  63. {
  64. return { 0xff323e44, 0xff263238, 0xff323e44,
  65. 0xff8e989b, 0xffffffff, 0xff42a2c8,
  66. 0xffffffff, 0xff181f22, 0xffffffff };
  67. }
  68. LookAndFeel_V4::ColourScheme LookAndFeel_V4::getMidnightColourScheme()
  69. {
  70. return { 0xff2f2f3a, 0xff191926, 0xffd0d0d0,
  71. 0xff66667c, 0xc8ffffff, 0xffd8d8d8,
  72. 0xffffffff, 0xff606073, 0xff000000 };
  73. }
  74. LookAndFeel_V4::ColourScheme LookAndFeel_V4::getGreyColourScheme()
  75. {
  76. return { 0xff505050, 0xff424242, 0xff606060,
  77. 0xffa6a6a6, 0xffffffff, 0xff21ba90,
  78. 0xff000000, 0xffffffff, 0xffffffff };
  79. }
  80. LookAndFeel_V4::ColourScheme LookAndFeel_V4::getLightColourScheme()
  81. {
  82. return { 0xffefefef, 0xffffffff, 0xffffffff,
  83. 0xffdddddd, 0xff000000, 0xffa9a9a9,
  84. 0xffffffff, 0xff42a2c8, 0xff000000 };
  85. }
  86. //==============================================================================
  87. class LookAndFeel_V4_DocumentWindowButton : public Button
  88. {
  89. public:
  90. LookAndFeel_V4_DocumentWindowButton (const String& name, Colour c, const Path& normal, const Path& toggled)
  91. : Button (name), colour (c), normalShape (normal), toggledShape (toggled)
  92. {
  93. }
  94. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) override
  95. {
  96. auto background = Colours::grey;
  97. if (auto* rw = findParentComponentOfClass<ResizableWindow>())
  98. if (auto lf = dynamic_cast<LookAndFeel_V4*> (&rw->getLookAndFeel()))
  99. background = lf->getCurrentColourScheme().getUIColour (LookAndFeel_V4::ColourScheme::widgetBackground);
  100. g.fillAll (background);
  101. g.setColour ((! isEnabled() || isButtonDown) ? colour.withAlpha (0.6f)
  102. : colour);
  103. if (isMouseOverButton)
  104. {
  105. g.fillAll();
  106. g.setColour (background);
  107. }
  108. auto& p = getToggleState() ? toggledShape : normalShape;
  109. auto reducedRect = Justification (Justification::centred)
  110. .appliedToRectangle (Rectangle<int> (getHeight(), getHeight()), getLocalBounds())
  111. .toFloat()
  112. .reduced (getHeight() * 0.3f);
  113. g.fillPath (p, p.getTransformToScaleToFit (reducedRect, true));
  114. }
  115. private:
  116. Colour colour;
  117. Path normalShape, toggledShape;
  118. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LookAndFeel_V4_DocumentWindowButton)
  119. };
  120. Button* LookAndFeel_V4::createDocumentWindowButton (int buttonType)
  121. {
  122. Path shape;
  123. auto crossThickness = 0.15f;
  124. if (buttonType == DocumentWindow::closeButton)
  125. {
  126. shape.addLineSegment ({ 0.0f, 0.0f, 1.0f, 1.0f }, crossThickness);
  127. shape.addLineSegment ({ 1.0f, 0.0f, 0.0f, 1.0f }, crossThickness);
  128. return new LookAndFeel_V4_DocumentWindowButton ("close", Colour (0xff9A131D), shape, shape);
  129. }
  130. if (buttonType == DocumentWindow::minimiseButton)
  131. {
  132. shape.addLineSegment ({ 0.0f, 0.5f, 1.0f, 0.5f }, crossThickness);
  133. return new LookAndFeel_V4_DocumentWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  134. }
  135. if (buttonType == DocumentWindow::maximiseButton)
  136. {
  137. shape.addLineSegment ({ 0.5f, 0.0f, 0.5f, 1.0f }, crossThickness);
  138. shape.addLineSegment ({ 0.0f, 0.5f, 1.0f, 0.5f }, crossThickness);
  139. Path fullscreenShape;
  140. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  141. fullscreenShape.lineTo (0.0f, 100.0f);
  142. fullscreenShape.lineTo (0.0f, 0.0f);
  143. fullscreenShape.lineTo (100.0f, 0.0f);
  144. fullscreenShape.lineTo (100.0f, 45.0f);
  145. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  146. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  147. return new LookAndFeel_V4_DocumentWindowButton ("maximise", Colour (0xff0A830A), shape, fullscreenShape);
  148. }
  149. jassertfalse;
  150. return nullptr;
  151. }
  152. void LookAndFeel_V4::positionDocumentWindowButtons (DocumentWindow&,
  153. int titleBarX, int titleBarY,
  154. int titleBarW, int titleBarH,
  155. Button* minimiseButton,
  156. Button* maximiseButton,
  157. Button* closeButton,
  158. bool positionTitleBarButtonsOnLeft)
  159. {
  160. titleBarH = jmin (titleBarH, titleBarH - titleBarY);
  161. auto buttonW = static_cast<int> (titleBarH * 1.2);
  162. auto x = positionTitleBarButtonsOnLeft ? titleBarX
  163. : titleBarX + titleBarW - buttonW;
  164. if (closeButton != nullptr)
  165. {
  166. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  167. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  168. }
  169. if (positionTitleBarButtonsOnLeft)
  170. std::swap (minimiseButton, maximiseButton);
  171. if (maximiseButton != nullptr)
  172. {
  173. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  174. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  175. }
  176. if (minimiseButton != nullptr)
  177. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  178. }
  179. void LookAndFeel_V4::drawDocumentWindowTitleBar (DocumentWindow& window, Graphics& g,
  180. int w, int h, int titleSpaceX, int titleSpaceW,
  181. const Image* icon, bool drawTitleTextOnLeft)
  182. {
  183. if (w * h == 0)
  184. return;
  185. auto isActive = window.isActiveWindow();
  186. g.setColour (getCurrentColourScheme().getUIColour (ColourScheme::widgetBackground));
  187. g.fillAll();
  188. Font font (h * 0.65f, Font::plain);
  189. g.setFont (font);
  190. auto textW = font.getStringWidth (window.getName());
  191. auto iconW = 0;
  192. auto iconH = 0;
  193. if (icon != nullptr)
  194. {
  195. iconH = static_cast<int> (font.getHeight());
  196. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  197. }
  198. textW = jmin (titleSpaceW, textW + iconW);
  199. auto textX = drawTitleTextOnLeft ? titleSpaceX
  200. : jmax (titleSpaceX, (w - textW) / 2);
  201. if (textX + textW > titleSpaceX + titleSpaceW)
  202. textX = titleSpaceX + titleSpaceW - textW;
  203. if (icon != nullptr)
  204. {
  205. g.setOpacity (isActive ? 1.0f : 0.6f);
  206. g.drawImageWithin (*icon, textX, (h - iconH) / 2, iconW, iconH,
  207. RectanglePlacement::centred, false);
  208. textX += iconW;
  209. textW -= iconW;
  210. }
  211. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  212. g.setColour (window.findColour (DocumentWindow::textColourId));
  213. else
  214. g.setColour (getCurrentColourScheme().getUIColour (ColourScheme::defaultText));
  215. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  216. }
  217. //==============================================================================
  218. void LookAndFeel_V4::drawButtonBackground (Graphics& g,
  219. Button& button,
  220. const Colour& backgroundColour,
  221. bool isMouseOverButton,
  222. bool isButtonDown)
  223. {
  224. auto cornerSize = 6.0f;
  225. auto bounds = button.getLocalBounds().toFloat().reduced (0.5f, 0.5f);
  226. auto baseColour = backgroundColour.withMultipliedSaturation (button.hasKeyboardFocus (true) ? 1.3f : 0.9f)
  227. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f);
  228. if (isButtonDown || isMouseOverButton)
  229. baseColour = baseColour.contrasting (isButtonDown ? 0.2f : 0.05f);
  230. g.setColour (baseColour);
  231. if (button.isConnectedOnLeft() || button.isConnectedOnRight())
  232. {
  233. Path path;
  234. path.addRoundedRectangle (bounds.getX(), bounds.getY(),
  235. bounds.getWidth(), bounds.getHeight(),
  236. cornerSize, cornerSize,
  237. ! button.isConnectedOnLeft(),
  238. ! button.isConnectedOnRight(),
  239. ! button.isConnectedOnLeft(),
  240. ! button.isConnectedOnRight());
  241. g.fillPath (path);
  242. g.setColour (button.findColour (ComboBox::outlineColourId));
  243. g.strokePath (path, PathStrokeType (1.0f));
  244. }
  245. else
  246. {
  247. g.fillRoundedRectangle (bounds, cornerSize);
  248. g.setColour (button.findColour (ComboBox::outlineColourId));
  249. g.drawRoundedRectangle (bounds, cornerSize, 1.0f);
  250. }
  251. }
  252. void LookAndFeel_V4::drawToggleButton (Graphics& g, ToggleButton& button,
  253. bool isMouseOverButton, bool isButtonDown)
  254. {
  255. auto fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  256. auto tickWidth = fontSize * 1.1f;
  257. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  258. tickWidth, tickWidth,
  259. button.getToggleState(),
  260. button.isEnabled(),
  261. isMouseOverButton,
  262. isButtonDown);
  263. g.setColour (button.findColour (ToggleButton::textColourId));
  264. g.setFont (fontSize);
  265. if (! button.isEnabled())
  266. g.setOpacity (0.5f);
  267. g.drawFittedText (button.getButtonText(),
  268. button.getLocalBounds().withTrimmedLeft (roundToInt (tickWidth) + 10)
  269. .withTrimmedRight (2),
  270. Justification::centredLeft, 10);
  271. }
  272. void LookAndFeel_V4::drawTickBox (Graphics& g, Component& component,
  273. float x, float y, float w, float h,
  274. const bool ticked,
  275. const bool isEnabled,
  276. const bool isMouseOverButton,
  277. const bool isButtonDown)
  278. {
  279. ignoreUnused (isEnabled, isMouseOverButton, isButtonDown);
  280. Rectangle<float> tickBounds (x, y, w, h);
  281. g.setColour (component.findColour (ToggleButton::tickDisabledColourId));
  282. g.drawRoundedRectangle (tickBounds, 4.0f, 1.0f);
  283. if (ticked)
  284. {
  285. g.setColour (component.findColour (ToggleButton::tickColourId));
  286. auto tick = getTickShape (0.75f);
  287. g.fillPath (tick, tick.getTransformToScaleToFit (tickBounds.reduced (4, 5).toFloat(), false));
  288. }
  289. }
  290. void LookAndFeel_V4::changeToggleButtonWidthToFitText (ToggleButton& button)
  291. {
  292. auto fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  293. auto tickWidth = fontSize * 1.1f;
  294. Font font (fontSize);
  295. button.setSize (font.getStringWidth (button.getButtonText()) + roundToInt (tickWidth) + 14, button.getHeight());
  296. }
  297. //==============================================================================
  298. AlertWindow* LookAndFeel_V4::createAlertWindow (const String& title, const String& message,
  299. const String& button1, const String& button2, const String& button3,
  300. AlertWindow::AlertIconType iconType,
  301. int numButtons, Component* associatedComponent)
  302. {
  303. auto boundsOffset = 50;
  304. auto* aw = LookAndFeel_V2::createAlertWindow (title, message, button1, button2, button3,
  305. iconType, numButtons, associatedComponent);
  306. auto bounds = aw->getBounds();
  307. bounds = bounds.withSizeKeepingCentre (bounds.getWidth() + boundsOffset, bounds.getHeight() + boundsOffset);
  308. aw->setBounds (bounds);
  309. for (auto* child : aw->getChildren())
  310. if (auto* button = dynamic_cast<TextButton*> (child))
  311. button->setBounds (button->getBounds() + Point<int> (25, 40));
  312. return aw;
  313. }
  314. void LookAndFeel_V4::drawAlertBox (Graphics& g, AlertWindow& alert,
  315. const Rectangle<int>& textArea, TextLayout& textLayout)
  316. {
  317. auto cornerSize = 4.0f;
  318. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  319. g.drawRoundedRectangle (alert.getLocalBounds().toFloat(), cornerSize, 2.0f);
  320. auto bounds = alert.getLocalBounds().reduced (1);
  321. g.reduceClipRegion (bounds);
  322. g.setColour (alert.findColour (AlertWindow::backgroundColourId));
  323. g.fillRoundedRectangle (bounds.toFloat(), cornerSize);
  324. auto iconSpaceUsed = 0;
  325. auto iconWidth = 80;
  326. auto iconSize = jmin (iconWidth + 50, bounds.getHeight() + 20);
  327. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  328. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  329. Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  330. iconSize, iconSize);
  331. if (alert.getAlertType() != AlertWindow::NoIcon)
  332. {
  333. Path icon;
  334. char character;
  335. uint32 colour;
  336. if (alert.getAlertType() == AlertWindow::WarningIcon)
  337. {
  338. character = '!';
  339. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  340. static_cast<float> (iconRect.getRight()), static_cast<float> (iconRect.getBottom()),
  341. static_cast<float> (iconRect.getX()), static_cast<float> (iconRect.getBottom()));
  342. icon = icon.createPathWithRoundedCorners (5.0f);
  343. colour = 0x66ff2a00;
  344. }
  345. else
  346. {
  347. colour = Colour (0xff00b0b9).withAlpha (0.4f).getARGB();
  348. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  349. icon.addEllipse (iconRect.toFloat());
  350. }
  351. GlyphArrangement ga;
  352. ga.addFittedText ({ iconRect.getHeight() * 0.9f, Font::bold },
  353. String::charToString ((juce_wchar) (uint8) character),
  354. static_cast<float> (iconRect.getX()), static_cast<float> (iconRect.getY()),
  355. static_cast<float> (iconRect.getWidth()), static_cast<float> (iconRect.getHeight()),
  356. Justification::centred, false);
  357. ga.createPath (icon);
  358. icon.setUsingNonZeroWinding (false);
  359. g.setColour (Colour (colour));
  360. g.fillPath (icon);
  361. iconSpaceUsed = iconWidth;
  362. }
  363. g.setColour (alert.findColour (AlertWindow::textColourId));
  364. Rectangle<int> alertBounds (bounds.getX() + iconSpaceUsed, 30,
  365. bounds.getWidth(), bounds.getHeight() - getAlertWindowButtonHeight() - 20);
  366. textLayout.draw (g, alertBounds.toFloat());
  367. }
  368. int LookAndFeel_V4::getAlertWindowButtonHeight() { return 40; }
  369. Font LookAndFeel_V4::getAlertWindowTitleFont() { return { 18.0f, Font::bold }; }
  370. Font LookAndFeel_V4::getAlertWindowMessageFont() { return { 16.0f }; }
  371. Font LookAndFeel_V4::getAlertWindowFont() { return { 14.0f }; }
  372. //==============================================================================
  373. void LookAndFeel_V4::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  374. int width, int height, double progress, const String& textToShow)
  375. {
  376. if (width == height)
  377. drawCircularProgressBar (g, progressBar, textToShow);
  378. else
  379. drawLinearProgressBar (g, progressBar, width, height, progress, textToShow);
  380. }
  381. void LookAndFeel_V4::drawLinearProgressBar (Graphics& g, ProgressBar& progressBar,
  382. int width, int height,
  383. double progress, const String& textToShow)
  384. {
  385. auto background = progressBar.findColour (ProgressBar::backgroundColourId);
  386. auto foreground = progressBar.findColour (ProgressBar::foregroundColourId);
  387. auto barBounds = progressBar.getLocalBounds().toFloat();
  388. g.setColour (background);
  389. g.fillRoundedRectangle (barBounds, progressBar.getHeight() * 0.5f);
  390. if (progress >= 0.0f && progress <= 1.0f)
  391. {
  392. Path p;
  393. p.addRoundedRectangle (barBounds, progressBar.getHeight() * 0.5f);
  394. g.reduceClipRegion (p);
  395. barBounds.setWidth (barBounds.getWidth() * (float) progress);
  396. g.setColour (foreground);
  397. g.fillRoundedRectangle (barBounds, progressBar.getHeight() * 0.5f);
  398. }
  399. else
  400. {
  401. // spinning bar..
  402. g.setColour (background);
  403. auto stripeWidth = height * 2;
  404. auto position = static_cast<int> (Time::getMillisecondCounter() / 15) % stripeWidth;
  405. Path p;
  406. for (auto x = static_cast<float> (-position); x < width + stripeWidth; x += stripeWidth)
  407. p.addQuadrilateral (x, 0.0f,
  408. x + stripeWidth * 0.5f, 0.0f,
  409. x, static_cast<float> (height),
  410. x - stripeWidth * 0.5f, static_cast<float> (height));
  411. Image im (Image::ARGB, width, height, true);
  412. {
  413. Graphics g2 (im);
  414. g2.setColour (foreground);
  415. g2.fillRoundedRectangle (barBounds, progressBar.getHeight() * 0.5f);
  416. }
  417. g.setTiledImageFill (im, 0, 0, 0.85f);
  418. g.fillPath (p);
  419. }
  420. if (textToShow.isNotEmpty())
  421. {
  422. g.setColour (Colour::contrasting (background, foreground));
  423. g.setFont (height * 0.6f);
  424. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  425. }
  426. }
  427. void LookAndFeel_V4::drawCircularProgressBar (Graphics& g, ProgressBar& progressBar, const String& progressText)
  428. {
  429. auto background = progressBar.findColour (ProgressBar::backgroundColourId);
  430. auto foreground = progressBar.findColour (ProgressBar::foregroundColourId);
  431. auto barBounds = progressBar.getLocalBounds().reduced (2, 2).toFloat();
  432. auto rotationInDegrees = static_cast<float> ((Time::getMillisecondCounter() / 10) % 360);
  433. auto normalisedRotation = rotationInDegrees / 360.0f;
  434. auto rotationOffset = 22.5f;
  435. auto maxRotation = 315.0f;
  436. auto startInDegrees = rotationInDegrees;
  437. auto endInDegrees = startInDegrees + rotationOffset;
  438. if (normalisedRotation >= 0.25f && normalisedRotation < 0.5f)
  439. {
  440. auto rescaledRotation = (normalisedRotation * 4.0f) - 1.0f;
  441. endInDegrees = startInDegrees + rotationOffset + (maxRotation * rescaledRotation);
  442. }
  443. else if (normalisedRotation >= 0.5f && normalisedRotation <= 1.0f)
  444. {
  445. endInDegrees = startInDegrees + rotationOffset + maxRotation;
  446. auto rescaledRotation = 1.0f - ((normalisedRotation * 2.0f) - 1.0f);
  447. startInDegrees = endInDegrees - rotationOffset - (maxRotation * rescaledRotation);
  448. }
  449. g.setColour (background);
  450. Path arcPath2;
  451. arcPath2.addCentredArc (barBounds.getCentreX(),
  452. barBounds.getCentreY(),
  453. barBounds.getWidth() * 0.5f,
  454. barBounds.getHeight() * 0.5f, 0.0f,
  455. 0.0f,
  456. MathConstants<float>::twoPi,
  457. true);
  458. g.strokePath (arcPath2, PathStrokeType (4.0f));
  459. g.setColour (foreground);
  460. Path arcPath;
  461. arcPath.addCentredArc (barBounds.getCentreX(),
  462. barBounds.getCentreY(),
  463. barBounds.getWidth() * 0.5f,
  464. barBounds.getHeight() * 0.5f,
  465. 0.0f,
  466. degreesToRadians (startInDegrees),
  467. degreesToRadians (endInDegrees),
  468. true);
  469. arcPath.applyTransform (AffineTransform::rotation (normalisedRotation * MathConstants<float>::pi * 2.25f, barBounds.getCentreX(), barBounds.getCentreY()));
  470. g.strokePath (arcPath, PathStrokeType (4.0f));
  471. if (progressText.isNotEmpty())
  472. {
  473. g.setColour (progressBar.findColour (TextButton::textColourOffId));
  474. g.setFont ({ 12.0f, Font::italic });
  475. g.drawText (progressText, barBounds, Justification::centred, false);
  476. }
  477. }
  478. //==============================================================================
  479. int LookAndFeel_V4::getDefaultScrollbarWidth()
  480. {
  481. return 8;
  482. }
  483. void LookAndFeel_V4::drawScrollbar (Graphics& g, ScrollBar& scrollbar, int x, int y, int width, int height,
  484. bool isScrollbarVertical, int thumbStartPosition, int thumbSize, bool isMouseOver, bool isMouseDown)
  485. {
  486. ignoreUnused (isMouseDown);
  487. Rectangle<int> thumbBounds;
  488. if (isScrollbarVertical)
  489. thumbBounds = { x, thumbStartPosition, width, thumbSize };
  490. else
  491. thumbBounds = { thumbStartPosition, y, thumbSize, height };
  492. auto c = scrollbar.findColour (ScrollBar::ColourIds::thumbColourId);
  493. g.setColour (isMouseOver ? c.brighter (0.25f) : c);
  494. g.fillRoundedRectangle (thumbBounds.reduced (1).toFloat(), 4.0f);
  495. }
  496. //==============================================================================
  497. Path LookAndFeel_V4::getTickShape (float height)
  498. {
  499. static const unsigned char pathData[] = { 110,109,32,210,202,64,126,183,148,64,108,39,244,247,64,245,76,124,64,108,178,131,27,65,246,76,252,64,108,175,242,4,65,246,76,252,
  500. 64,108,236,5,68,65,0,0,160,180,108,240,150,90,65,21,136,52,63,108,48,59,16,65,0,0,32,65,108,32,210,202,64,126,183,148,64, 99,101,0,0 };
  501. Path path;
  502. path.loadPathFromData (pathData, sizeof (pathData));
  503. path.scaleToFit (0, 0, height * 2.0f, height, true);
  504. return path;
  505. }
  506. Path LookAndFeel_V4::getCrossShape (float height)
  507. {
  508. static const unsigned char pathData[] = { 110,109,51,51,255,66,0,0,0,0,108,205,204,13,67,51,51,99,65,108,0,0,170,66,205,204,141,66,108,51,179,13,67,52,51,255,66,108,0,0,255,
  509. 66,205,204,13,67,108,205,204,141,66,0,0,170,66,108,52,51,99,65,51,179,13,67,108,0,0,0,0,51,51,255,66,108,205,204,98,66, 204,204,141,66,108,0,0,0,0,51,51,99,65,108,51,51,
  510. 99,65,0,0,0,0,108,205,204,141,66,205,204,98,66,108,51,51,255,66,0,0,0,0,99,101,0,0 };
  511. Path path;
  512. path.loadPathFromData (pathData, sizeof (pathData));
  513. path.scaleToFit (0, 0, height * 2.0f, height, true);
  514. return path;
  515. }
  516. //==============================================================================
  517. void LookAndFeel_V4::fillTextEditorBackground (Graphics& g, int width, int height, TextEditor& textEditor)
  518. {
  519. if (dynamic_cast<AlertWindow*> (textEditor.getParentComponent()) != nullptr)
  520. {
  521. g.setColour (textEditor.findColour (TextEditor::backgroundColourId));
  522. g.fillRect (0, 0, width, height);
  523. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  524. g.drawHorizontalLine (height - 1, 0.0f, static_cast<float> (width));
  525. }
  526. else
  527. {
  528. LookAndFeel_V2::fillTextEditorBackground (g, width, height, textEditor);
  529. }
  530. }
  531. void LookAndFeel_V4::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  532. {
  533. if (dynamic_cast<AlertWindow*> (textEditor.getParentComponent()) == nullptr)
  534. {
  535. if (textEditor.isEnabled())
  536. {
  537. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  538. {
  539. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  540. g.drawRect (0, 0, width, height, 2);
  541. }
  542. else
  543. {
  544. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  545. g.drawRect (0, 0, width, height);
  546. }
  547. }
  548. }
  549. }
  550. //==============================================================================
  551. Button* LookAndFeel_V4::createFileBrowserGoUpButton()
  552. {
  553. auto* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  554. Path arrowPath;
  555. arrowPath.addArrow ({ 50.0f, 100.0f, 50.0f, 0.0f }, 40.0f, 100.0f, 50.0f);
  556. DrawablePath arrowImage;
  557. arrowImage.setFill (goUpButton->findColour (TextButton::textColourOffId));
  558. arrowImage.setPath (arrowPath);
  559. goUpButton->setImages (&arrowImage);
  560. return goUpButton;
  561. }
  562. void LookAndFeel_V4::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  563. DirectoryContentsDisplayComponent* fileListComponent,
  564. FilePreviewComponent* previewComp,
  565. ComboBox* currentPathBox,
  566. TextEditor* filenameBox,
  567. Button* goUpButton)
  568. {
  569. auto sectionHeight = 22;
  570. auto buttonWidth = 50;
  571. auto b = browserComp.getLocalBounds().reduced (20, 5);
  572. auto topSlice = b.removeFromTop (sectionHeight);
  573. auto bottomSlice = b.removeFromBottom (sectionHeight);
  574. currentPathBox->setBounds (topSlice.removeFromLeft (topSlice.getWidth() - buttonWidth));
  575. topSlice.removeFromLeft (6);
  576. goUpButton->setBounds (topSlice);
  577. bottomSlice.removeFromLeft (20);
  578. filenameBox->setBounds (bottomSlice);
  579. if (previewComp != nullptr)
  580. previewComp->setBounds (b.removeFromRight (b.getWidth() / 3));
  581. if (auto* listAsComp = dynamic_cast<Component*> (fileListComponent))
  582. listAsComp->setBounds (b.reduced (0, 10));
  583. }
  584. void LookAndFeel_V4::drawFileBrowserRow (Graphics& g, int width, int height,
  585. const File& file, const String& filename, Image* icon,
  586. const String& fileSizeDescription,
  587. const String& fileTimeDescription,
  588. bool isDirectory, bool isItemSelected,
  589. int itemIndex, DirectoryContentsDisplayComponent& dcc)
  590. {
  591. LookAndFeel_V2::drawFileBrowserRow (g, width, height, file, filename, icon,
  592. fileSizeDescription, fileTimeDescription,
  593. isDirectory, isItemSelected, itemIndex, dcc);
  594. }
  595. //==============================================================================
  596. void LookAndFeel_V4::drawPopupMenuItem (Graphics& g, const Rectangle<int>& area,
  597. const bool isSeparator, const bool isActive,
  598. const bool isHighlighted, const bool isTicked,
  599. const bool hasSubMenu, const String& text,
  600. const String& shortcutKeyText,
  601. const Drawable* icon, const Colour* const textColourToUse)
  602. {
  603. if (isSeparator)
  604. {
  605. auto r = area.reduced (5, 0);
  606. r.removeFromTop (roundToInt ((r.getHeight() * 0.5f) - 0.5f));
  607. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.3f));
  608. g.fillRect (r.removeFromTop (1));
  609. }
  610. else
  611. {
  612. auto textColour = (textColourToUse == nullptr ? findColour (PopupMenu::textColourId)
  613. : *textColourToUse);
  614. auto r = area.reduced (1);
  615. if (isHighlighted && isActive)
  616. {
  617. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  618. g.fillRect (r);
  619. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  620. }
  621. else
  622. {
  623. g.setColour (textColour.withMultipliedAlpha (isActive ? 1.0f : 0.5f));
  624. }
  625. r.reduce (jmin (5, area.getWidth() / 20), 0);
  626. auto font = getPopupMenuFont();
  627. auto maxFontHeight = r.getHeight() / 1.3f;
  628. if (font.getHeight() > maxFontHeight)
  629. font.setHeight (maxFontHeight);
  630. g.setFont (font);
  631. auto iconArea = r.removeFromLeft (roundToInt (maxFontHeight)).toFloat();
  632. if (icon != nullptr)
  633. {
  634. icon->drawWithin (g, iconArea, RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, 1.0f);
  635. r.removeFromLeft (roundToInt (maxFontHeight * 0.5f));
  636. }
  637. else if (isTicked)
  638. {
  639. auto tick = getTickShape (1.0f);
  640. g.fillPath (tick, tick.getTransformToScaleToFit (iconArea.reduced (iconArea.getWidth() / 5, 0).toFloat(), true));
  641. }
  642. if (hasSubMenu)
  643. {
  644. auto arrowH = 0.6f * getPopupMenuFont().getAscent();
  645. auto x = static_cast<float> (r.removeFromRight ((int) arrowH).getX());
  646. auto halfH = static_cast<float> (r.getCentreY());
  647. Path path;
  648. path.startNewSubPath (x, halfH - arrowH * 0.5f);
  649. path.lineTo (x + arrowH * 0.6f, halfH);
  650. path.lineTo (x, halfH + arrowH * 0.5f);
  651. g.strokePath (path, PathStrokeType (2.0f));
  652. }
  653. r.removeFromRight (3);
  654. g.drawFittedText (text, r, Justification::centredLeft, 1);
  655. if (shortcutKeyText.isNotEmpty())
  656. {
  657. auto f2 = font;
  658. f2.setHeight (f2.getHeight() * 0.75f);
  659. f2.setHorizontalScale (0.95f);
  660. g.setFont (f2);
  661. g.drawText (shortcutKeyText, r, Justification::centredRight, true);
  662. }
  663. }
  664. }
  665. void LookAndFeel_V4::getIdealPopupMenuItemSize (const String& text, const bool isSeparator,
  666. int standardMenuItemHeight, int& idealWidth, int& idealHeight)
  667. {
  668. if (isSeparator)
  669. {
  670. idealWidth = 50;
  671. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 10 : 10;
  672. }
  673. else
  674. {
  675. auto font = getPopupMenuFont();
  676. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  677. font.setHeight (standardMenuItemHeight / 1.3f);
  678. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  679. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  680. }
  681. }
  682. void LookAndFeel_V4::drawMenuBarBackground (Graphics& g, int width, int height,
  683. bool, MenuBarComponent& menuBar)
  684. {
  685. auto colour = menuBar.findColour (TextButton::buttonColourId).withAlpha (0.4f);
  686. Rectangle<int> r (width, height);
  687. g.setColour (colour.contrasting (0.15f));
  688. g.fillRect (r.removeFromTop (1));
  689. g.fillRect (r.removeFromBottom (1));
  690. g.setGradientFill (ColourGradient::vertical (colour, 0, colour.darker (0.2f), (float) height));
  691. g.fillRect (r);
  692. }
  693. void LookAndFeel_V4::drawMenuBarItem (Graphics& g, int width, int height,
  694. int itemIndex, const String& itemText,
  695. bool isMouseOverItem, bool isMenuOpen,
  696. bool /*isMouseOverBar*/, MenuBarComponent& menuBar)
  697. {
  698. if (! menuBar.isEnabled())
  699. {
  700. g.setColour (menuBar.findColour (TextButton::textColourOffId)
  701. .withMultipliedAlpha (0.5f));
  702. }
  703. else if (isMenuOpen || isMouseOverItem)
  704. {
  705. g.fillAll (menuBar.findColour (TextButton::buttonOnColourId));
  706. g.setColour (menuBar.findColour (TextButton::textColourOnId));
  707. }
  708. else
  709. {
  710. g.setColour (menuBar.findColour (TextButton::textColourOffId));
  711. }
  712. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  713. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  714. }
  715. //==============================================================================
  716. void LookAndFeel_V4::drawComboBox (Graphics& g, int width, int height, bool,
  717. int, int, int, int, ComboBox& box)
  718. {
  719. auto cornerSize = box.findParentComponentOfClass<ChoicePropertyComponent>() != nullptr ? 0.0f : 3.0f;
  720. Rectangle<int> boxBounds (0, 0, width, height);
  721. g.setColour (box.findColour (ComboBox::backgroundColourId));
  722. g.fillRoundedRectangle (boxBounds.toFloat(), cornerSize);
  723. g.setColour (box.findColour (ComboBox::outlineColourId));
  724. g.drawRoundedRectangle (boxBounds.toFloat().reduced (0.5f, 0.5f), cornerSize, 1.0f);
  725. Rectangle<int> arrowZone (width - 30, 0, 20, height);
  726. Path path;
  727. path.startNewSubPath (arrowZone.getX() + 3.0f, arrowZone.getCentreY() - 2.0f);
  728. path.lineTo (static_cast<float> (arrowZone.getCentreX()), arrowZone.getCentreY() + 3.0f);
  729. path.lineTo (arrowZone.getRight() - 3.0f, arrowZone.getCentreY() - 2.0f);
  730. g.setColour (box.findColour (ComboBox::arrowColourId).withAlpha ((box.isEnabled() ? 0.9f : 0.2f)));
  731. g.strokePath (path, PathStrokeType (2.0f));
  732. }
  733. Font LookAndFeel_V4::getComboBoxFont (ComboBox& box)
  734. {
  735. return { jmin (16.0f, box.getHeight() * 0.85f) };
  736. }
  737. void LookAndFeel_V4::positionComboBoxText (ComboBox& box, Label& label)
  738. {
  739. label.setBounds (1, 1,
  740. box.getWidth() - 30,
  741. box.getHeight() - 2);
  742. label.setFont (getComboBoxFont (box));
  743. }
  744. //==============================================================================
  745. int LookAndFeel_V4::getSliderThumbRadius (Slider& slider)
  746. {
  747. return jmin (12, slider.isHorizontal() ? static_cast<int> (slider.getHeight() * 0.5f)
  748. : static_cast<int> (slider.getWidth() * 0.5f));
  749. }
  750. void LookAndFeel_V4::drawLinearSlider (Graphics& g, int x, int y, int width, int height,
  751. float sliderPos,
  752. float minSliderPos,
  753. float maxSliderPos,
  754. const Slider::SliderStyle style, Slider& slider)
  755. {
  756. if (slider.isBar())
  757. {
  758. g.setColour (slider.findColour (Slider::trackColourId));
  759. g.fillRect (slider.isHorizontal() ? Rectangle<float> (static_cast<float> (x), y + 0.5f, sliderPos - x, height - 1.0f)
  760. : Rectangle<float> (x + 0.5f, sliderPos, width - 1.0f, y + (height - sliderPos)));
  761. }
  762. else
  763. {
  764. auto isTwoVal = (style == Slider::SliderStyle::TwoValueVertical || style == Slider::SliderStyle::TwoValueHorizontal);
  765. auto isThreeVal = (style == Slider::SliderStyle::ThreeValueVertical || style == Slider::SliderStyle::ThreeValueHorizontal);
  766. auto trackWidth = jmin (6.0f, slider.isHorizontal() ? height * 0.25f : width * 0.25f);
  767. Point<float> startPoint (slider.isHorizontal() ? x : x + width * 0.5f,
  768. slider.isHorizontal() ? y + height * 0.5f : height + y);
  769. Point<float> endPoint (slider.isHorizontal() ? width + x : startPoint.x,
  770. slider.isHorizontal() ? startPoint.y : y);
  771. Path backgroundTrack;
  772. backgroundTrack.startNewSubPath (startPoint);
  773. backgroundTrack.lineTo (endPoint);
  774. g.setColour (slider.findColour (Slider::backgroundColourId));
  775. g.strokePath (backgroundTrack, { trackWidth, PathStrokeType::curved, PathStrokeType::rounded });
  776. Path valueTrack;
  777. Point<float> minPoint, maxPoint, thumbPoint;
  778. if (isTwoVal || isThreeVal)
  779. {
  780. minPoint = { slider.isHorizontal() ? minSliderPos : width * 0.5f,
  781. slider.isHorizontal() ? height * 0.5f : minSliderPos };
  782. if (isThreeVal)
  783. thumbPoint = { slider.isHorizontal() ? sliderPos : width * 0.5f,
  784. slider.isHorizontal() ? height * 0.5f : sliderPos };
  785. maxPoint = { slider.isHorizontal() ? maxSliderPos : width * 0.5f,
  786. slider.isHorizontal() ? height * 0.5f : maxSliderPos };
  787. }
  788. else
  789. {
  790. auto kx = slider.isHorizontal() ? sliderPos : (x + width * 0.5f);
  791. auto ky = slider.isHorizontal() ? (y + height * 0.5f) : sliderPos;
  792. minPoint = startPoint;
  793. maxPoint = { kx, ky };
  794. }
  795. auto thumbWidth = getSliderThumbRadius (slider);
  796. valueTrack.startNewSubPath (minPoint);
  797. valueTrack.lineTo (isThreeVal ? thumbPoint : maxPoint);
  798. g.setColour (slider.findColour (Slider::trackColourId));
  799. g.strokePath (valueTrack, { trackWidth, PathStrokeType::curved, PathStrokeType::rounded });
  800. if (! isTwoVal)
  801. {
  802. g.setColour (slider.findColour (Slider::thumbColourId));
  803. g.fillEllipse (Rectangle<float> (static_cast<float> (thumbWidth), static_cast<float> (thumbWidth)).withCentre (isThreeVal ? thumbPoint : maxPoint));
  804. }
  805. if (isTwoVal || isThreeVal)
  806. {
  807. auto sr = jmin (trackWidth, (slider.isHorizontal() ? height : width) * 0.4f);
  808. auto pointerColour = slider.findColour (Slider::thumbColourId);
  809. if (slider.isHorizontal())
  810. {
  811. drawPointer (g, minSliderPos - sr,
  812. jmax (0.0f, y + height * 0.5f - trackWidth * 2.0f),
  813. trackWidth * 2.0f, pointerColour, 2);
  814. drawPointer (g, maxSliderPos - trackWidth,
  815. jmin (y + height - trackWidth * 2.0f, y + height * 0.5f),
  816. trackWidth * 2.0f, pointerColour, 4);
  817. }
  818. else
  819. {
  820. drawPointer (g, jmax (0.0f, x + width * 0.5f - trackWidth * 2.0f),
  821. minSliderPos - trackWidth,
  822. trackWidth * 2.0f, pointerColour, 1);
  823. drawPointer (g, jmin (x + width - trackWidth * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  824. trackWidth * 2.0f, pointerColour, 3);
  825. }
  826. }
  827. }
  828. }
  829. void LookAndFeel_V4::drawRotarySlider (Graphics& g, int x, int y, int width, int height, float sliderPos,
  830. const float rotaryStartAngle, const float rotaryEndAngle, Slider& slider)
  831. {
  832. auto outline = slider.findColour (Slider::rotarySliderOutlineColourId);
  833. auto fill = slider.findColour (Slider::rotarySliderFillColourId);
  834. auto bounds = Rectangle<int> (x, y, width, height).toFloat().reduced (10);
  835. auto radius = jmin (bounds.getWidth(), bounds.getHeight()) / 2.0f;
  836. auto toAngle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  837. auto lineW = jmin (8.0f, radius * 0.5f);
  838. auto arcRadius = radius - lineW * 0.5f;
  839. Path backgroundArc;
  840. backgroundArc.addCentredArc (bounds.getCentreX(),
  841. bounds.getCentreY(),
  842. arcRadius,
  843. arcRadius,
  844. 0.0f,
  845. rotaryStartAngle,
  846. rotaryEndAngle,
  847. true);
  848. g.setColour (outline);
  849. g.strokePath (backgroundArc, PathStrokeType (lineW, PathStrokeType::curved, PathStrokeType::rounded));
  850. if (slider.isEnabled())
  851. {
  852. Path valueArc;
  853. valueArc.addCentredArc (bounds.getCentreX(),
  854. bounds.getCentreY(),
  855. arcRadius,
  856. arcRadius,
  857. 0.0f,
  858. rotaryStartAngle,
  859. toAngle,
  860. true);
  861. g.setColour (fill);
  862. g.strokePath (valueArc, PathStrokeType (lineW, PathStrokeType::curved, PathStrokeType::rounded));
  863. }
  864. auto thumbWidth = lineW * 2.0f;
  865. Point<float> thumbPoint (bounds.getCentreX() + arcRadius * std::cos (toAngle - MathConstants<float>::halfPi),
  866. bounds.getCentreY() + arcRadius * std::sin (toAngle - MathConstants<float>::halfPi));
  867. g.setColour (slider.findColour (Slider::thumbColourId));
  868. g.fillEllipse (Rectangle<float> (thumbWidth, thumbWidth).withCentre (thumbPoint));
  869. }
  870. void LookAndFeel_V4::drawPointer (Graphics& g, const float x, const float y, const float diameter,
  871. const Colour& colour, const int direction) noexcept
  872. {
  873. Path p;
  874. p.startNewSubPath (x + diameter * 0.5f, y);
  875. p.lineTo (x + diameter, y + diameter * 0.6f);
  876. p.lineTo (x + diameter, y + diameter);
  877. p.lineTo (x, y + diameter);
  878. p.lineTo (x, y + diameter * 0.6f);
  879. p.closeSubPath();
  880. p.applyTransform (AffineTransform::rotation (direction * MathConstants<float>::halfPi,
  881. x + diameter * 0.5f, y + diameter * 0.5f));
  882. g.setColour (colour);
  883. g.fillPath (p);
  884. }
  885. //==============================================================================
  886. void LookAndFeel_V4::drawTooltip (Graphics& g, const String& text, int width, int height)
  887. {
  888. Rectangle<int> bounds (width, height);
  889. auto cornerSize = 5.0f;
  890. g.setColour (findColour (TooltipWindow::backgroundColourId));
  891. g.fillRoundedRectangle (bounds.toFloat(), cornerSize);
  892. g.setColour (findColour (TooltipWindow::outlineColourId));
  893. g.drawRoundedRectangle (bounds.toFloat().reduced (0.5f, 0.5f), cornerSize, 1.0f);
  894. LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId))
  895. .draw (g, { static_cast<float> (width), static_cast<float> (height) });
  896. }
  897. //==============================================================================
  898. void LookAndFeel_V4::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int>& area,
  899. bool isMouseOver, bool /*isMouseDown*/,
  900. ConcertinaPanel& concertina, Component& panel)
  901. {
  902. auto bounds = area.toFloat().reduced (0.5f);
  903. auto cornerSize = 4.0f;
  904. auto isTopPanel = (concertina.getPanel (0) == &panel);
  905. Path p;
  906. p.addRoundedRectangle (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  907. cornerSize, cornerSize, isTopPanel, isTopPanel, false, false);
  908. auto bkg = Colours::grey;
  909. g.setGradientFill (ColourGradient::vertical (Colours::white.withAlpha (isMouseOver ? 0.4f : 0.2f), static_cast<float> (area.getY()),
  910. Colours::darkgrey.withAlpha (0.1f), static_cast<float> (area.getBottom())));
  911. g.fillPath (p);
  912. }
  913. //==============================================================================
  914. void LookAndFeel_V4::drawLevelMeter (Graphics& g, int width, int height, float level)
  915. {
  916. auto outerCornerSize = 3.0f;
  917. auto outerBorderWidth = 2.0f;
  918. auto totalBlocks = 7;
  919. auto spacingFraction = 0.03f;
  920. g.setColour (findColour (ResizableWindow::backgroundColourId));
  921. g.fillRoundedRectangle (0.0f, 0.0f, static_cast<float> (width), static_cast<float> (height), outerCornerSize);
  922. auto doubleOuterBorderWidth = 2.0f * outerBorderWidth;
  923. auto numBlocks = roundToInt (totalBlocks * level);
  924. auto blockWidth = (width - doubleOuterBorderWidth) / static_cast<float> (totalBlocks);
  925. auto blockHeight = height - doubleOuterBorderWidth;
  926. auto blockRectWidth = (1.0f - 2.0f * spacingFraction) * blockWidth;
  927. auto blockRectSpacing = spacingFraction * blockWidth;
  928. auto blockCornerSize = 0.1f * blockWidth;
  929. auto c = findColour (Slider::thumbColourId);
  930. for (auto i = 0; i < totalBlocks; ++i)
  931. {
  932. if (i >= numBlocks)
  933. g.setColour (c.withAlpha (0.5f));
  934. else
  935. g.setColour (i < totalBlocks - 1 ? c : Colours::red);
  936. g.fillRoundedRectangle (outerBorderWidth + (i * blockWidth) + blockRectSpacing,
  937. outerBorderWidth,
  938. blockRectWidth,
  939. blockHeight,
  940. blockCornerSize);
  941. }
  942. }
  943. //==============================================================================
  944. void LookAndFeel_V4::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  945. {
  946. auto background = toolbar.findColour (Toolbar::backgroundColourId);
  947. g.setGradientFill ({ background, 0.0f, 0.0f,
  948. background.darker (0.2f),
  949. toolbar.isVertical() ? w - 1.0f : 0.0f,
  950. toolbar.isVertical() ? 0.0f : h - 1.0f,
  951. false });
  952. g.fillAll();
  953. }
  954. void LookAndFeel_V4::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  955. const String& text, ToolbarItemComponent& component)
  956. {
  957. auto baseTextColour = component.findParentComponentOfClass<PopupMenu::CustomComponent>() != nullptr
  958. ? component.findColour (PopupMenu::textColourId)
  959. : component.findColour (Toolbar::labelTextColourId);
  960. g.setColour (baseTextColour.withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  961. auto fontHeight = jmin (14.0f, height * 0.85f);
  962. g.setFont (fontHeight);
  963. g.drawFittedText (text,
  964. x, y, width, height,
  965. Justification::centred,
  966. jmax (1, height / (int) fontHeight));
  967. }
  968. //==============================================================================
  969. void LookAndFeel_V4::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  970. bool isOpen, int width, int height)
  971. {
  972. auto buttonSize = height * 0.75f;
  973. auto buttonIndent = (height - buttonSize) * 0.5f;
  974. drawTreeviewPlusMinusBox (g, { buttonIndent, buttonIndent, buttonSize, buttonSize },
  975. findColour (ResizableWindow::backgroundColourId), isOpen, false);
  976. auto textX = static_cast<int> ((buttonIndent * 2.0f + buttonSize + 2.0f));
  977. g.setColour (findColour (PropertyComponent::labelTextColourId));
  978. g.setFont ({ height * 0.7f, Font::bold });
  979. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  980. }
  981. void LookAndFeel_V4::drawPropertyComponentBackground (Graphics& g, int width, int height, PropertyComponent& component)
  982. {
  983. g.setColour (component.findColour (PropertyComponent::backgroundColourId));
  984. g.fillRect (0, 0, width, height - 1);
  985. }
  986. void LookAndFeel_V4::drawPropertyComponentLabel (Graphics& g, int width, int height, PropertyComponent& component)
  987. {
  988. ignoreUnused (width);
  989. auto indent = getPropertyComponentIndent (component);
  990. g.setColour (component.findColour (PropertyComponent::labelTextColourId)
  991. .withMultipliedAlpha (component.isEnabled() ? 1.0f : 0.6f));
  992. g.setFont (jmin (height, 24) * 0.65f);
  993. auto r = getPropertyComponentContentPosition (component);
  994. g.drawFittedText (component.getName(),
  995. indent, r.getY(), r.getX() - 5, r.getHeight(),
  996. Justification::centredLeft, 2);
  997. }
  998. int LookAndFeel_V4::getPropertyComponentIndent (PropertyComponent& component)
  999. {
  1000. return jmin (10, component.getWidth() / 10);
  1001. }
  1002. Rectangle<int> LookAndFeel_V4::getPropertyComponentContentPosition (PropertyComponent& component)
  1003. {
  1004. auto textW = jmin (200, component.getWidth() / 2);
  1005. return { textW, 0, component.getWidth() - textW, component.getHeight() - 1 };
  1006. }
  1007. //==============================================================================
  1008. void LookAndFeel_V4::drawCallOutBoxBackground (CallOutBox& box, Graphics& g,
  1009. const Path& path, Image& cachedImage)
  1010. {
  1011. if (cachedImage.isNull())
  1012. {
  1013. cachedImage = { Image::ARGB, box.getWidth(), box.getHeight(), true };
  1014. Graphics g2 (cachedImage);
  1015. DropShadow (Colours::black.withAlpha (0.7f), 8, { 0, 2 }).drawForPath (g2, path);
  1016. }
  1017. g.setColour (Colours::black);
  1018. g.drawImageAt (cachedImage, 0, 0);
  1019. g.setColour (currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).withAlpha (0.8f));
  1020. g.fillPath (path);
  1021. g.setColour (currentColourScheme.getUIColour (ColourScheme::UIColour::outline).withAlpha (0.8f));
  1022. g.strokePath (path, PathStrokeType (2.0f));
  1023. }
  1024. //==============================================================================
  1025. void LookAndFeel_V4::drawStretchableLayoutResizerBar (Graphics& g, int /*w*/, int /*h*/, bool /*isVerticalBar*/,
  1026. bool isMouseOver, bool isMouseDragging)
  1027. {
  1028. if (isMouseOver || isMouseDragging)
  1029. g.fillAll (currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).withAlpha (0.5f));
  1030. }
  1031. //==============================================================================
  1032. void LookAndFeel_V4::initialiseColours()
  1033. {
  1034. const uint32 transparent = 0x00000000;
  1035. const uint32 coloursToUse[] =
  1036. {
  1037. TextButton::buttonColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1038. TextButton::buttonOnColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedFill).getARGB(),
  1039. TextButton::textColourOnId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedText).getARGB(),
  1040. TextButton::textColourOffId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1041. ToggleButton::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1042. ToggleButton::tickColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1043. ToggleButton::tickDisabledColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).withAlpha (0.5f).getARGB(),
  1044. TextEditor::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1045. TextEditor::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1046. TextEditor::highlightColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).withAlpha (0.4f).getARGB(),
  1047. TextEditor::highlightedTextColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedText).getARGB(),
  1048. TextEditor::outlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1049. TextEditor::focusedOutlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1050. TextEditor::shadowColourId, transparent,
  1051. CaretComponent::caretColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).getARGB(),
  1052. Label::backgroundColourId, transparent,
  1053. Label::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1054. Label::outlineColourId, transparent,
  1055. Label::textWhenEditingColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1056. ScrollBar::backgroundColourId, transparent,
  1057. ScrollBar::thumbColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).getARGB(),
  1058. ScrollBar::trackColourId, transparent,
  1059. TreeView::linesColourId, transparent,
  1060. TreeView::backgroundColourId, transparent,
  1061. TreeView::dragAndDropIndicatorColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1062. TreeView::selectedItemBackgroundColourId, transparent,
  1063. TreeView::oddItemsColourId, transparent,
  1064. TreeView::evenItemsColourId, transparent,
  1065. PopupMenu::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::menuBackground).getARGB(),
  1066. PopupMenu::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::menuText).getARGB(),
  1067. PopupMenu::headerTextColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::menuText).getARGB(),
  1068. PopupMenu::highlightedTextColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedText).getARGB(),
  1069. PopupMenu::highlightedBackgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedFill).getARGB(),
  1070. ComboBox::buttonColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1071. ComboBox::outlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1072. ComboBox::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1073. ComboBox::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1074. ComboBox::arrowColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1075. ComboBox::focusedOutlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1076. PropertyComponent::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1077. PropertyComponent::labelTextColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1078. TextPropertyComponent::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1079. TextPropertyComponent::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1080. TextPropertyComponent::outlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1081. BooleanPropertyComponent::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1082. BooleanPropertyComponent::outlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1083. ListBox::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1084. ListBox::outlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1085. ListBox::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1086. Slider::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1087. Slider::thumbColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).getARGB(),
  1088. Slider::trackColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedFill).getARGB(),
  1089. Slider::rotarySliderFillColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedFill).getARGB(),
  1090. Slider::rotarySliderOutlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1091. Slider::textBoxTextColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1092. Slider::textBoxBackgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).withAlpha (0.0f).getARGB(),
  1093. Slider::textBoxHighlightColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).withAlpha (0.4f).getARGB(),
  1094. Slider::textBoxOutlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1095. ResizableWindow::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::windowBackground).getARGB(),
  1096. DocumentWindow::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1097. AlertWindow::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1098. AlertWindow::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1099. AlertWindow::outlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1100. ProgressBar::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1101. ProgressBar::foregroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedFill).getARGB(),
  1102. TooltipWindow::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedFill).getARGB(),
  1103. TooltipWindow::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedText).getARGB(),
  1104. TooltipWindow::outlineColourId, transparent,
  1105. TabbedComponent::backgroundColourId, transparent,
  1106. TabbedComponent::outlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1107. TabbedButtonBar::tabOutlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).withAlpha (0.5f).getARGB(),
  1108. TabbedButtonBar::frontOutlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1109. Toolbar::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).withAlpha (0.4f).getARGB(),
  1110. Toolbar::separatorColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1111. Toolbar::buttonMouseOverBackgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).contrasting (0.2f).getARGB(),
  1112. Toolbar::buttonMouseDownBackgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).contrasting (0.5f).getARGB(),
  1113. Toolbar::labelTextColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1114. Toolbar::editingModeOutlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1115. DrawableButton::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1116. DrawableButton::textColourOnId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedText).getARGB(),
  1117. DrawableButton::backgroundColourId, transparent,
  1118. DrawableButton::backgroundOnColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedFill).getARGB(),
  1119. HyperlinkButton::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).interpolatedWith (Colours::blue, 0.4f).getARGB(),
  1120. GroupComponent::outlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1121. GroupComponent::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1122. BubbleComponent::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1123. BubbleComponent::outlineColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1124. DirectoryContentsDisplayComponent::highlightColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedFill).getARGB(),
  1125. DirectoryContentsDisplayComponent::textColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::menuText).getARGB(),
  1126. DirectoryContentsDisplayComponent::highlightedTextColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedText).getARGB(),
  1127. 0x1000440, /*LassoComponent::lassoFillColourId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).getARGB(),
  1128. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::outline).getARGB(),
  1129. 0x1005000, /*MidiKeyboardComponent::whiteNoteColourId*/ 0xffffffff,
  1130. 0x1005001, /*MidiKeyboardComponent::blackNoteColourId*/ 0xff000000,
  1131. 0x1005002, /*MidiKeyboardComponent::keySeparatorLineColourId*/ 0x66000000,
  1132. 0x1005003, /*MidiKeyboardComponent::mouseOverKeyOverlayColourId*/ 0x80ffff00,
  1133. 0x1005004, /*MidiKeyboardComponent::keyDownOverlayColourId*/ 0xffb6b600,
  1134. 0x1005005, /*MidiKeyboardComponent::textLabelColourId*/ 0xff000000,
  1135. 0x1005006, /*MidiKeyboardComponent::upDownButtonBackgroundColourId*/ 0xffd3d3d3,
  1136. 0x1005007, /*MidiKeyboardComponent::upDownButtonArrowColourId*/ 0xff000000,
  1137. 0x1005008, /*MidiKeyboardComponent::shadowColourId*/ 0x4c000000,
  1138. 0x1004500, /*CodeEditorComponent::backgroundColourId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1139. 0x1004502, /*CodeEditorComponent::highlightColourId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).withAlpha (0.4f).getARGB(),
  1140. 0x1004503, /*CodeEditorComponent::defaultTextColourId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1141. 0x1004504, /*CodeEditorComponent::lineNumberBackgroundId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::highlightedFill).withAlpha (0.5f).getARGB(),
  1142. 0x1004505, /*CodeEditorComponent::lineNumberTextId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).getARGB(),
  1143. 0x1007000, /*ColourSelector::backgroundColourId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1144. 0x1007001, /*ColourSelector::labelTextColourId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1145. 0x100ad00, /*KeyMappingEditorComponent::backgroundColourId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1146. 0x100ad01, /*KeyMappingEditorComponent::textColourId*/ currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1147. FileSearchPathListComponent::backgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::menuBackground).getARGB(),
  1148. FileChooserDialogBox::titleTextColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1149. SidePanel::backgroundColour, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).getARGB(),
  1150. SidePanel::titleTextColour, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultText).getARGB(),
  1151. SidePanel::shadowBaseColour, currentColourScheme.getUIColour (ColourScheme::UIColour::widgetBackground).darker().getARGB(),
  1152. SidePanel::dismissButtonNormalColour, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).getARGB(),
  1153. SidePanel::dismissButtonOverColour, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).darker().getARGB(),
  1154. SidePanel::dismissButtonDownColour, currentColourScheme.getUIColour (ColourScheme::UIColour::defaultFill).brighter().getARGB(),
  1155. FileBrowserComponent::currentPathBoxBackgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::menuBackground).getARGB(),
  1156. FileBrowserComponent::currentPathBoxTextColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::menuText).getARGB(),
  1157. FileBrowserComponent::currentPathBoxArrowColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::menuText).getARGB(),
  1158. FileBrowserComponent::filenameBoxBackgroundColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::menuBackground).getARGB(),
  1159. FileBrowserComponent::filenameBoxTextColourId, currentColourScheme.getUIColour (ColourScheme::UIColour::menuText).getARGB(),
  1160. };
  1161. for (int i = 0; i < numElementsInArray (coloursToUse); i += 2)
  1162. setColour ((int) coloursToUse [i], Colour ((uint32) coloursToUse [i + 1]));
  1163. }
  1164. } // namespace juce