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.

100 lines
2.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. #include "jucer_PointComponent.h"
  19. #include "jucer_ColouredElement.h"
  20. //==============================================================================
  21. class GradientPointComponent : public PointComponent
  22. {
  23. public:
  24. GradientPointComponent (ColouredElement* const owner_,
  25. const bool isStroke_,
  26. const bool isStart_)
  27. : PointComponent (owner_),
  28. isStroke (isStroke_),
  29. isStart (isStart_)
  30. {
  31. }
  32. RelativePositionedRectangle getPosition()
  33. {
  34. ColouredElement* e = dynamic_cast<ColouredElement*> (owner);
  35. if (isStroke)
  36. return isStart ? e->getStrokeType().fill.gradPos1
  37. : e->getStrokeType().fill.gradPos2;
  38. return isStart ? e->getFillType().gradPos1
  39. : e->getFillType().gradPos2;
  40. }
  41. void setPosition (const RelativePositionedRectangle& newPos)
  42. {
  43. ColouredElement* e = dynamic_cast<ColouredElement*> (owner);
  44. if (isStroke)
  45. {
  46. JucerFillType f (e->getStrokeType().fill);
  47. if (isStart)
  48. f.gradPos1 = newPos;
  49. else
  50. f.gradPos2 = newPos;
  51. e->setStrokeFill (f, true);
  52. }
  53. else
  54. {
  55. JucerFillType f (e->getFillType());
  56. if (isStart)
  57. f.gradPos1 = newPos;
  58. else
  59. f.gradPos2 = newPos;
  60. e->setFillType (f, true);
  61. }
  62. }
  63. void updatePosition()
  64. {
  65. PointComponent::updatePosition();
  66. ColouredElement* e = dynamic_cast<ColouredElement*> (owner);
  67. JucerFillType f (isStroke ? e->getStrokeType().fill
  68. : e->getFillType());
  69. setVisible (f.mode == JucerFillType::linearGradient
  70. || f.mode == JucerFillType::radialGradient);
  71. }
  72. private:
  73. bool isStroke, isStart;
  74. };