The windows resized since the last update_window_events.
for get_window_resizes() print("% x %\n", it.width, it.height);
assert(get_window_resizes().count == 0);↗#import "Input";
Keyboard, mouse, touch and window events for windows made with Window_Creation.
Call update_window_events once per frame, then read events_this_frame for what happened and
input_button_states for what is held. Each state is a Key_Current_State bit set indexed by
Key_Code.
#import "Window_Creation";
#import "Input";
window := create_window(800, 600, "input");
while true {
update_window_events();
for events_this_frame {
if it.type == .QUIT return;
if it.type == .KEYBOARD && it.key_code == .ESCAPE return;
}
if input_button_states[Key_Code.MOUSE_BUTTON_LEFT] & .START print("click at %, %\n", mouse_delta_x, mouse_delta_y);
}This one is only checked to compile, not run.
The windows resized since the last update_window_events.
for get_window_resizes() print("% x %\n", it.width, it.height);
assert(get_window_resizes().count == 0);↗The windows moved since the last update_window_events.
assert(get_window_moves().count == 0);↗Records a resize for get_window_resizes. The window backends call it; programs rarely need to.
Starts a new frame: drops this frame's events and resize or move records, zeroes the mouse deltas
and clears the START and END flags while keeping DOWN. update_window_events calls it first.
input_button_states[Key_Code.SPACEBAR] = .DOWN | .START;
input_per_frame_event_and_flag_update();
assert(input_button_states[Key_Code.SPACEBAR] == .DOWN);↗Maps an X11 key symbol to a Key_Code.
Tells the library whether the program manages the mouse cursor itself.
Collects the events of all windows into events_this_frame and the button states. Call once per frame.
The window procedure behind every window; it turns Win32 messages into events.
What kind of thing an Event reports.
What happened to the window, for events of type .WINDOW.
The state of a key or button this frame. DOWN lasts while it is held; START and END are set
only on the frame it went down or up.
state := Key_Current_State.DOWN | .START;
assert((state & .START) != 0);
assert((state & .END) == 0);↗One input event. Check type first; it decides which other fields mean anything: key_code and
repeat for .KEYBOARD, utf32 for .TEXT_INPUT, wheel_delta for .MOUSE_WHEEL, files for
.DRAG_AND_DROP_FILES, and so on. The modifier flags (shift_pressed, ctrl_pressed,
alt_pressed, cmd_meta_pressed) apply to every event.
event: Event;
event.type = .KEYBOARD;
event.key_code = .ENTER;
event.shift_pressed = true;
assert(event.key_code == .ENTER && event.packed != 0);↗The state and position of one finger on a touch screen.
A window's new size, from get_window_resizes.
A window's new position, from get_window_moves.
Keys, mouse buttons and gamepad buttons. Printable keys use their ASCII value, upper case for
letters (#char "A" is the A key); the rest have names. Index input_button_states with it.
assert(cast(u32) Key_Code.ENTER == 13);
assert(cast(Key_Code) #char "A" != .UNKNOWN);↗