more updates
[synfig.git] / synfig-core / trunk / src / synfig / target_tile.h
1 /* === S I N F G =========================================================== */
2 /*!     \file target_tile.h
3 **      \brief Template Header
4 **
5 **      $Id: target_tile.h,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SINFG_TARGET_TILE_H
25 #define __SINFG_TARGET_TILE_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include "target.h"
30
31 /* === M A C R O S ========================================================= */
32
33 /* === T Y P E D E F S ===================================================== */
34
35 /* === C L A S S E S & S T R U C T S ======================================= */
36
37 namespace sinfg {
38
39 /*!     \class Target_Tile
40 **      \brief Render-target
41 **      \todo writeme
42 */
43 class Target_Tile : public Target
44 {
45         int threads_;
46         int tile_w_;
47         int tile_h_;
48         int curr_tile_;
49         int curr_frame_;
50         bool clipping_;
51 public:
52         typedef etl::handle<Target_Tile> Handle;
53         typedef etl::loose_handle<Target_Tile> LooseHandle;
54         typedef etl::handle<const Target_Tile> ConstHandle;
55
56         Target_Tile();
57
58         //! Renders the canvas to the target
59         virtual bool render(ProgressCallback *cb=NULL);
60
61         //! Determines which tile needs to be rendered next.
62         /*!     Most cases will not have to redefine this function. 
63         **      The default should be adequate in nearly all situations.
64         **      \returns The number of tiles left to go <i>plus one</i>.
65         **              This means that whenever this function returns zero,
66         **              there are no more tiles to render and that any value
67         **              in \a x or \a y should be disregarded. */
68         virtual int next_tile(int& x, int& y);
69
70         virtual int next_frame(Time& time);
71
72         //! Adds the tile at \a x , \a y contained in \a surface 
73         virtual bool add_tile(const sinfg::Surface &surface, int x, int y)=0;
74
75         virtual int total_tiles()const
76         {
77                 // Width of the image(in tiles)
78                 const int tw(rend_desc().get_w()/tile_w_+(rend_desc().get_w()%tile_w_?1:0));
79                 const int th(rend_desc().get_h()/tile_h_+(rend_desc().get_h()%tile_h_?1:0));
80                 
81                 return tw*th;
82         }
83
84         //! Marks the start of a frame
85         /*! \return \c true on success, \c false upon an error.
86         **      \see end_frame(), start_scanline()
87         */
88         virtual bool start_frame(ProgressCallback *cb=NULL)=0;
89
90         //! Marks the end of a frame
91         /*! \see start_frame() */
92         virtual void end_frame()=0;
93         
94         void set_threads(int x) { threads_=x; }
95
96         int get_threads()const { return threads_; }
97
98         void set_tile_w(int w) { tile_w_=w; }
99
100         int get_tile_w()const { return tile_w_; }
101
102         void set_tile_h(int h) { tile_h_=h; }
103
104         int get_tile_h()const { return tile_h_; }
105         
106         bool get_clipping()const { return clipping_; }
107
108         void set_clipping(bool x) { clipping_=x; }
109         
110 private:
111         
112         bool render_frame_(Context context,ProgressCallback *cb=0);
113         
114 }; // END of class Target_Tile
115
116 }; // END of namespace sinfg
117
118 /* === E N D =============================================================== */
119
120 #endif