Blame synfig-core/src/synfig/layers/layer_pastecanvas.h

Carlos Lopez a09598
/* === S Y N F I G ========================================================= */
Carlos Lopez a09598
/*!	\file layer_pastecanvas.h
Carlos Lopez a09598
**	\brief Header file for implementation of the "Paste Canvas" layer
Carlos Lopez a09598
**
Carlos Lopez a09598
**	$Id$
Carlos Lopez a09598
**
Carlos Lopez a09598
**	\legal
Carlos Lopez a09598
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
Carlos Lopez a09598
**	Copyright (c) 2007, 2008 Chris Moore
Carlos Lopez e83454
**	Copyright (c) 2012-2013 Carlos Lรณpez
39b9b1
**	......... ... 2014-2017 Ivan Mahonin
Carlos Lopez a09598
**
Carlos Lopez a09598
**	This package is free software; you can redistribute it and/or
Carlos Lopez a09598
**	modify it under the terms of the GNU General Public License as
Carlos Lopez a09598
**	published by the Free Software Foundation; either version 2 of
Carlos Lopez a09598
**	the License, or (at your option) any later version.
Carlos Lopez a09598
**
Carlos Lopez a09598
**	This package is distributed in the hope that it will be useful,
Carlos Lopez a09598
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
Carlos Lopez a09598
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Carlos Lopez a09598
**	General Public License for more details.
Carlos Lopez a09598
**	\endlegal
Carlos Lopez a09598
*/
Carlos Lopez a09598
/* ========================================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === S T A R T =========================================================== */
Carlos Lopez a09598
b7acad
#ifndef __SYNFIG_LAYER_PASTECANVAS_H
b7acad
#define __SYNFIG_LAYER_PASTECANVAS_H
Carlos Lopez a09598
Carlos Lopez a09598
/* === H E A D E R S ======================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
#include "layer_composite.h"
Diego Barrios Romero dcc14d
#include <synfig color.h=""></synfig>
Diego Barrios Romero dcc14d
#include <synfig vector.h=""></synfig>
Diego Barrios Romero dcc14d
#include <synfig real.h=""></synfig>
Diego Barrios Romero dcc14d
#include <synfig time.h=""></synfig>
Diego Barrios Romero dcc14d
#include <synfig canvasbase.h=""></synfig>
Diego Barrios Romero dcc14d
#include <synfig canvas.h=""></synfig>
Diego Barrios Romero dcc14d
#include <synfig rect.h=""></synfig>
Diego Barrios Romero dcc14d
#include <synfig transformation.h=""></synfig>
Carlos Lopez a09598
Carlos Lopez a09598
/* === M A C R O S ========================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === T Y P E D E F S ===================================================== */
Carlos Lopez a09598
Carlos Lopez a09598
/* === C L A S S E S & S T R U C T S ======================================= */
Carlos Lopez a09598
Carlos Lopez a09598
namespace synfig {
Carlos Lopez b1ed91
/*!	\class Layer_PasteCanvas
Carlos Lopez b1ed91
**	\brief Class of the Pasted Canvas layer.
Carlos Lopez b1ed91
*/
Carlos Lopez a09598
class Layer_PasteCanvas : public Layer_Composite, public Layer_NoDeform
Carlos Lopez a09598
{
0dde72
public:
0dde72
	typedef etl::handle<layer_pastecanvas> Handle;</layer_pastecanvas>
0dde72
Carlos Lopez a09598
private:
a50429
	//! Parameter: (Origin) Position offset
a50429
	ValueBase param_origin;
luz.paz 99f3ef
	//! Parameter: (Transformation) Position, rotation and scale of the paste canvas layer
0e8ab5
	ValueBase param_transformation;
Carlos Lopez 1a39e8
	//! Parameter: (etl::loose_handle<synfig::canvas>) The canvas parameter</synfig::canvas>
39b9b1
	etl::loose_handle<synfig::canvas> sub_canvas;</synfig::canvas>
Permutator e9d9cb
	//! Parameter: (Real) Time dilation of the paste canvas layer
Permutator e9d9cb
	ValueBase param_time_dilation;
Carlos Lopez 1a39e8
	//! Parameter: (Time) Time offset of the paste canvas layer
Carlos Lopez 1a39e8
	ValueBase param_time_offset;
Carlos Lopez 1a39e8
	//! Parameter: (Real) The value to grow the children outline layers
Carlos Lopez 1a39e8
	ValueBase param_outline_grow;
Carlos Lopez 1a39e8
	//! Parameter: (bool) Value that avoid hit check to go depth into the children.
Carlos Lopez 1a39e8
	ValueBase param_children_lock;
Carlos Lopez 1a39e8
Carlos Lopez 1a39e8
	//! Recursion depth counter.
Carlos Lopez 1a39e8
	mutable int depth;
Carlos Lopez 1a39e8
Carlos Lopez 1a39e8
	//! Boundaries of the paste canvas layer. It is the canvas's boundary
a50429
	//! affected by the origin and transformation.
Carlos Lopez 1a39e8
	mutable Rect bounds;
Carlos Lopez b1ed91
	//! signal connection for children. Seems to be used only here
2051d1
	sigc::connection childs_changed_connection;
Carlos Lopez a09598
Carlos Lopez a09598
	// Nasty hack: Remember whether we called an extra ref() when
Carlos Lopez a09598
	// setting the canvas, so we know whether to call an extra unref()
Carlos Lopez a09598
	// when finished with the canvas.
Carlos Lopez a09598
	//
Carlos Lopez a09598
	// Here's the story:
Carlos Lopez a09598
	//
Carlos Lopez a09598
	// The root canvas is destructed first.  That sets the
Carlos Lopez a09598
	// Layer::canvas_ (the parent canvas) of any PasteCanvas layer it
Carlos Lopez a09598
	// contains to nil, due to a call to Layer::set_canvas(0),
Carlos Lopez a09598
	// triggered by the connection made when Layer::set_canvas
Carlos Lopez a09598
	// originally set its canvas_ member to point to the root canvas.
Carlos Lopez a09598
	// ~Canvas does begin_delete() which triggers that connection.
Carlos Lopez a09598
	//
Carlos Lopez a09598
	// After ~Canvas has run, the members of the root canvas are
Carlos Lopez a09598
	// freed, including its children_ list.  If this was the last
Carlos Lopez a09598
	// reference to the child canvas that the pastecanvas uses, that
Carlos Lopez a09598
	// child canvas will Layer_PasteCanvas::set_sub_canvas(0) on the
Carlos Lopez a09598
	// PasteCanvas layer to set its canvas (the child, pasted canvas)
Carlos Lopez a09598
	// not to refer to the soon-to-be destroys child canvas.  But
Carlos Lopez a09598
	// set_sub_canvas() originally looked at the value of
Carlos Lopez a09598
	// Layer::canvas_ (the parent canvas, obtained via
Carlos Lopez a09598
	// Layer::get_canvas()) to decide whether to do an extra ref() on
Carlos Lopez a09598
	// canvas (the child canvas).  We need to unref() it now if we
Carlos Lopez a09598
	// did, but we've forgotten whether we did.  So we use this
Carlos Lopez a09598
	// 'extra_reference' member to store that decision.
Carlos Lopez a09598
	bool extra_reference;
Carlos Lopez a09598
2051d1
	void childs_changed();
2051d1
Carlos Lopez a09598
	/*
Carlos Lopez a09598
 -- ** -- S I G N A L S -------------------------------------------------------
Carlos Lopez a09598
	*/
Carlos Lopez a09598
Carlos Lopez a09598
private:
Carlos Lopez b1ed91
	//! Signal used when the canvas parameter has changed. \see layertreestore.cpp
Carlos Lopez a09598
	sigc::signal<void> signal_subcanvas_changed_;</void>
Carlos Lopez a09598
Carlos Lopez a09598
	/*
Carlos Lopez a09598
 -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
Carlos Lopez a09598
	*/
Carlos Lopez a09598
Carlos Lopez a09598
public:
Carlos Lopez b1ed91
	//! Wrapper for the subcanvas changed signal
Carlos Lopez a09598
	sigc::signal<void>& signal_subcanvas_changed() { return signal_subcanvas_changed_; }</void>
Carlos Lopez a09598
Carlos Lopez a09598
public:
Carlos Lopez a09598
Carlos Lopez 7dff27
	//! Recursively update the Render Description for the inner inline only pasted canvases.
Carlos Lopez 7dff27
	//! Used for copy and paste Paste Canvas Layers between compositions.
Carlos Lopez a09598
	void update_renddesc();
Carlos Lopez a09598
Carlos Lopez 7dff27
	//! Every time the Paste Canvas Layer parent canvas is changed, this
Carlos Lopez 7dff27
	//! is called and it sets the parent of the canvas parameter to that canvas
Carlos Lopez 7dff27
	//! if it is on line
Carlos Lopez a09598
	virtual void on_canvas_set();
Carlos Lopez a09598
Carlos Lopez 7dff27
	//! Gets the canvas parameter. It is called sub_canvas to avoid confusion
Carlos Lopez 7dff27
	//! with the get_canvas from the Layer class.
39b9b1
	etl::handle<synfig::canvas> get_sub_canvas()const { return sub_canvas; }</synfig::canvas>
Carlos Lopez 7dff27
	//! Sets the canvas parameter.
Carlos Lopez 7dff27
	//! \see get_sub_canvas()
Carlos Lopez a09598
	void set_sub_canvas(etl::handle<synfig::canvas> x);</synfig::canvas>
Permutator e9d9cb
	//! Gets time dilation parameter
Permutator e9d9cb
	Real get_time_dilation()const { return param_time_dilation.get(Real()); }
Carlos Lopez 7dff27
	//! Gets time offset parameter
Carlos Lopez 1a39e8
	Time get_time_offset()const { return param_time_offset.get(Time()); }
1798f7
a50429
	//! Get origin parameter
a50429
	Point get_origin()const { return param_origin.get(Point()); }
0e8ab5
	//! Get transformation parameter
0e8ab5
	Transformation get_transformation()const { return param_transformation.get(Transformation()); }
1798f7
	//! Get summary transformation
1798f7
	Transformation get_summary_transformation()const
1798f7
	{
e0198d
		return get_transformation().transform( Transformation(-get_origin()) );
1798f7
	}
1798f7
Carlos Lopez 7dff27
	//! Default constructor
39b9b1
	explicit Layer_PasteCanvas(Real amount = 1.0, Color::BlendMethod blend_method = Color::BLEND_COMPOSITE);
Carlos Lopez 7dff27
	//! Destructor
Carlos Lopez a09598
	virtual ~Layer_PasteCanvas();
Carlos Lopez 7dff27
	//! Returns a string with the localized name of this layer
Carlos Lopez a09598
	virtual String get_local_name()const;
Carlos Lopez 7dff27
	//!	Sets the parameter described by \a param to \a value. \see Layer::set_param
Carlos Lopez a09598
	virtual bool set_param(const String & param, const synfig::ValueBase &value);
Carlos Lopez 7dff27
	//! Get the value of the specified parameter. \see Layer::get_param
Carlos Lopez a09598
	virtual ValueBase get_param(const String & param)const;
b7acad
	//! Sets z_range* fields of specified ContextParams \a cp
b7acad
	virtual void apply_z_range_to_params(ContextParams &cp)const;
Carlos Lopez 7dff27
	//! Gets the blend color of the Layer in the context at \a pos
Carlos Lopez a09598
	virtual Color get_color(Context context, const Point &pos)const;
dd97a8
8dcfee
	//! Bounding rect for this layer depends from context_params
8dcfee
	Rect get_bounding_rect_context_dependent(const ContextParams &context_params)const;
8dcfee
	//!Returns the rectangle that includes the context of the layer and
8dcfee
	//! the intersection of the layer in case it is active and not onto
8dcfee
	virtual Rect get_full_bounding_rect(Context context)const;
Carlos Lopez 7dff27
	//! Gets the parameter vocabulary
Carlos Lopez a09598
	virtual Vocab get_param_vocab()const;
Carlos Lopez 7dff27
	//! Checks to see if a part of the Paste Canvas Layer is directly under \a point
Carlos Lopez a09598
	virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const;
Carlos Lopez a09598
a435f0
	virtual void fill_sound_processor(SoundProcessor &soundProcessor) const;
a435f0
2051d1
	virtual void on_childs_changed() { }
2051d1
Carlos Lopez a09598
protected:
39b9b1
	virtual Context build_context_queue(Context context, CanvasBase &out_queue)const;
39b9b1
dd97a8
	//! Sets the time of the Paste Canvas Layer and those under it
dd97a8
	virtual void set_time_vfunc(IndependentContext context, Time time)const;
c006c9
	//! Loads external resources (frames) for child layers of the Paste Canvas Layer
c006c9
	virtual void load_resources_vfunc(IndependentContext context, Time time)const;
dd97a8
	//! Sets the outline_grow of the Paste Canvas Layer and those under it
dd97a8
	virtual void set_outline_grow_vfunc(IndependentContext context, Real outline_grow)const;
Carlos Lopez 7dff27
	//!	Function to be overloaded that fills the Time Point Set with
Carlos Lopez 7dff27
	//! all the children Time Points. In this case the children Time Points
Carlos Lopez 7dff27
	//! are the canvas parameter children layers Time points and the Paste Canvas
Carlos Lopez 7dff27
	//! Layer time points. \todo clarify all this comments.
Carlos Lopez a09598
	virtual void get_times_vfunc(Node::time_set &set) const;
Carlos Lopez a09598
39b9b1
	virtual rendering::Task::Handle build_rendering_task_vfunc(Context context)const;
Carlos Lopez a09598
}; // END of class Layer_PasteCanvas
Carlos Lopez a09598
Carlos Lopez a09598
}; // END of namespace synfig
Carlos Lopez a09598
Carlos Lopez a09598
/* === E N D =============================================================== */
Carlos Lopez a09598
Carlos Lopez a09598
#endif