juce_LookAndFeel_V3.cpp 25 KB

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