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.

134 lines
5.3KB

  1. /*
  2. ==============================================================================
  3. Copyright (c) 2015 - ROLI Ltd.
  4. ==============================================================================
  5. */
  6. #include "../JuceLibraryCode/JuceHeader.h"
  7. //==============================================================================
  8. class MaterialLookAndFeel : public LookAndFeel_V3
  9. {
  10. public:
  11. //==============================================================================
  12. MaterialLookAndFeel()
  13. {
  14. setColour (ResizableWindow::backgroundColourId, windowBackgroundColour);
  15. setColour (TextButton::buttonOnColourId, brightButtonColour);
  16. setColour (TextButton::buttonColourId, disabledButtonColour);
  17. }
  18. //==============================================================================
  19. void drawButtonBackground (Graphics& g,
  20. Button& button,
  21. const Colour& /*backgroundColour*/,
  22. bool isMouseOverButton,
  23. bool isButtonDown) override
  24. {
  25. ignoreUnused (isMouseOverButton);
  26. const int width = button.getWidth();
  27. const int height = button.getHeight();
  28. Rectangle<float> buttonRect (0, 0, width, height);
  29. buttonRect.reduce (haloRadius, 0.0f);
  30. if (isButtonDown)
  31. g.setColour (brightButtonColour.withAlpha (0.7f));
  32. else if (! button.isEnabled())
  33. g.setColour (disabledButtonColour);
  34. else
  35. g.setColour (brightButtonColour);
  36. g.fillRoundedRectangle (buttonRect, 5.0f);
  37. }
  38. //==============================================================================
  39. void drawButtonText (Graphics& g, TextButton& button, bool isMouseOverButton, bool isButtonDown) override
  40. {
  41. ignoreUnused (isMouseOverButton, isButtonDown);
  42. Font font (getTextButtonFont (button, button.getHeight()));
  43. g.setFont (font);
  44. if (button.isEnabled())
  45. g.setColour (Colours::white);
  46. else
  47. g.setColour (backgroundColour);
  48. g.drawFittedText (button.getButtonText(), 0, 1,
  49. button.getWidth(),
  50. button.getHeight(),
  51. Justification::centred, 2);
  52. }
  53. //==============================================================================
  54. void drawLinearSlider (Graphics& g, int x, int y, int width, int height,
  55. float sliderPos, float minSliderPos, float maxSliderPos,
  56. const Slider::SliderStyle style, Slider& slider) override
  57. {
  58. ignoreUnused (style, minSliderPos, maxSliderPos);
  59. Rectangle<int> r = Rectangle<int> (x + haloRadius, y, width - (haloRadius * 2), height);
  60. Rectangle<int> backgroundBar = r.withSizeKeepingCentre(r.getWidth(), 2);
  61. sliderPos = (sliderPos - minSliderPos) / static_cast<float> (width);
  62. int knobPos = static_cast<int> (sliderPos * r.getWidth());
  63. g.setColour (sliderActivePart);
  64. g.fillRect (backgroundBar.removeFromLeft (knobPos));
  65. g.setColour (sliderInactivePart);
  66. g.fillRect (backgroundBar);
  67. if (slider.isMouseOverOrDragging())
  68. {
  69. Rectangle<int> haloBounds = r.withTrimmedLeft (knobPos - haloRadius)
  70. .withWidth (haloRadius*2)
  71. .withSizeKeepingCentre(haloRadius*2, haloRadius*2);
  72. g.setColour (sliderActivePart.withAlpha (0.5f));
  73. g.fillEllipse (haloBounds.toFloat());
  74. }
  75. const int knobRadius = slider.isMouseOverOrDragging() ? knobActiveRadius : knobInActiveRadius;
  76. Rectangle<int> knobBounds = r.withTrimmedLeft (knobPos - knobRadius)
  77. .withWidth (knobRadius*2)
  78. .withSizeKeepingCentre(knobRadius*2, knobRadius*2);
  79. g.setColour (sliderActivePart);
  80. g.fillEllipse (knobBounds.toFloat());
  81. }
  82. //==============================================================================
  83. Font getTextButtonFont (TextButton& button, int buttonHeight) override
  84. {
  85. return LookAndFeel_V3::getTextButtonFont (button, buttonHeight).withHeight (buttonFontSize);
  86. }
  87. Font getLabelFont (Label& label) override
  88. {
  89. return LookAndFeel_V3::getLabelFont (label).withHeight (labelFontSize);
  90. }
  91. //==============================================================================
  92. const int labelFontSize = 12;
  93. const int buttonFontSize = 15;
  94. //==============================================================================
  95. const int knobActiveRadius = 12;
  96. const int knobInActiveRadius = 8;
  97. const int haloRadius = 18;
  98. //==============================================================================
  99. const Colour windowBackgroundColour = Colour (0xff262328);
  100. const Colour backgroundColour = Colour (0xff4d4d4d);
  101. const Colour brightButtonColour = Colour (0xff80cbc4);
  102. const Colour disabledButtonColour = Colour (0xffe4e4e4);
  103. const Colour sliderInactivePart = Colour (0xff545d62);
  104. const Colour sliderActivePart = Colour (0xff80cbc4);
  105. };