core/vgui/vgui_function_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_function_tableau.h
00002 #ifndef vgui_function_tableau_h_
00003 #define vgui_function_tableau_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief  Tableau where functions passed in are called for various events.
00010 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
00011 // \date   25 Nov 99
00012 //
00013 //  Contains class  vgui_function_tableau
00014 //
00015 // \verbatim
00016 //  Modifications
00017 //   25-NOV-1999 P.Pritchett - Initial version.
00018 //   02-OCT-2002 K.Y.McGaul - Added vgui_function_tableau_new.
00019 //                          - Added comments for the functions.
00020 //   14-OCT-2003 P.Vanroose - Added implementation for 5 missing tableau virtuals
00021 // \endverbatim
00022 
00023 #include <vgui/vgui_tableau.h>
00024 #include "vgui_function_tableau_sptr.h"
00025 #include "dll.h"
00026 
00027 //:  Tableau where functions passed in are called for various events.
00028 //
00029 //   For example, you can pass in my_draw_function() to draw() and
00030 //   it will be called every time a draw event occurs in this tableau.
00031 class vgui_function_tableau : public vgui_tableau
00032 {
00033  public:
00034   typedef bool (*function)(const vgui_event&);
00035 
00036   //: Constructor - don't use this, use vgui_function_tableau_new.
00037   //  Creates a default vgui_function tableau.
00038   vgui_function_tableau();
00039 
00040   //: Returns the type of this tableau ('vgui_function_tableau').
00041   vcl_string type_name() const { return "vgui_function_tableau"; }
00042 
00043   //: Call the given function when a draw event occurs.
00044   void draw(function f) {draw_ = f;}
00045   virtual bool draw();
00046 
00047   //: Call the given function when a mouse up event occurs.
00048   void mouse_up(function f) {mouse_up_ = f;}
00049   virtual bool mouse_up(int x, int y, vgui_button, vgui_modifier);
00050 
00051   //: Call the given function when a mouse down event occurs.
00052   void mouse_down(function f) {mouse_down_ = f;}
00053   virtual bool mouse_down(int x, int y, vgui_button, vgui_modifier);
00054 
00055   //: Call the given function when a mouse motion event occurs.
00056   void motion(function f) {motion_ = f;}
00057   virtual bool motion(int x, int y);
00058 
00059   //: Call the given function when a key is pressed by the user.
00060   void key_press(function f) {key_press_ = f;}
00061   virtual bool key_press(int x, int y, vgui_key, vgui_modifier);
00062 
00063   //: Call the given function when the '?' or 'help' key is pressed by the user.
00064   void help(function f) {help_ = f;}
00065   virtual bool help();
00066 
00067   static vgui_DLLDATA bool redraw;
00068 
00069  protected:
00070   //: Destructor - called by vgui_function_tableau_sptr.
00071  ~vgui_function_tableau();
00072 
00073   //: Handle all events by passing them to the appropriate functions.
00074   bool handle(const vgui_event&);
00075 
00076   function draw_;
00077   function mouse_up_;
00078   function mouse_down_;
00079   function motion_;
00080   function key_press_;
00081   function help_;
00082 };
00083 
00084 //: Creates a smart-pointer to a vgui_function_tableau.
00085 struct vgui_function_tableau_new : public vgui_function_tableau_sptr
00086 {
00087   //: Constructor - create a default vgui_function_tableau.
00088   vgui_function_tableau_new( )
00089     : vgui_function_tableau_sptr(new vgui_function_tableau) { }
00090 };
00091 
00092 #endif // vgui_function_tableau_h_