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.

3061 lines
120KB

  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. namespace LookAndFeelHelpers
  22. {
  23. static Colour createBaseColour (Colour buttonColour,
  24. bool hasKeyboardFocus,
  25. bool shouldDrawButtonAsHighlighted,
  26. bool shouldDrawButtonAsDown) noexcept
  27. {
  28. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  29. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  30. if (shouldDrawButtonAsDown) return baseColour.contrasting (0.2f);
  31. if (shouldDrawButtonAsHighlighted) return baseColour.contrasting (0.1f);
  32. return baseColour;
  33. }
  34. static TextLayout layoutTooltipText (const String& text, Colour colour) noexcept
  35. {
  36. const float tooltipFontSize = 13.0f;
  37. const int maxToolTipWidth = 400;
  38. AttributedString s;
  39. s.setJustification (Justification::centred);
  40. s.append (text, Font (tooltipFontSize, Font::bold), colour);
  41. TextLayout tl;
  42. tl.createLayoutWithBalancedLineLengths (s, (float) maxToolTipWidth);
  43. return tl;
  44. }
  45. }
  46. //==============================================================================
  47. LookAndFeel_V2::LookAndFeel_V2()
  48. {
  49. // initialise the standard set of colours..
  50. const uint32 textButtonColour = 0xffbbbbff;
  51. const uint32 textHighlightColour = 0x401111ee;
  52. const uint32 standardOutlineColour = 0xb2808080;
  53. static const uint32 standardColours[] =
  54. {
  55. TextButton::buttonColourId, textButtonColour,
  56. TextButton::buttonOnColourId, 0xff4444ff,
  57. TextButton::textColourOnId, 0xff000000,
  58. TextButton::textColourOffId, 0xff000000,
  59. ToggleButton::textColourId, 0xff000000,
  60. ToggleButton::tickColourId, 0xff000000,
  61. ToggleButton::tickDisabledColourId, 0xff808080,
  62. TextEditor::backgroundColourId, 0xffffffff,
  63. TextEditor::textColourId, 0xff000000,
  64. TextEditor::highlightColourId, textHighlightColour,
  65. TextEditor::highlightedTextColourId, 0xff000000,
  66. TextEditor::outlineColourId, 0x00000000,
  67. TextEditor::focusedOutlineColourId, textButtonColour,
  68. TextEditor::shadowColourId, 0x38000000,
  69. CaretComponent::caretColourId, 0xff000000,
  70. Label::backgroundColourId, 0x00000000,
  71. Label::textColourId, 0xff000000,
  72. Label::outlineColourId, 0x00000000,
  73. ScrollBar::backgroundColourId, 0x00000000,
  74. ScrollBar::thumbColourId, 0xffffffff,
  75. TreeView::linesColourId, 0x4c000000,
  76. TreeView::backgroundColourId, 0x00000000,
  77. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  78. TreeView::selectedItemBackgroundColourId, 0x00000000,
  79. TreeView::oddItemsColourId, 0x00000000,
  80. TreeView::evenItemsColourId, 0x00000000,
  81. PopupMenu::backgroundColourId, 0xffffffff,
  82. PopupMenu::textColourId, 0xff000000,
  83. PopupMenu::headerTextColourId, 0xff000000,
  84. PopupMenu::highlightedTextColourId, 0xffffffff,
  85. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  86. ComboBox::buttonColourId, 0xffbbbbff,
  87. ComboBox::outlineColourId, standardOutlineColour,
  88. ComboBox::textColourId, 0xff000000,
  89. ComboBox::backgroundColourId, 0xffffffff,
  90. ComboBox::arrowColourId, 0x99000000,
  91. ComboBox::focusedOutlineColourId, 0xffbbbbff,
  92. PropertyComponent::backgroundColourId, 0x66ffffff,
  93. PropertyComponent::labelTextColourId, 0xff000000,
  94. TextPropertyComponent::backgroundColourId, 0xffffffff,
  95. TextPropertyComponent::textColourId, 0xff000000,
  96. TextPropertyComponent::outlineColourId, standardOutlineColour,
  97. BooleanPropertyComponent::backgroundColourId, 0xffffffff,
  98. BooleanPropertyComponent::outlineColourId, standardOutlineColour,
  99. ListBox::backgroundColourId, 0xffffffff,
  100. ListBox::outlineColourId, standardOutlineColour,
  101. ListBox::textColourId, 0xff000000,
  102. Slider::backgroundColourId, 0x00000000,
  103. Slider::thumbColourId, textButtonColour,
  104. Slider::trackColourId, 0x7fffffff,
  105. Slider::rotarySliderFillColourId, 0x7f0000ff,
  106. Slider::rotarySliderOutlineColourId, 0x66000000,
  107. Slider::textBoxTextColourId, 0xff000000,
  108. Slider::textBoxBackgroundColourId, 0xffffffff,
  109. Slider::textBoxHighlightColourId, textHighlightColour,
  110. Slider::textBoxOutlineColourId, standardOutlineColour,
  111. ResizableWindow::backgroundColourId, 0xff777777,
  112. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  113. AlertWindow::backgroundColourId, 0xffededed,
  114. AlertWindow::textColourId, 0xff000000,
  115. AlertWindow::outlineColourId, 0xff666666,
  116. ProgressBar::backgroundColourId, 0xffeeeeee,
  117. ProgressBar::foregroundColourId, 0xffaaaaee,
  118. TooltipWindow::backgroundColourId, 0xffeeeebb,
  119. TooltipWindow::textColourId, 0xff000000,
  120. TooltipWindow::outlineColourId, 0x4c000000,
  121. TabbedComponent::backgroundColourId, 0x00000000,
  122. TabbedComponent::outlineColourId, 0xff777777,
  123. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  124. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  125. Toolbar::backgroundColourId, 0xfff6f8f9,
  126. Toolbar::separatorColourId, 0x4c000000,
  127. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  128. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  129. Toolbar::labelTextColourId, 0xff000000,
  130. Toolbar::editingModeOutlineColourId, 0xffff0000,
  131. DrawableButton::textColourId, 0xff000000,
  132. DrawableButton::textColourOnId, 0xff000000,
  133. DrawableButton::backgroundColourId, 0x00000000,
  134. DrawableButton::backgroundOnColourId, 0xaabbbbff,
  135. HyperlinkButton::textColourId, 0xcc1111ee,
  136. GroupComponent::outlineColourId, 0x66000000,
  137. GroupComponent::textColourId, 0xff000000,
  138. BubbleComponent::backgroundColourId, 0xeeeeeebb,
  139. BubbleComponent::outlineColourId, 0x77000000,
  140. TableHeaderComponent::textColourId, 0xff000000,
  141. TableHeaderComponent::backgroundColourId, 0xffe8ebf9,
  142. TableHeaderComponent::outlineColourId, 0x33000000,
  143. TableHeaderComponent::highlightColourId, 0x8899aadd,
  144. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  145. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  146. DirectoryContentsDisplayComponent::highlightedTextColourId, 0xff000000,
  147. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  148. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  149. 0x1005000, /*MidiKeyboardComponent::whiteNoteColourId*/ 0xffffffff,
  150. 0x1005001, /*MidiKeyboardComponent::blackNoteColourId*/ 0xff000000,
  151. 0x1005002, /*MidiKeyboardComponent::keySeparatorLineColourId*/ 0x66000000,
  152. 0x1005003, /*MidiKeyboardComponent::mouseOverKeyOverlayColourId*/ 0x80ffff00,
  153. 0x1005004, /*MidiKeyboardComponent::keyDownOverlayColourId*/ 0xffb6b600,
  154. 0x1005005, /*MidiKeyboardComponent::textLabelColourId*/ 0xff000000,
  155. 0x1005006, /*MidiKeyboardComponent::upDownButtonBackgroundColourId*/ 0xffd3d3d3,
  156. 0x1005007, /*MidiKeyboardComponent::upDownButtonArrowColourId*/ 0xff000000,
  157. 0x1005008, /*MidiKeyboardComponent::shadowColourId*/ 0x4c000000,
  158. 0x1004500, /*CodeEditorComponent::backgroundColourId*/ 0xffffffff,
  159. 0x1004502, /*CodeEditorComponent::highlightColourId*/ textHighlightColour,
  160. 0x1004503, /*CodeEditorComponent::defaultTextColourId*/ 0xff000000,
  161. 0x1004504, /*CodeEditorComponent::lineNumberBackgroundId*/ 0x44999999,
  162. 0x1004505, /*CodeEditorComponent::lineNumberTextId*/ 0x44000000,
  163. 0x1007000, /*ColourSelector::backgroundColourId*/ 0xffe5e5e5,
  164. 0x1007001, /*ColourSelector::labelTextColourId*/ 0xff000000,
  165. 0x100ad00, /*KeyMappingEditorComponent::backgroundColourId*/ 0x00000000,
  166. 0x100ad01, /*KeyMappingEditorComponent::textColourId*/ 0xff000000,
  167. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  168. FileChooserDialogBox::titleTextColourId, 0xff000000,
  169. SidePanel::backgroundColour, 0xffffffff,
  170. SidePanel::titleTextColour, 0xff000000,
  171. SidePanel::shadowBaseColour, 0xff000000,
  172. SidePanel::dismissButtonNormalColour, textButtonColour,
  173. SidePanel::dismissButtonOverColour, textButtonColour,
  174. SidePanel::dismissButtonDownColour, 0xff4444ff,
  175. FileBrowserComponent::currentPathBoxBackgroundColourId, 0xffffffff,
  176. FileBrowserComponent::currentPathBoxTextColourId, 0xff000000,
  177. FileBrowserComponent::currentPathBoxArrowColourId, 0x99000000,
  178. FileBrowserComponent::filenameBoxBackgroundColourId, 0xffffffff,
  179. FileBrowserComponent::filenameBoxTextColourId, 0xff000000,
  180. };
  181. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  182. setColour ((int) standardColours [i], Colour ((uint32) standardColours [i + 1]));
  183. }
  184. LookAndFeel_V2::~LookAndFeel_V2() {}
  185. //==============================================================================
  186. void LookAndFeel_V2::drawButtonBackground (Graphics& g,
  187. Button& button,
  188. const Colour& backgroundColour,
  189. bool shouldDrawButtonAsHighlighted,
  190. bool shouldDrawButtonAsDown)
  191. {
  192. const int width = button.getWidth();
  193. const int height = button.getHeight();
  194. const float outlineThickness = button.isEnabled() ? ((shouldDrawButtonAsDown || shouldDrawButtonAsHighlighted) ? 1.2f : 0.7f) : 0.4f;
  195. const float halfThickness = outlineThickness * 0.5f;
  196. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  197. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  198. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  199. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  200. const Colour baseColour (LookAndFeelHelpers::createBaseColour (backgroundColour,
  201. button.hasKeyboardFocus (true),
  202. shouldDrawButtonAsHighlighted,
  203. shouldDrawButtonAsDown)
  204. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  205. drawGlassLozenge (g,
  206. indentL,
  207. indentT,
  208. width - indentL - indentR,
  209. height - indentT - indentB,
  210. baseColour, outlineThickness, -1.0f,
  211. button.isConnectedOnLeft(),
  212. button.isConnectedOnRight(),
  213. button.isConnectedOnTop(),
  214. button.isConnectedOnBottom());
  215. }
  216. Font LookAndFeel_V2::getTextButtonFont (TextButton&, int buttonHeight)
  217. {
  218. return Font (jmin (15.0f, buttonHeight * 0.6f));
  219. }
  220. int LookAndFeel_V2::getTextButtonWidthToFitText (TextButton& b, int buttonHeight)
  221. {
  222. return getTextButtonFont (b, buttonHeight).getStringWidth (b.getButtonText()) + buttonHeight;
  223. }
  224. void LookAndFeel_V2::drawButtonText (Graphics& g, TextButton& button,
  225. bool /*shouldDrawButtonAsHighlighted*/, bool /*shouldDrawButtonAsDown*/)
  226. {
  227. Font font (getTextButtonFont (button, button.getHeight()));
  228. g.setFont (font);
  229. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  230. : TextButton::textColourOffId)
  231. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  232. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  233. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  234. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  235. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  236. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  237. const int textWidth = button.getWidth() - leftIndent - rightIndent;
  238. if (textWidth > 0)
  239. g.drawFittedText (button.getButtonText(),
  240. leftIndent, yIndent, textWidth, button.getHeight() - yIndent * 2,
  241. Justification::centred, 2);
  242. }
  243. void LookAndFeel_V2::drawTickBox (Graphics& g, Component& component,
  244. float x, float y, float w, float h,
  245. const bool ticked,
  246. const bool isEnabled,
  247. const bool shouldDrawButtonAsHighlighted,
  248. const bool shouldDrawButtonAsDown)
  249. {
  250. const float boxSize = w * 0.7f;
  251. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  252. LookAndFeelHelpers::createBaseColour (component.findColour (TextButton::buttonColourId)
  253. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  254. true, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown),
  255. isEnabled ? ((shouldDrawButtonAsDown || shouldDrawButtonAsHighlighted) ? 1.1f : 0.5f) : 0.3f);
  256. if (ticked)
  257. {
  258. Path tick;
  259. tick.startNewSubPath (1.5f, 3.0f);
  260. tick.lineTo (3.0f, 6.0f);
  261. tick.lineTo (6.0f, 0.0f);
  262. g.setColour (component.findColour (isEnabled ? ToggleButton::tickColourId
  263. : ToggleButton::tickDisabledColourId));
  264. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  265. .translated (x, y));
  266. g.strokePath (tick, PathStrokeType (2.5f), trans);
  267. }
  268. }
  269. void LookAndFeel_V2::drawToggleButton (Graphics& g, ToggleButton& button,
  270. bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
  271. {
  272. if (button.hasKeyboardFocus (true))
  273. {
  274. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  275. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  276. }
  277. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  278. const float tickWidth = fontSize * 1.1f;
  279. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  280. tickWidth, tickWidth,
  281. button.getToggleState(),
  282. button.isEnabled(),
  283. shouldDrawButtonAsHighlighted,
  284. shouldDrawButtonAsDown);
  285. g.setColour (button.findColour (ToggleButton::textColourId));
  286. g.setFont (fontSize);
  287. if (! button.isEnabled())
  288. g.setOpacity (0.5f);
  289. g.drawFittedText (button.getButtonText(),
  290. button.getLocalBounds().withTrimmedLeft (roundToInt (tickWidth) + 5)
  291. .withTrimmedRight (2),
  292. Justification::centredLeft, 10);
  293. }
  294. void LookAndFeel_V2::changeToggleButtonWidthToFitText (ToggleButton& button)
  295. {
  296. auto fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  297. auto tickWidth = fontSize * 1.1f;
  298. Font font (fontSize);
  299. button.setSize (font.getStringWidth (button.getButtonText()) + roundToInt (tickWidth) + 9,
  300. button.getHeight());
  301. }
  302. void LookAndFeel_V2::drawDrawableButton (Graphics& g, DrawableButton& button,
  303. bool /*shouldDrawButtonAsHighlighted*/, bool /*shouldDrawButtonAsDown*/)
  304. {
  305. bool toggleState = button.getToggleState();
  306. g.fillAll (button.findColour (toggleState ? DrawableButton::backgroundOnColourId
  307. : DrawableButton::backgroundColourId));
  308. const int textH = (button.getStyle() == DrawableButton::ImageAboveTextLabel)
  309. ? jmin (16, button.proportionOfHeight (0.25f))
  310. : 0;
  311. if (textH > 0)
  312. {
  313. g.setFont ((float) textH);
  314. g.setColour (button.findColour (toggleState ? DrawableButton::textColourOnId
  315. : DrawableButton::textColourId)
  316. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.4f));
  317. g.drawFittedText (button.getButtonText(),
  318. 2, button.getHeight() - textH - 1,
  319. button.getWidth() - 4, textH,
  320. Justification::centred, 1);
  321. }
  322. }
  323. //==============================================================================
  324. AlertWindow* LookAndFeel_V2::createAlertWindow (const String& title, const String& message,
  325. const String& button1, const String& button2, const String& button3,
  326. AlertWindow::AlertIconType iconType,
  327. int numButtons, Component* associatedComponent)
  328. {
  329. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  330. if (numButtons == 1)
  331. {
  332. aw->addButton (button1, 0,
  333. KeyPress (KeyPress::escapeKey),
  334. KeyPress (KeyPress::returnKey));
  335. }
  336. else
  337. {
  338. const KeyPress button1ShortCut ((int) CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  339. KeyPress button2ShortCut ((int) CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  340. if (button1ShortCut == button2ShortCut)
  341. button2ShortCut = KeyPress();
  342. if (numButtons == 2)
  343. {
  344. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey), button1ShortCut);
  345. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey), button2ShortCut);
  346. }
  347. else if (numButtons == 3)
  348. {
  349. aw->addButton (button1, 1, button1ShortCut);
  350. aw->addButton (button2, 2, button2ShortCut);
  351. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey));
  352. }
  353. }
  354. return aw;
  355. }
  356. void LookAndFeel_V2::drawAlertBox (Graphics& g, AlertWindow& alert,
  357. const Rectangle<int>& textArea, TextLayout& textLayout)
  358. {
  359. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  360. int iconSpaceUsed = 0;
  361. const int iconWidth = 80;
  362. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  363. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  364. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  365. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  366. iconSize, iconSize);
  367. if (alert.getAlertType() != AlertWindow::NoIcon)
  368. {
  369. Path icon;
  370. uint32 colour;
  371. char character;
  372. if (alert.getAlertType() == AlertWindow::WarningIcon)
  373. {
  374. colour = 0x55ff5555;
  375. character = '!';
  376. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  377. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  378. (float) iconRect.getX(), (float) iconRect.getBottom());
  379. icon = icon.createPathWithRoundedCorners (5.0f);
  380. }
  381. else
  382. {
  383. colour = alert.getAlertType() == AlertWindow::InfoIcon ? (uint32) 0x605555ff : (uint32) 0x40b69900;
  384. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  385. icon.addEllipse (iconRect.toFloat());
  386. }
  387. GlyphArrangement ga;
  388. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  389. String::charToString ((juce_wchar) (uint8) character),
  390. (float) iconRect.getX(), (float) iconRect.getY(),
  391. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  392. Justification::centred, false);
  393. ga.createPath (icon);
  394. icon.setUsingNonZeroWinding (false);
  395. g.setColour (Colour (colour));
  396. g.fillPath (icon);
  397. iconSpaceUsed = iconWidth;
  398. }
  399. g.setColour (alert.findColour (AlertWindow::textColourId));
  400. textLayout.draw (g, Rectangle<int> (textArea.getX() + iconSpaceUsed,
  401. textArea.getY(),
  402. textArea.getWidth() - iconSpaceUsed,
  403. textArea.getHeight()).toFloat());
  404. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  405. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  406. }
  407. int LookAndFeel_V2::getAlertBoxWindowFlags()
  408. {
  409. return ComponentPeer::windowAppearsOnTaskbar
  410. | ComponentPeer::windowHasDropShadow;
  411. }
  412. Array<int> LookAndFeel_V2::getWidthsForTextButtons (AlertWindow&, const Array<TextButton*>& buttons)
  413. {
  414. const int n = buttons.size();
  415. Array<int> buttonWidths;
  416. const int buttonHeight = getAlertWindowButtonHeight();
  417. for (int i = 0; i < n; ++i)
  418. buttonWidths.add (getTextButtonWidthToFitText (*buttons.getReference (i), buttonHeight));
  419. return buttonWidths;
  420. }
  421. int LookAndFeel_V2::getAlertWindowButtonHeight()
  422. {
  423. return 28;
  424. }
  425. Font LookAndFeel_V2::getAlertWindowTitleFont()
  426. {
  427. Font messageFont = getAlertWindowMessageFont();
  428. return messageFont.withHeight (messageFont.getHeight() * 1.1f).boldened();
  429. }
  430. Font LookAndFeel_V2::getAlertWindowMessageFont()
  431. {
  432. return Font (15.0f);
  433. }
  434. Font LookAndFeel_V2::getAlertWindowFont()
  435. {
  436. return Font (12.0f);
  437. }
  438. //==============================================================================
  439. void LookAndFeel_V2::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  440. int width, int height,
  441. double progress, const String& textToShow)
  442. {
  443. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  444. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  445. g.fillAll (background);
  446. if (progress >= 0.0f && progress < 1.0f)
  447. {
  448. drawGlassLozenge (g, 1.0f, 1.0f,
  449. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  450. (float) (height - 2),
  451. foreground,
  452. 0.5f, 0.0f,
  453. true, true, true, true);
  454. }
  455. else
  456. {
  457. // spinning bar..
  458. g.setColour (foreground);
  459. const int stripeWidth = height * 2;
  460. const int position = (int) (Time::getMillisecondCounter() / 15) % stripeWidth;
  461. Path p;
  462. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  463. p.addQuadrilateral (x, 0.0f,
  464. x + stripeWidth * 0.5f, 0.0f,
  465. x, (float) height,
  466. x - stripeWidth * 0.5f, (float) height);
  467. Image im (Image::ARGB, width, height, true);
  468. {
  469. Graphics g2 (im);
  470. drawGlassLozenge (g2, 1.0f, 1.0f,
  471. (float) (width - 2),
  472. (float) (height - 2),
  473. foreground,
  474. 0.5f, 0.0f,
  475. true, true, true, true);
  476. }
  477. g.setTiledImageFill (im, 0, 0, 0.85f);
  478. g.fillPath (p);
  479. }
  480. if (textToShow.isNotEmpty())
  481. {
  482. g.setColour (Colour::contrasting (background, foreground));
  483. g.setFont (height * 0.6f);
  484. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  485. }
  486. }
  487. void LookAndFeel_V2::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  488. {
  489. const float radius = jmin (w, h) * 0.4f;
  490. const float thickness = radius * 0.15f;
  491. Path p;
  492. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  493. radius * 0.6f, thickness,
  494. thickness * 0.5f);
  495. const float cx = x + w * 0.5f;
  496. const float cy = y + h * 0.5f;
  497. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  498. for (uint32 i = 0; i < 12; ++i)
  499. {
  500. const uint32 n = (i + 12 - animationIndex) % 12;
  501. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  502. g.fillPath (p, AffineTransform::rotation (i * (MathConstants<float>::pi / 6.0f))
  503. .translated (cx, cy));
  504. }
  505. }
  506. bool LookAndFeel_V2::isProgressBarOpaque (ProgressBar& progressBar)
  507. {
  508. return progressBar.findColour (ProgressBar::backgroundColourId).isOpaque();
  509. }
  510. bool LookAndFeel_V2::areScrollbarButtonsVisible()
  511. {
  512. return true;
  513. }
  514. void LookAndFeel_V2::drawScrollbarButton (Graphics& g, ScrollBar& scrollbar,
  515. int width, int height, int buttonDirection,
  516. bool /*isScrollbarVertical*/,
  517. bool /*shouldDrawButtonAsHighlighted*/,
  518. bool shouldDrawButtonAsDown)
  519. {
  520. Path p;
  521. if (buttonDirection == 0)
  522. p.addTriangle (width * 0.5f, height * 0.2f,
  523. width * 0.1f, height * 0.7f,
  524. width * 0.9f, height * 0.7f);
  525. else if (buttonDirection == 1)
  526. p.addTriangle (width * 0.8f, height * 0.5f,
  527. width * 0.3f, height * 0.1f,
  528. width * 0.3f, height * 0.9f);
  529. else if (buttonDirection == 2)
  530. p.addTriangle (width * 0.5f, height * 0.8f,
  531. width * 0.1f, height * 0.3f,
  532. width * 0.9f, height * 0.3f);
  533. else if (buttonDirection == 3)
  534. p.addTriangle (width * 0.2f, height * 0.5f,
  535. width * 0.7f, height * 0.1f,
  536. width * 0.7f, height * 0.9f);
  537. if (shouldDrawButtonAsDown)
  538. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  539. else
  540. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  541. g.fillPath (p);
  542. g.setColour (Colour (0x80000000));
  543. g.strokePath (p, PathStrokeType (0.5f));
  544. }
  545. void LookAndFeel_V2::drawScrollbar (Graphics& g,
  546. ScrollBar& scrollbar,
  547. int x, int y,
  548. int width, int height,
  549. bool isScrollbarVertical,
  550. int thumbStartPosition,
  551. int thumbSize,
  552. bool /*isMouseOver*/,
  553. bool /*isMouseDown*/)
  554. {
  555. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  556. Path slotPath, thumbPath;
  557. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  558. const float slotIndentx2 = slotIndent * 2.0f;
  559. const float thumbIndent = slotIndent + 1.0f;
  560. const float thumbIndentx2 = thumbIndent * 2.0f;
  561. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  562. if (isScrollbarVertical)
  563. {
  564. slotPath.addRoundedRectangle (x + slotIndent,
  565. y + slotIndent,
  566. width - slotIndentx2,
  567. height - slotIndentx2,
  568. (width - slotIndentx2) * 0.5f);
  569. if (thumbSize > 0)
  570. thumbPath.addRoundedRectangle (x + thumbIndent,
  571. thumbStartPosition + thumbIndent,
  572. width - thumbIndentx2,
  573. thumbSize - thumbIndentx2,
  574. (width - thumbIndentx2) * 0.5f);
  575. gx1 = (float) x;
  576. gx2 = x + width * 0.7f;
  577. }
  578. else
  579. {
  580. slotPath.addRoundedRectangle (x + slotIndent,
  581. y + slotIndent,
  582. width - slotIndentx2,
  583. height - slotIndentx2,
  584. (height - slotIndentx2) * 0.5f);
  585. if (thumbSize > 0)
  586. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  587. y + thumbIndent,
  588. thumbSize - thumbIndentx2,
  589. height - thumbIndentx2,
  590. (height - thumbIndentx2) * 0.5f);
  591. gy1 = (float) y;
  592. gy2 = y + height * 0.7f;
  593. }
  594. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  595. Colour trackColour1, trackColour2;
  596. if (scrollbar.isColourSpecified (ScrollBar::trackColourId)
  597. || isColourSpecified (ScrollBar::trackColourId))
  598. {
  599. trackColour1 = trackColour2 = scrollbar.findColour (ScrollBar::trackColourId);
  600. }
  601. else
  602. {
  603. trackColour1 = thumbColour.overlaidWith (Colour (0x44000000));
  604. trackColour2 = thumbColour.overlaidWith (Colour (0x19000000));
  605. }
  606. g.setGradientFill (ColourGradient (trackColour1, gx1, gy1,
  607. trackColour2, gx2, gy2, false));
  608. g.fillPath (slotPath);
  609. if (isScrollbarVertical)
  610. {
  611. gx1 = x + width * 0.6f;
  612. gx2 = (float) x + width;
  613. }
  614. else
  615. {
  616. gy1 = y + height * 0.6f;
  617. gy2 = (float) y + height;
  618. }
  619. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  620. Colour (0x19000000), gx2, gy2, false));
  621. g.fillPath (slotPath);
  622. g.setColour (thumbColour);
  623. g.fillPath (thumbPath);
  624. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  625. Colours::transparentBlack, gx2, gy2, false));
  626. {
  627. Graphics::ScopedSaveState ss (g);
  628. if (isScrollbarVertical)
  629. g.reduceClipRegion (x + width / 2, y, width, height);
  630. else
  631. g.reduceClipRegion (x, y + height / 2, width, height);
  632. g.fillPath (thumbPath);
  633. }
  634. g.setColour (Colour (0x4c000000));
  635. g.strokePath (thumbPath, PathStrokeType (0.4f));
  636. }
  637. ImageEffectFilter* LookAndFeel_V2::getScrollbarEffect()
  638. {
  639. return nullptr;
  640. }
  641. int LookAndFeel_V2::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  642. {
  643. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  644. }
  645. int LookAndFeel_V2::getDefaultScrollbarWidth()
  646. {
  647. return 18;
  648. }
  649. int LookAndFeel_V2::getScrollbarButtonSize (ScrollBar& scrollbar)
  650. {
  651. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  652. : scrollbar.getHeight());
  653. }
  654. //==============================================================================
  655. void LookAndFeel_V2::drawTreeviewPlusMinusBox (Graphics& g, const Rectangle<float>& area,
  656. Colour /*backgroundColour*/, bool isOpen, bool /*isMouseOver*/)
  657. {
  658. auto boxSize = roundToInt (jmin (16.0f, area.getWidth(), area.getHeight()) * 0.7f) | 1;
  659. auto x = ((int) area.getWidth() - boxSize) / 2 + (int) area.getX();
  660. auto y = ((int) area.getHeight() - boxSize) / 2 + (int) area.getY();
  661. Rectangle<float> boxArea ((float) x, (float) y, (float) boxSize, (float) boxSize);
  662. g.setColour (Colour (0xe5ffffff));
  663. g.fillRect (boxArea);
  664. g.setColour (Colour (0x80000000));
  665. g.drawRect (boxArea);
  666. auto size = boxSize / 2 + 1.0f;
  667. auto centre = (float) (boxSize / 2);
  668. g.fillRect (x + (boxSize - size) * 0.5f, y + centre, size, 1.0f);
  669. if (! isOpen)
  670. g.fillRect (x + centre, y + (boxSize - size) * 0.5f, 1.0f, size);
  671. }
  672. bool LookAndFeel_V2::areLinesDrawnForTreeView (TreeView&)
  673. {
  674. return true;
  675. }
  676. int LookAndFeel_V2::getTreeViewIndentSize (TreeView&)
  677. {
  678. return 24;
  679. }
  680. //==============================================================================
  681. void LookAndFeel_V2::drawBubble (Graphics& g, BubbleComponent& comp,
  682. const Point<float>& tip, const Rectangle<float>& body)
  683. {
  684. Path p;
  685. p.addBubble (body.reduced (0.5f), body.getUnion (Rectangle<float> (tip.x, tip.y, 1.0f, 1.0f)),
  686. tip, 5.0f, jmin (15.0f, body.getWidth() * 0.2f, body.getHeight() * 0.2f));
  687. g.setColour (comp.findColour (BubbleComponent::backgroundColourId));
  688. g.fillPath (p);
  689. g.setColour (comp.findColour (BubbleComponent::outlineColourId));
  690. g.strokePath (p, PathStrokeType (1.0f));
  691. }
  692. //==============================================================================
  693. Font LookAndFeel_V2::getPopupMenuFont()
  694. {
  695. return Font (17.0f);
  696. }
  697. void LookAndFeel_V2::getIdealPopupMenuItemSize (const String& text, const bool isSeparator,
  698. int standardMenuItemHeight, int& idealWidth, int& idealHeight)
  699. {
  700. if (isSeparator)
  701. {
  702. idealWidth = 50;
  703. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  704. }
  705. else
  706. {
  707. Font font (getPopupMenuFont());
  708. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  709. font.setHeight (standardMenuItemHeight / 1.3f);
  710. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  711. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  712. }
  713. }
  714. void LookAndFeel_V2::drawPopupMenuBackground (Graphics& g, int width, int height)
  715. {
  716. auto background = findColour (PopupMenu::backgroundColourId);
  717. g.fillAll (background);
  718. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  719. for (int i = 0; i < height; i += 3)
  720. g.fillRect (0, i, width, 1);
  721. #if ! JUCE_MAC
  722. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  723. g.drawRect (0, 0, width, height);
  724. #endif
  725. }
  726. void LookAndFeel_V2::drawPopupMenuUpDownArrow (Graphics& g, int width, int height, bool isScrollUpArrow)
  727. {
  728. auto background = findColour (PopupMenu::backgroundColourId);
  729. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  730. background.withAlpha (0.0f),
  731. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  732. false));
  733. g.fillRect (1, 1, width - 2, height - 2);
  734. auto hw = width * 0.5f;
  735. auto arrowW = height * 0.3f;
  736. auto y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  737. auto y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  738. Path p;
  739. p.addTriangle (hw - arrowW, y1,
  740. hw + arrowW, y1,
  741. hw, y2);
  742. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  743. g.fillPath (p);
  744. }
  745. void LookAndFeel_V2::drawPopupMenuItem (Graphics& g, const Rectangle<int>& area,
  746. const bool isSeparator, const bool isActive,
  747. const bool isHighlighted, const bool isTicked,
  748. const bool hasSubMenu, const String& text,
  749. const String& shortcutKeyText,
  750. const Drawable* icon, const Colour* const textColourToUse)
  751. {
  752. if (isSeparator)
  753. {
  754. auto r = area.reduced (5, 0);
  755. r.removeFromTop (r.getHeight() / 2 - 1);
  756. g.setColour (Colour (0x33000000));
  757. g.fillRect (r.removeFromTop (1));
  758. g.setColour (Colour (0x66ffffff));
  759. g.fillRect (r.removeFromTop (1));
  760. }
  761. else
  762. {
  763. auto textColour = findColour (PopupMenu::textColourId);
  764. if (textColourToUse != nullptr)
  765. textColour = *textColourToUse;
  766. auto r = area.reduced (1);
  767. if (isHighlighted)
  768. {
  769. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  770. g.fillRect (r);
  771. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  772. }
  773. else
  774. {
  775. g.setColour (textColour);
  776. }
  777. if (! isActive)
  778. g.setOpacity (0.3f);
  779. Font font (getPopupMenuFont());
  780. auto maxFontHeight = area.getHeight() / 1.3f;
  781. if (font.getHeight() > maxFontHeight)
  782. font.setHeight (maxFontHeight);
  783. g.setFont (font);
  784. auto iconArea = r.removeFromLeft ((r.getHeight() * 5) / 4).reduced (3).toFloat();
  785. if (icon != nullptr)
  786. {
  787. icon->drawWithin (g, iconArea, RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, 1.0f);
  788. }
  789. else if (isTicked)
  790. {
  791. auto tick = getTickShape (1.0f);
  792. g.fillPath (tick, tick.getTransformToScaleToFit (iconArea, true));
  793. }
  794. if (hasSubMenu)
  795. {
  796. auto arrowH = 0.6f * getPopupMenuFont().getAscent();
  797. auto x = (float) r.removeFromRight ((int) arrowH).getX();
  798. auto halfH = (float) r.getCentreY();
  799. Path p;
  800. p.addTriangle (x, halfH - arrowH * 0.5f,
  801. x, halfH + arrowH * 0.5f,
  802. x + arrowH * 0.6f, halfH);
  803. g.fillPath (p);
  804. }
  805. r.removeFromRight (3);
  806. g.drawFittedText (text, r, Justification::centredLeft, 1);
  807. if (shortcutKeyText.isNotEmpty())
  808. {
  809. Font f2 (font);
  810. f2.setHeight (f2.getHeight() * 0.75f);
  811. f2.setHorizontalScale (0.95f);
  812. g.setFont (f2);
  813. g.drawText (shortcutKeyText, r, Justification::centredRight, true);
  814. }
  815. }
  816. }
  817. void LookAndFeel_V2::drawPopupMenuSectionHeader (Graphics& g, const Rectangle<int>& area, const String& sectionName)
  818. {
  819. g.setFont (getPopupMenuFont().boldened());
  820. g.setColour (findColour (PopupMenu::headerTextColourId));
  821. g.drawFittedText (sectionName,
  822. area.getX() + 12, area.getY(), area.getWidth() - 16, (int) (area.getHeight() * 0.8f),
  823. Justification::bottomLeft, 1);
  824. }
  825. //==============================================================================
  826. int LookAndFeel_V2::getMenuWindowFlags()
  827. {
  828. return ComponentPeer::windowHasDropShadow;
  829. }
  830. void LookAndFeel_V2::drawMenuBarBackground (Graphics& g, int width, int height, bool, MenuBarComponent& menuBar)
  831. {
  832. auto baseColour = LookAndFeelHelpers::createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId),
  833. false, false, false);
  834. if (menuBar.isEnabled())
  835. drawShinyButtonShape (g, -4.0f, 0.0f, width + 8.0f, (float) height,
  836. 0.0f, baseColour, 0.4f, true, true, true, true);
  837. else
  838. g.fillAll (baseColour);
  839. }
  840. Font LookAndFeel_V2::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  841. {
  842. return Font (menuBar.getHeight() * 0.7f);
  843. }
  844. int LookAndFeel_V2::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  845. {
  846. return getMenuBarFont (menuBar, itemIndex, itemText)
  847. .getStringWidth (itemText) + menuBar.getHeight();
  848. }
  849. void LookAndFeel_V2::drawMenuBarItem (Graphics& g, int width, int height,
  850. int itemIndex, const String& itemText,
  851. bool isMouseOverItem, bool isMenuOpen,
  852. bool /*isMouseOverBar*/, MenuBarComponent& menuBar)
  853. {
  854. if (! menuBar.isEnabled())
  855. {
  856. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  857. .withMultipliedAlpha (0.5f));
  858. }
  859. else if (isMenuOpen || isMouseOverItem)
  860. {
  861. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  862. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  863. }
  864. else
  865. {
  866. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  867. }
  868. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  869. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  870. }
  871. Component* LookAndFeel_V2::getParentComponentForMenuOptions (const PopupMenu::Options& options)
  872. {
  873. return options.getParentComponent();
  874. }
  875. void LookAndFeel_V2::preparePopupMenuWindow (Component&) {}
  876. bool LookAndFeel_V2::shouldPopupMenuScaleWithTargetComponent (const PopupMenu::Options&) { return true; }
  877. int LookAndFeel_V2::getPopupMenuBorderSize() { return 2; }
  878. //==============================================================================
  879. void LookAndFeel_V2::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/, TextEditor& textEditor)
  880. {
  881. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  882. }
  883. void LookAndFeel_V2::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  884. {
  885. if (textEditor.isEnabled())
  886. {
  887. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  888. {
  889. const int border = 2;
  890. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  891. g.drawRect (0, 0, width, height, border);
  892. g.setOpacity (1.0f);
  893. auto shadowColour = textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f);
  894. drawBevel (g, 0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  895. }
  896. else
  897. {
  898. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  899. g.drawRect (0, 0, width, height);
  900. g.setOpacity (1.0f);
  901. auto shadowColour = textEditor.findColour (TextEditor::shadowColourId);
  902. drawBevel (g, 0, 0, width, height + 2, 3, shadowColour, shadowColour);
  903. }
  904. }
  905. }
  906. CaretComponent* LookAndFeel_V2::createCaretComponent (Component* keyFocusOwner)
  907. {
  908. return new CaretComponent (keyFocusOwner);
  909. }
  910. //==============================================================================
  911. void LookAndFeel_V2::drawComboBox (Graphics& g, int width, int height, const bool isMouseButtonDown,
  912. int buttonX, int buttonY, int buttonW, int buttonH, ComboBox& box)
  913. {
  914. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  915. if (box.isEnabled() && box.hasKeyboardFocus (false))
  916. {
  917. g.setColour (box.findColour (ComboBox::focusedOutlineColourId));
  918. g.drawRect (0, 0, width, height, 2);
  919. }
  920. else
  921. {
  922. g.setColour (box.findColour (ComboBox::outlineColourId));
  923. g.drawRect (0, 0, width, height);
  924. }
  925. auto outlineThickness = box.isEnabled() ? (isMouseButtonDown ? 1.2f : 0.5f) : 0.3f;
  926. auto baseColour = LookAndFeelHelpers::createBaseColour (box.findColour (ComboBox::buttonColourId),
  927. box.hasKeyboardFocus (true),
  928. false, isMouseButtonDown)
  929. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f);
  930. drawGlassLozenge (g,
  931. buttonX + outlineThickness, buttonY + outlineThickness,
  932. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  933. baseColour, outlineThickness, -1.0f,
  934. true, true, true, true);
  935. if (box.isEnabled())
  936. {
  937. const float arrowX = 0.3f;
  938. const float arrowH = 0.2f;
  939. Path p;
  940. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  941. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  942. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  943. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  944. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  945. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  946. g.setColour (box.findColour (ComboBox::arrowColourId));
  947. g.fillPath (p);
  948. }
  949. }
  950. Font LookAndFeel_V2::getComboBoxFont (ComboBox& box)
  951. {
  952. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  953. }
  954. Label* LookAndFeel_V2::createComboBoxTextBox (ComboBox&)
  955. {
  956. return new Label (String(), String());
  957. }
  958. void LookAndFeel_V2::positionComboBoxText (ComboBox& box, Label& label)
  959. {
  960. label.setBounds (1, 1,
  961. box.getWidth() + 3 - box.getHeight(),
  962. box.getHeight() - 2);
  963. label.setFont (getComboBoxFont (box));
  964. }
  965. PopupMenu::Options LookAndFeel_V2::getOptionsForComboBoxPopupMenu (ComboBox& box, Label& label)
  966. {
  967. return PopupMenu::Options().withTargetComponent (&box)
  968. .withItemThatMustBeVisible (box.getSelectedId())
  969. .withMinimumWidth (box.getWidth())
  970. .withMaximumNumColumns (1)
  971. .withStandardItemHeight (label.getHeight());
  972. }
  973. void LookAndFeel_V2::drawComboBoxTextWhenNothingSelected (Graphics& g, ComboBox& box, Label& label)
  974. {
  975. g.setColour (findColour (ComboBox::textColourId).withMultipliedAlpha (0.5f));
  976. auto font = label.getLookAndFeel().getLabelFont (label);
  977. g.setFont (font);
  978. auto textArea = getLabelBorderSize (label).subtractedFrom (label.getLocalBounds());
  979. g.drawFittedText (box.getTextWhenNothingSelected(), textArea, label.getJustificationType(),
  980. jmax (1, (int) (textArea.getHeight() / font.getHeight())),
  981. label.getMinimumHorizontalScale());
  982. }
  983. //==============================================================================
  984. Font LookAndFeel_V2::getLabelFont (Label& label)
  985. {
  986. return label.getFont();
  987. }
  988. void LookAndFeel_V2::drawLabel (Graphics& g, Label& label)
  989. {
  990. g.fillAll (label.findColour (Label::backgroundColourId));
  991. if (! label.isBeingEdited())
  992. {
  993. auto alpha = label.isEnabled() ? 1.0f : 0.5f;
  994. const Font font (getLabelFont (label));
  995. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  996. g.setFont (font);
  997. auto textArea = getLabelBorderSize (label).subtractedFrom (label.getLocalBounds());
  998. g.drawFittedText (label.getText(), textArea, label.getJustificationType(),
  999. jmax (1, (int) (textArea.getHeight() / font.getHeight())),
  1000. label.getMinimumHorizontalScale());
  1001. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  1002. }
  1003. else if (label.isEnabled())
  1004. {
  1005. g.setColour (label.findColour (Label::outlineColourId));
  1006. }
  1007. g.drawRect (label.getLocalBounds());
  1008. }
  1009. BorderSize<int> LookAndFeel_V2::getLabelBorderSize (Label& label)
  1010. {
  1011. return label.getBorderSize();
  1012. }
  1013. //==============================================================================
  1014. void LookAndFeel_V2::drawLinearSliderBackground (Graphics& g, int x, int y, int width, int height,
  1015. float /*sliderPos*/,
  1016. float /*minSliderPos*/,
  1017. float /*maxSliderPos*/,
  1018. const Slider::SliderStyle /*style*/, Slider& slider)
  1019. {
  1020. auto sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  1021. auto trackColour = slider.findColour (Slider::trackColourId);
  1022. auto gradCol1 = trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f));
  1023. auto gradCol2 = trackColour.overlaidWith (Colour (0x14000000));
  1024. Path indent;
  1025. if (slider.isHorizontal())
  1026. {
  1027. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  1028. const float ih = sliderRadius;
  1029. g.setGradientFill (ColourGradient::vertical (gradCol1, iy, gradCol2, iy + ih));
  1030. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  1031. width + sliderRadius, ih,
  1032. 5.0f);
  1033. }
  1034. else
  1035. {
  1036. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  1037. const float iw = sliderRadius;
  1038. g.setGradientFill (ColourGradient::horizontal (gradCol1, ix, gradCol2, ix + iw));
  1039. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  1040. iw, height + sliderRadius,
  1041. 5.0f);
  1042. }
  1043. g.fillPath (indent);
  1044. g.setColour (Colour (0x4c000000));
  1045. g.strokePath (indent, PathStrokeType (0.5f));
  1046. }
  1047. void LookAndFeel_V2::drawLinearSliderThumb (Graphics& g, int x, int y, int width, int height,
  1048. float sliderPos, float minSliderPos, float maxSliderPos,
  1049. const Slider::SliderStyle style, Slider& slider)
  1050. {
  1051. auto sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  1052. auto knobColour = LookAndFeelHelpers::createBaseColour (slider.findColour (Slider::thumbColourId),
  1053. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  1054. slider.isMouseOverOrDragging() && slider.isEnabled(),
  1055. slider.isMouseButtonDown() && slider.isEnabled());
  1056. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  1057. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  1058. {
  1059. float kx, ky;
  1060. if (style == Slider::LinearVertical)
  1061. {
  1062. kx = x + width * 0.5f;
  1063. ky = sliderPos;
  1064. }
  1065. else
  1066. {
  1067. kx = sliderPos;
  1068. ky = y + height * 0.5f;
  1069. }
  1070. drawGlassSphere (g,
  1071. kx - sliderRadius,
  1072. ky - sliderRadius,
  1073. sliderRadius * 2.0f,
  1074. knobColour, outlineThickness);
  1075. }
  1076. else
  1077. {
  1078. if (style == Slider::ThreeValueVertical)
  1079. {
  1080. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  1081. sliderPos - sliderRadius,
  1082. sliderRadius * 2.0f,
  1083. knobColour, outlineThickness);
  1084. }
  1085. else if (style == Slider::ThreeValueHorizontal)
  1086. {
  1087. drawGlassSphere (g,sliderPos - sliderRadius,
  1088. y + height * 0.5f - sliderRadius,
  1089. sliderRadius * 2.0f,
  1090. knobColour, outlineThickness);
  1091. }
  1092. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  1093. {
  1094. auto sr = jmin (sliderRadius, width * 0.4f);
  1095. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  1096. minSliderPos - sliderRadius,
  1097. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  1098. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  1099. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  1100. }
  1101. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  1102. {
  1103. auto sr = jmin (sliderRadius, height * 0.4f);
  1104. drawGlassPointer (g, minSliderPos - sr,
  1105. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  1106. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  1107. drawGlassPointer (g, maxSliderPos - sliderRadius,
  1108. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  1109. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  1110. }
  1111. }
  1112. }
  1113. void LookAndFeel_V2::drawLinearSlider (Graphics& g, int x, int y, int width, int height,
  1114. float sliderPos, float minSliderPos, float maxSliderPos,
  1115. const Slider::SliderStyle style, Slider& slider)
  1116. {
  1117. g.fillAll (slider.findColour (Slider::backgroundColourId));
  1118. if (style == Slider::LinearBar || style == Slider::LinearBarVertical)
  1119. {
  1120. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  1121. auto baseColour = LookAndFeelHelpers::createBaseColour (slider.findColour (Slider::thumbColourId)
  1122. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  1123. false, isMouseOver,
  1124. isMouseOver || slider.isMouseButtonDown());
  1125. drawShinyButtonShape (g,
  1126. (float) x,
  1127. style == Slider::LinearBarVertical ? sliderPos
  1128. : (float) y,
  1129. style == Slider::LinearBarVertical ? (float) width
  1130. : (sliderPos - x),
  1131. style == Slider::LinearBarVertical ? (height - sliderPos)
  1132. : (float) height, 0.0f,
  1133. baseColour,
  1134. slider.isEnabled() ? 0.9f : 0.3f,
  1135. true, true, true, true);
  1136. }
  1137. else
  1138. {
  1139. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  1140. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  1141. }
  1142. }
  1143. int LookAndFeel_V2::getSliderThumbRadius (Slider& slider)
  1144. {
  1145. return jmin (7,
  1146. slider.getHeight() / 2,
  1147. slider.getWidth() / 2) + 2;
  1148. }
  1149. void LookAndFeel_V2::drawRotarySlider (Graphics& g, int x, int y, int width, int height, float sliderPos,
  1150. const float rotaryStartAngle, const float rotaryEndAngle, Slider& slider)
  1151. {
  1152. const float radius = jmin (width / 2, height / 2) - 2.0f;
  1153. const float centreX = x + width * 0.5f;
  1154. const float centreY = y + height * 0.5f;
  1155. const float rx = centreX - radius;
  1156. const float ry = centreY - radius;
  1157. const float rw = radius * 2.0f;
  1158. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  1159. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  1160. if (radius > 12.0f)
  1161. {
  1162. if (slider.isEnabled())
  1163. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  1164. else
  1165. g.setColour (Colour (0x80808080));
  1166. const float thickness = 0.7f;
  1167. {
  1168. Path filledArc;
  1169. filledArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, angle, thickness);
  1170. g.fillPath (filledArc);
  1171. }
  1172. {
  1173. const float innerRadius = radius * 0.2f;
  1174. Path p;
  1175. p.addTriangle (-innerRadius, 0.0f,
  1176. 0.0f, -radius * thickness * 1.1f,
  1177. innerRadius, 0.0f);
  1178. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  1179. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  1180. }
  1181. if (slider.isEnabled())
  1182. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  1183. else
  1184. g.setColour (Colour (0x80808080));
  1185. Path outlineArc;
  1186. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  1187. outlineArc.closeSubPath();
  1188. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  1189. }
  1190. else
  1191. {
  1192. if (slider.isEnabled())
  1193. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  1194. else
  1195. g.setColour (Colour (0x80808080));
  1196. Path p;
  1197. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  1198. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  1199. p.addLineSegment (Line<float> (0.0f, 0.0f, 0.0f, -radius), rw * 0.2f);
  1200. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  1201. }
  1202. }
  1203. Button* LookAndFeel_V2::createSliderButton (Slider&, const bool isIncrement)
  1204. {
  1205. return new TextButton (isIncrement ? "+" : "-", String());
  1206. }
  1207. class LookAndFeel_V2::SliderLabelComp : public Label
  1208. {
  1209. public:
  1210. SliderLabelComp() : Label ({}, {}) {}
  1211. void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override {}
  1212. };
  1213. Label* LookAndFeel_V2::createSliderTextBox (Slider& slider)
  1214. {
  1215. auto l = new SliderLabelComp();
  1216. l->setJustificationType (Justification::centred);
  1217. l->setKeyboardType (TextInputTarget::decimalKeyboard);
  1218. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  1219. l->setColour (Label::backgroundColourId,
  1220. (slider.getSliderStyle() == Slider::LinearBar || slider.getSliderStyle() == Slider::LinearBarVertical)
  1221. ? Colours::transparentBlack
  1222. : slider.findColour (Slider::textBoxBackgroundColourId));
  1223. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  1224. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  1225. l->setColour (TextEditor::backgroundColourId,
  1226. slider.findColour (Slider::textBoxBackgroundColourId)
  1227. .withAlpha ((slider.getSliderStyle() == Slider::LinearBar || slider.getSliderStyle() == Slider::LinearBarVertical)
  1228. ? 0.7f : 1.0f));
  1229. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  1230. l->setColour (TextEditor::highlightColourId, slider.findColour (Slider::textBoxHighlightColourId));
  1231. return l;
  1232. }
  1233. ImageEffectFilter* LookAndFeel_V2::getSliderEffect (Slider&)
  1234. {
  1235. return nullptr;
  1236. }
  1237. Font LookAndFeel_V2::getSliderPopupFont (Slider&)
  1238. {
  1239. return Font (15.0f, Font::bold);
  1240. }
  1241. int LookAndFeel_V2::getSliderPopupPlacement (Slider&)
  1242. {
  1243. return BubbleComponent::above
  1244. | BubbleComponent::below
  1245. | BubbleComponent::left
  1246. | BubbleComponent::right;
  1247. }
  1248. //==============================================================================
  1249. Slider::SliderLayout LookAndFeel_V2::getSliderLayout (Slider& slider)
  1250. {
  1251. // 1. compute the actually visible textBox size from the slider textBox size and some additional constraints
  1252. int minXSpace = 0;
  1253. int minYSpace = 0;
  1254. auto textBoxPos = slider.getTextBoxPosition();
  1255. if (textBoxPos == Slider::TextBoxLeft || textBoxPos == Slider::TextBoxRight)
  1256. minXSpace = 30;
  1257. else
  1258. minYSpace = 15;
  1259. auto localBounds = slider.getLocalBounds();
  1260. auto textBoxWidth = jmax (0, jmin (slider.getTextBoxWidth(), localBounds.getWidth() - minXSpace));
  1261. auto textBoxHeight = jmax (0, jmin (slider.getTextBoxHeight(), localBounds.getHeight() - minYSpace));
  1262. Slider::SliderLayout layout;
  1263. // 2. set the textBox bounds
  1264. if (textBoxPos != Slider::NoTextBox)
  1265. {
  1266. if (slider.isBar())
  1267. {
  1268. layout.textBoxBounds = localBounds;
  1269. }
  1270. else
  1271. {
  1272. layout.textBoxBounds.setWidth (textBoxWidth);
  1273. layout.textBoxBounds.setHeight (textBoxHeight);
  1274. if (textBoxPos == Slider::TextBoxLeft) layout.textBoxBounds.setX (0);
  1275. else if (textBoxPos == Slider::TextBoxRight) layout.textBoxBounds.setX (localBounds.getWidth() - textBoxWidth);
  1276. else /* above or below -> centre horizontally */ layout.textBoxBounds.setX ((localBounds.getWidth() - textBoxWidth) / 2);
  1277. if (textBoxPos == Slider::TextBoxAbove) layout.textBoxBounds.setY (0);
  1278. else if (textBoxPos == Slider::TextBoxBelow) layout.textBoxBounds.setY (localBounds.getHeight() - textBoxHeight);
  1279. else /* left or right -> centre vertically */ layout.textBoxBounds.setY ((localBounds.getHeight() - textBoxHeight) / 2);
  1280. }
  1281. }
  1282. // 3. set the slider bounds
  1283. layout.sliderBounds = localBounds;
  1284. if (slider.isBar())
  1285. {
  1286. layout.sliderBounds.reduce (1, 1); // bar border
  1287. }
  1288. else
  1289. {
  1290. if (textBoxPos == Slider::TextBoxLeft) layout.sliderBounds.removeFromLeft (textBoxWidth);
  1291. else if (textBoxPos == Slider::TextBoxRight) layout.sliderBounds.removeFromRight (textBoxWidth);
  1292. else if (textBoxPos == Slider::TextBoxAbove) layout.sliderBounds.removeFromTop (textBoxHeight);
  1293. else if (textBoxPos == Slider::TextBoxBelow) layout.sliderBounds.removeFromBottom (textBoxHeight);
  1294. const int thumbIndent = getSliderThumbRadius (slider);
  1295. if (slider.isHorizontal()) layout.sliderBounds.reduce (thumbIndent, 0);
  1296. else if (slider.isVertical()) layout.sliderBounds.reduce (0, thumbIndent);
  1297. }
  1298. return layout;
  1299. }
  1300. //==============================================================================
  1301. Rectangle<int> LookAndFeel_V2::getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea)
  1302. {
  1303. const TextLayout tl (LookAndFeelHelpers::layoutTooltipText (tipText, Colours::black));
  1304. auto w = (int) (tl.getWidth() + 14.0f);
  1305. auto h = (int) (tl.getHeight() + 6.0f);
  1306. return Rectangle<int> (screenPos.x > parentArea.getCentreX() ? screenPos.x - (w + 12) : screenPos.x + 24,
  1307. screenPos.y > parentArea.getCentreY() ? screenPos.y - (h + 6) : screenPos.y + 6,
  1308. w, h)
  1309. .constrainedWithin (parentArea);
  1310. }
  1311. void LookAndFeel_V2::drawTooltip (Graphics& g, const String& text, int width, int height)
  1312. {
  1313. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  1314. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  1315. g.setColour (findColour (TooltipWindow::outlineColourId));
  1316. g.drawRect (0, 0, width, height, 1);
  1317. #endif
  1318. LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId))
  1319. .draw (g, Rectangle<float> ((float) width, (float) height));
  1320. }
  1321. //==============================================================================
  1322. Button* LookAndFeel_V2::createFilenameComponentBrowseButton (const String& text)
  1323. {
  1324. return new TextButton (text, TRANS("click to browse for a different file"));
  1325. }
  1326. void LookAndFeel_V2::layoutFilenameComponent (FilenameComponent& filenameComp,
  1327. ComboBox* filenameBox, Button* browseButton)
  1328. {
  1329. browseButton->setSize (80, filenameComp.getHeight());
  1330. if (auto* tb = dynamic_cast<TextButton*> (browseButton))
  1331. tb->changeWidthToFitText();
  1332. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  1333. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  1334. }
  1335. //==============================================================================
  1336. void LookAndFeel_V2::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int>& area,
  1337. bool isMouseOver, bool /*isMouseDown*/,
  1338. ConcertinaPanel&, Component& panel)
  1339. {
  1340. g.fillAll (Colours::grey.withAlpha (isMouseOver ? 0.9f : 0.7f));
  1341. g.setColour (Colours::black.withAlpha (0.5f));
  1342. g.drawRect (area);
  1343. g.setColour (Colours::white);
  1344. g.setFont (Font (area.getHeight() * 0.7f).boldened());
  1345. g.drawFittedText (panel.getName(), 4, 0, area.getWidth() - 6, area.getHeight(), Justification::centredLeft, 1);
  1346. }
  1347. //==============================================================================
  1348. void LookAndFeel_V2::drawImageButton (Graphics& g, Image* image,
  1349. int imageX, int imageY, int imageW, int imageH,
  1350. const Colour& overlayColour,
  1351. float imageOpacity,
  1352. ImageButton& button)
  1353. {
  1354. if (! button.isEnabled())
  1355. imageOpacity *= 0.3f;
  1356. AffineTransform t = RectanglePlacement (RectanglePlacement::stretchToFit)
  1357. .getTransformToFit (image->getBounds().toFloat(),
  1358. Rectangle<int> (imageX, imageY, imageW, imageH).toFloat());
  1359. if (! overlayColour.isOpaque())
  1360. {
  1361. g.setOpacity (imageOpacity);
  1362. g.drawImageTransformed (*image, t, false);
  1363. }
  1364. if (! overlayColour.isTransparent())
  1365. {
  1366. g.setColour (overlayColour);
  1367. g.drawImageTransformed (*image, t, true);
  1368. }
  1369. }
  1370. //==============================================================================
  1371. void LookAndFeel_V2::drawCornerResizer (Graphics& g, int w, int h, bool /*isMouseOver*/, bool /*isMouseDragging*/)
  1372. {
  1373. auto lineThickness = jmin (w, h) * 0.075f;
  1374. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  1375. {
  1376. g.setColour (Colours::lightgrey);
  1377. g.drawLine (w * i,
  1378. h + 1.0f,
  1379. w + 1.0f,
  1380. h * i,
  1381. lineThickness);
  1382. g.setColour (Colours::darkgrey);
  1383. g.drawLine (w * i + lineThickness,
  1384. h + 1.0f,
  1385. w + 1.0f,
  1386. h * i + lineThickness,
  1387. lineThickness);
  1388. }
  1389. }
  1390. void LookAndFeel_V2::drawResizableFrame (Graphics& g, int w, int h, const BorderSize<int>& border)
  1391. {
  1392. if (! border.isEmpty())
  1393. {
  1394. const Rectangle<int> fullSize (0, 0, w, h);
  1395. auto centreArea = border.subtractedFrom (fullSize);
  1396. Graphics::ScopedSaveState ss (g);
  1397. g.excludeClipRegion (centreArea);
  1398. g.setColour (Colour (0x50000000));
  1399. g.drawRect (fullSize);
  1400. g.setColour (Colour (0x19000000));
  1401. g.drawRect (centreArea.expanded (1, 1));
  1402. }
  1403. }
  1404. //==============================================================================
  1405. void LookAndFeel_V2::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  1406. const BorderSize<int>& /*border*/, ResizableWindow& window)
  1407. {
  1408. g.fillAll (window.getBackgroundColour());
  1409. }
  1410. void LookAndFeel_V2::drawResizableWindowBorder (Graphics&, int /*w*/, int /*h*/,
  1411. const BorderSize<int>& /*border*/, ResizableWindow&)
  1412. {
  1413. }
  1414. void LookAndFeel_V2::drawDocumentWindowTitleBar (DocumentWindow& window, Graphics& g,
  1415. int w, int h, int titleSpaceX, int titleSpaceW,
  1416. const Image* icon, bool drawTitleTextOnLeft)
  1417. {
  1418. if (w * h == 0)
  1419. return;
  1420. const bool isActive = window.isActiveWindow();
  1421. g.setGradientFill (ColourGradient::vertical (window.getBackgroundColour(), 0,
  1422. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f), (float) h));
  1423. g.fillAll();
  1424. Font font (h * 0.65f, Font::bold);
  1425. g.setFont (font);
  1426. int textW = font.getStringWidth (window.getName());
  1427. int iconW = 0;
  1428. int iconH = 0;
  1429. if (icon != nullptr)
  1430. {
  1431. iconH = (int) font.getHeight();
  1432. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  1433. }
  1434. textW = jmin (titleSpaceW, textW + iconW);
  1435. int textX = drawTitleTextOnLeft ? titleSpaceX
  1436. : jmax (titleSpaceX, (w - textW) / 2);
  1437. if (textX + textW > titleSpaceX + titleSpaceW)
  1438. textX = titleSpaceX + titleSpaceW - textW;
  1439. if (icon != nullptr)
  1440. {
  1441. g.setOpacity (isActive ? 1.0f : 0.6f);
  1442. g.drawImageWithin (*icon, textX, (h - iconH) / 2, iconW, iconH,
  1443. RectanglePlacement::centred, false);
  1444. textX += iconW;
  1445. textW -= iconW;
  1446. }
  1447. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  1448. g.setColour (window.findColour (DocumentWindow::textColourId));
  1449. else
  1450. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  1451. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  1452. }
  1453. //==============================================================================
  1454. class LookAndFeel_V2::GlassWindowButton : public Button
  1455. {
  1456. public:
  1457. GlassWindowButton (const String& name, Colour col,
  1458. const Path& normalShape_,
  1459. const Path& toggledShape_) noexcept
  1460. : Button (name),
  1461. colour (col),
  1462. normalShape (normalShape_),
  1463. toggledShape (toggledShape_)
  1464. {
  1465. }
  1466. //==============================================================================
  1467. void paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
  1468. {
  1469. float alpha = shouldDrawButtonAsHighlighted ? (shouldDrawButtonAsDown ? 1.0f : 0.8f) : 0.55f;
  1470. if (! isEnabled())
  1471. alpha *= 0.5f;
  1472. float x = 0, y = 0, diam;
  1473. if (getWidth() < getHeight())
  1474. {
  1475. diam = (float) getWidth();
  1476. y = (getHeight() - getWidth()) * 0.5f;
  1477. }
  1478. else
  1479. {
  1480. diam = (float) getHeight();
  1481. y = (getWidth() - getHeight()) * 0.5f;
  1482. }
  1483. x += diam * 0.05f;
  1484. y += diam * 0.05f;
  1485. diam *= 0.9f;
  1486. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  1487. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  1488. g.fillEllipse (x, y, diam, diam);
  1489. x += 2.0f;
  1490. y += 2.0f;
  1491. diam -= 4.0f;
  1492. LookAndFeel_V2::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  1493. Path& p = getToggleState() ? toggledShape : normalShape;
  1494. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  1495. diam * 0.4f, diam * 0.4f, true));
  1496. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  1497. g.fillPath (p, t);
  1498. }
  1499. private:
  1500. Colour colour;
  1501. Path normalShape, toggledShape;
  1502. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlassWindowButton)
  1503. };
  1504. Button* LookAndFeel_V2::createDocumentWindowButton (int buttonType)
  1505. {
  1506. Path shape;
  1507. const float crossThickness = 0.25f;
  1508. if (buttonType == DocumentWindow::closeButton)
  1509. {
  1510. shape.addLineSegment (Line<float> (0.0f, 0.0f, 1.0f, 1.0f), crossThickness * 1.4f);
  1511. shape.addLineSegment (Line<float> (1.0f, 0.0f, 0.0f, 1.0f), crossThickness * 1.4f);
  1512. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  1513. }
  1514. if (buttonType == DocumentWindow::minimiseButton)
  1515. {
  1516. shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), crossThickness);
  1517. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  1518. }
  1519. if (buttonType == DocumentWindow::maximiseButton)
  1520. {
  1521. shape.addLineSegment (Line<float> (0.5f, 0.0f, 0.5f, 1.0f), crossThickness);
  1522. shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), crossThickness);
  1523. Path fullscreenShape;
  1524. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  1525. fullscreenShape.lineTo (0.0f, 100.0f);
  1526. fullscreenShape.lineTo (0.0f, 0.0f);
  1527. fullscreenShape.lineTo (100.0f, 0.0f);
  1528. fullscreenShape.lineTo (100.0f, 45.0f);
  1529. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  1530. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  1531. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  1532. }
  1533. jassertfalse;
  1534. return nullptr;
  1535. }
  1536. void LookAndFeel_V2::positionDocumentWindowButtons (DocumentWindow&,
  1537. int titleBarX, int titleBarY,
  1538. int titleBarW, int titleBarH,
  1539. Button* minimiseButton,
  1540. Button* maximiseButton,
  1541. Button* closeButton,
  1542. bool positionTitleBarButtonsOnLeft)
  1543. {
  1544. const int buttonW = titleBarH - titleBarH / 8;
  1545. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  1546. : titleBarX + titleBarW - buttonW - buttonW / 4;
  1547. if (closeButton != nullptr)
  1548. {
  1549. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  1550. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  1551. }
  1552. if (positionTitleBarButtonsOnLeft)
  1553. std::swap (minimiseButton, maximiseButton);
  1554. if (maximiseButton != nullptr)
  1555. {
  1556. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  1557. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  1558. }
  1559. if (minimiseButton != nullptr)
  1560. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  1561. }
  1562. int LookAndFeel_V2::getDefaultMenuBarHeight()
  1563. {
  1564. return 24;
  1565. }
  1566. //==============================================================================
  1567. DropShadower* LookAndFeel_V2::createDropShadowerForComponent (Component*)
  1568. {
  1569. return new DropShadower (DropShadow (Colours::black.withAlpha (0.4f), 10, Point<int> (0, 2)));
  1570. }
  1571. //==============================================================================
  1572. void LookAndFeel_V2::drawStretchableLayoutResizerBar (Graphics& g, int w, int h,
  1573. bool /*isVerticalBar*/,
  1574. bool isMouseOver,
  1575. bool isMouseDragging)
  1576. {
  1577. auto alpha = 0.5f;
  1578. if (isMouseOver || isMouseDragging)
  1579. {
  1580. g.fillAll (Colour (0x190000ff));
  1581. alpha = 1.0f;
  1582. }
  1583. auto cx = w * 0.5f;
  1584. auto cy = h * 0.5f;
  1585. auto cr = jmin (w, h) * 0.4f;
  1586. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  1587. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  1588. true));
  1589. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  1590. }
  1591. //==============================================================================
  1592. void LookAndFeel_V2::drawGroupComponentOutline (Graphics& g, int width, int height,
  1593. const String& text, const Justification& position,
  1594. GroupComponent& group)
  1595. {
  1596. const float textH = 15.0f;
  1597. const float indent = 3.0f;
  1598. const float textEdgeGap = 4.0f;
  1599. auto cs = 5.0f;
  1600. Font f (textH);
  1601. Path p;
  1602. auto x = indent;
  1603. auto y = f.getAscent() - 3.0f;
  1604. auto w = jmax (0.0f, width - x * 2.0f);
  1605. auto h = jmax (0.0f, height - y - indent);
  1606. cs = jmin (cs, w * 0.5f, h * 0.5f);
  1607. auto cs2 = 2.0f * cs;
  1608. auto textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  1609. auto textX = cs + textEdgeGap;
  1610. if (position.testFlags (Justification::horizontallyCentred))
  1611. textX = cs + (w - cs2 - textW) * 0.5f;
  1612. else if (position.testFlags (Justification::right))
  1613. textX = w - cs - textW - textEdgeGap;
  1614. p.startNewSubPath (x + textX + textW, y);
  1615. p.lineTo (x + w - cs, y);
  1616. p.addArc (x + w - cs2, y, cs2, cs2, 0, MathConstants<float>::halfPi);
  1617. p.lineTo (x + w, y + h - cs);
  1618. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, MathConstants<float>::halfPi, MathConstants<float>::pi);
  1619. p.lineTo (x + cs, y + h);
  1620. p.addArc (x, y + h - cs2, cs2, cs2, MathConstants<float>::pi, MathConstants<float>::pi * 1.5f);
  1621. p.lineTo (x, y + cs);
  1622. p.addArc (x, y, cs2, cs2, MathConstants<float>::pi * 1.5f, MathConstants<float>::twoPi);
  1623. p.lineTo (x + textX, y);
  1624. auto alpha = group.isEnabled() ? 1.0f : 0.5f;
  1625. g.setColour (group.findColour (GroupComponent::outlineColourId)
  1626. .withMultipliedAlpha (alpha));
  1627. g.strokePath (p, PathStrokeType (2.0f));
  1628. g.setColour (group.findColour (GroupComponent::textColourId)
  1629. .withMultipliedAlpha (alpha));
  1630. g.setFont (f);
  1631. g.drawText (text,
  1632. roundToInt (x + textX), 0,
  1633. roundToInt (textW),
  1634. roundToInt (textH),
  1635. Justification::centred, true);
  1636. }
  1637. //==============================================================================
  1638. int LookAndFeel_V2::getTabButtonOverlap (int tabDepth)
  1639. {
  1640. return 1 + tabDepth / 3;
  1641. }
  1642. int LookAndFeel_V2::getTabButtonSpaceAroundImage()
  1643. {
  1644. return 4;
  1645. }
  1646. int LookAndFeel_V2::getTabButtonBestWidth (TabBarButton& button, int tabDepth)
  1647. {
  1648. int width = Font (tabDepth * 0.6f).getStringWidth (button.getButtonText().trim())
  1649. + getTabButtonOverlap (tabDepth) * 2;
  1650. if (auto* extraComponent = button.getExtraComponent())
  1651. width += button.getTabbedButtonBar().isVertical() ? extraComponent->getHeight()
  1652. : extraComponent->getWidth();
  1653. return jlimit (tabDepth * 2, tabDepth * 8, width);
  1654. }
  1655. Rectangle<int> LookAndFeel_V2::getTabButtonExtraComponentBounds (const TabBarButton& button, Rectangle<int>& textArea, Component& comp)
  1656. {
  1657. Rectangle<int> extraComp;
  1658. auto orientation = button.getTabbedButtonBar().getOrientation();
  1659. if (button.getExtraComponentPlacement() == TabBarButton::beforeText)
  1660. {
  1661. switch (orientation)
  1662. {
  1663. case TabbedButtonBar::TabsAtBottom:
  1664. case TabbedButtonBar::TabsAtTop: extraComp = textArea.removeFromLeft (comp.getWidth()); break;
  1665. case TabbedButtonBar::TabsAtLeft: extraComp = textArea.removeFromBottom (comp.getHeight()); break;
  1666. case TabbedButtonBar::TabsAtRight: extraComp = textArea.removeFromTop (comp.getHeight()); break;
  1667. default: jassertfalse; break;
  1668. }
  1669. }
  1670. else
  1671. {
  1672. switch (orientation)
  1673. {
  1674. case TabbedButtonBar::TabsAtBottom:
  1675. case TabbedButtonBar::TabsAtTop: extraComp = textArea.removeFromRight (comp.getWidth()); break;
  1676. case TabbedButtonBar::TabsAtLeft: extraComp = textArea.removeFromTop (comp.getHeight()); break;
  1677. case TabbedButtonBar::TabsAtRight: extraComp = textArea.removeFromBottom (comp.getHeight()); break;
  1678. default: jassertfalse; break;
  1679. }
  1680. }
  1681. return extraComp;
  1682. }
  1683. void LookAndFeel_V2::createTabButtonShape (TabBarButton& button, Path& p, bool /*isMouseOver*/, bool /*isMouseDown*/)
  1684. {
  1685. auto activeArea = button.getActiveArea();
  1686. auto w = (float) activeArea.getWidth();
  1687. auto h = (float) activeArea.getHeight();
  1688. auto length = w;
  1689. auto depth = h;
  1690. if (button.getTabbedButtonBar().isVertical())
  1691. std::swap (length, depth);
  1692. const float indent = (float) getTabButtonOverlap ((int) depth);
  1693. const float overhang = 4.0f;
  1694. switch (button.getTabbedButtonBar().getOrientation())
  1695. {
  1696. case TabbedButtonBar::TabsAtLeft:
  1697. p.startNewSubPath (w, 0.0f);
  1698. p.lineTo (0.0f, indent);
  1699. p.lineTo (0.0f, h - indent);
  1700. p.lineTo (w, h);
  1701. p.lineTo (w + overhang, h + overhang);
  1702. p.lineTo (w + overhang, -overhang);
  1703. break;
  1704. case TabbedButtonBar::TabsAtRight:
  1705. p.startNewSubPath (0.0f, 0.0f);
  1706. p.lineTo (w, indent);
  1707. p.lineTo (w, h - indent);
  1708. p.lineTo (0.0f, h);
  1709. p.lineTo (-overhang, h + overhang);
  1710. p.lineTo (-overhang, -overhang);
  1711. break;
  1712. case TabbedButtonBar::TabsAtBottom:
  1713. p.startNewSubPath (0.0f, 0.0f);
  1714. p.lineTo (indent, h);
  1715. p.lineTo (w - indent, h);
  1716. p.lineTo (w, 0.0f);
  1717. p.lineTo (w + overhang, -overhang);
  1718. p.lineTo (-overhang, -overhang);
  1719. break;
  1720. default:
  1721. p.startNewSubPath (0.0f, h);
  1722. p.lineTo (indent, 0.0f);
  1723. p.lineTo (w - indent, 0.0f);
  1724. p.lineTo (w, h);
  1725. p.lineTo (w + overhang, h + overhang);
  1726. p.lineTo (-overhang, h + overhang);
  1727. break;
  1728. }
  1729. p.closeSubPath();
  1730. p = p.createPathWithRoundedCorners (3.0f);
  1731. }
  1732. void LookAndFeel_V2::fillTabButtonShape (TabBarButton& button, Graphics& g, const Path& path,
  1733. bool /*isMouseOver*/, bool /*isMouseDown*/)
  1734. {
  1735. auto tabBackground = button.getTabBackgroundColour();
  1736. const bool isFrontTab = button.isFrontTab();
  1737. g.setColour (isFrontTab ? tabBackground
  1738. : tabBackground.withMultipliedAlpha (0.9f));
  1739. g.fillPath (path);
  1740. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  1741. : TabbedButtonBar::tabOutlineColourId, false)
  1742. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  1743. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  1744. }
  1745. Font LookAndFeel_V2::getTabButtonFont (TabBarButton&, float height)
  1746. {
  1747. return { height * 0.6f };
  1748. }
  1749. void LookAndFeel_V2::drawTabButtonText (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
  1750. {
  1751. auto area = button.getTextArea().toFloat();
  1752. auto length = area.getWidth();
  1753. auto depth = area.getHeight();
  1754. if (button.getTabbedButtonBar().isVertical())
  1755. std::swap (length, depth);
  1756. Font font (getTabButtonFont (button, depth));
  1757. font.setUnderline (button.hasKeyboardFocus (false));
  1758. AffineTransform t;
  1759. switch (button.getTabbedButtonBar().getOrientation())
  1760. {
  1761. case TabbedButtonBar::TabsAtLeft: t = t.rotated (MathConstants<float>::pi * -0.5f).translated (area.getX(), area.getBottom()); break;
  1762. case TabbedButtonBar::TabsAtRight: t = t.rotated (MathConstants<float>::pi * 0.5f).translated (area.getRight(), area.getY()); break;
  1763. case TabbedButtonBar::TabsAtTop:
  1764. case TabbedButtonBar::TabsAtBottom: t = t.translated (area.getX(), area.getY()); break;
  1765. default: jassertfalse; break;
  1766. }
  1767. Colour col;
  1768. if (button.isFrontTab() && (button.isColourSpecified (TabbedButtonBar::frontTextColourId)
  1769. || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  1770. col = findColour (TabbedButtonBar::frontTextColourId);
  1771. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId)
  1772. || isColourSpecified (TabbedButtonBar::tabTextColourId))
  1773. col = findColour (TabbedButtonBar::tabTextColourId);
  1774. else
  1775. col = button.getTabBackgroundColour().contrasting();
  1776. auto alpha = button.isEnabled() ? ((isMouseOver || isMouseDown) ? 1.0f : 0.8f) : 0.3f;
  1777. g.setColour (col.withMultipliedAlpha (alpha));
  1778. g.setFont (font);
  1779. g.addTransform (t);
  1780. g.drawFittedText (button.getButtonText().trim(),
  1781. 0, 0, (int) length, (int) depth,
  1782. Justification::centred,
  1783. jmax (1, ((int) depth) / 12));
  1784. }
  1785. void LookAndFeel_V2::drawTabButton (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
  1786. {
  1787. Path tabShape;
  1788. createTabButtonShape (button, tabShape, isMouseOver, isMouseDown);
  1789. auto activeArea = button.getActiveArea();
  1790. tabShape.applyTransform (AffineTransform::translation ((float) activeArea.getX(),
  1791. (float) activeArea.getY()));
  1792. DropShadow (Colours::black.withAlpha (0.5f), 2, Point<int> (0, 1)).drawForPath (g, tabShape);
  1793. fillTabButtonShape (button, g, tabShape, isMouseOver, isMouseDown);
  1794. drawTabButtonText (button, g, isMouseOver, isMouseDown);
  1795. }
  1796. void LookAndFeel_V2::drawTabbedButtonBarBackground (TabbedButtonBar&, Graphics&) {}
  1797. void LookAndFeel_V2::drawTabAreaBehindFrontButton (TabbedButtonBar& bar, Graphics& g, const int w, const int h)
  1798. {
  1799. auto shadowSize = 0.2f;
  1800. Rectangle<int> shadowRect, line;
  1801. ColourGradient gradient (Colours::black.withAlpha (bar.isEnabled() ? 0.25f : 0.15f), 0, 0,
  1802. Colours::transparentBlack, 0, 0, false);
  1803. switch (bar.getOrientation())
  1804. {
  1805. case TabbedButtonBar::TabsAtLeft:
  1806. gradient.point1.x = (float) w;
  1807. gradient.point2.x = w * (1.0f - shadowSize);
  1808. shadowRect.setBounds ((int) gradient.point2.x, 0, w - (int) gradient.point2.x, h);
  1809. line.setBounds (w - 1, 0, 1, h);
  1810. break;
  1811. case TabbedButtonBar::TabsAtRight:
  1812. gradient.point2.x = w * shadowSize;
  1813. shadowRect.setBounds (0, 0, (int) gradient.point2.x, h);
  1814. line.setBounds (0, 0, 1, h);
  1815. break;
  1816. case TabbedButtonBar::TabsAtTop:
  1817. gradient.point1.y = (float) h;
  1818. gradient.point2.y = h * (1.0f - shadowSize);
  1819. shadowRect.setBounds (0, (int) gradient.point2.y, w, h - (int) gradient.point2.y);
  1820. line.setBounds (0, h - 1, w, 1);
  1821. break;
  1822. case TabbedButtonBar::TabsAtBottom:
  1823. gradient.point2.y = h * shadowSize;
  1824. shadowRect.setBounds (0, 0, w, (int) gradient.point2.y);
  1825. line.setBounds (0, 0, w, 1);
  1826. break;
  1827. default: break;
  1828. }
  1829. g.setGradientFill (gradient);
  1830. g.fillRect (shadowRect.expanded (2, 2));
  1831. g.setColour (Colour (0x80000000));
  1832. g.fillRect (line);
  1833. }
  1834. Button* LookAndFeel_V2::createTabBarExtrasButton()
  1835. {
  1836. auto thickness = 7.0f;
  1837. auto indent = 22.0f;
  1838. Path p;
  1839. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  1840. DrawablePath ellipse;
  1841. ellipse.setPath (p);
  1842. ellipse.setFill (Colour (0x99ffffff));
  1843. p.clear();
  1844. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  1845. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  1846. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  1847. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  1848. p.setUsingNonZeroWinding (false);
  1849. DrawablePath dp;
  1850. dp.setPath (p);
  1851. dp.setFill (Colour (0x59000000));
  1852. DrawableComposite normalImage;
  1853. normalImage.addAndMakeVisible (ellipse.createCopy().release());
  1854. normalImage.addAndMakeVisible (dp.createCopy().release());
  1855. dp.setFill (Colour (0xcc000000));
  1856. DrawableComposite overImage;
  1857. overImage.addAndMakeVisible (ellipse.createCopy().release());
  1858. overImage.addAndMakeVisible (dp.createCopy().release());
  1859. auto db = new DrawableButton ("tabs", DrawableButton::ImageFitted);
  1860. db->setImages (&normalImage, &overImage, nullptr);
  1861. return db;
  1862. }
  1863. //==============================================================================
  1864. void LookAndFeel_V2::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  1865. {
  1866. g.fillAll (Colours::white);
  1867. auto area = header.getLocalBounds();
  1868. area.removeFromTop (area.getHeight() / 2);
  1869. auto backgroundColour = header.findColour (TableHeaderComponent::backgroundColourId);
  1870. g.setGradientFill (ColourGradient (backgroundColour,
  1871. 0.0f, (float) area.getY(),
  1872. backgroundColour.withMultipliedSaturation (.5f),
  1873. 0.0f, (float) area.getBottom(),
  1874. false));
  1875. g.fillRect (area);
  1876. g.setColour (header.findColour (TableHeaderComponent::outlineColourId));
  1877. g.fillRect (area.removeFromBottom (1));
  1878. for (int i = header.getNumColumns (true); --i >= 0;)
  1879. g.fillRect (header.getColumnPosition (i).removeFromRight (1));
  1880. }
  1881. void LookAndFeel_V2::drawTableHeaderColumn (Graphics& g, TableHeaderComponent& header,
  1882. const String& columnName, int /*columnId*/,
  1883. int width, int height, bool isMouseOver, bool isMouseDown,
  1884. int columnFlags)
  1885. {
  1886. auto highlightColour = header.findColour (TableHeaderComponent::highlightColourId);
  1887. if (isMouseDown)
  1888. g.fillAll (highlightColour);
  1889. else if (isMouseOver)
  1890. g.fillAll (highlightColour.withMultipliedAlpha (0.625f));
  1891. Rectangle<int> area (width, height);
  1892. area.reduce (4, 0);
  1893. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  1894. {
  1895. Path sortArrow;
  1896. sortArrow.addTriangle (0.0f, 0.0f,
  1897. 0.5f, (columnFlags & TableHeaderComponent::sortedForwards) != 0 ? -0.8f : 0.8f,
  1898. 1.0f, 0.0f);
  1899. g.setColour (Colour (0x99000000));
  1900. g.fillPath (sortArrow, sortArrow.getTransformToScaleToFit (area.removeFromRight (height / 2).reduced (2).toFloat(), true));
  1901. }
  1902. g.setColour (header.findColour (TableHeaderComponent::textColourId));
  1903. g.setFont (Font (height * 0.5f, Font::bold));
  1904. g.drawFittedText (columnName, area, Justification::centredLeft, 1);
  1905. }
  1906. //==============================================================================
  1907. void LookAndFeel_V2::drawLasso (Graphics& g, Component& lassoComp)
  1908. {
  1909. const int outlineThickness = 1;
  1910. g.fillAll (lassoComp.findColour (0x1000440 /*lassoFillColourId*/));
  1911. g.setColour (lassoComp.findColour (0x1000441 /*lassoOutlineColourId*/));
  1912. g.drawRect (lassoComp.getLocalBounds(), outlineThickness);
  1913. }
  1914. //==============================================================================
  1915. void LookAndFeel_V2::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  1916. {
  1917. auto background = toolbar.findColour (Toolbar::backgroundColourId);
  1918. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  1919. background.darker (0.1f),
  1920. toolbar.isVertical() ? w - 1.0f : 0.0f,
  1921. toolbar.isVertical() ? 0.0f : h - 1.0f,
  1922. false));
  1923. g.fillAll();
  1924. }
  1925. Button* LookAndFeel_V2::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  1926. {
  1927. return createTabBarExtrasButton();
  1928. }
  1929. void LookAndFeel_V2::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  1930. bool isMouseOver, bool isMouseDown,
  1931. ToolbarItemComponent& component)
  1932. {
  1933. if (isMouseDown)
  1934. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  1935. else if (isMouseOver)
  1936. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  1937. }
  1938. void LookAndFeel_V2::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  1939. const String& text, ToolbarItemComponent& component)
  1940. {
  1941. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  1942. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  1943. auto fontHeight = jmin (14.0f, height * 0.85f);
  1944. g.setFont (fontHeight);
  1945. g.drawFittedText (text,
  1946. x, y, width, height,
  1947. Justification::centred,
  1948. jmax (1, height / (int) fontHeight));
  1949. }
  1950. //==============================================================================
  1951. void LookAndFeel_V2::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  1952. bool isOpen, int width, int height)
  1953. {
  1954. auto buttonSize = height * 0.75f;
  1955. auto buttonIndent = (height - buttonSize) * 0.5f;
  1956. drawTreeviewPlusMinusBox (g, Rectangle<float> (buttonIndent, buttonIndent, buttonSize, buttonSize), Colours::white, isOpen, false);
  1957. auto textX = (int) (buttonIndent * 2.0f + buttonSize + 2.0f);
  1958. g.setColour (Colours::black);
  1959. g.setFont (Font (height * 0.7f, Font::bold));
  1960. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  1961. }
  1962. void LookAndFeel_V2::drawPropertyComponentBackground (Graphics& g, int width, int height, PropertyComponent& component)
  1963. {
  1964. g.setColour (component.findColour (PropertyComponent::backgroundColourId));
  1965. g.fillRect (0, 0, width, height - 1);
  1966. }
  1967. void LookAndFeel_V2::drawPropertyComponentLabel (Graphics& g, int, int height, PropertyComponent& component)
  1968. {
  1969. g.setColour (component.findColour (PropertyComponent::labelTextColourId)
  1970. .withMultipliedAlpha (component.isEnabled() ? 1.0f : 0.6f));
  1971. g.setFont (jmin (height, 24) * 0.65f);
  1972. auto r = getPropertyComponentContentPosition (component);
  1973. g.drawFittedText (component.getName(),
  1974. 3, r.getY(), r.getX() - 5, r.getHeight(),
  1975. Justification::centredLeft, 2);
  1976. }
  1977. Rectangle<int> LookAndFeel_V2::getPropertyComponentContentPosition (PropertyComponent& component)
  1978. {
  1979. const int textW = jmin (200, component.getWidth() / 3);
  1980. return Rectangle<int> (textW, 1, component.getWidth() - textW - 1, component.getHeight() - 3);
  1981. }
  1982. int LookAndFeel_V2::getPropertyPanelSectionHeaderHeight (const String& sectionTitle)
  1983. {
  1984. return sectionTitle.isEmpty() ? 0 : 22;
  1985. }
  1986. //==============================================================================
  1987. void LookAndFeel_V2::drawCallOutBoxBackground (CallOutBox& box, Graphics& g,
  1988. const Path& path, Image& cachedImage)
  1989. {
  1990. if (cachedImage.isNull())
  1991. {
  1992. cachedImage = Image (Image::ARGB, box.getWidth(), box.getHeight(), true);
  1993. Graphics g2 (cachedImage);
  1994. DropShadow (Colours::black.withAlpha (0.7f), 8, Point<int> (0, 2)).drawForPath (g2, path);
  1995. }
  1996. g.setColour (Colours::black);
  1997. g.drawImageAt (cachedImage, 0, 0);
  1998. g.setColour (Colour::greyLevel (0.23f).withAlpha (0.9f));
  1999. g.fillPath (path);
  2000. g.setColour (Colours::white.withAlpha (0.8f));
  2001. g.strokePath (path, PathStrokeType (2.0f));
  2002. }
  2003. int LookAndFeel_V2::getCallOutBoxBorderSize (const CallOutBox&)
  2004. {
  2005. return 20;
  2006. }
  2007. float LookAndFeel_V2::getCallOutBoxCornerSize (const CallOutBox&)
  2008. {
  2009. return 9.0f;
  2010. }
  2011. //==============================================================================
  2012. AttributedString LookAndFeel_V2::createFileChooserHeaderText (const String& title,
  2013. const String& instructions)
  2014. {
  2015. AttributedString s;
  2016. s.setJustification (Justification::centred);
  2017. auto colour = findColour (FileChooserDialogBox::titleTextColourId);
  2018. s.append (title + "\n\n", Font (17.0f, Font::bold), colour);
  2019. s.append (instructions, Font (14.0f), colour);
  2020. return s;
  2021. }
  2022. void LookAndFeel_V2::drawFileBrowserRow (Graphics& g, int width, int height,
  2023. const File&, const String& filename, Image* icon,
  2024. const String& fileSizeDescription,
  2025. const String& fileTimeDescription,
  2026. bool isDirectory, bool isItemSelected,
  2027. int /*itemIndex*/, DirectoryContentsDisplayComponent& dcc)
  2028. {
  2029. auto fileListComp = dynamic_cast<Component*> (&dcc);
  2030. if (isItemSelected)
  2031. g.fillAll (fileListComp != nullptr ? fileListComp->findColour (DirectoryContentsDisplayComponent::highlightColourId)
  2032. : findColour (DirectoryContentsDisplayComponent::highlightColourId));
  2033. const int x = 32;
  2034. g.setColour (Colours::black);
  2035. if (icon != nullptr && icon->isValid())
  2036. {
  2037. g.drawImageWithin (*icon, 2, 2, x - 4, height - 4,
  2038. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  2039. false);
  2040. }
  2041. else
  2042. {
  2043. if (auto* d = isDirectory ? getDefaultFolderImage()
  2044. : getDefaultDocumentFileImage())
  2045. d->drawWithin (g, Rectangle<float> (2.0f, 2.0f, x - 4.0f, height - 4.0f),
  2046. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, 1.0f);
  2047. }
  2048. if (isItemSelected)
  2049. g.setColour (fileListComp != nullptr ? fileListComp->findColour (DirectoryContentsDisplayComponent::highlightedTextColourId)
  2050. : findColour (DirectoryContentsDisplayComponent::highlightedTextColourId));
  2051. else
  2052. g.setColour (fileListComp != nullptr ? fileListComp->findColour (DirectoryContentsDisplayComponent::textColourId)
  2053. : findColour (DirectoryContentsDisplayComponent::textColourId));
  2054. g.setFont (height * 0.7f);
  2055. if (width > 450 && ! isDirectory)
  2056. {
  2057. auto sizeX = roundToInt (width * 0.7f);
  2058. auto dateX = roundToInt (width * 0.8f);
  2059. g.drawFittedText (filename,
  2060. x, 0, sizeX - x, height,
  2061. Justification::centredLeft, 1);
  2062. g.setFont (height * 0.5f);
  2063. g.setColour (Colours::darkgrey);
  2064. if (! isDirectory)
  2065. {
  2066. g.drawFittedText (fileSizeDescription,
  2067. sizeX, 0, dateX - sizeX - 8, height,
  2068. Justification::centredRight, 1);
  2069. g.drawFittedText (fileTimeDescription,
  2070. dateX, 0, width - 8 - dateX, height,
  2071. Justification::centredRight, 1);
  2072. }
  2073. }
  2074. else
  2075. {
  2076. g.drawFittedText (filename,
  2077. x, 0, width - x, height,
  2078. Justification::centredLeft, 1);
  2079. }
  2080. }
  2081. Button* LookAndFeel_V2::createFileBrowserGoUpButton()
  2082. {
  2083. auto goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  2084. Path arrowPath;
  2085. arrowPath.addArrow ({ 50.0f, 100.0f, 50.0f, 0.0f }, 40.0f, 100.0f, 50.0f);
  2086. DrawablePath arrowImage;
  2087. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  2088. arrowImage.setPath (arrowPath);
  2089. goUpButton->setImages (&arrowImage);
  2090. return goUpButton;
  2091. }
  2092. void LookAndFeel_V2::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  2093. DirectoryContentsDisplayComponent* fileListComponent,
  2094. FilePreviewComponent* previewComp,
  2095. ComboBox* currentPathBox,
  2096. TextEditor* filenameBox,
  2097. Button* goUpButton)
  2098. {
  2099. const int x = 8;
  2100. auto w = browserComp.getWidth() - x - x;
  2101. if (previewComp != nullptr)
  2102. {
  2103. auto previewWidth = w / 3;
  2104. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  2105. w -= previewWidth + 4;
  2106. }
  2107. int y = 4;
  2108. const int controlsHeight = 22;
  2109. const int upButtonWidth = 50;
  2110. auto bottomSectionHeight = controlsHeight + 8;
  2111. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  2112. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  2113. y += controlsHeight + 4;
  2114. if (auto listAsComp = dynamic_cast<Component*> (fileListComponent))
  2115. {
  2116. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  2117. y = listAsComp->getBottom() + 4;
  2118. }
  2119. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  2120. }
  2121. //==============================================================================
  2122. static std::unique_ptr<Drawable> createDrawableFromSVG (const char* data)
  2123. {
  2124. auto xml = parseXML (data);
  2125. jassert (xml != nullptr);
  2126. return Drawable::createFromSVG (*xml);
  2127. }
  2128. const Drawable* LookAndFeel_V2::getDefaultFolderImage()
  2129. {
  2130. if (folderImage == nullptr)
  2131. folderImage = createDrawableFromSVG (R"svgdata(
  2132. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="706" height="532">
  2133. <defs>
  2134. <linearGradient id="a">
  2135. <stop stop-color="#adf" offset="0"/>
  2136. <stop stop-color="#ecfaff" offset="1"/>
  2137. </linearGradient>
  2138. <linearGradient id="b" x1=".6" x2="0" y1=".9" xlink:href="#a"/>
  2139. <linearGradient id="c" x1=".6" x2=".1" y1=".9" y2=".3" xlink:href="#a"/>
  2140. </defs>
  2141. <g class="currentLayer">
  2142. <path d="M112.1 104c-8.2 2.2-13.2 11.6-11.3 21l68.3 342.7c1.9 9.4 10.1 15.2 18.4 13l384.3-104.1c8.2-2.2 13.2-11.6 11.3-21l-48-266a15.8 15.8 0 0 0-18.4-12.8l-224.2 38s-20.3-41.3-28.3-39.3z" display="block" fill="url(#b)" stroke="#446c98" stroke-width="7"/>
  2143. <path d="M608.6 136.8L235.2 208a22.7 22.7 0 0 0-16 19l-40.8 241c1.7 8.4 9.6 14.5 17.8 12.3l380-104c8-2.2 10.7-10.2 12.3-18.4l38-210.1c.4-15.4-10.4-11.8-18-11.1z" display="block" fill="url(#c)" opacity=".8" stroke="#446c98" stroke-width="7"/>
  2144. </g>
  2145. </svg>
  2146. )svgdata");
  2147. return folderImage.get();
  2148. }
  2149. const Drawable* LookAndFeel_V2::getDefaultDocumentFileImage()
  2150. {
  2151. if (documentImage == nullptr)
  2152. documentImage = createDrawableFromSVG (R"svgdata(
  2153. <svg version="1" viewBox="-10 -10 450 600" xmlns="http://www.w3.org/2000/svg">
  2154. <path d="M17 0h290l120 132v426c0 10-8 19-17 19H17c-9 0-17-9-17-19V19C0 8 8 0 17 0z" fill="#e5e5e5" stroke="#888888" stroke-width="7"/>
  2155. <path d="M427 132H324c-9 0-17-9-17-19V0l120 132z" fill="#ccc"/>
  2156. </svg>
  2157. )svgdata");
  2158. return documentImage.get();
  2159. }
  2160. //==============================================================================
  2161. static Path createPathFromData (float height, const unsigned char* data, size_t size)
  2162. {
  2163. Path p;
  2164. p.loadPathFromData (data, size);
  2165. p.scaleToFit (0, 0, height * 2.0f, height, true);
  2166. return p;
  2167. }
  2168. Path LookAndFeel_V2::getTickShape (float height)
  2169. {
  2170. static const unsigned char data[] =
  2171. {
  2172. 109,0,224,168,68,0,0,119,67,108,0,224,172,68,0,128,146,67,113,0,192,148,68,0,0,219,67,0,96,110,68,0,224,56,68,113,0,64,51,68,0,32,130,68,0,64,20,68,0,224,
  2173. 162,68,108,0,128,3,68,0,128,168,68,113,0,128,221,67,0,192,175,68,0,0,207,67,0,32,179,68,113,0,0,201,67,0,224,173,68,0,0,181,67,0,224,161,68,108,0,128,168,67,
  2174. 0,128,154,68,113,0,128,141,67,0,192,138,68,0,128,108,67,0,64,131,68,113,0,0,62,67,0,128,119,68,0,0,5,67,0,128,114,68,113,0,0,102,67,0,192,88,68,0,128,155,
  2175. 67,0,192,88,68,113,0,0,190,67,0,192,88,68,0,128,232,67,0,224,131,68,108,0,128,246,67,0,192,139,68,113,0,64,33,68,0,128,87,68,0,0,93,68,0,224,26,68,113,0,
  2176. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  2177. };
  2178. return createPathFromData (height, data, sizeof (data));
  2179. }
  2180. Path LookAndFeel_V2::getCrossShape (float height)
  2181. {
  2182. static const unsigned char data[] =
  2183. {
  2184. 109,0,0,17,68,0,96,145,68,108,0,192,13,68,0,192,147,68,113,0,0,213,67,0,64,174,68,0,0,168,67,0,64,174,68,113,0,0,104,67,0,64,174,68,0,0,5,67,0,64,
  2185. 153,68,113,0,0,18,67,0,64,153,68,0,0,24,67,0,64,153,68,113,0,0,135,67,0,64,153,68,0,128,207,67,0,224,130,68,108,0,0,220,67,0,0,126,68,108,0,0,204,67,
  2186. 0,128,117,68,113,0,0,138,67,0,64,82,68,0,0,138,67,0,192,57,68,113,0,0,138,67,0,192,37,68,0,128,210,67,0,64,10,68,113,0,128,220,67,0,64,45,68,0,0,8,
  2187. 68,0,128,78,68,108,0,192,14,68,0,0,87,68,108,0,64,20,68,0,0,80,68,113,0,192,57,68,0,0,32,68,0,128,88,68,0,0,32,68,113,0,64,112,68,0,0,32,68,0,
  2188. 128,124,68,0,64,68,68,113,0,0,121,68,0,192,67,68,0,128,119,68,0,192,67,68,113,0,192,108,68,0,192,67,68,0,32,89,68,0,96,82,68,113,0,128,69,68,0,0,97,68,
  2189. 0,0,56,68,0,64,115,68,108,0,64,49,68,0,128,124,68,108,0,192,55,68,0,96,129,68,113,0,0,92,68,0,224,146,68,0,192,129,68,0,224,146,68,113,0,64,110,68,0,64,
  2190. 168,68,0,64,87,68,0,64,168,68,113,0,128,66,68,0,64,168,68,0,64,27,68,0,32,150,68,99,101
  2191. };
  2192. return createPathFromData (height, data, sizeof (data));
  2193. }
  2194. //==============================================================================
  2195. void LookAndFeel_V2::drawLevelMeter (Graphics& g, int width, int height, float level)
  2196. {
  2197. g.setColour (Colours::white.withAlpha (0.7f));
  2198. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  2199. g.setColour (Colours::black.withAlpha (0.2f));
  2200. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  2201. const int totalBlocks = 7;
  2202. const int numBlocks = roundToInt (totalBlocks * level);
  2203. auto w = (width - 6.0f) / (float) totalBlocks;
  2204. for (int i = 0; i < totalBlocks; ++i)
  2205. {
  2206. if (i >= numBlocks)
  2207. g.setColour (Colours::lightblue.withAlpha (0.6f));
  2208. else
  2209. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  2210. : Colours::red);
  2211. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  2212. }
  2213. }
  2214. //==============================================================================
  2215. void LookAndFeel_V2::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  2216. {
  2217. auto textColour = button.findColour (0x100ad01 /*KeyMappingEditorComponent::textColourId*/, true);
  2218. if (keyDescription.isNotEmpty())
  2219. {
  2220. if (button.isEnabled())
  2221. {
  2222. auto alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  2223. g.fillAll (textColour.withAlpha (alpha));
  2224. g.setOpacity (0.3f);
  2225. drawBevel (g, 0, 0, width, height, 2);
  2226. }
  2227. g.setColour (textColour);
  2228. g.setFont (height * 0.6f);
  2229. g.drawFittedText (keyDescription,
  2230. 3, 0, width - 6, height,
  2231. Justification::centred, 1);
  2232. }
  2233. else
  2234. {
  2235. const float thickness = 7.0f;
  2236. const float indent = 22.0f;
  2237. Path p;
  2238. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  2239. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  2240. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  2241. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  2242. p.setUsingNonZeroWinding (false);
  2243. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  2244. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  2245. }
  2246. if (button.hasKeyboardFocus (false))
  2247. {
  2248. g.setColour (textColour.withAlpha (0.4f));
  2249. g.drawRect (0, 0, width, height);
  2250. }
  2251. }
  2252. //==============================================================================
  2253. Font LookAndFeel_V2::getSidePanelTitleFont (SidePanel&)
  2254. {
  2255. return Font (18.0f);
  2256. }
  2257. Justification LookAndFeel_V2::getSidePanelTitleJustification (SidePanel& panel)
  2258. {
  2259. return panel.isPanelOnLeft() ? Justification::centredRight
  2260. : Justification::centredLeft;
  2261. }
  2262. Path LookAndFeel_V2::getSidePanelDismissButtonShape (SidePanel& panel)
  2263. {
  2264. return getCrossShape ((float) panel.getTitleBarHeight());
  2265. }
  2266. //==============================================================================
  2267. void LookAndFeel_V2::drawBevel (Graphics& g, const int x, const int y, const int width, const int height,
  2268. const int bevelThickness, const Colour& topLeftColour, const Colour& bottomRightColour,
  2269. const bool useGradient, const bool sharpEdgeOnOutside)
  2270. {
  2271. if (g.clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  2272. {
  2273. auto& context = g.getInternalContext();
  2274. Graphics::ScopedSaveState ss (g);
  2275. for (int i = bevelThickness; --i >= 0;)
  2276. {
  2277. const float op = useGradient ? (sharpEdgeOnOutside ? bevelThickness - i : i) / (float) bevelThickness
  2278. : 1.0f;
  2279. context.setFill (topLeftColour.withMultipliedAlpha (op));
  2280. context.fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  2281. context.setFill (topLeftColour.withMultipliedAlpha (op * 0.75f));
  2282. context.fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  2283. context.setFill (bottomRightColour.withMultipliedAlpha (op));
  2284. context.fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  2285. context.setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
  2286. context.fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  2287. }
  2288. }
  2289. }
  2290. //==============================================================================
  2291. void LookAndFeel_V2::drawShinyButtonShape (Graphics& g, float x, float y, float w, float h,
  2292. float maxCornerSize, const Colour& baseColour, float strokeWidth,
  2293. bool flatOnLeft, bool flatOnRight, bool flatOnTop, bool flatOnBottom) noexcept
  2294. {
  2295. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  2296. return;
  2297. auto cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  2298. Path outline;
  2299. outline.addRoundedRectangle (x, y, w, h, cs, cs,
  2300. ! (flatOnLeft || flatOnTop),
  2301. ! (flatOnRight || flatOnTop),
  2302. ! (flatOnLeft || flatOnBottom),
  2303. ! (flatOnRight || flatOnBottom));
  2304. ColourGradient cg (baseColour, 0.0f, y,
  2305. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  2306. false);
  2307. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  2308. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  2309. g.setGradientFill (cg);
  2310. g.fillPath (outline);
  2311. g.setColour (Colour (0x80000000));
  2312. g.strokePath (outline, PathStrokeType (strokeWidth));
  2313. }
  2314. //==============================================================================
  2315. void LookAndFeel_V2::drawGlassSphere (Graphics& g, const float x, const float y,
  2316. const float diameter, const Colour& colour,
  2317. const float outlineThickness) noexcept
  2318. {
  2319. if (diameter <= outlineThickness)
  2320. return;
  2321. Path p;
  2322. p.addEllipse (x, y, diameter, diameter);
  2323. {
  2324. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  2325. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  2326. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  2327. g.setGradientFill (cg);
  2328. g.fillPath (p);
  2329. }
  2330. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  2331. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  2332. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  2333. ColourGradient cg (Colours::transparentBlack,
  2334. x + diameter * 0.5f, y + diameter * 0.5f,
  2335. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  2336. x, y + diameter * 0.5f, true);
  2337. cg.addColour (0.7, Colours::transparentBlack);
  2338. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  2339. g.setGradientFill (cg);
  2340. g.fillPath (p);
  2341. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  2342. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  2343. }
  2344. //==============================================================================
  2345. void LookAndFeel_V2::drawGlassPointer (Graphics& g,
  2346. const float x, const float y, const float diameter,
  2347. const Colour& colour, const float outlineThickness,
  2348. const int direction) noexcept
  2349. {
  2350. if (diameter <= outlineThickness)
  2351. return;
  2352. Path p;
  2353. p.startNewSubPath (x + diameter * 0.5f, y);
  2354. p.lineTo (x + diameter, y + diameter * 0.6f);
  2355. p.lineTo (x + diameter, y + diameter);
  2356. p.lineTo (x, y + diameter);
  2357. p.lineTo (x, y + diameter * 0.6f);
  2358. p.closeSubPath();
  2359. p.applyTransform (AffineTransform::rotation (direction * MathConstants<float>::halfPi, x + diameter * 0.5f, y + diameter * 0.5f));
  2360. {
  2361. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  2362. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  2363. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  2364. g.setGradientFill (cg);
  2365. g.fillPath (p);
  2366. }
  2367. ColourGradient cg (Colours::transparentBlack,
  2368. x + diameter * 0.5f, y + diameter * 0.5f,
  2369. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  2370. x - diameter * 0.2f, y + diameter * 0.5f, true);
  2371. cg.addColour (0.5, Colours::transparentBlack);
  2372. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  2373. g.setGradientFill (cg);
  2374. g.fillPath (p);
  2375. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  2376. g.strokePath (p, PathStrokeType (outlineThickness));
  2377. }
  2378. //==============================================================================
  2379. void LookAndFeel_V2::drawGlassLozenge (Graphics& g,
  2380. float x, float y, float width, float height,
  2381. const Colour& colour, float outlineThickness, float cornerSize,
  2382. bool flatOnLeft, bool flatOnRight, bool flatOnTop, bool flatOnBottom) noexcept
  2383. {
  2384. if (width <= outlineThickness || height <= outlineThickness)
  2385. return;
  2386. auto intX = (int) x;
  2387. auto intY = (int) y;
  2388. auto intW = (int) width;
  2389. auto intH = (int) height;
  2390. auto cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  2391. auto edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  2392. auto intEdge = (int) edgeBlurRadius;
  2393. Path outline;
  2394. outline.addRoundedRectangle (x, y, width, height, cs, cs,
  2395. ! (flatOnLeft || flatOnTop),
  2396. ! (flatOnRight || flatOnTop),
  2397. ! (flatOnLeft || flatOnBottom),
  2398. ! (flatOnRight || flatOnBottom));
  2399. {
  2400. ColourGradient cg (colour.darker (0.2f), 0, y,
  2401. colour.darker (0.2f), 0, y + height, false);
  2402. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  2403. cg.addColour (0.4, colour);
  2404. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  2405. g.setGradientFill (cg);
  2406. g.fillPath (outline);
  2407. }
  2408. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  2409. colour.darker (0.2f), x, y + height * 0.5f, true);
  2410. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  2411. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  2412. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  2413. {
  2414. Graphics::ScopedSaveState ss (g);
  2415. g.setGradientFill (cg);
  2416. g.reduceClipRegion (intX, intY, intEdge, intH);
  2417. g.fillPath (outline);
  2418. }
  2419. if (! (flatOnRight || flatOnTop || flatOnBottom))
  2420. {
  2421. cg.point1.setX (x + width - edgeBlurRadius);
  2422. cg.point2.setX (x + width);
  2423. Graphics::ScopedSaveState ss (g);
  2424. g.setGradientFill (cg);
  2425. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  2426. g.fillPath (outline);
  2427. }
  2428. {
  2429. auto leftIndent = (flatOnTop || flatOnLeft) ? 0.0f : cs * 0.4f;
  2430. auto rightIndent = (flatOnTop || flatOnRight) ? 0.0f : cs * 0.4f;
  2431. Path highlight;
  2432. highlight.addRoundedRectangle (x + leftIndent,
  2433. y + cs * 0.1f,
  2434. width - (leftIndent + rightIndent),
  2435. height * 0.4f,
  2436. cs * 0.4f,
  2437. cs * 0.4f,
  2438. ! (flatOnLeft || flatOnTop),
  2439. ! (flatOnRight || flatOnTop),
  2440. ! (flatOnLeft || flatOnBottom),
  2441. ! (flatOnRight || flatOnBottom));
  2442. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  2443. Colours::transparentWhite, 0, y + height * 0.4f, false));
  2444. g.fillPath (highlight);
  2445. }
  2446. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  2447. g.strokePath (outline, PathStrokeType (outlineThickness));
  2448. }
  2449. } // namespace juce