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.

93 lines
2.6KB

  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. #include "jucer_PointComponent.h"
  15. #include "jucer_ColouredElement.h"
  16. //==============================================================================
  17. class GradientPointComponent : public PointComponent
  18. {
  19. public:
  20. GradientPointComponent (ColouredElement* const owner_,
  21. const bool isStroke_,
  22. const bool isStart_)
  23. : PointComponent (owner_),
  24. isStroke (isStroke_),
  25. isStart (isStart_)
  26. {
  27. }
  28. RelativePositionedRectangle getPosition()
  29. {
  30. ColouredElement* e = dynamic_cast<ColouredElement*> (owner);
  31. if (isStroke)
  32. return isStart ? e->getStrokeType().fill.gradPos1
  33. : e->getStrokeType().fill.gradPos2;
  34. return isStart ? e->getFillType().gradPos1
  35. : e->getFillType().gradPos2;
  36. }
  37. void setPosition (const RelativePositionedRectangle& newPos)
  38. {
  39. ColouredElement* e = dynamic_cast<ColouredElement*> (owner);
  40. if (isStroke)
  41. {
  42. JucerFillType f (e->getStrokeType().fill);
  43. if (isStart)
  44. f.gradPos1 = newPos;
  45. else
  46. f.gradPos2 = newPos;
  47. e->setStrokeFill (f, true);
  48. }
  49. else
  50. {
  51. JucerFillType f (e->getFillType());
  52. if (isStart)
  53. f.gradPos1 = newPos;
  54. else
  55. f.gradPos2 = newPos;
  56. e->setFillType (f, true);
  57. }
  58. }
  59. void updatePosition()
  60. {
  61. PointComponent::updatePosition();
  62. ColouredElement* e = dynamic_cast<ColouredElement*> (owner);
  63. JucerFillType f (isStroke ? e->getStrokeType().fill
  64. : e->getFillType());
  65. setVisible (f.mode == JucerFillType::linearGradient
  66. || f.mode == JucerFillType::radialGradient);
  67. }
  68. private:
  69. bool isStroke, isStart;
  70. };