1 /* === S Y N F I G ========================================================= */
2 /*! \file canvasinterface.h
3 ** \brief Template Header
5 ** $Id: canvasinterface.h,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_APP_CANVASINTERFACE_H
26 #define __SYNFIG_APP_CANVASINTERFACE_H
28 /* === H E A D E R S ======================================================= */
30 //#include <synfig/canvas.h>
31 #include <synfig/value.h>
32 #include <sigc++/signal.h>
33 #include <sigc++/object.h>
35 #include "selectionmanager.h"
36 #include "uimanager.h"
37 #include "value_desc.h"
40 /* === M A C R O S ========================================================= */
42 /* === T Y P E D E F S ===================================================== */
44 /* === C L A S S E S & S T R U C T S ======================================= */
46 namespace synfig { class ValueNode_DynamicList; class Waypoint; class GUIDSet; class Canvas; };
50 namespace Action { class ParamList; class Param; class EditModeSet; };
55 class CanvasInterface : public etl::shared_object, public sigc::trackable
57 friend class Instance;
58 friend class Action::EditModeSet;
62 typedef EditMode Mode;
65 // Constructor is private to force the use of the "create()" constructor.
66 CanvasInterface(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas);
69 etl::loose_handle<Instance> instance_;
70 etl::handle<synfig::Canvas> canvas_;
71 etl::handle<SelectionManager> selection_manager_;
72 etl::handle<UIInterface> ui_interface_;
73 synfig::Time cur_time_;
76 sigc::signal<void,synfig::Layer::Handle> signal_layer_raised_;
77 sigc::signal<void,synfig::Layer::Handle> signal_layer_lowered_;
78 sigc::signal<void,synfig::Layer::Handle,int> signal_layer_inserted_;
79 sigc::signal<void,synfig::Layer::Handle,int,synfig::Canvas::Handle> signal_layer_moved_;
80 sigc::signal<void,synfig::Layer::Handle> signal_layer_removed_;
81 sigc::signal<void,synfig::Layer::Handle,bool> signal_layer_status_changed_;
82 sigc::signal<void,synfig::Layer::Handle,synfig::String> signal_layer_new_description_;
83 sigc::signal<void,synfig::Canvas::Handle> signal_canvas_added_;
84 sigc::signal<void,synfig::Canvas::Handle> signal_canvas_removed_;
86 sigc::signal<void,synfig::ValueNode::Handle> signal_value_node_added_;
87 sigc::signal<void,synfig::ValueNode::Handle> signal_value_node_deleted_;
88 sigc::signal<void,synfig::ValueNode::Handle> signal_value_node_changed_;
89 sigc::signal<void,synfig::ValueNode::Handle,synfig::ValueNode::Handle> signal_value_node_replaced_;
91 sigc::signal<void,synfig::Keyframe> signal_keyframe_added_;
92 sigc::signal<void,synfig::Keyframe> signal_keyframe_removed_;
93 sigc::signal<void,synfig::Keyframe> signal_keyframe_changed_;
95 sigc::signal<void> signal_id_changed_;
97 sigc::signal<void> signal_time_changed_;
99 sigc::signal<void> signal_rend_desc_changed_;
101 sigc::signal<void,Mode> signal_mode_changed_;
103 //sigc::signal<void> signal_dirty_preview_;
105 sigc::signal<void,synfig::Layer::Handle,synfig::String> signal_layer_param_changed_;
107 public: // Signal Interface
109 sigc::signal<void,synfig::Layer::Handle,int,synfig::Canvas::Handle>& signal_layer_moved() { return signal_layer_moved_; }
111 sigc::signal<void,synfig::Layer::Handle,synfig::String>& signal_layer_new_description() { return signal_layer_new_description_; }
113 //! Signal called when layer is raised.
114 sigc::signal<void,synfig::Layer::Handle>& signal_layer_raised() { return signal_layer_raised_; }
116 //! Signal called when layer is lowered.
117 sigc::signal<void,synfig::Layer::Handle>& signal_layer_lowered() { return signal_layer_lowered_; }
119 //! Signal called when layer has been inserted at a given position.
120 sigc::signal<void,synfig::Layer::Handle,int>& signal_layer_inserted() { return signal_layer_inserted_; }
122 //! Signal called when a layer has been removed from the canvas.
123 sigc::signal<void,synfig::Layer::Handle>& signal_layer_removed() { return signal_layer_removed_; }
125 //! Signal called when the layer's active status has changed.
126 sigc::signal<void,synfig::Layer::Handle,bool>& signal_layer_status_changed() { return signal_layer_status_changed_; }
128 //! Signal called when a canvas has been added.
129 sigc::signal<void,etl::handle<synfig::Canvas> >& signal_canvas_added() { return signal_canvas_added_; }
131 //! Signal called when a canvas has been removed.
132 sigc::signal<void,etl::handle<synfig::Canvas> >& signal_canvas_removed() { return signal_canvas_removed_; }
134 //! Signal called when a layer's parameter has been changed
135 sigc::signal<void,synfig::Layer::Handle,synfig::String>& signal_layer_param_changed() { return signal_layer_param_changed_; }
137 //! Signal called when the canvas's preview needs to be updated
138 //sigc::signal<void>& signal_dirty_preview() { return signal_dirty_preview_; }
139 sigc::signal<void>& signal_dirty_preview() { return get_canvas()->signal_dirty(); }
141 sigc::signal<void,etl::handle<synfig::ValueNode>,etl::handle<synfig::ValueNode> >&
142 signal_value_node_child_added() { return get_canvas()->signal_value_node_child_added(); }
143 sigc::signal<void,etl::handle<synfig::ValueNode>,etl::handle<synfig::ValueNode> >&
144 signal_value_node_child_removed() { return get_canvas()->signal_value_node_child_removed(); }
146 //! Signal called when a ValueNode has changed
147 sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_added() { return signal_value_node_added_; }
149 //! Signal called when a ValueNode has been deleted
150 sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_deleted() { return signal_value_node_deleted_; }
152 //! Signal called when a ValueNode has been changed
153 sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_changed() { return get_canvas()->signal_value_node_changed(); }
154 //sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_changed() { return signal_value_node_changed_; }
156 //! Signal called when the mode has changed
157 sigc::signal<void,Mode> signal_mode_changed() { return signal_mode_changed_; }
159 //! Signal called when a the ID has been changed
160 sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
162 //! Signal called whenever the time changes
163 sigc::signal<void> signal_time_changed() { return signal_time_changed_; }
165 //! Signal called whenever a data node has been replaced.
166 /*! Second ValueNode replaces first */
167 sigc::signal<void,synfig::ValueNode::Handle,synfig::ValueNode::Handle>& signal_value_node_replaced()
168 { return signal_value_node_replaced_; }
170 //! Signal called whenever the RendDesc changes
171 sigc::signal<void>& signal_rend_desc_changed() { return signal_rend_desc_changed_; }
173 sigc::signal<void,synfig::Keyframe>& signal_keyframe_added() { return signal_keyframe_added_; }
175 sigc::signal<void,synfig::Keyframe>& signal_keyframe_removed() { return signal_keyframe_removed_; }
177 sigc::signal<void,synfig::Keyframe>& signal_keyframe_changed() { return signal_keyframe_changed_; }
181 void auto_export(const ValueDesc& value_desc);
183 void auto_export(synfig::ValueNode::Handle value_node);
185 void set_meta_data(const synfig::String& key,const synfig::String& data);
187 //! Changes the current SelectionManager object
188 void set_selection_manager(const etl::handle<SelectionManager> &sm) { selection_manager_=sm; }
190 //! Disables the selection manager
191 void unset_selection_manager() { selection_manager_=new NullSelectionManager(); }
193 //! Returns a handle to the current SelectionManager
194 const etl::handle<SelectionManager> &get_selection_manager()const { return selection_manager_; }
196 //! Changes the current UIInterface object
197 void set_ui_interface(const etl::handle<UIInterface> &uim) { ui_interface_=uim; }
199 //! Disables the UIInterface
200 void unset_ui_interface() { ui_interface_=new DefaultUIInterface(); }
202 //! Returns a handle to the current UIInterface
203 const etl::handle<UIInterface> &get_ui_interface() { return ui_interface_; }
205 //! Returns the Canvas associated with this interface
206 etl::handle<synfig::Canvas> get_canvas()const { return canvas_; }
208 //! Returns the Instance associated with this interface
209 etl::loose_handle<Instance> get_instance()const { return instance_; }
211 //! Changes the name of the canvas. Undoable.
212 bool set_name(const synfig::String &x);
214 //! Changes the description of the canvas. Undoable.
215 bool set_description(const synfig::String &x);
217 //! Changes the ID of the canvas. Undoable.
218 bool set_id(const synfig::String &x);
220 //! Convience function to retrieve the name of the canvas
221 synfig::String get_name()const { return get_canvas()->get_name(); }
223 //! Convience function to retrieve the description of the canvas
224 synfig::String get_description()const { return get_canvas()->get_description(); }
226 //! Convience function to retrieve the ID of the canvas
227 synfig::String get_id()const { return get_canvas()->get_id(); }
229 //! Sets the current time
230 void set_time(synfig::Time x);
232 //! Retrieves the current time
233 synfig::Time get_time()const;
235 //! Changes the current time to the next keyframe
236 void jump_to_next_keyframe();
238 //! Changes the current time to the next keyframe
239 void jump_to_prev_keyframe();
241 void seek_frame(int frames);
243 void seek_time(synfig::Time time);
246 void refresh_current_values();
248 //! Sets the current editing mode
250 void set_mode(Mode x);
252 //! Retrieves the current editing mode
254 Mode get_mode()const;
256 //! Creates a new layer, of type \c id at the top of the layer stack
257 synfig::Layer::Handle add_layer(synfig::String id) { return add_layer_to(id,get_canvas()); }
259 synfig::Layer::Handle add_layer_to(synfig::String id,synfig::Canvas::Handle canvas, int depth=0);
261 bool convert(ValueDesc value_desc, synfig::String type);
262 //! Adds the given ValueNode to the canvas.
263 bool add_value_node(synfig::ValueNode::Handle value_node, synfig::String name);
266 Action::ParamList generate_param_list(const synfigapp::ValueDesc &);
268 Action::ParamList generate_param_list(const std::list<synfigapp::ValueDesc> &);
270 void set_rend_desc(const synfig::RendDesc &rend_desc);
272 bool import(const synfig::String &filename, bool copy=false);
275 void waypoint_duplicate(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint);
277 void waypoint_remove(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint);
279 bool change_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value);
282 int find_important_value_descs(std::vector<synfigapp::ValueDesc>& out);
283 static int find_important_value_descs(synfig::Canvas::Handle canvas,std::vector<synfigapp::ValueDesc>& out,synfig::GUIDSet& guid_set);
287 static etl::handle<CanvasInterface> create(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas);
288 }; // END of class CanvasInterface
291 ** \brief Class that changes the mode of a CanvasInterface, and restores it on destruction.
295 CanvasInterface* canvas_interface_;
296 CanvasInterface::Mode old_mode_;
298 PushMode(etl::loose_handle<CanvasInterface> c, CanvasInterface::Mode mode):
299 canvas_interface_(c.get()), old_mode_(canvas_interface_->get_mode())
300 { canvas_interface_->set_mode(mode); }
302 ~PushMode() { canvas_interface_->set_mode(old_mode_); }
303 }; // END of class PushMode
305 }; // END of namespace studio
307 /* === E N D =============================================================== */