mach/src/core/InputState.zig
Stephen Gutekanst 38f296ecce src/core: move mach-core@9a4d09707d9f1cb6ea5602bdf58caeefc46146be package to here
Helps hexops/mach#1165

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-03-05 00:22:22 -07:00

25 lines
912 B
Zig

const std = @import("std");
const core = @import("main.zig");
const KeyBitSet = std.StaticBitSet(@intFromEnum(core.Key.max) + 1);
const MouseButtonSet = std.StaticBitSet(@as(u4, @intFromEnum(core.MouseButton.max)) + 1);
const InputState = @This();
keys: KeyBitSet = KeyBitSet.initEmpty(),
mouse_buttons: MouseButtonSet = MouseButtonSet.initEmpty(),
mouse_position: core.Position = .{ .x = 0, .y = 0 },
pub inline fn isKeyPressed(self: InputState, key: core.Key) bool {
return self.keys.isSet(@intFromEnum(key));
}
pub inline fn isKeyReleased(self: InputState, key: core.Key) bool {
return !self.isKeyPressed(key);
}
pub inline fn isMouseButtonPressed(self: InputState, button: core.MouseButton) bool {
return self.mouse_buttons.isSet(@intFromEnum(button));
}
pub inline fn isMouseButtonReleased(self: InputState, button: core.MouseButton) bool {
return !self.isMouseButtonPressed(button);
}