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.

166 lines
6.8KB

  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. void drawXAxis (Graphics& g, const Rectangle<int>& r);
  40. void drawYAxis (Graphics& g, const Rectangle<int>& r);
  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. //==============================================================================
  49. virtual UndoManager& getUndoManager() = 0;
  50. virtual void documentChanged() = 0;
  51. virtual Component* createComponentHolder() = 0;
  52. virtual const Rectangle<int> getCanvasBounds() = 0;
  53. virtual void setCanvasBounds (const Rectangle<int>& newBounds) = 0;
  54. virtual bool canResizeCanvas() const = 0;
  55. virtual const SelectedItems::ItemType findObjectIdAt (const Point<int>& position) = 0;
  56. virtual void showPopupMenu (bool isClickOnSelectedObject) = 0;
  57. virtual void objectDoubleClicked (const MouseEvent& e, const ValueTree& state) = 0;
  58. virtual const ValueTree getObjectState (const String& objectId) = 0;
  59. virtual RelativeRectangle getObjectCoords (const ValueTree& state) = 0;
  60. virtual const Rectangle<int> getObjectPosition (const ValueTree& state) = 0;
  61. virtual bool hasSizeGuides() const = 0;
  62. virtual MarkerListBase& getMarkerList (bool isX) = 0;
  63. virtual double limitMarkerPosition (double pos) = 0;
  64. virtual SelectedItems& getSelection() = 0;
  65. virtual void deselectNonDraggableObjects() = 0;
  66. virtual void findLassoItemsInArea (Array <SelectedItems::ItemType>& itemsFound, const Rectangle<int>& area) = 0;
  67. //==============================================================================
  68. class DragOperation
  69. {
  70. public:
  71. DragOperation() {}
  72. virtual ~DragOperation() {}
  73. virtual void drag (const MouseEvent& e, const Point<int>& newPos) = 0;
  74. };
  75. virtual DragOperation* createDragOperation (const MouseEvent& e,
  76. Component* snapGuideParentComponent,
  77. const ResizableBorderComponent::Zone& zone) = 0;
  78. void beginDrag (const MouseEvent& e, const ResizableBorderComponent::Zone& zone);
  79. void continueDrag (const MouseEvent& e);
  80. void endDrag (const MouseEvent& e);
  81. void enableResizingMode();
  82. void enableControlPointMode (const ValueTree& objectToEdit);
  83. bool isResizingMode() const { return ! isControlPointMode(); }
  84. bool isControlPointMode() const { return controlPointEditingTarget.isValid(); }
  85. //==============================================================================
  86. Component* getComponentHolder() const { return componentHolder; }
  87. EditorPanelBase* getPanel() const;
  88. const Point<int>& getOrigin() const throw() { return origin; }
  89. const Point<int> screenSpaceToObjectSpace (const Point<int>& p) const;
  90. const Point<int> objectSpaceToScreenSpace (const Point<int>& p) const;
  91. const Rectangle<int> screenSpaceToObjectSpace (const Rectangle<int>& r) const;
  92. const Rectangle<int> objectSpaceToScreenSpace (const Rectangle<int>& r) const;
  93. //==============================================================================
  94. class OverlayItemComponent : public Component
  95. {
  96. public:
  97. OverlayItemComponent (EditorCanvasBase* canvas_);
  98. ~OverlayItemComponent();
  99. void setBoundsInTargetSpace (const Rectangle<int>& r);
  100. protected:
  101. EditorCanvasBase* canvas;
  102. };
  103. //==============================================================================
  104. virtual void updateControlPointComponents (Component* parent,
  105. OwnedArray<OverlayItemComponent>& existingComps) = 0;
  106. protected:
  107. //==============================================================================
  108. const BorderSize border;
  109. Point<int> origin;
  110. double scaleFactor;
  111. ValueTree controlPointEditingTarget;
  112. friend class OverlayItemComponent;
  113. class ResizeFrame;
  114. class MarkerComponent;
  115. class DocumentResizeFrame;
  116. class OverlayComponent;
  117. //==============================================================================
  118. Component* componentHolder;
  119. OverlayComponent* overlay;
  120. DocumentResizeFrame* resizeFrame;
  121. ScopedPointer<DragOperation> dragger;
  122. void handleAsyncUpdate();
  123. };
  124. #endif // __JUCER_EDITORCANVAS_H_EF886D17__