1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
5 ** $Id: workarea.h,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __SYNFIG_GTKMM_WORKAREA_H
25 #define __SYNFIG_GTKMM_WORKAREA_H
27 /* === H E A D E R S ======================================================= */
33 #include <ETL/smart_ptr>
36 #include <gtkmm/drawingarea.h>
37 #include <gtkmm/table.h>
38 #include <gtkmm/adjustment.h>
39 #include <gtkmm/ruler.h>
40 #include <gtkmm/image.h>
41 #include <gdkmm/pixbuf.h>
42 #include <gdkmm/cursor.h>
43 #include <gdkmm/device.h>
45 #include <synfig/time.h>
46 #include <synfig/vector.h>
47 #include <synfig/general.h>
48 #include <synfig/renddesc.h>
49 #include <synfig/canvas.h>
52 #include "duckmatic.h"
55 /* === M A C R O S ========================================================= */
57 /* === T Y P E D E F S ===================================================== */
59 /* === C L A S S E S & S T R U C T S ======================================= */
64 template <typename T_, typename C_=std::less<T_,T_> >
65 class dereferenced_compare
68 typedef etl::loose_handle<T_> first_argument_type;
69 typedef etl::loose_handle<T_> second_argument_type;
70 typedef bool result_type;
77 class WorkAreaTarget_Full;
78 namespace synfigapp { class CanvasInterface; };
80 namespace synfig { class Layer; };
81 namespace Gtk { class Frame; };
88 class WorkAreaRenderer;
92 friend class WorkArea;
95 DirtyTrap(WorkArea *work_area);
100 class WorkArea : public Gtk::Table, public Duckmatic
102 friend class WorkAreaTarget;
103 friend class WorkAreaTarget_Full;
104 friend class DirtyTrap;
105 friend class WorkAreaRenderer;
108 -- ** -- P U B L I C T Y P E S ---------------------------------------------
113 void insert_renderer(const etl::handle<WorkAreaRenderer> &x);
114 void insert_renderer(const etl::handle<WorkAreaRenderer> &x,int priority);
115 void erase_renderer(const etl::handle<WorkAreaRenderer> &x);
116 void resort_render_set();
128 -- ** -- P R I V A T E D A T A ---------------------------------------------
133 std::set<etl::handle<WorkAreaRenderer> > renderer_set_;
135 etl::handle<studio::AsyncRenderer> async_renderer;
138 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface;
139 etl::handle<synfig::Canvas> canvas;
140 etl::loose_handle<studio::Instance> instance;
141 etl::loose_handle<studio::CanvasView> canvas_view;
144 Gtk::DrawingArea *drawing_area;
145 Gtk::Adjustment scrollx_adjustment;
146 Gtk::Adjustment scrolly_adjustment;
149 Gtk::Button *menubutton;
150 Gtk::Frame *drawing_frame;
152 GdkDevice* curr_input_device;
155 int w; //!< Width of the image (in pixels)
156 int h; //!< Height of the image (in pixels)
157 synfig::Real canvaswidth; //!< Width of the canvas
158 synfig::Real canvasheight; //!< Height of the canvas
159 synfig::Real pw; //!< The width of a pixel
160 synfig::Real ph; //!< The height of a pixel
161 float zoom; //!< Zoom factor
162 float prev_zoom; //!< Previous Zoom factor
163 synfig::Point window_tl; //!< The (theoretical) top-left corner of the view window
164 synfig::Point window_br; //!< The (theoretical) bottom-right corner of the view window
166 guint32 last_event_time;
169 //unsigned char *buffer;
172 synfig::ProgressCallback *progresscallback;
175 synfig::RendDesc desc;
177 //! This flag is set if the user is dragging the video window
178 /*! \see drag_point */
181 etl::handle<Duckmatic::Duck> clicked_duck;
182 etl::handle<Duckmatic::Duck> hover_duck;
184 //! When dragging the viewport, this is set to the origin of the drag
185 synfig::Point drag_point;
187 synfig::Point curr_point;
190 synfig::Point previous_focus;
192 //! This flag is set if the grid should be drawn
195 //! This flag is set if the guides should be drawn
202 //! This flag is set if the entire frame is rendered rather than using tiles
205 //Glib::RefPtr<Gdk::Pixbuf> pix_buf;
207 //! This vector holds all of the tiles for this image
208 std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> > tile_book;
210 //! This integer describes the total times that the work are has been refreshed
213 //! This list holds the queue of tiles that need to be rendered
214 //std::list<int> tile_queue;
218 gint render_idle_func_id;
220 //! The coordinates of the focus the last time a part of the screen was refreshed
221 synfig::Point last_focus_point;
227 bool dirty_trap_enabled;
229 int dirty_trap_queued;
234 etl::loose_handle<synfig::ValueNode> selected_value_node_;
238 -- ** -- P U B L I C D A T A -----------------------------------------------
243 const etl::loose_handle<synfig::ValueNode>& get_selected_value_node() { return selected_value_node_; }
244 const synfig::Point& get_drag_point()const { return drag_point; }
245 std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& get_tile_book(){ return tile_book; }
246 int get_refreshes()const { return refreshes; }
247 bool get_canceled()const { return canceled_; }
248 bool get_queued()const { return queued; }
249 bool get_rendering()const { return rendering; }
250 bool get_full_frame()const { return full_frame; }
251 //int get_w()const { return w; }
252 //int get_h()const { return h; }
254 int get_tile_w()const { return tile_w; }
255 int get_tile_h()const { return tile_h; }
262 bool allow_layer_clicks;
263 bool allow_duck_clicks;
265 GuideList::iterator curr_guide;
266 bool curr_guide_is_x;
269 -- ** -- P R I V A T E M E T H O D S ---------------------------------------
274 //unsigned char *get_buffer() { return buffer; }
275 bool set_wh(int w, int h,int chan=3);
277 int next_unrendered_tile(int refreshes)const;
278 int next_unrendered_tile()const { return next_unrendered_tile(refreshes); }
281 -- ** -- S I G N A L S -------------------------------------------------------
286 sigc::signal<void,GdkDevice* > signal_input_device_changed_;
288 //! One signal per button
289 sigc::signal<void,synfig::Point> signal_user_click_[5];
291 sigc::signal<void> signal_popup_menu_;
293 sigc::signal<void> signal_cursor_moved_;
294 sigc::signal<void> signal_rendering_;
296 sigc::signal<void> signal_onion_skin_changed_;
298 //! Signal for when the user clicks on a layer
299 sigc::signal<void, etl::handle<synfig::Layer> > signal_layer_selected_;
301 sigc::signal<void> signal_view_window_changed_;
305 sigc::signal<void>& signal_onion_skin_changed() { return signal_onion_skin_changed_; }
307 sigc::signal<void>& signal_rendering() { return signal_rendering_; }
309 sigc::signal<void>& signal_cursor_moved() { return signal_cursor_moved_; }
311 sigc::signal<void>& signal_view_window_changed() { return signal_view_window_changed_; }
312 void view_window_changed() { signal_view_window_changed()(); }
314 sigc::signal<void,GdkDevice* >& signal_input_device_changed() { return signal_input_device_changed_; }
316 sigc::signal<void> &signal_popup_menu() { return signal_popup_menu_; }
318 //! One signal per button (5 buttons)
319 sigc::signal<void,synfig::Point> &signal_user_click(int button=0){ return signal_user_click_[button]; }
321 sigc::signal<void, etl::handle<synfig::Layer> >& signal_layer_selected() { return signal_layer_selected_; }
324 -- ** -- P U B L I C M E T H O D S -----------------------------------------
328 void set_onion_skin(bool x);
329 bool get_onion_skin()const;
330 void toggle_onion_skin() { set_onion_skin(!get_onion_skin()); }
332 void set_selected_value_node(etl::loose_handle<synfig::ValueNode> x);
334 bool is_dragging() { return dragging!=DRAG_NONE; }
336 DragMode get_dragging_mode() { return dragging; }
338 WorkArea(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface);
341 void set_cursor(const Gdk::Cursor& x);
342 void set_cursor(Gdk::CursorType x);
344 const synfig::Point& get_cursor_pos()const { return curr_point; }
346 Gtk::Adjustment *get_scrollx_adjustment() { return &scrollx_adjustment; }
347 Gtk::Adjustment *get_scrolly_adjustment() { return &scrolly_adjustment; }
348 const Gtk::Adjustment *get_scrollx_adjustment()const { return &scrollx_adjustment; }
349 const Gtk::Adjustment *get_scrolly_adjustment()const { return &scrolly_adjustment; }
351 void set_instance(etl::loose_handle<studio::Instance> x) { instance=x; }
352 void set_canvas(etl::handle<synfig::Canvas> x) { canvas=x; }
353 void set_canvas_view(etl::loose_handle<studio::CanvasView> x) { canvas_view=x; }
354 etl::handle<synfig::Canvas> get_canvas()const { return canvas; }
355 etl::handle<studio::Instance> get_instance()const { return instance; }
356 etl::loose_handle<studio::CanvasView> get_canvas_view()const { return canvas_view; }
358 void refresh_dimension_info();
360 //! Enables showing of the grid
363 //! Disables showing of the grid
366 //! Toggles the showing of the grid
369 //! Returns the state of the show_grid flag
370 bool grid_status()const { return show_grid; }
372 void toggle_grid_snap() { Duckmatic::toggle_grid_snap(); }
374 bool get_show_guides()const { return show_guides; }
375 void set_show_guides(bool x);
376 void toggle_show_guides() { set_show_guides(!get_show_guides()); }
378 bool get_low_resolution_flag()const { return low_resolution; }
379 void set_low_resolution_flag(bool x);
380 void toggle_low_resolution_flag();
385 //! Sets the size of the grid
386 void set_grid_size(const synfig::Vector &s);
391 int get_quality()const { return quality; }
393 void set_quality(int x);
396 int get_w()const { return w; }
397 int get_h()const { return h; }
398 int get_bpp()const { return bpp; }
401 const synfig::RendDesc &get_rend_desc()const { return desc; }
404 void set_rend_desc(const synfig::RendDesc &x) { desc=x; }
406 //! Converts screen coords (ie: pixels) to composition coordinates
407 synfig::Point screen_to_comp_coords(synfig::Point pos)const;
409 //! Converts composition coordinates to screen coords (ie: pixels)
410 synfig::Point comp_to_screen_coords(synfig::Point pos)const;
412 float get_pw()const { return pw; }
413 float get_ph()const { return ph; }
415 const synfig::Point &get_window_tl()const { return window_tl; }
416 const synfig::Point &get_window_br()const { return window_br; }
419 bool async_update_preview();
420 void async_update_finished();
421 void async_render_preview(synfig::Time time);
422 void async_render_preview();
424 bool sync_update_preview();
425 bool sync_render_preview(synfig::Time time);
426 bool sync_render_preview();
427 void sync_render_preview_hook();
429 void queue_render_preview();
432 void queue_draw_preview();
438 float get_zoom()const { return zoom; }
440 void set_zoom(float z);
443 void set_progress_callback(synfig::ProgressCallback *x) { progresscallback=x; }
444 synfig::ProgressCallback *get_progress_callback() { return progresscallback; }
446 void set_focus_point(const synfig::Point &x);
448 synfig::Point get_focus_point()const;
450 void done_rendering();
452 bool refresh(GdkEventExpose*bleh=NULL);
455 void refresh_cursor();
457 void save_meta_data();
458 void load_meta_data();
461 -- ** -- S I G N A L T E R M I N A L S -------------------------------------
465 bool on_key_press_event(GdkEventKey* event);
466 bool on_drawing_area_event(GdkEvent* event);
467 bool on_hruler_event(GdkEvent* event);
468 bool on_vruler_event(GdkEvent* event);
471 -- ** -- S T A T I C P U B L I C M E T H O D S ---------------------------
477 -- ** -- S T A T I C P R I V A T E M E T H O D S -------------------------
482 static gboolean __render_preview(gpointer data);
484 }; // END of class WorkArea
486 }; // END of namespace studio
488 /* === E N D =============================================================== */