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.

3186 lines
127KB

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