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