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.

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