From ce752713f673c0f18de825ea5bcfab0142bd8838 Mon Sep 17 00:00:00 2001 From: Martin Fouilleul Date: Mon, 11 Sep 2023 20:02:46 +0200 Subject: [PATCH] oc_matrix_push() -> oc_matrix_multiply_push(), and add oc_matrix_push() to push a matrix on the stack as is --- doc/QuickStart.md | 6 +++--- doc/cheatsheets/cheatsheet_graphics.h | 1 + samples/breakout/src/main.c | 8 ++++---- samples/clock/src/main.c | 6 +++--- sketches/image/main.c | 2 +- sketches/perf_text/main.c | 2 +- sketches/tiger/main.c | 2 +- src/graphics/graphics.h | 1 + src/graphics/graphics_common.c | 13 +++++++++++-- src/ui/ui.c | 8 ++++---- 10 files changed, 30 insertions(+), 19 deletions(-) diff --git a/doc/QuickStart.md b/doc/QuickStart.md index c7e0657..6ac8e10 100644 --- a/doc/QuickStart.md +++ b/doc/QuickStart.md @@ -91,9 +91,9 @@ For a list of canvas drawing functions, see the [graphics API cheatsheet](../doc #### Transforms -A special case of attribute setting function is the pair `oc_matrix_push()` and `oc_matrix_pop()`, which are used to manipulate a stack of transform matrices: +A special case of attribute setting function is the pair `oc_matrix_multiply_push()` and `oc_matrix_pop()`, which are used to manipulate a stack of transform matrices: -- `oc_matrix_push()` multiplies the matrix currently on top of the stack with its argument, and pushes the result on the stack. +- `oc_matrix_multiply_push()` multiplies the matrix currently on top of the stack with its argument, and pushes the result on the stack. - `oc_matrix_pop()` pops a matrix from the stack. The matrix on the top of the stack at the time a command is encoded is used to transform the path of that command. @@ -102,7 +102,7 @@ You can see an example of using transform matrices when drawing the clock's hand ``` // hours hand - oc_matrix_push(mat_transform(centerX, centerY, hoursRotation)); + oc_matrix_multiply_push(mat_transform(centerX, centerY, hoursRotation)); { oc_set_color_rgba(.2, 0.2, 0.2, 1); oc_rounded_rectangle_fill(0, -7.5 * uiScale, clockRadius * 0.5f, 15 * uiScale, 5 * uiScale); diff --git a/doc/cheatsheets/cheatsheet_graphics.h b/doc/cheatsheets/cheatsheet_graphics.h index 08eae0e..8a788c2 100644 --- a/doc/cheatsheets/cheatsheet_graphics.h +++ b/doc/cheatsheets/cheatsheet_graphics.h @@ -39,6 +39,7 @@ void oc_render(oc_canvas canvas); //------------------------------------------------------------------------------------------ void oc_matrix_push(oc_mat2x3 matrix); +void oc_matrix_multiply_push(oc_mat2x3 matrix); void oc_matrix_pop(void); oc_mat2x3 oc_matrix_top(); diff --git a/samples/breakout/src/main.c b/samples/breakout/src/main.c index 8a24a15..4c31de3 100644 --- a/samples/breakout/src/main.c +++ b/samples/breakout/src/main.c @@ -401,7 +401,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void) 0, -1, frameSize.y }; - oc_matrix_push(yUp); + oc_matrix_multiply_push(yUp); { for(int i = 0; i < NUM_BLOCKS; i++) { @@ -437,7 +437,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void) oc_set_font(font); oc_set_font_size(18); oc_move_to(textPos.x, textPos.y); - oc_matrix_push(flip_y_at(textPos)); + oc_matrix_multiply_push(flip_y_at(textPos)); { oc_text_outlines(text); oc_fill(); @@ -448,7 +448,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void) oc_set_color(paddleColor); oc_rounded_rectangle_fill(paddle.x, paddle.y, paddle.w, paddle.h, 4); - oc_matrix_push(flip_y(ball)); + oc_matrix_multiply_push(flip_y(ball)); { oc_image_draw(ballImage, ball); } @@ -459,7 +459,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void) oc_move_to(20, 20); oc_str8 text = oc_str8_pushf(oc_scratch(), "Destroy all %d blocks to win! Current score: %d", NUM_BLOCKS_TO_WIN, score); oc_vec2 textPos = { 20, 20 }; - oc_matrix_push(flip_y_at(textPos)); + oc_matrix_multiply_push(flip_y_at(textPos)); { oc_set_color_rgba(0.9, 0.9, 0.9, 1); oc_text_outlines(text); diff --git a/samples/clock/src/main.c b/samples/clock/src/main.c index 752463e..5783cbe 100644 --- a/samples/clock/src/main.c +++ b/samples/clock/src/main.c @@ -115,7 +115,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void) } // hours hand - oc_matrix_push(mat_transform(centerX, centerY, hoursRotation)); + oc_matrix_multiply_push(mat_transform(centerX, centerY, hoursRotation)); { oc_set_color_rgba(.2, 0.2, 0.2, 1); oc_rounded_rectangle_fill(0, -7.5 * uiScale, clockRadius * 0.5f, 15 * uiScale, 5 * uiScale); @@ -123,7 +123,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void) oc_matrix_pop(); // minutes hand - oc_matrix_push(mat_transform(centerX, centerY, minutesRotation)); + oc_matrix_multiply_push(mat_transform(centerX, centerY, minutesRotation)); { oc_set_color_rgba(.2, 0.2, 0.2, 1); oc_rounded_rectangle_fill(0, -5 * uiScale, clockRadius * 0.7f, 10 * uiScale, 5 * uiScale); @@ -131,7 +131,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void) oc_matrix_pop(); // seconds hand - oc_matrix_push(mat_transform(centerX, centerY, secondsRotation)); + oc_matrix_multiply_push(mat_transform(centerX, centerY, secondsRotation)); { oc_set_color_rgba(1, 0.2, 0.2, 1); oc_rounded_rectangle_fill(0, -2.5 * uiScale, clockRadius * 0.8f, 5 * uiScale, 5 * uiScale); diff --git a/sketches/image/main.c b/sketches/image/main.c index d5d896f..3b07f67 100644 --- a/sketches/image/main.c +++ b/sketches/image/main.c @@ -80,7 +80,7 @@ int main() oc_set_color_rgba(1, 1, 1, 1); /* - oc_matrix_push((oc_mat2x3){0.707, -0.707, 200, + oc_matrix_multiply_push((oc_mat2x3){0.707, -0.707, 200, 0.707, 0.707, 100}); oc_set_image(image); oc_set_image_source_region((oc_rect){500, 500, 2000, 1400}); diff --git a/sketches/perf_text/main.c b/sketches/perf_text/main.c index 1d1a345..251302a 100644 --- a/sketches/perf_text/main.c +++ b/sketches/perf_text/main.c @@ -249,7 +249,7 @@ int main() } */ - oc_matrix_push((oc_mat2x3){ zoom, 0, 0, + oc_matrix_multiply_push((oc_mat2x3){ zoom, 0, 0, 0, zoom, 0 }); oc_set_color_rgba(1, 1, 1, 1); diff --git a/sketches/tiger/main.c b/sketches/tiger/main.c index 3149529..a13d643 100644 --- a/sketches/tiger/main.c +++ b/sketches/tiger/main.c @@ -202,7 +202,7 @@ int main() oc_set_color_rgba(1, 0, 1, 1); oc_clear(); - oc_matrix_push((oc_mat2x3){ zoom, 0, startX, + oc_matrix_multiply_push((oc_mat2x3){ zoom, 0, startX, 0, zoom, startY }); draw_tiger(singlePath, singlePathIndex); diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index 264dc3c..7d6f797 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -288,6 +288,7 @@ ORCA_API void oc_image_atlas_recycle(oc_rect_atlas* atlas, oc_image_region image //SECTION: transform, viewport and clipping //------------------------------------------------------------------------------------------ ORCA_API void oc_matrix_push(oc_mat2x3 matrix); +ORCA_API void oc_matrix_multiply_push(oc_mat2x3 matrix); ORCA_API void oc_matrix_pop(void); ORCA_API oc_mat2x3 oc_matrix_top(); diff --git a/src/graphics/graphics_common.c b/src/graphics/graphics_common.c index 27cd6f7..7d29670 100644 --- a/src/graphics/graphics_common.c +++ b/src/graphics/graphics_common.c @@ -629,7 +629,7 @@ oc_str32 oc_font_get_glyph_indices_from_font_data(oc_font_data* fontData, oc_str } backing.ptr[i] = glyphIndex; } - oc_str32 res = {.ptr = backing.ptr , .len = count}; + oc_str32 res = { .ptr = backing.ptr, .len = count }; return (res); } @@ -1002,6 +1002,15 @@ void oc_render(oc_canvas canvas) //------------------------------------------------------------------------------------------ void oc_matrix_push(oc_mat2x3 matrix) +{ + oc_canvas_data* canvas = __mgCurrentCanvas; + if(canvas) + { + oc_matrix_stack_push(canvas, matrix); + } +} + +void oc_matrix_multiply_push(oc_mat2x3 matrix) { oc_canvas_data* canvas = __mgCurrentCanvas; if(canvas) @@ -1428,7 +1437,7 @@ oc_rect oc_glyph_outlines_from_font_data(oc_font_data* fontData, oc_str32 glyphI if(missingGlyphIndex) { - oc_font_get_glyph_metrics_from_font_data(fontData, (oc_str32){.ptr = &missingGlyphIndex , .len = 1}, &missingGlyphMetrics); + oc_font_get_glyph_metrics_from_font_data(fontData, (oc_str32){ .ptr = &missingGlyphIndex, .len = 1 }, &missingGlyphMetrics); } else { diff --git a/src/ui/ui.c b/src/ui/ui.c index 7249019..6f68fe3 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -1656,7 +1656,7 @@ void oc_ui_checkbox_draw(oc_ui_box* box, void* data) box->rect.w, 0, box->rect.x, 0, box->rect.h, box->rect.y }; - oc_matrix_push(matrix); + oc_matrix_multiply_push(matrix); oc_move_to(0.7255, 0.3045); oc_cubic_to(0.7529, 0.3255, 0.7581, 0.3647, 0.7371, 0.3921); @@ -2175,7 +2175,7 @@ void oc_ui_tooltip_arrow_draw(oc_ui_box* box, void* data) -box->rect.w, 0, box->rect.x + box->rect.w + 1, 0, box->rect.h, box->rect.y }; - oc_matrix_push(matrix); + oc_matrix_multiply_push(matrix); oc_move_to(0, 0); oc_line_to(0.0417, 0); @@ -2421,7 +2421,7 @@ void oc_ui_select_popup_draw_arrow(oc_ui_box* box, void* data) box->rect.w / 2, 0, box->rect.x + box->rect.w / 4, 0, box->rect.h / 2, box->rect.y + box->rect.h / 4 }; - oc_matrix_push(matrix); + oc_matrix_multiply_push(matrix); oc_move_to(0.17, 0.3166); oc_cubic_to(0.1944, 0.2922, 0.234, 0.2922, 0.2584, 0.3166); @@ -2447,7 +2447,7 @@ void oc_ui_select_popup_draw_checkmark(oc_ui_box* box, void* data) box->rect.w, 0, box->rect.x, 0, box->rect.h, box->rect.y }; - oc_matrix_push(matrix); + oc_matrix_multiply_push(matrix); oc_move_to(0.8897, 0.1777); oc_cubic_to(0.9181, 0.1973, 0.9252, 0.2362, 0.9056, 0.2647);