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.

128 lines
5.1KB

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