Audio plugin host https://kx.studio/carla
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.

639 lines
26KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. LookAndFeel_V3::LookAndFeel_V3()
  16. {
  17. setColour (TreeView::selectedItemBackgroundColourId, Colour (0x301111ee));
  18. const Colour textButtonColour (0xffeeeeff);
  19. setColour (TextButton::buttonColourId, textButtonColour);
  20. setColour (TextButton::buttonOnColourId, Colour (0xff888888));
  21. setColour (ComboBox::buttonColourId, textButtonColour);
  22. setColour (ComboBox::focusedOutlineColourId, textButtonColour);
  23. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  24. setColour (TabbedButtonBar::tabOutlineColourId, Colour (0x66000000));
  25. setColour (TabbedComponent::outlineColourId, Colour (0x66000000));
  26. setColour (Slider::trackColourId, Colour (0xbbffffff));
  27. setColour (Slider::thumbColourId, Colour (0xffddddff));
  28. setColour (BubbleComponent::backgroundColourId, Colour (0xeeeeeedd));
  29. setColour (ScrollBar::thumbColourId, Colour::greyLevel (0.8f).contrasting().withAlpha (0.13f));
  30. setColour (TableHeaderComponent::backgroundColourId, Colours::white.withAlpha (0.6f));
  31. setColour (TableHeaderComponent::outlineColourId, Colours::black.withAlpha (0.5f));
  32. }
  33. LookAndFeel_V3::~LookAndFeel_V3() {}
  34. bool LookAndFeel_V3::areScrollbarButtonsVisible() { return false; }
  35. void LookAndFeel_V3::drawStretchableLayoutResizerBar (Graphics& g, int /*w*/, int /*h*/, bool /*isVerticalBar*/,
  36. bool isMouseOver, bool isMouseDragging)
  37. {
  38. if (isMouseOver || isMouseDragging)
  39. g.fillAll (Colours::yellow.withAlpha (0.4f));
  40. }
  41. void LookAndFeel_V3::drawScrollbar (Graphics& g, ScrollBar& scrollbar, int x, int y, int width, int height,
  42. bool isScrollbarVertical, int thumbStartPosition, int thumbSize, bool isMouseOver, bool isMouseDown)
  43. {
  44. Path thumbPath;
  45. if (thumbSize > 0)
  46. {
  47. const float thumbIndent = (float) (isScrollbarVertical ? width : height) * 0.25f;
  48. const float thumbIndentx2 = thumbIndent * 2.0f;
  49. if (isScrollbarVertical)
  50. thumbPath.addRoundedRectangle ((float) x + thumbIndent, (float) thumbStartPosition + thumbIndent,
  51. (float) width - thumbIndentx2, (float) thumbSize - thumbIndentx2, ((float) width - thumbIndentx2) * 0.5f);
  52. else
  53. thumbPath.addRoundedRectangle ((float) thumbStartPosition + thumbIndent, (float) y + thumbIndent,
  54. (float) thumbSize - thumbIndentx2, (float) height - thumbIndentx2, ((float) height - thumbIndentx2) * 0.5f);
  55. }
  56. Colour thumbCol (scrollbar.findColour (ScrollBar::thumbColourId, true));
  57. if (isMouseOver || isMouseDown)
  58. thumbCol = thumbCol.withMultipliedAlpha (2.0f);
  59. g.setColour (thumbCol);
  60. g.fillPath (thumbPath);
  61. g.setColour (thumbCol.contrasting ((isMouseOver || isMouseDown) ? 0.2f : 0.1f));
  62. g.strokePath (thumbPath, PathStrokeType (1.0f));
  63. }
  64. void LookAndFeel_V3::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int>& area,
  65. bool isMouseOver, bool /*isMouseDown*/,
  66. ConcertinaPanel&, Component& panel)
  67. {
  68. const Colour bkg (Colours::grey);
  69. g.setGradientFill (ColourGradient::vertical (Colours::white.withAlpha (isMouseOver ? 0.4f : 0.2f), (float) area.getY(),
  70. Colours::darkgrey.withAlpha (0.1f), (float) area.getBottom()));
  71. g.fillAll();
  72. g.setColour (bkg.contrasting().withAlpha (0.1f));
  73. g.fillRect (area.withHeight (1));
  74. g.fillRect (area.withTop (area.getBottom() - 1));
  75. g.setColour (bkg.contrasting());
  76. g.setFont (Font ((float) area.getHeight() * 0.6f).boldened());
  77. g.drawFittedText (panel.getName(), 4, 0, area.getWidth() - 6, area.getHeight(), Justification::centredLeft, 1);
  78. }
  79. static void drawButtonShape (Graphics& g, const Path& outline, Colour baseColour, float height)
  80. {
  81. const float mainBrightness = baseColour.getBrightness();
  82. const float mainAlpha = baseColour.getFloatAlpha();
  83. g.setGradientFill (ColourGradient::vertical (baseColour.brighter (0.2f), 0.0f,
  84. baseColour.darker (0.25f), height));
  85. g.fillPath (outline);
  86. g.setColour (Colours::white.withAlpha (0.4f * mainAlpha * mainBrightness * mainBrightness));
  87. g.strokePath (outline, PathStrokeType (1.0f), AffineTransform::translation (0.0f, 1.0f)
  88. .scaled (1.0f, (height - 1.6f) / height));
  89. g.setColour (Colours::black.withAlpha (0.4f * mainAlpha));
  90. g.strokePath (outline, PathStrokeType (1.0f));
  91. }
  92. void LookAndFeel_V3::drawButtonBackground (Graphics& g, Button& button, const Colour& backgroundColour,
  93. bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
  94. {
  95. Colour baseColour (backgroundColour.withMultipliedSaturation (button.hasKeyboardFocus (true) ? 1.3f : 0.9f)
  96. .withMultipliedAlpha (button.isEnabled() ? 0.9f : 0.5f));
  97. if (shouldDrawButtonAsDown || shouldDrawButtonAsHighlighted)
  98. baseColour = baseColour.contrasting (shouldDrawButtonAsDown ? 0.2f : 0.1f);
  99. const bool flatOnLeft = button.isConnectedOnLeft();
  100. const bool flatOnRight = button.isConnectedOnRight();
  101. const bool flatOnTop = button.isConnectedOnTop();
  102. const bool flatOnBottom = button.isConnectedOnBottom();
  103. const float width = (float) button.getWidth() - 1.0f;
  104. const float height = (float) button.getHeight() - 1.0f;
  105. if (width > 0 && height > 0)
  106. {
  107. const float cornerSize = 4.0f;
  108. Path outline;
  109. outline.addRoundedRectangle (0.5f, 0.5f, width, height, cornerSize, cornerSize,
  110. ! (flatOnLeft || flatOnTop),
  111. ! (flatOnRight || flatOnTop),
  112. ! (flatOnLeft || flatOnBottom),
  113. ! (flatOnRight || flatOnBottom));
  114. drawButtonShape (g, outline, baseColour, height);
  115. }
  116. }
  117. void LookAndFeel_V3::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  118. {
  119. auto r = header.getLocalBounds();
  120. auto outlineColour = header.findColour (TableHeaderComponent::outlineColourId);
  121. g.setColour (outlineColour);
  122. g.fillRect (r.removeFromBottom (1));
  123. g.setColour (header.findColour (TableHeaderComponent::backgroundColourId));
  124. g.fillRect (r);
  125. g.setColour (outlineColour);
  126. for (int i = header.getNumColumns (true); --i >= 0;)
  127. g.fillRect (header.getColumnPosition (i).removeFromRight (1));
  128. }
  129. int LookAndFeel_V3::getTabButtonOverlap (int /*tabDepth*/) { return -1; }
  130. int LookAndFeel_V3::getTabButtonSpaceAroundImage() { return 0; }
  131. void LookAndFeel_V3::createTabTextLayout (const TabBarButton& button, float length, float depth,
  132. Colour colour, TextLayout& textLayout)
  133. {
  134. Font font (depth * 0.5f);
  135. font.setUnderline (button.hasKeyboardFocus (false));
  136. AttributedString s;
  137. s.setJustification (Justification::centred);
  138. s.append (button.getButtonText().trim(), font, colour);
  139. textLayout.createLayout (s, length);
  140. }
  141. void LookAndFeel_V3::drawTabButton (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
  142. {
  143. const Rectangle<int> activeArea (button.getActiveArea());
  144. const TabbedButtonBar::Orientation o = button.getTabbedButtonBar().getOrientation();
  145. const Colour bkg (button.getTabBackgroundColour());
  146. if (button.getToggleState())
  147. {
  148. g.setColour (bkg);
  149. }
  150. else
  151. {
  152. Point<int> p1, p2;
  153. switch (o)
  154. {
  155. case TabbedButtonBar::TabsAtBottom: p1 = activeArea.getBottomLeft(); p2 = activeArea.getTopLeft(); break;
  156. case TabbedButtonBar::TabsAtTop: p1 = activeArea.getTopLeft(); p2 = activeArea.getBottomLeft(); break;
  157. case TabbedButtonBar::TabsAtRight: p1 = activeArea.getTopRight(); p2 = activeArea.getTopLeft(); break;
  158. case TabbedButtonBar::TabsAtLeft: p1 = activeArea.getTopLeft(); p2 = activeArea.getTopRight(); break;
  159. default: jassertfalse; break;
  160. }
  161. g.setGradientFill (ColourGradient (bkg.brighter (0.2f), p1.toFloat(),
  162. bkg.darker (0.1f), p2.toFloat(), false));
  163. }
  164. g.fillRect (activeArea);
  165. g.setColour (button.findColour (TabbedButtonBar::tabOutlineColourId));
  166. Rectangle<int> r (activeArea);
  167. if (o != TabbedButtonBar::TabsAtBottom) g.fillRect (r.removeFromTop (1));
  168. if (o != TabbedButtonBar::TabsAtTop) g.fillRect (r.removeFromBottom (1));
  169. if (o != TabbedButtonBar::TabsAtRight) g.fillRect (r.removeFromLeft (1));
  170. if (o != TabbedButtonBar::TabsAtLeft) g.fillRect (r.removeFromRight (1));
  171. const float alpha = button.isEnabled() ? ((isMouseOver || isMouseDown) ? 1.0f : 0.8f) : 0.3f;
  172. Colour col (bkg.contrasting().withMultipliedAlpha (alpha));
  173. if (TabbedButtonBar* bar = button.findParentComponentOfClass<TabbedButtonBar>())
  174. {
  175. TabbedButtonBar::ColourIds colID = button.isFrontTab() ? TabbedButtonBar::frontTextColourId
  176. : TabbedButtonBar::tabTextColourId;
  177. if (bar->isColourSpecified (colID))
  178. col = bar->findColour (colID);
  179. else if (isColourSpecified (colID))
  180. col = findColour (colID);
  181. }
  182. const Rectangle<float> area (button.getTextArea().toFloat());
  183. float length = area.getWidth();
  184. float depth = area.getHeight();
  185. if (button.getTabbedButtonBar().isVertical())
  186. std::swap (length, depth);
  187. TextLayout textLayout;
  188. createTabTextLayout (button, length, depth, col, textLayout);
  189. AffineTransform t;
  190. switch (o)
  191. {
  192. case TabbedButtonBar::TabsAtLeft: t = t.rotated (MathConstants<float>::pi * -0.5f).translated (area.getX(), area.getBottom()); break;
  193. case TabbedButtonBar::TabsAtRight: t = t.rotated (MathConstants<float>::pi * 0.5f).translated (area.getRight(), area.getY()); break;
  194. case TabbedButtonBar::TabsAtTop:
  195. case TabbedButtonBar::TabsAtBottom: t = t.translated (area.getX(), area.getY()); break;
  196. default: jassertfalse; break;
  197. }
  198. g.addTransform (t);
  199. textLayout.draw (g, Rectangle<float> (length, depth));
  200. }
  201. void LookAndFeel_V3::drawTabAreaBehindFrontButton (TabbedButtonBar& bar, Graphics& g, const int w, const int h)
  202. {
  203. const float shadowSize = 0.15f;
  204. Rectangle<int> shadowRect, line;
  205. ColourGradient gradient (Colours::black.withAlpha (bar.isEnabled() ? 0.08f : 0.04f), 0, 0,
  206. Colours::transparentBlack, 0, 0, false);
  207. switch (bar.getOrientation())
  208. {
  209. case TabbedButtonBar::TabsAtLeft:
  210. gradient.point1.x = (float) w;
  211. gradient.point2.x = (float) w * (1.0f - shadowSize);
  212. shadowRect.setBounds ((int) gradient.point2.x, 0, w - (int) gradient.point2.x, h);
  213. line.setBounds (w - 1, 0, 1, h);
  214. break;
  215. case TabbedButtonBar::TabsAtRight:
  216. gradient.point2.x = (float) w * shadowSize;
  217. shadowRect.setBounds (0, 0, (int) gradient.point2.x, h);
  218. line.setBounds (0, 0, 1, h);
  219. break;
  220. case TabbedButtonBar::TabsAtTop:
  221. gradient.point1.y = (float) h;
  222. gradient.point2.y = (float) h * (1.0f - shadowSize);
  223. shadowRect.setBounds (0, (int) gradient.point2.y, w, h - (int) gradient.point2.y);
  224. line.setBounds (0, h - 1, w, 1);
  225. break;
  226. case TabbedButtonBar::TabsAtBottom:
  227. gradient.point2.y = (float) h * shadowSize;
  228. shadowRect.setBounds (0, 0, w, (int) gradient.point2.y);
  229. line.setBounds (0, 0, w, 1);
  230. break;
  231. default: break;
  232. }
  233. g.setGradientFill (gradient);
  234. g.fillRect (shadowRect.expanded (2, 2));
  235. g.setColour (bar.findColour (TabbedButtonBar::tabOutlineColourId));
  236. g.fillRect (line);
  237. }
  238. void LookAndFeel_V3::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  239. {
  240. if (textEditor.isEnabled())
  241. {
  242. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  243. {
  244. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  245. g.drawRect (0, 0, width, height, 2);
  246. }
  247. else
  248. {
  249. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  250. g.drawRect (0, 0, width, height);
  251. }
  252. }
  253. }
  254. void LookAndFeel_V3::drawTreeviewPlusMinusBox (Graphics& g, const Rectangle<float>& area,
  255. Colour backgroundColour, bool isOpen, bool isMouseOver)
  256. {
  257. Path p;
  258. p.addTriangle (0.0f, 0.0f, 1.0f, isOpen ? 0.0f : 0.5f, isOpen ? 0.5f : 0.0f, 1.0f);
  259. g.setColour (backgroundColour.contrasting().withAlpha (isMouseOver ? 0.5f : 0.3f));
  260. g.fillPath (p, p.getTransformToScaleToFit (area.reduced (2, area.getHeight() / 4), true));
  261. }
  262. bool LookAndFeel_V3::areLinesDrawnForTreeView (TreeView&)
  263. {
  264. return false;
  265. }
  266. int LookAndFeel_V3::getTreeViewIndentSize (TreeView&)
  267. {
  268. return 20;
  269. }
  270. void LookAndFeel_V3::drawComboBox (Graphics& g, int width, int height, const bool /*isMouseButtonDown*/,
  271. int buttonX, int buttonY, int buttonW, int buttonH, ComboBox& box)
  272. {
  273. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  274. if (box.isEnabled() && box.hasKeyboardFocus (false))
  275. {
  276. g.setColour (box.findColour (ComboBox::focusedOutlineColourId));
  277. g.drawRect (0, 0, width, height, 2);
  278. }
  279. else
  280. {
  281. g.setColour (box.findColour (ComboBox::outlineColourId));
  282. g.drawRect (0, 0, width, height);
  283. }
  284. const float arrowX = 0.3f;
  285. const float arrowH = 0.2f;
  286. const auto x = (float) buttonX;
  287. const auto y = (float) buttonY;
  288. const auto w = (float) buttonW;
  289. const auto h = (float) buttonH;
  290. Path p;
  291. p.addTriangle (x + w * 0.5f, y + h * (0.45f - arrowH),
  292. x + w * (1.0f - arrowX), y + h * 0.45f,
  293. x + w * arrowX, y + h * 0.45f);
  294. p.addTriangle (x + w * 0.5f, y + h * (0.55f + arrowH),
  295. x + w * (1.0f - arrowX), y + h * 0.55f,
  296. x + w * arrowX, y + h * 0.55f);
  297. g.setColour (box.findColour (ComboBox::arrowColourId).withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.3f));
  298. g.fillPath (p);
  299. }
  300. void LookAndFeel_V3::drawLinearSlider (Graphics& g, int x, int y, int width, int height,
  301. float sliderPos, float minSliderPos, float maxSliderPos,
  302. const Slider::SliderStyle style, Slider& slider)
  303. {
  304. g.fillAll (slider.findColour (Slider::backgroundColourId));
  305. if (style == Slider::LinearBar || style == Slider::LinearBarVertical)
  306. {
  307. const float fx = (float) x, fy = (float) y, fw = (float) width, fh = (float) height;
  308. Path p;
  309. if (style == Slider::LinearBarVertical)
  310. p.addRectangle (fx, sliderPos, fw, 1.0f + fh - sliderPos);
  311. else
  312. p.addRectangle (fx, fy, sliderPos - fx, fh);
  313. auto baseColour = slider.findColour (Slider::thumbColourId)
  314. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f)
  315. .withMultipliedAlpha (0.8f);
  316. g.setGradientFill (ColourGradient::vertical (baseColour.brighter (0.08f), 0.0f,
  317. baseColour.darker (0.08f), (float) height));
  318. g.fillPath (p);
  319. g.setColour (baseColour.darker (0.2f));
  320. if (style == Slider::LinearBarVertical)
  321. g.fillRect (fx, sliderPos, fw, 1.0f);
  322. else
  323. g.fillRect (sliderPos, fy, 1.0f, fh);
  324. }
  325. else
  326. {
  327. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  328. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  329. }
  330. }
  331. void LookAndFeel_V3::drawLinearSliderBackground (Graphics& g, int x, int y, int width, int height,
  332. float /*sliderPos*/,
  333. float /*minSliderPos*/,
  334. float /*maxSliderPos*/,
  335. const Slider::SliderStyle /*style*/, Slider& slider)
  336. {
  337. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  338. const Colour trackColour (slider.findColour (Slider::trackColourId));
  339. const Colour gradCol1 (trackColour.overlaidWith (Colour (slider.isEnabled() ? 0x13000000 : 0x09000000)));
  340. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x06000000)));
  341. Path indent;
  342. if (slider.isHorizontal())
  343. {
  344. auto iy = (float) y + (float) height * 0.5f - sliderRadius * 0.5f;
  345. g.setGradientFill (ColourGradient::vertical (gradCol1, iy, gradCol2, iy + sliderRadius));
  346. indent.addRoundedRectangle ((float) x - sliderRadius * 0.5f, iy, (float) width + sliderRadius, sliderRadius, 5.0f);
  347. }
  348. else
  349. {
  350. auto ix = (float) x + (float) width * 0.5f - sliderRadius * 0.5f;
  351. g.setGradientFill (ColourGradient::horizontal (gradCol1, ix, gradCol2, ix + sliderRadius));
  352. indent.addRoundedRectangle (ix, (float) y - sliderRadius * 0.5f, sliderRadius, (float) height + sliderRadius, 5.0f);
  353. }
  354. g.fillPath (indent);
  355. g.setColour (trackColour.contrasting (0.5f));
  356. g.strokePath (indent, PathStrokeType (0.5f));
  357. }
  358. void LookAndFeel_V3::drawPopupMenuBackground (Graphics& g, int width, int height)
  359. {
  360. g.fillAll (findColour (PopupMenu::backgroundColourId));
  361. ignoreUnused (width, height);
  362. #if ! JUCE_MAC
  363. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  364. g.drawRect (0, 0, width, height);
  365. #endif
  366. }
  367. void LookAndFeel_V3::drawMenuBarBackground (Graphics& g, int width, int height,
  368. bool, MenuBarComponent& menuBar)
  369. {
  370. auto colour = menuBar.findColour (PopupMenu::backgroundColourId);
  371. Rectangle<int> r (width, height);
  372. g.setColour (colour.contrasting (0.15f));
  373. g.fillRect (r.removeFromTop (1));
  374. g.fillRect (r.removeFromBottom (1));
  375. g.setGradientFill (ColourGradient::vertical (colour, 0, colour.darker (0.08f), (float) height));
  376. g.fillRect (r);
  377. }
  378. void LookAndFeel_V3::drawKeymapChangeButton (Graphics& g, int width, int height,
  379. Button& button, const String& keyDescription)
  380. {
  381. const Colour textColour (button.findColour (0x100ad01 /*KeyMappingEditorComponent::textColourId*/, true));
  382. if (keyDescription.isNotEmpty())
  383. {
  384. if (button.isEnabled())
  385. {
  386. g.setColour (textColour.withAlpha (button.isDown() ? 0.4f : (button.isOver() ? 0.2f : 0.1f)));
  387. g.fillRoundedRectangle (button.getLocalBounds().toFloat(), 4.0f);
  388. g.drawRoundedRectangle (button.getLocalBounds().toFloat(), 4.0f, 1.0f);
  389. }
  390. g.setColour (textColour);
  391. g.setFont ((float) height * 0.6f);
  392. g.drawFittedText (keyDescription, 4, 0, width - 8, height, Justification::centred, 1);
  393. }
  394. else
  395. {
  396. const float thickness = 7.0f;
  397. const float indent = 22.0f;
  398. Path p;
  399. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  400. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  401. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  402. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  403. p.setUsingNonZeroWinding (false);
  404. g.setColour (textColour.darker(0.1f).withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  405. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, (float) width - 4.0f, (float) height - 4.0f, true));
  406. }
  407. if (button.hasKeyboardFocus (false))
  408. {
  409. g.setColour (textColour.withAlpha (0.4f));
  410. g.drawRect (0, 0, width, height);
  411. }
  412. }
  413. class LookAndFeel_V3_DocumentWindowButton : public Button
  414. {
  415. public:
  416. LookAndFeel_V3_DocumentWindowButton (const String& name, Colour c, const Path& normal, const Path& toggled)
  417. : Button (name), colour (c), normalShape (normal), toggledShape (toggled)
  418. {
  419. }
  420. void paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
  421. {
  422. Colour background (Colours::grey);
  423. if (ResizableWindow* rw = findParentComponentOfClass<ResizableWindow>())
  424. background = rw->getBackgroundColour();
  425. const float cx = (float) getWidth() * 0.5f, cy = (float) getHeight() * 0.5f;
  426. const float diam = jmin (cx, cy) * (shouldDrawButtonAsDown ? 0.60f : 0.65f);
  427. g.setColour (background);
  428. g.fillEllipse (cx - diam, cy - diam, diam * 2.0f, diam * 2.0f);
  429. Colour c (background.contrasting (colour, 0.6f));
  430. if (! isEnabled())
  431. c = c.withAlpha (0.6f);
  432. else if (shouldDrawButtonAsHighlighted)
  433. c = c.brighter();
  434. g.setColour (c);
  435. g.drawEllipse (cx - diam, cy - diam, diam * 2.0f, diam * 2.0f, diam * 0.2f);
  436. Path& p = getToggleState() ? toggledShape : normalShape;
  437. float scale = 0.55f;
  438. g.fillPath (p, p.getTransformToScaleToFit (cx - diam * scale, cy - diam * scale,
  439. diam * 2.0f * scale, diam * 2.0f * scale, true));
  440. }
  441. private:
  442. Colour colour;
  443. Path normalShape, toggledShape;
  444. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LookAndFeel_V3_DocumentWindowButton)
  445. };
  446. Button* LookAndFeel_V3::createDocumentWindowButton (int buttonType)
  447. {
  448. Path shape;
  449. const float crossThickness = 0.25f;
  450. if (buttonType == DocumentWindow::closeButton)
  451. {
  452. shape.addLineSegment (Line<float> (0.0f, 0.0f, 1.0f, 1.0f), crossThickness * 1.4f);
  453. shape.addLineSegment (Line<float> (1.0f, 0.0f, 0.0f, 1.0f), crossThickness * 1.4f);
  454. return new LookAndFeel_V3_DocumentWindowButton ("close", Colour (0xffdd1100), shape, shape);
  455. }
  456. if (buttonType == DocumentWindow::minimiseButton)
  457. {
  458. shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), crossThickness);
  459. return new LookAndFeel_V3_DocumentWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  460. }
  461. if (buttonType == DocumentWindow::maximiseButton)
  462. {
  463. shape.addLineSegment (Line<float> (0.5f, 0.0f, 0.5f, 1.0f), crossThickness);
  464. shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), crossThickness);
  465. Path fullscreenShape;
  466. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  467. fullscreenShape.lineTo (0.0f, 100.0f);
  468. fullscreenShape.lineTo (0.0f, 0.0f);
  469. fullscreenShape.lineTo (100.0f, 0.0f);
  470. fullscreenShape.lineTo (100.0f, 45.0f);
  471. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  472. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  473. return new LookAndFeel_V3_DocumentWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  474. }
  475. jassertfalse;
  476. return nullptr;
  477. }
  478. Path LookAndFeel_V3::getTickShape (const float height)
  479. {
  480. static const unsigned char pathData[]
  481. = { 110,109,32,210,202,64,126,183,148,64,108,39,244,247,64,245,76,124,64,108,178,131,27,65,246,76,252,64,108,175,242,4,65,246,76,252,
  482. 64,108,236,5,68,65,0,0,160,180,108,240,150,90,65,21,136,52,63,108,48,59,16,65,0,0,32,65,108,32,210,202,64,126,183,148,64, 99,101,0,0 };
  483. Path p;
  484. p.loadPathFromData (pathData, sizeof (pathData));
  485. p.scaleToFit (0, 0, height * 2.0f, height, true);
  486. return p;
  487. }
  488. Path LookAndFeel_V3::getCrossShape (const float height)
  489. {
  490. static const unsigned char pathData[]
  491. = { 110,109,88,57,198,65,29,90,171,65,108,63,53,154,65,8,172,126,65,108,76,55,198,65,215,163,38,65,108,141,151,175,65,82,184,242,64,108,117,147,131,65,90,100,81,65,108,184,30,47,65,82,184,242,64,108,59,223,1,65,215,163,38,65,108,84,227,89,65,8,172,126,65,
  492. 108,35,219,1,65,29,90,171,65,108,209,34,47,65,231,251,193,65,108,117,147,131,65,207,247,149,65,108,129,149,175,65,231,251,193,65,99,101,0,0 };
  493. Path p;
  494. p.loadPathFromData (pathData, sizeof (pathData));
  495. p.scaleToFit (0, 0, height * 2.0f, height, true);
  496. return p;
  497. }
  498. } // namespace juce