core/vgui/vgui_viewer2D_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_viewer2D_tableau.h
00002 #ifndef vgui_viewer2D_tableau_h_
00003 #define vgui_viewer2D_tableau_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
00010 // \date   14 Sep 99
00011 // \brief  Tableau with functions to view 2D objects (eg, zoom, drag, centre).
00012 //
00013 //  Contains classes:  vgui_viewer2D_tableau  vgui_viewer2D_tableau_new
00014 //
00015 // \verbatim
00016 //  Modifications
00017 //    23-AUG-2000 Marko Bacic, Oxford RRG -- Added support for scroll bars
00018 //    07-AUG-2002 K.Y.McGaul - Changed to and added Doxygen style comments.
00019 //    01-OCT-2002 K.Y.McGaul - Moved vgui_viewer2D to vgui_viewer2D_tableau.
00020 //    23-DEC-2002 J.L. Mundy - Modified scrollbar support to reflect scale
00021 //                             and centering.
00022 // \endverbatim
00023 
00024 #include <vgui/vgui_drag_mixin.h>
00025 #include <vgui/vgui_wrapper_tableau.h>
00026 #include <vgui/vgui_viewer2D_tableau_sptr.h>
00027 
00028 #include "dll.h"
00029 
00030 //: Tableau with functions to view 2D objects (eg, zoom, drag, centre).
00031 class vgui_viewer2D_tableau : public vgui_wrapper_tableau, public vgui_drag_mixin
00032 {
00033  public:
00034   //: Constructor - don't use this, use vgui_viewer2D_tableau_new.
00035   //  Takes a child tableau as parameter.
00036   vgui_viewer2D_tableau(vgui_tableau_sptr const&);
00037 
00038   //: Handle all events sent to this tableau.
00039   //  In particular, uses gestures from the user to zoom, drag and centre
00040   //  the display.
00041   virtual bool handle(const vgui_event& event);
00042 
00043   //: Returns the type of this tableau ('vgui_viewer2D_tableau').
00044   virtual vcl_string type_name() const;
00045 
00046   //: Set the correct projection matrix for GL (take account of zoom, drag etc).
00047   void setup_gl_matrices();
00048 
00049   //: Modify the token to zoom in by the given factor, about the given (x,y).
00050   //  (x, y) are in viewport coordinates.
00051   void zoomin(float zoom_factor, int x, int y);
00052 
00053   //: Modify the token to zoom out by the given factor, about the given (x,y).
00054   //  (x, y) are in viewport coordinates.
00055   void zoomout(float zoom_factor, int x, int y);
00056 
00057   //: Centre the image with the given width and height inside the tableau.
00058   void center_image(int w, int h);
00059 
00060   //: Find the image (if it exists) and center it inside the tableau.
00061   void center_event();
00062 
00063   //: Called when the user presses a mouse button in the rendering area.
00064   bool mouse_down(int x, int y, vgui_button button, vgui_modifier modifier);
00065 
00066   //: Called when the user drags a mouse inside the rendering area.
00067   bool mouse_drag(int x, int y,  vgui_button button, vgui_modifier modifier);
00068 
00069   //: Called when the user releases a mouse button in the rendering area.
00070   bool mouse_up(int x, int y,  vgui_button button, vgui_modifier modifier);
00071 
00072   //: Called when the user presses the '?' key.
00073   bool help();
00074 
00075   //: Called when the user presses a key.
00076   bool key_press(int x, int y, vgui_key key, vgui_modifier);
00077 
00078   //: Data on the current state of vgui_viewer2D_tableau (eg the amount we are zoomed).
00079   struct token_t
00080   {
00081     float scaleX;
00082     float scaleY;
00083     float offsetX;
00084     float offsetY;
00085     token_t() : scaleX(1.0f), scaleY(1.0f), offsetX(0.0f), offsetY(0.0f) { }
00086   } token;
00087 
00088   // static data
00089   static vgui_DLLDATA const void * const CENTER_EVENT;
00090 
00091 
00092   bool nice_points;
00093   bool nice_lines;
00094 
00095   enum {normal_zoom, smooth_zoom} zoom_type;
00096 
00097   bool panning;
00098   bool smooth_zooming;
00099   bool sweep_zooming;
00100   bool sweep_next;
00101   float prev_x,prev_y;
00102   float zoom_x,zoom_y;
00103   float new_x,new_y;
00104   float zoom_factor;
00105   int npos_x;
00106   int npos_y;
00107  protected:
00108   //:get the image size
00109   bool image_size(int& width, int& height);
00110 
00111   //: Destructor - called by vgui_viewer2D_tableau_sptr.
00112  ~vgui_viewer2D_tableau();
00113 };
00114 
00115 //: Create a smart-pointer to a vgui_viewer2D_tableau tableau.
00116 struct vgui_viewer2D_tableau_new : public vgui_viewer2D_tableau_sptr
00117 {
00118   //: Create a smart-pointer to a vgui_viewer2D_tableau tableau.
00119   //  Takes a child tableau as parameter.
00120   vgui_viewer2D_tableau_new(vgui_tableau_sptr const& that) :
00121     vgui_viewer2D_tableau_sptr(new vgui_viewer2D_tableau(that)) { }
00122 };
00123 
00124 #endif // vgui_viewer2D_tableau_h_