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.

581 lines
22KB

  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_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 ((float) width * 0.4f),
  43. roundToInt ((float) height * 0.4f));
  44. Path p;
  45. p.addRoundedRectangle (indent, indent,
  46. (float) width - indent * 2.0f,
  47. (float) 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, (float) (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, (float) 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 ((float) 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. const auto w = (float) width;
  150. const auto h = (float) height;
  151. if (buttonDirection == 0)
  152. p.addTriangle (w * 0.5f, h * 0.2f,
  153. w * 0.1f, h * 0.7f,
  154. w * 0.9f, h * 0.7f);
  155. else if (buttonDirection == 1)
  156. p.addTriangle (w * 0.8f, h * 0.5f,
  157. w * 0.3f, h * 0.1f,
  158. w * 0.3f, h * 0.9f);
  159. else if (buttonDirection == 2)
  160. p.addTriangle (w * 0.5f, h * 0.8f,
  161. w * 0.1f, h * 0.3f,
  162. w * 0.9f, h * 0.3f);
  163. else if (buttonDirection == 3)
  164. p.addTriangle (w * 0.2f, h * 0.5f,
  165. w * 0.7f, h * 0.1f,
  166. w * 0.7f, h * 0.9f);
  167. if (shouldDrawButtonAsDown)
  168. g.setColour (Colours::white);
  169. else if (shouldDrawButtonAsHighlighted)
  170. g.setColour (Colours::white.withAlpha (0.7f));
  171. else
  172. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  173. g.fillPath (p);
  174. g.setColour (Colours::black.withAlpha (0.5f));
  175. g.strokePath (p, PathStrokeType (0.5f));
  176. }
  177. void LookAndFeel_V1::drawScrollbar (Graphics& g, ScrollBar& bar,
  178. int x, int y, int width, int height,
  179. bool isScrollbarVertical, int thumbStartPosition, int thumbSize,
  180. bool isMouseOver, bool isMouseDown)
  181. {
  182. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  183. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  184. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  185. if ((float) thumbSize > 0.0f)
  186. {
  187. Rectangle<int> thumb;
  188. if (isScrollbarVertical)
  189. {
  190. width -= 2;
  191. g.fillRect (x + roundToInt ((float) width * 0.35f), y,
  192. roundToInt ((float) width * 0.3f), height);
  193. thumb.setBounds (x + 1, thumbStartPosition,
  194. width - 2, thumbSize);
  195. }
  196. else
  197. {
  198. height -= 2;
  199. g.fillRect (x, y + roundToInt ((float) height * 0.35f),
  200. width, roundToInt ((float) height * 0.3f));
  201. thumb.setBounds (thumbStartPosition, y + 1,
  202. thumbSize, height - 2);
  203. }
  204. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  205. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  206. g.fillRect (thumb);
  207. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  208. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  209. if (thumbSize > 16)
  210. {
  211. for (int i = 3; --i >= 0;)
  212. {
  213. const float linePos = (float) thumbStartPosition + (float) thumbSize * 0.5f + (float) (i - 1) * 4.0f;
  214. g.setColour (Colours::black.withAlpha (0.15f));
  215. if (isScrollbarVertical)
  216. {
  217. g.drawLine ((float) x + (float) width * 0.2f, linePos, (float) width * 0.8f, linePos);
  218. g.setColour (Colours::white.withAlpha (0.15f));
  219. g.drawLine ((float) width * 0.2f, linePos - 1.0f, (float) width * 0.8f, linePos - 1.0f);
  220. }
  221. else
  222. {
  223. g.drawLine (linePos, (float) height * 0.2f, linePos, (float) height * 0.8f);
  224. g.setColour (Colours::white.withAlpha (0.15f));
  225. g.drawLine (linePos - 1.0f, (float) height * 0.2f, linePos - 1.0f, (float) height * 0.8f);
  226. }
  227. }
  228. }
  229. }
  230. }
  231. ImageEffectFilter* LookAndFeel_V1::getScrollbarEffect()
  232. {
  233. return &scrollbarShadow;
  234. }
  235. //==============================================================================
  236. void LookAndFeel_V1::drawPopupMenuBackground (Graphics& g, int width, int height)
  237. {
  238. g.fillAll (findColour (PopupMenu::backgroundColourId));
  239. g.setColour (Colours::black.withAlpha (0.6f));
  240. g.drawRect (0, 0, width, height);
  241. }
  242. void LookAndFeel_V1::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/, bool, MenuBarComponent& menuBar)
  243. {
  244. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  245. }
  246. //==============================================================================
  247. void LookAndFeel_V1::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  248. {
  249. if (textEditor.isEnabled())
  250. {
  251. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  252. g.drawRect (0, 0, width, height);
  253. }
  254. }
  255. //==============================================================================
  256. void LookAndFeel_V1::drawComboBox (Graphics& g, int width, int height,
  257. const bool isButtonDown,
  258. int buttonX, int buttonY, int buttonW, int buttonH,
  259. ComboBox& box)
  260. {
  261. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  262. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  263. : ComboBox::backgroundColourId));
  264. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  265. g.setColour (box.findColour (ComboBox::outlineColourId));
  266. g.drawRect (0, 0, width, height);
  267. const float arrowX = 0.2f;
  268. const float arrowH = 0.3f;
  269. const auto x = (float) buttonX;
  270. const auto y = (float) buttonY;
  271. const auto w = (float) buttonW;
  272. const auto h = (float) buttonH;
  273. if (box.isEnabled())
  274. {
  275. Path p;
  276. p.addTriangle (x + w * 0.5f, y + h * (0.45f - arrowH),
  277. x + w * (1.0f - arrowX), y + h * 0.45f,
  278. x + w * arrowX, y + h * 0.45f);
  279. p.addTriangle (x + w * 0.5f, y + h * (0.55f + arrowH),
  280. x + w * (1.0f - arrowX), y + h * 0.55f,
  281. x + w * arrowX, y + h * 0.55f);
  282. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  283. : ComboBox::buttonColourId));
  284. g.fillPath (p);
  285. }
  286. }
  287. Font LookAndFeel_V1::getComboBoxFont (ComboBox& box)
  288. {
  289. Font f (jmin (15.0f, (float) box.getHeight() * 0.85f));
  290. f.setHorizontalScale (0.9f);
  291. return f;
  292. }
  293. //==============================================================================
  294. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, Colour fill, Colour outline)
  295. {
  296. Path p;
  297. p.addTriangle (x1, y1, x2, y2, x3, y3);
  298. g.setColour (fill);
  299. g.fillPath (p);
  300. g.setColour (outline);
  301. g.strokePath (p, PathStrokeType (0.3f));
  302. }
  303. void LookAndFeel_V1::drawLinearSlider (Graphics& g,
  304. int x, int y, int w, int h,
  305. float sliderPos, float minSliderPos, float maxSliderPos,
  306. const Slider::SliderStyle style,
  307. Slider& slider)
  308. {
  309. g.fillAll (slider.findColour (Slider::backgroundColourId));
  310. if (style == Slider::LinearBar)
  311. {
  312. g.setColour (slider.findColour (Slider::thumbColourId));
  313. g.fillRect (x, y, (int) sliderPos - x, h);
  314. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  315. g.drawRect (x, y, (int) sliderPos - x, h);
  316. }
  317. else
  318. {
  319. g.setColour (slider.findColour (Slider::trackColourId)
  320. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  321. if (slider.isHorizontal())
  322. {
  323. g.fillRect (x, y + roundToInt ((float) h * 0.6f),
  324. w, roundToInt ((float) h * 0.2f));
  325. }
  326. else
  327. {
  328. g.fillRect (x + roundToInt ((float) w * 0.5f - jmin (3.0f, (float) w * 0.1f)), y,
  329. jmin (4, roundToInt ((float) w * 0.2f)), h);
  330. }
  331. float alpha = 0.35f;
  332. if (slider.isEnabled())
  333. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  334. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  335. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  336. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  337. {
  338. drawTriangle (g,
  339. (float) x + (float) w * 0.5f + jmin (4.0f, (float) w * 0.3f), minSliderPos,
  340. (float) x + (float) w * 0.5f - jmin (8.0f, (float) w * 0.4f), minSliderPos - 7.0f,
  341. (float) x + (float) w * 0.5f - jmin (8.0f, (float) w * 0.4f), minSliderPos,
  342. fill, outline);
  343. drawTriangle (g,
  344. (float) x + (float) w * 0.5f + jmin (4.0f, (float) w * 0.3f), maxSliderPos,
  345. (float) x + (float) w * 0.5f - jmin (8.0f, (float) w * 0.4f), maxSliderPos,
  346. (float) x + (float) w * 0.5f - jmin (8.0f, (float) w * 0.4f), maxSliderPos + 7.0f,
  347. fill, outline);
  348. }
  349. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  350. {
  351. drawTriangle (g,
  352. minSliderPos, (float) y + (float) h * 0.6f - jmin (4.0f, (float) h * 0.3f),
  353. minSliderPos - 7.0f, (float) y + (float) h * 0.9f,
  354. minSliderPos, (float) y + (float) h * 0.9f,
  355. fill, outline);
  356. drawTriangle (g,
  357. maxSliderPos, (float) y + (float) h * 0.6f - jmin (4.0f, (float) h * 0.3f),
  358. maxSliderPos, (float) y + (float) h * 0.9f,
  359. maxSliderPos + 7.0f, (float) y + (float) h * 0.9f,
  360. fill, outline);
  361. }
  362. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  363. {
  364. drawTriangle (g,
  365. sliderPos, (float) y + (float) h * 0.9f,
  366. sliderPos - 7.0f, (float) y + (float) h * 0.2f,
  367. sliderPos + 7.0f, (float) y + (float) h * 0.2f,
  368. fill, outline);
  369. }
  370. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  371. {
  372. drawTriangle (g,
  373. (float) x + (float) w * 0.5f - jmin (4.0f, (float) w * 0.3f), sliderPos,
  374. (float) x + (float) w * 0.5f + jmin (8.0f, (float) w * 0.4f), sliderPos - 7.0f,
  375. (float) x + (float) w * 0.5f + jmin (8.0f, (float) w * 0.4f), sliderPos + 7.0f,
  376. fill, outline);
  377. }
  378. }
  379. }
  380. Button* LookAndFeel_V1::createSliderButton (Slider&, const bool isIncrement)
  381. {
  382. if (isIncrement)
  383. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  384. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  385. }
  386. ImageEffectFilter* LookAndFeel_V1::getSliderEffect (Slider&)
  387. {
  388. return &scrollbarShadow;
  389. }
  390. int LookAndFeel_V1::getSliderThumbRadius (Slider&)
  391. {
  392. return 8;
  393. }
  394. //==============================================================================
  395. void LookAndFeel_V1::drawCornerResizer (Graphics& g, int w, int h, bool isMouseOver, bool isMouseDragging)
  396. {
  397. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  398. : Colours::darkgrey);
  399. const float lineThickness = (float) jmin (w, h) * 0.1f;
  400. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  401. {
  402. g.drawLine ((float) w * i,
  403. (float) h + 1.0f,
  404. (float) w + 1.0f,
  405. (float) h * i,
  406. lineThickness);
  407. }
  408. }
  409. //==============================================================================
  410. Button* LookAndFeel_V1::createDocumentWindowButton (int buttonType)
  411. {
  412. Path shape;
  413. if (buttonType == DocumentWindow::closeButton)
  414. {
  415. shape.addLineSegment (Line<float> (0.0f, 0.0f, 1.0f, 1.0f), 0.35f);
  416. shape.addLineSegment (Line<float> (1.0f, 0.0f, 0.0f, 1.0f), 0.35f);
  417. ShapeButton* const b = new ShapeButton ("close",
  418. Colour (0x7fff3333),
  419. Colour (0xd7ff3333),
  420. Colour (0xf7ff3333));
  421. b->setShape (shape, true, true, true);
  422. return b;
  423. }
  424. else if (buttonType == DocumentWindow::minimiseButton)
  425. {
  426. shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), 0.25f);
  427. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  428. DrawablePath dp;
  429. dp.setPath (shape);
  430. dp.setFill (Colours::black.withAlpha (0.3f));
  431. b->setImages (&dp);
  432. return b;
  433. }
  434. else if (buttonType == DocumentWindow::maximiseButton)
  435. {
  436. shape.addLineSegment (Line<float> (0.5f, 0.0f, 0.5f, 1.0f), 0.25f);
  437. shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), 0.25f);
  438. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  439. DrawablePath dp;
  440. dp.setPath (shape);
  441. dp.setFill (Colours::black.withAlpha (0.3f));
  442. b->setImages (&dp);
  443. return b;
  444. }
  445. jassertfalse;
  446. return nullptr;
  447. }
  448. void LookAndFeel_V1::positionDocumentWindowButtons (DocumentWindow&,
  449. int titleBarX, int titleBarY, int titleBarW, int titleBarH,
  450. Button* minimiseButton,
  451. Button* maximiseButton,
  452. Button* closeButton,
  453. bool positionTitleBarButtonsOnLeft)
  454. {
  455. titleBarY += titleBarH / 8;
  456. titleBarH -= titleBarH / 4;
  457. const int buttonW = titleBarH;
  458. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  459. : titleBarX + titleBarW - buttonW - 4;
  460. if (closeButton != nullptr)
  461. {
  462. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  463. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  464. : -(buttonW + buttonW / 5);
  465. }
  466. if (positionTitleBarButtonsOnLeft)
  467. std::swap (minimiseButton, maximiseButton);
  468. if (maximiseButton != nullptr)
  469. {
  470. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  471. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  472. }
  473. if (minimiseButton != nullptr)
  474. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  475. }
  476. } // namespace juce