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.

113 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_POINTCOMPONENT_JUCEHEADER__
  19. #define __JUCER_POINTCOMPONENT_JUCEHEADER__
  20. #include "jucer_ElementSiblingComponent.h"
  21. #include "../ui/jucer_PaintRoutineEditor.h"
  22. //==============================================================================
  23. class PointComponent : public ElementSiblingComponent
  24. {
  25. public:
  26. PointComponent (PaintElement* const e)
  27. : ElementSiblingComponent (e)
  28. {
  29. setSize (11, 11);
  30. setMouseCursor (MouseCursor::UpDownLeftRightResizeCursor);
  31. }
  32. virtual RelativePositionedRectangle getPosition() = 0;
  33. virtual void setPosition (const RelativePositionedRectangle& newPos) = 0;
  34. virtual void updatePosition()
  35. {
  36. if (dynamic_cast <PaintRoutineEditor*> (getParentComponent()) != 0)
  37. {
  38. const Rectangle<int> area (((PaintRoutineEditor*) getParentComponent())->getComponentArea());
  39. const Rectangle<int> r (getPosition().getRectangle (area, owner->getDocument()->getComponentLayout()));
  40. setCentrePosition (r.getX(), r.getY());
  41. }
  42. }
  43. //==============================================================================
  44. void paint (Graphics& g)
  45. {
  46. g.setColour (Colours::white);
  47. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 2.0f);
  48. g.setColour (Colours::black);
  49. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 2.0f);
  50. }
  51. //==============================================================================
  52. void mouseDown (const MouseEvent&)
  53. {
  54. const Rectangle<int> area (((PaintRoutineEditor*) getParentComponent())->getComponentArea());
  55. dragX = getX() + getWidth() / 2 - area.getX();
  56. dragY = getY() + getHeight() / 2 - area.getY();
  57. }
  58. void mouseDrag (const MouseEvent& e)
  59. {
  60. const Rectangle<int> area (((PaintRoutineEditor*) getParentComponent())->getComponentArea());
  61. int x = dragX + e.getDistanceFromDragStartX();
  62. int y = dragY + e.getDistanceFromDragStartY();
  63. if (JucerDocument* const document = owner->getDocument())
  64. {
  65. x = document->snapPosition (x);
  66. y = document->snapPosition (y);
  67. const RelativePositionedRectangle original (getPosition());
  68. RelativePositionedRectangle pr (original);
  69. Rectangle<int> r (pr.getRectangle (Rectangle<int> (0, 0, area.getWidth(), area.getHeight()),
  70. document->getComponentLayout()));
  71. r.setPosition (x, y);
  72. pr.updateFrom (r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  73. Rectangle<int> (0, 0, area.getWidth(), area.getHeight()),
  74. document->getComponentLayout());
  75. if (pr != original)
  76. setPosition (pr);
  77. }
  78. }
  79. void mouseUp (const MouseEvent&)
  80. {
  81. }
  82. private:
  83. int dragX, dragY;
  84. };
  85. #endif // __JUCER_POINTCOMPONENT_JUCEHEADER__