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.

247 lines
7.7KB

  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_DRAWABLEOBJECTCOMPONENT_JUCEHEADER__
  19. #define __JUCER_DRAWABLEOBJECTCOMPONENT_JUCEHEADER__
  20. #include "jucer_DrawableEditor.h"
  21. //==============================================================================
  22. class DrawableEditorCanvas : public EditorCanvasBase,
  23. public Timer
  24. {
  25. public:
  26. DrawableEditorCanvas (DrawableEditor& editor_)
  27. : editor (editor_)
  28. {
  29. initialise();
  30. editor.getDocument().getRoot().addListener (this);
  31. }
  32. ~DrawableEditorCanvas()
  33. {
  34. editor.getDocument().getRoot().removeListener (this);
  35. shutdown();
  36. }
  37. Component* createComponentHolder()
  38. {
  39. return new DrawableComponent (this);
  40. }
  41. void updateComponents()
  42. {
  43. drawable = Drawable::createFromValueTree (getEditor().getDocument().getRootDrawableNode());
  44. getComponentHolder()->repaint();
  45. startTimer (500);
  46. }
  47. int getCanvasWidth() { return getDocument().getCanvasWidth().getValue(); }
  48. int getCanvasHeight() { return getDocument().getCanvasHeight().getValue(); }
  49. void setCanvasWidth (int w) { getDocument().getCanvasWidth() = w; }
  50. void setCanvasHeight (int h) { getDocument().getCanvasHeight() = h; }
  51. MarkerListBase& getMarkerList (bool isX)
  52. {
  53. return getDocument().getMarkerList (isX);
  54. }
  55. const SelectedItems::ItemType findObjectIdAt (const Point<int>& position)
  56. {
  57. return String::empty;
  58. }
  59. void showPopupMenu (bool isClickOnSelectedObject)
  60. {
  61. PopupMenu m;
  62. if (isClickOnSelectedObject)
  63. {
  64. m.addCommandItem (commandManager, CommandIDs::toFront);
  65. m.addCommandItem (commandManager, CommandIDs::toBack);
  66. m.addSeparator();
  67. m.addCommandItem (commandManager, StandardApplicationCommandIDs::del);
  68. const int r = m.show();
  69. (void) r;
  70. }
  71. else
  72. {
  73. // getDocument().addNewComponentMenuItems (m);
  74. // const int r = m.show();
  75. // getDocument().performNewComponentMenuItem (r);
  76. }
  77. }
  78. void objectDoubleClicked (const MouseEvent& e, const ValueTree& state)
  79. {
  80. }
  81. const ValueTree getObjectState (const String& objectId)
  82. {
  83. return ValueTree();
  84. }
  85. const Rectangle<int> getObjectPosition (const ValueTree& state)
  86. {
  87. return Rectangle<int>();//getDocument().getCoordsFor (state).resolve (getDocument());
  88. }
  89. RectangleCoordinates getObjectCoords (const ValueTree& state)
  90. {
  91. return RectangleCoordinates();
  92. // return getDocument().getCoordsFor (state);
  93. }
  94. SelectedItems& getSelection()
  95. {
  96. return editor.getSelection();
  97. }
  98. void deselectNonDraggableObjects()
  99. {
  100. }
  101. void findLassoItemsInArea (Array <SelectedItems::ItemType>& itemsFound, const Rectangle<int>& area)
  102. {
  103. }
  104. //==============================================================================
  105. class DragOperation : public EditorDragOperation
  106. {
  107. public:
  108. DragOperation (DrawableEditorCanvas* canvas_,
  109. const MouseEvent& e,
  110. Component* snapGuideParentComp_,
  111. const ResizableBorderComponent::Zone& zone_)
  112. : EditorDragOperation (canvas_, e, snapGuideParentComp_, zone_)
  113. {
  114. }
  115. ~DragOperation()
  116. {
  117. getUndoManager().beginNewTransaction();
  118. }
  119. protected:
  120. DrawableDocument& getDocument() throw() { return static_cast <DrawableEditorCanvas*> (canvas)->getDocument(); }
  121. int getCanvasWidth() { return getDocument().getCanvasWidth().getValue(); }
  122. int getCanvasHeight() { return getDocument().getCanvasHeight().getValue(); }
  123. UndoManager& getUndoManager() { return *getDocument().getUndoManager(); }
  124. const Rectangle<float> getObjectPosition (const ValueTree& state)
  125. {
  126. return Rectangle<float> ();
  127. }
  128. bool setObjectPosition (ValueTree& state, const Rectangle<float>& newBounds)
  129. {
  130. return false;
  131. }
  132. float getMarkerPosition (const ValueTree& marker, bool isX)
  133. {
  134. return 0;
  135. }
  136. };
  137. DragOperation* createDragOperation (const MouseEvent& e, Component* snapGuideParentComponent,
  138. const ResizableBorderComponent::Zone& zone)
  139. {
  140. DragOperation* d = new DragOperation (this, e, snapGuideParentComponent, zone);
  141. Array<ValueTree> selected, unselected;
  142. /*for (int i = getDocument().getNumComponents(); --i >= 0;)
  143. {
  144. const ValueTree v (getDocument().getComponent (i));
  145. if (editor.getSelection().isSelected (v [ComponentDocument::idProperty]))
  146. selected.add (v);
  147. else
  148. unselected.add (v);
  149. }*/
  150. d->initialise (selected, unselected);
  151. return d;
  152. }
  153. UndoManager& getUndoManager()
  154. {
  155. return *getDocument().getUndoManager();
  156. }
  157. DrawableEditor& getEditor() throw() { return editor; }
  158. DrawableDocument& getDocument() throw() { return editor.getDocument(); }
  159. void timerCallback()
  160. {
  161. stopTimer();
  162. if (! Component::isMouseButtonDownAnywhere())
  163. getUndoManager().beginNewTransaction();
  164. }
  165. //==============================================================================
  166. class DrawableComponent : public Component
  167. {
  168. public:
  169. DrawableComponent (DrawableEditorCanvas* canvas_)
  170. : canvas (canvas_)
  171. {
  172. setOpaque (true);
  173. }
  174. ~DrawableComponent()
  175. {
  176. }
  177. void updateDrawable()
  178. {
  179. repaint();
  180. }
  181. void paint (Graphics& g)
  182. {
  183. g.fillAll (Colours::white);
  184. canvas->drawable->draw (g, 1.0f);
  185. }
  186. private:
  187. DrawableEditorCanvas* canvas;
  188. DrawableEditor& getEditor() const { return canvas->getEditor(); }
  189. };
  190. ScopedPointer<Drawable> drawable;
  191. private:
  192. //==============================================================================
  193. DrawableEditor& editor;
  194. };
  195. #endif // __JUCER_DRAWABLEOBJECTCOMPONENT_JUCEHEADER__