diff --git a/src/app/app.h b/src/app/app.h index 367f116..4596ece 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -37,15 +37,19 @@ typedef enum OC_MOUSE_CURSOR_TEXT } oc_mouse_cursor; -typedef i32 oc_window_style; -static const oc_window_style OC_WINDOW_STYLE_NO_TITLE = 0x01 << 0, - OC_WINDOW_STYLE_FIXED_SIZE = 0x01 << 1, - OC_WINDOW_STYLE_NO_CLOSE = 0x01 << 2, - OC_WINDOW_STYLE_NO_MINIFY = 0x01 << 3, - OC_WINDOW_STYLE_NO_FOCUS = 0x01 << 4, - OC_WINDOW_STYLE_FLOAT = 0x01 << 5, - OC_WINDOW_STYLE_POPUPMENU = 0x01 << 6, - OC_WINDOW_STYLE_NO_BUTTONS = 0x01 << 7; +typedef u32 oc_window_style; + +enum oc_window_style_enum +{ + OC_WINDOW_STYLE_NO_TITLE = 0x01 << 0, + OC_WINDOW_STYLE_FIXED_SIZE = 0x01 << 1, + OC_WINDOW_STYLE_NO_CLOSE = 0x01 << 2, + OC_WINDOW_STYLE_NO_MINIFY = 0x01 << 3, + OC_WINDOW_STYLE_NO_FOCUS = 0x01 << 4, + OC_WINDOW_STYLE_FLOAT = 0x01 << 5, + OC_WINDOW_STYLE_POPUPMENU = 0x01 << 6, + OC_WINDOW_STYLE_NO_BUTTONS = 0x01 << 7 +}; typedef enum { diff --git a/src/ui/input_state.c b/src/ui/input_state.c index 32f6654..8db0d2e 100644 --- a/src/ui/input_state.c +++ b/src/ui/input_state.c @@ -231,9 +231,9 @@ oc_key_state oc_mouse_button_get_state(oc_input_state* input, oc_mouse_button bu return (state); } -int oc_key_state_press_count(oc_input_state* input, oc_key_state* key) +u8 oc_key_state_press_count(oc_input_state* input, oc_key_state* key) { - int count = 0; + u8 count = 0; if(key->lastUpdate == input->frameCounter) { count = key->transitionCount / 2; @@ -246,9 +246,9 @@ int oc_key_state_press_count(oc_input_state* input, oc_key_state* key) return (count); } -int oc_key_state_release_count(oc_input_state* input, oc_key_state* key) +u8 oc_key_state_release_count(oc_input_state* input, oc_key_state* key) { - int count = 0; + u8 count = 0; if(key->lastUpdate == input->frameCounter) { count = key->transitionCount / 2; @@ -261,9 +261,9 @@ int oc_key_state_release_count(oc_input_state* input, oc_key_state* key) return (count); } -int oc_key_state_repeat_count(oc_input_state* input, oc_key_state* key) +u8 oc_key_state_repeat_count(oc_input_state* input, oc_key_state* key) { - int count = 0; + u8 count = 0; if(key->lastUpdate == input->frameCounter) { count = key->repeatCount; @@ -277,25 +277,22 @@ bool oc_key_down(oc_input_state* input, oc_key_code key) return (state.down); } -int oc_key_pressed(oc_input_state* input, oc_key_code key) +u8 oc_key_press_count(oc_input_state* input, oc_key_code key) { oc_key_state state = oc_key_get_state(input, key); - int res = oc_key_state_press_count(input, &state); - return (res); + return (oc_key_state_press_count(input, &state)); } -int oc_key_released(oc_input_state* input, oc_key_code key) +u8 oc_key_release_count(oc_input_state* input, oc_key_code key) { oc_key_state state = oc_key_get_state(input, key); - int res = oc_key_state_release_count(input, &state); - return (res); + return (oc_key_state_release_count(input, &state)); } -int oc_key_repeated(oc_input_state* input, oc_key_code key) +u8 oc_key_repeat_count(oc_input_state* input, oc_key_code key) { oc_key_state state = oc_key_get_state(input, key); - int res = oc_key_state_repeat_count(input, &state); - return (res); + return (oc_key_state_repeat_count(input, &state)); } bool oc_key_down_scancode(oc_input_state* state, oc_scan_code scanCode) @@ -304,22 +301,22 @@ bool oc_key_down_scancode(oc_input_state* state, oc_scan_code scanCode) return (oc_key_down(state, key)); } -int oc_key_pressed_scancode(oc_input_state* state, oc_scan_code scanCode) +u8 oc_key_press_count_scancode(oc_input_state* state, oc_scan_code scanCode) { oc_key_code key = oc_scancode_to_keycode(scanCode); - return (oc_key_pressed(state, key)); + return (oc_key_press_count(state, key)); } -int oc_key_released_scancode(oc_input_state* state, oc_scan_code scanCode) +u8 oc_key_release_count_scancode(oc_input_state* state, oc_scan_code scanCode) { oc_key_code key = oc_scancode_to_keycode(scanCode); - return (oc_key_released(state, key)); + return (oc_key_release_count(state, key)); } -int oc_key_repeated_scancode(oc_input_state* state, oc_scan_code scanCode) +u8 oc_key_repeat_count_scancode(oc_input_state* state, oc_scan_code scanCode) { oc_key_code key = oc_scancode_to_keycode(scanCode); - return (oc_key_repeated(state, key)); + return (oc_key_repeat_count(state, key)); } bool oc_mouse_down(oc_input_state* input, oc_mouse_button button) @@ -328,18 +325,16 @@ bool oc_mouse_down(oc_input_state* input, oc_mouse_button button) return (state.down); } -int oc_mouse_pressed(oc_input_state* input, oc_mouse_button button) +u8 oc_mouse_pressed(oc_input_state* input, oc_mouse_button button) { oc_key_state state = oc_mouse_button_get_state(input, button); - int res = oc_key_state_press_count(input, &state); - return (res); + return (oc_key_state_press_count(input, &state)); } -int oc_mouse_released(oc_input_state* input, oc_mouse_button button) +u8 oc_mouse_released(oc_input_state* input, oc_mouse_button button) { oc_key_state state = oc_mouse_button_get_state(input, button); - int res = oc_key_state_release_count(input, &state); - return (res); + return (oc_key_state_release_count(input, &state)); } bool oc_mouse_clicked(oc_input_state* input, oc_mouse_button button) diff --git a/src/ui/input_state.h b/src/ui/input_state.h index c476f51..583c2e5 100644 --- a/src/ui/input_state.h +++ b/src/ui/input_state.h @@ -90,18 +90,18 @@ ORCA_API void oc_input_process_event(oc_input_state* state, oc_arena* arena, oc_ ORCA_API void oc_input_next_frame(oc_input_state* state); ORCA_API bool oc_key_down(oc_input_state* state, oc_key_code key); -ORCA_API int oc_key_pressed(oc_input_state* state, oc_key_code key); -ORCA_API int oc_key_released(oc_input_state* state, oc_key_code key); -ORCA_API int oc_key_repeated(oc_input_state* state, oc_key_code key); +ORCA_API u8 oc_key_press_count(oc_input_state* state, oc_key_code key); +ORCA_API u8 oc_key_release_count(oc_input_state* state, oc_key_code key); +ORCA_API u8 oc_key_repeat_count(oc_input_state* state, oc_key_code key); ORCA_API bool oc_key_down_scancode(oc_input_state* state, oc_scan_code key); -ORCA_API int oc_key_pressed_scancode(oc_input_state* state, oc_scan_code key); -ORCA_API int oc_key_released_scancode(oc_input_state* state, oc_scan_code key); -ORCA_API int oc_key_repeated_scancode(oc_input_state* state, oc_scan_code key); +ORCA_API u8 oc_key_press_count_scancode(oc_input_state* state, oc_scan_code key); +ORCA_API u8 oc_key_release_count_scancode(oc_input_state* state, oc_scan_code key); +ORCA_API u8 oc_key_repeat_count_scancode(oc_input_state* state, oc_scan_code key); ORCA_API bool oc_mouse_down(oc_input_state* state, oc_mouse_button button); -ORCA_API int oc_mouse_pressed(oc_input_state* state, oc_mouse_button button); -ORCA_API int oc_mouse_released(oc_input_state* state, oc_mouse_button button); +ORCA_API u8 oc_mouse_pressed(oc_input_state* state, oc_mouse_button button); +ORCA_API u8 oc_mouse_released(oc_input_state* state, oc_mouse_button button); ORCA_API bool oc_mouse_clicked(oc_input_state* state, oc_mouse_button button); ORCA_API bool oc_mouse_double_clicked(oc_input_state* state, oc_mouse_button button); diff --git a/src/ui/ui.c b/src/ui/ui.c index 3476168..5d6ff5b 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -3836,7 +3836,7 @@ oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8 { const oc_ui_edit_command* command = &(editCommands[i]); - if((oc_key_pressed(&ui->input, command->key) || oc_key_repeated(&ui->input, command->key)) + if((oc_key_press_count(&ui->input, command->key) || oc_key_repeat_count(&ui->input, command->key)) && (mods & ~OC_KEYMOD_MAIN_MODIFIER) == command->mods) { codepoints = oc_ui_edit_perform_operation(ui, command->operation, command->move, command->direction, codepoints); @@ -3858,7 +3858,7 @@ oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8 result.text = oc_utf8_push_from_codepoints(arena, codepoints); } - if(oc_key_pressed(&ui->input, OC_KEY_ENTER)) + if(oc_key_press_count(&ui->input, OC_KEY_ENTER)) { //TODO(martin): extract in gui_edit_complete() (and use below) result.accepted = true;