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.

2884 lines
121KB

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