gfx/Viewport.hpp

Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2004
00003  * Swiss Federal Institute of Technology, Lausanne. All rights reserved.
00004  * 
00005  * Author: Roland Philippsen <roland dot philippsen at gmx net>
00006  *         Autonomous Systems Lab <http://asl.epfl.ch/>
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  * 
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021  * USA
00022  */
00023 
00024 
00025 #ifndef GFX_VIEWPORT_HPP
00026 #define GFX_VIEWPORT_HPP
00027 
00028 
00029 #include <gfx/Subwindow.hpp>
00030 #include <boost/shared_ptr.hpp>
00031 #include <map>
00032 #include <limits>
00033 
00034 
00035 namespace gfx {
00036   
00037   
00038   class Mousehandler;
00039   
00040   
00042   class Viewport:
00043     public Subwindow
00044   {
00045   public:
00046     typedef enum { NONE, LEFT, MIDDLE, RIGHT } button_t;
00047 
00048 
00049     Viewport(const std::string & name,
00050              logical_bbox_t realbbox,
00051              logical_bbox_t lbbox,
00052              bool enable = true,
00053              bool preserve_aspect = true,
00054              double remap_thresh = std::numeric_limits<double>::round_error());
00055 
00056     Viewport * Clone(const std::string & newname) const;
00057 
00058 
00059     virtual void PushProjection() const;
00060     virtual void PopProjection() const;
00061 
00062     void Remap(logical_bbox_t realbbox);
00063     logical_point_t PaddedScreen2Real(screen_point_t pixel) const;
00064 
00066     void SetMousehandler(button_t button,
00067                          boost::shared_ptr<Mousehandler> mousehandler);
00068 
00069 
00070   protected:
00071     virtual void PostResize();
00072     virtual void Click(int button, int state, screen_point_t mouse);
00073     virtual void Drag(screen_point_t mouse);
00074   
00075     typedef std::map<button_t, boost::shared_ptr<Mousehandler> > handler_t;
00076     handler_t m_handler;
00077     
00078     
00079   private:
00080     void CalculatePadding();
00081 
00082 
00083     const double m_remap_thresh;
00084     logical_bbox_t m_padded_sbbox;
00085     logical_point_t m_padded_ssize;
00086     logical_bbox_t m_rbbox;
00087     logical_point_t m_rsize;
00088     bool m_preserve_aspect;
00089     button_t m_lastdown;
00090   };
00091 
00092 
00094   class PassiveViewport:
00095     public Viewport
00096   {
00097   public:
00098     PassiveViewport(const std::string & name,
00099                     logical_bbox_t realbbox,
00100                     logical_bbox_t lbbox,
00101                     bool preserve_aspect,
00102                     double remap_thresh);
00103   
00104   protected:
00105     virtual void Click(int button, int state, screen_point_t mouse);  
00106   };
00107 
00108 }
00109 
00110 #endif // GFX_VIEWPORT_HPP

doxygen SourceForge.net Logo
E* Interpolated Graph Replanner Wed Dec 12 18:55:40 2007