FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
ec_mouseevent.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 #ifndef FIFE_EVENTCHANNEL_MOUSEEVENT_H
00023 #define FIFE_EVENTCHANNEL_MOUSEEVENT_H
00024 
00025 // Standard C++ library includes
00026 //
00027 
00028 // 3rd party library includes
00029 //
00030 
00031 // FIFE includes
00032 // These includes are split up in two parts, separated by one empty line
00033 // First block: files included from the FIFE root src directory
00034 // Second block: files included from the same folder
00035 //
00036 #include "eventchannel/base/ec_inputevent.h"
00037 
00038 namespace FIFE {
00039 
00042     class MouseEvent: public InputEvent {
00043     public:
00047         enum MouseEventType
00048         {
00049             UNKNOWN_EVENT = -1,
00050             MOVED = 0,
00051             PRESSED,
00052             RELEASED,
00053             WHEEL_MOVED_DOWN,
00054             WHEEL_MOVED_UP,
00055             CLICKED,
00056             ENTERED,
00057             EXITED,
00058             DRAGGED
00059         };
00060 
00064         enum MouseButtonType
00065         {
00066             EMPTY = 0,
00067             LEFT = 1,
00068             RIGHT = 2,
00069             MIDDLE = 4,
00070             UNKNOWN_BUTTON = 8
00071         };
00072 
00073 
00076         MouseEvent():
00077             InputEvent(),
00078             m_eventtype(UNKNOWN_EVENT),
00079             m_buttontype(UNKNOWN_BUTTON),
00080             m_x(-1),
00081             m_y(-1) {}
00082 
00085         virtual ~MouseEvent() {}
00086 
00091         MouseButtonType getButton() const { return m_buttontype; }
00092         void setButton(MouseButtonType type) { m_buttontype = type; }
00093 
00098         MouseEventType getType() const { return m_eventtype; }
00099         void setType(MouseEventType type) { m_eventtype = type; }
00100 
00106         int getX() const { return m_x; }
00107         void setX(int x) { m_x = x; }
00108 
00114         int getY() const { return m_y; }
00115         void setY(int y) { m_y = y; }
00116 
00117         virtual bool isAltPressed() const { return InputEvent::isAltPressed(); }
00118         virtual void setAltPressed(bool pressed) { InputEvent::setAltPressed(pressed); }
00119         virtual bool isControlPressed() const { return InputEvent::isControlPressed(); }
00120         virtual void setControlPressed(bool pressed) { InputEvent::setControlPressed(pressed); }
00121         virtual bool isMetaPressed() const { return InputEvent::isMetaPressed(); }
00122         virtual void setMetaPressed(bool pressed) { InputEvent::setMetaPressed(pressed); }
00123         virtual bool isShiftPressed() const { return InputEvent::isShiftPressed(); }
00124         virtual void setShiftPressed(bool pressed) { InputEvent::setShiftPressed(pressed); }
00125 
00126         virtual void consume() { InputEvent::consume(); }
00127         virtual bool isConsumed() const { return InputEvent::isConsumed(); }
00128         virtual void consumedByWidgets() { InputEvent::consumedByWidgets(); }
00129         virtual bool isConsumedByWidgets() const { return InputEvent::isConsumedByWidgets(); }
00130         virtual IEventSource* getSource() { return InputEvent::getSource(); }
00131         virtual void setSource(IEventSource* source) { InputEvent::setSource(source); }
00132         virtual int getTimeStamp() const { return InputEvent::getTimeStamp(); }
00133         virtual void setTimeStamp(int timestamp ) { InputEvent::setTimeStamp(timestamp); }
00134 
00135         virtual const std::string& getName() const {
00136             const static std::string eventName("MouseEvent");
00137             return eventName;
00138         }
00139         virtual std::string getDebugString() const { return InputEvent::getDebugString(); }
00140         virtual std::string getAttrStr() const {
00141             std::stringstream ss;
00142             ss << InputEvent::getAttrStr() << std::endl;
00143             ss << "event = " << mouseEventType2str(m_eventtype) << ", ";
00144             ss << "button = " << mouseButtonType2str(m_buttontype) << ", ";
00145             ss << "x = " << m_x << ", ";
00146             ss << "y = " << m_y;
00147             return  ss.str();
00148         }
00149 
00152         inline static std::string mouseEventType2str(MouseEventType t)  {
00153             std::string s("unknown");
00154             switch (t) {
00155                 case MouseEvent::MOVED:
00156                     s = "moved";
00157                     break;
00158                 case MouseEvent::PRESSED:
00159                     s = "pressed";
00160                     break;
00161                 case MouseEvent::RELEASED:
00162                     s = "released";
00163                     break;
00164                 case MouseEvent::WHEEL_MOVED_DOWN:
00165                     s = "wheel_moved_down";
00166                     break;
00167                 case MouseEvent::WHEEL_MOVED_UP:
00168                     s = "wheel_moved_up";
00169                     break;
00170                 case MouseEvent::CLICKED:
00171                     s = "clicked";
00172                     break;
00173                 case MouseEvent::ENTERED:
00174                     s = "entered";
00175                     break;
00176                 case MouseEvent::EXITED:
00177                     s = "excited";
00178                     break;
00179                 case MouseEvent::DRAGGED:
00180                     s = "dragged";
00181                     break;
00182                 default:
00183                     break;
00184             }
00185             return s;
00186         }
00187 
00190         inline static std::string mouseButtonType2str(MouseButtonType t) {
00191             std::string s("unknown");
00192             switch (t) {
00193                 case MouseEvent::EMPTY:
00194                     s = "empty";
00195                     break;
00196                 case MouseEvent::LEFT:
00197                     s = "left";
00198                     break;
00199                 case MouseEvent::RIGHT:
00200                     s = "right";
00201                     break;
00202                 case MouseEvent::MIDDLE:
00203                     s = "middle";
00204                     break;
00205                 default:
00206                     break;
00207             }
00208             return s;
00209         }
00210 
00211 
00212 
00213     private:
00214         MouseEventType m_eventtype;
00215         MouseButtonType m_buttontype;
00216         int m_x;
00217         int m_y;
00218 
00219     };
00220 
00221 } //FIFE
00222 
00223 #endif