| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
#ifndef FIFE_EVENTCHANNEL_INPUTEVENT_H |
| 23 |
#define FIFE_EVENTCHANNEL_INPUTEVENT_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
// |
| 27 |
|
| 28 |
// 3rd party library includes |
| 29 |
// |
| 30 |
|
| 31 |
// FIFE includes |
| 32 |
// These includes are split up in two parts, separated by one empty line |
| 33 |
// First block: files included from the FIFE root src directory |
| 34 |
// Second block: files included from the same folder |
| 35 |
// |
| 36 |
#include "event.h" |
| 37 |
|
| 38 |
namespace FIFE { |
| 39 |
|
| 40 |
/** Base class for input events (like mouse and keyboard) |
| 41 |
*/ |
| 42 |
class InputEvent: public Event { |
| 43 |
public: |
| 44 |
/** Constructor. |
| 45 |
*/ |
| 46 |
InputEvent(): |
| 47 |
Event(), |
| 48 |
m_consumedByWidgets(false), |
| 49 |
m_isShiftPressed(false), |
| 50 |
m_isControlPressed(false), |
| 51 |
m_isAltPressed(false), |
| 52 |
m_isMetaPressed(false) {} |
| 53 |
|
| 54 |
/** Destructor. |
| 55 |
*/ |
| 56 |
~InputEvent() {} |
| 57 |
|
| 58 |
/** Checks whether alt is pressed. |
| 59 |
*/ |
| 60 |
virtual bool isAltPressed() const { return m_isAltPressed; } |
| 61 |
|
| 62 |
/** Sets alt to pressed. |
| 63 |
*/ |
| 64 |
virtual void setAltPressed(bool pressed) { m_isAltPressed = pressed; } |
| 65 |
|
| 66 |
/** Checks whether control is pressed. |
| 67 |
*/ |
| 68 |
virtual bool isControlPressed() const { return m_isControlPressed; } |
| 69 |
|
| 70 |
/** Sets control to pressed. |
| 71 |
*/ |
| 72 |
virtual void setControlPressed(bool pressed) { m_isControlPressed = pressed; } |
| 73 |
|
| 74 |
/** Checks whether meta is pressed. |
| 75 |
*/ |
| 76 |
virtual bool isMetaPressed() const { return m_isMetaPressed; } |
| 77 |
|
| 78 |
/** Sets meta to pressed. |
| 79 |
*/ |
| 80 |
virtual void setMetaPressed(bool pressed) { m_isMetaPressed = pressed; } |
| 81 |
|
| 82 |
/** Checks whether shift is pressed. |
| 83 |
*/ |
| 84 |
virtual bool isShiftPressed() const { return m_isShiftPressed; } |
| 85 |
|
| 86 |
/** Sets shift to pressed. |
| 87 |
*/ |
| 88 |
virtual void setShiftPressed(bool pressed) { m_isShiftPressed = pressed; } |
| 89 |
|
| 90 |
/** Marks events as consumed by widget library. |
| 91 |
*/ |
| 92 |
virtual void consumedByWidgets() { m_consumedByWidgets = true; } |
| 93 |
|
| 94 |
/** Checks whether event is consumed by widget library. |
| 95 |
*/ |
| 96 |
virtual bool isConsumedByWidgets() const { return m_consumedByWidgets; } |
| 97 |
|
| 98 |
/** Marks events as consumed. |
| 99 |
*/ |
| 100 |
virtual void consume() { Event::consume(); } |
| 101 |
|
| 102 |
/** Checks whether event is consumed. |
| 103 |
*/ |
| 104 |
virtual bool isConsumed() const { return Event::isConsumed(); } |
| 105 |
|
| 106 |
/** Gets the source of the event. |
| 107 |
*/ |
| 108 |
virtual IEventSource* getSource() const { return Event::getSource(); } |
| 109 |
|
| 110 |
/** Sets the source of the event. |
| 111 |
*/ |
| 112 |
virtual void setSource(IEventSource* source) { Event::setSource(source); } |
| 113 |
|
| 114 |
/** Gets the timestamp of the event. |
| 115 |
*/ |
| 116 |
virtual int32_t getTimeStamp() const { return Event::getTimeStamp(); } |
| 117 |
|
| 118 |
/** Sets the timestamp of the event. |
| 119 |
*/ |
| 120 |
virtual void setTimeStamp(int32_t timestamp ) { Event::setTimeStamp(timestamp); } |
| 121 |
|
| 122 |
/** Gets the name of the event. |
| 123 |
*/ |
| 124 |
virtual const std::string& getName() const { |
| 125 |
const static std::string eventName("InputEvent"); |
| 126 |
return eventName; |
| 127 |
} |
| 128 |
|
| 129 |
/** Gets the debugstring of the event. |
| 130 |
*/ |
| 131 |
virtual std::string getDebugString() const { return Event::getDebugString(); } |
| 132 |
|
| 133 |
/** Gets attribute string of the event. |
| 134 |
*/ |
| 135 |
virtual std::string getAttrStr() const { |
| 136 |
std::stringstream ss; |
| 137 |
ss << Event::getAttrStr() << std::endl; |
| 138 |
ss << "shift = " << m_isShiftPressed << ", "; |
| 139 |
ss << "ctrl = " << m_isControlPressed << ", "; |
| 140 |
ss << "alt = " << m_isAltPressed << ", "; |
| 141 |
ss << "meta = " << m_isMetaPressed; |
| 142 |
return ss.str(); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
private: |
| 147 |
bool m_consumedByWidgets; |
| 148 |
bool m_isShiftPressed; |
| 149 |
bool m_isControlPressed; |
| 150 |
bool m_isAltPressed; |
| 151 |
bool m_isMetaPressed; |
| 152 |
}; |
| 153 |
} //FIFE |
| 154 |
|
| 155 |
#endif |