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