njin
Engine 2D gọn nhẹ để tự tay làm game theo ý mình. Vibe coding cũng ổn luôn
Loading...
Searching...
No Matches
njin_input.h
1#pragma once
2#include "_types.h"
3
4namespace njin {
5// Opaque, see njin_ctx.h.
6struct context;
7
10
15bool key_pressed(const context &ctx, key_code key);
16
25bool key_held(const context &ctx, key_code key);
26
31bool key_released(const context &ctx, key_code key);
32
39action_handle action_register(context &ctx, const char *name);
40
45action_handle action_find(const context &ctx, const char *name);
46
51void action_bind_key(context &ctx, action_handle handle, key_code key);
52
58void action_bind_mouse(context &ctx, action_handle handle, mouse_button button);
59
64void action_bind_pad(context &ctx, action_handle handle, gamepad_button button);
65
72void action_clear_binds(context &ctx, action_handle handle);
73
79bool action_pressed(const context &ctx, action_handle handle);
80
86bool action_held(const context &ctx, action_handle handle);
87
92bool action_released(const context &ctx, action_handle handle);
93
99vec2 mouse_pos(const context &ctx);
100
104vec2 mouse_delta(const context &ctx);
105
110f32 mouse_wheel(const context &ctx);
111
116bool mouse_pressed(const context &ctx, mouse_button button);
117
123bool mouse_held(const context &ctx, mouse_button button);
124
129bool mouse_released(const context &ctx, mouse_button button);
130
137bool pad_available(const context &ctx, i32 pad);
138
144bool pad_pressed(const context &ctx, i32 pad, gamepad_button button);
145
152bool pad_held(const context &ctx, i32 pad, gamepad_button button);
153
159bool pad_released(const context &ctx, i32 pad, gamepad_button button);
160
170f32 pad_axis(const context &ctx, i32 pad, gamepad_axis axis);
171
175void pad_set_deadzone(context &ctx, f32 deadzone);
176
184i32 text_count(const context &ctx);
185
190i32 text_char(const context &ctx, i32 index);
191
199void key_consume(context &ctx, key_code key);
200
205void mouse_consume(context &ctx, mouse_button button);
206
209void mouse_wheel_consume(context &ctx);
210
219axis_handle axis_register(context &ctx, const char *name);
220
225axis_handle axis_find(const context &ctx, const char *name);
226
235void axis_bind_keys(context &ctx, axis_handle handle, key_code negative,
236 key_code positive);
237
242void axis_bind_pad(context &ctx, axis_handle handle, gamepad_axis axis);
243
247void axis_clear_binds(context &ctx, axis_handle handle);
248
256f32 axis_value(const context &ctx, axis_handle handle);
258} // namespace njin
void axis_bind_keys(context &ctx, axis_handle handle, key_code negative, key_code positive)
Gắn một cặp phím vào axis, đóng vai một cần analog.
action_handle action_find(const context &ctx, const char *name)
Tìm action theo tên.
bool pad_released(const context &ctx, i32 pad, gamepad_button button)
Đúng ở frame mà nút tay cầm vừa được thả (chỉ một frame).
bool mouse_pressed(const context &ctx, mouse_button button)
Đúng ở frame mà nút chuột vừa được nhấn xuống (chỉ một frame).
bool pad_available(const context &ctx, i32 pad)
Tay cầm số pad có đang được cắm không.
bool mouse_held(const context &ctx, mouse_button button)
Đúng khi nút chuột đã được giữ từ frame trước và vẫn đang giữ.
i32 text_count(const context &ctx)
Số ký tự đã gõ trong frame này.
f32 mouse_wheel(const context &ctx)
Số nấc cuộn bánh xe chuột trong frame này.
axis_handle axis_find(const context &ctx, const char *name)
Tìm axis theo tên.
void action_clear_binds(context &ctx, action_handle handle)
Xóa mọi phím, nút chuột và nút tay cầm đã gắn vào action.
void action_bind_mouse(context &ctx, action_handle handle, mouse_button button)
Gắn một nút chuột vào action.
bool key_pressed(const context &ctx, key_code key)
Đúng ở frame mà phím vừa được nhấn xuống (chỉ một frame).
bool action_held(const context &ctx, action_handle handle)
Đúng khi một trong các nguồn của action đã được giữ từ frame trước và vẫn đang giữ.
void action_bind_pad(context &ctx, action_handle handle, gamepad_button button)
Gắn một nút tay cầm vào action.
void axis_clear_binds(context &ctx, axis_handle handle)
Xóa mọi cặp phím và trục tay cầm đã gắn vào axis.
bool key_held(const context &ctx, key_code key)
Đúng khi phím đã được giữ từ frame trước và vẫn đang giữ.
axis_handle axis_register(context &ctx, const char *name)
Đăng ký một axis có tên.
bool pad_held(const context &ctx, i32 pad, gamepad_button button)
Đúng khi nút tay cầm đã được giữ từ frame trước và vẫn đang giữ.
f32 pad_axis(const context &ctx, i32 pad, gamepad_axis axis)
Giá trị một trục analog của tay cầm.
void key_consume(context &ctx, key_code key)
Xóa trạng thái của một phím trong phần còn lại của frame.
bool pad_pressed(const context &ctx, i32 pad, gamepad_button button)
Đúng ở frame mà nút tay cầm vừa được nhấn xuống (chỉ một frame).
void pad_set_deadzone(context &ctx, f32 deadzone)
Đặt vùng chết cho mọi cần trên mọi tay cầm.
void action_bind_key(context &ctx, action_handle handle, key_code key)
Gắn một phím vào action.
void mouse_wheel_consume(context &ctx)
Xóa cuộn bánh xe trong phần còn lại của frame.
bool key_released(const context &ctx, key_code key)
Đúng ở frame mà phím vừa được thả ra (chỉ một frame).
void mouse_consume(context &ctx, mouse_button button)
Xóa trạng thái của một nút chuột trong phần còn lại của frame.
gamepad_button
Nút tay cầm, dùng với pad_pressed(), action_bind_pad() và các hàm liên quan.
Definition _types.h:489
f32 axis_value(const context &ctx, axis_handle handle)
Giá trị hiện tại của axis.
gamepad_axis
Trục analog của tay cầm, dùng với pad_axis() và axis_bind_pad().
Definition _types.h:512
bool action_pressed(const context &ctx, action_handle handle)
Đúng ở frame mà một trong các nguồn của action (phím, nút chuột, nút tay cầm) vừa được nhấn.
mouse_button
Nút chuột, dùng với mouse_pressed(), action_bind_mouse() và các hàm liên quan.
Definition _types.h:474
vec2 mouse_delta(const context &ctx)
Độ dời của chuột so với frame trước, tính bằng pixel.
i32 text_char(const context &ctx, i32 index)
Mã Unicode của ký tự thứ index đã gõ trong frame này, theo thứ tự gõ.
bool mouse_released(const context &ctx, mouse_button button)
Đúng ở frame mà nút chuột vừa được thả (chỉ một frame).
vec2 mouse_pos(const context &ctx)
Vị trí con trỏ chuột, tính bằng pixel màn hình.
bool action_released(const context &ctx, action_handle handle)
Đúng ở frame mà một trong các nguồn của action vừa được thả.
action_handle action_register(context &ctx, const char *name)
Đăng ký một action có tên.
void axis_bind_pad(context &ctx, axis_handle handle, gamepad_axis axis)
Gắn một trục tay cầm vào axis.
key_code
Mã phím bàn phím, dùng với key_pressed(), action_bind_key() và các hàm liên quan.
Definition _types.h:340
std::int32_t i32
Số nguyên có dấu 32 bit.
Definition _types.h:14
float f32
Số thực 32 bit.
Definition _types.h:28
Định danh của một action nhập liệu, tạo bởi action_register().
Definition _types.h:85
Định danh của một axis nhập liệu, tạo bởi axis_register().
Definition _types.h:93
Vector 2 chiều. Dùng cho vị trí, kích thước, độ dời.
Definition _types.h:39