Added Events
This commit is contained in:
parent
7998d53c31
commit
ac1c0adedf
3 changed files with 157 additions and 0 deletions
40
Engine/src/Engine/Events/Event.h
Normal file
40
Engine/src/Engine/Events/Event.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base.h"
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
enum EventType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
|
||||||
|
// input
|
||||||
|
MouseMoved, ButtonPressed, ButtonReleased, // mouse
|
||||||
|
KeyPressed, KeyReleased, // keyboard
|
||||||
|
|
||||||
|
// window
|
||||||
|
WindowMoved, WindowResized, WindowClosed,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define EVENT_TYPE(x) virtual EventType GetType() override { return x; }
|
||||||
|
|
||||||
|
class Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
bool b_Handled;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual EventType GetType() = 0;
|
||||||
|
virtual std::string GetInfoLog() const = 0;
|
||||||
|
|
||||||
|
inline bool IsHandled() const { return b_Handled; }
|
||||||
|
|
||||||
|
friend std::ostream & operator<<(std::ostream & os, const Event& e)
|
||||||
|
{
|
||||||
|
return os << e.GetInfoLog();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
48
Engine/src/Engine/Events/KeyboardEvent.h
Normal file
48
Engine/src/Engine/Events/KeyboardEvent.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base.h"
|
||||||
|
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class KeyPressedEvent : public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int m_Key;
|
||||||
|
|
||||||
|
public:
|
||||||
|
KeyPressedEvent(int key): m_Key(key) {}
|
||||||
|
|
||||||
|
inline int GetKey() const { return m_Key; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "KeyPressed: " << m_Key;
|
||||||
|
}
|
||||||
|
EVENT_TYPE(KeyPressed)
|
||||||
|
};
|
||||||
|
|
||||||
|
class KeyReleasedEvent : public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int m_Key;
|
||||||
|
|
||||||
|
public:
|
||||||
|
KeyReleasedEvent(int key): m_Key(key) {}
|
||||||
|
|
||||||
|
inline int GetKey() const { return m_Key; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "KeyReleased: " << m_Key;
|
||||||
|
}
|
||||||
|
EVENT_TYPE(KeyReleased)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
69
Engine/src/Engine/Events/MouseEvents.h
Normal file
69
Engine/src/Engine/Events/MouseEvents.h
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base.h"
|
||||||
|
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class MouseMovedEvent : public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const float m_PositionX, m_PositionY;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MouseMovedEvent(float x, float y) : m_PositionX(x), m_PositionY(y) {}
|
||||||
|
|
||||||
|
inline float GetX() const { return m_PositionX; }
|
||||||
|
inline float GetY() const { return m_PositionY; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "MouseMoved: " << m_PositionX << ", " << m_PositionY;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(MouseMoved)
|
||||||
|
};
|
||||||
|
|
||||||
|
class ButtonPressedEvent : public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int m_Button;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ButtonPressedEvent(int button): m_Button(button) {}
|
||||||
|
|
||||||
|
inline int GetButton() const { return m_Button; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "ButtonPressed: " << m_Button;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(ButtonPressed)
|
||||||
|
};
|
||||||
|
|
||||||
|
class ButtonReleasedEvent : public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int m_Button;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ButtonReleasedEvent(int button) : m_Button(button) {}
|
||||||
|
|
||||||
|
inline int GetButton() const { return m_Button; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "ButtonReleased: " << m_Button;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(ButtonReleased)
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue