Begin Repo
This commit is contained in:
9
events/event.cpp
Normal file
9
events/event.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "event.h"
|
||||
|
||||
Event::Event() {
|
||||
|
||||
}
|
||||
|
||||
Event::~Event()
|
||||
{
|
||||
}
|
||||
20
events/event.h
Normal file
20
events/event.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "terminal.h"
|
||||
|
||||
enum class EventType {
|
||||
None = 0,
|
||||
WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved,
|
||||
KeyPressed, KeyReleased, KeyTyped,
|
||||
MouseButtonPressed, MouseButtonReleased, MouseMoved, MouseScrolled
|
||||
};
|
||||
|
||||
class Event {
|
||||
|
||||
public:
|
||||
Event();
|
||||
virtual ~Event();
|
||||
|
||||
virtual EventType getType() const = 0;
|
||||
|
||||
};
|
||||
39
events/eventHandler.cpp
Normal file
39
events/eventHandler.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "eventHandler.h"
|
||||
#include "application.h"
|
||||
|
||||
EventHandler::EventHandler() {
|
||||
|
||||
}
|
||||
|
||||
bool EventHandler::handleEvent(const Event* e, Layer* layer) {
|
||||
//std::cout << (int)e->getType() << '\n';
|
||||
switch(e->getType()) {
|
||||
case EventType::KeyPressed:
|
||||
return layer->onKeyPressed(static_cast<const KeyEvent*>(e));
|
||||
case EventType::KeyReleased:
|
||||
return layer->onKeyReleased(static_cast<const KeyEvent*>(e));
|
||||
case EventType::KeyTyped:
|
||||
return layer->onKeyTyped(static_cast<const KeyTypedEvent*>(e));
|
||||
case EventType::MouseButtonPressed:
|
||||
return layer->onMouseButtonPressed(static_cast<const MouseButtonEvent*>(e));
|
||||
case EventType::MouseButtonReleased:
|
||||
return layer->onMouseButtonReleased(static_cast<const MouseButtonEvent*>(e));
|
||||
case EventType::MouseScrolled:
|
||||
return layer->onMouseScrolled(static_cast<const MouseScrolledEvent*>(e));
|
||||
case EventType::MouseMoved:
|
||||
return layer->onMouseMoved(static_cast<const MouseMovedEvent*>(e));
|
||||
case EventType::WindowClose:
|
||||
return layer->onWindowClose(static_cast<const WindowEvent*>(e));
|
||||
case EventType::WindowFocus:
|
||||
return layer->onWindowFocus(static_cast<const WindowEvent*>(e));
|
||||
case EventType::WindowLostFocus:
|
||||
return layer->onWindowFocusLost(static_cast<const WindowEvent*>(e));
|
||||
case EventType::WindowMoved:
|
||||
return layer->onWindowMoved(static_cast<const WindowEvent*>(e));
|
||||
case EventType::WindowResize:
|
||||
return layer->onWindowResize(static_cast<const WindowEvent*>(e));
|
||||
//default:
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
14
events/eventHandler.h
Normal file
14
events/eventHandler.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "terminal.h"
|
||||
|
||||
#include "event.h"
|
||||
|
||||
|
||||
class EventHandler {
|
||||
|
||||
public:
|
||||
EventHandler();
|
||||
|
||||
bool handleEvent(const Event*, Layer*);
|
||||
};
|
||||
10
events/keyEvent.cpp
Normal file
10
events/keyEvent.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "keyEvent.h"
|
||||
|
||||
KeyEvent::KeyEvent(int k, int s, int m, int r, bool p) : key(k), scancode(s), mod(m), repeat(r), pressed(p) {
|
||||
|
||||
}
|
||||
|
||||
KeyTypedEvent::KeyTypedEvent(int w, char* t) : windowID(w), text(t)
|
||||
{
|
||||
|
||||
}
|
||||
28
events/keyEvent.h
Normal file
28
events/keyEvent.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "terminal.h"
|
||||
#include "event.h"
|
||||
|
||||
class KeyEvent : public Event {
|
||||
const int key;
|
||||
const int scancode;
|
||||
const int mod;
|
||||
const int repeat;
|
||||
const bool pressed;
|
||||
public:
|
||||
KeyEvent(int, int, int, int, bool);
|
||||
inline int getKey() const { return key; }
|
||||
inline int getScancode() const { return scancode; }
|
||||
inline int getMod() const { return mod; }
|
||||
inline bool getPressed() const { return pressed; }
|
||||
EventType getType() const { return pressed ? EventType::KeyPressed : EventType::KeyReleased; }
|
||||
};
|
||||
|
||||
class KeyTypedEvent : public Event {
|
||||
const std::string text;
|
||||
const int windowID;
|
||||
|
||||
public:
|
||||
KeyTypedEvent(int, char*);
|
||||
inline int getWindowID() const { return windowID; }
|
||||
inline const char* getText() const { return text.c_str(); }
|
||||
EventType getType() const { return EventType::KeyTyped; }
|
||||
};
|
||||
13
events/mouseEvent.cpp
Normal file
13
events/mouseEvent.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "mouseEvent.h"
|
||||
|
||||
MouseButtonEvent::MouseButtonEvent(int b, bool p) : button(b), pressed(p) {
|
||||
|
||||
}
|
||||
|
||||
MouseMovedEvent::MouseMovedEvent(int _x, int _y, double _dx, double _dy) : x(_x), y(_y), dx(_dx), dy(_dy) {
|
||||
|
||||
}
|
||||
|
||||
MouseScrolledEvent::MouseScrolledEvent(int _x, int _y) : x(_x), y(_y) {
|
||||
|
||||
}
|
||||
33
events/mouseEvent.h
Normal file
33
events/mouseEvent.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "terminal.h"
|
||||
#include "event.h"
|
||||
|
||||
class MouseButtonEvent : public Event {
|
||||
const int button;
|
||||
const bool pressed;
|
||||
public:
|
||||
MouseButtonEvent(int, bool);
|
||||
inline int getButton() const { return button; }
|
||||
inline bool getPressed() const { return pressed; }
|
||||
EventType getType() const { return pressed ? EventType::MouseButtonPressed : EventType::MouseButtonReleased; }
|
||||
};
|
||||
|
||||
class MouseMovedEvent : public Event {
|
||||
const int x, y;
|
||||
const double dx, dy;
|
||||
public:
|
||||
MouseMovedEvent(int, int, double, double);
|
||||
inline int getX() const { return x; }
|
||||
inline int getY() const { return y; }
|
||||
inline double getDeltaX() const { return dx; }
|
||||
inline double getDeltaY() const { return dy; }
|
||||
EventType getType() const { return EventType::MouseMoved; }
|
||||
};
|
||||
|
||||
class MouseScrolledEvent : public Event {
|
||||
const int x, y;
|
||||
public:
|
||||
MouseScrolledEvent(int, int);
|
||||
inline int getX() const { return x; }
|
||||
inline int getY() const { return y; }
|
||||
EventType getType() const { return EventType::MouseScrolled; }
|
||||
};
|
||||
5
events/windowEvent.cpp
Normal file
5
events/windowEvent.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "windowEvent.h"
|
||||
|
||||
WindowEvent::WindowEvent(int id, int e) : windowID(id), event(e) {
|
||||
|
||||
}
|
||||
27
events/windowEvent.h
Normal file
27
events/windowEvent.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "terminal.h"
|
||||
#include "event.h"
|
||||
|
||||
|
||||
class WindowEvent : public Event {
|
||||
const int windowID, event;
|
||||
public:
|
||||
WindowEvent(int, int);
|
||||
|
||||
inline int getWindowID() const { return windowID; }
|
||||
|
||||
EventType getType() const {
|
||||
switch(event) {
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
return EventType::WindowClose;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
return EventType::WindowResize;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
return EventType::WindowFocus;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
return EventType::WindowLostFocus;
|
||||
}
|
||||
return EventType::None;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user