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.

109 lines
3.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "../../../core/juce_StandardHeader.h"
  19. BEGIN_JUCE_NAMESPACE
  20. #include "juce_GradientBrush.h"
  21. #include "../contexts/juce_LowLevelGraphicsContext.h"
  22. //==============================================================================
  23. GradientBrush::GradientBrush (const Colour& colour1,
  24. const float x1,
  25. const float y1,
  26. const Colour& colour2,
  27. const float x2,
  28. const float y2,
  29. const bool isRadial) throw()
  30. : gradient (colour1, x1, y1,
  31. colour2, x2, y2,
  32. isRadial)
  33. {
  34. }
  35. GradientBrush::GradientBrush (const ColourGradient& gradient_) throw()
  36. : gradient (gradient_)
  37. {
  38. }
  39. GradientBrush::~GradientBrush() throw()
  40. {
  41. }
  42. Brush* GradientBrush::createCopy() const throw()
  43. {
  44. return new GradientBrush (gradient);
  45. }
  46. void GradientBrush::applyTransform (const AffineTransform& transform) throw()
  47. {
  48. gradient.transform = gradient.transform.followedBy (transform);
  49. }
  50. void GradientBrush::multiplyOpacity (const float multiple) throw()
  51. {
  52. gradient.multiplyOpacity (multiple);
  53. }
  54. bool GradientBrush::isInvisible() const throw()
  55. {
  56. return gradient.isInvisible();
  57. }
  58. //==============================================================================
  59. void GradientBrush::paintPath (LowLevelGraphicsContext& context,
  60. const Path& path, const AffineTransform& transform) throw()
  61. {
  62. context.setGradient (gradient);
  63. context.fillPath (path, transform);
  64. }
  65. void GradientBrush::paintRectangle (LowLevelGraphicsContext& context,
  66. int x, int y, int w, int h) throw()
  67. {
  68. context.setGradient (gradient);
  69. context.fillRect (x, y, w, h, false);
  70. }
  71. void GradientBrush::paintAlphaChannel (LowLevelGraphicsContext& context,
  72. const Image& alphaChannelImage, int imageX, int imageY,
  73. int x, int y, int w, int h) throw()
  74. {
  75. context.saveState();
  76. if (context.reduceClipRegion (x, y, w, h))
  77. {
  78. context.setGradient (gradient);
  79. context.fillAlphaChannel (alphaChannelImage, imageX, imageY);
  80. }
  81. context.restoreState();
  82. }
  83. END_JUCE_NAMESPACE