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.

243 lines
7.6KB

  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 (const Point<int>& position)
  60. {
  61. PopupMenu m;
  62. if (findObjectIdAt (position).isNotEmpty())
  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. const ValueTree getObjectState (const String& objectId)
  79. {
  80. return ValueTree();
  81. }
  82. const Rectangle<int> getObjectPosition (const ValueTree& state)
  83. {
  84. return Rectangle<int>();//getDocument().getCoordsFor (state).resolve (getDocument());
  85. }
  86. RectangleCoordinates getObjectCoords (const ValueTree& state)
  87. {
  88. return RectangleCoordinates();
  89. // return getDocument().getCoordsFor (state);
  90. }
  91. SelectedItems& getSelection()
  92. {
  93. return editor.getSelection();
  94. }
  95. void deselectNonDraggableObjects()
  96. {
  97. }
  98. void findLassoItemsInArea (Array <SelectedItems::ItemType>& itemsFound, const Rectangle<int>& area)
  99. {
  100. }
  101. //==============================================================================
  102. class DragOperation : public EditorDragOperation
  103. {
  104. public:
  105. DragOperation (DrawableEditorCanvas* canvas_,
  106. const MouseEvent& e,
  107. Component* snapGuideParentComp_,
  108. const ResizableBorderComponent::Zone& zone_)
  109. : EditorDragOperation (canvas_, e, snapGuideParentComp_, zone_)
  110. {
  111. }
  112. ~DragOperation()
  113. {
  114. getUndoManager().beginNewTransaction();
  115. }
  116. protected:
  117. DrawableDocument& getDocument() throw() { return static_cast <DrawableEditorCanvas*> (canvas)->getDocument(); }
  118. int getCanvasWidth() { return getDocument().getCanvasWidth().getValue(); }
  119. int getCanvasHeight() { return getDocument().getCanvasHeight().getValue(); }
  120. UndoManager& getUndoManager() { return *getDocument().getUndoManager(); }
  121. const Rectangle<float> getObjectPosition (const ValueTree& state)
  122. {
  123. return Rectangle<float> ();
  124. }
  125. bool setObjectPosition (ValueTree& state, const Rectangle<float>& newBounds)
  126. {
  127. return false;
  128. }
  129. float getMarkerPosition (const ValueTree& marker, bool isX)
  130. {
  131. return 0;
  132. }
  133. };
  134. DragOperation* createDragOperation (const MouseEvent& e, Component* snapGuideParentComponent,
  135. const ResizableBorderComponent::Zone& zone)
  136. {
  137. DragOperation* d = new DragOperation (this, e, snapGuideParentComponent, zone);
  138. Array<ValueTree> selected, unselected;
  139. /*for (int i = getDocument().getNumComponents(); --i >= 0;)
  140. {
  141. const ValueTree v (getDocument().getComponent (i));
  142. if (editor.getSelection().isSelected (v [ComponentDocument::idProperty]))
  143. selected.add (v);
  144. else
  145. unselected.add (v);
  146. }*/
  147. d->initialise (selected, unselected);
  148. return d;
  149. }
  150. UndoManager& getUndoManager()
  151. {
  152. return *getDocument().getUndoManager();
  153. }
  154. DrawableEditor& getEditor() throw() { return editor; }
  155. DrawableDocument& getDocument() throw() { return editor.getDocument(); }
  156. void timerCallback()
  157. {
  158. stopTimer();
  159. if (! Component::isMouseButtonDownAnywhere())
  160. getUndoManager().beginNewTransaction();
  161. }
  162. //==============================================================================
  163. class DrawableComponent : public Component
  164. {
  165. public:
  166. DrawableComponent (DrawableEditorCanvas* canvas_)
  167. : canvas (canvas_)
  168. {
  169. setOpaque (true);
  170. }
  171. ~DrawableComponent()
  172. {
  173. }
  174. void updateDrawable()
  175. {
  176. repaint();
  177. }
  178. void paint (Graphics& g)
  179. {
  180. g.fillAll (Colours::white);
  181. canvas->drawable->draw (g, 1.0f);
  182. }
  183. private:
  184. DrawableEditorCanvas* canvas;
  185. DrawableEditor& getEditor() const { return canvas->getEditor(); }
  186. };
  187. ScopedPointer<Drawable> drawable;
  188. private:
  189. //==============================================================================
  190. DrawableEditor& editor;
  191. };
  192. #endif // __JUCER_DRAWABLEOBJECTCOMPONENT_JUCEHEADER__