src/core: move mach-core@9a4d09707d9f1cb6ea5602bdf58caeefc46146be package to here
Helps hexops/mach#1165 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
fa3f6161ad
commit
38f296ecce
157 changed files with 28383 additions and 0 deletions
25
src/core/InputState.zig
Normal file
25
src/core/InputState.zig
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue