viewport.h

00001 /***************************************************************************
00002 *   Copyright (C) 2004 by Rick L. Vinyard, Jr.                            *
00003 *   rvinyard@cs.nmsu.edu                                                  *
00004 *                                                                         *
00005 *   This program is free software; you can redistribute it and/or modify  *
00006 *   it under the terms of the GNU Lesser General Public License as        *
00007 *   published by the Free Software Foundation version 2.1.                *
00008 *                                                                         *
00009 *   This program is distributed in the hope that it will be useful,       *
00010 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012 *   GNU General Public License for more details.                          *
00013 *                                                                         *
00014 *   You should have received a copy of the GNU Lesser General Public      *
00015 *   License along with this library; if not, write to the                 *
00016 *   Free Software Foundation, Inc.,                                       *
00017 *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018 ***************************************************************************/
00019 #ifndef PAPYRUSGTKVIEWPORT_H
00020 #define PAPYRUSGTKVIEWPORT_H
00021 
00022 #include <set>
00023 
00024 #include <gtkmm.h>
00025 
00026 #include <papyrus/canvas.h>
00027 #include <papyrus/controller.h>
00028 #include <papyrusmm/enums.h>
00029 
00030 namespace PapyrusGtk {
00031 
00035 class Viewport: public Gtk::EventBox {
00036 
00037 public:
00038   Viewport();
00039   virtual ~Viewport();
00040 
00041 
00042 public:
00043   typedef std::set<Papyrus::Controller::pointer> Controllers;
00044 
00045   // Drawing Operations
00046   virtual void clear();
00047 
00049   Papyrus::Canvas::pointer canvas();
00050 
00052   void set_canvas( Papyrus::Canvas::pointer  canvas );
00053 
00054   void set_scroll_point(SCROLL_TO scroll_to=SCROLL_TO_CENTER);
00055 
00056   SCROLL_TO scroll_point();
00057 
00058   void scroll_offsets(double& x, double& y) const;
00059 
00060   void scroll_to(double offset_x, double offset_y);
00061 
00062   void scroll_to_center();
00063 
00071   void window_to_canvas(double winx, double winy, double& canvasx, double& canvasy) const;
00072 
00080   void canvas_to_window(double canvasx, double canvasy, double& winx, double& winy) const;
00081 
00082   const Controllers& controllers();
00083 
00084   void add_controller( Papyrus::Controller::pointer controller );
00085 
00086   void remove_controller( Papyrus::Controller::pointer controller );
00087 
00088   bool canvas_size_tied_to_viewport();
00089 
00090   void tie_canvas_size_to_viewport(bool tie=true);
00091 
00092   bool viewport_size_tied_to_canvas();
00093 
00094   void tie_viewport_size_to_canvas(bool tie=true);
00095 
00096 protected:
00097   Papyrus::Canvas::pointer m_canvas;
00098   Papyrus::Group::pointer m_root;
00099   int m_width, m_height;
00100   double m_scroll_x, m_scroll_y;
00101   bool m_tie_canvas_size_to_viewport, m_tie_viewport_size_to_canvas;
00102   Controllers m_controllers;
00103   sigc::connection m_canvas_redraw_connection;
00104   sigc::connection m_canvas_size_connection;
00105   SCROLL_TO m_scroll_to;
00106   Cairo::RefPtr<Cairo::Context> m_context;
00107 
00108   void on_canvas_size_changed();
00109 
00110   void on_need_redraw(double x, double y, double w, double h);
00111 
00112   bool expose_event_callback(GdkEventExpose* e);
00113 
00114   void size_allocate_callback(Gtk::Allocation& allocation);
00115 
00116   bool button_press_event_callback( GdkEventButton* event );
00117 
00118   bool button_release_event_callback( GdkEventButton* event );
00119 
00120   bool key_press_event_callback( GdkEventKey* event );
00121 
00122   bool key_release_event_callback( GdkEventKey* event );
00123 
00124   bool motion_notify_event_callback( GdkEventMotion* event );
00125 
00126   bool scroll_event_callback( GdkEventScroll* event );
00127 
00128 }; // class Viewport
00129 
00130 }
00131 
00132 #endif

Generated on Sun Mar 11 10:01:28 2007 by  doxygen 1.5.1