1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_GTKMM_WORKAREA_H
26 #define __SYNFIG_GTKMM_WORKAREA_H
28 /* === H E A D E R S ======================================================= */
34 #include <ETL/smart_ptr>
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>
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>
53 #include "duckmatic.h"
56 /* === M A C R O S ========================================================= */
58 /* === T Y P E D E F S ===================================================== */
60 /* === C L A S S E S & S T R U C T S ======================================= */
65 template <typename T_, typename C_=std::less<T_,T_> >
66 class dereferenced_compare
69 typedef etl::loose_handle<T_> first_argument_type;
70 typedef etl::loose_handle<T_> second_argument_type;
71 typedef bool result_type;
77 namespace synfigapp { class CanvasInterface; };
79 namespace synfig { class Layer; };
80 namespace Gtk { class Frame; };
85 class WorkAreaTarget_Full;
90 class WorkAreaRenderer;
94 friend class WorkArea;
97 DirtyTrap(WorkArea *work_area);
102 class WorkArea : public Gtk::Table, public Duckmatic
104 friend class WorkAreaTarget;
105 friend class WorkAreaTarget_Full;
106 friend class DirtyTrap;
107 friend class WorkAreaRenderer;
108 friend class WorkAreaProgress;
111 -- ** -- P U B L I C T Y P E S ---------------------------------------------
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();
131 -- ** -- P R I V A T E D A T A ---------------------------------------------
136 std::set<etl::handle<WorkAreaRenderer> > renderer_set_;
138 etl::handle<studio::AsyncRenderer> async_renderer;
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;
147 Gtk::DrawingArea *drawing_area;
148 Gtk::Adjustment scrollx_adjustment;
149 Gtk::Adjustment scrolly_adjustment;
152 Gtk::Button *menubutton;
153 Gtk::Frame *drawing_frame;
155 GdkDevice* curr_input_device;
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
169 guint32 last_event_time;
172 //unsigned char *buffer;
175 synfig::ProgressCallback *progresscallback;
178 synfig::RendDesc desc;
180 //! This flag is set if the user is dragging the video window
181 /*! \see drag_point */
184 etl::handle<Duckmatic::Duck> clicked_duck;
185 etl::handle<Duckmatic::Duck> hover_duck;
187 //! When dragging the viewport, this is set to the origin of the drag
188 synfig::Point drag_point;
190 synfig::Point curr_point;
193 synfig::Point previous_focus;
195 //! This flag is set if the grid should be drawn
198 //! This flag is set if the guides should be drawn
205 //! This flag is set if the entire frame is rendered rather than using tiles
208 //Glib::RefPtr<Gdk::Pixbuf> pix_buf;
210 //! This vector holds all of the tiles for this image
211 std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> > tile_book;
213 //! This integer describes the total times that the work are has been refreshed
216 //! This list holds the queue of tiles that need to be rendered
217 //std::list<int> tile_queue;
221 gint render_idle_func_id;
223 //! The coordinates of the focus the last time a part of the screen was refreshed
224 synfig::Point last_focus_point;
230 bool dirty_trap_enabled;
232 int dirty_trap_queued;
237 etl::loose_handle<synfig::ValueNode> selected_value_node_;
239 bool allow_duck_clicks;
240 bool allow_layer_clicks;
242 bool curr_guide_is_x;
248 -- ** -- P U B L I C D A T A -----------------------------------------------
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; }
264 int get_tile_w()const { return tile_w; }
265 int get_tile_h()const { return tile_h; }
267 bool get_allow_layer_clicks() { return allow_layer_clicks; }
268 void set_allow_layer_clicks(bool value) { allow_layer_clicks=value; }
270 bool get_allow_duck_clicks() { return allow_duck_clicks; }
271 void set_allow_duck_clicks(bool value) { allow_duck_clicks=value; }
273 // used in renderer_ducks.cpp
276 // used in renderer_guides.cpp
277 GuideList::iterator curr_guide;
279 // used in renderer_timecode.cpp
280 int timecode_width, timecode_height;
283 -- ** -- P R I V A T E M E T H O D S ---------------------------------------
288 //unsigned char *get_buffer() { return buffer; }
289 bool set_wh(int w, int h,int chan=3);
291 int next_unrendered_tile(int refreshes)const;
292 int next_unrendered_tile()const { return next_unrendered_tile(refreshes); }
295 -- ** -- S I G N A L S -------------------------------------------------------
300 sigc::signal<void,GdkDevice* > signal_input_device_changed_;
302 //! One signal per button
303 sigc::signal<void,synfig::Point> signal_user_click_[5];
305 sigc::signal<void> signal_popup_menu_;
307 sigc::signal<void> signal_cursor_moved_;
308 sigc::signal<void> signal_rendering_;
310 sigc::signal<void> signal_onion_skin_changed_;
312 //! Signal for when the user clicks on a layer
313 sigc::signal<void, etl::handle<synfig::Layer> > signal_layer_selected_;
315 sigc::signal<void> signal_view_window_changed_;
319 sigc::signal<void>& signal_onion_skin_changed() { return signal_onion_skin_changed_; }
321 sigc::signal<void>& signal_rendering() { return signal_rendering_; }
323 sigc::signal<void>& signal_cursor_moved() { return signal_cursor_moved_; }
325 sigc::signal<void>& signal_view_window_changed() { return signal_view_window_changed_; }
326 void view_window_changed() { signal_view_window_changed()(); }
328 sigc::signal<void,GdkDevice* >& signal_input_device_changed() { return signal_input_device_changed_; }
330 sigc::signal<void> &signal_popup_menu() { return signal_popup_menu_; }
332 //! One signal per button (5 buttons)
333 sigc::signal<void,synfig::Point> &signal_user_click(int button=0){ return signal_user_click_[button]; }
335 sigc::signal<void, etl::handle<synfig::Layer> >& signal_layer_selected() { return signal_layer_selected_; }
338 -- ** -- P U B L I C M E T H O D S -----------------------------------------
342 void set_onion_skin(bool x);
343 bool get_onion_skin()const;
344 void toggle_onion_skin() { set_onion_skin(!get_onion_skin()); }
346 void set_selected_value_node(etl::loose_handle<synfig::ValueNode> x);
348 bool is_dragging() { return dragging!=DRAG_NONE; }
350 DragMode get_dragging_mode() { return dragging; }
352 WorkArea(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface);
355 void set_cursor(const Gdk::Cursor& x);
356 void set_cursor(Gdk::CursorType x);
358 const synfig::Point& get_cursor_pos()const { return curr_point; }
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; }
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; }
372 void refresh_dimension_info();
374 //! Enables showing of the grid
377 //! Disables showing of the grid
380 //! Toggles the showing of the grid
383 //! Returns the state of the show_grid flag
384 bool grid_status()const { return show_grid; }
386 void toggle_grid_snap() { Duckmatic::toggle_grid_snap(); }
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()); }
392 bool get_low_resolution_flag()const { return low_resolution; }
393 void set_low_resolution_flag(bool x);
394 void toggle_low_resolution_flag();
399 //! Sets the size of the grid
400 void set_grid_size(const synfig::Vector &s);
405 int get_quality()const { return quality; }
407 void set_quality(int x);
410 int get_w()const { return w; }
411 int get_h()const { return h; }
412 int get_bpp()const { return bpp; }
415 const synfig::RendDesc &get_rend_desc()const { return desc; }
418 void set_rend_desc(const synfig::RendDesc &x) { desc=x; }
420 //! Converts screen coords (ie: pixels) to composition coordinates
421 synfig::Point screen_to_comp_coords(synfig::Point pos)const;
423 //! Converts composition coordinates to screen coords (ie: pixels)
424 synfig::Point comp_to_screen_coords(synfig::Point pos)const;
426 float get_pw()const { return pw; }
427 float get_ph()const { return ph; }
429 const synfig::Point &get_window_tl()const { return window_tl; }
430 const synfig::Point &get_window_br()const { return window_br; }
433 bool async_update_preview();
434 void async_update_finished();
435 void async_render_preview(synfig::Time time);
436 void async_render_preview();
438 bool sync_update_preview();
439 bool sync_render_preview(synfig::Time time);
440 bool sync_render_preview();
441 void sync_render_preview_hook();
443 void queue_render_preview();
446 void queue_draw_preview();
452 float get_zoom()const { return zoom; }
454 void set_zoom(float z);
457 void set_progress_callback(synfig::ProgressCallback *x) { progresscallback=x; }
458 synfig::ProgressCallback *get_progress_callback() { return progresscallback; }
460 void set_focus_point(const synfig::Point &x);
462 synfig::Point get_focus_point()const;
464 void done_rendering();
466 bool refresh(GdkEventExpose*bleh=NULL);
469 void refresh_cursor();
471 void save_meta_data();
472 void load_meta_data();
475 -- ** -- S I G N A L T E R M I N A L S -------------------------------------
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);
485 -- ** -- S T A T I C P U B L I C M E T H O D S ---------------------------
491 -- ** -- S T A T I C P R I V A T E M E T H O D S -------------------------
496 static gboolean __render_preview(gpointer data);
498 }; // END of class WorkArea
500 }; // END of namespace studio
502 /* === E N D =============================================================== */