animated example

This commit is contained in:
Jorijn van der Graaf 2026-05-02 00:03:24 +02:00
commit c9fd1b1585
17 changed files with 576 additions and 465 deletions

View file

@ -30,9 +30,26 @@ module;
#endif
export module Crafter.Graphics:Device;
import std;
import :Types; // CrafterKeys for keyboard repeat state
export namespace Crafter {
struct Window;
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
// Wayland's wl_keyboard.key only fires on real press/release — the
// compositor expects the application to synthesize repeat events
// itself using the rate/delay it advertises via wl_keyboard.repeat_info.
struct KeyRepeatState {
int rate = 25; // chars/sec
int delay = 500; // ms before first repeat
bool active = false;
CrafterKeys key{};
std::string utf8; // UTF-8 to re-emit as onTextInput, if any
std::chrono::time_point<std::chrono::steady_clock> pressTime;
std::chrono::time_point<std::chrono::steady_clock> lastFireTime;
};
#endif
struct Device {
static void Initialize();
@ -131,5 +148,18 @@ export namespace Crafter {
static void CheckVkResult(VkResult result);
static std::uint32_t GetMemoryType(std::uint32_t typeBits, VkMemoryPropertyFlags properties);
// ─── Wayland key repeat ────────────────────────────────────────
// TickKeyRepeats walks the held-key state and fires onKeyDown /
// onTextInput accordingly. Called once per frame from
// Window::Render. KeyRepeatState lives at namespace scope so its
// member initializers don't trip C++'s "complete-type-needed"
// rule for the inline static below.
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
inline static KeyRepeatState keyRepeat;
static void TickKeyRepeats();
#else
static void TickKeyRepeats() {}
#endif
};
}