core/vgui/vgui_function_tableau.cxx
Go to the documentation of this file.
00001 // This is core/vgui/vgui_function_tableau.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Philip C. Pritchett, RRG, University of Oxford
00008 // \date   25 Nov 99
00009 // \brief  See vgui_function_tableau.h for a description of this file.
00010 
00011 #include "vgui_function_tableau.h"
00012 #include <vgui/vgui_event.h>
00013 
00014 //----------------------------------------------------------------------------
00015 //: Constructor - don't use this, use vgui_function_tableau_new.
00016 //  Creates a default vgui_function_tableau.
00017 vgui_function_tableau::vgui_function_tableau()
00018   : draw_(0)
00019   , mouse_up_(0)
00020   , mouse_down_(0)
00021   , motion_(0)
00022   , key_press_(0)
00023   , help_(0)
00024 {
00025 }
00026 
00027 //----------------------------------------------------------------------------
00028 //: Destructor - called by vgui_function_tableau_sptr.
00029 vgui_function_tableau::~vgui_function_tableau()
00030 {
00031 }
00032 
00033 bool vgui_function_tableau::redraw = false;
00034 
00035 //----------------------------------------------------------------------------
00036 //: Handles all events by passing them to the appropriate functions.
00037 bool vgui_function_tableau::handle(const vgui_event& event)
00038 {
00039   if (event.type==vgui_DRAW && draw_)
00040   {
00041     return (*draw_)(event);
00042   }
00043   else if (event.type==vgui_BUTTON_DOWN && mouse_down_)
00044   {
00045     bool retv = (*mouse_down_)(event);
00046     if (redraw) {
00047       post_redraw();
00048       redraw = false;
00049     }
00050     return retv;
00051   }
00052   else if (event.type==vgui_BUTTON_UP && mouse_up_)
00053   {
00054     bool retv = (*mouse_up_)(event);
00055     if (redraw) {
00056       post_redraw();
00057       redraw = false;
00058     }
00059     return retv;
00060   }
00061   else if (event.type==vgui_MOTION && motion_)
00062   {
00063     bool retv = (*motion_)(event);
00064     if (redraw) {
00065       post_redraw();
00066       redraw = false;
00067     }
00068     return retv;
00069   }
00070   else if (event.type==vgui_KEY_PRESS)
00071   {
00072     if (event.key == '?' && help_)
00073       return (*help_)(event);
00074     else if (key_press_)
00075     {
00076       bool retv = (*key_press_)(event);
00077       if (redraw) {
00078         post_redraw();
00079         redraw = false;
00080       }
00081       return retv;
00082     }
00083   }
00084   return false;
00085 }
00086 
00087 bool vgui_function_tableau::draw()
00088 {
00089   if (!draw_) return false;
00090   return (*draw_)(vgui_event(vgui_DRAW));
00091 }
00092 
00093 bool vgui_function_tableau::mouse_up(int x, int y, vgui_button b, vgui_modifier m)
00094 {
00095   if (!mouse_up_) return false;
00096   vgui_event e(vgui_BUTTON_UP);
00097   e.button=b; e.modifier=m; e.wx=x; e.wy=y;
00098   return (*mouse_up_)(e);
00099 }
00100 
00101 bool vgui_function_tableau::mouse_down(int x, int y, vgui_button b, vgui_modifier m)
00102 {
00103   if (!mouse_down_) return false;
00104   vgui_event e(vgui_BUTTON_DOWN);
00105   e.button=b; e.modifier=m; e.wx=x; e.wy=y;
00106   return (*mouse_down_)(e);
00107 }
00108 
00109 bool vgui_function_tableau::motion(int x, int y)
00110 {
00111   if (!motion_) return false;
00112   vgui_event e(vgui_MOTION);
00113   e.wx=x; e.wy=y;
00114   return (*motion_)(e);
00115 }
00116 
00117 bool vgui_function_tableau::key_press(int x, int y, vgui_key k, vgui_modifier m)
00118 {
00119   if (!key_press_) return false;
00120   vgui_event e(vgui_KEY_PRESS);
00121   e.wx=x; e.wy=y; e.key=k; e.modifier=m;
00122   return (*key_press_)(e);
00123 }
00124 
00125 bool vgui_function_tableau::help()
00126 {
00127   if (!help_) return false;
00128   return (*help_)(vgui_event(vgui_KEY_PRESS));
00129 }