format app.h

This commit is contained in:
Reuben Dunnington 2023-08-23 12:59:53 -07:00
parent b9e843f4bb
commit 72209200b5
Signed by: rdunnington
GPG Key ID: 3D57C8938EA08E90
1 changed files with 341 additions and 340 deletions

View File

@ -15,31 +15,30 @@
#include "util/utf8.h" #include "util/utf8.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Typedefs, enums and constants // Typedefs, enums and constants
//-------------------------------------------------------------------- //--------------------------------------------------------------------
typedef struct oc_window typedef struct oc_window
{ {
u64 h; u64 h;
} oc_window; } oc_window;
typedef enum typedef enum
{ {
OC_MOUSE_CURSOR_ARROW, OC_MOUSE_CURSOR_ARROW,
OC_MOUSE_CURSOR_RESIZE_0, OC_MOUSE_CURSOR_RESIZE_0,
OC_MOUSE_CURSOR_RESIZE_90, OC_MOUSE_CURSOR_RESIZE_90,
OC_MOUSE_CURSOR_RESIZE_45, OC_MOUSE_CURSOR_RESIZE_45,
OC_MOUSE_CURSOR_RESIZE_135, OC_MOUSE_CURSOR_RESIZE_135,
OC_MOUSE_CURSOR_TEXT OC_MOUSE_CURSOR_TEXT
} oc_mouse_cursor; } oc_mouse_cursor;
typedef i32 oc_window_style; typedef i32 oc_window_style;
static const oc_window_style OC_WINDOW_STYLE_NO_TITLE = 0x01 << 0, static const oc_window_style 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,
@ -48,8 +47,8 @@ extern "C"
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
{ {
OC_EVENT_NONE, OC_EVENT_NONE,
OC_EVENT_KEYBOARD_MODS, //TODO: remove, keep only key? OC_EVENT_KEYBOARD_MODS, //TODO: remove, keep only key?
OC_EVENT_KEYBOARD_KEY, OC_EVENT_KEYBOARD_KEY,
@ -69,18 +68,18 @@ extern "C"
OC_EVENT_PATHDROP, OC_EVENT_PATHDROP,
OC_EVENT_FRAME, OC_EVENT_FRAME,
OC_EVENT_QUIT OC_EVENT_QUIT
} oc_event_type; } oc_event_type;
typedef enum typedef enum
{ {
OC_KEY_NO_ACTION, OC_KEY_NO_ACTION,
OC_KEY_PRESS, OC_KEY_PRESS,
OC_KEY_RELEASE, OC_KEY_RELEASE,
OC_KEY_REPEAT OC_KEY_REPEAT
} oc_key_action; } oc_key_action;
typedef enum typedef enum
{ {
OC_KEY_UNKNOWN = 0, OC_KEY_UNKNOWN = 0,
OC_KEY_SPACE = 32, OC_KEY_SPACE = 32,
OC_KEY_APOSTROPHE = 39, /* ' */ OC_KEY_APOSTROPHE = 39, /* ' */
@ -203,62 +202,62 @@ extern "C"
OC_KEY_RIGHT_SUPER = 347, OC_KEY_RIGHT_SUPER = 347,
OC_KEY_MENU = 348, OC_KEY_MENU = 348,
OC_KEY_COUNT OC_KEY_COUNT
} oc_key_code; } oc_key_code;
typedef enum typedef enum
{ {
OC_KEYMOD_NONE = 0x00, OC_KEYMOD_NONE = 0x00,
OC_KEYMOD_ALT = 0x01, OC_KEYMOD_ALT = 0x01,
OC_KEYMOD_SHIFT = 0x02, OC_KEYMOD_SHIFT = 0x02,
OC_KEYMOD_CTRL = 0x04, OC_KEYMOD_CTRL = 0x04,
OC_KEYMOD_CMD = 0x08, OC_KEYMOD_CMD = 0x08,
OC_KEYMOD_MAIN_MODIFIER = 0x16 /* CMD on Mac, CTRL on Win32 */ OC_KEYMOD_MAIN_MODIFIER = 0x16 /* CMD on Mac, CTRL on Win32 */
} oc_keymod_flags; } oc_keymod_flags;
typedef enum typedef enum
{ {
OC_MOUSE_LEFT = 0x00, OC_MOUSE_LEFT = 0x00,
OC_MOUSE_RIGHT = 0x01, OC_MOUSE_RIGHT = 0x01,
OC_MOUSE_MIDDLE = 0x02, OC_MOUSE_MIDDLE = 0x02,
OC_MOUSE_EXT1 = 0x03, OC_MOUSE_EXT1 = 0x03,
OC_MOUSE_EXT2 = 0x04, OC_MOUSE_EXT2 = 0x04,
OC_MOUSE_BUTTON_COUNT OC_MOUSE_BUTTON_COUNT
} oc_mouse_button; } oc_mouse_button;
typedef struct oc_key_event // keyboard and mouse buttons input typedef struct oc_key_event // keyboard and mouse buttons input
{ {
oc_key_action action; oc_key_action action;
i32 code; i32 code;
oc_keymod_flags mods; oc_keymod_flags mods;
char label[8]; char label[8];
u8 labelLen; u8 labelLen;
int clickCount; int clickCount;
} oc_key_event; } oc_key_event;
typedef struct oc_char_event // character input typedef struct oc_char_event // character input
{ {
oc_utf32 codepoint; oc_utf32 codepoint;
char sequence[8]; char sequence[8];
u8 seqLen; u8 seqLen;
} oc_char_event; } oc_char_event;
typedef struct oc_mouse_event // mouse move/scroll typedef struct oc_mouse_event // mouse move/scroll
{ {
f32 x; f32 x;
f32 y; f32 y;
f32 deltaX; f32 deltaX;
f32 deltaY; f32 deltaY;
oc_keymod_flags mods; oc_keymod_flags mods;
} oc_mouse_event; } oc_mouse_event;
typedef struct oc_move_event // window resize / move typedef struct oc_move_event // window resize / move
{ {
oc_rect frame; oc_rect frame;
oc_rect content; oc_rect content;
} oc_move_event; } oc_move_event;
typedef struct oc_event typedef struct oc_event
{ {
//TODO clipboard and path drop //TODO clipboard and path drop
oc_window window; oc_window window;
oc_event_type type; oc_event_type type;
@ -272,135 +271,137 @@ extern "C"
oc_str8_list paths; oc_str8_list paths;
}; };
} oc_event; } oc_event;
//NOTE: these APIs are not directly available to Orca apps //NOTE: these APIs are not directly available to Orca apps
#if !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA) #if !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA)
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// app management // app management
//-------------------------------------------------------------------- //--------------------------------------------------------------------
ORCA_API void oc_init(void); ORCA_API void oc_init(void);
ORCA_API void oc_terminate(void); ORCA_API void oc_terminate(void);
ORCA_API bool oc_should_quit(void); ORCA_API bool oc_should_quit(void);
ORCA_API void oc_cancel_quit(void); ORCA_API void oc_cancel_quit(void);
ORCA_API void oc_request_quit(void); ORCA_API void oc_request_quit(void);
ORCA_API void oc_set_cursor(oc_mouse_cursor cursor); ORCA_API void oc_set_cursor(oc_mouse_cursor cursor);
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Main loop and events handling // Main loop and events handling
//-------------------------------------------------------------------- //--------------------------------------------------------------------
/*NOTE: /*NOTE:
oc_pump_events() pumps system events into the event queue. A timeout of 0 polls for events, oc_pump_events() pumps system events into the event queue. A timeout of 0 polls for events,
while a timeout of -1 blocks for events. A timeout > 0 blocks until new events are available while a timeout of -1 blocks for events. A timeout > 0 blocks until new events are available
or the timeout elapses. or the timeout elapses.
oc_next_event() get the next event from the event queue, allocating from the passed arena oc_next_event() get the next event from the event queue, allocating from the passed arena
*/ */
ORCA_API void oc_pump_events(f64 timeout); ORCA_API void oc_pump_events(f64 timeout);
ORCA_API oc_event* oc_next_event(oc_arena* arena); ORCA_API oc_event* oc_next_event(oc_arena* arena);
typedef void (*oc_live_resize_callback)(oc_event event, void* data); typedef void (*oc_live_resize_callback)(oc_event event, void* data);
ORCA_API void oc_set_live_resize_callback(oc_live_resize_callback callback, void* data); ORCA_API void oc_set_live_resize_callback(oc_live_resize_callback callback, void* data);
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// window management // window management
//-------------------------------------------------------------------- //--------------------------------------------------------------------
ORCA_API bool oc_window_handle_is_null(oc_window window); ORCA_API bool oc_window_handle_is_null(oc_window window);
ORCA_API oc_window oc_window_null_handle(void); ORCA_API oc_window oc_window_null_handle(void);
ORCA_API oc_window oc_window_create(oc_rect contentRect, oc_str8 title, oc_window_style style); ORCA_API oc_window oc_window_create(oc_rect contentRect, oc_str8 title, oc_window_style style);
ORCA_API void oc_window_destroy(oc_window window); ORCA_API void oc_window_destroy(oc_window window);
ORCA_API void* oc_window_native_pointer(oc_window window); ORCA_API void* oc_window_native_pointer(oc_window window);
ORCA_API bool oc_window_should_close(oc_window window); ORCA_API bool oc_window_should_close(oc_window window);
ORCA_API void oc_window_request_close(oc_window window); ORCA_API void oc_window_request_close(oc_window window);
ORCA_API void oc_window_cancel_close(oc_window window); ORCA_API void oc_window_cancel_close(oc_window window);
ORCA_API bool oc_window_is_hidden(oc_window window); ORCA_API bool oc_window_is_hidden(oc_window window);
ORCA_API void oc_window_hide(oc_window window); ORCA_API void oc_window_hide(oc_window window);
ORCA_API void oc_window_show(oc_window window); ORCA_API void oc_window_show(oc_window window);
ORCA_API bool oc_window_is_minimized(oc_window window); ORCA_API bool oc_window_is_minimized(oc_window window);
ORCA_API void oc_window_minimize(oc_window window); ORCA_API bool oc_window_is_maximized(oc_window window);
ORCA_API void oc_window_restore(oc_window window); ORCA_API void oc_window_minimize(oc_window window);
ORCA_API void oc_window_maximize(oc_window window);
ORCA_API void oc_window_restore(oc_window window);
ORCA_API bool oc_window_has_focus(oc_window window); ORCA_API bool oc_window_has_focus(oc_window window);
ORCA_API void oc_window_focus(oc_window window); ORCA_API void oc_window_focus(oc_window window);
ORCA_API void oc_window_unfocus(oc_window window); ORCA_API void oc_window_unfocus(oc_window window);
ORCA_API void oc_window_send_to_back(oc_window window); ORCA_API void oc_window_send_to_back(oc_window window);
ORCA_API void oc_window_bring_to_front(oc_window window); ORCA_API void oc_window_bring_to_front(oc_window window);
ORCA_API oc_rect oc_window_get_frame_rect(oc_window window); ORCA_API oc_rect oc_window_get_frame_rect(oc_window window);
ORCA_API void oc_window_set_frame_rect(oc_window window, oc_rect rect); ORCA_API void oc_window_set_frame_rect(oc_window window, oc_rect rect);
ORCA_API void oc_window_set_frame_position(oc_window window, oc_vec2 position); ORCA_API void oc_window_set_frame_position(oc_window window, oc_vec2 position);
ORCA_API void oc_window_set_frame_size(oc_window window, oc_vec2 size); ORCA_API void oc_window_set_frame_size(oc_window window, oc_vec2 size);
ORCA_API oc_rect oc_window_get_content_rect(oc_window window); ORCA_API oc_rect oc_window_get_content_rect(oc_window window);
ORCA_API void oc_window_set_content_rect(oc_window window, oc_rect rect); ORCA_API void oc_window_set_content_rect(oc_window window, oc_rect rect);
ORCA_API void oc_window_set_content_position(oc_window window, oc_vec2 position); ORCA_API void oc_window_set_content_position(oc_window window, oc_vec2 position);
ORCA_API void oc_window_set_content_size(oc_window window, oc_vec2 size); ORCA_API void oc_window_set_content_size(oc_window window, oc_vec2 size);
ORCA_API void oc_window_center(oc_window window); ORCA_API void oc_window_center(oc_window window);
ORCA_API oc_rect oc_window_content_rect_for_frame_rect(oc_rect frameRect, oc_window_style style); ORCA_API oc_rect oc_window_content_rect_for_frame_rect(oc_rect frameRect, oc_window_style style);
ORCA_API oc_rect oc_window_frame_rect_for_content_rect(oc_rect contentRect, oc_window_style style); ORCA_API oc_rect oc_window_frame_rect_for_content_rect(oc_rect contentRect, oc_window_style style);
//--------------------------------------------------------------- //---------------------------------------------------------------
// Dispatching stuff to the main thread // Dispatching stuff to the main thread
//--------------------------------------------------------------- //---------------------------------------------------------------
typedef i32 (*oc_dispatch_proc)(void* user); typedef i32 (*oc_dispatch_proc)(void* user);
ORCA_API i32 oc_dispatch_on_main_thread_sync(oc_window main_window, oc_dispatch_proc proc, void* user); ORCA_API i32 oc_dispatch_on_main_thread_sync(oc_window main_window, oc_dispatch_proc proc, void* user);
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Clipboard // Clipboard
//-------------------------------------------------------------------- //--------------------------------------------------------------------
ORCA_API void oc_clipboard_clear(void); ORCA_API void oc_clipboard_clear(void);
ORCA_API void oc_clipboard_set_string(oc_str8 string); ORCA_API void oc_clipboard_set_string(oc_str8 string);
ORCA_API oc_str8 oc_clipboard_get_string(oc_arena* arena); ORCA_API oc_str8 oc_clipboard_get_string(oc_arena* arena);
ORCA_API oc_str8 oc_clipboard_copy_string(oc_str8 backing); ORCA_API oc_str8 oc_clipboard_copy_string(oc_str8 backing);
ORCA_API bool oc_clipboard_has_tag(const char* tag); ORCA_API bool oc_clipboard_has_tag(const char* tag);
ORCA_API void oc_clipboard_set_data_for_tag(const char* tag, oc_str8 data); ORCA_API void oc_clipboard_set_data_for_tag(const char* tag, oc_str8 data);
ORCA_API oc_str8 oc_clipboard_get_data_for_tag(oc_arena* arena, const char* tag); ORCA_API oc_str8 oc_clipboard_get_data_for_tag(oc_arena* arena, const char* tag);
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// native open/save/alert windows // native open/save/alert windows
//-------------------------------------------------------------------- //--------------------------------------------------------------------
ORCA_API oc_str8 oc_open_dialog(oc_arena* arena, ORCA_API oc_str8 oc_open_dialog(oc_arena* arena,
oc_str8 title, oc_str8 title,
oc_str8 defaultPath, oc_str8 defaultPath,
oc_str8_list filters, oc_str8_list filters,
bool directory); bool directory);
ORCA_API oc_str8 oc_save_dialog(oc_arena* arena, ORCA_API oc_str8 oc_save_dialog(oc_arena* arena,
oc_str8 title, oc_str8 title,
oc_str8 defaultPath, oc_str8 defaultPath,
oc_str8_list filters); oc_str8_list filters);
ORCA_API int oc_alert_popup(oc_str8 title, ORCA_API int oc_alert_popup(oc_str8 title,
oc_str8 message, oc_str8 message,
oc_str8_list options); oc_str8_list options);
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// file system stuff... //TODO: move elsewhere // file system stuff... //TODO: move elsewhere
//-------------------------------------------------------------------- //--------------------------------------------------------------------
ORCA_API int oc_file_move(oc_str8 from, oc_str8 to); ORCA_API int oc_file_move(oc_str8 from, oc_str8 to);
ORCA_API int oc_file_remove(oc_str8 path); ORCA_API int oc_file_remove(oc_str8 path);
ORCA_API int oc_directory_create(oc_str8 path); ORCA_API int oc_directory_create(oc_str8 path);
#else #else
void ORCA_IMPORT(oc_request_quit)(void); void ORCA_IMPORT(oc_request_quit)(void);
#endif // !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA) #endif // !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA)