synfig-studio  1.0.3
workarea.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
23 /* ========================================================================= */
24 
25 /* === S T A R T =========================================================== */
26 
27 #ifndef __SYNFIG_GTKMM_WORKAREA_H
28 #define __SYNFIG_GTKMM_WORKAREA_H
29 
30 /* === H E A D E R S ======================================================= */
31 
32 #include <list>
33 #include <map>
34 #include <set>
35 
36 #include <ETL/smart_ptr>
37 #include <ETL/handle>
38 
39 #include <gtkmm/drawingarea.h>
40 #include <gtkmm/table.h>
41 #include <gtkmm/adjustment.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 "dials/zoomdial.h"
54 #include "widgets/widget_ruler.h"
55 #include "duckmatic.h"
56 #include "instance.h"
57 #include "app.h"
58 
59 /* === M A C R O S ========================================================= */
60 
61 /* === T Y P E D E F S ===================================================== */
62 
63 /* === C L A S S E S & S T R U C T S ======================================= */
64 
65 /*
66 namespace etl {
67 
68 template <typename T_, typename C_=std::less<T_,T_> >
69 class dereferenced_compare
70 {
71 public:
72  typedef etl::loose_handle<T_> first_argument_type;
73  typedef etl::loose_handle<T_> second_argument_type;
74  typedef bool result_type;
75 
76 }
77 };
78 */
79 
80 namespace synfigapp { class CanvasInterface; };
81 
82 namespace synfig { class Layer; };
83 namespace Gtk { class Frame; };
84 
85 namespace studio
86 {
87 class WorkAreaTarget;
88 class WorkAreaTarget_Full;
89 class WorkAreaTarget_Cairo;
90 class WorkAreaTarget_Cairo_Tile;
91 
92 class Instance;
93 class CanvasView;
94 class WorkArea;
95 class WorkAreaRenderer;
96 class AsyncRenderer;
97 class DirtyTrap
98 {
99  friend class WorkArea;
100  WorkArea *work_area;
101 public:
102  DirtyTrap(WorkArea *work_area);
103  ~DirtyTrap();
104 };
105 
106 
107 class WorkArea : public Gtk::Table, public Duckmatic
108 {
109  friend class WorkAreaTarget;
110  friend class WorkAreaTarget_Full;
111  friend class WorkAreaTarget_Cairo;
113  friend class DirtyTrap;
114  friend class WorkAreaRenderer;
115  friend class WorkAreaProgress;
116 
117  /*
118  -- ** -- P U B L I C T Y P E S ---------------------------------------------
119  */
120 
121 public:
122 
123  class PushState;
124  friend class PushState;
125 
126  void insert_renderer(const etl::handle<WorkAreaRenderer> &x);
127  void insert_renderer(const etl::handle<WorkAreaRenderer> &x,int priority);
128  void erase_renderer(const etl::handle<WorkAreaRenderer> &x);
129  void resort_render_set();
130 
131  enum DragMode
132  {
139  };
140  // Class used to store the cairo surface
142  {
143  public:
144  cairo_surface_t* surface;
147  {
148  surface=NULL;
149  refreshes=0;
150  }
151  //Copy constructor
152  SurfaceElement(const SurfaceElement& other): surface(cairo_surface_reference(other.surface)), refreshes(other.refreshes)
153  {
154  }
156  {
157  if(surface)
158  cairo_surface_destroy(surface);
159  }
160  };
161 
162  typedef std::vector<SurfaceElement> SurfaceBook;
163 
164  /*
165  -- ** -- P R I V A T E D A T A ---------------------------------------------
166  */
167 
168 private:
169 
170  std::set<etl::handle<WorkAreaRenderer> > renderer_set_;
171 
172  etl::handle<studio::AsyncRenderer> async_renderer;
173 
174 
175  etl::loose_handle<synfigapp::CanvasInterface> canvas_interface;
176  etl::handle<synfig::Canvas> canvas;
177  etl::loose_handle<studio::Instance> instance;
178  etl::loose_handle<studio::CanvasView> canvas_view;
179 
180  // Widgets
181  Gtk::DrawingArea *drawing_area;
182  Glib::RefPtr<Gtk::Adjustment> scrollx_adjustment;
183  Glib::RefPtr<Gtk::Adjustment> scrolly_adjustment;
184  // TODO: Implement Rulers
185  Widget_Ruler *vruler;
186  Widget_Ruler *hruler;
187  Gtk::Button *menubutton;
188  Gtk::Frame *drawing_frame;
189 
190  GdkDevice* curr_input_device;
191 
192  // Bleh!
193  int w;
194  int h;
195  synfig::Real canvaswidth;
196  synfig::Real canvasheight;
197  synfig::Real pw;
198  synfig::Real ph;
199  // float zoom and prev_zoom are declared in Duckmatic
200  synfig::Point window_tl;
201  synfig::Point window_br;
202 
203  guint32 last_event_time;
204 
205  int bpp;
206  //unsigned char *buffer;
207 
209  synfig::ProgressCallback *progresscallback;
210 
212  synfig::RendDesc desc;
213 
215 
216  DragMode dragging;
217 
218  etl::handle<Duckmatic::Duck> clicked_duck;
219  etl::handle<Duckmatic::Duck> hover_duck;
220 
222  synfig::Point drag_point;
223 
224  synfig::Point curr_point;
225 
227  synfig::Point previous_focus;
228 
230  bool show_grid;
231 
233  bool show_guides;
234 
236  synfig::Vector background_size;
238  synfig::Color background_first_color;
240  synfig::Color background_second_color;
241 
242  synfig::Time jack_offset;
243 
244  bool low_resolution;
245 
246  bool meta_data_lock;
247 
249  bool full_frame;
250 
251  //Glib::RefPtr<Gdk::Pixbuf> pix_buf;
252 
254  std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> > tile_book;
255  // This vector holds all the cairo surfaces for the frame
256  SurfaceBook cairo_book;
257 
259  int refreshes;
260 
262  //std::list<int> tile_queue;
263 
264  int tile_w, tile_h;
265 
266  gint render_idle_func_id;
267 
269  synfig::Point last_focus_point;
270 
271  bool canceled_;
272 
273  int quality;
274  int low_res_pixel_size;
275 
276  bool dirty_trap_enabled;
277 
278  int dirty_trap_queued;
279 
280  // This flag is set if onion skin is visible
281  bool onion_skin;
283  int onion_skins[2];
284 
285  etl::loose_handle<synfig::ValueNode> selected_value_node_;
286 
287  bool allow_duck_clicks;
288  bool allow_bezier_clicks;
289  bool allow_layer_clicks;
290  bool cancel;
291  bool curr_guide_is_x;
292  bool dirty;
293  bool queued;
294  bool rendering;
295 
296 #ifdef SINGLE_THREADED
297  /* resize bug workaround */
298  int old_window_width;
299  int old_window_height;
300 #endif
301 
302  /*
303  -- ** -- P U B L I C D A T A -----------------------------------------------
304  */
305 
306 public:
307 
308  const etl::loose_handle<synfig::ValueNode>& get_selected_value_node() { return selected_value_node_; }
309  const synfig::Point& get_drag_point()const { return drag_point; }
310  std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& get_tile_book(){ return tile_book; }
311  SurfaceBook& get_cairo_book() { return cairo_book; }
312  int get_refreshes()const { return refreshes; }
313  bool get_canceled()const { return canceled_; }
314  bool get_queued()const { return queued; }
315  bool get_rendering()const { return rendering; }
316 #ifdef SINGLE_THREADED
317  bool get_updating()const;
318  void stop_updating(bool cancel = false);
319 #endif
320  bool get_full_frame()const { return full_frame; }
321  //int get_w()const { return w; }
322  //int get_h()const { return h; }
323 
324  int get_tile_w()const { return tile_w; }
325  int get_tile_h()const { return tile_h; }
326 
327  bool get_allow_layer_clicks() { return allow_layer_clicks; }
328  void set_allow_layer_clicks(bool value) { allow_layer_clicks=value; }
329 
330  bool get_allow_duck_clicks() { return allow_duck_clicks; }
331  void set_allow_duck_clicks(bool value) { allow_duck_clicks=value; }
332 
333  bool get_allow_bezier_clicks() { return allow_bezier_clicks; }
334  void set_allow_bezier_clicks(bool value) { allow_bezier_clicks=value; }
335 
336  // used in renderer_ducks.cpp
338 
339  // used in renderer_guides.cpp
340  GuideList::iterator curr_guide;
341 
342  // used in renderer_timecode.cpp
344 
345  // used in renderer_bonesetup.cpp
347 
348  /*
349  -- ** -- P R I V A T E M E T H O D S ---------------------------------------
350  */
351 
352 private:
353 
354  //unsigned char *get_buffer() { return buffer; }
355  bool set_wh(int w, int h,int chan=3);
356 
357  int next_unrendered_tile(int refreshes)const;
358  int next_unrendered_tile()const { return next_unrendered_tile(refreshes); }
359 
360  /*
361  -- ** -- S I G N A L S -------------------------------------------------------
362  */
363 
364 private:
365 
366  sigc::signal<void,GdkDevice* > signal_input_device_changed_;
367 
369  sigc::signal<void,synfig::Point> signal_user_click_[5];
370 
371  sigc::signal<void> signal_popup_menu_;
372 
373  sigc::signal<void> signal_cursor_moved_;
374  sigc::signal<void> signal_rendering_;
375 
377  sigc::signal<void, etl::handle<synfig::Layer> > signal_layer_selected_;
378 
379  sigc::signal<void> signal_view_window_changed_;
380 
381  sigc::signal<void> signal_meta_data_changed_;
382 
383 public:
384 
385  sigc::signal<void>& signal_rendering() { return signal_rendering_; }
386 
387  sigc::signal<void>& signal_cursor_moved() { return signal_cursor_moved_; }
388 
389  sigc::signal<void>& signal_view_window_changed() { return signal_view_window_changed_; }
390 
391  sigc::signal<void>& signal_meta_data_changed() { return signal_meta_data_changed_; }
392 
394 
395  sigc::signal<void,GdkDevice* >& signal_input_device_changed() { return signal_input_device_changed_; }
396 
397  sigc::signal<void> &signal_popup_menu() { return signal_popup_menu_; }
398 
400  sigc::signal<void,synfig::Point> &signal_user_click(int button=0){ return signal_user_click_[button]; }
401 
402  sigc::signal<void, etl::handle<synfig::Layer> >& signal_layer_selected() { return signal_layer_selected_; }
403 
404  /*
405  -- ** -- P U B L I C M E T H O D S -----------------------------------------
406  */
407 
408 public:
409  void set_onion_skin(bool x);
410  bool get_onion_skin()const;
412  void set_onion_skins(int *onions);
413  int const * get_onion_skins()const;
414 
415  void set_selected_value_node(etl::loose_handle<synfig::ValueNode> x);
416 
417  bool is_dragging() { return dragging!=DRAG_NONE; }
418 
419  DragMode get_dragging_mode() { return dragging; }
420 
421  WorkArea(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface);
422  virtual ~WorkArea();
423 
424  void set_cursor(const Glib::RefPtr<Gdk::Cursor> &x);
425  void set_cursor(Gdk::CursorType x);
426 
427  const synfig::Point& get_cursor_pos()const { return curr_point; }
428 
429  Glib::RefPtr<Gtk::Adjustment> get_scrollx_adjustment() { return scrollx_adjustment; }
430  Glib::RefPtr<Gtk::Adjustment> get_scrolly_adjustment() { return scrolly_adjustment; }
431  Glib::RefPtr<const Gtk::Adjustment> get_scrollx_adjustment() const { return scrollx_adjustment; }
432  Glib::RefPtr<const Gtk::Adjustment> get_scrolly_adjustment() const { return scrolly_adjustment; }
433 
434  void set_instance(etl::loose_handle<studio::Instance> x) { instance=x; }
435  void set_canvas(etl::handle<synfig::Canvas> x) { canvas=x; }
436  void set_canvas_view(etl::loose_handle<studio::CanvasView> x) { canvas_view=x; }
437  etl::handle<synfig::Canvas> get_canvas()const { return canvas; }
438  etl::handle<studio::Instance> get_instance()const { return instance; }
439  etl::loose_handle<studio::CanvasView> get_canvas_view()const { return canvas_view; }
440 
441  void refresh_dimension_info();
442 
444  void enable_grid();
446  void disable_grid();
448  void toggle_grid();
450  bool grid_status()const { return show_grid; }
452  void toggle_grid_snap();
454  void set_grid_size(const synfig::Vector &s);
456  void set_grid_color(const synfig::Color &c);
458  const synfig::Color &get_grid_color()const { return Duckmatic::get_grid_color();}
459 
461  bool get_show_guides()const { return show_guides; }
463  void set_show_guides(bool x);
467  void toggle_guide_snap();
469  void set_guides_color(const synfig::Color &c);
471  const synfig::Color &get_guides_color()const { return Duckmatic::get_guides_color();}
472 
473  synfig::Time get_jack_offset()const { return jack_offset; }
474  void set_jack_offset(const synfig::Time &x);
475 
477  void set_background_size(const synfig::Vector &s);
479  void set_background_first_color(const synfig::Color &c);
481  void set_background_second_color(const synfig::Color &c);
483  const synfig::Vector &get_background_size()const { return background_size;}
485  const synfig::Color &get_background_first_color()const { return background_first_color;}
487  const synfig::Color &get_background_second_color()const { return background_second_color;}
488 
489  bool get_low_resolution_flag()const { return low_resolution; }
490  void set_low_resolution_flag(bool x);
492 
494  void queue_scroll();
495 
497  void popup_menu();
498 
499  int get_quality()const { return quality; }
500  int get_low_res_pixel_size()const { return low_res_pixel_size; }
501 
502  void set_quality(int x);
503  void set_low_res_pixel_size(int x);
504 
505 
506  int get_w()const { return w; }
507  int get_h()const { return h; }
508  int get_bpp()const { return bpp; }
509 
511  const synfig::RendDesc &get_rend_desc()const { return desc; }
512 
514  void set_rend_desc(const synfig::RendDesc &x) { desc=x; }
515 
517  synfig::Point screen_to_comp_coords(synfig::Point pos)const;
518 
520  synfig::Point comp_to_screen_coords(synfig::Point pos)const;
521 
522  float get_pw()const { return pw; }
523  float get_ph()const { return ph; }
524 
525  const synfig::Point &get_window_tl()const { return window_tl; }
526  const synfig::Point &get_window_br()const { return window_br; }
527 
528 
529  bool async_update_preview();
530  void async_update_finished();
531  void async_render_preview(synfig::Time time);
532  void async_render_preview();
533 
534  bool sync_update_preview();
535  bool sync_render_preview(synfig::Time time);
536  bool sync_render_preview();
538 
539  void queue_render_preview();
540 
541 
542  void queue_draw_preview();
543 
544  void zoom_in();
545  void zoom_out();
546  void zoom_fit();
547  void zoom_norm();
548  float get_zoom()const { return zoom; } // zoom is declared in Duckmatic
549 
550  void set_zoom(float z);
551 
552 
553  void set_progress_callback(synfig::ProgressCallback *x) { progresscallback=x; }
554  synfig::ProgressCallback *get_progress_callback() { return progresscallback; }
555 
556  void set_focus_point(const synfig::Point &x);
557 
558  synfig::Point get_focus_point()const;
559 
560  void done_rendering();
561 
562 #ifdef SINGLE_THREADED
563  /* resize bug workaround */
564  void refresh_second_check();
565 #endif
566  bool refresh(const Cairo::RefPtr<Cairo::Context> &cr);
567 
568  void reset_cursor();
569  void refresh_cursor();
570 
571  void save_meta_data();
572  void load_meta_data();
574  bool have_meta_data();
575 
576  /*
577  -- ** -- S I G N A L T E R M I N A L S -------------------------------------
578  */
579 
580 private:
581  bool on_key_press_event(GdkEventKey* event);
582  bool on_key_release_event(GdkEventKey* event);
583  bool on_drawing_area_event(GdkEvent* event);
584  bool on_hruler_event(GdkEvent* event);
585  bool on_vruler_event(GdkEvent* event);
586 
587  /*
588  -- ** -- S T A T I C P U B L I C M E T H O D S ---------------------------
589  */
590 
591 public:
592 
593  /*
594  -- ** -- S T A T I C P R I V A T E M E T H O D S -------------------------
595  */
596 
597 private:
598 
599  static gboolean __render_preview(gpointer data);
600 #ifdef SINGLE_THREADED
601  /* resize bug workaround */
602  static gboolean __refresh_second_check(gpointer data);
603 #endif
604 
605 }; // END of class WorkArea
606 
611 {
612  WorkArea *workarea_;
613  Type type_mask;
614  bool allow_duck_clicks;
615  bool allow_bezier_clicks;
616  bool allow_layer_clicks;
617 
618  bool needs_restore;
619 
620 public:
621  PushState(WorkArea *workarea_);
622  ~PushState();
623  void restore();
624 }; // END of class WorkArea::PushState
625 
626 }; // END of namespace studio
627 
628 /* === E N D =============================================================== */
629 
630 #endif