04adab742d67402bca98fe9d681e7da72bb0c95a
[synfig.git] / synfig-studio / trunk / src / gtkmm / asyncrenderer.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file asyncrenderer.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_ASYNCRENDERER_H
26 #define __SYNFIG_ASYNCRENDERER_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <ETL/handle>
31 #include <sigc++/signal.h>
32 #include <sigc++/trackable.h>
33 #include <sigc++/connection.h>
34
35 #include <synfig/target_scanline.h>
36 #include <synfig/target_tile.h>
37 #include <synfig/surface.h>
38 #include <glibmm/main.h>
39 #include <ETL/ref_count>
40 #include <glibmm/thread.h>
41 #include <glibmm/dispatcher.h>
42
43 /* === M A C R O S ========================================================= */
44
45 #define single_threaded()       App::single_threaded
46 #define NotLock Glib::NOT_LOCK
47
48 /* === T Y P E D E F S ===================================================== */
49
50 /* === C L A S S E S & S T R U C T S ======================================= */
51
52 namespace studio {
53
54 class AsyncRenderer : public etl::shared_object, public sigc::trackable
55 {
56         sigc::signal<void> signal_finished_;
57         sigc::signal<void> signal_success_;
58
59         std::list<sigc::connection> activity_connection_list;
60
61         //etl::handle<synfig::Target_Scanline> target_scanline;
62         //etl::handle<synfig::Target_Tile> target_tile;
63         etl::handle<synfig::Target> target;
64
65         bool error;
66         bool success;
67
68         synfig::ProgressCallback *cb;
69
70         sigc::signal<void> signal_stop_;
71
72         Glib::Thread* render_thread;
73         Glib::Dispatcher signal_done_;
74         Glib::Mutex mutex;
75         sigc::connection done_connection;
76
77         /*
78  --     ** -- P A R E N T   M E M B E R S -----------------------------------------
79         */
80 public:
81
82         AsyncRenderer(etl::handle<synfig::Target> target,synfig::ProgressCallback *cb=0);
83         virtual ~AsyncRenderer();
84
85         void start();
86         void stop();
87         void pause();
88         void resume();
89         void rendering_progress();
90
91         bool has_error()const { return error; }
92         bool has_success()const { return success; }
93
94         bool updating;
95
96         sigc::signal<void>& signal_finished() { return signal_finished_; }
97         sigc::signal<void>& signal_success() { return signal_success_; }
98
99 private:
100
101         void render_target();
102         void start_();
103
104         /*
105  --     ** -- C H I L D   M E M B E R S -------------------------------------------
106         */
107
108 protected:
109
110 };
111
112 }; // END of namespace studio
113
114 /* === E N D =============================================================== */
115
116 #endif