Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07_rc1 / 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 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_TARGET_TILE_H
26 #define __SYNFIG_TARGET_TILE_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include "target.h"
31
32 /* === M A C R O S ========================================================= */
33
34 /* === T Y P E D E F S ===================================================== */
35
36 /* === C L A S S E S & S T R U C T S ======================================= */
37
38 namespace synfig {
39
40 /*!     \class Target_Tile
41 **      \brief Render-target
42 **      \todo writeme
43 */
44 class Target_Tile : public Target
45 {
46         int threads_;
47         int tile_w_;
48         int tile_h_;
49         int curr_tile_;
50         int curr_frame_;
51         bool clipping_;
52 public:
53         typedef etl::handle<Target_Tile> Handle;
54         typedef etl::loose_handle<Target_Tile> LooseHandle;
55         typedef etl::handle<const Target_Tile> ConstHandle;
56
57         Target_Tile();
58
59         //! Renders the canvas to the target
60         virtual bool render(ProgressCallback *cb=NULL);
61
62         //! Determines which tile needs to be rendered next.
63         /*!     Most cases will not have to redefine this function.
64         **      The default should be adequate in nearly all situations.
65         **      \returns The number of tiles left to go <i>plus one</i>.
66         **              This means that whenever this function returns zero,
67         **              there are no more tiles to render and that any value
68         **              in \a x or \a y should be disregarded. */
69         virtual int next_tile(int& x, int& y);
70
71         virtual int next_frame(Time& time);
72
73         //! Adds the tile at \a x , \a y contained in \a surface
74         virtual bool add_tile(const synfig::Surface &surface, int x, int y)=0;
75
76         virtual int total_tiles()const
77         {
78                 // Width of the image(in tiles)
79                 const int tw(rend_desc().get_w()/tile_w_+(rend_desc().get_w()%tile_w_?1:0));
80                 const int th(rend_desc().get_h()/tile_h_+(rend_desc().get_h()%tile_h_?1:0));
81
82                 return tw*th;
83         }
84
85         //! Marks the start of a frame
86         /*! \return \c true on success, \c false upon an error.
87         **      \see end_frame(), start_scanline()
88         */
89         virtual bool start_frame(ProgressCallback *cb=NULL)=0;
90
91         //! Marks the end of a frame
92         /*! \see start_frame() */
93         virtual void end_frame()=0;
94
95         void set_threads(int x) { threads_=x; }
96
97         int get_threads()const { return threads_; }
98
99         void set_tile_w(int w) { tile_w_=w; }
100
101         int get_tile_w()const { return tile_w_; }
102
103         void set_tile_h(int h) { tile_h_=h; }
104
105         int get_tile_h()const { return tile_h_; }
106
107         bool get_clipping()const { return clipping_; }
108
109         void set_clipping(bool x) { clipping_=x; }
110
111 private:
112
113         bool render_frame_(Context context,ProgressCallback *cb=0);
114
115 }; // END of class Target_Tile
116
117 }; // END of namespace synfig
118
119 /* === E N D =============================================================== */
120
121 #endif