Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / 0.61.08 / src / gtkmm / workarea.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file workarea.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, 2008 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_GTKMM_WORKAREA_H
27 #define __SYNFIG_GTKMM_WORKAREA_H
28
29 /* === H E A D E R S ======================================================= */
30
31 #include <list>
32 #include <map>
33 #include <set>
34
35 #include <ETL/smart_ptr>
36 #include <ETL/handle>
37
38 #include <gtkmm/drawingarea.h>
39 #include <gtkmm/table.h>
40 #include <gtkmm/adjustment.h>
41 #include <gtkmm/ruler.h>
42 #include <gtkmm/image.h>
43 #include <gdkmm/pixbuf.h>
44 #include <gdkmm/cursor.h>
45 #include <gdkmm/device.h>
46
47 #include <synfig/time.h>
48 #include <synfig/vector.h>
49 #include <synfig/general.h>
50 #include <synfig/renddesc.h>
51 #include <synfig/canvas.h>
52
53 #include "zoomdial.h"
54 #include "duckmatic.h"
55 #include "instance.h"
56
57 /* === M A C R O S ========================================================= */
58
59 /* === T Y P E D E F S ===================================================== */
60
61 /* === C L A S S E S & S T R U C T S ======================================= */
62
63 /*
64 namespace etl {
65
66 template <typename T_, typename C_=std::less<T_,T_> >
67 class dereferenced_compare
68 {
69 public:
70         typedef etl::loose_handle<T_> first_argument_type;
71         typedef etl::loose_handle<T_> second_argument_type;
72         typedef bool result_type;
73
74 }
75 };
76 */
77
78 namespace synfigapp { class CanvasInterface; };
79
80 namespace synfig { class Layer; };
81 namespace Gtk { class Frame; };
82
83 namespace studio
84 {
85 class WorkAreaTarget;
86 class WorkAreaTarget_Full;
87
88 class Instance;
89 class CanvasView;
90 class WorkArea;
91 class WorkAreaRenderer;
92 class AsyncRenderer;
93 class DirtyTrap
94 {
95         friend class WorkArea;
96         WorkArea *work_area;
97 public:
98         DirtyTrap(WorkArea *work_area);
99         ~DirtyTrap();
100 };
101
102
103 class WorkArea : public Gtk::Table, public Duckmatic
104 {
105         friend class WorkAreaTarget;
106         friend class WorkAreaTarget_Full;
107         friend class DirtyTrap;
108         friend class WorkAreaRenderer;
109         friend class WorkAreaProgress;
110
111         /*
112  -- ** -- P U B L I C   T Y P E S ---------------------------------------------
113         */
114
115 public:
116
117         void insert_renderer(const etl::handle<WorkAreaRenderer> &x);
118         void insert_renderer(const etl::handle<WorkAreaRenderer> &x,int priority);
119         void erase_renderer(const etl::handle<WorkAreaRenderer> &x);
120         void resort_render_set();
121
122         enum DragMode
123         {
124                 DRAG_NONE=0,
125                 DRAG_WINDOW,
126                 DRAG_DUCK,
127                 DRAG_GUIDE,
128                 DRAG_BOX
129         };
130
131         /*
132  -- ** -- P R I V A T E   D A T A ---------------------------------------------
133         */
134
135 private:
136
137         std::set<etl::handle<WorkAreaRenderer> > renderer_set_;
138
139         etl::handle<studio::AsyncRenderer> async_renderer;
140
141
142         etl::loose_handle<synfigapp::CanvasInterface> canvas_interface;
143         etl::handle<synfig::Canvas> canvas;
144         etl::loose_handle<studio::Instance> instance;
145         etl::loose_handle<studio::CanvasView> canvas_view;
146
147         // Widgets
148         Gtk::DrawingArea *drawing_area;
149         Gtk::Adjustment scrollx_adjustment;
150         Gtk::Adjustment scrolly_adjustment;
151         Gtk::VRuler *vruler;
152         Gtk::HRuler *hruler;
153         Gtk::Button *menubutton;
154         Gtk::Frame *drawing_frame;
155
156         GdkDevice* curr_input_device;
157
158         // Bleh!
159         int     w;                                              //!< Width of the image (in pixels)
160         int     h;                                              //!< Height of the image (in pixels)
161         synfig::Real    canvaswidth;    //!< Width of the canvas
162         synfig::Real    canvasheight;   //!< Height of the canvas
163         synfig::Real    pw;                             //!< The width of a pixel
164         synfig::Real    ph;                             //!< The height of a pixel
165         float zoom;                                     //!< Zoom factor
166         float prev_zoom;                        //!< Previous Zoom factor
167         synfig::Point window_tl;                //!< The (theoretical) top-left corner of the view window
168         synfig::Point window_br;                //!< The (theoretical) bottom-right corner of the view window
169
170         guint32 last_event_time;
171
172         int bpp;
173         //unsigned char *buffer;
174
175         //! ???
176         synfig::ProgressCallback *progresscallback;
177
178         //! ???
179         synfig::RendDesc desc;
180
181         //! This flag is set if the user is dragging the video window
182         /*! \see drag_point */
183         DragMode dragging;
184
185         etl::handle<Duckmatic::Duck> clicked_duck;
186         etl::handle<Duckmatic::Duck> hover_duck;
187
188         //! When dragging the viewport, this is set to the origin of the drag
189         synfig::Point drag_point;
190
191         synfig::Point curr_point;
192
193         //! ???
194         synfig::Point previous_focus;
195
196         //! This flag is set if the grid should be drawn
197         bool show_grid;
198
199         //! This flag is set if the guides should be drawn
200         bool show_guides;
201
202         bool low_resolution;
203
204         bool meta_data_lock;
205
206         //! This flag is set if the entire frame is rendered rather than using tiles
207         bool full_frame;
208
209         //Glib::RefPtr<Gdk::Pixbuf> pix_buf;
210
211         //! This vector holds all of the tiles for this image
212         std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> > tile_book;
213
214         //! This integer describes the total times that the work are has been refreshed
215         int refreshes;
216
217         //! This list holds the queue of tiles that need to be rendered
218         //std::list<int> tile_queue;
219
220         int tile_w, tile_h;
221
222         gint render_idle_func_id;
223
224         //! The coordinates of the focus the last time a part of the screen was refreshed
225         synfig::Point last_focus_point;
226
227         bool canceled_;
228
229         int quality;
230         int low_res_pixel_size;
231
232         bool dirty_trap_enabled;
233
234         int dirty_trap_queued;
235
236
237         bool onion_skin;
238
239         etl::loose_handle<synfig::ValueNode> selected_value_node_;
240
241         bool allow_duck_clicks;
242         bool allow_layer_clicks;
243         bool cancel;
244         bool curr_guide_is_x;
245         bool dirty;
246         bool queued;
247         bool rendering;
248
249         /*
250  -- ** -- P U B L I C   D A T A -----------------------------------------------
251         */
252
253 public:
254
255         const etl::loose_handle<synfig::ValueNode>& get_selected_value_node() { return  selected_value_node_; }
256         const synfig::Point& get_drag_point()const { return drag_point; }
257         std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& get_tile_book(){ return tile_book; }
258         int get_refreshes()const { return refreshes; }
259         bool get_canceled()const { return canceled_; }
260         bool get_queued()const { return queued; }
261         bool get_rendering()const { return rendering; }
262 #ifdef SINGLE_THREADED
263         bool get_updating()const;
264         void stop_updating(bool cancel = false);
265 #endif
266         bool get_full_frame()const { return full_frame; }
267         //int get_w()const { return w; }
268         //int get_h()const { return h; }
269
270         int get_tile_w()const { return tile_w; }
271         int get_tile_h()const { return tile_h; }
272
273         bool get_allow_layer_clicks() { return allow_layer_clicks; }
274         void set_allow_layer_clicks(bool value) { allow_layer_clicks=value; }
275
276         bool get_allow_duck_clicks() { return allow_duck_clicks; }
277         void set_allow_duck_clicks(bool value) { allow_duck_clicks=value; }
278
279         // used in renderer_ducks.cpp
280         bool solid_lines;
281
282         // used in renderer_guides.cpp
283         GuideList::iterator curr_guide;
284
285         // used in renderer_timecode.cpp
286         int timecode_width, timecode_height;
287
288         /*
289  -- ** -- P R I V A T E   M E T H O D S ---------------------------------------
290         */
291
292 private:
293
294         //unsigned char *get_buffer() { return buffer; }
295         bool set_wh(int w, int h,int chan=3);
296
297         int next_unrendered_tile(int refreshes)const;
298         int next_unrendered_tile()const { return next_unrendered_tile(refreshes); }
299
300         /*
301  -- ** -- S I G N A L S -------------------------------------------------------
302         */
303
304 private:
305
306         sigc::signal<void,GdkDevice* > signal_input_device_changed_;
307
308         //! One signal per button
309         sigc::signal<void,synfig::Point> signal_user_click_[5];
310
311         sigc::signal<void> signal_popup_menu_;
312
313         sigc::signal<void> signal_cursor_moved_;
314         sigc::signal<void> signal_rendering_;
315
316         sigc::signal<void> signal_onion_skin_changed_;
317
318         //! Signal for when the user clicks on a layer
319         sigc::signal<void, etl::handle<synfig::Layer> > signal_layer_selected_;
320
321         sigc::signal<void> signal_view_window_changed_;
322
323 public:
324
325         sigc::signal<void>& signal_onion_skin_changed() { return signal_onion_skin_changed_; }
326
327         sigc::signal<void>& signal_rendering() { return signal_rendering_; }
328
329         sigc::signal<void>& signal_cursor_moved() { return signal_cursor_moved_; }
330
331         sigc::signal<void>& signal_view_window_changed() { return signal_view_window_changed_; }
332         void view_window_changed() { signal_view_window_changed()(); }
333
334         sigc::signal<void,GdkDevice* >& signal_input_device_changed() { return signal_input_device_changed_; }
335
336         sigc::signal<void> &signal_popup_menu() { return signal_popup_menu_; }
337
338         //! One signal per button (5 buttons)
339         sigc::signal<void,synfig::Point> &signal_user_click(int button=0){ return signal_user_click_[button]; }
340
341         sigc::signal<void, etl::handle<synfig::Layer> >& signal_layer_selected() { return signal_layer_selected_; }
342
343         /*
344  -- ** -- P U B L I C   M E T H O D S -----------------------------------------
345         */
346
347 public:
348         void set_onion_skin(bool x);
349         bool get_onion_skin()const;
350         void toggle_onion_skin() { set_onion_skin(!get_onion_skin()); }
351
352         void set_selected_value_node(etl::loose_handle<synfig::ValueNode> x);
353
354         bool is_dragging() { return dragging!=DRAG_NONE; }
355
356         DragMode get_dragging_mode() { return dragging; }
357
358         WorkArea(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface);
359         virtual ~WorkArea();
360
361         void set_cursor(const Gdk::Cursor& x);
362         void set_cursor(Gdk::CursorType x);
363
364         const synfig::Point& get_cursor_pos()const { return curr_point; }
365
366         Gtk::Adjustment *get_scrollx_adjustment() { return &scrollx_adjustment; }
367         Gtk::Adjustment *get_scrolly_adjustment() { return &scrolly_adjustment; }
368         const Gtk::Adjustment *get_scrollx_adjustment()const { return &scrollx_adjustment; }
369         const Gtk::Adjustment *get_scrolly_adjustment()const { return &scrolly_adjustment; }
370
371         void set_instance(etl::loose_handle<studio::Instance> x) { instance=x; }
372         void set_canvas(etl::handle<synfig::Canvas> x) { canvas=x; }
373         void set_canvas_view(etl::loose_handle<studio::CanvasView> x) { canvas_view=x; }
374         etl::handle<synfig::Canvas> get_canvas()const { return canvas; }
375         etl::handle<studio::Instance> get_instance()const { return instance; }
376         etl::loose_handle<studio::CanvasView> get_canvas_view()const { return canvas_view; }
377
378         void refresh_dimension_info();
379
380         //! Enables showing of the grid
381         void enable_grid();
382
383         //! Disables showing of the grid
384         void disable_grid();
385
386         //! Toggles the showing of the grid
387         void toggle_grid();
388
389         //! Returns the state of the show_grid flag
390         bool grid_status()const { return show_grid; }
391
392         void toggle_grid_snap() { Duckmatic::toggle_grid_snap(); }
393
394         bool get_show_guides()const { return show_guides; }
395         void set_show_guides(bool x);
396         void toggle_show_guides() { set_show_guides(!get_show_guides()); }
397
398         bool get_low_resolution_flag()const { return low_resolution; }
399         void set_low_resolution_flag(bool x);
400         void toggle_low_resolution_flag();
401
402         //! ???
403         void queue_scroll();
404
405         //! Sets the size of the grid
406         void set_grid_size(const synfig::Vector &s);
407
408         //! ??
409         void popup_menu();
410
411         int get_quality()const { return quality; }
412         int get_low_res_pixel_size()const { return low_res_pixel_size; }
413
414         void set_quality(int x);
415         void set_low_res_pixel_size(int x);
416
417
418         int get_w()const { return w; }
419         int get_h()const { return h; }
420         int get_bpp()const { return bpp; }
421
422         //! ??
423         const synfig::RendDesc &get_rend_desc()const { return desc; }
424
425         //! ??
426         void set_rend_desc(const synfig::RendDesc &x) { desc=x; }
427
428         //! Converts screen coords (ie: pixels) to composition coordinates
429         synfig::Point screen_to_comp_coords(synfig::Point pos)const;
430
431         //! Converts composition coordinates to screen coords (ie: pixels)
432         synfig::Point comp_to_screen_coords(synfig::Point pos)const;
433
434         float get_pw()const { return pw; }
435         float get_ph()const { return ph; }
436
437         const synfig::Point &get_window_tl()const { return window_tl; }
438         const synfig::Point &get_window_br()const { return window_br; }
439
440
441         bool async_update_preview();
442         void async_update_finished();
443         void async_render_preview(synfig::Time time);
444         void async_render_preview();
445
446         bool sync_update_preview();
447         bool sync_render_preview(synfig::Time time);
448         bool sync_render_preview();
449         void sync_render_preview_hook();
450
451         void queue_render_preview();
452
453
454         void queue_draw_preview();
455
456         void zoom_in();
457         void zoom_out();
458         void zoom_fit();
459         void zoom_norm();
460         float get_zoom()const { return zoom; }
461
462         void set_zoom(float z);
463
464
465         void set_progress_callback(synfig::ProgressCallback *x) { progresscallback=x; }
466         synfig::ProgressCallback *get_progress_callback() { return progresscallback; }
467
468         void set_focus_point(const synfig::Point &x);
469
470         synfig::Point get_focus_point()const;
471
472         void done_rendering();
473
474         bool refresh(GdkEventExpose*bleh=NULL);
475
476         void reset_cursor();
477         void refresh_cursor();
478
479         void save_meta_data();
480         void load_meta_data();
481
482         /*
483  -- ** -- S I G N A L   T E R M I N A L S -------------------------------------
484         */
485
486 private:
487         bool on_key_press_event(GdkEventKey* event);
488         bool on_drawing_area_event(GdkEvent* event);
489         bool on_hruler_event(GdkEvent* event);
490         bool on_vruler_event(GdkEvent* event);
491
492         /*
493  -- ** -- S T A T I C   P U B L I C   M E T H O D S ---------------------------
494         */
495
496 public:
497
498         /*
499  -- ** -- S T A T I C   P R I V A T E   M E T H O D S -------------------------
500         */
501
502 private:
503
504         static gboolean __render_preview(gpointer data);
505
506 }; // END of class WorkArea
507
508 }; // END of namespace studio
509
510 /* === E N D =============================================================== */
511
512 #endif