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.

104 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef __JUCER_GRADIENTPOINTCOMPONENT_JUCEHEADER__
  18. #define __JUCER_GRADIENTPOINTCOMPONENT_JUCEHEADER__
  19. #include "jucer_PointComponent.h"
  20. #include "jucer_ColouredElement.h"
  21. //==============================================================================
  22. class GradientPointComponent : public PointComponent
  23. {
  24. public:
  25. GradientPointComponent (ColouredElement* const owner_,
  26. const bool isStroke_,
  27. const bool isStart_)
  28. : PointComponent (owner_),
  29. isStroke (isStroke_),
  30. isStart (isStart_)
  31. {
  32. }
  33. RelativePositionedRectangle getPosition()
  34. {
  35. ColouredElement* e = dynamic_cast <ColouredElement*> (owner);
  36. if (isStroke)
  37. return isStart ? e->getStrokeType().fill.gradPos1
  38. : e->getStrokeType().fill.gradPos2;
  39. return isStart ? e->getFillType().gradPos1
  40. : e->getFillType().gradPos2;
  41. }
  42. void setPosition (const RelativePositionedRectangle& newPos)
  43. {
  44. ColouredElement* e = dynamic_cast <ColouredElement*> (owner);
  45. if (isStroke)
  46. {
  47. JucerFillType f (e->getStrokeType().fill);
  48. if (isStart)
  49. f.gradPos1 = newPos;
  50. else
  51. f.gradPos2 = newPos;
  52. e->setStrokeFill (f, true);
  53. }
  54. else
  55. {
  56. JucerFillType f (e->getFillType());
  57. if (isStart)
  58. f.gradPos1 = newPos;
  59. else
  60. f.gradPos2 = newPos;
  61. e->setFillType (f, true);
  62. }
  63. }
  64. void updatePosition()
  65. {
  66. PointComponent::updatePosition();
  67. ColouredElement* e = dynamic_cast <ColouredElement*> (owner);
  68. JucerFillType f (isStroke ? e->getStrokeType().fill
  69. : e->getFillType());
  70. setVisible (f.mode == JucerFillType::linearGradient
  71. || f.mode == JucerFillType::radialGradient);
  72. }
  73. private:
  74. bool isStroke, isStart;
  75. };
  76. #endif // __JUCER_GRADIENTPOINTCOMPONENT_JUCEHEADER__