Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / stable / src / gtkmm / preview.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file preview.h
3 **      \brief Previews an animation
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_PREVIEW_H
26 #define __SYNFIG_PREVIEW_H
27
28 /* === H E A D E R S ======================================================= */
29 #include <ETL/handle>
30 #include <ETL/clock> /* indirectly includes winnt.h on WIN32 - needs to be included before gtkmm headers, which fix this */
31
32 #include <gtkmm/drawingarea.h>
33 #include <gtkmm/table.h>
34 #include <gtkmm/adjustment.h>
35 #include <gtkmm/image.h>
36 #include <gdkmm/pixbuf.h>
37 #include <gtkmm/dialog.h>
38 #include <gtkmm/scrollbar.h>
39 #include <gtkmm/checkbutton.h>
40 #include <gtkmm/canvasview.h>
41 #include <gtkmm/tooltips.h>
42
43 #include <synfig/time.h>
44 #include <synfig/vector.h>
45 #include <synfig/general.h>
46 #include <synfig/renddesc.h>
47 #include <synfig/canvas.h>
48
49 #include "widget_sound.h"
50
51 #include <vector>
52
53 /* === M A C R O S ========================================================= */
54
55 /* === T Y P E D E F S ===================================================== */
56
57 /* === C L A S S E S & S T R U C T S ======================================= */
58
59 namespace studio {
60 class AsyncRenderer;
61
62 class Preview : public sigc::trackable, public etl::shared_object
63 {
64 public:
65         struct FlipbookElem
66         {
67                 float                                           t;
68                 Glib::RefPtr<Gdk::Pixbuf>       buf; //at whatever resolution they are rendered at (resized at run time)
69         };
70
71         etl::handle<studio::AsyncRenderer>      renderer;
72
73         sigc::signal<void, Preview *>   signal_destroyed_;      //so things can reference us without fear
74
75         typedef std::vector<FlipbookElem>        FlipBook;
76 private:
77
78         FlipBook                        frames;
79
80         studio::CanvasView::LooseHandle canvasview;
81
82         //synfig::RendDesc              description; //for rendering the preview...
83         float   zoom,fps;
84         float   begintime,endtime;
85         bool    overbegin,overend;
86         int             quality;
87
88         float   global_fps;
89
90         //expose the frame information etc.
91         class Preview_Target;
92         void frame_finish(const Preview_Target *);
93
94         sigc::signal0<void>     sig_changed;
95
96 public:
97
98         Preview(const studio::CanvasView::LooseHandle &h = studio::CanvasView::LooseHandle(),
99                                 float zoom = 0.5f, float fps = 15);
100         ~Preview();
101
102         float   get_zoom() const {return zoom;}
103         void    set_zoom(float z){zoom = z;}
104
105         float   get_fps() const {return fps;}
106         void    set_fps(float f){fps = f;}
107
108         float   get_global_fps() const {return global_fps;}
109         void    set_global_fps(float f){global_fps = f;}
110
111         float   get_begintime() const
112         {
113                 if(overbegin)
114                         return begintime;
115                 else if(canvasview)
116                         return get_canvas()->rend_desc().get_time_start();
117                 else return -1;
118         }
119
120         float   get_endtime() const
121         {
122                 if(overend)
123                         return endtime;
124                 else if(canvasview)
125                         return get_canvas()->rend_desc().get_time_end();
126                 else return -1;
127         }
128
129         void    set_begintime(float t)  {begintime = t;}
130         void    set_endtime(float t)    {endtime = t;}
131
132         bool get_overbegin() const {return overbegin;}
133         void set_overbegin(bool b) {overbegin = b;}
134
135         bool get_overend() const {return overend;}
136         void set_overend(bool b) {overend = b;}
137
138         int             get_quality() const {return quality;}
139         void    set_quality(int i)      {quality = i;}
140
141         synfig::Canvas::Handle  get_canvas() const {return canvasview->get_canvas();}
142         studio::CanvasView::Handle      get_canvasview() const {return canvasview;}
143
144         void set_canvasview(const studio::CanvasView::LooseHandle &h);
145
146         //signal interface
147         sigc::signal<void, Preview *> & signal_destroyed() { return signal_destroyed_; }
148         //sigc::signal<void, const synfig::RendDesc &>  &signal_desc_change() {return signal_desc_change_;}
149
150         //functions for exposing iterators through the preview
151         FlipBook::iterator      begin()         {return frames.begin();}
152         FlipBook::iterator      end()           {return frames.end();}
153
154         FlipBook::const_iterator        begin() const {return frames.begin();}
155         FlipBook::const_iterator        end() const       {return frames.end();}
156
157         void clear() {frames.clear();}
158
159         unsigned int                            numframes() const  {return frames.size();}
160
161         void render();
162
163         sigc::signal0<void>     &signal_changed() { return sig_changed; }
164 };
165
166 class Widget_Preview : public Gtk::Table
167 {
168         Gtk::DrawingArea        draw_area;
169         Gtk::Adjustment         adj_time_scrub; //the adjustment for the managed scrollbar
170         Gtk::HScrollbar         scr_time_scrub;
171         Gtk::ToggleButton       b_loop;
172         Gtk::Tooltips           tooltips;
173
174         //Glib::RefPtr<Gdk::GC>         gc_area;
175         Glib::RefPtr<Gdk::Pixbuf>       currentbuf;
176         int                                                     currentindex;
177         //double                                                timeupdate;
178         double                                          timedisp;
179         double                                          audiotime;
180
181         //sound stuff
182         etl::handle<AudioContainer>     audio;
183         sigc::connection        scrstartcon;
184         sigc::connection        scrstopcon;
185         sigc::connection        scrubcon;
186
187         //preview encapsulation
188         etl::handle<Preview>    preview;
189         sigc::connection                prevchanged;
190
191         Widget_Sound                    disp_sound;
192         Gtk::Adjustment                 adj_sound;
193
194         Gtk::Label                              l_lasttime;
195
196         //only for internal stuff, doesn't set anything
197         bool    playing;
198         bool    singleframe;
199
200         //for accurate time tracking
201         etl::clock      timer;
202
203         //int           curindex; //for later
204         sigc::connection        timecon;
205
206         void slider_move(); //later to be a time_slider that's cooler
207         bool play_update();
208         void play_stop();
209         //bool play_frameupdate();
210         void update();
211
212         void scrub_updated(double t);
213
214         void repreview();
215
216         void whenupdated();
217
218         void eraseall();
219
220         bool scroll_move_event(GdkEvent *);
221         void disconnect_preview(Preview *);
222
223         bool redraw(GdkEventExpose *heh = 0);
224         void preview_draw();
225
226         sigc::signal<void,float>        signal_play_;
227         sigc::signal<void>                      signal_stop_;
228         sigc::signal<void,float>        signal_seek_;
229
230 public:
231
232         Widget_Preview();
233         ~Widget_Preview();
234
235         //sets a signal to identify disconnection (so we don't hold onto it)...
236         void set_preview(etl::handle<Preview> prev);
237         void set_audioprofile(etl::handle<AudioProfile> p);
238         void set_audio(etl::handle<AudioContainer> a);
239
240         void clear();
241
242         void play();
243         void stop();
244         void seek(float t);
245
246         void stoprender();
247
248         sigc::signal<void,float>        &signal_play() {return signal_play_;}
249         sigc::signal<void>      &signal_stop() {return signal_stop_;}
250         sigc::signal<void,float>        &signal_seek() {return signal_seek_;}
251
252         bool get_loop_flag() const {return b_loop.get_active();}
253         void set_loop_flag(bool b) {return b_loop.set_active(b);}
254 };
255
256 }; // END of namespace studio
257
258 /* === E N D =============================================================== */
259
260 #endif