00001 /*************************************************************************** 00002 * Copyright (C) 2004 by Rick L. Vinyard, Jr. * 00003 * rvinyard@cs.nmsu.edu * 00004 * * 00005 * This file is part of the papyrus library. * 00006 * * 00007 * papyrus is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU Lesser General Public License * 00009 * version 3.0 as published by the Free Software Foundation. * 00010 * * 00011 * papyrus is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU Lesser General Public License version 3.0 for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with the papyrus library. If not, see * 00018 * <http://www.gnu.org/licenses/>. * 00019 ***************************************************************************/ 00020 #ifndef PAPYRUSGTKVIEWPORT_H 00021 #define PAPYRUSGTKVIEWPORT_H 00022 00023 #include <set> 00024 00025 #include <gtkmm.h> 00026 00027 #include <papyrus/canvas.h> 00028 #include <papyrus/controller.h> 00029 #include <papyrus-gtkmm/enums.h> 00030 00031 namespace Papyrus 00032 { 00033 namespace Gtk 00034 { 00035 00039 class Viewport: public ::Gtk::EventBox 00040 { 00041 00042 public: 00043 00044 Viewport(); 00045 00046 virtual ~Viewport(); 00047 00048 typedef std::set<Papyrus::Controller::pointer> Controllers; 00049 00050 // Drawing Operations 00051 virtual void clear(); 00052 00054 Papyrus::Canvas::pointer canvas(); 00055 00057 void set_canvas ( Papyrus::Canvas::pointer canvas ); 00058 00059 const Controllers& controllers(); 00060 00061 void add_controller ( Papyrus::Controller::pointer controller ); 00062 00063 void remove_controller ( Papyrus::Controller::pointer controller ); 00064 00065 bool canvas_size_tied_to_viewport(); 00066 00067 void tie_canvas_size_to_viewport ( bool tie=true ); 00068 00069 bool viewport_size_tied_to_canvas(); 00070 00071 void tie_viewport_size_to_canvas ( bool tie=true ); 00072 00073 Papyrus::Event::signal& signal_papyrus_event(); 00074 00075 protected: 00076 Papyrus::Canvas::pointer m_canvas; 00077 int m_width, m_height; 00078 bool m_tie_canvas_size_to_viewport, m_tie_viewport_size_to_canvas; 00079 00080 Controllers m_controllers; 00081 00082 typedef std::map<Papyrus::Controller::pointer,sigc::connection> ControllerConnections; 00083 00084 ControllerConnections m_controller_connections; 00085 00086 Papyrus::Event::signal m_signal_papyrus_event; 00087 00088 sigc::connection m_canvas_redraw_connection; 00089 sigc::connection m_canvas_size_connection; 00090 Cairo::RefPtr<Cairo::Context> m_context; 00091 00092 void on_canvas_size_changed(); 00093 00094 void on_redraw ( double x, double y, double w, double h ); 00095 00096 bool expose_event_callback ( GdkEventExpose* e ); 00097 00098 void size_allocate_callback ( ::Gtk::Allocation& allocation ); 00099 00100 bool button_press_event_callback ( GdkEventButton* event ); 00101 00102 bool button_release_event_callback ( GdkEventButton* event ); 00103 00104 bool key_press_event_callback ( GdkEventKey* event ); 00105 00106 bool key_release_event_callback ( GdkEventKey* event ); 00107 00108 bool motion_notify_event_callback ( GdkEventMotion* event ); 00109 00110 bool scroll_event_callback ( GdkEventScroll* event ); 00111 00112 }; 00113 00114 } 00115 00116 } 00117 00118 #endif