orca/src/ui/input_state.h

97 lines
2.4 KiB
C
Raw Normal View History

/************************************************************//**
*
* @file: input_state.h
* @author: Martin Fouilleul
* @date: 19/04/2023
*
*****************************************************************/
#ifndef __INPUT_STATE_H_
#define __INPUT_STATE_H_
#include"platform/platform.h"
#include"util/typedefs.h"
#include"util/strings.h"
#include"util/utf8.h"
This commit restructures the codebase to melt the milepost platform layer into the main orca codebase. Here's a list of commits squashed in this update: - move angle files to ext/ and pull includes/libs from there when needed - remove milepost/ext/angle_headers - Collapsed milepost/ext into ext - Collapse milepost/scripts into scripts/ - collapse milepost/resources into resources/. WARN: this temporarily breaks milepost's native examples - collapse milepost/test into test/ - renamed test/ to tests/ - build milepost directly into build/bin - remove unused GLES and KHR folders from sdk/ - reorganizing milepost directory tree into app, graphics, platfrom, ui, util - collapse milepost/src to src/ - Move all native examples to sketches/ and remove milepost repo - Moving sketches resources into their own shared folder separate from the runtime's resource folder - Moving all binding code to src/wasmbind - Moving all binding code to src/wasmbind - pong: fix typo in error log - fixing log parameter order - add error logs to mg_image_create_* - Fix build scripts on windows - fixed include mistake after rebase - collapsing milepost.{h|c|m} to orca.{h|c|m} and moving from sdk/ to src/ - rename orca_app.h/main.c to runtime.h/c - collapsed sdk/ to src/ - put old sdk files into their respective dirs - renamed canvas_api.json to surface_api.json - moved all stb headers in ext/stb/ - remove unused OpenSansLatinSubset.ttf font - moving cstdlib to src/wasmlibc and removing some duplicates with src/platform - move libc stdarg and string functions from platform/ to wasmlibc/ - rename wasmlibc to libc-shim to reflect non-completeness - Expose abort/assert variadic functions and macros to orca apps, and forward libc-shim abort/assert to these - move Orca API runtime implementations to runtime_xxx - fix missing math constants when including math.h with msvc in graphics_common.c - Change name of runtime to orca_runtime. When bundling on Windows, change name of runtime executable to the name of the app.
2023-08-09 11:06:32 +00:00
#include"app/mp_app.h"
typedef struct mp_key_state
{
u64 lastUpdate;
u32 transitionCount;
u32 repeatCount;
bool down;
bool sysClicked;
bool sysDoubleClicked;
} mp_key_state;
typedef struct mp_keyboard_state
{
mp_key_state keys[MP_KEY_COUNT];
mp_keymod_flags mods;
} mp_keyboard_state;
typedef struct mp_mouse_state
{
u64 lastUpdate;
bool posValid;
vec2 pos;
vec2 delta;
vec2 wheel;
union
{
mp_key_state buttons[MP_MOUSE_BUTTON_COUNT];
struct
{
mp_key_state left;
mp_key_state right;
mp_key_state middle;
mp_key_state ext1;
mp_key_state ext2;
};
};
} mp_mouse_state;
enum { MP_INPUT_TEXT_BACKING_SIZE = 64 };
typedef struct mp_text_state
{
u64 lastUpdate;
utf32 backing[MP_INPUT_TEXT_BACKING_SIZE];
str32 codePoints;
} mp_text_state;
typedef struct mp_input_state
{
u64 frameCounter;
mp_keyboard_state keyboard;
mp_mouse_state mouse;
mp_text_state text;
} mp_input_state;
MP_API void mp_input_process_event(mp_input_state* state, mp_event* event);
MP_API void mp_input_next_frame(mp_input_state* state);
MP_API bool mp_key_down(mp_input_state* state, mp_key_code key);
MP_API int mp_key_pressed(mp_input_state* state, mp_key_code key);
MP_API int mp_key_released(mp_input_state* state, mp_key_code key);
MP_API int mp_key_repeated(mp_input_state* state, mp_key_code key);
MP_API bool mp_mouse_down(mp_input_state* state, mp_mouse_button button);
MP_API int mp_mouse_pressed(mp_input_state* state, mp_mouse_button button);
MP_API int mp_mouse_released(mp_input_state* state, mp_mouse_button button);
MP_API bool mp_mouse_clicked(mp_input_state* state, mp_mouse_button button);
MP_API bool mp_mouse_double_clicked(mp_input_state* state, mp_mouse_button button);
MP_API vec2 mp_mouse_position(mp_input_state* state);
MP_API vec2 mp_mouse_delta(mp_input_state* state);
MP_API vec2 mp_mouse_wheel(mp_input_state* state);
MP_API str32 mp_input_text_utf32(mp_input_state* state, mem_arena* arena);
MP_API str8 mp_input_text_utf8(mp_input_state* state, mem_arena* arena);
MP_API mp_keymod_flags mp_key_mods(mp_input_state* state);
#endif //__INPUT_STATE_H_