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.

146 lines
5.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "../JuceLibraryCode/JuceHeader.h"
  20. //==============================================================================
  21. class MaterialLookAndFeel : public LookAndFeel_V4
  22. {
  23. public:
  24. //==============================================================================
  25. MaterialLookAndFeel()
  26. {
  27. setColour (ResizableWindow::backgroundColourId, windowBackgroundColour);
  28. setColour (TextButton::buttonOnColourId, brightButtonColour);
  29. setColour (TextButton::buttonColourId, disabledButtonColour);
  30. }
  31. //==============================================================================
  32. void drawButtonBackground (Graphics& g,
  33. Button& button,
  34. const Colour& /*backgroundColour*/,
  35. bool /*isMouseOverButton*/,
  36. bool isButtonDown) override
  37. {
  38. const auto buttonRect = button.getLocalBounds().toFloat();
  39. if (isButtonDown)
  40. g.setColour (brightButtonColour.withAlpha (0.7f));
  41. else if (! button.isEnabled())
  42. g.setColour (disabledButtonColour);
  43. else
  44. g.setColour (brightButtonColour);
  45. g.fillRoundedRectangle (buttonRect, 5.0f);
  46. }
  47. //==============================================================================
  48. void drawButtonText (Graphics& g, TextButton& button, bool isMouseOverButton, bool isButtonDown) override
  49. {
  50. ignoreUnused (isMouseOverButton, isButtonDown);
  51. Font font (getTextButtonFont (button, button.getHeight()));
  52. g.setFont (font);
  53. if (button.isEnabled())
  54. g.setColour (Colours::white);
  55. else
  56. g.setColour (backgroundColour);
  57. g.drawFittedText (button.getButtonText(), 0, 0,
  58. button.getWidth(),
  59. button.getHeight(),
  60. Justification::centred, 2);
  61. }
  62. //==============================================================================
  63. void drawLinearSlider (Graphics& g, int x, int y, int width, int height,
  64. float sliderPos, float minSliderPos, float maxSliderPos,
  65. const Slider::SliderStyle style, Slider& slider) override
  66. {
  67. ignoreUnused (style, minSliderPos, maxSliderPos);
  68. Rectangle<int> r = Rectangle<int> (x + haloRadius, y, width - (haloRadius * 2), height);
  69. Rectangle<int> backgroundBar = r.withSizeKeepingCentre(r.getWidth(), 2);
  70. sliderPos = (sliderPos - minSliderPos) / static_cast<float> (width);
  71. int knobPos = static_cast<int> (sliderPos * r.getWidth());
  72. g.setColour (sliderActivePart);
  73. g.fillRect (backgroundBar.removeFromLeft (knobPos));
  74. g.setColour (sliderInactivePart);
  75. g.fillRect (backgroundBar);
  76. if (slider.isMouseOverOrDragging())
  77. {
  78. Rectangle<int> haloBounds = r.withTrimmedLeft (knobPos - haloRadius)
  79. .withWidth (haloRadius*2)
  80. .withSizeKeepingCentre(haloRadius*2, haloRadius*2);
  81. g.setColour (sliderActivePart.withAlpha (0.5f));
  82. g.fillEllipse (haloBounds.toFloat());
  83. }
  84. const int knobRadius = slider.isMouseOverOrDragging() ? knobActiveRadius : knobInActiveRadius;
  85. Rectangle<int> knobBounds = r.withTrimmedLeft (knobPos - knobRadius)
  86. .withWidth (knobRadius*2)
  87. .withSizeKeepingCentre(knobRadius*2, knobRadius*2);
  88. g.setColour (sliderActivePart);
  89. g.fillEllipse (knobBounds.toFloat());
  90. }
  91. //==============================================================================
  92. Font getTextButtonFont (TextButton& button, int buttonHeight) override
  93. {
  94. return LookAndFeel_V3::getTextButtonFont (button, buttonHeight).withHeight (buttonFontSize);
  95. }
  96. Font getLabelFont (Label& label) override
  97. {
  98. return LookAndFeel_V3::getLabelFont (label).withHeight (labelFontSize);
  99. }
  100. //==============================================================================
  101. const int labelFontSize = 12;
  102. const int buttonFontSize = 15;
  103. //==============================================================================
  104. const int knobActiveRadius = 12;
  105. const int knobInActiveRadius = 8;
  106. const int haloRadius = 18;
  107. //==============================================================================
  108. const Colour windowBackgroundColour = Colour (0xff262328);
  109. const Colour backgroundColour = Colour (0xff4d4d4d);
  110. const Colour brightButtonColour = Colour (0xff80cbc4);
  111. const Colour disabledButtonColour = Colour (0xffe4e4e4);
  112. const Colour sliderInactivePart = Colour (0xff545d62);
  113. const Colour sliderActivePart = Colour (0xff80cbc4);
  114. };