- Added basic cheatsheets

- Minor cleanups:
    - Hiding some native-only path APIs
    - Re-formatting ui.h
This commit is contained in:
Martin Fouilleul 2023-09-05 16:25:04 +02:00
parent bd35b75f4b
commit 425d9b3448
9 changed files with 874 additions and 464 deletions

35
doc/cheatsheet_app.h Normal file
View File

@ -0,0 +1,35 @@
/************************************************************/ /**
*
* @file: cheatsheet_app.h
* @author: Martin Fouilleul
* @date: 05/09/2023
*
*****************************************************************/
//----------------------------------------------------------------
// Handlers (can be defined by your app to respond to events)
//----------------------------------------------------------------
void oc_on_init(void);
void oc_on_mouse_down(oc_mouse_button button);
void oc_on_mouse_up(oc_mouse_button button);
void oc_on_mouse_enter(void);
void oc_on_mouse_leave(void);
void oc_on_mouse_move(f32 x, f32 y, f32 deltaX, f32 deltaY);
void oc_on_mouse_wheel(f32 deltaX, f32 deltaY);
void oc_on_key_down(oc_key_code key);
void oc_on_key_up(oc_key_code key);
void oc_on_frame_refresh(void);
void oc_on_resize(f32 width, f32 height);
void oc_on_raw_event(oc_event* event);
void oc_on_terminate(void);
//----------------------------------------------------------------
// Window
//----------------------------------------------------------------
void oc_window_set_title(oc_str8 title);
void oc_window_set_size(oc_vec2 size);
//----------------------------------------------------------------
// Quitting
//----------------------------------------------------------------
void oc_request_quit(void)

162
doc/cheatsheet_graphics.h Normal file
View File

@ -0,0 +1,162 @@
/************************************************************/ /**
*
* @file: cheatsheet_graphics.h
* @author: Martin Fouilleul
* @date: 05/09/2023
*
*****************************************************************/
//------------------------------------------------------------------------------------------
// graphics surface
//------------------------------------------------------------------------------------------
oc_surface oc_surface_nil(void);
bool oc_surface_is_nil(oc_surface surface);
oc_surface oc_surface_canvas();
oc_surface oc_surface_gles();
void oc_surface_destroy(oc_surface surface);
void oc_surface_select(oc_surface surface);
void oc_surface_present(oc_surface surface);
void oc_surface_deselect(void);
oc_vec2 oc_surface_get_size(oc_surface surface);
oc_vec2 oc_surface_contents_scaling(oc_surface surface);
void oc_surface_bring_to_front(oc_surface surface);
void oc_surface_send_to_back(oc_surface surface);
//------------------------------------------------------------------------------------------
// 2D canvas command buffer
//------------------------------------------------------------------------------------------
oc_canvas oc_canvas_nil(void);
bool oc_canvas_is_nil(oc_canvas canvas);
oc_canvas oc_canvas_create(void);
void oc_canvas_destroy(oc_canvas canvas);
oc_canvas oc_canvas_set_current(oc_canvas canvas);
void oc_render(oc_surface surface, oc_canvas canvas);
//------------------------------------------------------------------------------------------
// transform and clipping
//------------------------------------------------------------------------------------------
void oc_matrix_push(oc_mat2x3 matrix);
void oc_matrix_pop(void);
oc_mat2x3 oc_matrix_top();
void oc_clip_push(f32 x, f32 y, f32 w, f32 h);
void oc_clip_pop(void);
oc_rect oc_clip_top();
//------------------------------------------------------------------------------------------
// graphics attributes setting/getting
//------------------------------------------------------------------------------------------
void oc_set_color(oc_color color);
void oc_set_color_rgba(f32 r, f32 g, f32 b, f32 a);
void oc_set_width(f32 width);
void oc_set_tolerance(f32 tolerance);
void oc_set_joint(oc_joint_type joint);
void oc_set_max_joint_excursion(f32 maxJointExcursion);
void oc_set_cap(oc_cap_type cap);
void oc_set_font(oc_font font);
void oc_set_font_size(f32 size);
void oc_set_text_flip(bool flip);
void oc_set_image(oc_image image);
void oc_set_image_source_region(oc_rect region);
oc_color oc_get_color(void);
f32 oc_get_width(void);
f32 oc_get_tolerance(void);
oc_joint_type oc_get_joint(void);
f32 oc_get_max_joint_excursion(void);
oc_cap_type oc_get_cap(void);
oc_font oc_get_font(void);
f32 oc_get_font_size(void);
bool oc_get_text_flip(void);
oc_image oc_get_image();
//------------------------------------------------------------------------------------------
// path construction
//------------------------------------------------------------------------------------------
oc_vec2 oc_get_position(void);
void oc_move_to(f32 x, f32 y);
void oc_line_to(f32 x, f32 y);
void oc_quadratic_to(f32 x1, f32 y1, f32 x2, f32 y2);
void oc_cubic_to(f32 x1, f32 y1, f32 x2, f32 y2, f32 x3, f32 y3);
void oc_close_path(void);
oc_rect oc_glyph_outlines(oc_str32 glyphIndices);
void oc_codepoints_outlines(oc_str32 string);
void oc_text_outlines(oc_str8 string);
//------------------------------------------------------------------------------------------
// clear/fill/stroke
//------------------------------------------------------------------------------------------
void oc_clear(void);
void oc_fill(void);
void oc_stroke(void);
//------------------------------------------------------------------------------------------
// shapes helpers
//------------------------------------------------------------------------------------------
void oc_rectangle_fill(f32 x, f32 y, f32 w, f32 h);
void oc_rectangle_stroke(f32 x, f32 y, f32 w, f32 h);
void oc_rounded_rectangle_fill(f32 x, f32 y, f32 w, f32 h, f32 r);
void oc_rounded_rectangle_stroke(f32 x, f32 y, f32 w, f32 h, f32 r);
void oc_ellipse_fill(f32 x, f32 y, f32 rx, f32 ry);
void oc_ellipse_stroke(f32 x, f32 y, f32 rx, f32 ry);
void oc_circle_fill(f32 x, f32 y, f32 r);
void oc_circle_stroke(f32 x, f32 y, f32 r);
void oc_arc(f32 x, f32 y, f32 r, f32 arcAngle, f32 startAngle);
void oc_image_draw(oc_image image, oc_rect rect);
void oc_image_draw_region(oc_image image, oc_rect srcRegion, oc_rect dstRegion);
//------------------------------------------------------------------------------------------
// fonts
//------------------------------------------------------------------------------------------
oc_font oc_font_nil(void);
bool oc_font_is_nil(oc_font font);
oc_font oc_font_create_from_memory(oc_str8 mem, u32 rangeCount, oc_unicode_range* ranges);
void oc_font_destroy(oc_font font);
oc_font_extents oc_font_get_extents(oc_font font);
oc_font_extents oc_font_get_scaled_extents(oc_font font, f32 emSize);
f32 oc_font_get_scale_for_em_pixels(oc_font font, f32 emSize);
u32 oc_font_get_glyph_index(oc_font font, oc_utf32 codePoint);
oc_str32 oc_font_get_glyph_indices(oc_font font, oc_str32 codePoints, oc_str32 backing);
oc_str32 oc_font_push_glyph_indices(oc_font font, oc_arena* arena, oc_str32 codePoints);
int oc_font_get_codepoint_extents(oc_font font, oc_utf32 codePoint, oc_text_extents* outExtents);
int oc_font_get_glyph_extents(oc_font font, oc_str32 glyphIndices, oc_text_extents* outExtents);
oc_rect oc_text_bounding_box_utf32(oc_font font, f32 fontSize, oc_str32 text);
oc_rect oc_text_bounding_box(oc_font font, f32 fontSize, oc_str8 text);
//------------------------------------------------------------------------------------------
// images
//------------------------------------------------------------------------------------------
oc_image oc_image_nil(void);
bool oc_image_is_nil(oc_image a);
oc_image oc_image_create(oc_surface surface, u32 width, u32 height);
oc_image oc_image_create_from_rgba8(oc_surface surface, u32 width, u32 height, u8* pixels);
oc_image oc_image_create_from_memory(oc_surface surface, oc_str8 mem, bool flip);
oc_image oc_image_create_from_file(oc_surface surface, oc_str8 path, bool flip);
void oc_image_destroy(oc_image image);
void oc_image_upload_region_rgba8(oc_image image, oc_rect region, u8* pixels);
oc_vec2 oc_image_size(oc_image image);
//------------------------------------------------------------------------------------------
// image atlas
//------------------------------------------------------------------------------------------
oc_rect_atlas* oc_rect_atlas_create(oc_arena* arena, i32 width, i32 height);
oc_rect oc_rect_atlas_alloc(oc_rect_atlas* atlas, i32 width, i32 height);
void oc_rect_atlas_recycle(oc_rect_atlas* atlas, oc_rect rect);
oc_image_region oc_image_atlas_alloc_from_rgba8(oc_rect_atlas* atlas, oc_image backingImage, u32 width, u32 height, u8* pixels);
oc_image_region oc_image_atlas_alloc_from_data(oc_rect_atlas* atlas, oc_image backingImage, oc_str8 data, bool flip);
oc_image_region oc_image_atlas_alloc_from_file(oc_rect_atlas* atlas, oc_image backingImage, oc_str8 path, bool flip);
void oc_image_atlas_recycle(oc_rect_atlas* atlas, oc_image_region imageRgn);

39
doc/cheatsheet_io.h Normal file
View File

@ -0,0 +1,39 @@
/************************************************************/ /**
*
* @file: cheatsheet_io.h
* @author: Martin Fouilleul
* @date: 05/09/2023
*
*****************************************************************/
//----------------------------------------------------------------
// Low-level File IO API
//----------------------------------------------------------------
oc_io_cmp oc_io_wait_single_req(oc_io_req* req);
//----------------------------------------------------------------
// High-level File IO API
//----------------------------------------------------------------
oc_file oc_file_nil();
bool oc_file_is_nil(oc_file handle);
oc_file oc_file_open(oc_str8 path, oc_file_access rights, oc_file_open_flags flags);
oc_file oc_file_open_at(oc_file dir, oc_str8 path, oc_file_access rights, oc_file_open_flags flags);
void oc_file_close(oc_file file);
oc_io_error oc_file_last_error(oc_file handle);
i64 oc_file_pos(oc_file file);
i64 oc_file_seek(oc_file file, i64 offset, oc_file_whence whence);
u64 oc_file_write(oc_file file, u64 size, char* buffer);
u64 oc_file_read(oc_file file, u64 size, char* buffer);
oc_file_status oc_file_get_status(oc_file file);
u64 oc_file_size(oc_file file);
//----------------------------------------------------------------
// Asking users for file capabilities
//----------------------------------------------------------------
oc_file oc_file_open_with_request(oc_str8 path, oc_file_access rights, oc_file_open_flags flags);
oc_file_open_with_dialog_result oc_file_open_with_dialog(oc_arena* arena, oc_file_access rights, oc_file_open_flags flags, oc_file_dialog_desc* desc);

64
doc/cheatsheet_ui.h Normal file
View File

@ -0,0 +1,64 @@
/************************************************************/ /**
*
* @file: cheatsheet_ui.h
* @author: Martin Fouilleul
* @date: 05/09/2023
*
*****************************************************************/
//----------------------------------------------------------------
// Context and frame lifecycle
//----------------------------------------------------------------
void oc_ui_init(oc_ui_context* context);
oc_ui_context* oc_ui_get_context(void);
void oc_ui_set_context(oc_ui_context* context);
void oc_ui_process_event(oc_event* event);
void oc_ui_begin_frame(oc_vec2 size, oc_ui_style* defaultStyle, oc_ui_style_mask mask);
void oc_ui_end_frame(void);
void oc_ui_draw(void);
#define oc_ui_frame(size, style, mask)
//----------------------------------------------------------------
// Common widget helpers
//----------------------------------------------------------------
oc_ui_sig oc_ui_label(const char* label);
oc_ui_sig oc_ui_label_str8(oc_str8 label);
oc_ui_sig oc_ui_button(const char* label);
oc_ui_sig oc_ui_checkbox(const char* name, bool* checked);
oc_ui_box* oc_ui_slider(const char* label, f32 thumbRatio, f32* scrollValue);
oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8 text);
oc_ui_select_popup_info oc_ui_select_popup(const char* name, oc_ui_select_popup_info* info);
void oc_ui_panel_begin(const char* name, oc_ui_flags flags);
void oc_ui_panel_end(void);
#define oc_ui_panel(s, f)
void oc_ui_menu_bar_begin(const char* label);
void oc_ui_menu_bar_end(void);
#define oc_ui_menu_bar(name)
void oc_ui_menu_begin(const char* label);
void oc_ui_menu_end(void);
#define oc_ui_menu(name)
oc_ui_sig oc_ui_menu_button(const char* name);
oc_ui_sig oc_ui_tooltip_begin(const char* name);
void oc_ui_tooltip_end(void);
#define oc_ui_tooltip(name)
//-------------------------------------------------------------------------------------
// Styling
//-------------------------------------------------------------------------------------
void oc_ui_style_next(oc_ui_style* style, oc_ui_style_mask mask);
void oc_ui_pattern_push(oc_arena* arena, oc_ui_pattern* pattern, oc_ui_selector selector);
oc_ui_pattern oc_ui_pattern_all(void);
oc_ui_pattern oc_ui_pattern_owner(void);
void oc_ui_style_match_before(oc_ui_pattern pattern, oc_ui_style* style, oc_ui_style_mask mask);
void oc_ui_style_match_after(oc_ui_pattern pattern, oc_ui_style* style, oc_ui_style_mask mask);

101
doc/cheatsheet_util.h Normal file
View File

@ -0,0 +1,101 @@
/************************************************************/ /**
*
* @file: cheatsheet_util.h
* @author: Martin Fouilleul
* @date: 05/09/2023
*
*****************************************************************/
//----------------------------------------------------------------
// Arenas
//----------------------------------------------------------------
void oc_arena_init(oc_arena* arena);
void oc_arena_init_with_options(oc_arena* arena, oc_arena_options* options);
void oc_arena_cleanup(oc_arena* arena);
void* oc_arena_push(oc_arena* arena, u64 size);
#define oc_arena_push_type(arena, type)
#define oc_arena_push_array(arena, type, count)
void oc_arena_clear(oc_arena* arena);
oc_arena_scope oc_arena_scope_begin(oc_arena* arena);
void oc_arena_scope_end(oc_arena_scope scope);
oc_arena_scope oc_scratch_begin(void);
oc_arena_scope oc_scratch_begin_next(oc_arena* used);
#define oc_scratch_end(scope)
//----------------------------------------------------------------
// Lists
//----------------------------------------------------------------
void oc_list_init(oc_list* list);
bool oc_list_empty(oc_list* list);
oc_list_elt* oc_list_begin(oc_list* list);
oc_list_elt* oc_list_end(oc_list* list);
oc_list_elt* oc_list_last(oc_list* list);
#define oc_list_next(elt)
#define oc_list_prev(elt)
#define oc_list_entry(ptr, type, member)
#define oc_list_next_entry(list, elt, type, member)
#define oc_list_prev_entry(list, elt, type, member)
#define oc_list_first_entry(list, type, member)
#define oc_list_last_entry(list, type, member)
#define oc_list_pop_entry(list, type, member)
void oc_list_insert(oc_list* list, oc_list_elt* afterElt, oc_list_elt* elt);
void oc_list_insert_before(oc_list* list, oc_list_elt* beforeElt, oc_list_elt* elt);
void oc_list_remove(oc_list* list, oc_list_elt* elt);
void oc_list_push(oc_list* list, oc_list_elt* elt);
oc_list_elt* oc_list_pop(oc_list* list);
void oc_list_push_back(oc_list* list, oc_list_elt* elt);
oc_list_elt* oc_list_pop_back(oc_list* list);
#define oc_list_for(list, elt, type, member)
#define oc_list_for_reverse(list, elt, type, member)
#define oc_list_for_safe(list, elt, type, member)
//----------------------------------------------------------------
// Strings / string lists / path strings
//----------------------------------------------------------------
oc_str8 oc_str8_from_buffer(u64 len, char* buffer);
oc_str8 oc_str8_slice(oc_str8 s, u64 start, u64 end);
oc_str8 oc_str8_push_buffer(oc_arena* arena, u64 len, char* buffer);
oc_str8 oc_str8_push_cstring(oc_arena* arena, const char* str);
oc_str8 oc_str8_push_copy(oc_arena* arena, oc_str8 s);
oc_str8 oc_str8_push_slice(oc_arena* arena, oc_str8 s, u64 start, u64 end);
oc_str8 oc_str8_pushfv(oc_arena* arena, const char* format, va_list args);
oc_str8 oc_str8_pushf(oc_arena* arena, const char* format, ...);
int oc_str8_cmp(oc_str8 s1, oc_str8 s2);
char* oc_str8_to_cstring(oc_arena* arena, oc_str8 string);
void oc_str8_list_push(oc_arena* arena, oc_str8_list* list, oc_str8 str);
void oc_str8_list_pushf(oc_arena* arena, oc_str8_list* list, const char* format, ...);
oc_str8 oc_str8_list_collate(oc_arena* arena, oc_str8_list list, oc_str8 prefix, oc_str8 separator, oc_str8 postfix);
oc_str8 oc_str8_list_join(oc_arena* arena, oc_str8_list list);
oc_str8_list oc_str8_split(oc_arena* arena, oc_str8 str, oc_str8_list separators);
oc_str8 oc_path_slice_directory(oc_str8 path);
oc_str8 oc_path_slice_filename(oc_str8 path);
oc_str8_list oc_path_split(oc_arena* arena, oc_str8 path);
oc_str8 oc_path_join(oc_arena* arena, oc_str8_list elements);
oc_str8 oc_path_append(oc_arena* arena, oc_str8 parent, oc_str8 relPath);
bool oc_path_is_absolute(oc_str8 path);
//----------------------------------------------------------------
// Debugging
//----------------------------------------------------------------
#define oc_log_info(message, ...)
#define oc_log_warning(message, ...)
#define oc_log_error(message, ...)
#define OC_ASSERT(test, message, ...)
#define OC_ABORT(message, ...)

View File

@ -53,6 +53,7 @@
#include "platform/platform_io_common.c" #include "platform/platform_io_common.c"
#include "platform/orca_io_stubs.c" #include "platform/orca_io_stubs.c"
#include "platform/orca_platform.c" #include "platform/orca_platform.c"
#include "platform/platform_path.c"
#else #else
#error "Unsupported platform" #error "Unsupported platform"
#endif #endif

View File

@ -90,6 +90,8 @@ oc_str8 oc_path_append(oc_arena* arena, oc_str8 parent, oc_str8 relPath)
return (result); return (result);
} }
#if !defined(OC_PLATFORM_ORCA) || !OC_PLATFORM_ORCA
oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath) oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath)
{ {
oc_str8_list list = { 0 }; oc_str8_list list = { 0 };
@ -103,3 +105,5 @@ oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath)
oc_scratch_end(scratch); oc_scratch_end(scratch);
return (path); return (path);
} }
#endif

View File

@ -8,6 +8,7 @@
#ifndef __PLATFORM_PATH_H_ #ifndef __PLATFORM_PATH_H_
#define __PLATFORM_PATH_H_ #define __PLATFORM_PATH_H_
#include"platform.h"
#include "util/strings.h" #include "util/strings.h"
/*NOTE: /*NOTE:
@ -24,10 +25,14 @@ ORCA_API oc_str8 oc_path_join(oc_arena* arena, oc_str8_list elements);
ORCA_API oc_str8 oc_path_append(oc_arena* arena, oc_str8 parent, oc_str8 relPath); ORCA_API oc_str8 oc_path_append(oc_arena* arena, oc_str8 parent, oc_str8 relPath);
ORCA_API bool oc_path_is_absolute(oc_str8 path); ORCA_API bool oc_path_is_absolute(oc_str8 path);
#if !defined(OC_PLATFORM_ORCA) || !OC_PLATFORM_ORCA
ORCA_API oc_str8 oc_path_executable(oc_arena* arena); ORCA_API oc_str8 oc_path_executable(oc_arena* arena);
ORCA_API oc_str8 oc_path_canonical(oc_arena* arena, oc_str8 path); ORCA_API oc_str8 oc_path_canonical(oc_arena* arena, oc_str8 path);
// helper: gets the path from oc_path_executable() and appends relPath // helper: gets the path from oc_path_executable() and appends relPath
ORCA_API oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath); ORCA_API oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath);
#endif
#endif //__PLATFORM_PATH_H_ #endif //__PLATFORM_PATH_H_

View File

@ -15,8 +15,7 @@
#include "util/typedefs.h" #include "util/typedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
typedef struct oc_ui_key typedef struct oc_ui_key