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