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.

108 lines
3.8KB

  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_ElementSiblingComponent.h"
  19. #include "../ui/jucer_PaintRoutineEditor.h"
  20. //==============================================================================
  21. class PointComponent : public ElementSiblingComponent
  22. {
  23. public:
  24. PointComponent (PaintElement* const e)
  25. : ElementSiblingComponent (e)
  26. {
  27. setSize (11, 11);
  28. setMouseCursor (MouseCursor::UpDownLeftRightResizeCursor);
  29. }
  30. virtual RelativePositionedRectangle getPosition() = 0;
  31. virtual void setPosition (const RelativePositionedRectangle& newPos) = 0;
  32. void updatePosition() override
  33. {
  34. if (dynamic_cast<PaintRoutineEditor*> (getParentComponent()) != nullptr)
  35. {
  36. const Rectangle<int> area (((PaintRoutineEditor*) getParentComponent())->getComponentArea());
  37. const Rectangle<int> r (getPosition().getRectangle (area, owner->getDocument()->getComponentLayout()));
  38. setCentrePosition (r.getX(), r.getY());
  39. }
  40. }
  41. //==============================================================================
  42. void paint (Graphics& g) override
  43. {
  44. g.setColour (Colours::white);
  45. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 2.0f);
  46. g.setColour (Colours::black);
  47. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 2.0f);
  48. }
  49. //==============================================================================
  50. void mouseDown (const MouseEvent&) override
  51. {
  52. const Rectangle<int> area (((PaintRoutineEditor*) getParentComponent())->getComponentArea());
  53. dragX = getX() + getWidth() / 2 - area.getX();
  54. dragY = getY() + getHeight() / 2 - area.getY();
  55. }
  56. void mouseDrag (const MouseEvent& e) override
  57. {
  58. const Rectangle<int> area (((PaintRoutineEditor*) getParentComponent())->getComponentArea());
  59. int x = dragX + e.getDistanceFromDragStartX();
  60. int y = dragY + e.getDistanceFromDragStartY();
  61. if (JucerDocument* const document = owner->getDocument())
  62. {
  63. x = document->snapPosition (x);
  64. y = document->snapPosition (y);
  65. const RelativePositionedRectangle original (getPosition());
  66. RelativePositionedRectangle pr (original);
  67. Rectangle<int> r (pr.getRectangle (Rectangle<int> (0, 0, area.getWidth(), area.getHeight()),
  68. document->getComponentLayout()));
  69. r.setPosition (x, y);
  70. pr.updateFrom (r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  71. Rectangle<int> (0, 0, area.getWidth(), area.getHeight()),
  72. document->getComponentLayout());
  73. if (pr != original)
  74. setPosition (pr);
  75. }
  76. }
  77. void mouseUp (const MouseEvent&) override
  78. {
  79. }
  80. private:
  81. int dragX, dragY;
  82. };