Gel2D - The free/open source game creation suite

gelEvent.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 2011 Mark D. Procarione
00004 
00005 Gel2D is free software: you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation, either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 Gel2D is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __GELEVENT_H__
00017 #define __GELEVENT_H__
00018 
00019 #include "gelNamespace.h"
00020 #include "gelSize.h"
00021 #include "gelLinkedList.h"
00022 
00023 namespace gel
00024 {
00026 
00030     class GelEvent
00031     {
00032         public:
00034 
00035             GelEvent( EventType tp ) : type(tp), acc(true) {}
00036 
00038             virtual ~GelEvent() {};
00039 
00041             EventType getType() const { return type; }
00042 
00044             bool isAccepted() const { return acc; }
00045 
00047             void accept() { acc = true; }
00048 
00050             void ignore() { acc = false; }
00051 
00052         protected:
00054             EventType type;
00056             bool acc;
00057     };
00058 
00060     class GelResizeEvent : public GelEvent
00061     {
00062         public:
00064 
00066             GelResizeEvent( GelSize olds, GelSize news );
00067 
00069             GelSize getSize() const { return size; }
00070 
00072             GelSize getOldSize() const { return oldsize; }
00073 
00074         private:
00075             GelSize oldsize;
00076             GelSize size;
00077     };
00078 
00080     class GelKeyEvent : public GelEvent
00081     {
00082         public:
00084 
00088             GelKeyEvent( EventType tp, Key ky, int ch, KeyModifier modifiers );
00089 
00091             Key getKey() const { return key; }
00092 
00094 
00096             int getChar() const { return character; }
00097 
00099             KeyModifier getModifiers() const { return mods; }
00100 
00101         private:
00102             Key key;
00103             KeyModifier mods;
00104             int character;
00105     };
00106 
00108     class GelMouseEvent : public GelEvent
00109     {
00110         public:
00112 
00120             GelMouseEvent( EventType tp, MouseButton btn, MouseButton btns, GelPoint mpos, int whl, KeyModifier modifiers );
00121 
00123             MouseButton getButton() const { return button; }
00124 
00126             MouseButton getButtons() const { return buttons; }
00127 
00129 
00131             int getWheelDelta() const { return wheel; }
00132 
00134             GelPoint getCursorPos() const { return pos; }
00135 
00137             KeyModifier getModifiers() const { return mods; }
00138 
00139         private:
00140             MouseButton button;
00141             MouseButton buttons;
00142             KeyModifier mods;
00143             int wheel;
00144             GelPoint pos;
00145     };
00146 
00148 
00149     class GelEventReceiver
00150     {
00151         public:
00153 
00154             GelEventReceiver();
00155 
00157 
00158             virtual ~GelEventReceiver();
00159 
00160             virtual bool onEvent( GelEvent *event );
00161 
00162             virtual void mousePressEvent( GelMouseEvent *event ) {};
00163             virtual void mouseReleaseEvent( GelMouseEvent *event ) {};
00164             virtual void mouseDblClkEvent( GelMouseEvent *event ) {};
00165             virtual void mouseWheelEvent( GelMouseEvent *event ) {};
00166             virtual void mouseMoveEvent( GelMouseEvent *event ) {};
00167             virtual void keyPressEvent( GelKeyEvent *event ) {};
00168             virtual void keyReleaseEvent( GelKeyEvent *event ) {};
00169             virtual void resizeEvent( GelResizeEvent *event ) {};
00170             virtual void closeEvent( GelEvent *event ) {};
00171             virtual void otherEvent( GelEvent *event ) {};
00172 
00173         private:
00174             int ID;
00175     };
00176 
00178 
00180     class GelEventDispatcher
00181     {
00182         public:
00184 
00187             static int addReceiver( GelEventReceiver *receiver );
00188 
00190 
00192             static void removeReceiver( int index );
00193 
00195 
00196             static void sendEvent( GelEvent *event );
00197 
00198         private:
00199             static GelLinkedList<GelEventReceiver*> elist;
00200     };
00201 }
00202 
00203 #endif // __GELEVENT_H__