Added setMouseButtonCallback

This commit is contained in:
2022-01-09 23:44:57 -07:00
parent e53d1dd0aa
commit ea1c1281ef
2 changed files with 55 additions and 1 deletions

View File

@ -132,6 +132,11 @@ fn handleResize(win: mfb.Window(State), width: i32, height: i32) callconv(.C) vo
}
}
fn handleMouseButton(_: mfb.Window(State), mouse_button: mfb.MouseButton, key_mod: mfb.KeyMod, is_pressed: bool) callconv(.C) void {
const up_down: []const u8 = if (is_pressed) "down" else "up";
std.log.info("{any} mouse{d} {s}", .{ key_mod, @enumToInt(mouse_button), up_down });
}
pub fn main() !void {
var gp_allocator = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gp_allocator.allocator();
@ -141,12 +146,13 @@ pub fn main() !void {
var win = mfb.Window(State).open("Hello minifb-zig", Width, Height, .{ .resizable = true, .alwaysOnTop = true }) catch unreachable;
const scale = win.getMonitorScale();
std.log.info("Monitor scale: {d} * {d}", .{scale.x, scale.y});
std.log.info("Monitor scale: {d} * {d}", .{ scale.x, scale.y });
mfb.setTargetFPS(30);
win.setUserData(&state);
win.setActiveCallback(handleActive);
win.setResizeCallback(handleResize);
win.setMouseButtonCallback(handleMouseButton);
var buf = try Buffer.init(alloc, Width, Height);
defer buf.deinit();