initial version
[synfig.git] / synfig-studio / trunk / src / gtkmm / workarea.h
diff --git a/synfig-studio/trunk/src/gtkmm/workarea.h b/synfig-studio/trunk/src/gtkmm/workarea.h
new file mode 100644 (file)
index 0000000..8e1da79
--- /dev/null
@@ -0,0 +1,490 @@
+/* === S I N F G =========================================================== */
+/*!    \file workarea.h
+**     \brief Template Header
+**
+**     $Id: workarea.h,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
+**
+**     \legal
+**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**
+**     This software and associated documentation
+**     are CONFIDENTIAL and PROPRIETARY property of
+**     the above-mentioned copyright holder.
+**
+**     You may not copy, print, publish, or in any
+**     other way distribute this software without
+**     a prior written agreement with
+**     the copyright holder.
+**     \endlegal
+*/
+/* ========================================================================= */
+
+/* === S T A R T =========================================================== */
+
+#ifndef __SINFG_GTKMM_WORKAREA_H
+#define __SINFG_GTKMM_WORKAREA_H
+
+/* === H E A D E R S ======================================================= */
+
+#include <list>
+#include <map>
+#include <set>
+
+#include <ETL/smart_ptr>
+#include <ETL/handle>
+
+#include <gtkmm/drawingarea.h>
+#include <gtkmm/table.h>
+#include <gtkmm/adjustment.h>
+#include <gtkmm/ruler.h>
+#include <gtkmm/image.h>
+#include <gdkmm/pixbuf.h>
+#include <gdkmm/cursor.h>
+#include <gdkmm/device.h>
+
+#include <sinfg/time.h>
+#include <sinfg/vector.h>
+#include <sinfg/general.h>
+#include <sinfg/renddesc.h>
+#include <sinfg/canvas.h>
+
+#include "zoomdial.h"
+#include "duckmatic.h"
+#include "instance.h"
+
+/* === M A C R O S ========================================================= */
+
+/* === T Y P E D E F S ===================================================== */
+
+/* === C L A S S E S & S T R U C T S ======================================= */
+
+/*
+namespace etl {
+
+template <typename T_, typename C_=std::less<T_,T_> >
+class dereferenced_compare
+{
+public:
+       typedef etl::loose_handle<T_> first_argument_type;
+       typedef etl::loose_handle<T_> second_argument_type;
+       typedef bool result_type;
+       
+}
+};
+*/
+
+class WorkAreaTarget;
+class WorkAreaTarget_Full;
+namespace sinfgapp { class CanvasInterface; };
+
+namespace sinfg { class Layer; };
+namespace Gtk { class Frame; };
+
+namespace studio
+{
+class Instance;
+class CanvasView;
+class WorkArea;
+class WorkAreaRenderer;
+class AsyncRenderer;
+class DirtyTrap
+{
+       friend class WorkArea;
+       WorkArea *work_area;
+public:
+       DirtyTrap(WorkArea *work_area);
+       ~DirtyTrap();
+};
+
+
+class WorkArea : public Gtk::Table, public Duckmatic
+{
+       friend class WorkAreaTarget;
+       friend class WorkAreaTarget_Full;
+       friend class DirtyTrap;
+       friend class WorkAreaRenderer;
+               
+       /*
+ -- ** -- P U B L I C   T Y P E S ---------------------------------------------
+       */
+       
+public:
+
+       void insert_renderer(const etl::handle<WorkAreaRenderer> &x);
+       void insert_renderer(const etl::handle<WorkAreaRenderer> &x,int priority);
+       void erase_renderer(const etl::handle<WorkAreaRenderer> &x);
+       void resort_render_set();
+
+       enum DragMode
+       {
+               DRAG_NONE=0,
+               DRAG_WINDOW,
+               DRAG_DUCK,
+               DRAG_GUIDE,
+               DRAG_BOX
+       };
+
+       /*
+ -- ** -- P R I V A T E   D A T A ---------------------------------------------
+       */
+
+private:
+
+       std::set<etl::handle<WorkAreaRenderer> > renderer_set_;
+
+       etl::handle<studio::AsyncRenderer> async_renderer;
+
+
+       etl::loose_handle<sinfgapp::CanvasInterface> canvas_interface;
+       etl::handle<sinfg::Canvas> canvas;
+       etl::loose_handle<studio::Instance> instance;
+       etl::loose_handle<studio::CanvasView> canvas_view;
+
+       // Widgets
+       Gtk::DrawingArea *drawing_area;
+       Gtk::Adjustment scrollx_adjustment;
+       Gtk::Adjustment scrolly_adjustment;
+       Gtk::VRuler *vruler;
+       Gtk::HRuler *hruler;
+       Gtk::Button *menubutton;
+       Gtk::Frame *drawing_frame;
+
+       GdkDevice* curr_input_device;
+       
+       // Bleh!
+       int     w;                                              //!< Width of the image (in pixels)
+       int     h;                                              //!< Height of the image (in pixels)
+       sinfg::Real     canvaswidth;    //!< Width of the canvas
+       sinfg::Real     canvasheight;   //!< Height of the canvas
+       sinfg::Real     pw;                             //!< The width of a pixel
+       sinfg::Real     ph;                             //!< The height of a pixel
+       float zoom;                                     //!< Zoom factor
+       float prev_zoom;                        //!< Previous Zoom factor
+       sinfg::Point window_tl;         //!< The (theoretical) top-left corner of the view window
+       sinfg::Point window_br;         //!< The (theoretical) bottom-right corner of the view window
+
+       guint32 last_event_time;
+
+       int bpp;
+       //unsigned char *buffer;
+       
+       //! ???
+       sinfg::ProgressCallback *progresscallback;
+
+       //! ???
+       sinfg::RendDesc desc;
+       
+       //! This flag is set if the user is dragging the video window
+       /*! \see drag_point */
+       DragMode dragging;
+               
+       etl::handle<Duckmatic::Duck> clicked_duck;
+       etl::handle<Duckmatic::Duck> hover_duck;
+
+       //! When dragging the viewport, this is set to the origin of the drag
+       sinfg::Point drag_point;
+
+       sinfg::Point curr_point;
+
+       //! ???
+       sinfg::Point previous_focus;
+
+       //! This flag is set if the grid should be drawn
+       bool show_grid;
+
+       //! This flag is set if the guides should be drawn
+       bool show_guides;
+
+       bool low_resolution;
+       
+       bool meta_data_lock;
+
+       //! This flag is set if the entire frame is rendered rather than using tiles    
+       bool full_frame;
+       
+       //Glib::RefPtr<Gdk::Pixbuf> pix_buf;
+       
+       //! This vector holds all of the tiles for this image
+       std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> > tile_book;
+
+       //! This integer describes the total times that the work are has been refreshed
+       int refreshes;
+       
+       //! This list holds the queue of tiles that need to be rendered
+       //std::list<int> tile_queue;
+       
+       int tile_w, tile_h;
+
+       gint render_idle_func_id;
+
+       //! The coordinates of the focus the last time a part of the screen was refreshed
+       sinfg::Point last_focus_point;
+
+       bool canceled_;
+       
+       int quality;
+
+       bool dirty_trap_enabled;
+       
+       int dirty_trap_queued;
+       
+       
+       bool onion_skin;
+               
+       etl::loose_handle<sinfg::ValueNode> selected_value_node_;
+
+
+       /*
+ -- ** -- P U B L I C   D A T A -----------------------------------------------
+       */
+
+public:
+
+       const etl::loose_handle<sinfg::ValueNode>& get_selected_value_node() { return  selected_value_node_; }
+       const sinfg::Point& get_drag_point()const { return drag_point; }
+       std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& get_tile_book(){ return tile_book; }
+       int get_refreshes()const { return refreshes; }
+       bool get_canceled()const { return canceled_; }
+       bool get_queued()const { return queued; }
+       bool get_rendering()const { return rendering; }
+       bool get_full_frame()const { return full_frame; }
+       //int get_w()const { return w; }
+       //int get_h()const { return h; }
+
+       int get_tile_w()const { return tile_w; }
+       int get_tile_h()const { return tile_h; }
+       
+       bool solid_lines;
+       bool rendering;
+       bool dirty;
+       bool queued;
+       bool cancel;
+       bool allow_layer_clicks;
+       bool allow_duck_clicks;
+
+       GuideList::iterator curr_guide;
+       bool curr_guide_is_x;
+
+       /*
+ -- ** -- P R I V A T E   M E T H O D S ---------------------------------------
+       */
+
+private:
+
+       //unsigned char *get_buffer() { return buffer; }
+       bool set_wh(int w, int h,int chan=3);
+
+       int next_unrendered_tile(int refreshes)const;
+       int next_unrendered_tile()const { return next_unrendered_tile(refreshes); }
+
+       /*
+ -- ** -- S I G N A L S -------------------------------------------------------
+       */
+
+private:
+
+       sigc::signal<void,GdkDevice* > signal_input_device_changed_;
+
+       //! One signal per button
+       sigc::signal<void,sinfg::Point> signal_user_click_[5];
+
+       sigc::signal<void> signal_popup_menu_;
+
+       sigc::signal<void> signal_cursor_moved_;
+       sigc::signal<void> signal_rendering_;
+
+       sigc::signal<void> signal_onion_skin_changed_;
+
+       //! Signal for when the user clicks on a layer
+       sigc::signal<void, etl::handle<sinfg::Layer> > signal_layer_selected_;
+
+       sigc::signal<void> signal_view_window_changed_;
+
+public:
+
+       sigc::signal<void>& signal_onion_skin_changed() { return signal_onion_skin_changed_; }
+
+       sigc::signal<void>& signal_rendering() { return signal_rendering_; }
+
+       sigc::signal<void>& signal_cursor_moved() { return signal_cursor_moved_; }
+
+       sigc::signal<void>& signal_view_window_changed() { return signal_view_window_changed_; }
+       void view_window_changed() { signal_view_window_changed()(); }
+
+       sigc::signal<void,GdkDevice* >& signal_input_device_changed() { return signal_input_device_changed_; }
+
+       sigc::signal<void> &signal_popup_menu() { return signal_popup_menu_; }
+
+       //! One signal per button (5 buttons)
+       sigc::signal<void,sinfg::Point> &signal_user_click(int button=0){ return signal_user_click_[button]; }
+
+       sigc::signal<void, etl::handle<sinfg::Layer> >& signal_layer_selected() { return signal_layer_selected_; }
+
+       /*
+ -- ** -- P U B L I C   M E T H O D S -----------------------------------------
+       */
+
+public:
+       void set_onion_skin(bool x);
+       bool get_onion_skin()const;
+       void toggle_onion_skin() { set_onion_skin(!get_onion_skin()); }
+
+       void set_selected_value_node(etl::loose_handle<sinfg::ValueNode> x);
+
+       bool is_dragging() { return dragging!=DRAG_NONE; }
+
+       DragMode get_dragging_mode() { return dragging; }
+
+       WorkArea(etl::loose_handle<sinfgapp::CanvasInterface> canvas_interface);
+       virtual ~WorkArea();
+
+       void set_cursor(const Gdk::Cursor& x);
+       void set_cursor(Gdk::CursorType x);
+
+       const sinfg::Point& get_cursor_pos()const { return curr_point; }
+
+       Gtk::Adjustment *get_scrollx_adjustment() { return &scrollx_adjustment; }
+       Gtk::Adjustment *get_scrolly_adjustment() { return &scrolly_adjustment; }
+       const Gtk::Adjustment *get_scrollx_adjustment()const { return &scrollx_adjustment; }
+       const Gtk::Adjustment *get_scrolly_adjustment()const { return &scrolly_adjustment; }
+
+       void set_instance(etl::loose_handle<studio::Instance> x) { instance=x; }
+       void set_canvas(etl::handle<sinfg::Canvas> x) { canvas=x; }
+       void set_canvas_view(etl::loose_handle<studio::CanvasView> x) { canvas_view=x; }
+       etl::handle<sinfg::Canvas> get_canvas()const { return canvas; }
+       etl::handle<studio::Instance> get_instance()const { return instance; }
+       etl::loose_handle<studio::CanvasView> get_canvas_view()const { return canvas_view; }
+
+       void refresh_dimension_info();
+       
+       //! Enables showing of the grid
+       void enable_grid();
+       
+       //! Disables showing of the grid
+       void disable_grid();
+       
+       //! Toggles the showing of the grid
+       void toggle_grid();
+       
+       //! Returns the state of the show_grid flag
+       bool grid_status()const { return show_grid; }
+
+       void toggle_grid_snap() { Duckmatic::toggle_grid_snap(); }
+
+       bool get_show_guides()const { return show_guides; }
+       void set_show_guides(bool x);
+       void toggle_show_guides() { set_show_guides(!get_show_guides()); }
+               
+       bool get_low_resolution_flag()const { return low_resolution; }
+       void set_low_resolution_flag(bool x);
+       void toggle_low_resolution_flag();
+       
+       //! ???
+       void queue_scroll();
+       
+       //! Sets the size of the grid
+       void set_grid_size(const sinfg::Vector &s);
+               
+       //! ??
+       void popup_menu();
+       
+       int get_quality()const { return quality; }
+
+       void set_quality(int x);
+       
+
+       int get_w()const { return w; }
+       int get_h()const { return h; }
+       int get_bpp()const { return bpp; }
+
+       //! ??
+       const sinfg::RendDesc &get_rend_desc()const { return desc; }
+       
+       //! ??
+       void set_rend_desc(const sinfg::RendDesc &x) { desc=x; }
+       
+       //! Converts screen coords (ie: pixels) to composition coordinates
+       sinfg::Point screen_to_comp_coords(sinfg::Point pos)const;
+
+       //! Converts composition coordinates to screen coords (ie: pixels)
+       sinfg::Point comp_to_screen_coords(sinfg::Point pos)const;
+
+       float get_pw()const { return pw; }
+       float get_ph()const { return ph; }
+       
+       const sinfg::Point &get_window_tl()const { return window_tl; }
+       const sinfg::Point &get_window_br()const { return window_br; }
+
+
+       bool async_update_preview();
+       void async_update_finished();
+       void async_render_preview(sinfg::Time time);
+       void async_render_preview();
+       
+       bool sync_update_preview();
+       bool sync_render_preview(sinfg::Time time);
+       bool sync_render_preview();
+       void sync_render_preview_hook();
+
+       void queue_render_preview();
+       
+       
+       void queue_draw_preview();
+       
+       void zoom_in();
+       void zoom_out();
+       void zoom_fit();
+       void zoom_norm();
+       float get_zoom()const { return zoom; }
+       
+       void set_zoom(float z);
+
+
+       void set_progress_callback(sinfg::ProgressCallback *x)  { progresscallback=x; }
+       sinfg::ProgressCallback *get_progress_callback() { return progresscallback; }
+
+       void set_focus_point(const sinfg::Point &x);
+
+       sinfg::Point get_focus_point()const;
+
+       void done_rendering();
+       
+       bool refresh(GdkEventExpose*bleh=NULL);
+       
+       void reset_cursor();
+       void refresh_cursor();
+
+       void save_meta_data();
+       void load_meta_data();
+       
+       /*
+ -- ** -- S I G N A L   T E R M I N A L S -------------------------------------
+       */
+
+private:
+       bool on_key_press_event(GdkEventKey* event);
+       bool on_drawing_area_event(GdkEvent* event);
+       bool on_hruler_event(GdkEvent* event);
+       bool on_vruler_event(GdkEvent* event);
+
+       /*
+ -- ** -- S T A T I C   P U B L I C   M E T H O D S ---------------------------
+       */
+
+public:
+
+       /*
+ -- ** -- S T A T I C   P R I V A T E   M E T H O D S -------------------------
+       */
+
+private:
+
+       static gboolean __render_preview(gpointer data);
+
+}; // END of class WorkArea
+
+}; // END of namespace studio
+
+/* === E N D =============================================================== */
+
+#endif