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.

143 lines
5.8KB

  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. #pragma once
  18. class ProjucerDialogLookAndFeel : public LookAndFeel_V3
  19. {
  20. public:
  21. //==============================================================================
  22. const float labelFontSize = 12.0f;
  23. const float buttonFontSize = 15.0f;
  24. //==============================================================================
  25. void drawToggleButton (Graphics& g, ToggleButton& button, bool /*isMouseOverButton*/, bool /*isButtonDown*/) override
  26. {
  27. g.setColour (Colours::white);
  28. Rectangle<float> box (4.0f, 4.0f, 13.0f, 13.0f);
  29. g.fillRoundedRectangle (box, 3.0f);
  30. if (button.getToggleState())
  31. {
  32. g.setColour (Colours::black);
  33. Path tick;
  34. tick.startNewSubPath (box.getX(), box.getCentreY() + 1.0f);
  35. tick.lineTo (box.getCentreX() - 1.0f, box.getBottom());
  36. tick.lineTo (box.getRight(), box.getY());
  37. const AffineTransform trans (AffineTransform::scale (0.75, 0.75, box.getCentreX(), box.getCentreY()));
  38. g.strokePath (tick, PathStrokeType (3.0f), trans);
  39. }
  40. g.setColour (button.findColour (ToggleButton::textColourId));
  41. g.setFont (getDialogFont().withHeight (labelFontSize));
  42. g.drawFittedText (button.getButtonText(), 24, 1,
  43. button.getWidth() - 24, button.getHeight(),
  44. Justification::centredLeft, 10);
  45. }
  46. void drawButtonBackground (Graphics& g, Button& button, const Colour& /*backgroundColour*/,
  47. bool isMouseOverButton, bool isButtonDown) override
  48. {
  49. auto buttonRect = button.getLocalBounds().toFloat();
  50. if (button.getProperties()["isSecondaryButton"])
  51. drawSecondaryButtonBackground (g, buttonRect, isMouseOverButton, isButtonDown);
  52. else
  53. drawPrimaryButtonBackground (g, buttonRect, isMouseOverButton, isButtonDown);
  54. }
  55. void drawButtonText (Graphics& g, TextButton& button, bool isMouseOverButton, bool isButtonDown) override
  56. {
  57. Font font (getTextButtonFont (button, button.getHeight()));
  58. g.setFont (font);
  59. if (button.getProperties()["isSecondaryButton"])
  60. g.setColour (getBrightButtonColour (isMouseOverButton, isButtonDown));
  61. else
  62. g.setColour (getBackgroundColour());
  63. g.drawFittedText (button.getButtonText(), 0, 1,
  64. button.getWidth(),
  65. button.getHeight(),
  66. Justification::centred, 2);
  67. }
  68. //==============================================================================
  69. Font getTextButtonFont (TextButton&, int /*buttonHeight*/) override
  70. {
  71. return getDialogFont().withHeight (buttonFontSize);
  72. }
  73. Font getLabelFont (Label&) override
  74. {
  75. return getDialogFont().withHeight (labelFontSize);
  76. }
  77. //==============================================================================
  78. int getAlertWindowButtonHeight() override { return 40; }
  79. static Font getDialogFont() { return Font(); }
  80. Font getAlertWindowTitleFont() override { return getDialogFont().withHeight (18); }
  81. Font getAlertWindowMessageFont() override { return getDialogFont().withHeight (12); }
  82. Font getAlertWindowFont() override { return getDialogFont().withHeight (12); }
  83. //==============================================================================
  84. static Colour getBackgroundColour() { return Colour (0xff4d4d4d); }
  85. static Colour getBrightButtonColour() { return Colour (0xffe6e6e6); }
  86. static Colour getErrorTextColour() { return Colour (0xfff390a2); }
  87. static Colour getBrightButtonColour (bool isMouseOverButton, bool isButtonDown)
  88. {
  89. if (isButtonDown) return getBrightButtonColour().withAlpha (0.7f);
  90. if (isMouseOverButton) return getBrightButtonColour().withAlpha (0.85f);
  91. return getBrightButtonColour();
  92. }
  93. private:
  94. //==============================================================================
  95. void drawPrimaryButtonBackground (Graphics& g,
  96. Rectangle<float> buttonRect,
  97. bool isMouseOverButton,
  98. bool isButtonDown)
  99. {
  100. g.setColour (getBrightButtonColour (isMouseOverButton, isButtonDown));
  101. g.fillRoundedRectangle (buttonRect, 5.0f);
  102. }
  103. void drawSecondaryButtonBackground (Graphics& g,
  104. Rectangle<float> buttonRect,
  105. bool isMouseOverButton,
  106. bool isButtonDown)
  107. {
  108. g.setColour (getBrightButtonColour (isMouseOverButton, isButtonDown));
  109. g.drawRoundedRectangle (buttonRect.reduced (1.0f), 5.0f, 2.0f);
  110. }
  111. };