summaryrefslogtreecommitdiff
path: root/main.zig
blob: ab5f802d680d5adc8ccaee35284e45be5e97ce1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const std = @import("std");
const rgfw = @import("rgfw.zig");

fn keyfunc (event: [*c]const rgfw.RGFW_event) callconv(.c) void {
  if(event.*.key.value == rgfw.RGFW_keyEscape) {
    rgfw.RGFW_window_setShouldClose(event.*.common.win, 1);
  }
}

pub fn main() !void {
  const win: ?*rgfw.RGFW_window = rgfw.RGFW_createWindow("a window", 0, 0, 800, 600, rgfw.RGFW_windowCenter | rgfw.RGFW_windowNoResize | rgfw.RGFW_windowOpenGL);
  _ = rgfw.RGFW_setEventCallback(rgfw.RGFW_keyPressed, keyfunc);

  var mouseX: i32 = 0;
  var mouseY: i32 = 0;

  while(rgfw.RGFW_FALSE == rgfw.RGFW_window_shouldClose(win)) {
    var event: rgfw.RGFW_event = undefined;
    while(rgfw.RGFW_TRUE == rgfw.RGFW_window_checkEvent(win, &event)) {
      _ = rgfw.RGFW_window_getMouse(win, &mouseX, &mouseY);
      if(event.type == rgfw.RGFW_mouseButtonPressed and event.button.value == rgfw.RGFW_mouseLeft) {
        std.debug.print("You clicked at x: {d}, y: {d}\n", .{mouseX, mouseY});
      }
    }
    if(rgfw.RGFW_TRUE == rgfw.RGFW_isMousePressed(rgfw.RGFW_mouseRight)) {
      std.debug.print("The right mouse button was clicked at x: {d}, y: {d}\n", .{mouseX, mouseY});
    }
    rgfw.RGFW_window_swapBuffers_OpenGL(win);
  }
  rgfw.RGFW_window_close(win);
}