1dc9506764edad2e7b1fbd2a1d678b4284615e7c
[synfig.git] / synfig-core / trunk / src / synfig / layer_pastecanvas.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layer_pastecanvas.h
3 **      \brief Header file for implementation of the "Paste Canvas" layer
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === S T A R T =========================================================== */
25
26 #ifndef __SYNFIG_LAYER_PASTEIMAGE_H
27 #define __SYNFIG_LAYER_PASTEIMAGE_H
28
29 /* === H E A D E R S ======================================================= */
30
31 #include "layer_composite.h"
32 #include "color.h"
33 #include "vector.h"
34 #include "real.h"
35 #include "time.h"
36 #include "canvasbase.h"
37 #include "canvas.h"
38 #include "rect.h"
39
40 /* === M A C R O S ========================================================= */
41
42 /* === T Y P E D E F S ===================================================== */
43
44 /* === C L A S S E S & S T R U C T S ======================================= */
45
46 namespace synfig {
47
48 class Layer_PasteCanvas : public Layer_Composite, public Layer_NoDeform
49 {
50         SYNFIG_LAYER_MODULE_EXT
51 private:
52
53         Vector origin;
54
55         etl::loose_handle<synfig::Canvas> canvas;
56
57         //! Recursion depth counter
58         mutable int depth;
59
60         Real zoom;
61
62         Time time_offset;
63
64         mutable Time curr_time;
65
66         bool muck_with_time_;
67
68         bool children_lock;
69
70         mutable Rect bounds;
71
72         sigc::connection child_changed_connection;
73
74         // Nasty hack: Remember whether we called an extra ref() when
75         // setting the canvas, so we know whether to call an extra unref()
76         // when finished with the canvas.
77         //
78         // Here's the story:
79         //
80         // The root canvas is destructed first.  That sets the
81         // Layer::canvas_ (the parent canvas) of any PasteCanvas layer it
82         // contains to nil, due to a call to Layer::set_canvas(0),
83         // triggered by the connection made when Layer::set_canvas
84         // originally set its canvas_ member to point to the root canvas.
85         // ~Canvas does begin_delete() which triggers that connection.
86         //
87         // After ~Canvas has run, the members of the root canvas are
88         // freed, including its children_ list.  If this was the last
89         // reference to the child canvas that the pastecanvas uses, that
90         // child canvas will Layer_PasteCanvas::set_sub_canvas(0) on the
91         // PasteCanvas layer to set its canvas (the child, pasted canvas)
92         // not to refer to the soon-to-be destroys child canvas.  But
93         // set_sub_canvas() originally looked at the value of
94         // Layer::canvas_ (the parent canvas, obtained via
95         // Layer::get_canvas()) to decide whether to do an extra ref() on
96         // canvas (the child canvas).  We need to unref() it now if we
97         // did, but we've forgotten whether we did.  So we use this
98         // 'extra_reference' member to store that decision.
99         bool extra_reference;
100 public:
101
102         virtual void on_canvas_set();
103
104         void set_muck_with_time(bool x=false) { muck_with_time_=x; }
105
106         etl::handle<synfig::Canvas> get_sub_canvas()const { return canvas; }
107         void set_sub_canvas(etl::handle<synfig::Canvas> x);
108
109         Real get_zoom()const { return zoom; }
110
111         Time get_time_offset()const { return time_offset; }
112
113         Point get_origin()const { return origin; }
114
115         Layer_PasteCanvas();
116         virtual ~Layer_PasteCanvas();
117
118         virtual String get_local_name()const;
119
120         virtual bool set_param(const String & param, const synfig::ValueBase &value);
121
122         virtual ValueBase get_param(const String & param)const;
123
124         virtual Color get_color(Context context, const Point &pos)const;
125
126         virtual void set_time(Context context, Time time)const;
127
128         virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
129
130         virtual Vocab get_param_vocab()const;
131
132         virtual synfig::Rect get_bounding_rect()const;
133
134         virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const;
135
136 protected:
137         virtual void get_times_vfunc(Node::time_set &set) const;
138
139 }; // END of class Layer_PasteCanvas
140
141 }; // END of namespace synfig
142
143 /* === E N D =============================================================== */
144
145 #endif