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