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.

1433 lines
65KB

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