oc_matrix_push() -> oc_matrix_multiply_push(), and add oc_matrix_push() to push a matrix on the stack as is
This commit is contained in:
parent
313f2e0ad4
commit
ce752713f6
|
@ -91,9 +91,9 @@ For a list of canvas drawing functions, see the [graphics API cheatsheet](../doc
|
||||||
|
|
||||||
#### Transforms
|
#### 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.
|
- `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.
|
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
|
// 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_set_color_rgba(.2, 0.2, 0.2, 1);
|
||||||
oc_rounded_rectangle_fill(0, -7.5 * uiScale, clockRadius * 0.5f, 15 * uiScale, 5 * uiScale);
|
oc_rounded_rectangle_fill(0, -7.5 * uiScale, clockRadius * 0.5f, 15 * uiScale, 5 * uiScale);
|
||||||
|
|
|
@ -39,6 +39,7 @@ void oc_render(oc_canvas canvas);
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void oc_matrix_push(oc_mat2x3 matrix);
|
void oc_matrix_push(oc_mat2x3 matrix);
|
||||||
|
void oc_matrix_multiply_push(oc_mat2x3 matrix);
|
||||||
void oc_matrix_pop(void);
|
void oc_matrix_pop(void);
|
||||||
oc_mat2x3 oc_matrix_top();
|
oc_mat2x3 oc_matrix_top();
|
||||||
|
|
||||||
|
|
|
@ -401,7 +401,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
|
||||||
0, -1, frameSize.y
|
0, -1, frameSize.y
|
||||||
};
|
};
|
||||||
|
|
||||||
oc_matrix_push(yUp);
|
oc_matrix_multiply_push(yUp);
|
||||||
{
|
{
|
||||||
for(int i = 0; i < NUM_BLOCKS; i++)
|
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(font);
|
||||||
oc_set_font_size(18);
|
oc_set_font_size(18);
|
||||||
oc_move_to(textPos.x, textPos.y);
|
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_text_outlines(text);
|
||||||
oc_fill();
|
oc_fill();
|
||||||
|
@ -448,7 +448,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
|
||||||
oc_set_color(paddleColor);
|
oc_set_color(paddleColor);
|
||||||
oc_rounded_rectangle_fill(paddle.x, paddle.y, paddle.w, paddle.h, 4);
|
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);
|
oc_image_draw(ballImage, ball);
|
||||||
}
|
}
|
||||||
|
@ -459,7 +459,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
|
||||||
oc_move_to(20, 20);
|
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_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_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_set_color_rgba(0.9, 0.9, 0.9, 1);
|
||||||
oc_text_outlines(text);
|
oc_text_outlines(text);
|
||||||
|
|
|
@ -115,7 +115,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// hours 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_set_color_rgba(.2, 0.2, 0.2, 1);
|
||||||
oc_rounded_rectangle_fill(0, -7.5 * uiScale, clockRadius * 0.5f, 15 * uiScale, 5 * uiScale);
|
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();
|
oc_matrix_pop();
|
||||||
|
|
||||||
// minutes hand
|
// 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_set_color_rgba(.2, 0.2, 0.2, 1);
|
||||||
oc_rounded_rectangle_fill(0, -5 * uiScale, clockRadius * 0.7f, 10 * uiScale, 5 * uiScale);
|
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();
|
oc_matrix_pop();
|
||||||
|
|
||||||
// seconds hand
|
// 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_set_color_rgba(1, 0.2, 0.2, 1);
|
||||||
oc_rounded_rectangle_fill(0, -2.5 * uiScale, clockRadius * 0.8f, 5 * uiScale, 5 * uiScale);
|
oc_rounded_rectangle_fill(0, -2.5 * uiScale, clockRadius * 0.8f, 5 * uiScale, 5 * uiScale);
|
||||||
|
|
|
@ -80,7 +80,7 @@ int main()
|
||||||
|
|
||||||
oc_set_color_rgba(1, 1, 1, 1);
|
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});
|
0.707, 0.707, 100});
|
||||||
oc_set_image(image);
|
oc_set_image(image);
|
||||||
oc_set_image_source_region((oc_rect){500, 500, 2000, 1400});
|
oc_set_image_source_region((oc_rect){500, 500, 2000, 1400});
|
||||||
|
|
|
@ -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 });
|
0, zoom, 0 });
|
||||||
|
|
||||||
oc_set_color_rgba(1, 1, 1, 1);
|
oc_set_color_rgba(1, 1, 1, 1);
|
||||||
|
|
|
@ -202,7 +202,7 @@ int main()
|
||||||
oc_set_color_rgba(1, 0, 1, 1);
|
oc_set_color_rgba(1, 0, 1, 1);
|
||||||
oc_clear();
|
oc_clear();
|
||||||
|
|
||||||
oc_matrix_push((oc_mat2x3){ zoom, 0, startX,
|
oc_matrix_multiply_push((oc_mat2x3){ zoom, 0, startX,
|
||||||
0, zoom, startY });
|
0, zoom, startY });
|
||||||
|
|
||||||
draw_tiger(singlePath, singlePathIndex);
|
draw_tiger(singlePath, singlePathIndex);
|
||||||
|
|
|
@ -288,6 +288,7 @@ ORCA_API void oc_image_atlas_recycle(oc_rect_atlas* atlas, oc_image_region image
|
||||||
//SECTION: transform, viewport and clipping
|
//SECTION: transform, viewport and clipping
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
ORCA_API void oc_matrix_push(oc_mat2x3 matrix);
|
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 void oc_matrix_pop(void);
|
||||||
ORCA_API oc_mat2x3 oc_matrix_top();
|
ORCA_API oc_mat2x3 oc_matrix_top();
|
||||||
|
|
||||||
|
|
|
@ -629,7 +629,7 @@ oc_str32 oc_font_get_glyph_indices_from_font_data(oc_font_data* fontData, oc_str
|
||||||
}
|
}
|
||||||
backing.ptr[i] = glyphIndex;
|
backing.ptr[i] = glyphIndex;
|
||||||
}
|
}
|
||||||
oc_str32 res = {.ptr = backing.ptr , .len = count};
|
oc_str32 res = { .ptr = backing.ptr, .len = count };
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1002,6 +1002,15 @@ void oc_render(oc_canvas canvas)
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void oc_matrix_push(oc_mat2x3 matrix)
|
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;
|
oc_canvas_data* canvas = __mgCurrentCanvas;
|
||||||
if(canvas)
|
if(canvas)
|
||||||
|
@ -1428,7 +1437,7 @@ oc_rect oc_glyph_outlines_from_font_data(oc_font_data* fontData, oc_str32 glyphI
|
||||||
|
|
||||||
if(missingGlyphIndex)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1656,7 +1656,7 @@ void oc_ui_checkbox_draw(oc_ui_box* box, void* data)
|
||||||
box->rect.w, 0, box->rect.x,
|
box->rect.w, 0, box->rect.x,
|
||||||
0, box->rect.h, box->rect.y
|
0, box->rect.h, box->rect.y
|
||||||
};
|
};
|
||||||
oc_matrix_push(matrix);
|
oc_matrix_multiply_push(matrix);
|
||||||
|
|
||||||
oc_move_to(0.7255, 0.3045);
|
oc_move_to(0.7255, 0.3045);
|
||||||
oc_cubic_to(0.7529, 0.3255, 0.7581, 0.3647, 0.7371, 0.3921);
|
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,
|
-box->rect.w, 0, box->rect.x + box->rect.w + 1,
|
||||||
0, box->rect.h, box->rect.y
|
0, box->rect.h, box->rect.y
|
||||||
};
|
};
|
||||||
oc_matrix_push(matrix);
|
oc_matrix_multiply_push(matrix);
|
||||||
|
|
||||||
oc_move_to(0, 0);
|
oc_move_to(0, 0);
|
||||||
oc_line_to(0.0417, 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,
|
box->rect.w / 2, 0, box->rect.x + box->rect.w / 4,
|
||||||
0, box->rect.h / 2, box->rect.y + box->rect.h / 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_move_to(0.17, 0.3166);
|
||||||
oc_cubic_to(0.1944, 0.2922, 0.234, 0.2922, 0.2584, 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,
|
box->rect.w, 0, box->rect.x,
|
||||||
0, box->rect.h, box->rect.y
|
0, box->rect.h, box->rect.y
|
||||||
};
|
};
|
||||||
oc_matrix_push(matrix);
|
oc_matrix_multiply_push(matrix);
|
||||||
|
|
||||||
oc_move_to(0.8897, 0.1777);
|
oc_move_to(0.8897, 0.1777);
|
||||||
oc_cubic_to(0.9181, 0.1973, 0.9252, 0.2362, 0.9056, 0.2647);
|
oc_cubic_to(0.9181, 0.1973, 0.9252, 0.2362, 0.9056, 0.2647);
|
||||||
|
|
Loading…
Reference in New Issue