| 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 |
%module fife |
| 23 |
%{ |
| 24 |
#include "eventchannel/base/event.h" |
| 25 |
#include "eventchannel/base/inputevent.h" |
| 26 |
#include "eventchannel/command/command.h" |
| 27 |
#include "eventchannel/command/commandids.h" |
| 28 |
#include "eventchannel/command/icommandlistener.h" |
| 29 |
#include "eventchannel/drop/dropevent.h" |
| 30 |
#include "eventchannel/drop/idroplistener.h" |
| 31 |
#include "eventchannel/joystick/joystick.h" |
| 32 |
#include "eventchannel/joystick/joystickevent.h" |
| 33 |
#include "eventchannel/joystick/ijoysticklistener.h" |
| 34 |
#include "eventchannel/key/key.h" |
| 35 |
#include "eventchannel/key/keyevent.h" |
| 36 |
#include "eventchannel/key/ikeylistener.h" |
| 37 |
#include "eventchannel/key/ikeyfilter.h" |
| 38 |
#include "eventchannel/text/text.h" |
| 39 |
#include "eventchannel/text/textevent.h" |
| 40 |
#include "eventchannel/text/itextlistener.h" |
| 41 |
#include "eventchannel/source/eventsourcetypes.h" |
| 42 |
#include "eventchannel/source/ieventsource.h" |
| 43 |
#include "eventchannel/mouse/mouseevent.h" |
| 44 |
#include "eventchannel/mouse/imouselistener.h" |
| 45 |
#include "eventchannel/sdl/isdleventlistener.h" |
| 46 |
#include "eventchannel/eventmanager.h" |
| 47 |
%} |
| 48 |
|
| 49 |
%include "eventchannel/key/key.h" |
| 50 |
%include "eventchannel/text/text.h" |
| 51 |
%include "eventchannel/source/eventsourcetypes.h" |
| 52 |
%include "eventchannel/command/commandids.h" |
| 53 |
|
| 54 |
namespace FIFE { |
| 55 |
%feature("director") IEventSource; |
| 56 |
class IEventSource { |
| 57 |
public: |
| 58 |
virtual EventSourceType getEventSourceType() = 0; |
| 59 |
virtual ~IEventSource(); |
| 60 |
}; |
| 61 |
|
| 62 |
class Event { |
| 63 |
public: |
| 64 |
virtual void consume(); |
| 65 |
virtual bool isConsumed() const; |
| 66 |
virtual IEventSource* getSource(); |
| 67 |
virtual int32_t getTimeStamp() const; |
| 68 |
virtual std::string getDebugString() const; |
| 69 |
virtual const std::string& getName() const; |
| 70 |
virtual ~Event() {} |
| 71 |
private: |
| 72 |
Event(); |
| 73 |
}; |
| 74 |
|
| 75 |
class InputEvent: public Event { |
| 76 |
public: |
| 77 |
virtual bool isConsumedByWidgets() const; |
| 78 |
virtual bool isAltPressed() const; |
| 79 |
virtual bool isControlPressed() const; |
| 80 |
virtual bool isMetaPressed() const; |
| 81 |
virtual bool isShiftPressed() const; |
| 82 |
virtual ~InputEvent() {} |
| 83 |
private: |
| 84 |
InputEvent(); |
| 85 |
}; |
| 86 |
|
| 87 |
class Command: public Event { |
| 88 |
public: |
| 89 |
Command(); |
| 90 |
virtual ~Command(); |
| 91 |
|
| 92 |
CommandType getCommandType(); |
| 93 |
void setCommandType(CommandType type); |
| 94 |
|
| 95 |
int32_t getCode() const; |
| 96 |
void setCode(int32_t code); |
| 97 |
|
| 98 |
virtual void setSource(IEventSource* source); |
| 99 |
virtual void setTimeStamp(int32_t timestamp); |
| 100 |
}; |
| 101 |
|
| 102 |
%feature("director") ICommandListener; |
| 103 |
class ICommandListener { |
| 104 |
public: |
| 105 |
virtual void onCommand(Command& command) = 0; |
| 106 |
virtual ~ICommandListener() {} |
| 107 |
}; |
| 108 |
|
| 109 |
class KeyEvent: public InputEvent { |
| 110 |
public: |
| 111 |
enum KeyEventType { |
| 112 |
UNKNOWN = -1, |
| 113 |
PRESSED = 0, |
| 114 |
RELEASED |
| 115 |
}; |
| 116 |
virtual KeyEventType getType() const; |
| 117 |
virtual bool isNumericPad() const; |
| 118 |
virtual const Key& getKey() const; |
| 119 |
virtual ~KeyEvent(); |
| 120 |
private: |
| 121 |
KeyEvent(); |
| 122 |
}; |
| 123 |
|
| 124 |
%feature("director") IKeyListener; |
| 125 |
class IKeyListener { |
| 126 |
public: |
| 127 |
virtual void keyPressed(KeyEvent& evt) = 0; |
| 128 |
virtual void keyReleased(KeyEvent& evt) = 0; |
| 129 |
virtual bool isGlobalListener() const; |
| 130 |
virtual void setGlobalListener(bool global); |
| 131 |
virtual ~IKeyListener(); |
| 132 |
}; |
| 133 |
|
| 134 |
class TextEvent: public InputEvent { |
| 135 |
public: |
| 136 |
enum TextEventType { |
| 137 |
UNKNOWN = 0, |
| 138 |
INPUT = 1, |
| 139 |
EDIT = 2 |
| 140 |
}; |
| 141 |
virtual TextEventType getType() const; |
| 142 |
virtual const Text& getText() const; |
| 143 |
virtual ~TextEvent(); |
| 144 |
private: |
| 145 |
TextEvent(); |
| 146 |
}; |
| 147 |
|
| 148 |
%feature("director") ITextListener; |
| 149 |
class ITextListener { |
| 150 |
public: |
| 151 |
virtual void textInput(TextEvent& evt) = 0; |
| 152 |
virtual void textEdit(TextEvent& evt) = 0; |
| 153 |
virtual ~ITextListener(); |
| 154 |
}; |
| 155 |
|
| 156 |
%feature("director") ISdlEventListener; |
| 157 |
class ISdlEventListener { |
| 158 |
public: |
| 159 |
virtual bool onSdlEvent(SDL_Event& evt) = 0; |
| 160 |
virtual ~ISdlEventListener(); |
| 161 |
}; |
| 162 |
|
| 163 |
class MouseEvent: public InputEvent { |
| 164 |
public: |
| 165 |
enum MouseEventType { |
| 166 |
UNKNOWN_EVENT = -1, |
| 167 |
MOVED = 0, |
| 168 |
PRESSED, |
| 169 |
RELEASED, |
| 170 |
WHEEL_MOVED_DOWN, |
| 171 |
WHEEL_MOVED_UP, |
| 172 |
WHEEL_MOVED_RIGHT, |
| 173 |
WHEEL_MOVED_LEFT, |
| 174 |
CLICKED, |
| 175 |
ENTERED, |
| 176 |
EXITED, |
| 177 |
DRAGGED |
| 178 |
}; |
| 179 |
|
| 180 |
enum MouseButtonType { |
| 181 |
EMPTY = 0, |
| 182 |
LEFT = 1, |
| 183 |
RIGHT = 2, |
| 184 |
MIDDLE = 4, |
| 185 |
X1 = 8, |
| 186 |
X2 = 16, |
| 187 |
UNKNOWN_BUTTON = 32 |
| 188 |
}; |
| 189 |
virtual int32_t getX() const; |
| 190 |
virtual int32_t getY() const; |
| 191 |
virtual MouseEventType getType() const; |
| 192 |
virtual MouseButtonType getButton() const; |
| 193 |
virtual ~MouseEvent(); |
| 194 |
private: |
| 195 |
MouseEvent(); |
| 196 |
}; |
| 197 |
|
| 198 |
%feature("director") IMouseListener; |
| 199 |
class IMouseListener { |
| 200 |
public: |
| 201 |
virtual void mouseEntered(MouseEvent& evt) = 0; |
| 202 |
virtual void mouseExited(MouseEvent& evt) = 0; |
| 203 |
virtual void mousePressed(MouseEvent& evt) = 0; |
| 204 |
virtual void mouseReleased(MouseEvent& evt) = 0; |
| 205 |
virtual void mouseClicked(MouseEvent& evt) = 0; |
| 206 |
virtual void mouseWheelMovedUp(MouseEvent& evt) = 0; |
| 207 |
virtual void mouseWheelMovedDown(MouseEvent& evt) = 0; |
| 208 |
virtual void mouseWheelMovedRight(MouseEvent& evt) = 0; |
| 209 |
virtual void mouseWheelMovedLeft(MouseEvent& evt) = 0; |
| 210 |
virtual void mouseMoved(MouseEvent& evt) = 0; |
| 211 |
virtual void mouseDragged(MouseEvent& evt) = 0; |
| 212 |
virtual bool isGlobalListener() const; |
| 213 |
virtual void setGlobalListener(bool global); |
| 214 |
virtual ~IMouseListener(); |
| 215 |
}; |
| 216 |
|
| 217 |
%feature("director") IKeyFilter; |
| 218 |
class IKeyFilter { |
| 219 |
public: |
| 220 |
virtual bool isFiltered(const KeyEvent& evt) = 0; |
| 221 |
virtual ~IKeyFilter(); |
| 222 |
}; |
| 223 |
|
| 224 |
class DropEvent: public InputEvent { |
| 225 |
public: |
| 226 |
virtual const std::string& getPath() const; |
| 227 |
virtual ~DropEvent(); |
| 228 |
private: |
| 229 |
DropEvent(); |
| 230 |
}; |
| 231 |
|
| 232 |
%feature("director") IDropListener; |
| 233 |
class IDropListener { |
| 234 |
public: |
| 235 |
virtual void fileDropped(DropEvent& evt) = 0; |
| 236 |
virtual ~IDropListener(); |
| 237 |
}; |
| 238 |
|
| 239 |
class Joystick { |
| 240 |
public: |
| 241 |
enum Hat { |
| 242 |
HAT_INVALID = -1, |
| 243 |
HAT_CENTERED = 0, |
| 244 |
HAT_UP = 1, |
| 245 |
HAT_RIGHT = 2, |
| 246 |
HAT_DOWN = 4, |
| 247 |
HAT_LEFT = 8, |
| 248 |
HAT_RIGHTUP = 3, |
| 249 |
HAT_RIGHTDOWN = 6, |
| 250 |
HAT_LEFTUP = 9, |
| 251 |
HAT_LEFTDOWN = 12 |
| 252 |
}; |
| 253 |
|
| 254 |
enum ContollerAxis { |
| 255 |
CONTOLLER_AXIS_INVALID = -1, |
| 256 |
CONTOLLER_AXIS_LEFTX, |
| 257 |
CONTOLLER_AXIS_LEFTY, |
| 258 |
CONTOLLER_AXIS_RIGHTX, |
| 259 |
CONTOLLER_AXIS_RIGHTY, |
| 260 |
CONTOLLER_AXIS_TRIGGERLEFT, |
| 261 |
CONTOLLER_AXIS_TRIGGERRIGHT, |
| 262 |
CONTOLLER_AXIS_MAX |
| 263 |
}; |
| 264 |
|
| 265 |
enum ControllerButton { |
| 266 |
CONTOLLER_BUTTON_INVALID = -1, |
| 267 |
CONTOLLER_BUTTON_A, |
| 268 |
CONTOLLER_BUTTON_B, |
| 269 |
CONTOLLER_BUTTON_X, |
| 270 |
CONTOLLER_BUTTON_Y, |
| 271 |
CONTOLLER_BUTTON_BACK, |
| 272 |
CONTOLLER_BUTTON_GUIDE, |
| 273 |
CONTOLLER_BUTTON_START, |
| 274 |
CONTOLLER_BUTTON_LEFTSTICK, |
| 275 |
CONTOLLER_BUTTON_RIGHTSTICK, |
| 276 |
CONTOLLER_BUTTON_LEFTSHOULDER, |
| 277 |
CONTOLLER_BUTTON_RIGHTSHOULDER, |
| 278 |
CONTOLLER_BUTTON_DPAD_UP, |
| 279 |
CONTOLLER_BUTTON_DPAD_DOWN, |
| 280 |
CONTOLLER_BUTTON_DPAD_LEFT, |
| 281 |
CONTOLLER_BUTTON_DPAD_RIGHT, |
| 282 |
CONTOLLER_BUTTON_MAX |
| 283 |
}; |
| 284 |
|
| 285 |
~Joystick(); |
| 286 |
|
| 287 |
int32_t getDeviceIndex() const; |
| 288 |
int32_t getInstanceId() const; |
| 289 |
std::string getGuid(); |
| 290 |
std::string getName(); |
| 291 |
|
| 292 |
bool isConnected() const; |
| 293 |
bool isController() const; |
| 294 |
|
| 295 |
uint8_t getNumberOfAxes() const; |
| 296 |
uint8_t getNumberOfButtons() const; |
| 297 |
uint8_t getNumberOfHats() const; |
| 298 |
float getAxisValue(int8_t axis) const; |
| 299 |
int8_t getHatValue(int8_t hat) const; |
| 300 |
bool isButtonPressed(int8_t button) const; |
| 301 |
|
| 302 |
private: |
| 303 |
Joystick(int32_t joystickId, int32_t deviceIndex); |
| 304 |
}; |
| 305 |
|
| 306 |
class JoystickEvent: public InputEvent { |
| 307 |
public: |
| 308 |
enum JoystickEventType { |
| 309 |
UNKNOWN_EVENT = 0, |
| 310 |
AXIS_MOTION, |
| 311 |
HAT_MOTION, |
| 312 |
BUTTON_PRESSED, |
| 313 |
BUTTON_RELEASED, |
| 314 |
DEVICE_ADDED, |
| 315 |
DEVICE_REMOVED |
| 316 |
}; |
| 317 |
JoystickEventType getType() const; |
| 318 |
int32_t getInstanceId() const; |
| 319 |
int8_t getAxis() const; |
| 320 |
float getAxisValue() const; |
| 321 |
int8_t getHat() const; |
| 322 |
int8_t getHatValue() const; |
| 323 |
int8_t getButton() const; |
| 324 |
bool isController() const; |
| 325 |
virtual ~JoystickEvent(); |
| 326 |
private: |
| 327 |
JoystickEvent(); |
| 328 |
}; |
| 329 |
|
| 330 |
%feature("director") IJoystickListener; |
| 331 |
class IJoystickListener { |
| 332 |
public: |
| 333 |
virtual void axisMotion(JoystickEvent& evt) = 0; |
| 334 |
virtual void hatMotion(JoystickEvent& evt) = 0; |
| 335 |
virtual void buttonPressed(JoystickEvent& evt) = 0; |
| 336 |
virtual void buttonReleased(JoystickEvent& evt) = 0; |
| 337 |
virtual void deviceAdded(JoystickEvent& evt) = 0; |
| 338 |
virtual void deviceRemoved(JoystickEvent& evt) = 0; |
| 339 |
virtual ~IJoystickListener(); |
| 340 |
}; |
| 341 |
|
| 342 |
class EventManager { |
| 343 |
public: |
| 344 |
EventManager(); |
| 345 |
virtual ~EventManager(); |
| 346 |
void addCommandListener(ICommandListener* listener); |
| 347 |
void addCommandListenerFront(ICommandListener* listener); |
| 348 |
void removeCommandListener(ICommandListener* listener); |
| 349 |
void addKeyListener(IKeyListener* listener); |
| 350 |
void addKeyListenerFront(IKeyListener* listener); |
| 351 |
void removeKeyListener(IKeyListener* listener); |
| 352 |
void addTextListener(ITextListener* listener); |
| 353 |
void addTextListenerFront(ITextListener* listener); |
| 354 |
void removeTextListener(ITextListener* listener); |
| 355 |
void addMouseListener(IMouseListener* listener); |
| 356 |
void addMouseListenerFront(IMouseListener* listener); |
| 357 |
void removeMouseListener(IMouseListener* listener); |
| 358 |
void addDropListener(IDropListener* listener); |
| 359 |
void addDropListenerFront(IDropListener* listener); |
| 360 |
void removeDropListener(IDropListener* listener); |
| 361 |
void addJoystickListener(IJoystickListener* listener); |
| 362 |
void addJoystickListenerFront(IJoystickListener* listener); |
| 363 |
void removeJoystickListener(IJoystickListener* listener); |
| 364 |
|
| 365 |
void addSdlEventListener(ISdlEventListener* listener); |
| 366 |
void addSdlEventListenerFront(ISdlEventListener* listener); |
| 367 |
void removeSdlEventListener(ISdlEventListener* listener); |
| 368 |
|
| 369 |
EventSourceType getEventSourceType(); |
| 370 |
void dispatchCommand(Command& command); |
| 371 |
void setKeyFilter(IKeyFilter* keyFilter); |
| 372 |
|
| 373 |
void setMouseSensitivity(float sensitivity); |
| 374 |
float getMouseSensitivity() const; |
| 375 |
void setMouseAccelerationEnabled(bool acceleration); |
| 376 |
bool isMouseAccelerationEnabled() const; |
| 377 |
|
| 378 |
bool isClipboardText() const; |
| 379 |
std::string getClipboardText() const; |
| 380 |
void setClipboardText(const std::string& text); |
| 381 |
|
| 382 |
Joystick* getJoystick(int32_t instanceId); |
| 383 |
uint8_t getJoystickCount() const; |
| 384 |
void loadGamepadMapping(const std::string& file); |
| 385 |
void saveGamepadMapping(const std::string guid, const std::string& file); |
| 386 |
void saveGamepadMappings(const std::string& file); |
| 387 |
std::string getGamepadStringMapping(const std::string& guid); |
| 388 |
void setGamepadStringMapping(const std::string& mapping); |
| 389 |
}; |
| 390 |
}; |