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.

221 lines
8.4KB

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