00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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