event.h

00001 /***************************************************************************
00002 *   Copyright (C) 2004 by Rick L. Vinyard, Jr.                            *
00003 *   rvinyard@cs.nmsu.edu                                                  *
00004 *                                                                         *
00005 *   This program is free software; you can redistribute it and/or modify  *
00006 *   it under the terms of the GNU Lesser General Public License as        *
00007 *   published by the Free Software Foundation version 2.1.                *
00008 *                                                                         *
00009 *   This program is distributed in the hope that it will be useful,       *
00010 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012 *   GNU General Public License for more details.                          *
00013 *                                                                         *
00014 *   You should have received a copy of the GNU Lesser General Public      *
00015 *   License along with this library; if not, write to the                 *
00016 *   Free Software Foundation, Inc.,                                       *
00017 *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018 ***************************************************************************/
00019 #ifndef PAPYRUSEVENT_H
00020 #define PAPYRUSEVENT_H
00021 
00022 namespace Papyrus {
00023 
00024 namespace Event {
00025 
00026   typedef enum Type {
00027     BUTTON_PRESS,
00028     BUTTON_RELEASE,
00029     BUTTON_DOUBLE_PRESS,
00030     BUTTON_TRIPLE_PRESS,
00031     SCROLL,
00032     MOTION,
00033     KEY_PRESS,
00034     KEY_RELEASE,
00035   } Type;
00036 
00037   typedef enum ScrollDirection {
00038     SCROLL_UP,
00039     SCROLL_DOWN,
00040     SCROLL_LEFT,
00041     SCROLL_RIGHT,
00042   };
00043 
00044   // These are taken straight from GDK
00045   typedef enum ModifierType
00046   {
00047     SHIFT_MASK    = 1 << 0,
00048     LOCK_MASK     = 1 << 1,
00049     CONTROL_MASK  = 1 << 2,
00050     MOD1_MASK     = 1 << 3,
00051     MOD2_MASK     = 1 << 4,
00052     MOD3_MASK     = 1 << 5,
00053     MOD4_MASK     = 1 << 6,
00054     MOD5_MASK     = 1 << 7,
00055     BUTTON1_MASK  = 1 << 8,
00056     BUTTON2_MASK  = 1 << 9,
00057     BUTTON3_MASK  = 1 << 10,
00058     BUTTON4_MASK  = 1 << 11,
00059     BUTTON5_MASK  = 1 << 12,
00060 
00061     /* The next few modifiers are used by XKB, so we skip to the end.
00062      * Bits 15 - 25 are currently unused. Bit 29 is used internally.
00063      */
00064 
00065     SUPER_MASK    = 1 << 26,
00066     HYPER_MASK    = 1 << 27,
00067     META_MASK     = 1 << 28,
00068 
00069     RELEASE_MASK  = 1 << 30,
00070 
00071     MODIFIER_MASK = 0x5c001fff
00072   } ModifierType;
00073 
00074   struct Event {
00075   Event( uint32_t t=0, unsigned s=0 ): time(t), state(s) { }
00076     virtual ~Event() { }
00077 
00078     uint32_t time;
00079     unsigned state;
00080 
00081     virtual Type type() const = 0;
00082   };
00083 
00084   struct Button: public Event {
00085   Button( uint32_t t=0, unsigned s=0, unsigned b=0, double nx=0.0, double ny=0.0 ):
00086     Event( t, s ), button(b), x(nx), y(ny) { }
00087     virtual ~Button() { }
00088 
00089     unsigned button;
00090     double x;
00091     double y;
00092   };
00093 
00094   struct ButtonPress: public Button {
00095   ButtonPress( uint32_t t=0, unsigned s=0, unsigned b=0, double nx=0.0, double ny=0.0 ):
00096         Button( t, s, b, nx, ny) { }
00097     virtual ~ButtonPress() { }
00098 
00099     virtual Type type() const { return BUTTON_PRESS; }
00100   };
00101 
00102   struct ButtonRelease: public Button {
00103   ButtonRelease( uint32_t t=0, unsigned s=0, unsigned b=0, double nx=0.0, double ny=0.0 ):
00104         Button( t, s, b, nx, ny) { }
00105     virtual ~ButtonRelease() { }
00106 
00107     virtual Type type() const { return BUTTON_RELEASE; }
00108   };
00109 
00110   struct ButtonDoublePress: public Button {
00111   ButtonDoublePress( uint32_t t=0, unsigned s=0, unsigned b=0, double nx=0.0, double ny=0.0 ):
00112         Button( t, s, b, nx, ny) { }
00113 
00114     virtual ~ButtonDoublePress() { }
00115 
00116     virtual Type type() const { return BUTTON_DOUBLE_PRESS; }
00117   };
00118 
00119   struct ButtonTriplePress: public Button {
00120   ButtonTriplePress( uint32_t t=0, unsigned s=0, unsigned b=0, double nx=0.0, double ny=0.0 ):
00121         Button( t, s, b, nx, ny) { }
00122 
00123     virtual ~ButtonTriplePress() { }
00124 
00125     virtual Type type() const { return BUTTON_TRIPLE_PRESS; }
00126   };
00127 
00128   struct Scroll: public Event {
00129   Scroll( uint32_t t=0, unsigned s=0, ScrollDirection d=SCROLL_UP, double nx=0, double ny=0 ):
00130     Event(t, s), direction(d), x(nx), y(ny) { }
00131 
00132     virtual ~Scroll() { }
00133 
00134     ScrollDirection direction;
00135     double x;
00136     double y;
00137 
00138     virtual Type type() const { return SCROLL; }
00139   };
00140 
00141   struct Motion: public Event {
00142   Motion( uint32_t t=0, unsigned s=0, double nx=0.0, double ny=0.0 ):
00143     Event(t, s), x(nx), y(ny) { }
00144 
00145     virtual ~Motion() { }
00146 
00147     double x;
00148     double y;
00149 
00150     virtual Type type() const { return MOTION; }
00151   };
00152 
00153   struct Key: public Event {
00154   Key( uint32_t t=0, unsigned s=0, unsigned k=0, uint16_t hc=0, uint8_t kg=0 ):
00155         Event(t, s), key(k), hardware_code(hc), keyboard_group(kg) { }
00156 
00157     virtual ~Key() { }
00158 
00159     unsigned key;
00160     uint16_t hardware_code;
00161     uint8_t keyboard_group;
00162   };
00163 
00164   struct KeyPress: public Key {
00165   KeyPress( uint32_t t=0, unsigned s=0, unsigned k=0, uint16_t hc=0, uint8_t kg=0 ):
00166         Key( t, s, k, hc, kg) { }
00167 
00168     virtual ~KeyPress() { }
00169 
00170     virtual Type type() const { return KEY_PRESS; }
00171   };
00172 
00173   struct KeyRelease: public Key {
00174   KeyRelease( uint32_t t=0, unsigned s=0, unsigned k=0, uint16_t hc=0, uint8_t kg=0 ):
00175         Key( t, s, k, hc, kg) { }
00176 
00177     virtual ~KeyRelease() { }
00178 
00179     virtual Type type() const { return KEY_RELEASE; }
00180   };
00181 
00182 }
00183 
00184 }
00185 
00186 #endif

Generated on Sun Mar 11 10:01:28 2007 by  doxygen 1.5.1