00001
00022
00023
00024
00025
00026 #ifndef __SYNFIG_APP_ACTION_H
00027 #define __SYNFIG_APP_ACTION_H
00028
00029
00030
00031 #include <synfig/string.h>
00032 #include <synfig/canvas.h>
00033 #include <ETL/handle>
00034 #include <ETL/stringf>
00035 #include <ETL/trivial>
00036
00037 #include <map>
00038 #include <list>
00039
00040 #include <synfig/layer.h>
00041 #include <synfig/canvas.h>
00042 #include <synfig/valuenode.h>
00043 #include <synfigapp/value_desc.h>
00044 #include <synfig/value.h>
00045 #include <synfig/activepoint.h>
00046 #include <synfig/valuenode_animated.h>
00047 #include <synfig/string.h>
00048 #include <synfig/keyframe.h>
00049
00050 #include "action_param.h"
00051 #include "editmode.h"
00052
00053
00054
00055 #define ACTION_MODULE_EXT public: \
00056 static const char name__[], local_name__[], version__[], cvs_id__[], task__[]; \
00057 static const Category category__; \
00058 static const int priority__; \
00059 static Action::Base *create(); \
00060 virtual synfig::String get_name()const; \
00061 virtual synfig::String get_local_name()const;
00062
00063
00064 #define ACTION_SET_NAME(class,x) const char class::name__[]=x
00065
00066 #define ACTION_SET_CATEGORY(class,x) const Category class::category__(x)
00067
00068 #define ACTION_SET_TASK(class,x) const char class::task__[]=x
00069
00070 #define ACTION_SET_PRIORITY(class,x) const int class::priority__=x
00071
00072 #define ACTION_SET_LOCAL_NAME(class,x) const char class::local_name__[]=x
00073
00074 #define ACTION_SET_VERSION(class,x) const char class::version__[]=x
00075
00076 #define ACTION_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
00077
00079 #define ACTION_INIT_NO_GET_LOCAL_NAME(class) \
00080 Action::Base* class::create() { return new class(); } \
00081 synfig::String class::get_name()const { return name__; }
00082
00083 #define ACTION_INIT(class) \
00084 ACTION_INIT_NO_GET_LOCAL_NAME(class) \
00085 synfig::String class::get_local_name()const { return dgettext("synfigstudio",local_name__); }
00086
00087
00088
00089
00090
00091 namespace synfig {
00092 class ProgressCallback;
00093 class Canvas;
00094 };
00095
00096 namespace synfigapp {
00097
00098 class Instance;
00099 class Main;
00100
00101 namespace Action {
00102
00103 class System;
00104
00105
00107 class Error
00108 {
00109 public:
00110 enum Type
00111 {
00112 TYPE_UNKNOWN,
00113 TYPE_UNABLE,
00114 TYPE_BADPARAM,
00115 TYPE_CRITICAL,
00116 TYPE_NOTREADY,
00117 TYPE_BUG,
00118
00119 TYPE_END
00120 };
00121 private:
00122
00123 Type type_;
00124 synfig::String desc_;
00125
00126 public:
00127
00128 Error(Type type, const char *format, ...):
00129 type_(type)
00130 {
00131 va_list args;
00132 va_start(args,format);
00133 desc_=etl::vstrprintf(format,args);
00134 }
00135
00136 Error(const char *format, ...):
00137 type_(TYPE_UNKNOWN)
00138 {
00139 va_list args;
00140 va_start(args,format);
00141 desc_=etl::vstrprintf(format,args);
00142 }
00143
00144 Error(Type type=TYPE_UNABLE):
00145 type_(type)
00146 {
00147 }
00148
00149 Type get_type()const { return type_; }
00150 synfig::String get_desc()const { return desc_; }
00151
00152 };
00153
00154 class Param;
00155 class ParamList;
00156 class ParamDesc;
00157 class ParamVocab;
00158
00159
00160 enum Category
00161 {
00162 CATEGORY_NONE =0,
00163 CATEGORY_LAYER =(1<<0),
00164 CATEGORY_CANVAS =(1<<1),
00165 CATEGORY_WAYPOINT =(1<<2),
00166 CATEGORY_ACTIVEPOINT =(1<<3),
00167 CATEGORY_VALUEDESC =(1<<4),
00168 CATEGORY_VALUENODE =(1<<5),
00169 CATEGORY_KEYFRAME =(1<<6),
00170 CATEGORY_GROUP =(1<<7),
00171 CATEGORY_BEZIER =(1<<8),
00172
00173 CATEGORY_OTHER =(1<<12),
00174
00175 CATEGORY_DRAG =(1<<24),
00176
00177 CATEGORY_HIDDEN =(1<<31),
00178 CATEGORY_ALL =(~0)-(1<<31)
00179 };
00180
00181 inline Category operator|(Category lhs, Category rhs)
00182 { return static_cast<Category>(int(lhs)|int(rhs)); }
00183
00184
00185
00187
00197 class Base : public etl::shared_object
00198 {
00199 protected:
00200 Base() { }
00201
00202 public:
00203 virtual ~Base() { };
00204
00206 virtual void perform()=0;
00207
00208 virtual bool set_param(const synfig::String& , const Param &) { return false; }
00209 virtual bool is_ready()const=0;
00210
00211 virtual synfig::String get_name()const =0;
00212 virtual synfig::String get_local_name()const { return get_name(); }
00213
00214 void set_param_list(const ParamList &);
00215
00216 static synfig::String get_layer_descriptions(const std::list<synfig::Layer::Handle> layers, synfig::String singular_prefix = "", synfig::String plural_prefix = "");
00217 static synfig::String get_layer_descriptions(const std::list<std::pair<synfig::Layer::Handle,int> > layers, synfig::String singular_prefix = "", synfig::String plural_prefix = "");
00218 };
00219
00220 typedef Action::Base* (*Factory)();
00221 typedef bool (*CandidateChecker)(const ParamList &x);
00222 typedef ParamVocab (*GetParamVocab)();
00223
00224 typedef etl::handle<Base> Handle;
00225
00227 class Undoable : public Base
00228 {
00229 friend class System;
00230 bool active_;
00231
00232 protected:
00233 Undoable():active_(true) { }
00234
00235 private:
00236 void set_active(bool x) { active_=x; }
00237
00238 public:
00239
00241 virtual void undo()=0;
00242
00243 bool is_active()const { return active_; }
00244
00245 };
00246
00248 class CanvasSpecific
00249 {
00250 private:
00251 bool is_dirty_;
00252 EditMode mode_;
00253
00254 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_;
00255 synfig::Canvas::Handle canvas_;
00256
00257 protected:
00258 CanvasSpecific(const synfig::Canvas::Handle &canvas):is_dirty_(true),mode_(MODE_UNDEFINED),canvas_(canvas) { }
00259 CanvasSpecific():is_dirty_(true), mode_(MODE_UNDEFINED) { }
00260
00261 virtual ~CanvasSpecific() { };
00262
00263
00264 public:
00265
00266 void set_canvas(synfig::Canvas::Handle x) { canvas_=x; }
00267 void set_canvas_interface(etl::loose_handle<synfigapp::CanvasInterface> x) { canvas_interface_=x; }
00268
00269 synfig::Canvas::Handle get_canvas()const { return canvas_; }
00270 etl::loose_handle<synfigapp::CanvasInterface> get_canvas_interface()const { return canvas_interface_; }
00271
00272 static ParamVocab get_param_vocab();
00273 virtual bool set_param(const synfig::String& name, const Param &);
00274 virtual bool is_ready()const;
00275
00276 EditMode get_edit_mode()const;
00277
00278 void set_edit_mode(EditMode x) { mode_=x; }
00279
00280 bool is_dirty()const { return is_dirty_; }
00281 void set_dirty(bool x=true) { is_dirty_=x; }
00282
00283 };
00284
00285 typedef std::list< etl::handle<Action::Undoable> > ActionList;
00286
00293 class Super : public Undoable, public CanvasSpecific
00294 {
00295 ActionList action_list_;
00296
00297 public:
00298
00299 ActionList &action_list() { return action_list_; }
00300 const ActionList &action_list()const { return action_list_; }
00301
00302 virtual void prepare()=0;
00303
00304 void clear() { action_list().clear(); }
00305
00306 bool first_time()const { return action_list_.empty(); }
00307
00308 void add_action(etl::handle<Undoable> action);
00309
00310 void add_action_front(etl::handle<Undoable> action);
00311
00312 virtual void perform();
00313 virtual void undo();
00314
00315 };
00316
00317
00318 class Group : public Super
00319 {
00320 synfig::String name_;
00321
00322 ActionList action_list_;
00323 protected:
00324 bool ready_;
00325 public:
00326 Group(const synfig::String &str="Group");
00327 virtual ~Group();
00328
00329 virtual synfig::String get_name()const { return name_; }
00330
00331 virtual void prepare() { };
00332
00333 virtual bool set_param(const synfig::String& , const Param &)const { return false; }
00334 virtual bool is_ready()const { return ready_; }
00335
00336 void set_name(std::string&x) { name_=x; }
00337 };
00338
00339
00340
00341
00342
00343 struct BookEntry
00344 {
00345 synfig::String name;
00346 synfig::String local_name;
00347 synfig::String version;
00348 synfig::String task;
00349 int priority;
00350 Category category;
00351 Factory factory;
00352 CandidateChecker is_candidate;
00353 GetParamVocab get_param_vocab;
00354
00355 bool operator<(const BookEntry &rhs)const { return priority<rhs.priority; }
00356 };
00357
00358 typedef std::map<synfig::String,BookEntry> Book;
00359
00360 class CandidateList : public std::list<BookEntry>
00361 {
00362 public:
00363 iterator find(const synfig::String& x);
00364 const_iterator find(const synfig::String& x)const { return const_cast<CandidateList*>(this)->find(x); }
00365 };
00366
00367 Book& book();
00368
00369 Handle create(const synfig::String &name);
00370
00372 CandidateList compile_candidate_list(const ParamList& param_list, Category category=CATEGORY_ALL);
00373
00379 class Main
00380 {
00381 friend class synfigapp::Main;
00382
00383 Main();
00384
00385 public:
00386 ~Main();
00387
00388 };
00389
00390 };
00391
00392 };
00393
00394
00395
00396 #endif