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.

2980 lines
125KB

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