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.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  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. };