diff options
author | alaric <alaric@netmythos.org> | 2024-04-12 15:37:29 -0700 |
---|---|---|
committer | alaric <alaric@netmythos.org> | 2024-04-12 15:37:29 -0700 |
commit | 8d0b946c1bfcc437458dc0971ad7024110f37b25 (patch) | |
tree | da5c462883d0f721d16841c948f08cd9853cad75 | |
parent | 9af697af684a15aa22a04221e214e26b220c33b0 (diff) | |
download | engine-8d0b946c1bfcc437458dc0971ad7024110f37b25.tar.gz engine-8d0b946c1bfcc437458dc0971ad7024110f37b25.zip |
feat:setCursor and abs
-rw-r--r-- | src/engine.zig | 8 | ||||
-rw-r--r-- | src/math.zig | 4 | ||||
-rw-r--r-- | src/shell/shell.html | 13 |
3 files changed, 25 insertions, 0 deletions
diff --git a/src/engine.zig b/src/engine.zig index 3c22ae5..bc39f55 100644 --- a/src/engine.zig +++ b/src/engine.zig @@ -67,3 +67,11 @@ pub const Color = struct { return Color.fromVec(out); } }; + +pub const Cursor = enum(u8) { + pointer, + grab, + grabbing, +}; + +pub extern fn setCursor(cursor: Cursor) void; diff --git a/src/math.zig b/src/math.zig index a649b1f..ab8c263 100644 --- a/src/math.zig +++ b/src/math.zig @@ -47,3 +47,7 @@ pub fn maxInt(comptime T: type) comptime_int { if (bit_count == 0) return 0; return (1 << (bit_count - @intFromBool(info.Int.signedness == .signed))) - 1; } + +pub fn abs(v: anytype) @TypeOf(v) { + if (v < 0) return -v else return v; +} diff --git a/src/shell/shell.html b/src/shell/shell.html index 7f91847..9c93f99 100644 --- a/src/shell/shell.html +++ b/src/shell/shell.html @@ -103,6 +103,18 @@ keyRegistry.set(code, list); }; + const cursors = { + 0: "default", + 1: "grab", + 2: "grabbing", + }; + const setCursor = (c_idx) => { + const c = cursors[c_idx]; + if (c) { + canvas.style.cursor = c; + } + }; + const importObject = { env: { ...webgl, @@ -110,6 +122,7 @@ rand, loadTexture, registerKeyInput, + setCursor, }, }; |