- Main Page
- Related Pages
- Namespaces
- Classes
- Files

# preview.h

Go to the documentation of this file.

    00001 /* === S Y N F I G ========================================================= */
    00021 /* ========================================================================= */
    00022
    00023 /* === S T A R T =========================================================== */
    00024
    00025 #ifndef __SYNFIG_PREVIEW_H
    00026 #define __SYNFIG_PREVIEW_H
    00027
    00028 /* === H E A D E R S ======================================================= */
    00029 #include <ETL/handle>
    00030 #include <ETL/clock> /* indirectly includes winnt.h on WIN32 - needs to be included before gtkmm headers, which fix this */
    00031
    00032 #include <gtkmm/drawingarea.h>
    00033 #include <gtkmm/table.h>
    00034 #include <gtkmm/adjustment.h>
    00035 #include <gtkmm/image.h>
    00036 #include <gdkmm/pixbuf.h>
    00037 #include <gtkmm/dialog.h>
    00038 #include <gtkmm/scrollbar.h>
    00039 #include <gtkmm/checkbutton.h>
    00040 #include <gtkmm/canvasview.h>
    00041 #include <gtkmm/tooltips.h>
    00042
    00043 #include <synfig/time.h>
    00044 #include <synfig/vector.h>
    00045 #include <synfig/general.h>
    00046 #include <synfig/renddesc.h>
    00047 #include <synfig/canvas.h>
    00048
    00049 #include "widget_sound.h"
    00050
    00051 #include <vector>
    00052
    00053 /* === M A C R O S ========================================================= */
    00054
    00055 /* === T Y P E D E F S ===================================================== */
    00056
    00057 /* === C L A S S E S & S T R U C T S ======================================= */
    00058
    00059 namespace studio {
    00060 class AsyncRenderer;
    00061
    00062 class Preview : public sigc::trackable, public etl::shared_object
    00063 {
    00064 public:
    00065     struct FlipbookElem
    00066     {
    00067         float                       t;
    00068         Glib::RefPtr<Gdk::Pixbuf>   buf; //at whatever resolution they are rendered at (resized at run time)
    00069     };
    00070
    00071     etl::handle<studio::AsyncRenderer>  renderer;
    00072
    00073     sigc::signal<void, Preview *>   signal_destroyed_;  //so things can reference us without fear
    00074
    00075     typedef std::vector<FlipbookElem>    FlipBook;
    00076 private:
    00077
    00078     FlipBook            frames;
    00079
    00080     studio::CanvasView::LooseHandle canvasview;
    00081
    00082     //synfig::RendDesc      description; //for rendering the preview...
    00083     float   zoom,fps;
    00084     float   begintime,endtime;
    00085     bool    overbegin,overend;
    00086     int     quality;
    00087
    00088     float   global_fps;
    00089
    00090     //expose the frame information etc.
    00091     class Preview_Target;
    00092     void frame_finish(const Preview_Target *);
    00093
    00094     sigc::signal0<void> sig_changed;
    00095
    00096 public:
    00097
    00098     Preview(const studio::CanvasView::LooseHandle &h = studio::CanvasView::LooseHandle(),
    00099                 float zoom = 0.5f, float fps = 15);
    00100     ~Preview();
    00101
    00102     float   get_zoom() const {return zoom;}
    00103     void    set_zoom(float z){zoom = z;}
    00104
    00105     float   get_fps() const {return fps;}
    00106     void    set_fps(float f){fps = f;}
    00107
    00108     float   get_global_fps() const {return global_fps;}
    00109     void    set_global_fps(float f){global_fps = f;}
    00110
    00111     float   get_begintime() const
    00112     {
    00113         if(overbegin)
    00114             return begintime;
    00115         else if(canvasview)
    00116             return get_canvas()->rend_desc().get_time_start();
    00117         else return -1;
    00118     }
    00119
    00120     float   get_endtime() const
    00121     {
    00122         if(overend)
    00123             return endtime;
    00124         else if(canvasview)
    00125             return get_canvas()->rend_desc().get_time_end();
    00126         else return -1;
    00127     }
    00128
    00129     void    set_begintime(float t)  {begintime = t;}
    00130     void    set_endtime(float t)    {endtime = t;}
    00131
    00132     bool get_overbegin() const {return overbegin;}
    00133     void set_overbegin(bool b) {overbegin = b;}
    00134
    00135     bool get_overend() const {return overend;}
    00136     void set_overend(bool b) {overend = b;}
    00137
    00138     int     get_quality() const {return quality;}
    00139     void    set_quality(int i)  {quality = i;}
    00140
    00141     synfig::Canvas::Handle  get_canvas() const {return canvasview->get_canvas();}
    00142     studio::CanvasView::Handle  get_canvasview() const {return canvasview;}
    00143
    00144     void set_canvasview(const studio::CanvasView::LooseHandle &h);
    00145
    00146     //signal interface
    00147     sigc::signal<void, Preview *> & signal_destroyed() { return signal_destroyed_; }
    00148     //sigc::signal<void, const synfig::RendDesc &>  &signal_desc_change() {return signal_desc_change_;}
    00149
    00150     //functions for exposing iterators through the preview
    00151     FlipBook::iterator  begin()     {return frames.begin();}
    00152     FlipBook::iterator  end()       {return frames.end();}
    00153
    00154     FlipBook::const_iterator    begin() const {return frames.begin();}
    00155     FlipBook::const_iterator    end() const   {return frames.end();}
    00156
    00157     void clear() {frames.clear();}
    00158
    00159     unsigned int                numframes() const  {return frames.size();}
    00160
    00161     void render();
    00162
    00163     sigc::signal0<void> &signal_changed() { return sig_changed; }
    00164 };
    00165
    00166 class Widget_Preview : public Gtk::Table
    00167 {
    00168     Gtk::DrawingArea    draw_area;
    00169     Gtk::Adjustment     adj_time_scrub; //the adjustment for the managed scrollbar
    00170     Gtk::HScrollbar     scr_time_scrub;
    00171     Gtk::ToggleButton   b_loop;
    00172     Gtk::Tooltips       tooltips;
    00173
    00174     //Glib::RefPtr<Gdk::GC>     gc_area;
    00175     Glib::RefPtr<Gdk::Pixbuf>   currentbuf;
    00176     int                         currentindex;
    00177     //double                        timeupdate;
    00178     double                      timedisp;
    00179     double                      audiotime;
    00180
    00181     //sound stuff
    00182     etl::handle<AudioContainer> audio;
    00183     sigc::connection    scrstartcon;
    00184     sigc::connection    scrstopcon;
    00185     sigc::connection    scrubcon;
    00186
    00187     //preview encapsulation
    00188     etl::handle<Preview>    preview;
    00189     sigc::connection        prevchanged;
    00190
    00191     Widget_Sound            disp_sound;
    00192     Gtk::Adjustment         adj_sound;
    00193
    00194     Gtk::Label              l_lasttime;
    00195
    00196     //only for internal stuff, doesn't set anything
    00197     bool    playing;
    00198     bool    singleframe;
    00199
    00200     //for accurate time tracking
    00201     etl::clock  timer;
    00202
    00203     //int       curindex; //for later
    00204     sigc::connection    timecon;
    00205
    00206     void slider_move(); //later to be a time_slider that's cooler
    00207     bool play_update();
    00208     void play_stop();
    00209     //bool play_frameupdate();
    00210     void update();
    00211
    00212     void scrub_updated(double t);
    00213
    00214     void repreview();
    00215
    00216     void whenupdated();
    00217
    00218     void eraseall();
    00219
    00220     bool scroll_move_event(GdkEvent *);
    00221     void disconnect_preview(Preview *);
    00222
    00223     bool redraw(GdkEventExpose *heh = 0);
    00224     void preview_draw();
    00225
    00226     sigc::signal<void,float>    signal_play_;
    00227     sigc::signal<void>          signal_stop_;
    00228     sigc::signal<void,float>    signal_seek_;
    00229
    00230 public:
    00231
    00232     Widget_Preview();
    00233     ~Widget_Preview();
    00234
    00235     //sets a signal to identify disconnection (so we don't hold onto it)...
    00236     void set_preview(etl::handle<Preview> prev);
    00237     void set_audioprofile(etl::handle<AudioProfile> p);
    00238     void set_audio(etl::handle<AudioContainer> a);
    00239
    00240     void clear();
    00241
    00242     void play();
    00243     void stop();
    00244     void seek(float t);
    00245
    00246     void stoprender();
    00247
    00248     sigc::signal<void,float>    &signal_play() {return signal_play_;}
    00249     sigc::signal<void>  &signal_stop() {return signal_stop_;}
    00250     sigc::signal<void,float>    &signal_seek() {return signal_seek_;}
    00251
    00252     bool get_loop_flag() const {return b_loop.get_active();}
    00253     void set_loop_flag(bool b) {return b_loop.set_active(b);}
    00254 };
    00255
    00256 }; // END of namespace studio
    00257
    00258 /* === E N D =============================================================== */
    00259
    00260 #endif