The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2943 lines
123KB

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