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.

204 lines
8.0KB

  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. bool keyStateChanged (bool isKeyDown);
  39. bool keyPressed (const KeyPress& key);
  40. const Rectangle<int> getContentArea() const;
  41. //==============================================================================
  42. void valueTreePropertyChanged (ValueTree&, const Identifier&) { triggerAsyncUpdate(); }
  43. void valueTreeChildrenChanged (ValueTree& treeWhoseChildHasChanged) { triggerAsyncUpdate(); }
  44. void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged) {}
  45. //==============================================================================
  46. void showSizeGuides();
  47. void hideSizeGuides();
  48. struct Scale
  49. {
  50. Scale();
  51. Point<int> origin;
  52. double scale;
  53. };
  54. const Scale& getScale() const throw() { return scale; }
  55. void setScale (const Scale& newScale);
  56. //==============================================================================
  57. virtual UndoManager& getUndoManager() = 0;
  58. virtual void documentChanged() = 0;
  59. virtual Component* createComponentHolder() = 0;
  60. virtual const Rectangle<int> getCanvasBounds() = 0;
  61. virtual void setCanvasBounds (const Rectangle<int>& newBounds) = 0;
  62. virtual bool canResizeCanvas() const = 0;
  63. virtual const SelectedItems::ItemType findObjectIdAt (const Point<int>& position) = 0;
  64. virtual void showPopupMenu (bool isClickOnSelectedObject) = 0;
  65. virtual void objectDoubleClicked (const MouseEvent& e, const ValueTree& state) = 0;
  66. virtual const ValueTree getObjectState (const String& objectId) = 0;
  67. virtual RelativeRectangle getObjectCoords (const ValueTree& state) = 0;
  68. virtual const Rectangle<int> getObjectPosition (const ValueTree& state) = 0;
  69. virtual bool hasSizeGuides() const = 0;
  70. virtual MarkerListBase& getMarkerList (bool isX) = 0;
  71. virtual double limitMarkerPosition (double pos) = 0;
  72. virtual SelectedItems& getSelection() = 0;
  73. virtual void deselectNonDraggableObjects() = 0;
  74. virtual void findLassoItemsInArea (Array <SelectedItems::ItemType>& itemsFound, const Rectangle<int>& area) = 0;
  75. //==============================================================================
  76. class DragOperation
  77. {
  78. public:
  79. DragOperation() {}
  80. virtual ~DragOperation() {}
  81. virtual void drag (const MouseEvent& e, const Point<int>& newPos) = 0;
  82. virtual void setRotationCentre (const Point<float>& rotationCentre) = 0;
  83. virtual bool isRotating() const = 0;
  84. };
  85. virtual DragOperation* createDragOperation (const Point<int>& mouseDownPos,
  86. Component* snapGuideParentComponent,
  87. const ResizableBorderComponent::Zone& zone,
  88. bool isRotating) = 0;
  89. virtual bool canRotate() const = 0;
  90. void beginDrag (const MouseEvent& e, const ResizableBorderComponent::Zone& zone,
  91. bool isRotating, const Point<float>& rotationCentre);
  92. void continueDrag (const MouseEvent& e);
  93. void endDrag (const MouseEvent& e);
  94. void enableResizingMode();
  95. void enableControlPointMode (const ValueTree& objectToEdit);
  96. bool isResizingMode() const { return ! isControlPointMode(); }
  97. bool isControlPointMode() const { return controlPointEditingTarget.isValid(); }
  98. bool isRotating() const;
  99. //==============================================================================
  100. Component* getComponentHolder() const { return componentHolder; }
  101. EditorPanelBase* getPanel() const;
  102. const Point<int> screenSpaceToObjectSpace (const Point<int>& p) const;
  103. const Point<float> screenSpaceToObjectSpace (const Point<float>& p) const;
  104. const Point<int> objectSpaceToScreenSpace (const Point<int>& p) const;
  105. const Point<float> objectSpaceToScreenSpace (const Point<float>& p) const;
  106. const Rectangle<int> screenSpaceToObjectSpace (const Rectangle<int>& r) const;
  107. const Rectangle<int> objectSpaceToScreenSpace (const Rectangle<int>& r) const;
  108. //==============================================================================
  109. class OverlayItemComponent : public Component
  110. {
  111. public:
  112. OverlayItemComponent (EditorCanvasBase* canvas_);
  113. ~OverlayItemComponent();
  114. void setBoundsInTargetSpace (const Rectangle<int>& r);
  115. const Point<float> pointToLocalSpace (const Point<float>& p) const;
  116. protected:
  117. EditorCanvasBase* canvas;
  118. };
  119. //==============================================================================
  120. virtual void updateControlPointComponents (Component* parent,
  121. OwnedArray<OverlayItemComponent>& existingComps) = 0;
  122. protected:
  123. //==============================================================================
  124. const BorderSize border;
  125. Scale scale;
  126. ValueTree controlPointEditingTarget;
  127. friend class OverlayItemComponent;
  128. class ResizeFrame;
  129. class MarkerComponent;
  130. class DocumentResizeFrame;
  131. class OverlayComponent;
  132. class SpacebarDragOverlay : public Component
  133. {
  134. public:
  135. SpacebarDragOverlay();
  136. ~SpacebarDragOverlay();
  137. bool updateVisibility();
  138. void paint (Graphics&);
  139. void mouseMove (const MouseEvent& e);
  140. void mouseDown (const MouseEvent& e);
  141. void mouseDrag (const MouseEvent& e);
  142. void modifierKeysChanged (const ModifierKeys& modifiers);
  143. private:
  144. Point<int> dragStart;
  145. };
  146. //==============================================================================
  147. ScopedPointer<Component> componentHolder;
  148. ScopedPointer<OverlayComponent> overlay;
  149. ScopedPointer<DocumentResizeFrame> resizeFrame;
  150. SpacebarDragOverlay spacebarDragOverlay;
  151. ScopedPointer<DragOperation> dragger;
  152. void handleAsyncUpdate();
  153. };
  154. #endif // __JUCER_EDITORCANVAS_H_EF886D17__