Audio plugin host https://kx.studio/carla
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.

1446 lines
66KB

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