- Main Page
- Related Pages
- Namespaces
- Classes
- Files

# canvas.h

Go to the documentation of this file.

    00001 /* === S Y N F I G ========================================================= */
    00022 /* ========================================================================= */
    00023
    00024 /* === S T A R T =========================================================== */
    00025
    00026 #ifndef __SYNFIG_CANVAS_H
    00027 #define __SYNFIG_CANVAS_H
    00028
    00029 /* === H E A D E R S ======================================================= */
    00030
    00031 #include <map>
    00032 #include <list>
    00033 #include <ETL/handle>
    00034 #include <sigc++/signal.h>
    00035 #include <sigc++/connection.h>
    00036
    00037 #include "vector.h"
    00038 #include "string.h"
    00039 #include "canvasbase.h"
    00040 #include "valuenode.h"
    00041 #include "keyframe.h"
    00042 #include "renddesc.h"
    00043 #include "node.h"
    00044 #include "guid.h"
    00045
    00046 /* === M A C R O S ========================================================= */
    00047
    00048 /* version change history:
    00049  *
    00050  * 0.1: the original version
    00051  *
    00052  *      if a waypoint goes from -179 to 179 degrees, that is a 2
    00053  *      degree change.  there's no way to express a 720 degree
    00054  *      rotation with a single pair of waypoints
    00055  *
    00056  * 0.2: svn r1227
    00057  *
    00058  *      angles no longer wrap at -180 degrees back to 180 degrees; if
    00059  *      a waypoint goes from -179 to 179 degrees, that is a rotation
    00060  *      of 358 degrees.  loading a version 0.1 canvas will modify
    00061  *      constant angle waypoints to that they are within 180 degrees
    00062  *      of the previous waypoint's value
    00063  *
    00064  *      the 'straight' blend method didn't used to work properly.  it
    00065  *      didn't work at all on transparent pixels in layers other than
    00066  *      the PasteCanvas layer.  for example, the examples/japan.sifz
    00067  *      file has a red circle (straight, amount=1.0) on top of a
    00068  *      striped conical gradient.  if 'straight' was working, the
    00069  *      conical gradient would be entirely obscured by the circle
    00070  *      layer (even by its transparent pixels)
    00071  *
    00072  * 0.3: svn r1422
    00073  *
    00074  *      the 'straight' blend method was fixed.  loading a version 0.2
    00075  *      or older canvas will replace the 'straight' blend method in
    00076  *      non-pastecanvas layers with 'composite', unless they're
    00077  *      completely transparent, in which case it will replace them
    00078  *      with an  'alpha over' blend instead.  Images like
    00079  *      examples/logo.sifz use transparent straight blends to do
    00080  *      masking, which no longer works now that 'straight' blending is
    00081  *      fixed.
    00082  *
    00083  *      Tangent lengths calculated by the "Segment Tangent" and "BLine
    00084  *      Tangent" ValueNodes were scaled by a factor of 0.5.
    00085  *
    00086  * 0.4: svn r1856
    00087  *
    00088  *      Stop scaling tangents by 0.5.
    00089  *
    00090  * 0.5: svn r1863
    00091  *
    00092  *      Added "offset", "scale", and "fixed_length" links to the
    00093  *      "BLine Tangent" ValueNode.
    00094  *
    00095  * 0.6: svn r2067
    00096  *
    00097  *      Added "scale" link to the "BLine Width" ValueNode in svn r1872.
    00098  *
    00099  *      Added "loop" link to the "Gradient Color" ValueNode in svn r1901.
    00100  *
    00101  * 0.7: svn r2315
    00102  *
    00103  *      Added "loop" link to the "Random" ValueNode in svn r2315.
    00104  */
    00105
    00106 #define CURRENT_CANVAS_VERSION "0.7"
    00107
    00108 /* === T Y P E D E F S ===================================================== */
    00109
    00110 /* === C L A S S E S & S T R U C T S ======================================= */
    00111
    00112 namespace synfig {
    00113
    00114 class Context;
    00115 class GUID;
    00116
    00120 class Canvas : public CanvasBase, public Node
    00121 {
    00122     /*
    00123  -- ** -- T Y P E S -----------------------------------------------------------
    00124     */
    00125
    00126 public:
    00127     typedef etl::handle<Canvas> Handle;
    00128     typedef etl::loose_handle<Canvas> LooseHandle;
    00129     typedef etl::handle<const Canvas> ConstHandle;
    00130
    00131     typedef std::list<Handle> Children;
    00132
    00133     friend void synfig::optimize_layers(Time, Context, Canvas::Handle, bool seen_motion_blur);
    00134
    00135     /*
    00136  -- ** -- D A T A -------------------------------------------------------------
    00137     */
    00138
    00139 private:
    00140
    00142
    00143     String id_;
    00144
    00146
    00147     String name_;
    00148
    00150
    00151     String description_;
    00152
    00154
    00155     String version_;
    00156
    00158
    00159     String author_;
    00160
    00162
    00163     String email_;
    00164
    00166
    00167     String file_name_;
    00168
    00170
    00171     std::map<String, String> meta_data_;
    00172
    00174
    00175     ValueNodeList value_node_list_;
    00176
    00178     KeyframeList keyframe_list_;
    00179
    00181
    00184     LooseHandle parent_;
    00185
    00187
    00188     Children children_;
    00189
    00191
    00192     RendDesc desc_;
    00193
    00195     Time cur_time_;
    00196
    00198     mutable std::map<String,Handle> externals_;
    00199
    00201     bool is_inline_;
    00202
    00203     mutable bool is_dirty_;
    00204
    00205     bool op_flag_;
    00206
    00208     std::map<String,std::set<etl::handle<Layer> > > group_db_;
    00209
    00211     std::map<etl::loose_handle<Layer>,std::vector<sigc::connection> > connections_;
    00212
    00213     /*
    00214  -- ** -- S I G N A L S -------------------------------------------------------
    00215     */
    00216
    00217 private:
    00218
    00220     sigc::signal<void,String> signal_group_added_;
    00221
    00223     sigc::signal<void,String> signal_group_removed_;
    00224
    00226     sigc::signal<void,String> signal_group_changed_;
    00227
    00228     sigc::signal<void,String,etl::handle<synfig::Layer> > signal_group_pair_added_;
    00229     sigc::signal<void,String,etl::handle<synfig::Layer> > signal_group_pair_removed_;
    00230
    00232     sigc::signal<void,int*> signal_layers_reordered_;
    00233
    00235     sigc::signal<void> signal_rend_desc_changed_;
    00236
    00238     sigc::signal<void> signal_id_changed_;
    00239
    00241     //sigc::signal<void> signal_dirty_;
    00242
    00244     sigc::signal<void> signal_file_name_changed_;
    00245
    00247     sigc::signal<void, String> signal_meta_data_changed_;
    00248
    00250     std::map<String, sigc::signal<void> > signal_map_meta_data_changed_;
    00251
    00252
    00254     sigc::signal<void, etl::handle<ValueNode> > signal_value_node_changed_;
    00255
    00256     sigc::signal<void, etl::handle<ValueNode> > signal_value_node_renamed_;
    00257
    00258     sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> > signal_value_node_child_added_;
    00259
    00260     sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> > signal_value_node_child_removed_;
    00261
    00262     /*
    00263  -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
    00264     */
    00265
    00266 public:
    00267
    00268     sigc::signal<void,String,etl::handle<synfig::Layer> >& signal_group_pair_added() { return signal_group_pair_added_; }
    00269     sigc::signal<void,String,etl::handle<synfig::Layer> >& signal_group_pair_removed() { return signal_group_pair_removed_; }
    00270
    00272     sigc::signal<void,String>& signal_group_added() { return signal_group_added_; }
    00273
    00275     sigc::signal<void,String>& signal_group_removed() { return signal_group_removed_; }
    00276
    00278     sigc::signal<void,String>& signal_group_changed() { return signal_group_changed_; }
    00279
    00281     sigc::signal<void,int*>& signal_layers_reordered() { return signal_layers_reordered_; }
    00282
    00284     sigc::signal<void>& signal_rend_desc_changed() { return signal_rend_desc_changed_; }
    00285
    00287     sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
    00288
    00290     sigc::signal<void>& signal_file_name_changed();
    00291
    00293     sigc::signal<void, String>& signal_meta_data_changed() { return signal_meta_data_changed_; }
    00294
    00296     sigc::signal<void>& signal_meta_data_changed(const String& key) { return signal_map_meta_data_changed_[key]; }
    00297
    00298
    00299     sigc::signal<void, etl::handle<ValueNode> >& signal_value_node_changed() { return signal_value_node_changed_; }
    00300
    00301     sigc::signal<void, etl::handle<ValueNode> >& signal_value_node_renamed() { return signal_value_node_renamed_; }
    00302
    00304     sigc::signal<void>& signal_dirty() { return signal_changed();   }
    00305
    00307     sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> >& signal_value_node_child_added() { return signal_value_node_child_added_; }
    00308
    00310     sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> >& signal_value_node_child_removed() { return signal_value_node_child_removed_; }
    00311
    00312     /*
    00313  -- ** -- C O N S T R U C T O R S ---------------------------------------------
    00314     */
    00315
    00316 protected:
    00317
    00318     Canvas(const String &name);
    00319
    00320 public:
    00321
    00322     ~Canvas();
    00323
    00324     /*
    00325  -- ** -- M E M B E R   F U N C T I O N S -------------------------------------
    00326     */
    00327
    00328 public:
    00329
    00331     std::set<etl::handle<Layer> > get_layers_in_group(const String&group);
    00332
    00334     std::set<String> get_groups()const;
    00335
    00337     int get_group_count()const;
    00338
    00340     void rename_group(const String&old_name,const String&new_name);
    00341
    00343     bool is_inline()const { return is_inline_; }
    00344
    00346     RendDesc &rend_desc() { return desc_; }
    00347
    00349     const RendDesc &rend_desc()const { return desc_; }
    00350
    00352     const String & get_name()const { return name_; }
    00353
    00355     void set_name(const String &x);
    00356
    00358     const String get_version()const { return version_; }
    00359
    00361     void set_version(const String &x) { version_ = x; }
    00362
    00364     const String & get_author()const { return author_; }
    00365
    00367     void set_author(const String &x);
    00368
    00370     const String & get_description()const { return description_; }
    00371
    00373     void set_description(const String &x);
    00374
    00376     const String & get_id()const { return id_; }
    00377
    00379     void set_id(const String &x);
    00380
    00382     String get_meta_data(const String& key)const;
    00383
    00385     std::list<String> get_meta_data_keys()const;
    00386
    00388     void set_meta_data(const String& key, const String& data);
    00389
    00391     void erase_meta_data(const String& key);
    00392
    00394     String get_relative_id(etl::loose_handle<const Canvas> x)const;
    00395
    00397     String _get_relative_id(etl::loose_handle<const Canvas> x)const;
    00398
    00400     bool is_root()const { return !parent_; }
    00401
    00403
    00404     LooseHandle parent()const { return parent_; }
    00405
    00406     LooseHandle get_root()const;
    00407
    00409     std::list<Handle> &children() { return children_; }
    00410
    00412     const std::list<Handle> &children()const { return children_; }
    00413
    00415     //Color get_color(const Point &pos)const;
    00416
    00418     void set_time(Time t)const;
    00419
    00421     Time get_time()const { return cur_time_; }
    00422
    00424     int size()const;
    00425
    00427     void clear();
    00428
    00430     bool empty()const;
    00431
    00433     // ValueNodeList &value_node_list() { return value_node_list_; }
    00434
    00436     const ValueNodeList &value_node_list()const;
    00437
    00439     KeyframeList &keyframe_list();
    00440
    00442     const KeyframeList &keyframe_list()const;
    00443
    00445
    00448     ValueNode::Handle find_value_node(const String &id);
    00449
    00451     ValueNode::Handle surefind_value_node(const String &id);
    00452
    00454
    00457     ValueNode::ConstHandle find_value_node(const String &id)const;
    00458
    00460     void add_value_node(ValueNode::Handle x, const String &id);
    00461
    00463     //void rename_value_node(ValueNode::Handle x, const String &id);
    00464
    00466     void remove_value_node(ValueNode::Handle x);
    00467
    00469     void remove_value_node(const String &id) { remove_value_node(find_value_node(id)); }
    00470
    00472
    00476     Handle surefind_canvas(const String &id,String &warnings);
    00477
    00479
    00482     Handle find_canvas(const String &id, String &warnings);
    00483
    00485
    00488     ConstHandle find_canvas(const String &id, String &warnings)const;
    00489
    00491     //void set_file_path(const String &);
    00492
    00494     String get_file_path()const;
    00495
    00497     void set_file_name(const String &);
    00498
    00500     String get_file_name()const;
    00501
    00503     Handle new_child_canvas();
    00504
    00506     Handle new_child_canvas(const String &id);
    00507
    00509     Handle add_child_canvas(Handle child_canvas, const String &id);
    00510
    00511     void remove_child_canvas(Handle child_canvas);
    00512
    00513     etl::handle<Layer> find_layer(const Point &pos);
    00514
    00515     int get_depth(etl::handle<Layer>)const;
    00516
    00517     Context get_context()const;
    00518
    00519     iterator end();
    00520
    00521     const_iterator end()const;
    00522
    00523     reverse_iterator rbegin();
    00524
    00525     const_reverse_iterator rbegin()const;
    00526
    00527     etl::handle<Layer> &back();
    00528
    00529     void push_back(etl::handle<Layer> x);
    00530
    00531     void push_front(etl::handle<Layer> x);
    00532
    00533     void push_back_simple(etl::handle<Layer> x);
    00534
    00535     void insert(iterator iter,etl::handle<Layer> x);
    00536     void erase(iterator iter);
    00537
    00538     const etl::handle<Layer> &back()const;
    00539
    00540     void set_inline(LooseHandle parent);
    00541
    00542     static Handle create();
    00543
    00544     static Handle create_inline(Handle parent);
    00545
    00546     Handle clone(const GUID& deriv_guid=GUID())const;
    00547
    00548     void register_external_canvas(String file, Handle canvas);
    00549
    00550 #ifdef _DEBUG
    00551     void show_externals(String file, int line, String text) const;
    00552 #endif  // _DEBUG
    00553
    00554 private:
    00555     void add_group_pair(String group, etl::handle<Layer> layer);
    00556     void remove_group_pair(String group, etl::handle<Layer> layer);
    00557     void add_connection(etl::loose_handle<Layer> layer, sigc::connection connection);
    00558     void disconnect_connections(etl::loose_handle<Layer> layer);
    00559
    00560 protected:
    00561     virtual void on_changed();
    00562     virtual void get_times_vfunc(Node::time_set &set) const;
    00563 }; // END of class Canvas
    00564
    00565 void optimize_layers(Time time, Context context, Canvas::Handle op_canvas, bool seen_motion_blur=false);
    00566
    00567
    00568 }; // END of namespace synfig
    00569
    00570 /* === E N D =============================================================== */
    00571
    00572 #endif