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.

183 lines
7.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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_EDITORCANVAS_H_EF886D17__
  19. #define __JUCER_EDITORCANVAS_H_EF886D17__
  20. #include "../../utility/jucer_MarkerListBase.h"
  21. class EditorPanelBase;
  22. //==============================================================================
  23. class EditorCanvasBase : public Component,
  24. public ValueTree::Listener,
  25. public AsyncUpdater
  26. {
  27. public:
  28. //==============================================================================
  29. EditorCanvasBase();
  30. ~EditorCanvasBase();
  31. void initialise();
  32. void shutdown();
  33. //==============================================================================
  34. typedef SelectedItemSet<String> SelectedItems;
  35. //==============================================================================
  36. void paint (Graphics& g);
  37. void resized();
  38. const Rectangle<int> getContentArea() const;
  39. //==============================================================================
  40. void valueTreePropertyChanged (ValueTree&, const Identifier&) { triggerAsyncUpdate(); }
  41. void valueTreeChildrenChanged (ValueTree& treeWhoseChildHasChanged) { triggerAsyncUpdate(); }
  42. void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged) {}
  43. //==============================================================================
  44. void showSizeGuides();
  45. void hideSizeGuides();
  46. struct Scale
  47. {
  48. Scale();
  49. Point<int> origin;
  50. double scale;
  51. };
  52. const Scale& getScale() const throw() { return scale; }
  53. void setScale (const Scale& newScale);
  54. //==============================================================================
  55. virtual UndoManager& getUndoManager() = 0;
  56. virtual void documentChanged() = 0;
  57. virtual Component* createComponentHolder() = 0;
  58. virtual const Rectangle<int> getCanvasBounds() = 0;
  59. virtual void setCanvasBounds (const Rectangle<int>& newBounds) = 0;
  60. virtual bool canResizeCanvas() const = 0;
  61. virtual const SelectedItems::ItemType findObjectIdAt (const Point<int>& position) = 0;
  62. virtual void showPopupMenu (bool isClickOnSelectedObject) = 0;
  63. virtual void objectDoubleClicked (const MouseEvent& e, const ValueTree& state) = 0;
  64. virtual const ValueTree getObjectState (const String& objectId) = 0;
  65. virtual RelativeRectangle getObjectCoords (const ValueTree& state) = 0;
  66. virtual const Rectangle<int> getObjectPosition (const ValueTree& state) = 0;
  67. virtual bool hasSizeGuides() const = 0;
  68. virtual MarkerListBase& getMarkerList (bool isX) = 0;
  69. virtual double limitMarkerPosition (double pos) = 0;
  70. virtual SelectedItems& getSelection() = 0;
  71. virtual void deselectNonDraggableObjects() = 0;
  72. virtual void findLassoItemsInArea (Array <SelectedItems::ItemType>& itemsFound, const Rectangle<int>& area) = 0;
  73. //==============================================================================
  74. class DragOperation
  75. {
  76. public:
  77. DragOperation() {}
  78. virtual ~DragOperation() {}
  79. virtual void drag (const MouseEvent& e, const Point<int>& newPos) = 0;
  80. virtual void setRotationCentre (const Point<float>& rotationCentre) = 0;
  81. virtual bool isRotating() const = 0;
  82. };
  83. virtual DragOperation* createDragOperation (const Point<int>& mouseDownPos,
  84. Component* snapGuideParentComponent,
  85. const ResizableBorderComponent::Zone& zone,
  86. bool isRotating) = 0;
  87. virtual bool canRotate() const = 0;
  88. void beginDrag (const MouseEvent& e, const ResizableBorderComponent::Zone& zone,
  89. bool isRotating, const Point<float>& rotationCentre);
  90. void continueDrag (const MouseEvent& e);
  91. void endDrag (const MouseEvent& e);
  92. void enableResizingMode();
  93. void enableControlPointMode (const ValueTree& objectToEdit);
  94. bool isResizingMode() const { return ! isControlPointMode(); }
  95. bool isControlPointMode() const { return controlPointEditingTarget.isValid(); }
  96. bool isRotating() const;
  97. //==============================================================================
  98. Component* getComponentHolder() const { return componentHolder; }
  99. EditorPanelBase* getPanel() const;
  100. const Point<int> screenSpaceToObjectSpace (const Point<int>& p) const;
  101. const Point<float> screenSpaceToObjectSpace (const Point<float>& p) const;
  102. const Point<int> objectSpaceToScreenSpace (const Point<int>& p) const;
  103. const Point<float> objectSpaceToScreenSpace (const Point<float>& p) const;
  104. const Rectangle<int> screenSpaceToObjectSpace (const Rectangle<int>& r) const;
  105. const Rectangle<int> objectSpaceToScreenSpace (const Rectangle<int>& r) const;
  106. //==============================================================================
  107. class OverlayItemComponent : public Component
  108. {
  109. public:
  110. OverlayItemComponent (EditorCanvasBase* canvas_);
  111. ~OverlayItemComponent();
  112. void setBoundsInTargetSpace (const Rectangle<int>& r);
  113. const Point<float> pointToLocalSpace (const Point<float>& p) const;
  114. protected:
  115. EditorCanvasBase* canvas;
  116. };
  117. //==============================================================================
  118. virtual void updateControlPointComponents (Component* parent,
  119. OwnedArray<OverlayItemComponent>& existingComps) = 0;
  120. protected:
  121. //==============================================================================
  122. const BorderSize border;
  123. Scale scale;
  124. ValueTree controlPointEditingTarget;
  125. friend class OverlayItemComponent;
  126. class ResizeFrame;
  127. class MarkerComponent;
  128. class DocumentResizeFrame;
  129. class OverlayComponent;
  130. //==============================================================================
  131. Component* componentHolder;
  132. OverlayComponent* overlay;
  133. DocumentResizeFrame* resizeFrame;
  134. ScopedPointer<DragOperation> dragger;
  135. void handleAsyncUpdate();
  136. };
  137. #endif // __JUCER_EDITORCANVAS_H_EF886D17__