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 gcn::Widget* getSourceWidget() { return InputEvent::getSourceWidget(); }
00133         virtual void setSourceWidget(gcn::Widget* widget) { InputEvent::setSourceWidget(widget); }
00134         virtual int getTimeStamp() const { return InputEvent::getTimeStamp(); }
00135         virtual void setTimeStamp(int timestamp ) { InputEvent::setTimeStamp(timestamp); }
00136 
00137         virtual const std::string& getName() const {
00138             const static std::string eventName("MouseEvent");
00139             return eventName;
00140         }
00141         virtual std::string getDebugString() const { return InputEvent::getDebugString(); }
00142         virtual std::string getAttrStr() const {
00143             std::stringstream ss;
00144             ss << InputEvent::getAttrStr() << std::endl;
00145             ss << "event = " << mouseEventType2str(m_eventtype) << ", ";
00146             ss << "button = " << mouseButtonType2str(m_buttontype) << ", ";
00147             ss << "x = " << m_x << ", ";
00148             ss << "y = " << m_y;
00149             return  ss.str();
00150         }
00151 
00154         inline static std::string mouseEventType2str(MouseEventType t)  {
00155             std::string s("unknown");
00156             switch (t) {
00157                 case MouseEvent::MOVED:
00158                     s = "moved";
00159                     break;
00160                 case MouseEvent::PRESSED:
00161                     s = "pressed";
00162                     break;
00163                 case MouseEvent::RELEASED:
00164                     s = "released";
00165                     break;
00166                 case MouseEvent::WHEEL_MOVED_DOWN:
00167                     s = "wheel_moved_down";
00168                     break;
00169                 case MouseEvent::WHEEL_MOVED_UP:
00170                     s = "wheel_moved_up";
00171                     break;
00172                 case MouseEvent::CLICKED:
00173                     s = "clicked";
00174                     break;
00175                 case MouseEvent::ENTERED:
00176                     s = "entered";
00177                     break;
00178                 case MouseEvent::EXITED:
00179                     s = "excited";
00180                     break;
00181                 case MouseEvent::DRAGGED:
00182                     s = "dragged";
00183                     break;
00184                 default:
00185                     break;
00186             }
00187             return s;
00188         }
00189     
00192         inline static std::string mouseButtonType2str(MouseButtonType t) {
00193             std::string s("unknown");
00194             switch (t) {
00195                 case MouseEvent::EMPTY:
00196                     s = "empty";
00197                     break;
00198                 case MouseEvent::LEFT:
00199                     s = "left";
00200                     break;
00201                 case MouseEvent::RIGHT:
00202                     s = "right";
00203                     break;
00204                 case MouseEvent::MIDDLE:
00205                     s = "middle";
00206                     break;
00207                 default:
00208                     break;
00209             }
00210             return s;
00211         }
00212         
00213 
00214 
00215     private:
00216         MouseEventType m_eventtype;
00217         MouseButtonType m_buttontype;
00218         int m_x;
00219         int m_y;
00220         
00221     };
00222     
00223 } //FIFE
00224 
00225 #endif