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.

3071 lines
129KB

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