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.

3063 lines
126KB

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