Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3089 lines
122KB

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