mach: add setCursorMode (desktop only for now)
This commit is contained in:
parent
2c65845aed
commit
78dfa2df6b
5 changed files with 31 additions and 0 deletions
|
|
@ -87,6 +87,10 @@ pub fn setMouseCursor(core: *Core, cursor: enums.MouseCursor) !void {
|
||||||
try core.internal.setMouseCursor(cursor);
|
try core.internal.setMouseCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setCursorMode(core: *Core, mode: enums.CursorMode) !void {
|
||||||
|
try core.internal.setCursorMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn hasEvent(core: *Core) bool {
|
pub fn hasEvent(core: *Core) bool {
|
||||||
return core.internal.hasEvent();
|
return core.internal.hasEvent();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,19 @@ pub const MouseCursor = enum {
|
||||||
not_allowed,
|
not_allowed,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const CursorMode = enum {
|
||||||
|
/// Makes the cursor visible and behaving normally.
|
||||||
|
normal,
|
||||||
|
|
||||||
|
/// Makes the cursor invisible when it is over the content area of the window but does not
|
||||||
|
/// restrict it from leaving.
|
||||||
|
hidden,
|
||||||
|
|
||||||
|
/// Hides and grabs the cursor, providing virtual and unlimited cursor movement. This is useful
|
||||||
|
/// for implementing for example 3D camera controls.
|
||||||
|
disabled,
|
||||||
|
};
|
||||||
|
|
||||||
pub const MouseButton = enum {
|
pub const MouseButton = enum {
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ fn Interface(comptime T: type) type {
|
||||||
assertHasDecl(T.Platform, "getFramebufferSize");
|
assertHasDecl(T.Platform, "getFramebufferSize");
|
||||||
assertHasDecl(T.Platform, "getWindowSize");
|
assertHasDecl(T.Platform, "getWindowSize");
|
||||||
assertHasDecl(T.Platform, "setMouseCursor");
|
assertHasDecl(T.Platform, "setMouseCursor");
|
||||||
|
assertHasDecl(T.Platform, "setCursorMode");
|
||||||
assertHasDecl(T.Platform, "hasEvent");
|
assertHasDecl(T.Platform, "hasEvent");
|
||||||
assertHasDecl(T.Platform, "pollEvent");
|
assertHasDecl(T.Platform, "pollEvent");
|
||||||
assertHasDecl(T.BackingTimer, "start");
|
assertHasDecl(T.BackingTimer, "start");
|
||||||
|
|
|
||||||
|
|
@ -374,6 +374,15 @@ pub const Platform = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setCursorMode(platform: *Platform, mode: enums.CursorMode) !void {
|
||||||
|
const glfw_mode: glfw.Window.InputModeCursor = switch (mode) {
|
||||||
|
.normal => .normal,
|
||||||
|
.hidden => .hidden,
|
||||||
|
.disabled => .disabled,
|
||||||
|
};
|
||||||
|
try platform.window.setInputModeCursor(glfw_mode);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn hasEvent(platform: *Platform) bool {
|
pub fn hasEvent(platform: *Platform) bool {
|
||||||
return platform.events.first != null;
|
return platform.events.first != null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,10 @@ pub const Platform = struct {
|
||||||
js.machSetMouseCursor(cursor_name.ptr, cursor_name.len);
|
js.machSetMouseCursor(cursor_name.ptr, cursor_name.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setCursorMode(_: *Platform, _: enums.CursorMode) !void {
|
||||||
|
@panic("TODO: Implement setCursorMode for wasm");
|
||||||
|
}
|
||||||
|
|
||||||
fn pollChanges(platform: *Platform) void {
|
fn pollChanges(platform: *Platform) void {
|
||||||
const change_type = js.machChangeShift();
|
const change_type = js.machChangeShift();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue