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.

1489 lines
68KB

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