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.

84 lines
2.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. //==============================================================================
  15. struct IconButton : public Button
  16. {
  17. IconButton (String name, const Path* p)
  18. : Button (name),
  19. icon (p, Colours::transparentBlack)
  20. {
  21. lookAndFeelChanged();
  22. setTooltip (name);
  23. }
  24. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) override
  25. {
  26. auto alpha = 1.0f;
  27. if (! isEnabled())
  28. {
  29. isMouseOverButton = false;
  30. isButtonDown = false;
  31. alpha = 0.2f;
  32. }
  33. auto backgroundColour = isIDEButton ? Colours::white
  34. : isUserButton ? findColour (userButtonBackgroundColourId)
  35. : findColour (defaultButtonBackgroundColourId);
  36. backgroundColour = isButtonDown ? backgroundColour.darker (0.5f)
  37. : isMouseOverButton ? backgroundColour.darker (0.2f)
  38. : backgroundColour;
  39. auto bounds = getLocalBounds().toFloat();
  40. if (isButtonDown)
  41. bounds.reduce (2, 2);
  42. Path ellipse;
  43. ellipse.addEllipse (bounds);
  44. g.reduceClipRegion(ellipse);
  45. g.setColour (backgroundColour.withAlpha (alpha));
  46. g.fillAll();
  47. if (iconImage != Image())
  48. {
  49. if (isIDEButton)
  50. bounds.reduce (7, 7);
  51. g.setOpacity (alpha);
  52. g.drawImage (iconImage, bounds, RectanglePlacement::fillDestination, false);
  53. }
  54. else
  55. {
  56. icon.withColour (findColour (defaultIconColourId).withAlpha (alpha)).draw (g, bounds.reduced (2, 2), false);
  57. }
  58. }
  59. Icon icon;
  60. Image iconImage;
  61. bool isIDEButton = false;
  62. bool isUserButton = false;
  63. };