Initial commit
This commit is contained in:
commit
edfc5298e1
252 changed files with 93965 additions and 0 deletions
19
include/Spectre/Input/InputDevice.h
Normal file
19
include/Spectre/Input/InputDevice.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
#ifndef SPECTRE_INTPUT_DEVICE_H
|
||||
#define SPECTRE_INTPUT_DEVICE_H
|
||||
|
||||
class InputDevice
|
||||
{
|
||||
friend class InputModule;
|
||||
|
||||
public :
|
||||
virtual ~InputDevice();
|
||||
|
||||
virtual void init();
|
||||
|
||||
protected :
|
||||
|
||||
virtual void update(InputModule *input) = 0;
|
||||
};
|
||||
|
||||
#endif /* SPECTRE_INTPUT_DEVICE_H */
|
||||
153
include/Spectre/Input/InputEvent.h
Normal file
153
include/Spectre/Input/InputEvent.h
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
|
||||
#ifndef SPECTRE_INPUT_EVENT_H
|
||||
#define SPECTRE_INPUT_EVENT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace MouseButton {
|
||||
|
||||
enum Type {
|
||||
Unknown,
|
||||
Left,
|
||||
Right,
|
||||
Middle,
|
||||
Button1,
|
||||
Button2,
|
||||
NUM_MBUTTONS,
|
||||
};
|
||||
};
|
||||
|
||||
namespace Key {
|
||||
|
||||
enum Type {
|
||||
Unknown,
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
D,
|
||||
E,
|
||||
F,
|
||||
G,
|
||||
H,
|
||||
I,
|
||||
J,
|
||||
K,
|
||||
L,
|
||||
M,
|
||||
N,
|
||||
O,
|
||||
P,
|
||||
Q,
|
||||
R,
|
||||
S,
|
||||
T,
|
||||
U,
|
||||
V,
|
||||
W,
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
One,
|
||||
Two,
|
||||
Three,
|
||||
Four,
|
||||
Five,
|
||||
Six,
|
||||
Seven,
|
||||
Eight,
|
||||
Nine,
|
||||
Zero,
|
||||
Period,
|
||||
Comma,
|
||||
Enter,
|
||||
Backspace,
|
||||
Escape,
|
||||
Space,
|
||||
Capslock,
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
NUMPAD_1,
|
||||
NUMPAD_2,
|
||||
NUMPAD_3,
|
||||
NUMPAD_4,
|
||||
NUMPAD_5,
|
||||
NUMPAD_6,
|
||||
NUMPAD_7,
|
||||
NUMPAD_8,
|
||||
NUMPAD_9,
|
||||
NUMPAD_0,
|
||||
NUMPAD_Enter,
|
||||
Home,
|
||||
End,
|
||||
Insert,
|
||||
Delete,
|
||||
PageUp,
|
||||
PageDown,
|
||||
Pause,
|
||||
F1,
|
||||
F2,
|
||||
F3,
|
||||
F4,
|
||||
F5,
|
||||
F6,
|
||||
F7,
|
||||
F8,
|
||||
F9,
|
||||
F10,
|
||||
F11,
|
||||
F12,
|
||||
Tab,
|
||||
LShift,
|
||||
RShift,
|
||||
LCtrl,
|
||||
RCtrl,
|
||||
LAlt,
|
||||
RAlt,
|
||||
NUM_KEYS,
|
||||
};
|
||||
}
|
||||
|
||||
typedef struct InputEvent
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
None,
|
||||
Key,
|
||||
MouseButton,
|
||||
MousePosition
|
||||
};
|
||||
|
||||
struct KeyEvent {
|
||||
Key::Type code;
|
||||
bool pressed; /* true if pressed, false if released. */
|
||||
|
||||
std::string getKeyName() const; /* Get the key name */
|
||||
};
|
||||
|
||||
struct MouseButtonEvent {
|
||||
MouseButton::Type button;
|
||||
bool pressed; /* true if pressed, false if released. */
|
||||
|
||||
std::string getName() const;
|
||||
};
|
||||
|
||||
struct MouseEvent {
|
||||
unsigned int x;
|
||||
unsigned int y;
|
||||
};
|
||||
|
||||
Type type;
|
||||
union {
|
||||
struct KeyEvent key;
|
||||
struct MouseEvent mouse;
|
||||
struct MouseButtonEvent mouseButton;
|
||||
};
|
||||
|
||||
InputEvent(Type type = None);
|
||||
|
||||
} InputEvent;
|
||||
|
||||
#endif /* SPECTRE_INPUT_EVENT_H */
|
||||
13
include/Spectre/Input/InputListener.h
Normal file
13
include/Spectre/Input/InputListener.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#ifndef SPECTRE_INPUT_LISTENER_H
|
||||
#define SPECTRE_INPUT_LISTENER_H
|
||||
|
||||
#include "InputEvent.h"
|
||||
|
||||
class InputListener
|
||||
{
|
||||
public :
|
||||
virtual void onInputEvent(const InputEvent& event);
|
||||
};
|
||||
|
||||
#endif /* SPECTRE_INPUT_LISTENER_H */
|
||||
57
include/Spectre/Input/InputModule.h
Normal file
57
include/Spectre/Input/InputModule.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
#ifndef SPECTRE_INPUT_MODULE_H
|
||||
#define SPECTRE_INPUT_MODULE_H
|
||||
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
#include "InputListener.h"
|
||||
#include "InputEvent.h"
|
||||
|
||||
class Mouse;
|
||||
class Keyboard;
|
||||
class InputDevice;
|
||||
class PlatformInput;
|
||||
|
||||
class InputModule
|
||||
{
|
||||
public :
|
||||
InputModule(PlatformInput *platform);
|
||||
|
||||
virtual ~InputModule();
|
||||
|
||||
Mouse* getMouse();
|
||||
|
||||
Keyboard* getKeyboard();
|
||||
|
||||
void addInputDevice(InputDevice *device);
|
||||
|
||||
void registerListener(InputListener* listener);
|
||||
|
||||
void removeListener(InputListener* listener);
|
||||
|
||||
void postInputEvent(const InputEvent& event);
|
||||
|
||||
// NOTE: Update devices here! (for winapi, process keyboard/mouse messages)
|
||||
void update();
|
||||
|
||||
protected :
|
||||
|
||||
void dispatch();
|
||||
|
||||
typedef std::vector<InputDevice*> InputDeviceVec;
|
||||
InputDeviceVec m_devices;
|
||||
|
||||
Mouse *m_mouse;
|
||||
|
||||
Keyboard *m_keyboard;
|
||||
|
||||
// Buffered input queue.
|
||||
std::deque<InputEvent> m_buffer;
|
||||
|
||||
std::vector<InputListener*> m_listeners;
|
||||
|
||||
PlatformInput *m_platform;
|
||||
};
|
||||
|
||||
#endif /* SPECTRE_INPUT_MODULE_H */
|
||||
19
include/Spectre/Input/Keyboard.h
Normal file
19
include/Spectre/Input/Keyboard.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
#ifndef SPECTRE_INPUT_KEYBOARD_H
|
||||
#define SPECTRE_INPUT_KEYBOARD_H
|
||||
|
||||
#include <string>
|
||||
#include "InputEvent.h"
|
||||
#include "InputDevice.h"
|
||||
|
||||
class Keyboard : public InputDevice
|
||||
{
|
||||
public :
|
||||
virtual ~Keyboard() {};
|
||||
|
||||
virtual bool isKeyDown(Key::Type key) = 0;
|
||||
|
||||
static std::string getKeyName(Key::Type key);
|
||||
};
|
||||
|
||||
#endif /* SPECTRE_INPUT_KEYBOARD_H */
|
||||
25
include/Spectre/Input/Mouse.h
Normal file
25
include/Spectre/Input/Mouse.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
#ifndef SPECTRE_INPUT_MOUSE_H
|
||||
#define SPECTRE_INPUT_MOUSE_H
|
||||
|
||||
#include <string>
|
||||
#include <Spectre/Math/Vector2.h>
|
||||
#include "InputEvent.h"
|
||||
#include "InputDevice.h"
|
||||
|
||||
class Mouse : public InputDevice
|
||||
{
|
||||
public :
|
||||
virtual ~Mouse();
|
||||
|
||||
// Get mouse position
|
||||
virtual Vector2f getPosition() const = 0;
|
||||
|
||||
//virtual Vector2i getPositionAbs() const = 0;
|
||||
|
||||
virtual bool isButtonDown(MouseButton::Type button) const = 0;
|
||||
|
||||
static std::string getButtonName(MouseButton::Type button);
|
||||
};
|
||||
|
||||
#endif /* SPECTRE_INPUT_MOUSE_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue