73c0d8386779b4ce29b61b5405ba676c3a8a62af
[synfig.git] / synfig-core / 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, 2008 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 /*!     \class Layer_PasteCanvas
48 **      \brief Class of the Pasted Canvas layer.
49 */
50 class Layer_PasteCanvas : public Layer_Composite, public Layer_NoDeform
51 {
52         //! Layer module: defines the needed members to belong to a layer's factory.
53         SYNFIG_LAYER_MODULE_EXT
54 private:
55         //! Parameter Origin of the paste canvas layer
56         Vector origin;
57         //!Parameter Focus of the zoom of the paste canvas layer
58         Vector focus;
59         //! The canvas parameter
60         etl::loose_handle<synfig::Canvas> canvas;
61         //! Recursion depth counter. Not a parameter
62         mutable int depth;
63         //! Zoom parameter of the paste canvas layer
64         Real zoom;
65         //! Time offset parameter of the paste canvas layer
66         Time time_offset;
67         //! Current time of the paste canvas layer. \see set_time
68         mutable Time curr_time;
69         //! \todo writeme! Not a parameter
70         bool muck_with_time_;
71         //! Parameter that avoid hit check to go depth into the children.
72         bool children_lock;
73         //! Boundaries of the paste canvas layer. It is the canvas's boundary
74         //! affected by the zoom, origin and focus.
75         mutable Rect bounds;
76         //! signal connection for children. Seems to be used only here
77         sigc::connection child_changed_connection;
78
79         bool origin_static;
80         bool focus_static;
81         bool canvas_static;
82         bool zoom_static;
83         bool time_offset_static;
84         bool children_lock_static;
85
86         // Nasty hack: Remember whether we called an extra ref() when
87         // setting the canvas, so we know whether to call an extra unref()
88         // when finished with the canvas.
89         //
90         // Here's the story:
91         //
92         // The root canvas is destructed first.  That sets the
93         // Layer::canvas_ (the parent canvas) of any PasteCanvas layer it
94         // contains to nil, due to a call to Layer::set_canvas(0),
95         // triggered by the connection made when Layer::set_canvas
96         // originally set its canvas_ member to point to the root canvas.
97         // ~Canvas does begin_delete() which triggers that connection.
98         //
99         // After ~Canvas has run, the members of the root canvas are
100         // freed, including its children_ list.  If this was the last
101         // reference to the child canvas that the pastecanvas uses, that
102         // child canvas will Layer_PasteCanvas::set_sub_canvas(0) on the
103         // PasteCanvas layer to set its canvas (the child, pasted canvas)
104         // not to refer to the soon-to-be destroys child canvas.  But
105         // set_sub_canvas() originally looked at the value of
106         // Layer::canvas_ (the parent canvas, obtained via
107         // Layer::get_canvas()) to decide whether to do an extra ref() on
108         // canvas (the child canvas).  We need to unref() it now if we
109         // did, but we've forgotten whether we did.  So we use this
110         // 'extra_reference' member to store that decision.
111         bool extra_reference;
112
113         /*
114  -- ** -- S I G N A L S -------------------------------------------------------
115         */
116
117 private:
118         //! Signal used when the canvas parameter has changed. \see layertreestore.cpp
119         sigc::signal<void> signal_subcanvas_changed_;
120
121         /*
122  -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
123         */
124
125 public:
126         //! Wrapper for the subcanvas changed signal
127         sigc::signal<void>& signal_subcanvas_changed() { return signal_subcanvas_changed_; }
128
129 public:
130
131         //! Recursively update the Render Description for the inner inline only pasted canvases.
132         //! Used for copy and paste Paste Canvas Layers between compositions.
133         void update_renddesc();
134
135         //! Every time the Paste Canvas Layer parent canvas is changed, this
136         //! is called and it sets the parent of the canvas parameter to that canvas
137         //! if it is on line
138         virtual void on_canvas_set();
139         //! Sets muck_with_time.
140         //! \todo writeme!
141         void set_muck_with_time(bool x=false) { muck_with_time_=x; }
142
143         //! Gets the canvas parameter. It is called sub_canvas to avoid confusion
144         //! with the get_canvas from the Layer class.
145         etl::handle<synfig::Canvas> get_sub_canvas()const { return canvas; }
146         //! Sets the canvas parameter.
147         //! \see get_sub_canvas()
148         void set_sub_canvas(etl::handle<synfig::Canvas> x);
149         //! Gets zoom parameter
150         Real get_zoom()const { return zoom; }
151         //! Gets time offset parameter
152         Time get_time_offset()const { return time_offset; }
153         //! Get origin parameter
154         Point get_origin()const { return origin; }
155         //! Get focus parameter
156         Vector get_focus()const { return focus; }
157         //! Default constructor
158         Layer_PasteCanvas();
159         //! Destructor
160         virtual ~Layer_PasteCanvas();
161         //! Returns a string with the localized name of this layer
162         virtual String get_local_name()const;
163         //!     Sets the parameter described by \a param to \a value. \see Layer::set_param
164         virtual bool set_param(const String & param, const synfig::ValueBase &value);
165         //! Get the value of the specified parameter. \see Layer::get_param
166         virtual ValueBase get_param(const String & param)const;
167         virtual bool set_param_static(const String &param, const bool x);
168         virtual bool get_param_static(const String &param) const;
169         //! Gets the blend color of the Layer in the context at \a pos
170         virtual Color get_color(Context context, const Point &pos)const;
171         //! Sets the time of the Paste Canvas Layer and those under it
172         virtual void set_time(Context context, Time time)const;
173         //! Renders the Canvas to the given Surface in an accelerated manner
174         //! See Layer::accelerated_render
175         virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
176         //! Gets the parameter vocabulary
177         virtual Vocab get_param_vocab()const;
178         //! Returns the rectangle that includes the layer
179         virtual synfig::Rect get_bounding_rect()const;
180         //! Checks to see if a part of the Paste Canvas Layer is directly under \a point
181         virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const;
182
183 protected:
184         //!     Function to be overloaded that fills the Time Point Set with
185         //! all the children Time Points. In this case the children Time Points
186         //! are the canvas parameter children layers Time points and the Paste Canvas
187         //! Layer time points. \todo clarify all this comments.
188         virtual void get_times_vfunc(Node::time_set &set) const;
189
190 }; // END of class Layer_PasteCanvas
191
192 }; // END of namespace synfig
193
194 /* === E N D =============================================================== */
195
196 #endif