ArtifactEngine/Client/Platform/Window.h
2026-04-06 19:22:10 -04:00

103 lines
1.8 KiB
C++

#pragma once
#include <string>
#include <GLFW/glfw3.h>
#include <webgpu/webgpu.h>
#include <Shared.h>
#include "Events.h"
#include "Client.h"
namespace Artifact {
enum class Key {
Unknown = 0,
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,
Zero, One, Two, Three, Four, Five,
Six, Seven, Eight, Nine,
ShiftLeft, ShiftRight,
ControlLeft, ControlRight,
OptionLeft, OptionRight,
CommandLeft, CommandRight,
Enter,
DeleteForward, DeleteBackward,
ArrowLeft, ArrowRight, ArrowUp, ArrowDown,
Tab,
Last
};
namespace Events {
struct InputBegin {};
struct InputEnd {};
enum Action {
ACTION_PRESS,
ACTION_RELEASE
};
struct KeyDownEvent {
Key key;
};
struct KeyUpEvent {
Key key;
};
struct CharInputEvent {
uint32_t codepoint;
};
struct CursorPosEvent {
double x;
double y;
};
struct ScrollEvent {
double dx;
double dy;
};
enum MouseButton {
MOUSE_BUTTON_LEFT,
MOUSE_BUTTON_RIGHT,
MOUSE_BUTTON_MIDDLE
};
struct MouseEvent {
MouseButton button;
bool state;
double x;
double y;
};
}
class WindowImpl: public EventTarget, public ClientSubsystem {
public:
virtual bool shouldClose() = 0;
virtual WGPUSurface createWGPUSurface(WGPUInstance instance) = 0;
virtual void setPointerLock() = 0;
virtual void releasePointerLock() = 0;
virtual bool isKeyDown(Key key) = 0;
};
class Window: public WindowImpl {
private:
GLFWwindow * window = nullptr;
public:
Window(uint32_t width, uint32_t height, std::string title);
void render() override;
WGPUSurface createWGPUSurface(WGPUInstance instance) override;
void setTitle(std::string title);
bool shouldClose() override;
void setPointerLock() override;
void releasePointerLock() override;
bool isKeyDown(Key key) override;
};
}