Update some things.
This commit is contained in:
parent
f215bc3742
commit
4ad41f2e2e
34 changed files with 573 additions and 905 deletions
|
|
@ -6,6 +6,7 @@
|
|||
namespace Artifact {
|
||||
|
||||
static std::array<Key, GLFW_KEY_LAST + 1> GLFWToArtifact {};
|
||||
static std::array<int, static_cast<size_t>(Key::Last) + 1> ArtifactToGLFW {};
|
||||
|
||||
namespace {
|
||||
// Ensure that GLFW is transparently initialized prior to window creation.
|
||||
|
|
@ -15,7 +16,8 @@ static struct _glfwInit {
|
|||
|
||||
// Populate the global GLFW-to-Artifact keycode mapping.
|
||||
GLFWToArtifact.fill(Key::Unknown);
|
||||
#define X(glfw, artifact) GLFWToArtifact[glfw] = Key::artifact
|
||||
#define X(glfw, artifact) GLFWToArtifact[glfw] = Key::artifact;\
|
||||
ArtifactToGLFW[static_cast<int>(Key::artifact)] = glfw
|
||||
X(GLFW_KEY_A, A);
|
||||
X(GLFW_KEY_B, B);
|
||||
X(GLFW_KEY_C, C);
|
||||
|
|
@ -160,4 +162,16 @@ bool Window::shouldClose() {
|
|||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
void Window::setPointerLock() {
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
|
||||
void Window::releasePointerLock() {
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
|
||||
bool Window::isKeyDown(Key key) {
|
||||
return glfwGetKey(window, ArtifactToGLFW[static_cast<int>(key)]) == GLFW_PRESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@
|
|||
#include <GLFW/glfw3.h>
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#include "Shared.h"
|
||||
#include <Shared.h>
|
||||
#include "Events.h"
|
||||
#include "Client.h"
|
||||
|
||||
namespace Artifact {
|
||||
|
||||
|
|
@ -23,6 +24,8 @@ enum class Key {
|
|||
DeleteForward, DeleteBackward,
|
||||
ArrowLeft, ArrowRight, ArrowUp, ArrowDown,
|
||||
Tab,
|
||||
|
||||
Last
|
||||
};
|
||||
|
||||
namespace Events {
|
||||
|
|
@ -72,7 +75,16 @@ struct MouseEvent {
|
|||
|
||||
}
|
||||
|
||||
class Window: public EventTarget, public BaseSubsystem {
|
||||
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:
|
||||
|
|
@ -80,9 +92,12 @@ public:
|
|||
|
||||
void render() override;
|
||||
|
||||
WGPUSurface createWGPUSurface(WGPUInstance instance);
|
||||
WGPUSurface createWGPUSurface(WGPUInstance instance) override;
|
||||
void setTitle(std::string title);
|
||||
bool shouldClose();
|
||||
bool shouldClose() override;
|
||||
void setPointerLock() override;
|
||||
void releasePointerLock() override;
|
||||
bool isKeyDown(Key key) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue