feat: event sketch
This commit is contained in:
7
Makefile
7
Makefile
@@ -1,8 +1,8 @@
|
||||
CFLAGS = -Wall -Wextra -I./include/ -g
|
||||
LIBS = $(shell pkg-config --libs wayland-client wayland-egl egl glesv2 wayland-cursor)
|
||||
|
||||
build/main: src/main.cpp build/shader.o build/state.o build/renderer.o build/window.o build/window_wayland.o build/input.o build/input_wayland.o build/xdg-shell-protocol.o
|
||||
g++ -o build/main $(CFLAGS) src/main.cpp build/shader.o build/state.o build/renderer.o build/window.o build/window_wayland.o build/input.o build/input_wayland.o build/xdg-shell-protocol.o $(LIBS)
|
||||
build/main: src/main.cpp build/shader.o build/state.o build/renderer.o build/window.o build/window_wayland.o build/input.o build/input_wayland.o build/event.o build/xdg-shell-protocol.o
|
||||
g++ -o build/main $(CFLAGS) src/main.cpp build/shader.o build/state.o build/renderer.o build/window.o build/window_wayland.o build/input.o build/input_wayland.o build/event.o build/xdg-shell-protocol.o $(LIBS)
|
||||
|
||||
build/shader.o: src/shader.cpp include/shader.h
|
||||
g++ -o build/shader.o $(CFLAGS) -c src/shader.cpp
|
||||
@@ -28,6 +28,9 @@ build/input.o: src/input.cpp include/input.h
|
||||
build/input_wayland.o: include/input/wayland.h src/input/wayland.cpp
|
||||
g++ -o build/input_wayland.o $(CFLAGS) -c src/input/wayland.cpp
|
||||
|
||||
build/event.o: src/event.cpp include/event.h
|
||||
g++ -o build/event.o $(CFLAGS) -c src/event.cpp
|
||||
|
||||
build/xdg-shell-protocol.o: src/xdg-shell-protocol.c
|
||||
gcc -o build/xdg-shell-protocol.o -c $(CFLAGS) $(LIBS) src/xdg-shell-protocol.c
|
||||
|
||||
|
||||
35
include/event.h
Normal file
35
include/event.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#ifndef EVENT_H_
|
||||
#define EVENT_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
enum class EventType {
|
||||
INPUT,
|
||||
};
|
||||
|
||||
struct Event {
|
||||
public:
|
||||
Event();
|
||||
virtual ~Event() = default;
|
||||
|
||||
public:
|
||||
virtual EventType GetType() const = 0;
|
||||
|
||||
public:
|
||||
void Handle();
|
||||
size_t Id() const;
|
||||
|
||||
public:
|
||||
bool IsHandled() const;
|
||||
|
||||
private:
|
||||
bool m_handled;
|
||||
size_t m_id;
|
||||
|
||||
private:
|
||||
static size_t s_id_counter;
|
||||
};
|
||||
|
||||
#endif // EVENT_H_
|
||||
16
include/event/input.h
Normal file
16
include/event/input.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#ifndef H_INPUT_EVENT_
|
||||
#define H_INPUT_EVENT_
|
||||
|
||||
#include "event.h"
|
||||
|
||||
struct InputEvent : public Event {
|
||||
public:
|
||||
InputEvent() = default;
|
||||
~InputEvent() = default;
|
||||
|
||||
public:
|
||||
EventType GetType() const override;
|
||||
};
|
||||
|
||||
#endif // H_INPUT_EVENT_
|
||||
18
src/event.cpp
Normal file
18
src/event.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "event.h"
|
||||
|
||||
size_t Event::s_id_counter = 0;
|
||||
|
||||
Event::Event() : m_id(s_id_counter++) {}
|
||||
|
||||
void Event::Handle() {
|
||||
m_handled = true;
|
||||
}
|
||||
|
||||
bool Event::IsHandled() const {
|
||||
return m_handled;
|
||||
}
|
||||
|
||||
size_t Event::Id() const {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
6
src/event/input.cpp
Normal file
6
src/event/input.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "event/input.h"
|
||||
|
||||
EventType InputEvent::GetType() const {
|
||||
return EventType::INPUT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user