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.

139 lines
5.5KB

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