Add and implement key Events
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#ifndef KEYEVENT_H
|
||||
#define KEYEVENT_H
|
||||
|
||||
#include "inferno/event/event.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class KeyEvent : public Event {
|
||||
public:
|
||||
inline int getKey() const { return m_key; }
|
||||
|
||||
EVENT_CLASS_CATEGORY(InputEventCategory | KeyEventCategory)
|
||||
|
||||
protected:
|
||||
KeyEvent(int key) :
|
||||
m_key(key) {}
|
||||
|
||||
private:
|
||||
int m_key;
|
||||
};
|
||||
|
||||
class KeyPressEvent : public KeyEvent {
|
||||
public:
|
||||
KeyPressEvent(int key) :
|
||||
KeyEvent(key) {}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "KeyPress: " << getKey();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
EVENT_CLASS_TYPE(KeyPress)
|
||||
};
|
||||
|
||||
class KeyReleaseEvent : public KeyEvent {
|
||||
public:
|
||||
KeyReleaseEvent(int key) :
|
||||
KeyEvent(key) {}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "KeyRelease: " << getKey();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
EVENT_CLASS_TYPE(KeyPress)
|
||||
};
|
||||
|
||||
class KeyRepeatEvent : public KeyEvent {
|
||||
public:
|
||||
KeyRepeatEvent(int key) :
|
||||
KeyEvent(key) {}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "KeyRepeat: " << getKey();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
EVENT_CLASS_TYPE(KeyPress)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // KEYEVENT_H
|
||||
@@ -7,16 +7,15 @@ namespace Inferno {
|
||||
|
||||
class MouseButtonEvent : public Event {
|
||||
public:
|
||||
MouseButtonEvent(int button) :
|
||||
m_button(button) {}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
inline int getButton() const { return m_button; }
|
||||
|
||||
EVENT_CLASS_CATEGORY(InputEventCategory | MouseEventCategory | MouseButtonEventCategory)
|
||||
|
||||
protected:
|
||||
MouseButtonEvent(int button) :
|
||||
m_button(button) {}
|
||||
|
||||
private:
|
||||
int m_button;
|
||||
};
|
||||
|
||||
@@ -28,7 +27,7 @@ namespace Inferno {
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "MouseButtonPressed: " << m_button;
|
||||
ss << "MouseButtonPressed: " << getButton();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@@ -43,7 +42,7 @@ namespace Inferno {
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "MouseButtonReleased: " << m_button;
|
||||
ss << "MouseButtonReleased: " << getButton();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "inferno/core.h"
|
||||
#include "inferno/event/applicationevent.h"
|
||||
#include "inferno/event/keyevent.h"
|
||||
#include "inferno/event/mouseevent.h"
|
||||
#include "inferno/log.h"
|
||||
#include "inferno/settings.h"
|
||||
@@ -92,7 +93,27 @@ namespace Inferno {
|
||||
});
|
||||
|
||||
// Keyboard callback
|
||||
// glfwSetKeyCallback(GLFWwindow* window, int key, int scanCode, int action, int mods);
|
||||
glfwSetKeyCallback(m_window, [](GLFWwindow* window, int key, int scanCode, int action, int mods) {
|
||||
Window &w = *(Window*)glfwGetWindowUserPointer(window);
|
||||
|
||||
switch (action) {
|
||||
case GLFW_PRESS: {
|
||||
KeyPressEvent event(key);
|
||||
w.m_eventCallback(event);
|
||||
break;
|
||||
}
|
||||
case GLFW_RELEASE: {
|
||||
KeyReleaseEvent event(key);
|
||||
w.m_eventCallback(event);
|
||||
break;
|
||||
}
|
||||
case GLFW_REPEAT: {
|
||||
KeyRepeatEvent event(key);
|
||||
w.m_eventCallback(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Mouse button callback
|
||||
glfwSetMouseButtonCallback(m_window, [](GLFWwindow* window, int button, int action, int mods) {
|
||||
|
||||
Reference in New Issue
Block a user