Added setCharInputCallback, and minor cleanup

This commit is contained in:
2022-01-10 16:30:58 -07:00
parent ed6ab7c92a
commit ed2445e623
2 changed files with 62 additions and 28 deletions

View File

@ -145,8 +145,8 @@ pub const KeyMod = packed struct {
control: bool = false,
alt: bool = false,
super: bool = false,
capsLock: bool = false,
numLock: bool = false,
caps_lock: bool = false,
num_lock: bool = false,
_reserved: u26 = 0,
fn putName(present: bool, name: []const u8, names: *[6][]const u8, index: *usize) void {
@ -168,8 +168,8 @@ pub const KeyMod = packed struct {
putName(self.control, "Control", &names, &i);
putName(self.alt, "Alt", &names, &i);
putName(self.super, "Super", &names, &i);
putName(self.capsLock, "Caps_Lock", &names, &i);
putName(self.numLock, "Num_Lock", &names, &i);
putName(self.caps_lock, "Caps_Lock", &names, &i);
putName(self.num_lock, "Num_Lock", &names, &i);
var first = true;
for (names[0..i]) |name| {
if (!first) {
@ -221,16 +221,14 @@ pub fn Window(comptime TUserData: type) type {
pub const OpenFlags = packed struct {
resizable: bool = false,
fullscreen: bool = false,
fullscreenDesktop: bool = false,
fullscreen_desktop: bool = false,
borderless: bool = false,
alwaysOnTop: bool = false,
always_on_top: bool = false,
reserved: u27 = 0,
};
pub fn open(title: [*:0]const u8, width: u32, height: u32, flags: OpenFlags) !Window(TUserData) {
const intFlags = @bitCast(u32, flags);
const cTitle = @as([*c]const u8, title);
const cwin: ?*c.mfb_window = c.mfb_open_ex(cTitle, width, height, intFlags);
const cwin: ?*c.mfb_window = c.mfb_open_ex(title, width, height, @bitCast(u32, flags));
if (cwin) |value| {
const win = Window(TUserData){ .cwin = value };
assert(@bitCast(usize, win) == @ptrToInt(win.cwin));
@ -299,6 +297,11 @@ pub fn Window(comptime TUserData: type) type {
c.mfb_set_keyboard_callback(self.cwin, @ptrCast(c.mfb_keyboard_func, callback));
}
pub const CharInputFunc = fn (win: Window(TUserData), code: u32) callconv(.C) void;
pub fn setCharInputCallback(self: Window(TUserData), callback: CharInputFunc) void {
c.mfb_set_char_input_callback(self.cwin, @ptrCast(c.mfb_char_input_func, callback));
}
pub fn setViewport(self: Window(TUserData), offset_x: u32, offset_y: u32, width: u32, height: u32) bool {
return c.mfb_set_viewport(self.cwin, offset_x, offset_y, width, height);
}