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.

567 lines
21KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - 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 this technical preview, this file is not subject to commercial licensing.
  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_V1::LookAndFeel_V1()
  16. {
  17. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  18. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  19. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  20. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  21. setColour (Slider::thumbColourId, Colours::white);
  22. setColour (Slider::trackColourId, Colour (0x7f000000));
  23. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  24. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  25. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  26. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  27. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  28. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  29. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  30. scrollbarShadow.setShadowProperties (DropShadow (Colours::black.withAlpha (0.5f), 2, Point<int>()));
  31. }
  32. LookAndFeel_V1::~LookAndFeel_V1()
  33. {
  34. }
  35. //==============================================================================
  36. void LookAndFeel_V1::drawButtonBackground (Graphics& g, Button& button, const Colour& backgroundColour,
  37. bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
  38. {
  39. const int width = button.getWidth();
  40. const int height = button.getHeight();
  41. const float indent = 2.0f;
  42. const int cornerSize = jmin (roundToInt (width * 0.4f),
  43. roundToInt (height * 0.4f));
  44. Path p;
  45. p.addRoundedRectangle (indent, indent,
  46. width - indent * 2.0f,
  47. height - indent * 2.0f,
  48. (float) cornerSize);
  49. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  50. if (shouldDrawButtonAsHighlighted)
  51. {
  52. if (shouldDrawButtonAsDown)
  53. bc = bc.brighter();
  54. else if (bc.getBrightness() > 0.5f)
  55. bc = bc.darker (0.1f);
  56. else
  57. bc = bc.brighter (0.1f);
  58. }
  59. g.setColour (bc);
  60. g.fillPath (p);
  61. g.setColour (bc.contrasting().withAlpha ((shouldDrawButtonAsHighlighted) ? 0.6f : 0.4f));
  62. g.strokePath (p, PathStrokeType ((shouldDrawButtonAsHighlighted) ? 2.0f : 1.4f));
  63. }
  64. void LookAndFeel_V1::drawTickBox (Graphics& g, Component& /*component*/,
  65. float x, float y, float w, float h,
  66. const bool ticked,
  67. const bool isEnabled,
  68. const bool /*shouldDrawButtonAsHighlighted*/,
  69. const bool shouldDrawButtonAsDown)
  70. {
  71. Path box;
  72. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  73. g.setColour (isEnabled ? Colours::blue.withAlpha (shouldDrawButtonAsDown ? 0.3f : 0.1f)
  74. : Colours::lightgrey.withAlpha (0.1f));
  75. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  76. g.fillPath (box, trans);
  77. g.setColour (Colours::black.withAlpha (0.6f));
  78. g.strokePath (box, PathStrokeType (0.9f), trans);
  79. if (ticked)
  80. {
  81. Path tick;
  82. tick.startNewSubPath (1.5f, 3.0f);
  83. tick.lineTo (3.0f, 6.0f);
  84. tick.lineTo (6.0f, 0.0f);
  85. g.setColour (isEnabled ? Colours::black : Colours::grey);
  86. g.strokePath (tick, PathStrokeType (2.5f), trans);
  87. }
  88. }
  89. void LookAndFeel_V1::drawToggleButton (Graphics& g, ToggleButton& button, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
  90. {
  91. if (button.hasKeyboardFocus (true))
  92. {
  93. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  94. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  95. }
  96. const int tickWidth = jmin (20, button.getHeight() - 4);
  97. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  98. (float) tickWidth, (float) tickWidth,
  99. button.getToggleState(),
  100. button.isEnabled(),
  101. shouldDrawButtonAsHighlighted,
  102. shouldDrawButtonAsDown);
  103. g.setColour (button.findColour (ToggleButton::textColourId));
  104. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  105. if (! button.isEnabled())
  106. g.setOpacity (0.5f);
  107. const int textX = tickWidth + 5;
  108. g.drawFittedText (button.getButtonText(),
  109. textX, 4,
  110. button.getWidth() - textX - 2, button.getHeight() - 8,
  111. Justification::centredLeft, 10);
  112. }
  113. void LookAndFeel_V1::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  114. int width, int height,
  115. double progress, const String& textToShow)
  116. {
  117. if (progress < 0 || progress >= 1.0)
  118. {
  119. LookAndFeel_V2::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  120. }
  121. else
  122. {
  123. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  124. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  125. g.fillAll (background);
  126. g.setColour (foreground);
  127. g.fillRect (1, 1,
  128. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  129. height - 2);
  130. if (textToShow.isNotEmpty())
  131. {
  132. g.setColour (Colour::contrasting (background, foreground));
  133. g.setFont (height * 0.6f);
  134. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  135. }
  136. }
  137. }
  138. void LookAndFeel_V1::drawScrollbarButton (Graphics& g, ScrollBar& bar,
  139. int width, int height, int buttonDirection,
  140. bool isScrollbarVertical,
  141. bool shouldDrawButtonAsHighlighted,
  142. bool shouldDrawButtonAsDown)
  143. {
  144. if (isScrollbarVertical)
  145. width -= 2;
  146. else
  147. height -= 2;
  148. Path p;
  149. if (buttonDirection == 0)
  150. p.addTriangle (width * 0.5f, height * 0.2f,
  151. width * 0.1f, height * 0.7f,
  152. width * 0.9f, height * 0.7f);
  153. else if (buttonDirection == 1)
  154. p.addTriangle (width * 0.8f, height * 0.5f,
  155. width * 0.3f, height * 0.1f,
  156. width * 0.3f, height * 0.9f);
  157. else if (buttonDirection == 2)
  158. p.addTriangle (width * 0.5f, height * 0.8f,
  159. width * 0.1f, height * 0.3f,
  160. width * 0.9f, height * 0.3f);
  161. else if (buttonDirection == 3)
  162. p.addTriangle (width * 0.2f, height * 0.5f,
  163. width * 0.7f, height * 0.1f,
  164. width * 0.7f, height * 0.9f);
  165. if (shouldDrawButtonAsDown)
  166. g.setColour (Colours::white);
  167. else if (shouldDrawButtonAsHighlighted)
  168. g.setColour (Colours::white.withAlpha (0.7f));
  169. else
  170. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  171. g.fillPath (p);
  172. g.setColour (Colours::black.withAlpha (0.5f));
  173. g.strokePath (p, PathStrokeType (0.5f));
  174. }
  175. void LookAndFeel_V1::drawScrollbar (Graphics& g, ScrollBar& bar,
  176. int x, int y, int width, int height,
  177. bool isScrollbarVertical, int thumbStartPosition, int thumbSize,
  178. bool isMouseOver, bool isMouseDown)
  179. {
  180. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  181. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  182. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  183. if (thumbSize > 0.0f)
  184. {
  185. Rectangle<int> thumb;
  186. if (isScrollbarVertical)
  187. {
  188. width -= 2;
  189. g.fillRect (x + roundToInt (width * 0.35f), y,
  190. roundToInt (width * 0.3f), height);
  191. thumb.setBounds (x + 1, thumbStartPosition,
  192. width - 2, thumbSize);
  193. }
  194. else
  195. {
  196. height -= 2;
  197. g.fillRect (x, y + roundToInt (height * 0.35f),
  198. width, roundToInt (height * 0.3f));
  199. thumb.setBounds (thumbStartPosition, y + 1,
  200. thumbSize, height - 2);
  201. }
  202. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  203. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  204. g.fillRect (thumb);
  205. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  206. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  207. if (thumbSize > 16)
  208. {
  209. for (int i = 3; --i >= 0;)
  210. {
  211. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  212. g.setColour (Colours::black.withAlpha (0.15f));
  213. if (isScrollbarVertical)
  214. {
  215. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  216. g.setColour (Colours::white.withAlpha (0.15f));
  217. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  218. }
  219. else
  220. {
  221. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  222. g.setColour (Colours::white.withAlpha (0.15f));
  223. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  224. }
  225. }
  226. }
  227. }
  228. }
  229. ImageEffectFilter* LookAndFeel_V1::getScrollbarEffect()
  230. {
  231. return &scrollbarShadow;
  232. }
  233. //==============================================================================
  234. void LookAndFeel_V1::drawPopupMenuBackground (Graphics& g, int width, int height)
  235. {
  236. g.fillAll (findColour (PopupMenu::backgroundColourId));
  237. g.setColour (Colours::black.withAlpha (0.6f));
  238. g.drawRect (0, 0, width, height);
  239. }
  240. void LookAndFeel_V1::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/, bool, MenuBarComponent& menuBar)
  241. {
  242. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  243. }
  244. //==============================================================================
  245. void LookAndFeel_V1::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  246. {
  247. if (textEditor.isEnabled())
  248. {
  249. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  250. g.drawRect (0, 0, width, height);
  251. }
  252. }
  253. //==============================================================================
  254. void LookAndFeel_V1::drawComboBox (Graphics& g, int width, int height,
  255. const bool isButtonDown,
  256. int buttonX, int buttonY, int buttonW, int buttonH,
  257. ComboBox& box)
  258. {
  259. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  260. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  261. : ComboBox::backgroundColourId));
  262. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  263. g.setColour (box.findColour (ComboBox::outlineColourId));
  264. g.drawRect (0, 0, width, height);
  265. const float arrowX = 0.2f;
  266. const float arrowH = 0.3f;
  267. if (box.isEnabled())
  268. {
  269. Path p;
  270. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  271. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  272. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  273. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  274. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  275. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  276. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  277. : ComboBox::buttonColourId));
  278. g.fillPath (p);
  279. }
  280. }
  281. Font LookAndFeel_V1::getComboBoxFont (ComboBox& box)
  282. {
  283. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  284. f.setHorizontalScale (0.9f);
  285. return f;
  286. }
  287. //==============================================================================
  288. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, Colour fill, Colour outline)
  289. {
  290. Path p;
  291. p.addTriangle (x1, y1, x2, y2, x3, y3);
  292. g.setColour (fill);
  293. g.fillPath (p);
  294. g.setColour (outline);
  295. g.strokePath (p, PathStrokeType (0.3f));
  296. }
  297. void LookAndFeel_V1::drawLinearSlider (Graphics& g,
  298. int x, int y, int w, int h,
  299. float sliderPos, float minSliderPos, float maxSliderPos,
  300. const Slider::SliderStyle style,
  301. Slider& slider)
  302. {
  303. g.fillAll (slider.findColour (Slider::backgroundColourId));
  304. if (style == Slider::LinearBar)
  305. {
  306. g.setColour (slider.findColour (Slider::thumbColourId));
  307. g.fillRect (x, y, (int) sliderPos - x, h);
  308. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  309. g.drawRect (x, y, (int) sliderPos - x, h);
  310. }
  311. else
  312. {
  313. g.setColour (slider.findColour (Slider::trackColourId)
  314. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  315. if (slider.isHorizontal())
  316. {
  317. g.fillRect (x, y + roundToInt (h * 0.6f),
  318. w, roundToInt (h * 0.2f));
  319. }
  320. else
  321. {
  322. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  323. jmin (4, roundToInt (w * 0.2f)), h);
  324. }
  325. float alpha = 0.35f;
  326. if (slider.isEnabled())
  327. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  328. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  329. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  330. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  331. {
  332. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  333. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  334. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  335. fill, outline);
  336. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  337. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  338. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  339. fill, outline);
  340. }
  341. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  342. {
  343. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  344. minSliderPos - 7.0f, y + h * 0.9f ,
  345. minSliderPos, y + h * 0.9f,
  346. fill, outline);
  347. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  348. maxSliderPos, y + h * 0.9f,
  349. maxSliderPos + 7.0f, y + h * 0.9f,
  350. fill, outline);
  351. }
  352. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  353. {
  354. drawTriangle (g, sliderPos, y + h * 0.9f,
  355. sliderPos - 7.0f, y + h * 0.2f,
  356. sliderPos + 7.0f, y + h * 0.2f,
  357. fill, outline);
  358. }
  359. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  360. {
  361. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  362. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  363. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  364. fill, outline);
  365. }
  366. }
  367. }
  368. Button* LookAndFeel_V1::createSliderButton (Slider&, const bool isIncrement)
  369. {
  370. if (isIncrement)
  371. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  372. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  373. }
  374. ImageEffectFilter* LookAndFeel_V1::getSliderEffect (Slider&)
  375. {
  376. return &scrollbarShadow;
  377. }
  378. int LookAndFeel_V1::getSliderThumbRadius (Slider&)
  379. {
  380. return 8;
  381. }
  382. //==============================================================================
  383. void LookAndFeel_V1::drawCornerResizer (Graphics& g, int w, int h, bool isMouseOver, bool isMouseDragging)
  384. {
  385. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  386. : Colours::darkgrey);
  387. const float lineThickness = jmin (w, h) * 0.1f;
  388. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  389. {
  390. g.drawLine (w * i,
  391. h + 1.0f,
  392. w + 1.0f,
  393. h * i,
  394. lineThickness);
  395. }
  396. }
  397. //==============================================================================
  398. Button* LookAndFeel_V1::createDocumentWindowButton (int buttonType)
  399. {
  400. Path shape;
  401. if (buttonType == DocumentWindow::closeButton)
  402. {
  403. shape.addLineSegment (Line<float> (0.0f, 0.0f, 1.0f, 1.0f), 0.35f);
  404. shape.addLineSegment (Line<float> (1.0f, 0.0f, 0.0f, 1.0f), 0.35f);
  405. ShapeButton* const b = new ShapeButton ("close",
  406. Colour (0x7fff3333),
  407. Colour (0xd7ff3333),
  408. Colour (0xf7ff3333));
  409. b->setShape (shape, true, true, true);
  410. return b;
  411. }
  412. else if (buttonType == DocumentWindow::minimiseButton)
  413. {
  414. shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), 0.25f);
  415. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  416. DrawablePath dp;
  417. dp.setPath (shape);
  418. dp.setFill (Colours::black.withAlpha (0.3f));
  419. b->setImages (&dp);
  420. return b;
  421. }
  422. else if (buttonType == DocumentWindow::maximiseButton)
  423. {
  424. shape.addLineSegment (Line<float> (0.5f, 0.0f, 0.5f, 1.0f), 0.25f);
  425. shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), 0.25f);
  426. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  427. DrawablePath dp;
  428. dp.setPath (shape);
  429. dp.setFill (Colours::black.withAlpha (0.3f));
  430. b->setImages (&dp);
  431. return b;
  432. }
  433. jassertfalse;
  434. return nullptr;
  435. }
  436. void LookAndFeel_V1::positionDocumentWindowButtons (DocumentWindow&,
  437. int titleBarX, int titleBarY, int titleBarW, int titleBarH,
  438. Button* minimiseButton,
  439. Button* maximiseButton,
  440. Button* closeButton,
  441. bool positionTitleBarButtonsOnLeft)
  442. {
  443. titleBarY += titleBarH / 8;
  444. titleBarH -= titleBarH / 4;
  445. const int buttonW = titleBarH;
  446. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  447. : titleBarX + titleBarW - buttonW - 4;
  448. if (closeButton != nullptr)
  449. {
  450. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  451. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  452. : -(buttonW + buttonW / 5);
  453. }
  454. if (positionTitleBarButtonsOnLeft)
  455. std::swap (minimiseButton, maximiseButton);
  456. if (maximiseButton != nullptr)
  457. {
  458. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  459. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  460. }
  461. if (minimiseButton != nullptr)
  462. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  463. }
  464. } // namespace juce