papyrus logo

event.h

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

Generated on Wed Mar 18 12:34:03 2009 for papyrus by doxygen 1.5.7.1