Merge branch 'maint-platform' into dev
This commit is contained in:
commit
f86a1ae90c
45 changed files with 1091 additions and 1001 deletions
|
|
@ -27,7 +27,8 @@ local system_module = Module("source/System", {
|
||||||
"Path.cpp",
|
"Path.cpp",
|
||||||
"MessageHandler.cpp",
|
"MessageHandler.cpp",
|
||||||
"MessageQueue.cpp",
|
"MessageQueue.cpp",
|
||||||
"SystemEvent.cpp",
|
"Event.cpp",
|
||||||
|
"EventListener.cpp",
|
||||||
"Log.cpp"
|
"Log.cpp"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -46,7 +47,7 @@ local platform_spec_module = Module("source/Platform/Win32", {
|
||||||
"Win32Keyboard.cpp",
|
"Win32Keyboard.cpp",
|
||||||
"Win32Misc.cpp",
|
"Win32Misc.cpp",
|
||||||
"Win32Mouse.cpp",
|
"Win32Mouse.cpp",
|
||||||
"Win32MsgBuffer.cpp",
|
"Win32EventQueue.cpp",
|
||||||
"Win32System.cpp",
|
"Win32System.cpp",
|
||||||
"glad_wgl.c"
|
"glad_wgl.c"
|
||||||
})
|
})
|
||||||
|
|
@ -54,8 +55,6 @@ local platform_spec_module = Module("source/Platform/Win32", {
|
||||||
|
|
||||||
local input_module = Module("source/Input", {
|
local input_module = Module("source/Input", {
|
||||||
"InputDevice.cpp",
|
"InputDevice.cpp",
|
||||||
"InputEvent.cpp",
|
|
||||||
"InputListener.cpp",
|
|
||||||
"InputModule.cpp",
|
"InputModule.cpp",
|
||||||
"Keyboard.cpp",
|
"Keyboard.cpp",
|
||||||
"Mouse.cpp"
|
"Mouse.cpp"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include "DisplayMode.h"
|
#include "DisplayMode.h"
|
||||||
#include "DisplayDescription.h"
|
#include "DisplayDescription.h"
|
||||||
#include <Spectre/Display/GLContext.h>
|
#include <Spectre/Display/GLContext.h>
|
||||||
#include <Spectre/System/SystemEvent.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
#define SPECTRE_GAME_H
|
#define SPECTRE_GAME_H
|
||||||
|
|
||||||
#include <Spectre/Graphics.h>
|
#include <Spectre/Graphics.h>
|
||||||
#include <Spectre/Input/InputEvent.h>
|
|
||||||
#include <Spectre/Game/FPSCounter.h>
|
#include <Spectre/Game/FPSCounter.h>
|
||||||
|
|
||||||
class InputModule;
|
class InputModule;
|
||||||
|
|
@ -37,9 +36,9 @@ protected :
|
||||||
|
|
||||||
FPSCounter& getFpsCounter();
|
FPSCounter& getFpsCounter();
|
||||||
|
|
||||||
private :
|
MessageHandler* getMessageHandler() const;
|
||||||
|
|
||||||
void setup();
|
private :
|
||||||
|
|
||||||
void gameLoop();
|
void gameLoop();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
#ifndef SPECTRE_INTPUT_DEVICE_H
|
#ifndef SPECTRE_INTPUT_DEVICE_H
|
||||||
#define SPECTRE_INTPUT_DEVICE_H
|
#define SPECTRE_INTPUT_DEVICE_H
|
||||||
|
|
||||||
#include "InputModule.h"
|
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
class InputMudule;
|
||||||
|
|
||||||
class InputDevice
|
class InputDevice
|
||||||
{
|
{
|
||||||
friend class InputModule;
|
friend class InputModule;
|
||||||
|
|
|
||||||
|
|
@ -1,157 +0,0 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_INPUT_EVENT_H
|
|
||||||
#define SPECTRE_INPUT_EVENT_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
||||||
#endif /* SPECTRE_INPUT_EVENT_H */
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_INPUT_LISTENER_H
|
|
||||||
#define SPECTRE_INPUT_LISTENER_H
|
|
||||||
|
|
||||||
#include "InputEvent.h"
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
class InputListener
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
virtual void onInputEvent(const InputEvent& event);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
||||||
#endif /* SPECTRE_INPUT_LISTENER_H */
|
|
||||||
|
|
@ -5,9 +5,6 @@
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "InputListener.h"
|
|
||||||
#include "InputEvent.h"
|
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Mouse;
|
class Mouse;
|
||||||
|
|
@ -28,12 +25,6 @@ public :
|
||||||
|
|
||||||
void addInputDevice(InputDevice *device);
|
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)
|
// NOTE: Update devices here! (for winapi, process keyboard/mouse messages)
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
|
@ -48,11 +39,6 @@ protected :
|
||||||
|
|
||||||
Keyboard *m_keyboard;
|
Keyboard *m_keyboard;
|
||||||
|
|
||||||
// Buffered input queue.
|
|
||||||
std::deque<InputEvent> m_buffer;
|
|
||||||
|
|
||||||
std::vector<InputListener*> m_listeners;
|
|
||||||
|
|
||||||
PlatformInput *m_platform;
|
PlatformInput *m_platform;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,107 @@
|
||||||
#define SPECTRE_INPUT_KEYBOARD_H
|
#define SPECTRE_INPUT_KEYBOARD_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "InputEvent.h"
|
|
||||||
#include "InputDevice.h"
|
#include "InputDevice.h"
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Keyboard : public InputDevice
|
class Keyboard : public InputDevice
|
||||||
{
|
{
|
||||||
|
public :
|
||||||
|
enum Key {
|
||||||
|
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,
|
||||||
|
Numpad1,
|
||||||
|
Numpad2,
|
||||||
|
Numpad3,
|
||||||
|
Numpad4,
|
||||||
|
Numpad5,
|
||||||
|
Numpad6,
|
||||||
|
Numpad7,
|
||||||
|
Numpad8,
|
||||||
|
Numpad9,
|
||||||
|
Numpad0,
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
public :
|
public :
|
||||||
virtual ~Keyboard() {};
|
virtual ~Keyboard() {};
|
||||||
|
|
||||||
virtual bool isKeyDown(Key::Type key) = 0;
|
virtual bool isKeyDown(Key key) = 0;
|
||||||
|
|
||||||
static std::string getKeyName(Key::Type key);
|
static std::string getKeyName(Key key);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -4,26 +4,39 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <Spectre/Math/Vector2.h>
|
#include <Spectre/Math/Vector2.h>
|
||||||
#include "InputEvent.h"
|
|
||||||
#include "InputDevice.h"
|
#include "InputDevice.h"
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Mouse : public InputDevice
|
class Mouse : public InputDevice
|
||||||
{
|
{
|
||||||
|
public :
|
||||||
|
enum Button {
|
||||||
|
Unknown,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Middle,
|
||||||
|
Button1,
|
||||||
|
Button2,
|
||||||
|
NUM_MBUTTONS
|
||||||
|
};
|
||||||
|
|
||||||
public :
|
public :
|
||||||
virtual ~Mouse();
|
virtual ~Mouse();
|
||||||
|
|
||||||
// Get mouse position
|
// Get the position in relative (focused window) coordinates.
|
||||||
|
// coordinates are relative to the window's top-left corner.
|
||||||
virtual Vector2f getPosition() const = 0;
|
virtual Vector2f getPosition() const = 0;
|
||||||
|
|
||||||
//virtual Vector2i getPositionAbs() const = 0;
|
// Get the position in absolute (screen) coordinates.
|
||||||
|
// 0,0 is located at the screen's top-left corner.
|
||||||
|
virtual Vector2f getAbsPosition() const = 0;
|
||||||
|
|
||||||
virtual bool isButtonDown(MouseButton::Type button) const = 0;
|
virtual bool isButtonDown(Button button) const = 0;
|
||||||
|
|
||||||
static std::string getButtonName(MouseButton::Type button);
|
static std::string getButtonName(Button button);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
}; // namespace sp
|
||||||
|
|
||||||
#endif /* SPECTRE_INPUT_MOUSE_H */
|
#endif /* SPECTRE_INPUT_MOUSE_H */
|
||||||
|
|
|
||||||
74
include/Spectre/System/Event.h
Normal file
74
include/Spectre/System/Event.h
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_SYSTEM_EVENT_H
|
||||||
|
#define SPECTRE_SYSTEM_EVENT_H
|
||||||
|
|
||||||
|
#include <Spectre/Input/Mouse.h>
|
||||||
|
#include <Spectre/Input/Keyboard.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class Display;
|
||||||
|
|
||||||
|
struct Event
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
None,
|
||||||
|
Quit,
|
||||||
|
Size,
|
||||||
|
Key,
|
||||||
|
MouseButton,
|
||||||
|
MouseMove
|
||||||
|
};
|
||||||
|
|
||||||
|
struct KeyEvent {
|
||||||
|
Keyboard::Key code;
|
||||||
|
bool pressed; /* true if pressed, false if released. */
|
||||||
|
|
||||||
|
std::string getKeyName() const; /* Get the key name */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MouseButtonEvent {
|
||||||
|
Mouse::Button button;
|
||||||
|
bool pressed; /* true if pressed, false if released. */
|
||||||
|
|
||||||
|
std::string getName() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MouseMoveEvent {
|
||||||
|
unsigned int x;
|
||||||
|
unsigned int y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SizeEvent
|
||||||
|
{
|
||||||
|
Display *display;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
};
|
||||||
|
|
||||||
|
Type type;
|
||||||
|
union {
|
||||||
|
struct SizeEvent size;
|
||||||
|
struct KeyEvent key;
|
||||||
|
struct MouseMoveEvent mouseMove;
|
||||||
|
struct MouseButtonEvent mouseButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
Event(Type type = None);
|
||||||
|
|
||||||
|
// Helper methods
|
||||||
|
|
||||||
|
static Event createSize(Display *display, int width, int height);
|
||||||
|
|
||||||
|
static Event createKey(Keyboard::Key code, bool pressed);
|
||||||
|
|
||||||
|
static Event createMouseButton(Mouse::Button button, bool pressed);
|
||||||
|
|
||||||
|
static Event createMouseMove(unsigned int x, unsigned int y);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_SYSTEM_EVENT_H */
|
||||||
23
include/Spectre/System/EventListener.h
Normal file
23
include/Spectre/System/EventListener.h
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
|
||||||
|
#ifndef SYSTEM_EVENT_LISTENER_H
|
||||||
|
#define SYSTEM_EVENT_LISTENER_H
|
||||||
|
|
||||||
|
#include <Spectre/System/Event.h>
|
||||||
|
#include <Spectre/Input/Mouse.h>
|
||||||
|
#include <Spectre/Input/Keyboard.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class Display;
|
||||||
|
|
||||||
|
class EventListener
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
virtual void onSizeChanged(Display* display, int width, int height);
|
||||||
|
|
||||||
|
virtual void onEvent(const Event& event);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SYSTEM_EVENT_LISTENER_H */
|
||||||
|
|
@ -2,16 +2,25 @@
|
||||||
#ifndef SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
#ifndef SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
||||||
#define SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
#define SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
||||||
|
|
||||||
#include "SystemEvent.h"
|
#include <vector>
|
||||||
|
#include "EventListener.h"
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Display;
|
class MessageHandler : public EventListener
|
||||||
|
|
||||||
class MessageHandler
|
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
|
void registerListener(EventListener *listener);
|
||||||
|
|
||||||
|
void unregisterListener(EventListener *listener);
|
||||||
|
|
||||||
virtual void onSizeChanged(Display* display, int width, int height);
|
virtual void onSizeChanged(Display* display, int width, int height);
|
||||||
|
|
||||||
|
virtual void onEvent(const Event& event);
|
||||||
|
|
||||||
|
protected :
|
||||||
|
std::vector<EventListener*> m_listeners;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,29 @@
|
||||||
#ifndef SPECTRE_MESSAGE_QUEUE_H
|
#ifndef SPECTRE_MESSAGE_QUEUE_H
|
||||||
#define SPECTRE_MESSAGE_QUEUE_H
|
#define SPECTRE_MESSAGE_QUEUE_H
|
||||||
|
|
||||||
#include <Spectre/System/SystemEvent.h>
|
#include <Spectre/System/Event.h>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
class PlatformEventQueue;
|
||||||
|
|
||||||
class MessageQueue
|
class MessageQueue
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
void postEvent(SysEvent event);
|
MessageQueue();
|
||||||
|
~MessageQueue();
|
||||||
|
|
||||||
bool pollEvent(SysEvent& event);
|
void postEvent(Event event);
|
||||||
|
|
||||||
|
bool pollEvent(Event& event);
|
||||||
|
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
std::deque<SysEvent> m_queue;
|
std::deque<Event> m_queue;
|
||||||
|
|
||||||
|
PlatformEventQueue* m_impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
|
|
||||||
#ifndef SYSTEM_EVENT_H
|
|
||||||
#define SYSTEM_EVENT_H
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
class Display;
|
|
||||||
|
|
||||||
struct SysEvent
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
|
|
||||||
enum Type {
|
|
||||||
None,
|
|
||||||
Quit,
|
|
||||||
Size,
|
|
||||||
};
|
|
||||||
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
struct Size
|
|
||||||
{
|
|
||||||
Display *display;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
};
|
|
||||||
|
|
||||||
union {
|
|
||||||
struct Size size;
|
|
||||||
};
|
|
||||||
|
|
||||||
SysEvent(Type type = None);
|
|
||||||
|
|
||||||
// Helper methods
|
|
||||||
|
|
||||||
static SysEvent sizeEvent(Display *display, int width, int height);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
||||||
#endif /* SYSTEM_EVENT_H */
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Spectre/Display/Display.h>
|
#include <Spectre/Display/Display.h>
|
||||||
#include <Spectre/Display/GLContext.h>
|
#include <Spectre/Display/GLContext.h>
|
||||||
#include <Spectre/System/SystemEvent.h>
|
|
||||||
#include <Platform/PlatformDisplay.h>
|
#include <Platform/PlatformDisplay.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,12 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
Game::Game()
|
Game::Game() :
|
||||||
|
m_running(false)
|
||||||
{
|
{
|
||||||
m_platform = new Win32Application();
|
m_platform = new Win32Application();
|
||||||
|
|
||||||
m_running = false;
|
|
||||||
m_graphics = new Graphics(m_platform);
|
m_graphics = new Graphics(m_platform);
|
||||||
m_input = new InputModule(&m_platform->getInput());
|
m_input = new InputModule(&m_platform->getInput());
|
||||||
|
|
||||||
m_messageHandler = new MessageHandler();
|
m_messageHandler = new MessageHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,18 +28,13 @@ Game::~Game()
|
||||||
delete m_messageHandler;
|
delete m_messageHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::setup()
|
|
||||||
{
|
|
||||||
m_graphics->init();
|
|
||||||
|
|
||||||
m_graphics->setClearColor(0.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::run()
|
void Game::run()
|
||||||
{
|
{
|
||||||
setup();
|
if (!m_graphics->init()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
gameLoop();
|
gameLoop();
|
||||||
}
|
}
|
||||||
|
|
@ -56,6 +49,9 @@ void Game::gameLoop()
|
||||||
|
|
||||||
processEvents();
|
processEvents();
|
||||||
|
|
||||||
|
// Update input.
|
||||||
|
getInput()->update();
|
||||||
|
|
||||||
if (time.beginFrame()) {
|
if (time.beginFrame()) {
|
||||||
|
|
||||||
while(time.tick()) {
|
while(time.tick()) {
|
||||||
|
|
@ -71,22 +67,22 @@ void Game::gameLoop()
|
||||||
void Game::processEvents()
|
void Game::processEvents()
|
||||||
{
|
{
|
||||||
MessageQueue& queue = m_platform->getMessageQueue();
|
MessageQueue& queue = m_platform->getMessageQueue();
|
||||||
SysEvent event;
|
Event event;
|
||||||
|
|
||||||
m_platform->update();
|
|
||||||
|
|
||||||
while(queue.pollEvent(event)) {
|
while(queue.pollEvent(event)) {
|
||||||
|
|
||||||
if (event.type == SysEvent::Quit) {
|
if (event.type == Event::Quit) {
|
||||||
exit();
|
exit();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call message handler.
|
// Call message handler.
|
||||||
|
|
||||||
if (event.type == SysEvent::Size) {
|
if (event.type == Event::Size) {
|
||||||
m_messageHandler->onSizeChanged(event.size.display, event.size.width, event.size.height);
|
m_messageHandler->onSizeChanged(event.size.display, event.size.width, event.size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_messageHandler->onEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,4 +106,9 @@ FPSCounter& Game::getFpsCounter()
|
||||||
return m_fpsCounter;
|
return m_fpsCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessageHandler* Game::getMessageHandler() const
|
||||||
|
{
|
||||||
|
return m_messageHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,9 @@ bool Graphics::init()
|
||||||
|
|
||||||
desc.decoration = DisplayDecorate::Menu | DisplayDecorate::Close | DisplayDecorate::Resize;
|
desc.decoration = DisplayDecorate::Menu | DisplayDecorate::Close | DisplayDecorate::Resize;
|
||||||
|
|
||||||
m_display->create(desc);
|
if (!m_display->create(desc)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
setClearColor(0.0f, 0.0f, 0.0f);
|
setClearColor(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
|
|
||||||
#include <Spectre/Input/Mouse.h>
|
|
||||||
#include <Spectre/Input/Keyboard.h>
|
|
||||||
#include <Spectre/Input/InputEvent.h>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
InputEvent::InputEvent(Type type) :
|
|
||||||
type (type)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string InputEvent::KeyEvent::getKeyName() const
|
|
||||||
{
|
|
||||||
return Keyboard::getKeyName(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string InputEvent::MouseButtonEvent::getName() const
|
|
||||||
{
|
|
||||||
return Mouse::getButtonName(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
|
|
||||||
#include <Spectre/Input/InputListener.h>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
void InputListener::onInputEvent(const InputEvent& event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
#include <Platform/PlatformInput.h>
|
#include <Platform/PlatformInput.h>
|
||||||
#include <Spectre/Input/Keyboard.h>
|
#include <Spectre/Input/Keyboard.h>
|
||||||
#include <Spectre/Input/Mouse.h>
|
#include <Spectre/Input/Mouse.h>
|
||||||
#include <Spectre/Input/InputEvent.h>
|
|
||||||
#include <Spectre/Input/InputDevice.h>
|
#include <Spectre/Input/InputDevice.h>
|
||||||
#include <Spectre/Input/InputModule.h>
|
#include <Spectre/Input/InputModule.h>
|
||||||
|
|
||||||
|
|
@ -35,16 +34,6 @@ void InputModule::addInputDevice(InputDevice *device)
|
||||||
m_devices.push_back(device);
|
m_devices.push_back(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputModule::registerListener(InputListener* listener)
|
|
||||||
{
|
|
||||||
m_listeners.push_back(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputModule::removeListener(InputListener* listener)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Mouse* InputModule::getMouse()
|
Mouse* InputModule::getMouse()
|
||||||
{
|
{
|
||||||
return m_mouse;
|
return m_mouse;
|
||||||
|
|
@ -55,46 +44,14 @@ Keyboard* InputModule::getKeyboard()
|
||||||
return m_keyboard;
|
return m_keyboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputModule::postInputEvent(const InputEvent& event)
|
|
||||||
{
|
|
||||||
if (m_buffer.size() < 128) {
|
|
||||||
m_buffer.push_back(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputModule::update()
|
void InputModule::update()
|
||||||
{
|
{
|
||||||
InputDeviceVec::iterator it;
|
InputDeviceVec::iterator it;
|
||||||
|
|
||||||
m_platform->update();
|
|
||||||
|
|
||||||
// Update all devices.
|
// Update all devices.
|
||||||
for(it = m_devices.begin(); it != m_devices.end(); it++) {
|
for(it = m_devices.begin(); it != m_devices.end(); it++) {
|
||||||
|
|
||||||
(*it)->update(this);
|
(*it)->update(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch all events to listeners.
|
|
||||||
dispatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputModule::dispatch()
|
|
||||||
{
|
|
||||||
std::deque<InputEvent>::iterator it;
|
|
||||||
|
|
||||||
for(it = m_buffer.begin(); it != m_buffer.end(); it++) {
|
|
||||||
|
|
||||||
const InputEvent& event = *it;
|
|
||||||
|
|
||||||
// Call listeners.
|
|
||||||
std::vector<InputListener*>::iterator it;
|
|
||||||
for(it = m_listeners.begin(); it != m_listeners.end(); it++) {
|
|
||||||
|
|
||||||
(*it)->onInputEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_buffer.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -5,107 +5,106 @@ namespace sp {
|
||||||
|
|
||||||
struct keyentry
|
struct keyentry
|
||||||
{
|
{
|
||||||
Key::Type type;
|
Keyboard::Key type;
|
||||||
const char *name;
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MapSym(key, name) { key, name }
|
#define MapSym(key, name) { key, name }
|
||||||
|
|
||||||
struct keyentry table[] = {
|
struct keyentry table[] = {
|
||||||
MapSym(Key::Unknown, "Unknown"),
|
MapSym(Keyboard::Key::Unknown, "Unknown"),
|
||||||
MapSym(Key::A, "A"),
|
MapSym(Keyboard::Key::A, "A"),
|
||||||
MapSym(Key::B, "B"),
|
MapSym(Keyboard::Key::B, "B"),
|
||||||
MapSym(Key::C, "C"),
|
MapSym(Keyboard::Key::C, "C"),
|
||||||
MapSym(Key::D, "D"),
|
MapSym(Keyboard::Key::D, "D"),
|
||||||
MapSym(Key::E, "E"),
|
MapSym(Keyboard::Key::E, "E"),
|
||||||
MapSym(Key::F, "F"),
|
MapSym(Keyboard::Key::F, "F"),
|
||||||
MapSym(Key::G, "G"),
|
MapSym(Keyboard::Key::G, "G"),
|
||||||
MapSym(Key::H, "H"),
|
MapSym(Keyboard::Key::H, "H"),
|
||||||
MapSym(Key::I, "I"),
|
MapSym(Keyboard::Key::I, "I"),
|
||||||
MapSym(Key::J, "J"),
|
MapSym(Keyboard::Key::J, "J"),
|
||||||
MapSym(Key::K, "K"),
|
MapSym(Keyboard::Key::K, "K"),
|
||||||
MapSym(Key::L, "L"),
|
MapSym(Keyboard::Key::L, "L"),
|
||||||
MapSym(Key::M, "M"),
|
MapSym(Keyboard::Key::M, "M"),
|
||||||
MapSym(Key::N, "N"),
|
MapSym(Keyboard::Key::N, "N"),
|
||||||
MapSym(Key::O, "O"),
|
MapSym(Keyboard::Key::O, "O"),
|
||||||
MapSym(Key::P, "P"),
|
MapSym(Keyboard::Key::P, "P"),
|
||||||
MapSym(Key::Q, "Q"),
|
MapSym(Keyboard::Key::Q, "Q"),
|
||||||
MapSym(Key::R, "R"),
|
MapSym(Keyboard::Key::R, "R"),
|
||||||
MapSym(Key::S, "S"),
|
MapSym(Keyboard::Key::S, "S"),
|
||||||
MapSym(Key::T, "T"),
|
MapSym(Keyboard::Key::T, "T"),
|
||||||
MapSym(Key::U, "U"),
|
MapSym(Keyboard::Key::U, "U"),
|
||||||
MapSym(Key::V, "V"),
|
MapSym(Keyboard::Key::V, "V"),
|
||||||
MapSym(Key::W, "W"),
|
MapSym(Keyboard::Key::W, "W"),
|
||||||
MapSym(Key::X, "X"),
|
MapSym(Keyboard::Key::X, "X"),
|
||||||
MapSym(Key::Y, "Y"),
|
MapSym(Keyboard::Key::Y, "Y"),
|
||||||
MapSym(Key::Z, "Z"),
|
MapSym(Keyboard::Key::Z, "Z"),
|
||||||
MapSym(Key::One, "1"),
|
MapSym(Keyboard::Key::One, "1"),
|
||||||
MapSym(Key::Two, "2"),
|
MapSym(Keyboard::Key::Two, "2"),
|
||||||
MapSym(Key::Three, "3"),
|
MapSym(Keyboard::Key::Three, "3"),
|
||||||
MapSym(Key::Four, "4"),
|
MapSym(Keyboard::Key::Four, "4"),
|
||||||
MapSym(Key::Five, "5"),
|
MapSym(Keyboard::Key::Five, "5"),
|
||||||
MapSym(Key::Six, "6"),
|
MapSym(Keyboard::Key::Six, "6"),
|
||||||
MapSym(Key::Seven, "7"),
|
MapSym(Keyboard::Key::Seven, "7"),
|
||||||
MapSym(Key::Eight, "8"),
|
MapSym(Keyboard::Key::Eight, "8"),
|
||||||
MapSym(Key::Nine, "9"),
|
MapSym(Keyboard::Key::Nine, "9"),
|
||||||
MapSym(Key::Zero, "0"),
|
MapSym(Keyboard::Key::Zero, "0"),
|
||||||
MapSym(Key::Period, "Period"),
|
MapSym(Keyboard::Key::Period, "Period"),
|
||||||
MapSym(Key::Comma, "Comma"),
|
MapSym(Keyboard::Key::Comma, "Comma"),
|
||||||
MapSym(Key::Enter, "Enter"),
|
MapSym(Keyboard::Key::Enter, "Enter"),
|
||||||
MapSym(Key::Backspace, "Backspace"),
|
MapSym(Keyboard::Key::Backspace, "Backspace"),
|
||||||
MapSym(Key::Escape, "Escape"),
|
MapSym(Keyboard::Key::Escape, "Escape"),
|
||||||
MapSym(Key::Space, "Space"),
|
MapSym(Keyboard::Key::Space, "Space"),
|
||||||
MapSym(Key::Capslock, "Capslock"),
|
MapSym(Keyboard::Key::Capslock, "Capslock"),
|
||||||
MapSym(Key::Up, "Up"),
|
MapSym(Keyboard::Key::Up, "Up"),
|
||||||
MapSym(Key::Down, "Down"),
|
MapSym(Keyboard::Key::Down, "Down"),
|
||||||
MapSym(Key::Left, "Left"),
|
MapSym(Keyboard::Key::Left, "Left"),
|
||||||
MapSym(Key::Right, "Right"),
|
MapSym(Keyboard::Key::Right, "Right"),
|
||||||
|
|
||||||
// Numpad
|
// Numpad
|
||||||
MapSym(Key::NUMPAD_1, "Numpad 1"),
|
MapSym(Keyboard::Key::Numpad1, "Numpad 1"),
|
||||||
MapSym(Key::NUMPAD_2, "Numpad 2"),
|
MapSym(Keyboard::Key::Numpad2, "Numpad 2"),
|
||||||
MapSym(Key::NUMPAD_3, "Numpad 3"),
|
MapSym(Keyboard::Key::Numpad3, "Numpad 3"),
|
||||||
MapSym(Key::NUMPAD_4, "Numpad 4"),
|
MapSym(Keyboard::Key::Numpad4, "Numpad 4"),
|
||||||
MapSym(Key::NUMPAD_5, "Numpad 5"),
|
MapSym(Keyboard::Key::Numpad5, "Numpad 5"),
|
||||||
MapSym(Key::NUMPAD_6, "Numpad 6"),
|
MapSym(Keyboard::Key::Numpad6, "Numpad 6"),
|
||||||
MapSym(Key::NUMPAD_7, "Numpad 7"),
|
MapSym(Keyboard::Key::Numpad7, "Numpad 7"),
|
||||||
MapSym(Key::NUMPAD_8, "Numpad 8"),
|
MapSym(Keyboard::Key::Numpad8, "Numpad 8"),
|
||||||
MapSym(Key::NUMPAD_9, "Numpad 9"),
|
MapSym(Keyboard::Key::Numpad9, "Numpad 9"),
|
||||||
MapSym(Key::NUMPAD_0, "Numpad 0"),
|
MapSym(Keyboard::Key::Numpad0, "Numpad 0"),
|
||||||
MapSym(Key::NUMPAD_Enter, "Numpad Enter"),
|
|
||||||
|
|
||||||
MapSym(Key::Home, "Home"),
|
MapSym(Keyboard::Key::Home, "Home"),
|
||||||
MapSym(Key::End, "End"),
|
MapSym(Keyboard::Key::End, "End"),
|
||||||
MapSym(Key::Insert, "Insert"),
|
MapSym(Keyboard::Key::Insert, "Insert"),
|
||||||
MapSym(Key::Delete, "Delete"),
|
MapSym(Keyboard::Key::Delete, "Delete"),
|
||||||
MapSym(Key::PageUp, "Page up"),
|
MapSym(Keyboard::Key::PageUp, "Page up"),
|
||||||
MapSym(Key::PageDown, "Page down"),
|
MapSym(Keyboard::Key::PageDown, "Page down"),
|
||||||
MapSym(Key::Pause, "Pause"),
|
MapSym(Keyboard::Key::Pause, "Pause"),
|
||||||
|
|
||||||
// Function keys.
|
// Function keys.
|
||||||
MapSym(Key::F1, "F1"),
|
MapSym(Keyboard::Key::F1, "F1"),
|
||||||
MapSym(Key::F2, "F2"),
|
MapSym(Keyboard::Key::F2, "F2"),
|
||||||
MapSym(Key::F3, "F3"),
|
MapSym(Keyboard::Key::F3, "F3"),
|
||||||
MapSym(Key::F4, "F4"),
|
MapSym(Keyboard::Key::F4, "F4"),
|
||||||
MapSym(Key::F5, "F5"),
|
MapSym(Keyboard::Key::F5, "F5"),
|
||||||
MapSym(Key::F6, "F6"),
|
MapSym(Keyboard::Key::F6, "F6"),
|
||||||
MapSym(Key::F7, "F7"),
|
MapSym(Keyboard::Key::F7, "F7"),
|
||||||
MapSym(Key::F8, "F8"),
|
MapSym(Keyboard::Key::F8, "F8"),
|
||||||
MapSym(Key::F9, "F9"),
|
MapSym(Keyboard::Key::F9, "F9"),
|
||||||
MapSym(Key::F10, "F10"),
|
MapSym(Keyboard::Key::F10, "F10"),
|
||||||
MapSym(Key::F11, "F11"),
|
MapSym(Keyboard::Key::F11, "F11"),
|
||||||
MapSym(Key::F12, "F12"),
|
MapSym(Keyboard::Key::F12, "F12"),
|
||||||
|
|
||||||
MapSym(Key::Tab, "Tab"),
|
MapSym(Keyboard::Key::Tab, "Tab"),
|
||||||
MapSym(Key::LShift, "Left Shift"),
|
MapSym(Keyboard::Key::LShift, "Left Shift"),
|
||||||
MapSym(Key::RShift, "Right Shift"),
|
MapSym(Keyboard::Key::RShift, "Right Shift"),
|
||||||
MapSym(Key::LCtrl, "Left Control"),
|
MapSym(Keyboard::Key::LCtrl, "Left Control"),
|
||||||
MapSym(Key::RCtrl, "Right Control"),
|
MapSym(Keyboard::Key::RCtrl, "Right Control"),
|
||||||
MapSym(Key::LAlt, "Left Alt"),
|
MapSym(Keyboard::Key::LAlt, "Left Alt"),
|
||||||
MapSym(Key::RAlt, "Right Alt"),
|
MapSym(Keyboard::Key::RAlt, "Right Alt"),
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string Keyboard::getKeyName(Key::Type key)
|
std::string Keyboard::getKeyName(Key key)
|
||||||
{
|
{
|
||||||
if (key >= Key::NUM_KEYS) {
|
if (key >= Key::NUM_KEYS) {
|
||||||
key = Key::Unknown;
|
key = Key::Unknown;
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,15 @@ Mouse::~Mouse()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Mouse::getButtonName(MouseButton::Type button)
|
std::string Mouse::getButtonName(Button button)
|
||||||
{
|
{
|
||||||
switch(button) {
|
switch(button) {
|
||||||
case MouseButton::Button1 : return "Button1";
|
case Button::Button1 : return "Button1";
|
||||||
case MouseButton::Button2 : return "Button2";
|
case Button::Button2 : return "Button2";
|
||||||
case MouseButton::Left : return "Left";
|
case Button::Left : return "Left";
|
||||||
case MouseButton::Right : return "Right";
|
case Button::Right : return "Right";
|
||||||
case MouseButton::Middle : return "Middle";
|
case Button::Middle : return "Middle";
|
||||||
case MouseButton::Unknown :
|
case Button::Unknown :
|
||||||
default:
|
default:
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ public :
|
||||||
virtual PlatformInput& getInput() = 0;
|
virtual PlatformInput& getInput() = 0;
|
||||||
|
|
||||||
virtual MessageQueue& getMessageQueue() = 0;
|
virtual MessageQueue& getMessageQueue() = 0;
|
||||||
|
|
||||||
virtual void update() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
21
source/Platform/PlatformEventQueue.h
Normal file
21
source/Platform/PlatformEventQueue.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef PLATFORM_MESSAGE_QUEUE_H
|
||||||
|
#define PLATFORM_MESSAGE_QUEUE_H
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
struct Event;
|
||||||
|
|
||||||
|
// Interface for platform specific event queue.
|
||||||
|
class PlatformEventQueue
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
|
||||||
|
// Poll one event from the platform's event queue.
|
||||||
|
// Returns false if there was no events.
|
||||||
|
// NOTE: This method is guaranteed to be non-blocking.
|
||||||
|
virtual bool poll(Event& event) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* PLATFORM_MESSAGE_QUEUE_H */
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include "Win32Keyboard.h"
|
|
||||||
#include "Win32Mouse.h"
|
|
||||||
#include "Win32Application.h"
|
#include "Win32Application.h"
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
@ -30,71 +27,4 @@ MessageQueue& Win32Application::getMessageQueue()
|
||||||
return m_messageQueue;
|
return m_messageQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Application::update()
|
|
||||||
{
|
|
||||||
MSG msg;
|
|
||||||
|
|
||||||
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
|
|
||||||
TranslateMessage(&msg);
|
|
||||||
processMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LRESULT Win32Application::processMessage(MSG msg)
|
|
||||||
{
|
|
||||||
switch(msg.message) {
|
|
||||||
case WM_QUIT :
|
|
||||||
m_messageQueue.postEvent(SysEvent(SysEvent::Quit));
|
|
||||||
return 0;
|
|
||||||
// Input, Forward to devices.
|
|
||||||
case WM_KEYDOWN :
|
|
||||||
case WM_KEYUP :
|
|
||||||
OutputDebugString("WM_KEYDOWN\n");
|
|
||||||
//SetCapture(msg.hwnd);
|
|
||||||
|
|
||||||
if (Win32Keyboard::handleMessage(msg)) {
|
|
||||||
// Keyboard did handle the message.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case WM_MOUSEMOVE :
|
|
||||||
case WM_MOUSELEAVE :
|
|
||||||
|
|
||||||
if (Win32Mouse::handleMessage(msg)) {
|
|
||||||
// Mouse did handle the message.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case WM_LBUTTONDOWN :
|
|
||||||
case WM_RBUTTONDOWN :
|
|
||||||
case WM_MBUTTONDOWN :
|
|
||||||
case WM_XBUTTONDOWN :
|
|
||||||
|
|
||||||
SetCapture(msg.hwnd);
|
|
||||||
|
|
||||||
if (Win32Mouse::handleMessage(msg)) {
|
|
||||||
// Mouse did handle the message.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case WM_LBUTTONUP :
|
|
||||||
case WM_RBUTTONUP :
|
|
||||||
case WM_MBUTTONUP :
|
|
||||||
case WM_XBUTTONUP :
|
|
||||||
|
|
||||||
ReleaseCapture();
|
|
||||||
|
|
||||||
if (Win32Mouse::handleMessage(msg)) {
|
|
||||||
// Mouse did handle the message.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Message was not intercepted. Pass down to window.
|
|
||||||
return DispatchMessage(&msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,6 @@ public :
|
||||||
|
|
||||||
virtual MessageQueue& getMessageQueue();
|
virtual MessageQueue& getMessageQueue();
|
||||||
|
|
||||||
virtual void update();
|
|
||||||
|
|
||||||
protected :
|
|
||||||
|
|
||||||
LRESULT processMessage(MSG msg);
|
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
//Win32Display m_display;
|
//Win32Display m_display;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include <Spectre/Display/Display.h>
|
#include <Spectre/Display/Display.h>
|
||||||
#include <Spectre/System/SystemEvent.h>
|
|
||||||
#include <Spectre/System/Log.h>
|
#include <Spectre/System/Log.h>
|
||||||
#include "Win32Application.h"
|
#include "Win32Application.h"
|
||||||
#include "Win32Internal.h"
|
#include "Win32Internal.h"
|
||||||
|
|
|
||||||
79
source/Platform/Win32/Win32EventQueue.cpp
Normal file
79
source/Platform/Win32/Win32EventQueue.cpp
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include "Win32Keyboard.h"
|
||||||
|
#include "Win32Mouse.h"
|
||||||
|
#include "Win32EventQueue.h"
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
bool Win32EventQueue::poll(Event& event)
|
||||||
|
{
|
||||||
|
MSG msg;
|
||||||
|
|
||||||
|
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
if (processMessage(msg, event) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LRESULT Win32EventQueue::processMessage(MSG msg, Event& event)
|
||||||
|
{
|
||||||
|
switch(msg.message) {
|
||||||
|
case WM_QUIT :
|
||||||
|
event.type = Event::Quit;
|
||||||
|
return 0;
|
||||||
|
// Input, Forward to devices.
|
||||||
|
case WM_KEYDOWN :
|
||||||
|
case WM_KEYUP :
|
||||||
|
OutputDebugString("WM_KEYDOWN\n");
|
||||||
|
//SetCapture(msg.hwnd);
|
||||||
|
|
||||||
|
if (Win32Keyboard::handleMessage(msg, event)) {
|
||||||
|
// Keyboard did handle the message.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WM_MOUSEMOVE :
|
||||||
|
case WM_MOUSELEAVE :
|
||||||
|
|
||||||
|
if (Win32Mouse::handleMessage(msg, event)) {
|
||||||
|
// Mouse did handle the message.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WM_LBUTTONDOWN :
|
||||||
|
case WM_RBUTTONDOWN :
|
||||||
|
case WM_MBUTTONDOWN :
|
||||||
|
case WM_XBUTTONDOWN :
|
||||||
|
|
||||||
|
SetCapture(msg.hwnd);
|
||||||
|
|
||||||
|
if (Win32Mouse::handleMessage(msg, event)) {
|
||||||
|
// Mouse did handle the message.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WM_LBUTTONUP :
|
||||||
|
case WM_RBUTTONUP :
|
||||||
|
case WM_MBUTTONUP :
|
||||||
|
case WM_XBUTTONUP :
|
||||||
|
|
||||||
|
ReleaseCapture();
|
||||||
|
|
||||||
|
if (Win32Mouse::handleMessage(msg, event)) {
|
||||||
|
// Mouse did handle the message.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message was not intercepted. Pass down to window.
|
||||||
|
return DispatchMessage(&msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
22
source/Platform/Win32/Win32EventQueue.h
Normal file
22
source/Platform/Win32/Win32EventQueue.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef PLATFORM_WIN32_EVENT_QUEUE_H
|
||||||
|
#define PLATFORM_WIN32_EVENT_QUEUE_H
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <Spectre/System/Event.h>
|
||||||
|
#include <Platform/PlatformEventQueue.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class Win32EventQueue : public PlatformEventQueue
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
virtual bool poll(Event& event);
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
LRESULT processMessage(MSG msg, Event& event);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* PLATFORM_WIN32_MESSAGE_QUEUE_H */
|
||||||
|
|
@ -9,29 +9,26 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
// Can't use GLAD's standard loader function because it
|
|
||||||
// calls wglGetProcAddress without __stdcall
|
|
||||||
// that results in some runtime exception.
|
|
||||||
static GLADapiproc func_loader(const char *name) {
|
|
||||||
return (GLADapiproc) wglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that OpenGL extensions are loaded.
|
// Ensure that OpenGL extensions are loaded.
|
||||||
static void ensureExtensionsLoaded(HDC dc)
|
static bool ensureExtensionsLoaded(HDC dc)
|
||||||
{
|
{
|
||||||
static bool init = false;
|
static bool init = false;
|
||||||
|
|
||||||
if (!init) {
|
if (!init) {
|
||||||
init = true;
|
|
||||||
|
|
||||||
if (!gladLoadWGL(dc, func_loader)) {
|
if (!gladLoaderLoadWGL(dc)) {
|
||||||
Log::error("WGL: Could not load WGL extensions");
|
Log::error("WGL: Could not load WGL extensions");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gladLoaderLoadGL()) {
|
if (!gladLoaderLoadGL()) {
|
||||||
Log::error("WGL: Could not load OpenGL extensions");
|
Log::error("WGL: Could not load OpenGL extensions");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init = true;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32GLContext::Win32GLContext() :
|
Win32GLContext::Win32GLContext() :
|
||||||
|
|
@ -103,11 +100,9 @@ void Win32GLContext::createGLContext()
|
||||||
tmpDC = ::wglCreateContext(m_deviceContext);
|
tmpDC = ::wglCreateContext(m_deviceContext);
|
||||||
::wglMakeCurrent(m_deviceContext, tmpDC);
|
::wglMakeCurrent(m_deviceContext, tmpDC);
|
||||||
|
|
||||||
ensureExtensionsLoaded(m_deviceContext);
|
if (!ensureExtensionsLoaded(m_deviceContext)) {
|
||||||
|
goto err;
|
||||||
// Dont need to old one anymore.
|
}
|
||||||
wglMakeCurrent(m_deviceContext, NULL);
|
|
||||||
::wglDeleteContext(tmpDC);
|
|
||||||
|
|
||||||
// TODO: For now.. We force 3.2 Core but this should not be implementation specific.
|
// TODO: For now.. We force 3.2 Core but this should not be implementation specific.
|
||||||
// The Display class should force that for all GLContext Implementations.
|
// The Display class should force that for all GLContext Implementations.
|
||||||
|
|
@ -121,6 +116,11 @@ void Win32GLContext::createGLContext()
|
||||||
|
|
||||||
// Create real context.
|
// Create real context.
|
||||||
m_renderContext = ::wglCreateContextAttribsARB(m_deviceContext, 0, attriblist);
|
m_renderContext = ::wglCreateContextAttribsARB(m_deviceContext, 0, attriblist);
|
||||||
|
|
||||||
|
err:
|
||||||
|
// Dont need the old one anymore.
|
||||||
|
wglMakeCurrent(m_deviceContext, NULL);
|
||||||
|
::wglDeleteContext(tmpDC);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32GLContext::activate()
|
bool Win32GLContext::activate()
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,6 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
Win32InputMsgBuffer Win32Input::inputMsgBuffer;
|
|
||||||
|
|
||||||
Win32InputMsgBuffer::Win32InputMsgBuffer() :
|
|
||||||
index (0),
|
|
||||||
enabled (false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Keyboard* Win32Input::createKeyboard()
|
Keyboard* Win32Input::createKeyboard()
|
||||||
{
|
{
|
||||||
return new Win32Keyboard();
|
return new Win32Keyboard();
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,6 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
#define WIN32_INPUT_BUFFER_QUEUE_MAX_SIZE 64
|
|
||||||
|
|
||||||
struct Win32InputMsgBuffer {
|
|
||||||
int index;
|
|
||||||
MSG messages[WIN32_INPUT_BUFFER_QUEUE_MAX_SIZE];
|
|
||||||
bool enabled;
|
|
||||||
|
|
||||||
Win32InputMsgBuffer();
|
|
||||||
|
|
||||||
bool postMessage(MSG msg);
|
|
||||||
};
|
|
||||||
|
|
||||||
class Win32Input : public PlatformInput
|
class Win32Input : public PlatformInput
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
@ -27,8 +15,6 @@ public :
|
||||||
virtual Mouse* createMouse();
|
virtual Mouse* createMouse();
|
||||||
|
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
|
||||||
static Win32InputMsgBuffer inputMsgBuffer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -1,123 +1,183 @@
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
#include <Spectre/Input/InputEvent.h>
|
#include <Spectre/System/Event.h>
|
||||||
#include <Spectre/Input/InputModule.h>
|
#include <Spectre/Input/InputModule.h>
|
||||||
#include "Win32Input.h"
|
#include "Win32Input.h"
|
||||||
#include "Win32Keyboard.h"
|
#include "Win32Keyboard.h"
|
||||||
#include "Win32MsgBuffer.h"
|
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
static Win32MsgBuffer msg_buf;
|
static const BYTE keyToWin32[Keyboard::Key::NUM_KEYS] = {
|
||||||
|
0x0, // Unknown
|
||||||
|
|
||||||
static const Key::Type deviceToKey[256] = {
|
0x41, // A
|
||||||
|
0x42, // B
|
||||||
|
0x43, // C
|
||||||
|
0x42, // D
|
||||||
|
0x43, // E
|
||||||
|
0x44, // F
|
||||||
|
0x45, // G
|
||||||
|
0x46, // H
|
||||||
|
0x47, // I
|
||||||
|
0x48, // J
|
||||||
|
0x49, // K
|
||||||
|
0x50, // L
|
||||||
|
0x51, // M
|
||||||
|
0x52, // N
|
||||||
|
0x53, // O
|
||||||
|
0x54, // P
|
||||||
|
0x55, // Q
|
||||||
|
0x56, // R
|
||||||
|
0x57, // S
|
||||||
|
0x58, // T
|
||||||
|
0x59, // U
|
||||||
|
0x60, // V
|
||||||
|
0x61, // W
|
||||||
|
0x62, // X
|
||||||
|
0x63, // Y
|
||||||
|
0x64, // Z
|
||||||
|
|
||||||
|
0x30, // One
|
||||||
|
0x31, // Two
|
||||||
|
0x32, // Three
|
||||||
|
0x33, // Four
|
||||||
|
0x34, // Five
|
||||||
|
0x35, // Six
|
||||||
|
0x36, // Seven
|
||||||
|
0x37, // Eight
|
||||||
|
0x38, // Nine
|
||||||
|
0x39, // Zero
|
||||||
|
|
||||||
|
VK_OEM_PERIOD, // Period
|
||||||
|
VK_OEM_COMMA, // Comma
|
||||||
|
VK_RETURN, // Enter
|
||||||
|
VK_BACK, // Backspace
|
||||||
|
VK_ESCAPE, // Escape
|
||||||
|
VK_SPACE, // Space
|
||||||
|
VK_CAPITAL, // Capslock
|
||||||
|
|
||||||
|
VK_UP, // Up
|
||||||
|
VK_DOWN, // Down
|
||||||
|
VK_LEFT, // Left
|
||||||
|
VK_RIGHT, // Right
|
||||||
|
|
||||||
|
VK_NUMPAD1, // Numpad1
|
||||||
|
VK_NUMPAD2, // Numpad2
|
||||||
|
VK_NUMPAD3, // Numpad3
|
||||||
|
VK_NUMPAD4, // Numpad4
|
||||||
|
VK_NUMPAD5, // Numpad5
|
||||||
|
VK_NUMPAD6, // Numpad6
|
||||||
|
VK_NUMPAD7, // Numpad7
|
||||||
|
VK_NUMPAD8, // Numpad8
|
||||||
|
VK_NUMPAD9, // Numpad9
|
||||||
|
VK_NUMPAD0, // Numpad0
|
||||||
|
|
||||||
|
VK_HOME, // Home
|
||||||
|
VK_END, // End
|
||||||
|
VK_INSERT, // Insert
|
||||||
|
VK_DELETE, // Delete
|
||||||
|
VK_PRIOR, // PageUp
|
||||||
|
VK_NEXT, // PageDown
|
||||||
|
VK_PAUSE, // Pause
|
||||||
|
|
||||||
|
VK_F1, // F1
|
||||||
|
VK_F2, // F2
|
||||||
|
VK_F3, // F3
|
||||||
|
VK_F4, // F4
|
||||||
|
VK_F5, // F5
|
||||||
|
VK_F6, // F6
|
||||||
|
VK_F7, // F7
|
||||||
|
VK_F8, // F8
|
||||||
|
VK_F9, // F9
|
||||||
|
VK_F10, // F10
|
||||||
|
VK_F11, // F11
|
||||||
|
VK_F12, // F12
|
||||||
|
|
||||||
|
VK_TAB, // Tab
|
||||||
|
VK_LSHIFT, // LShift
|
||||||
|
VK_RSHIFT, // RShift
|
||||||
|
VK_LCONTROL, // LCtrl
|
||||||
|
VK_RCONTROL, // RCtrl
|
||||||
|
VK_LMENU, // LAlt
|
||||||
|
VK_RMENU // RAlt
|
||||||
|
};
|
||||||
|
|
||||||
|
static const Keyboard::Key deviceToKey[256] = {
|
||||||
/* 0 1 2 3 4 5 6 7 */
|
/* 0 1 2 3 4 5 6 7 */
|
||||||
/* 8 9 A B C D E F */
|
/* 8 9 A B C D E F */
|
||||||
// 00-0F
|
// 00-0F
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
Key::Backspace, Key::Tab, Key::Unknown, Key::Unknown, Key::Unknown, Key::Enter, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Backspace, Keyboard::Key::Tab, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Enter, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// 10-1F
|
// 10-1F
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Pause, Key::Capslock, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Pause, Keyboard::Key::Capslock, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Escape, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Escape, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// 20-2F
|
// 20-2F
|
||||||
Key::Space, Key::PageUp, Key::PageDown, Key::End, Key::Home, Key::Left, Key::Up, Key::Right,
|
Keyboard::Key::Space, Keyboard::Key::PageUp, Keyboard::Key::PageDown, Keyboard::Key::End, Keyboard::Key::Home, Keyboard::Key::Left, Keyboard::Key::Up, Keyboard::Key::Right,
|
||||||
Key::Down, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Insert, Key::Delete, Key::Unknown,
|
Keyboard::Key::Down, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Insert, Keyboard::Key::Delete, Keyboard::Key::Unknown,
|
||||||
// 30-3F
|
// 30-3F
|
||||||
Key::Zero, Key::One, Key::Two, Key::Three, Key::Four, Key::Five, Key::Six, Key::Seven,
|
Keyboard::Key::Zero, Keyboard::Key::One, Keyboard::Key::Two, Keyboard::Key::Three, Keyboard::Key::Four, Keyboard::Key::Five, Keyboard::Key::Six, Keyboard::Key::Seven,
|
||||||
Key::Eight, Key::Nine, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Eight, Keyboard::Key::Nine, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// 40-4F
|
// 40-4F
|
||||||
Key::Unknown, Key::A, Key::B, Key::C, Key::D, Key::E, Key::F, Key::G,
|
Keyboard::Key::Unknown, Keyboard::Key::A, Keyboard::Key::B, Keyboard::Key::C, Keyboard::Key::D, Keyboard::Key::E, Keyboard::Key::F, Keyboard::Key::G,
|
||||||
Key::H, Key::I, Key::J, Key::K, Key::L, Key::M, Key::N, Key::O,
|
Keyboard::Key::H, Keyboard::Key::I, Keyboard::Key::J, Keyboard::Key::K, Keyboard::Key::L, Keyboard::Key::M, Keyboard::Key::N, Keyboard::Key::O,
|
||||||
// 50-5F
|
// 50-5F
|
||||||
Key::P, Key::Q, Key::R, Key::S, Key::T, Key::U, Key::V, Key::W,
|
Keyboard::Key::P, Keyboard::Key::Q, Keyboard::Key::R, Keyboard::Key::S, Keyboard::Key::T, Keyboard::Key::U, Keyboard::Key::V, Keyboard::Key::W,
|
||||||
Key::X, Key::Y, Key::Z, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::X, Keyboard::Key::Y, Keyboard::Key::Z, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// 60-6F
|
// 60-6F
|
||||||
Key::NUMPAD_0, Key::NUMPAD_1, Key::NUMPAD_2, Key::NUMPAD_3, Key::NUMPAD_4, Key::NUMPAD_5, Key::NUMPAD_6, Key::NUMPAD_7,
|
Keyboard::Key::Numpad0, Keyboard::Key::Numpad1, Keyboard::Key::Numpad2, Keyboard::Key::Numpad3, Keyboard::Key::Numpad4, Keyboard::Key::Numpad5, Keyboard::Key::Numpad6, Keyboard::Key::Numpad7,
|
||||||
Key::NUMPAD_8, Key::NUMPAD_9, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Numpad8, Keyboard::Key::Numpad9, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// 70-7F
|
// 70-7F
|
||||||
Key::F1, Key::F2, Key::F3, Key::F4, Key::F5, Key::F6, Key::F7, Key::F8,
|
Keyboard::Key::F1, Keyboard::Key::F2, Keyboard::Key::F3, Keyboard::Key::F4, Keyboard::Key::F5, Keyboard::Key::F6, Keyboard::Key::F7, Keyboard::Key::F8,
|
||||||
Key::F9, Key::F10, Key::F11, Key::F12, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::F9, Keyboard::Key::F10, Keyboard::Key::F11, Keyboard::Key::F12, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// 80-8F
|
// 80-8F
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// 90-9F
|
// 90-9F
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// A0-AF
|
// A0-AF
|
||||||
Key::LShift, Key::RShift, Key::LCtrl, Key::RCtrl, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::LShift, Keyboard::Key::RShift, Keyboard::Key::LCtrl, Keyboard::Key::RCtrl, Keyboard::Key::LAlt, Keyboard::Key::RAlt, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// B0-BF
|
// B0-BF
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Comma, Key::Unknown, Key::Period, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Comma, Keyboard::Key::Unknown, Keyboard::Key::Period, Keyboard::Key::Unknown,
|
||||||
// C0-CF
|
// C0-CF
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// E0-EF
|
// E0-EF
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
// F0-FF
|
// F0-FF
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown, Key::Unknown,
|
Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown, Keyboard::Key::Unknown,
|
||||||
};
|
};
|
||||||
|
|
||||||
void Win32Keyboard::init()
|
void Win32Keyboard::init()
|
||||||
{
|
{
|
||||||
Win32Input::inputMsgBuffer.enabled = true;
|
|
||||||
|
|
||||||
memset(m_btnState, 0, sizeof(m_btnState) / sizeof(m_btnState[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32Keyboard::isKeyDown(Key::Type key)
|
bool Win32Keyboard::isKeyDown(Keyboard::Key key)
|
||||||
{
|
{
|
||||||
return m_btnState[key];
|
return ::GetAsyncKeyState(keyToWin32[key]) & 0x8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Keyboard::update(InputModule *input)
|
void Win32Keyboard::update(InputModule *input)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < msg_buf.index; i++) {
|
|
||||||
|
|
||||||
MSG msg = msg_buf.messages[i];
|
|
||||||
|
|
||||||
if (msg.message == WM_KILLFOCUS) {
|
|
||||||
|
|
||||||
for(int i = 0; i < Key::NUM_KEYS; i++) {
|
|
||||||
|
|
||||||
if (m_btnState[i]) {
|
|
||||||
InputEvent event(InputEvent::Key);
|
|
||||||
event.key.code = (Key::Type) i;
|
|
||||||
event.key.pressed = msg.message == WM_KEYDOWN;
|
|
||||||
|
|
||||||
m_btnState[i] = false;
|
|
||||||
input->postInputEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.message != WM_KEYDOWN && msg.message != WM_KEYUP) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Key::Type key = deviceToKey[msg.wParam % 0xFF];
|
|
||||||
|
|
||||||
if (key != Key::Unknown) {
|
|
||||||
InputEvent event(InputEvent::Key);
|
|
||||||
event.key.code = key;
|
|
||||||
event.key.pressed = msg.message == WM_KEYDOWN;
|
|
||||||
|
|
||||||
m_btnState[key] = event.key.pressed;
|
|
||||||
input->postInputEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
msg_buf.index = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32Keyboard::handleMessage(MSG message)
|
bool Win32Keyboard::handleMessage(MSG msg, Event& event)
|
||||||
{
|
{
|
||||||
return msg_buf.postMessage(message);
|
Keyboard::Key key = deviceToKey[msg.wParam % 0xFF];
|
||||||
|
|
||||||
|
if (key != Keyboard::Key::Unknown) {
|
||||||
|
event.type = Event::Key;
|
||||||
|
event.key.code = key;
|
||||||
|
event.key.pressed = msg.message == WM_KEYDOWN;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#define PLATFORM_WIN32_KEYBOARD_H
|
#define PLATFORM_WIN32_KEYBOARD_H
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <Spectre/System/Event.h>
|
||||||
#include <Spectre/Input/Keyboard.h>
|
#include <Spectre/Input/Keyboard.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
@ -12,19 +13,14 @@ class Win32Keyboard : public Keyboard
|
||||||
public :
|
public :
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
bool isKeyDown(Key::Type key);
|
bool isKeyDown(Keyboard::Key key);
|
||||||
|
|
||||||
static bool handleMessage(MSG message);
|
// Translate a Win32 Event to sp::Event, Called from Win32EventQueue
|
||||||
|
static bool handleMessage(MSG message, Event& event);
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
void update(InputModule *input);
|
void update(InputModule *input);
|
||||||
|
|
||||||
protected :
|
|
||||||
|
|
||||||
bool m_btnState[Key::NUM_KEYS];
|
|
||||||
|
|
||||||
bool m_hasFocus;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,11 @@
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <Spectre/System/Log.h>
|
#include <Spectre/System/Log.h>
|
||||||
#include <Spectre/Input/InputModule.h>
|
#include <Spectre/Input/InputModule.h>
|
||||||
#include "Win32MsgBuffer.h"
|
|
||||||
#include "Win32Input.h"
|
#include "Win32Input.h"
|
||||||
#include "Win32Mouse.h"
|
#include "Win32Mouse.h"
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
static Win32MsgBuffer msg_buf;
|
|
||||||
|
|
||||||
static Vector2f _normalizePos(int x, int y, RECT area)
|
static Vector2f _normalizePos(int x, int y, RECT area)
|
||||||
{
|
{
|
||||||
Vector2f out;
|
Vector2f out;
|
||||||
|
|
@ -29,8 +26,6 @@ static RECT GetClientArea(HWND hwnd) {
|
||||||
|
|
||||||
void Win32Mouse::init()
|
void Win32Mouse::init()
|
||||||
{
|
{
|
||||||
memset(m_state, 0, MouseButton::NUM_MBUTTONS);
|
|
||||||
m_tracked = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2f Win32Mouse::getPosition() const
|
Vector2f Win32Mouse::getPosition() const
|
||||||
|
|
@ -38,82 +33,104 @@ Vector2f Win32Mouse::getPosition() const
|
||||||
return m_position;
|
return m_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32Mouse::isButtonDown(MouseButton::Type button) const
|
Vector2f Win32Mouse::getAbsPosition() const
|
||||||
{
|
{
|
||||||
return m_state[button];
|
return m_abs_position;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Win32Mouse::isButtonDown(Mouse::Button button) const
|
||||||
|
{
|
||||||
|
int btn;
|
||||||
|
|
||||||
|
switch(button) {
|
||||||
|
case Mouse::Left : btn = GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON; break;
|
||||||
|
case Mouse::Right : btn = GetSystemMetrics(SM_SWAPBUTTON) ? VK_LBUTTON : VK_RBUTTON; break;
|
||||||
|
case Mouse::Middle : btn = VK_MBUTTON; break;
|
||||||
|
case Mouse::Button1 : btn = VK_XBUTTON1; break;
|
||||||
|
case Mouse::Button2 : btn = VK_XBUTTON2; break;
|
||||||
|
default: btn = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ::GetAsyncKeyState(btn) & 0x8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Mouse::update(InputModule *input)
|
void Win32Mouse::update(InputModule *input)
|
||||||
{
|
{
|
||||||
// TODO: Clean this.
|
HWND handle;
|
||||||
for(int i = 0; i < msg_buf.index; i++) {
|
POINT p;
|
||||||
|
|
||||||
MSG msg = msg_buf.messages[i];
|
// Update absolute position
|
||||||
|
GetCursorPos(&p);
|
||||||
|
m_abs_position = Vector2f(p.x, p.y);
|
||||||
|
|
||||||
if (msg.message == WM_LBUTTONDOWN || msg.message == WM_LBUTTONUP) {
|
// Update relative position
|
||||||
InputEvent event(InputEvent::MouseButton);
|
handle = ::GetCapture();
|
||||||
|
if (handle) {
|
||||||
event.mouseButton.button = MouseButton::Left;
|
// Translate position to focued window.
|
||||||
event.mouseButton.pressed = msg.message == WM_LBUTTONDOWN;
|
ScreenToClient(handle, &p);
|
||||||
|
m_position = Vector2f(p.x, p.y);
|
||||||
m_state[MouseButton::Left] = event.mouseButton.pressed;
|
|
||||||
input->postInputEvent(event);
|
|
||||||
} else if (msg.message == WM_RBUTTONDOWN || msg.message == WM_RBUTTONUP) {
|
|
||||||
InputEvent event(InputEvent::MouseButton);
|
|
||||||
|
|
||||||
event.mouseButton.button = MouseButton::Right;
|
|
||||||
event.mouseButton.pressed = msg.message == WM_RBUTTONDOWN;
|
|
||||||
|
|
||||||
m_state[MouseButton::Right] = event.mouseButton.pressed;
|
|
||||||
input->postInputEvent(event);
|
|
||||||
} else if (msg.message == WM_MBUTTONDOWN || msg.message == WM_MBUTTONUP) {
|
|
||||||
InputEvent event(InputEvent::MouseButton);
|
|
||||||
|
|
||||||
event.mouseButton.button = MouseButton::Middle;
|
|
||||||
event.mouseButton.pressed = msg.message == WM_MBUTTONDOWN;
|
|
||||||
|
|
||||||
m_state[MouseButton::Middle] = event.mouseButton.pressed;
|
|
||||||
input->postInputEvent(event);
|
|
||||||
|
|
||||||
} else if (msg.message == WM_XBUTTONDOWN || msg.message == WM_XBUTTONUP) {
|
|
||||||
|
|
||||||
int btn = GET_XBUTTON_WPARAM(msg.wParam);
|
|
||||||
InputEvent event(InputEvent::MouseButton);
|
|
||||||
|
|
||||||
event.mouseButton.button = btn == XBUTTON1 ? MouseButton::Button1 : MouseButton::Button2;
|
|
||||||
event.mouseButton.pressed = msg.message == WM_XBUTTONDOWN;
|
|
||||||
|
|
||||||
m_state[MouseButton::Button1] = event.mouseButton.pressed;
|
|
||||||
input->postInputEvent(event);
|
|
||||||
|
|
||||||
} else if (msg.message == WM_MOUSEMOVE) {
|
|
||||||
|
|
||||||
InputEvent event(InputEvent::MousePosition);
|
|
||||||
RECT area = GetClientArea(msg.hwnd);
|
|
||||||
|
|
||||||
int x = LOWORD(msg.lParam);
|
|
||||||
int y = HIWORD(msg.lParam);
|
|
||||||
|
|
||||||
// Do not forward the message if mouse is outside client area.
|
|
||||||
if ((x < area.left) || (x > area.right) || (y < area.top) || (y > area.bottom)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.mouse.x = x;
|
|
||||||
event.mouse.y = y;
|
|
||||||
|
|
||||||
input->postInputEvent(event);
|
|
||||||
|
|
||||||
m_position = _normalizePos(x, y, area);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_buf.index = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32Mouse::handleMessage(MSG message)
|
bool Win32Mouse::handleMessage(MSG msg, Event& event)
|
||||||
{
|
{
|
||||||
return msg_buf.postMessage(message);
|
switch(msg.message) {
|
||||||
|
case WM_LBUTTONUP :
|
||||||
|
case WM_LBUTTONDOWN :
|
||||||
|
case WM_RBUTTONUP :
|
||||||
|
case WM_RBUTTONDOWN :
|
||||||
|
case WM_MBUTTONUP :
|
||||||
|
case WM_MBUTTONDOWN :
|
||||||
|
case WM_XBUTTONUP :
|
||||||
|
case WM_XBUTTONDOWN :
|
||||||
|
event.type = Event::MouseButton;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(msg.message) {
|
||||||
|
case WM_LBUTTONUP :
|
||||||
|
case WM_LBUTTONDOWN :
|
||||||
|
event.mouseButton.button = Mouse::Button::Left;
|
||||||
|
event.mouseButton.pressed = msg.message == WM_LBUTTONDOWN;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case WM_RBUTTONUP :
|
||||||
|
case WM_RBUTTONDOWN :
|
||||||
|
event.mouseButton.button = Mouse::Button::Right;
|
||||||
|
event.mouseButton.pressed = msg.message == WM_RBUTTONDOWN;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case WM_MBUTTONUP :
|
||||||
|
case WM_MBUTTONDOWN :
|
||||||
|
event.mouseButton.button = Mouse::Button::Right;
|
||||||
|
event.mouseButton.pressed = msg.message == WM_MBUTTONDOWN;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case WM_XBUTTONUP :
|
||||||
|
case WM_XBUTTONDOWN :
|
||||||
|
event.mouseButton.button = GET_XBUTTON_WPARAM(msg.wParam) == XBUTTON1
|
||||||
|
? Mouse::Button::Button1 : Mouse::Button::Button2;
|
||||||
|
event.mouseButton.pressed = msg.message == WM_XBUTTONDOWN;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case WM_MOUSEMOVE :
|
||||||
|
RECT area = GetClientArea(msg.hwnd);
|
||||||
|
int x = LOWORD(msg.lParam);
|
||||||
|
int y = HIWORD(msg.lParam);
|
||||||
|
|
||||||
|
// Do not forward the message if mouse is outside client area.
|
||||||
|
if ( (x < area.left) || (x > area.right)
|
||||||
|
|| (y < area.top) || (y > area.bottom) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.type = Event::MouseMove;
|
||||||
|
event.mouseMove.x = x;
|
||||||
|
event.mouseMove.y = y;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#define PLATFORM_WIN32_MOUSE_H
|
#define PLATFORM_WIN32_MOUSE_H
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <Spectre/System/Event.h>
|
||||||
#include <Spectre/Input/Mouse.h>
|
#include <Spectre/Input/Mouse.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
@ -17,20 +18,22 @@ public :
|
||||||
// Get mouse position
|
// Get mouse position
|
||||||
virtual Vector2f getPosition() const;
|
virtual Vector2f getPosition() const;
|
||||||
|
|
||||||
virtual bool isButtonDown(MouseButton::Type button) const;
|
virtual Vector2f getAbsPosition() const;
|
||||||
|
|
||||||
static bool handleMessage(MSG message);
|
virtual bool isButtonDown(Mouse::Button button) const;
|
||||||
|
|
||||||
|
static bool handleMessage(MSG msg, Event& event);
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
virtual void update(InputModule *input);
|
virtual void update(InputModule *input);
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
// position in relative (focused window) coordinates.
|
||||||
Vector2f m_position;
|
Vector2f m_position;
|
||||||
|
|
||||||
bool m_state[MouseButton::NUM_MBUTTONS];
|
// position in absolute (screen) coordinates.
|
||||||
|
Vector2f m_abs_position;
|
||||||
bool m_tracked;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
|
|
||||||
#include <Spectre/System/Log.h>
|
|
||||||
#include "Win32MsgBuffer.h"
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
Win32MsgBuffer::Win32MsgBuffer() :
|
|
||||||
index (0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Win32MsgBuffer::postMessage(MSG msg)
|
|
||||||
{
|
|
||||||
if (index < WIN32_MSG_BUFFER_MAX_SIZE) {
|
|
||||||
messages[index++] = msg;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Log::warn("Win32MsgBuffer: Queue overflow\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
|
|
||||||
#ifndef PLATFORM_WIN32_MSG_BUFFER_H
|
|
||||||
#define PLATFORM_WIN32_MSG_BUFFER_H
|
|
||||||
|
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
#define WIN32_MSG_BUFFER_MAX_SIZE 64
|
|
||||||
|
|
||||||
struct Win32MsgBuffer {
|
|
||||||
int index;
|
|
||||||
MSG messages[WIN32_MSG_BUFFER_MAX_SIZE];
|
|
||||||
|
|
||||||
Win32MsgBuffer();
|
|
||||||
|
|
||||||
bool postMessage(MSG msg);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
||||||
#endif /* PLATFORM_WIN32_MSG_BUFFER_H */
|
|
||||||
|
|
@ -14,6 +14,11 @@
|
||||||
|
|
||||||
#endif /* GLAD_IMPL_UTIL_C_ */
|
#endif /* GLAD_IMPL_UTIL_C_ */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int GLAD_WGL_VERSION_1_0 = 0;
|
int GLAD_WGL_VERSION_1_0 = 0;
|
||||||
int GLAD_WGL_ARB_create_context = 0;
|
int GLAD_WGL_ARB_create_context = 0;
|
||||||
|
|
@ -32,21 +37,21 @@ PFNWGLSWAPINTERVALEXTPROC glad_wglSwapIntervalEXT = NULL;
|
||||||
|
|
||||||
|
|
||||||
static void glad_wgl_load_WGL_ARB_create_context(GLADuserptrloadfunc load, void *userptr) {
|
static void glad_wgl_load_WGL_ARB_create_context(GLADuserptrloadfunc load, void *userptr) {
|
||||||
if (!GLAD_WGL_ARB_create_context) return;
|
if(!GLAD_WGL_ARB_create_context) return;
|
||||||
glad_wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)load(userptr, "wglCreateContextAttribsARB");
|
glad_wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) load(userptr, "wglCreateContextAttribsARB");
|
||||||
}
|
}
|
||||||
static void glad_wgl_load_WGL_ARB_extensions_string(GLADuserptrloadfunc load, void *userptr) {
|
static void glad_wgl_load_WGL_ARB_extensions_string(GLADuserptrloadfunc load, void *userptr) {
|
||||||
if (!GLAD_WGL_ARB_extensions_string) return;
|
if(!GLAD_WGL_ARB_extensions_string) return;
|
||||||
glad_wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)load(userptr, "wglGetExtensionsStringARB");
|
glad_wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) load(userptr, "wglGetExtensionsStringARB");
|
||||||
}
|
}
|
||||||
static void glad_wgl_load_WGL_EXT_extensions_string(GLADuserptrloadfunc load, void *userptr) {
|
static void glad_wgl_load_WGL_EXT_extensions_string(GLADuserptrloadfunc load, void *userptr) {
|
||||||
if (!GLAD_WGL_EXT_extensions_string) return;
|
if(!GLAD_WGL_EXT_extensions_string) return;
|
||||||
glad_wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)load(userptr, "wglGetExtensionsStringEXT");
|
glad_wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC) load(userptr, "wglGetExtensionsStringEXT");
|
||||||
}
|
}
|
||||||
static void glad_wgl_load_WGL_EXT_swap_control(GLADuserptrloadfunc load, void *userptr) {
|
static void glad_wgl_load_WGL_EXT_swap_control(GLADuserptrloadfunc load, void *userptr) {
|
||||||
if (!GLAD_WGL_EXT_swap_control) return;
|
if(!GLAD_WGL_EXT_swap_control) return;
|
||||||
glad_wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC)load(userptr, "wglGetSwapIntervalEXT");
|
glad_wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC) load(userptr, "wglGetSwapIntervalEXT");
|
||||||
glad_wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)load(userptr, "wglSwapIntervalEXT");
|
glad_wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) load(userptr, "wglSwapIntervalEXT");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -54,85 +59,93 @@ static void glad_wgl_resolve_aliases(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int glad_wgl_has_extension(HDC hdc, const char *ext) {
|
static int glad_wgl_has_extension(HDC hdc, const char *ext) {
|
||||||
const char *terminator;
|
const char *terminator;
|
||||||
const char *loc;
|
const char *loc;
|
||||||
const char *extensions;
|
const char *extensions;
|
||||||
|
|
||||||
if (wglGetExtensionsStringEXT == NULL && wglGetExtensionsStringARB == NULL)
|
if(wglGetExtensionsStringEXT == NULL && wglGetExtensionsStringARB == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (wglGetExtensionsStringARB == NULL || hdc == INVALID_HANDLE_VALUE)
|
if(wglGetExtensionsStringARB == NULL || hdc == INVALID_HANDLE_VALUE)
|
||||||
extensions = wglGetExtensionsStringEXT();
|
extensions = wglGetExtensionsStringEXT();
|
||||||
else
|
else
|
||||||
extensions = wglGetExtensionsStringARB(hdc);
|
extensions = wglGetExtensionsStringARB(hdc);
|
||||||
|
|
||||||
if (extensions == NULL || ext == NULL)
|
if(extensions == NULL || ext == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while (1) {
|
while(1) {
|
||||||
loc = strstr(extensions, ext);
|
loc = strstr(extensions, ext);
|
||||||
if (loc == NULL)
|
if(loc == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
terminator = loc + strlen(ext);
|
terminator = loc + strlen(ext);
|
||||||
if ((loc == extensions || *(loc - 1) == ' ') &&
|
if((loc == extensions || *(loc - 1) == ' ') &&
|
||||||
(*terminator == ' ' || *terminator == '\0'))
|
(*terminator == ' ' || *terminator == '\0'))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
extensions = terminator;
|
extensions = terminator;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLADapiproc glad_wgl_get_proc_from_userptr(void *userptr, const char* name) {
|
static GLADapiproc glad_wgl_get_proc_from_userptr(void *userptr, const char* name) {
|
||||||
|
return (GLAD_GNUC_EXTENSION (GLADapiproc (*)(const char *name)) userptr)(name);
|
||||||
return (GLAD_GNUC_EXTENSION(GLADapiproc(*)(const char *name)) userptr)(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int glad_wgl_find_extensions_wgl(HDC hdc) {
|
static int glad_wgl_find_extensions_wgl(HDC hdc) {
|
||||||
GLAD_WGL_ARB_create_context = glad_wgl_has_extension(hdc, "WGL_ARB_create_context");
|
GLAD_WGL_ARB_create_context = glad_wgl_has_extension(hdc, "WGL_ARB_create_context");
|
||||||
GLAD_WGL_ARB_create_context_profile = glad_wgl_has_extension(hdc, "WGL_ARB_create_context_profile");
|
GLAD_WGL_ARB_create_context_profile = glad_wgl_has_extension(hdc, "WGL_ARB_create_context_profile");
|
||||||
GLAD_WGL_ARB_extensions_string = glad_wgl_has_extension(hdc, "WGL_ARB_extensions_string");
|
GLAD_WGL_ARB_extensions_string = glad_wgl_has_extension(hdc, "WGL_ARB_extensions_string");
|
||||||
GLAD_WGL_EXT_extensions_string = glad_wgl_has_extension(hdc, "WGL_EXT_extensions_string");
|
GLAD_WGL_EXT_extensions_string = glad_wgl_has_extension(hdc, "WGL_EXT_extensions_string");
|
||||||
GLAD_WGL_EXT_swap_control = glad_wgl_has_extension(hdc, "WGL_EXT_swap_control");
|
GLAD_WGL_EXT_swap_control = glad_wgl_has_extension(hdc, "WGL_EXT_swap_control");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int glad_wgl_find_core_wgl(void) {
|
static int glad_wgl_find_core_wgl(void) {
|
||||||
int major = 1, minor = 0;
|
int major = 1, minor = 0;
|
||||||
GLAD_WGL_VERSION_1_0 = (major == 1 && minor >= 0) || major > 1;
|
GLAD_WGL_VERSION_1_0 = (major == 1 && minor >= 0) || major > 1;
|
||||||
return GLAD_MAKE_VERSION(major, minor);
|
return GLAD_MAKE_VERSION(major, minor);
|
||||||
}
|
}
|
||||||
|
|
||||||
int gladLoadWGLUserPtr(HDC hdc, GLADuserptrloadfunc load, void *userptr) {
|
int gladLoadWGLUserPtr(HDC hdc, GLADuserptrloadfunc load, void *userptr) {
|
||||||
int version;
|
int version;
|
||||||
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)load(userptr, "wglGetExtensionsStringARB");
|
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) load(userptr, "wglGetExtensionsStringARB");
|
||||||
wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)load(userptr, "wglGetExtensionsStringEXT");
|
wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC) load(userptr, "wglGetExtensionsStringEXT");
|
||||||
if (wglGetExtensionsStringARB == NULL && wglGetExtensionsStringEXT == NULL) return 0;
|
if(wglGetExtensionsStringARB == NULL && wglGetExtensionsStringEXT == NULL) return 0;
|
||||||
version = glad_wgl_find_core_wgl();
|
version = glad_wgl_find_core_wgl();
|
||||||
|
|
||||||
|
|
||||||
if (!glad_wgl_find_extensions_wgl(hdc)) return 0;
|
if (!glad_wgl_find_extensions_wgl(hdc)) return 0;
|
||||||
glad_wgl_load_WGL_ARB_create_context(load, userptr);
|
glad_wgl_load_WGL_ARB_create_context(load, userptr);
|
||||||
glad_wgl_load_WGL_ARB_extensions_string(load, userptr);
|
glad_wgl_load_WGL_ARB_extensions_string(load, userptr);
|
||||||
glad_wgl_load_WGL_EXT_extensions_string(load, userptr);
|
glad_wgl_load_WGL_EXT_extensions_string(load, userptr);
|
||||||
glad_wgl_load_WGL_EXT_swap_control(load, userptr);
|
glad_wgl_load_WGL_EXT_swap_control(load, userptr);
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gladLoadWGL(HDC hdc, GLADloadfunc load) {
|
int gladLoadWGL(HDC hdc, GLADloadfunc load) {
|
||||||
return gladLoadWGLUserPtr(hdc, glad_wgl_get_proc_from_userptr, GLAD_GNUC_EXTENSION(void*) load);
|
return gladLoadWGLUserPtr(hdc, glad_wgl_get_proc_from_userptr, GLAD_GNUC_EXTENSION (void*) load);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef GLAD_WGL
|
#ifdef GLAD_WGL
|
||||||
|
|
||||||
|
static GLADapiproc glad_wgl_get_proc(void *vuserptr, const char* name) {
|
||||||
|
(void) vuserptr;
|
||||||
|
return GLAD_GNUC_EXTENSION (GLADapiproc) wglGetProcAddress(name);
|
||||||
|
}
|
||||||
|
|
||||||
int gladLoaderLoadWGL(HDC hdc) {
|
int gladLoaderLoadWGL(HDC hdc) {
|
||||||
return gladLoadWGLUserPtr(hdc, glad_wgl_get_proc_from_userptr, GLAD_GNUC_EXTENSION(void*) wglGetProcAddress);
|
return gladLoadWGLUserPtr(hdc, glad_wgl_get_proc, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* GLAD_WGL */
|
#endif /* GLAD_WGL */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,29 @@
|
||||||
/**
|
/**
|
||||||
* Loader generated by glad 2.0.0-beta on Sun Dec 22 19:55:16 2019
|
* Loader generated by glad 2.0.0-beta on Mon Sep 21 17:37:19 2020
|
||||||
*
|
*
|
||||||
* Generator: C/C++
|
* Generator: C/C++
|
||||||
* Specification: wgl
|
* Specification: wgl
|
||||||
* Extensions: 5
|
* Extensions: 5
|
||||||
*
|
*
|
||||||
* APIs:
|
* APIs:
|
||||||
* - wgl=1.0
|
* - wgl=1.0
|
||||||
*
|
*
|
||||||
* Options:
|
* Options:
|
||||||
* - MX_GLOBAL = False
|
* - MX_GLOBAL = False
|
||||||
* - ON_DEMAND = False
|
* - ON_DEMAND = False
|
||||||
* - LOADER = True
|
* - LOADER = True
|
||||||
* - ALIAS = True
|
* - ALIAS = True
|
||||||
* - HEADER_ONLY = False
|
* - HEADER_ONLY = False
|
||||||
* - DEBUG = False
|
* - DEBUG = False
|
||||||
* - MX = False
|
* - MX = False
|
||||||
*
|
*
|
||||||
* Commandline:
|
* Commandline:
|
||||||
* --api='wgl=1.0' --extensions='WGL_ARB_create_context,WGL_ARB_create_context_profile,WGL_ARB_extensions_string,WGL_EXT_extensions_string,WGL_EXT_swap_control' c --loader --alias
|
* --api='wgl=1.0' --extensions='WGL_ARB_create_context,WGL_ARB_create_context_profile,WGL_ARB_extensions_string,WGL_EXT_extensions_string,WGL_EXT_swap_control' c --loader --alias
|
||||||
*
|
*
|
||||||
* Online:
|
* Online:
|
||||||
* http://glad.sh/#api=wgl%3D1.0&extensions=WGL_ARB_create_context%2CWGL_ARB_create_context_profile%2CWGL_ARB_extensions_string%2CWGL_EXT_extensions_string%2CWGL_EXT_swap_control&generator=c&options=LOADER%2CALIAS
|
* http://glad.sh/#api=wgl%3D1.0&extensions=WGL_ARB_create_context%2CWGL_ARB_create_context_profile%2CWGL_ARB_extensions_string%2CWGL_EXT_extensions_string%2CWGL_EXT_swap_control&generator=c&options=LOADER%2CALIAS
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef GLAD_WGL_H_
|
#ifndef GLAD_WGL_H_
|
||||||
#define GLAD_WGL_H_
|
#define GLAD_WGL_H_
|
||||||
|
|
@ -43,90 +43,90 @@ extern "C" {
|
||||||
#define GLAD_PLATFORM_H_
|
#define GLAD_PLATFORM_H_
|
||||||
|
|
||||||
#ifndef GLAD_PLATFORM_WIN32
|
#ifndef GLAD_PLATFORM_WIN32
|
||||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__MINGW32__)
|
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__MINGW32__)
|
||||||
#define GLAD_PLATFORM_WIN32 1
|
#define GLAD_PLATFORM_WIN32 1
|
||||||
#else
|
#else
|
||||||
#define GLAD_PLATFORM_WIN32 0
|
#define GLAD_PLATFORM_WIN32 0
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GLAD_PLATFORM_APPLE
|
#ifndef GLAD_PLATFORM_APPLE
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#define GLAD_PLATFORM_APPLE 1
|
#define GLAD_PLATFORM_APPLE 1
|
||||||
#else
|
#else
|
||||||
#define GLAD_PLATFORM_APPLE 0
|
#define GLAD_PLATFORM_APPLE 0
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GLAD_PLATFORM_EMSCRIPTEN
|
#ifndef GLAD_PLATFORM_EMSCRIPTEN
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
#define GLAD_PLATFORM_EMSCRIPTEN 1
|
#define GLAD_PLATFORM_EMSCRIPTEN 1
|
||||||
#else
|
#else
|
||||||
#define GLAD_PLATFORM_EMSCRIPTEN 0
|
#define GLAD_PLATFORM_EMSCRIPTEN 0
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GLAD_PLATFORM_UWP
|
#ifndef GLAD_PLATFORM_UWP
|
||||||
#if defined(_MSC_VER) && !defined(GLAD_INTERNAL_HAVE_WINAPIFAMILY)
|
#if defined(_MSC_VER) && !defined(GLAD_INTERNAL_HAVE_WINAPIFAMILY)
|
||||||
#ifdef __has_include
|
#ifdef __has_include
|
||||||
#if __has_include(<winapifamily.h>)
|
#if __has_include(<winapifamily.h>)
|
||||||
#define GLAD_INTERNAL_HAVE_WINAPIFAMILY 1
|
#define GLAD_INTERNAL_HAVE_WINAPIFAMILY 1
|
||||||
#endif
|
#endif
|
||||||
#elif _MSC_VER >= 1700 && !_USING_V110_SDK71_
|
#elif _MSC_VER >= 1700 && !_USING_V110_SDK71_
|
||||||
#define GLAD_INTERNAL_HAVE_WINAPIFAMILY 1
|
#define GLAD_INTERNAL_HAVE_WINAPIFAMILY 1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GLAD_INTERNAL_HAVE_WINAPIFAMILY
|
#ifdef GLAD_INTERNAL_HAVE_WINAPIFAMILY
|
||||||
#include <winapifamily.h>
|
#include <winapifamily.h>
|
||||||
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
|
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
|
||||||
#define GLAD_PLATFORM_UWP 1
|
#define GLAD_PLATFORM_UWP 1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GLAD_PLATFORM_UWP
|
#ifndef GLAD_PLATFORM_UWP
|
||||||
#define GLAD_PLATFORM_UWP 0
|
#define GLAD_PLATFORM_UWP 0
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define GLAD_GNUC_EXTENSION __extension__
|
#define GLAD_GNUC_EXTENSION __extension__
|
||||||
#else
|
#else
|
||||||
#define GLAD_GNUC_EXTENSION
|
#define GLAD_GNUC_EXTENSION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GLAD_API_CALL
|
#ifndef GLAD_API_CALL
|
||||||
#if defined(GLAD_API_CALL_EXPORT)
|
#if defined(GLAD_API_CALL_EXPORT)
|
||||||
#if GLAD_PLATFORM_WIN32 || defined(__CYGWIN__)
|
#if GLAD_PLATFORM_WIN32 || defined(__CYGWIN__)
|
||||||
#if defined(GLAD_API_CALL_EXPORT_BUILD)
|
#if defined(GLAD_API_CALL_EXPORT_BUILD)
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
#define GLAD_API_CALL __attribute__ ((dllexport)) extern
|
#define GLAD_API_CALL __attribute__ ((dllexport)) extern
|
||||||
#else
|
#else
|
||||||
#define GLAD_API_CALL __declspec(dllexport) extern
|
#define GLAD_API_CALL __declspec(dllexport) extern
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
#define GLAD_API_CALL __attribute__ ((dllimport)) extern
|
#define GLAD_API_CALL __attribute__ ((dllimport)) extern
|
||||||
#else
|
#else
|
||||||
#define GLAD_API_CALL __declspec(dllimport) extern
|
#define GLAD_API_CALL __declspec(dllimport) extern
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#elif defined(__GNUC__) && defined(GLAD_API_CALL_EXPORT_BUILD)
|
#elif defined(__GNUC__) && defined(GLAD_API_CALL_EXPORT_BUILD)
|
||||||
#define GLAD_API_CALL __attribute__ ((visibility ("default"))) extern
|
#define GLAD_API_CALL __attribute__ ((visibility ("default"))) extern
|
||||||
#else
|
#else
|
||||||
#define GLAD_API_CALL extern
|
#define GLAD_API_CALL extern
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define GLAD_API_CALL extern
|
#define GLAD_API_CALL extern
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef APIENTRY
|
#ifdef APIENTRY
|
||||||
#define GLAD_API_PTR APIENTRY
|
#define GLAD_API_PTR APIENTRY
|
||||||
#elif GLAD_PLATFORM_WIN32
|
#elif GLAD_PLATFORM_WIN32
|
||||||
#define GLAD_API_PTR __stdcall
|
#define GLAD_API_PTR __stdcall
|
||||||
#else
|
#else
|
||||||
#define GLAD_API_PTR
|
#define GLAD_API_PTR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GLAPI
|
#ifndef GLAPI
|
||||||
|
|
@ -143,13 +143,13 @@ extern "C" {
|
||||||
|
|
||||||
#define GLAD_GENERATOR_VERSION "2.0.0-beta"
|
#define GLAD_GENERATOR_VERSION "2.0.0-beta"
|
||||||
|
|
||||||
typedef void(*GLADapiproc)(void);
|
typedef void (*GLADapiproc)(void);
|
||||||
|
|
||||||
typedef GLADapiproc(*GLADloadfunc)(const char *name);
|
typedef GLADapiproc (*GLADloadfunc)(const char *name);
|
||||||
typedef GLADapiproc(*GLADuserptrloadfunc)(void *userptr, const char *name);
|
typedef GLADapiproc (*GLADuserptrloadfunc)(void *userptr, const char *name);
|
||||||
|
|
||||||
typedef void(*GLADprecallback)(const char *name, GLADapiproc apiproc, int len_args, ...);
|
typedef void (*GLADprecallback)(const char *name, GLADapiproc apiproc, int len_args, ...);
|
||||||
typedef void(*GLADpostcallback)(void *ret, const char *name, GLADapiproc apiproc, int len_args, ...);
|
typedef void (*GLADpostcallback)(void *ret, const char *name, GLADapiproc apiproc, int len_args, ...);
|
||||||
|
|
||||||
#endif /* GLAD_PLATFORM_H_ */
|
#endif /* GLAD_PLATFORM_H_ */
|
||||||
|
|
||||||
|
|
@ -229,91 +229,101 @@ extern "C" {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct _GPU_DEVICE {
|
struct _GPU_DEVICE {
|
||||||
DWORD cb;
|
DWORD cb;
|
||||||
CHAR DeviceName[32];
|
CHAR DeviceName[32];
|
||||||
CHAR DeviceString[128];
|
CHAR DeviceString[128];
|
||||||
DWORD Flags;
|
DWORD Flags;
|
||||||
RECT rcVirtualScreen;
|
RECT rcVirtualScreen;
|
||||||
};
|
};
|
||||||
DECLARE_HANDLE(HPBUFFERARB);
|
|
||||||
DECLARE_HANDLE(HPBUFFEREXT);
|
DECLARE_HANDLE(HPBUFFERARB);
|
||||||
DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV);
|
|
||||||
DECLARE_HANDLE(HPVIDEODEV);
|
DECLARE_HANDLE(HPBUFFEREXT);
|
||||||
DECLARE_HANDLE(HPGPUNV);
|
|
||||||
DECLARE_HANDLE(HGPUNV);
|
DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV);
|
||||||
DECLARE_HANDLE(HVIDEOINPUTDEVICENV);
|
|
||||||
typedef struct _GPU_DEVICE GPU_DEVICE;
|
DECLARE_HANDLE(HPVIDEODEV);
|
||||||
typedef struct _GPU_DEVICE *PGPU_DEVICE;
|
|
||||||
|
DECLARE_HANDLE(HPGPUNV);
|
||||||
|
|
||||||
|
DECLARE_HANDLE(HGPUNV);
|
||||||
|
|
||||||
|
DECLARE_HANDLE(HVIDEOINPUTDEVICENV);
|
||||||
|
|
||||||
|
typedef struct _GPU_DEVICE GPU_DEVICE;
|
||||||
|
|
||||||
|
typedef struct _GPU_DEVICE *PGPU_DEVICE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define WGL_VERSION_1_0 1
|
#define WGL_VERSION_1_0 1
|
||||||
GLAD_API_CALL int GLAD_WGL_VERSION_1_0;
|
GLAD_API_CALL int GLAD_WGL_VERSION_1_0;
|
||||||
#define WGL_ARB_create_context 1
|
#define WGL_ARB_create_context 1
|
||||||
GLAD_API_CALL int GLAD_WGL_ARB_create_context;
|
GLAD_API_CALL int GLAD_WGL_ARB_create_context;
|
||||||
#define WGL_ARB_create_context_profile 1
|
#define WGL_ARB_create_context_profile 1
|
||||||
GLAD_API_CALL int GLAD_WGL_ARB_create_context_profile;
|
GLAD_API_CALL int GLAD_WGL_ARB_create_context_profile;
|
||||||
#define WGL_ARB_extensions_string 1
|
#define WGL_ARB_extensions_string 1
|
||||||
GLAD_API_CALL int GLAD_WGL_ARB_extensions_string;
|
GLAD_API_CALL int GLAD_WGL_ARB_extensions_string;
|
||||||
#define WGL_EXT_extensions_string 1
|
#define WGL_EXT_extensions_string 1
|
||||||
GLAD_API_CALL int GLAD_WGL_EXT_extensions_string;
|
GLAD_API_CALL int GLAD_WGL_EXT_extensions_string;
|
||||||
#define WGL_EXT_swap_control 1
|
#define WGL_EXT_swap_control 1
|
||||||
GLAD_API_CALL int GLAD_WGL_EXT_swap_control;
|
GLAD_API_CALL int GLAD_WGL_EXT_swap_control;
|
||||||
|
|
||||||
|
|
||||||
typedef int (GLAD_API_PTR *PFNCHOOSEPIXELFORMATPROC)(HDC hDc, const PIXELFORMATDESCRIPTOR * pPfd);
|
typedef int (GLAD_API_PTR *PFNCHOOSEPIXELFORMATPROC)(HDC hDc, const PIXELFORMATDESCRIPTOR * pPfd);
|
||||||
typedef int (GLAD_API_PTR *PFNDESCRIBEPIXELFORMATPROC)(HDC hdc, int ipfd, UINT cjpfd, const PIXELFORMATDESCRIPTOR * ppfd);
|
typedef int (GLAD_API_PTR *PFNDESCRIBEPIXELFORMATPROC)(HDC hdc, int ipfd, UINT cjpfd, const PIXELFORMATDESCRIPTOR * ppfd);
|
||||||
typedef UINT(GLAD_API_PTR *PFNGETENHMETAFILEPIXELFORMATPROC)(HENHMETAFILE hemf, const PIXELFORMATDESCRIPTOR * ppfd);
|
typedef UINT (GLAD_API_PTR *PFNGETENHMETAFILEPIXELFORMATPROC)(HENHMETAFILE hemf, const PIXELFORMATDESCRIPTOR * ppfd);
|
||||||
typedef int (GLAD_API_PTR *PFNGETPIXELFORMATPROC)(HDC hdc);
|
typedef int (GLAD_API_PTR *PFNGETPIXELFORMATPROC)(HDC hdc);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNSETPIXELFORMATPROC)(HDC hdc, int ipfd, const PIXELFORMATDESCRIPTOR * ppfd);
|
typedef BOOL (GLAD_API_PTR *PFNSETPIXELFORMATPROC)(HDC hdc, int ipfd, const PIXELFORMATDESCRIPTOR * ppfd);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNSWAPBUFFERSPROC)(HDC hdc);
|
typedef BOOL (GLAD_API_PTR *PFNSWAPBUFFERSPROC)(HDC hdc);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLCOPYCONTEXTPROC)(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask);
|
typedef BOOL (GLAD_API_PTR *PFNWGLCOPYCONTEXTPROC)(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask);
|
||||||
typedef HGLRC(GLAD_API_PTR *PFNWGLCREATECONTEXTPROC)(HDC hDc);
|
typedef HGLRC (GLAD_API_PTR *PFNWGLCREATECONTEXTPROC)(HDC hDc);
|
||||||
typedef HGLRC(GLAD_API_PTR *PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC hDC, HGLRC hShareContext, const int * attribList);
|
typedef HGLRC (GLAD_API_PTR *PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC hDC, HGLRC hShareContext, const int * attribList);
|
||||||
typedef HGLRC(GLAD_API_PTR *PFNWGLCREATELAYERCONTEXTPROC)(HDC hDc, int level);
|
typedef HGLRC (GLAD_API_PTR *PFNWGLCREATELAYERCONTEXTPROC)(HDC hDc, int level);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLDELETECONTEXTPROC)(HGLRC oldContext);
|
typedef BOOL (GLAD_API_PTR *PFNWGLDELETECONTEXTPROC)(HGLRC oldContext);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLDESCRIBELAYERPLANEPROC)(HDC hDc, int pixelFormat, int layerPlane, UINT nBytes, const LAYERPLANEDESCRIPTOR * plpd);
|
typedef BOOL (GLAD_API_PTR *PFNWGLDESCRIBELAYERPLANEPROC)(HDC hDc, int pixelFormat, int layerPlane, UINT nBytes, const LAYERPLANEDESCRIPTOR * plpd);
|
||||||
typedef HGLRC(GLAD_API_PTR *PFNWGLGETCURRENTCONTEXTPROC)(void);
|
typedef HGLRC (GLAD_API_PTR *PFNWGLGETCURRENTCONTEXTPROC)(void);
|
||||||
typedef HDC(GLAD_API_PTR *PFNWGLGETCURRENTDCPROC)(void);
|
typedef HDC (GLAD_API_PTR *PFNWGLGETCURRENTDCPROC)(void);
|
||||||
typedef const char * (GLAD_API_PTR *PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC hdc);
|
typedef const char * (GLAD_API_PTR *PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC hdc);
|
||||||
typedef const char * (GLAD_API_PTR *PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void);
|
typedef const char * (GLAD_API_PTR *PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void);
|
||||||
typedef int (GLAD_API_PTR *PFNWGLGETLAYERPALETTEENTRIESPROC)(HDC hdc, int iLayerPlane, int iStart, int cEntries, const COLORREF * pcr);
|
typedef int (GLAD_API_PTR *PFNWGLGETLAYERPALETTEENTRIESPROC)(HDC hdc, int iLayerPlane, int iStart, int cEntries, const COLORREF * pcr);
|
||||||
typedef PROC(GLAD_API_PTR *PFNWGLGETPROCADDRESSPROC)(LPCSTR lpszProc);
|
typedef PROC (GLAD_API_PTR *PFNWGLGETPROCADDRESSPROC)(LPCSTR lpszProc);
|
||||||
typedef int (GLAD_API_PTR *PFNWGLGETSWAPINTERVALEXTPROC)(void);
|
typedef int (GLAD_API_PTR *PFNWGLGETSWAPINTERVALEXTPROC)(void);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLMAKECURRENTPROC)(HDC hDc, HGLRC newContext);
|
typedef BOOL (GLAD_API_PTR *PFNWGLMAKECURRENTPROC)(HDC hDc, HGLRC newContext);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLREALIZELAYERPALETTEPROC)(HDC hdc, int iLayerPlane, BOOL bRealize);
|
typedef BOOL (GLAD_API_PTR *PFNWGLREALIZELAYERPALETTEPROC)(HDC hdc, int iLayerPlane, BOOL bRealize);
|
||||||
typedef int (GLAD_API_PTR *PFNWGLSETLAYERPALETTEENTRIESPROC)(HDC hdc, int iLayerPlane, int iStart, int cEntries, const COLORREF * pcr);
|
typedef int (GLAD_API_PTR *PFNWGLSETLAYERPALETTEENTRIESPROC)(HDC hdc, int iLayerPlane, int iStart, int cEntries, const COLORREF * pcr);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLSHARELISTSPROC)(HGLRC hrcSrvShare, HGLRC hrcSrvSource);
|
typedef BOOL (GLAD_API_PTR *PFNWGLSHARELISTSPROC)(HGLRC hrcSrvShare, HGLRC hrcSrvSource);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLSWAPINTERVALEXTPROC)(int interval);
|
typedef BOOL (GLAD_API_PTR *PFNWGLSWAPINTERVALEXTPROC)(int interval);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLSWAPLAYERBUFFERSPROC)(HDC hdc, UINT fuFlags);
|
typedef BOOL (GLAD_API_PTR *PFNWGLSWAPLAYERBUFFERSPROC)(HDC hdc, UINT fuFlags);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLUSEFONTBITMAPSPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase);
|
typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTBITMAPSPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLUSEFONTBITMAPSAPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase);
|
typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTBITMAPSAPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLUSEFONTBITMAPSWPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase);
|
typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTBITMAPSWPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLUSEFONTOUTLINESPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf);
|
typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTOUTLINESPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLUSEFONTOUTLINESAPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf);
|
typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTOUTLINESAPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf);
|
||||||
typedef BOOL(GLAD_API_PTR *PFNWGLUSEFONTOUTLINESWPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf);
|
typedef BOOL (GLAD_API_PTR *PFNWGLUSEFONTOUTLINESWPROC)(HDC hDC, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf);
|
||||||
|
|
||||||
GLAD_API_CALL PFNWGLCREATECONTEXTATTRIBSARBPROC glad_wglCreateContextAttribsARB;
|
GLAD_API_CALL PFNWGLCREATECONTEXTATTRIBSARBPROC glad_wglCreateContextAttribsARB;
|
||||||
#define wglCreateContextAttribsARB glad_wglCreateContextAttribsARB
|
#define wglCreateContextAttribsARB glad_wglCreateContextAttribsARB
|
||||||
GLAD_API_CALL PFNWGLGETEXTENSIONSSTRINGARBPROC glad_wglGetExtensionsStringARB;
|
GLAD_API_CALL PFNWGLGETEXTENSIONSSTRINGARBPROC glad_wglGetExtensionsStringARB;
|
||||||
#define wglGetExtensionsStringARB glad_wglGetExtensionsStringARB
|
#define wglGetExtensionsStringARB glad_wglGetExtensionsStringARB
|
||||||
GLAD_API_CALL PFNWGLGETEXTENSIONSSTRINGEXTPROC glad_wglGetExtensionsStringEXT;
|
GLAD_API_CALL PFNWGLGETEXTENSIONSSTRINGEXTPROC glad_wglGetExtensionsStringEXT;
|
||||||
#define wglGetExtensionsStringEXT glad_wglGetExtensionsStringEXT
|
#define wglGetExtensionsStringEXT glad_wglGetExtensionsStringEXT
|
||||||
GLAD_API_CALL PFNWGLGETSWAPINTERVALEXTPROC glad_wglGetSwapIntervalEXT;
|
GLAD_API_CALL PFNWGLGETSWAPINTERVALEXTPROC glad_wglGetSwapIntervalEXT;
|
||||||
#define wglGetSwapIntervalEXT glad_wglGetSwapIntervalEXT
|
#define wglGetSwapIntervalEXT glad_wglGetSwapIntervalEXT
|
||||||
GLAD_API_CALL PFNWGLSWAPINTERVALEXTPROC glad_wglSwapIntervalEXT;
|
GLAD_API_CALL PFNWGLSWAPINTERVALEXTPROC glad_wglSwapIntervalEXT;
|
||||||
#define wglSwapIntervalEXT glad_wglSwapIntervalEXT
|
#define wglSwapIntervalEXT glad_wglSwapIntervalEXT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GLAD_API_CALL int gladLoadWGLUserPtr(HDC hdc, GLADuserptrloadfunc load, void *userptr);
|
GLAD_API_CALL int gladLoadWGLUserPtr(HDC hdc, GLADuserptrloadfunc load, void *userptr);
|
||||||
GLAD_API_CALL int gladLoadWGL(HDC hdc, GLADloadfunc load);
|
GLAD_API_CALL int gladLoadWGL(HDC hdc, GLADloadfunc load);
|
||||||
|
|
||||||
#ifdef GLAD_WGL
|
#ifdef GLAD_WGL
|
||||||
|
|
||||||
GLAD_API_CALL int gladLoaderLoadWGL(HDC hdc);
|
GLAD_API_CALL int gladLoaderLoadWGL(HDC hdc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
56
source/System/Event.cpp
Normal file
56
source/System/Event.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
|
||||||
|
#include <Spectre/System/Event.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
Event::Event(Type type) :
|
||||||
|
type (type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Event::KeyEvent::getKeyName() const
|
||||||
|
{
|
||||||
|
return Keyboard::getKeyName(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Event::MouseButtonEvent::getName() const
|
||||||
|
{
|
||||||
|
return Mouse::getButtonName(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper methods
|
||||||
|
|
||||||
|
Event Event::createSize(Display *display, int width, int height)
|
||||||
|
{
|
||||||
|
Event event(Size);
|
||||||
|
event.size.display = display;
|
||||||
|
event.size.width = width;
|
||||||
|
event.size.height = height;
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
Event Event::createKey(Keyboard::Key code, bool pressed)
|
||||||
|
{
|
||||||
|
Event event(Key);
|
||||||
|
event.key.code = code;
|
||||||
|
event.key.pressed = pressed;
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
Event Event::createMouseButton(Mouse::Button button, bool pressed)
|
||||||
|
{
|
||||||
|
Event event(MouseButton);
|
||||||
|
event.mouseButton.button = button;
|
||||||
|
event.mouseButton.pressed = pressed;
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
Event Event::createMouseMove(unsigned int x, unsigned int y)
|
||||||
|
{
|
||||||
|
Event event(MouseMove);
|
||||||
|
event.mouseMove.x = x;
|
||||||
|
event.mouseMove.y = y;
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
14
source/System/EventListener.cpp
Normal file
14
source/System/EventListener.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include <Spectre/Display/Display.h>
|
||||||
|
#include <Spectre/System/EventListener.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
void EventListener::onSizeChanged(Display* display, int width, int height)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventListener::onEvent(const Event& event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
@ -4,8 +4,42 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
void MessageHandler::registerListener(EventListener *listener)
|
||||||
|
{
|
||||||
|
for(auto it = m_listeners.begin(); it != m_listeners.end(); it++) {
|
||||||
|
|
||||||
|
if (listener == *it) {
|
||||||
|
// Already in vector. nothing to do.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_listeners.push_back(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageHandler::unregisterListener(EventListener *listener)
|
||||||
|
{
|
||||||
|
for(auto it = m_listeners.begin(); it != m_listeners.end(); it++) {
|
||||||
|
|
||||||
|
if (listener == *it) {
|
||||||
|
m_listeners.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MessageHandler::onSizeChanged(Display* display, int width, int height)
|
void MessageHandler::onSizeChanged(Display* display, int width, int height)
|
||||||
{
|
{
|
||||||
|
for(EventListener* listener : m_listeners) {
|
||||||
|
listener->onSizeChanged(display, width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageHandler::onEvent(const Event& event)
|
||||||
|
{
|
||||||
|
for(EventListener* listener : m_listeners) {
|
||||||
|
listener->onEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,38 @@
|
||||||
|
|
||||||
#include <Spectre/System/MessageQueue.h>
|
#include <Spectre/System/MessageQueue.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <Platform/Win32/Win32EventQueue.h>
|
||||||
|
typedef sp::Win32EventQueue ImplType;
|
||||||
|
#else
|
||||||
|
#error "No MessageQueue implementation exists"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
void MessageQueue::postEvent(SysEvent event)
|
MessageQueue::MessageQueue()
|
||||||
|
{
|
||||||
|
m_impl = new ImplType();
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageQueue::~MessageQueue()
|
||||||
|
{
|
||||||
|
delete m_impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageQueue::postEvent(Event event)
|
||||||
{
|
{
|
||||||
m_queue.push_back(event);
|
m_queue.push_back(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessageQueue::pollEvent(SysEvent& event)
|
bool MessageQueue::pollEvent(Event& event)
|
||||||
{
|
{
|
||||||
|
// Process platform events first.
|
||||||
|
if (m_impl->poll(event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isEmpty()) {
|
if (!isEmpty()) {
|
||||||
event = m_queue.front();
|
event = m_queue.front();
|
||||||
m_queue.pop_front();
|
m_queue.pop_front();
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
|
|
||||||
#include <Spectre/System/SystemEvent.h>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
SysEvent::SysEvent(Type type) :
|
|
||||||
type (type)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SysEvent SysEvent::sizeEvent(Display *display, int width, int height)
|
|
||||||
{
|
|
||||||
SysEvent event(Size);
|
|
||||||
event.size.display = display;
|
|
||||||
event.size.width = width;
|
|
||||||
event.size.height = height;
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue