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.

3013 lines
124KB

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