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.

1435 lines
65KB

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