synfig-studio  1.0.3
action.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
22 /* ========================================================================= */
23 
24 /* === S T A R T =========================================================== */
25 
26 #ifndef __SYNFIG_APP_ACTION_H
27 #define __SYNFIG_APP_ACTION_H
28 
29 /* === H E A D E R S ======================================================= */
30 
31 #include <synfig/string.h>
32 #include <synfig/canvas.h>
33 #include <ETL/handle>
34 #include <ETL/stringf>
35 #include <ETL/trivial>
36 
37 #include <map>
38 #include <list>
39 
40 #include <synfig/layer.h>
41 #include <synfig/canvas.h>
42 #include <synfig/valuenode.h>
43 #include <synfigapp/value_desc.h>
44 #include <synfig/value.h>
45 #include <synfig/activepoint.h>
46 #include <synfig/valuenodes/valuenode_animated.h>
47 #include <synfig/string.h>
48 #include <synfig/keyframe.h>
49 
50 #include "action_param.h"
51 #include "editmode.h"
52 
53 /* === M A C R O S ========================================================= */
54 
55 #define ACTION_MODULE_EXT public: \
56  static const char name__[], local_name__[], version__[], cvs_id__[], task__[]; \
57  static const Category category__; \
58  static const int priority__; \
59  static Action::Base *create(); \
60  virtual synfig::String get_name()const; \
61  virtual synfig::String get_local_name()const;
62 
63 
64 #define ACTION_SET_NAME(class,x) const char class::name__[]=x
65 
66 #define ACTION_SET_CATEGORY(class,x) const Category class::category__(x)
67 
68 #define ACTION_SET_TASK(class,x) const char class::task__[]=x
69 
70 #define ACTION_SET_PRIORITY(class,x) const int class::priority__=x
71 
72 #define ACTION_SET_LOCAL_NAME(class,x) const char class::local_name__[]=x
73 
74 #define ACTION_SET_VERSION(class,x) const char class::version__[]=x
75 
76 #define ACTION_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
77 
79 #define ACTION_INIT_NO_GET_LOCAL_NAME(class) \
80  Action::Base* class::create() { return new class(); } \
81  synfig::String class::get_name()const { return name__; }
82 
83 #define ACTION_INIT(class) \
84  ACTION_INIT_NO_GET_LOCAL_NAME(class) \
85  synfig::String class::get_local_name()const { return dgettext("synfigstudio",local_name__); }
86 
87 /* === T Y P E D E F S ===================================================== */
88 
89 /* === C L A S S E S & S T R U C T S ======================================= */
90 
91 namespace synfig {
92 class ProgressCallback;
93 class Canvas;
94 }; // END of namespace synfig
95 
96 namespace synfigapp {
97 
98 class Instance;
99 class Main;
100 
101 namespace Action {
102 
103 class System;
104 
105 
107 class Error
108 {
109 public:
110  enum Type
111  {
118 
120  };
121 private:
122 
123  Type type_;
124  synfig::String desc_;
125 
126 public:
127 
128  Error(Type type, const char *format, ...):
129  type_(type)
130  {
131  va_list args;
132  va_start(args,format);
133  desc_=etl::vstrprintf(format,args);
134  }
135 
136  Error(const char *format, ...):
137  type_(TYPE_UNKNOWN)
138  {
139  va_list args;
140  va_start(args,format);
141  desc_=etl::vstrprintf(format,args);
142  }
143 
145  type_(type)
146  {
147  }
148 
149  Type get_type()const { return type_; }
150  synfig::String get_desc()const { return desc_; }
151 
152 }; // END of class Action::Error
153 
154 class Param;
155 class ParamList;
156 class ParamDesc;
157 class ParamVocab;
158 
159 // Action Category
161 {
163  CATEGORY_LAYER =(1<<0),
170  CATEGORY_GROUP =(1<<7),
172 
173  CATEGORY_OTHER =(1<<12),
174 
175  CATEGORY_DRAG =(1<<24),
176 
177  CATEGORY_HIDDEN =(1<<31),
178  CATEGORY_ALL =(~0)-(1<<31)
179 }; // END of enum Category
180 
182 { return static_cast<Category>(int(lhs)|int(rhs)); }
183 
184 
185 
187 
197 class Base : public etl::shared_object
198 {
199 protected:
200  Base() { }
201 
202 public:
203  virtual ~Base() { };
204 
206  virtual void perform()=0;
207 
208  virtual bool set_param(const synfig::String& /*name*/, const Param &) { return false; }
209  virtual bool get_param(const synfig::String& /*name*/, Param &) { return false; }
210  virtual bool is_ready()const=0;
211 
212  virtual synfig::String get_name()const =0;
213  virtual synfig::String get_local_name()const { return get_name(); }
214 
215  void set_param_list(const ParamList &);
216 
217  static synfig::String get_layer_descriptions(const std::list<synfig::Layer::Handle> layers, synfig::String singular_prefix = "", synfig::String plural_prefix = "");
218  static synfig::String get_layer_descriptions(const std::list<std::pair<synfig::Layer::Handle,int> > layers, synfig::String singular_prefix = "", synfig::String plural_prefix = "");
219 }; // END of class Action::Base
220 
221 typedef Action::Base* (*Factory)();
222 typedef bool (*CandidateChecker)(const ParamList &x);
224 
225 typedef etl::handle<Base> Handle;
226 
228 class Undoable : public Base
229 {
230  friend class System;
231  bool active_;
232 
233 protected:
234  Undoable();
235 
236 #ifdef _DEBUG
237  ~Undoable();
238 #endif
239 
240 private:
241  void set_active(bool x) { active_=x; }
242 
243 public:
244 
246  virtual void undo()=0;
247 
248  bool is_active()const { return active_; }
249 
250 #ifdef _DEBUG
251  virtual void ref()const;
252  virtual bool unref()const;
253 #endif
254 }; // END of class Action::Undoable
255 
258 {
259 private:
260  bool is_dirty_;
261  EditMode mode_;
262 
263  etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_;
264  synfig::Canvas::Handle canvas_;
265 
266 protected:
267  CanvasSpecific(const synfig::Canvas::Handle &canvas):is_dirty_(true),mode_(MODE_UNDEFINED),canvas_(canvas) { }
268  CanvasSpecific():is_dirty_(true), mode_(MODE_UNDEFINED) { }
269 
270  virtual ~CanvasSpecific() { };
271 
272 
273 public:
274 
275  void set_canvas(synfig::Canvas::Handle x) { canvas_=x; }
276  void set_canvas_interface(etl::loose_handle<synfigapp::CanvasInterface> x) { canvas_interface_=x; }
277 
278  synfig::Canvas::Handle get_canvas()const { return canvas_; }
279  etl::loose_handle<synfigapp::CanvasInterface> get_canvas_interface()const { return canvas_interface_; }
280 
281  static ParamVocab get_param_vocab();
282  virtual bool set_param(const synfig::String& name, const Param &);
283  virtual bool get_param(const synfig::String& /*name*/, Param &) { return false; }
284  virtual bool is_ready()const;
285 
286  EditMode get_edit_mode()const;
287 
288  void set_edit_mode(EditMode x) { mode_=x; }
289 
290  bool is_dirty()const { return is_dirty_; }
291  void set_dirty(bool x=true) { is_dirty_=x; }
292 
293 }; // END of class Action::CanvasSpecific
294 
295 typedef std::list< etl::handle<Action::Undoable> > ActionList;
296 
303 class Super : public Undoable, public CanvasSpecific
304 {
305  ActionList action_list_;
306 
307 public:
308 
309  ActionList &action_list() { return action_list_; }
310  const ActionList &action_list()const { return action_list_; }
311 
312  virtual void prepare()=0;
313 
314  void clear() { action_list().clear(); }
315 
316  bool first_time()const { return action_list_.empty(); }
317 
318  void add_action(etl::handle<Undoable> action);
319 
320  void add_action_front(etl::handle<Undoable> action);
321 
322  virtual void perform();
323  virtual void undo();
324 
325 }; // END of class Action::Super
326 
327 
328 class Group : public Super
329 {
330  synfig::String name_;
331 
332  ActionList action_list_;
333 protected:
334  bool ready_;
335 public:
336  Group(const synfig::String &str="Group");
337  virtual ~Group();
338 
339  virtual synfig::String get_name()const { return name_; }
340 
341  virtual void prepare() { };
342 
343  virtual bool set_param(const synfig::String& /*name*/, const Param &)const { return false; }
344  virtual bool is_ready()const { return ready_; }
345 
346  void set_name(std::string&x) { name_=x; }
347 }; // END of class Action::Group
348 
349 
350 
351 
352 
353 struct BookEntry
354 {
355  synfig::String name;
356  synfig::String local_name;
357  synfig::String version;
358  synfig::String task;
359  int priority;
364 
365  bool operator<(const BookEntry &rhs)const { return priority<rhs.priority; }
366 }; // END of struct BookEntry
367 
368 typedef std::map<synfig::String,BookEntry> Book;
369 
370 class CandidateList : public std::list<BookEntry>
371 {
372 public:
373  iterator find(const synfig::String& x);
374  const_iterator find(const synfig::String& x)const { return const_cast<CandidateList*>(this)->find(x); }
375 };
376 
377 Book& book();
378 
379 Handle create(const synfig::String &name);
380 
382 CandidateList compile_candidate_list(const ParamList& param_list, Category category=CATEGORY_ALL);
383 
389 class Main
390 {
391  friend class synfigapp::Main;
392 
393  Main();
394 
395 public:
396  ~Main();
397 
398 }; // END of class Action::Main
399 
400 }; // END of namespace Action
401 
402 }; // END of namespace synfigapp
403 
404 /* === E N D =============================================================== */
405 
406 #endif