Use LinkableValueNode members functions when possible in the derived valuenodes.
[synfig.git] / synfig-core / src / synfig / target_tile.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file target_tile.h
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 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_TARGET_TILE_H
27 #define __SYNFIG_TARGET_TILE_H
28
29 /* === H E A D E R S ======================================================= */
30
31 #include "target.h"
32
33 /* === M A C R O S ========================================================= */
34
35 #define TILE_SIZE 120
36
37 /* === T Y P E D E F S ===================================================== */
38
39 /* === C L A S S E S & S T R U C T S ======================================= */
40
41 namespace synfig {
42
43 /*!     \class Target_Tile
44 **      \brief Render-target
45 **      \todo writeme
46 */
47 class Target_Tile : public Target
48 {
49         //! Number of threads
50         int threads_;
51         //! Tile width in pixels
52         int tile_w_;
53         //! Tile height in pixles
54         int tile_h_;
55         //! The current tile being rendered
56         int curr_tile_;
57         //! The current frame being rendered
58         int curr_frame_;
59         //! Determines if the tiles should be clipped to the redener description
60         //! or not
61         bool clipping_;
62 public:
63         typedef etl::handle<Target_Tile> Handle;
64         typedef etl::loose_handle<Target_Tile> LooseHandle;
65         typedef etl::handle<const Target_Tile> ConstHandle;
66
67         Target_Tile();
68
69         //! Renders the canvas to the target
70         virtual bool render(ProgressCallback *cb=NULL);
71
72         //! Determines which tile needs to be rendered next.
73         /*!     Most cases will not have to redefine this function.
74         **      The default should be adequate in nearly all situations.
75         **      \returns The number of tiles left to go <i>plus one</i>.
76         **              This means that whenever this function returns zero,
77         **              there are no more tiles to render and that any value
78         **              in \a x or \a y should be disregarded. */
79         virtual int next_tile(int& x, int& y);
80         //! Returns the number of peniding frames to render. If it is zero it
81         //! stops rendering frames.
82         /*! \todo Fix the calculation of frames to really render the last frame
83         ** When start frame= 1f and end frame = 1f it just render one frame (at 1f)
84         ** When start frame= 1f and end frame = 2f it just render one frame (at 1f)
85         ** which is a bug.*/
86         virtual int next_frame(Time& time);
87
88         //! Adds the tile at \a x , \a y contained in \a surface
89         virtual bool add_tile(const synfig::Surface &surface, int x, int y)=0;
90         //! Returns the total tiles of the imaged rounded to integer number of tiles
91         virtual int total_tiles()const
92         {
93                 // Width of the image(in tiles)
94                 const int tw(rend_desc().get_w()/tile_w_+(rend_desc().get_w()%tile_w_?1:0));
95                 const int th(rend_desc().get_h()/tile_h_+(rend_desc().get_h()%tile_h_?1:0));
96
97                 return tw*th;
98         }
99
100         //! Marks the start of a frame
101         /*! \return \c true on success, \c false upon an error.
102         **      \see end_frame(), start_scanline()
103         */
104         virtual bool start_frame(ProgressCallback *cb=NULL)=0;
105
106         //! Marks the end of a frame
107         /*! \see start_frame() */
108         virtual void end_frame()=0;
109         //!Sets the number of threads
110         void set_threads(int x) { threads_=x; }
111         //!Gets the number of threads
112         int get_threads()const { return threads_; }
113         //!Sets the tile widht
114         void set_tile_w(int w) { tile_w_=w; }
115         //!Gets the tile widht
116         int get_tile_w()const { return tile_w_; }
117         //!Sets the tile height
118         void set_tile_h(int h) { tile_h_=h; }
119         //!Gets the tile height
120         int get_tile_h()const { return tile_h_; }
121         //! Gets clipping
122         bool get_clipping()const { return clipping_; }
123         //! Sets clipping
124         void set_clipping(bool x) { clipping_=x; }
125
126 private:
127         //! Renders the context to the surface
128         bool render_frame_(Context context,ProgressCallback *cb=0);
129
130 }; // END of class Target_Tile
131
132 }; // END of namespace synfig
133
134 /* === E N D =============================================================== */
135
136 #endif