ec_event.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library 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 GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 /***************************************************************************
00022  * Note! FIFE event channel borrows heavily from ideas pf Guichan library  *
00023  * version 0.6                                                             *
00024  ***************************************************************************/
00025 
00026 
00027 #ifndef FIFE_EVENTCHANNEL_EVENT_H
00028 #define FIFE_EVENTCHANNEL_EVENT_H
00029 
00030 // Standard C++ library includes
00031 //
00032 #include <string>
00033 #include <sstream>
00034 
00035 // 3rd party library includes
00036 //
00037 #include <SDL.h>
00038 
00039 // FIFE includes
00040 // These includes are split up in two parts, separated by one empty line
00041 // First block: files included from the FIFE root src directory
00042 // Second block: files included from the same folder
00043 //
00044 #include "eventchannel/source/ec_ieventsource.h"
00045 
00046 namespace gcn {
00047     class Widget;
00048 }
00049 
00050 namespace FIFE {
00053     class Event {
00054     public:
00057         Event(): 
00058             m_isconsumed(false), 
00059             m_eventsource(NULL),
00060             m_timestamp(SDL_GetTicks()) {}
00061 
00064         virtual ~Event() {}
00065 
00068         virtual void consume() { m_isconsumed = true; }
00069         
00073         virtual bool isConsumed() const { return m_isconsumed; }
00074         
00077         virtual IEventSource* getSource() const { return m_eventsource; }
00078         
00081         virtual void setSource(IEventSource* source) { m_eventsource = source; }
00082         
00087         virtual gcn::Widget* getSourceWidget() const { return m_sourcewidget; }
00088         
00091         virtual void setSourceWidget(gcn::Widget* widget) { m_sourcewidget = widget; }
00092         
00095         virtual int getTimeStamp() const { return m_timestamp; }
00096         
00099         virtual void setTimeStamp(int timestamp ) { m_timestamp = timestamp; }
00100 
00103         virtual const std::string& getName() const {
00104             const static std::string eventName("Event");
00105             return eventName;
00106         }
00107 
00110         virtual std::string getAttrStr() const {
00111             std::stringstream ss;
00112             ss << "consumed = " << m_isconsumed << ", ";
00113             ss << "src = " << m_eventsource << ", ";
00114             ss << "timestamp = " << m_timestamp;
00115             return ss.str();
00116         }
00117 
00120         virtual std::string getDebugString() const { 
00121             std::stringstream ss;
00122             ss << getName() << std::endl;
00123             ss << getAttrStr() << std::endl;
00124             return ss.str();
00125         }
00126 
00127     private:
00128         bool m_isconsumed;
00129         IEventSource* m_eventsource;
00130         gcn::Widget* m_sourcewidget;
00131         int m_timestamp;
00132     };
00133 
00134 } //FIFE
00135 
00136 #endif