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.

148 lines
5.9KB

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