Minor consistency things:

- oc_window_style could be enum
- clikCount in oc_key_event to u8
- return of oc_input_key_press -> u8
- rename oc_key_pressed/released/repeated to oc_key_press/release/repeat_count to reflect meaning of return value
This commit is contained in:
Martin Fouilleul 2023-09-14 10:47:10 +02:00
parent 0e680c989b
commit 47dc052508
4 changed files with 45 additions and 46 deletions

View File

@ -37,15 +37,19 @@ typedef enum
OC_MOUSE_CURSOR_TEXT OC_MOUSE_CURSOR_TEXT
} oc_mouse_cursor; } oc_mouse_cursor;
typedef i32 oc_window_style; typedef u32 oc_window_style;
static const oc_window_style OC_WINDOW_STYLE_NO_TITLE = 0x01 << 0,
enum oc_window_style_enum
{
OC_WINDOW_STYLE_NO_TITLE = 0x01 << 0,
OC_WINDOW_STYLE_FIXED_SIZE = 0x01 << 1, OC_WINDOW_STYLE_FIXED_SIZE = 0x01 << 1,
OC_WINDOW_STYLE_NO_CLOSE = 0x01 << 2, OC_WINDOW_STYLE_NO_CLOSE = 0x01 << 2,
OC_WINDOW_STYLE_NO_MINIFY = 0x01 << 3, OC_WINDOW_STYLE_NO_MINIFY = 0x01 << 3,
OC_WINDOW_STYLE_NO_FOCUS = 0x01 << 4, OC_WINDOW_STYLE_NO_FOCUS = 0x01 << 4,
OC_WINDOW_STYLE_FLOAT = 0x01 << 5, OC_WINDOW_STYLE_FLOAT = 0x01 << 5,
OC_WINDOW_STYLE_POPUPMENU = 0x01 << 6, OC_WINDOW_STYLE_POPUPMENU = 0x01 << 6,
OC_WINDOW_STYLE_NO_BUTTONS = 0x01 << 7; OC_WINDOW_STYLE_NO_BUTTONS = 0x01 << 7
};
typedef enum typedef enum
{ {

View File

@ -231,9 +231,9 @@ oc_key_state oc_mouse_button_get_state(oc_input_state* input, oc_mouse_button bu
return (state); 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) if(key->lastUpdate == input->frameCounter)
{ {
count = key->transitionCount / 2; count = key->transitionCount / 2;
@ -246,9 +246,9 @@ int oc_key_state_press_count(oc_input_state* input, oc_key_state* key)
return (count); 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) if(key->lastUpdate == input->frameCounter)
{ {
count = key->transitionCount / 2; count = key->transitionCount / 2;
@ -261,9 +261,9 @@ int oc_key_state_release_count(oc_input_state* input, oc_key_state* key)
return (count); 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) if(key->lastUpdate == input->frameCounter)
{ {
count = key->repeatCount; count = key->repeatCount;
@ -277,25 +277,22 @@ bool oc_key_down(oc_input_state* input, oc_key_code key)
return (state.down); 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); oc_key_state state = oc_key_get_state(input, key);
int res = oc_key_state_press_count(input, &state); return (oc_key_state_press_count(input, &state));
return (res);
} }
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); oc_key_state state = oc_key_get_state(input, key);
int res = oc_key_state_release_count(input, &state); return (oc_key_state_release_count(input, &state));
return (res);
} }
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); oc_key_state state = oc_key_get_state(input, key);
int res = oc_key_state_repeat_count(input, &state); return (oc_key_state_repeat_count(input, &state));
return (res);
} }
bool oc_key_down_scancode(oc_input_state* state, oc_scan_code scanCode) 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)); 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); 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); 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); 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) 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); 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); oc_key_state state = oc_mouse_button_get_state(input, button);
int res = oc_key_state_press_count(input, &state); return (oc_key_state_press_count(input, &state));
return (res);
} }
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); oc_key_state state = oc_mouse_button_get_state(input, button);
int res = oc_key_state_release_count(input, &state); return (oc_key_state_release_count(input, &state));
return (res);
} }
bool oc_mouse_clicked(oc_input_state* input, oc_mouse_button button) bool oc_mouse_clicked(oc_input_state* input, oc_mouse_button button)

View File

@ -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 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 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 u8 oc_key_press_count(oc_input_state* state, oc_key_code key);
ORCA_API int oc_key_released(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 int oc_key_repeated(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 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 u8 oc_key_press_count_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 u8 oc_key_release_count_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_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 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 u8 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_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_clicked(oc_input_state* state, oc_mouse_button button);
ORCA_API bool oc_mouse_double_clicked(oc_input_state* state, oc_mouse_button button); ORCA_API bool oc_mouse_double_clicked(oc_input_state* state, oc_mouse_button button);

View File

@ -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]); 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) && (mods & ~OC_KEYMOD_MAIN_MODIFIER) == command->mods)
{ {
codepoints = oc_ui_edit_perform_operation(ui, command->operation, command->move, command->direction, codepoints); 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); 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) //TODO(martin): extract in gui_edit_complete() (and use below)
result.accepted = true; result.accepted = true;