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 sigc::signal<void>& signal_canvas_replaced(); 00076 00077 protected: 00078 Papyrus::Canvas::pointer m_canvas; 00079 int m_width, m_height; 00080 bool m_tie_canvas_size_to_viewport, m_tie_viewport_size_to_canvas; 00081 00082 Controllers m_controllers; 00083 00084 typedef std::map<Papyrus::Controller::pointer,sigc::connection> ControllerConnections; 00085 00086 ControllerConnections m_controller_connections; 00087 00088 Papyrus::Event::signal m_signal_papyrus_event; 00089 00090 sigc::connection m_canvas_redraw_connection; 00091 sigc::connection m_canvas_size_connection; 00092 00093 Context m_context; 00094 00095 sigc::signal<void> m_signal_canvas_replaced; 00096 00097 void on_canvas_size_changed(); 00098 00099 void on_redraw ( double x, double y, double w, double h ); 00100 00101 bool expose_event_callback ( GdkEventExpose* e ); 00102 00103 void size_allocate_callback ( ::Gtk::Allocation& allocation ); 00104 00105 bool button_press_event_callback ( GdkEventButton* event ); 00106 00107 bool button_release_event_callback ( GdkEventButton* event ); 00108 00109 bool key_press_event_callback ( GdkEventKey* event ); 00110 00111 bool key_release_event_callback ( GdkEventKey* event ); 00112 00113 bool motion_notify_event_callback ( GdkEventMotion* event ); 00114 00115 bool scroll_event_callback ( GdkEventScroll* event ); 00116 00117 }; 00118 00119 } 00120 00121 } 00122 00123 #endif