Allow setting texture on arbitrary path fills

This commit is contained in:
Martin Fouilleul 2023-02-24 23:06:39 +01:00
parent 4333ed02b0
commit 50569a1427
3 changed files with 38 additions and 31 deletions

View File

@ -79,7 +79,15 @@ int main()
mg_matrix_push((mg_mat2x3){0.707, -0.707, 200, mg_matrix_push((mg_mat2x3){0.707, -0.707, 200,
0.707, 0.707, 100}); 0.707, 0.707, 100});
mg_image_draw_rounded(image, (mp_rect){0, 0, imageSize.x/8, imageSize.y/8}, 40.); mg_set_image(image);
mg_move_to(0, 0);
mg_line_to(100, 0);
mg_line_to(150, 50);
mg_line_to(100, 100);
mg_line_to(0, 100);
mg_line_to(50, 50);
mg_fill();
//mg_image_draw_rounded(image, (mp_rect){0, 0, imageSize.x/8, imageSize.y/8}, 40.);
mg_matrix_pop(); mg_matrix_pop();

View File

@ -3078,11 +3078,10 @@ void mg_clip_pop()
void mg_set_color(mg_color color) void mg_set_color(mg_color color)
{ {
mg_canvas_data* canvas = __mgCurrentCanvas; mg_canvas_data* canvas = __mgCurrentCanvas;
if(!canvas) if(canvas)
{ {
return;
}
canvas->attributes.color = color; canvas->attributes.color = color;
}
} }
void mg_set_color_rgba(f32 r, f32 g, f32 b, f32 a) void mg_set_color_rgba(f32 r, f32 g, f32 b, f32 a)
@ -3093,81 +3092,82 @@ void mg_set_color_rgba(f32 r, f32 g, f32 b, f32 a)
void mg_set_width(f32 width) void mg_set_width(f32 width)
{ {
mg_canvas_data* canvas = __mgCurrentCanvas; mg_canvas_data* canvas = __mgCurrentCanvas;
if(!canvas) if(canvas)
{ {
return;
}
canvas->attributes.width = width; canvas->attributes.width = width;
}
} }
void mg_set_tolerance(f32 tolerance) void mg_set_tolerance(f32 tolerance)
{ {
mg_canvas_data* canvas = __mgCurrentCanvas; mg_canvas_data* canvas = __mgCurrentCanvas;
if(!canvas) if(canvas)
{ {
return;
}
canvas->attributes.tolerance = tolerance; canvas->attributes.tolerance = tolerance;
}
} }
void mg_set_joint(mg_joint_type joint) void mg_set_joint(mg_joint_type joint)
{ {
mg_canvas_data* canvas = __mgCurrentCanvas; mg_canvas_data* canvas = __mgCurrentCanvas;
if(!canvas) if(canvas)
{ {
return;
}
canvas->attributes.joint = joint; canvas->attributes.joint = joint;
}
} }
void mg_set_max_joint_excursion(f32 maxJointExcursion) void mg_set_max_joint_excursion(f32 maxJointExcursion)
{ {
mg_canvas_data* canvas = __mgCurrentCanvas; mg_canvas_data* canvas = __mgCurrentCanvas;
if(!canvas) if(canvas)
{ {
return;
}
canvas->attributes.maxJointExcursion = maxJointExcursion; canvas->attributes.maxJointExcursion = maxJointExcursion;
}
} }
void mg_set_cap(mg_cap_type cap) void mg_set_cap(mg_cap_type cap)
{ {
mg_canvas_data* canvas = __mgCurrentCanvas; mg_canvas_data* canvas = __mgCurrentCanvas;
if(!canvas) if(canvas)
{ {
return;
}
canvas->attributes.cap = cap; canvas->attributes.cap = cap;
}
} }
void mg_set_font(mg_font font) void mg_set_font(mg_font font)
{ {
mg_canvas_data* canvas = __mgCurrentCanvas; mg_canvas_data* canvas = __mgCurrentCanvas;
if(!canvas) if(canvas)
{ {
return;
}
canvas->attributes.font = font; canvas->attributes.font = font;
}
} }
void mg_set_font_size(f32 fontSize) void mg_set_font_size(f32 fontSize)
{ {
mg_canvas_data* canvas = __mgCurrentCanvas; mg_canvas_data* canvas = __mgCurrentCanvas;
if(!canvas) if(canvas)
{ {
return;
}
canvas->attributes.fontSize = fontSize; canvas->attributes.fontSize = fontSize;
}
} }
void mg_set_text_flip(bool flip) void mg_set_text_flip(bool flip)
{ {
mg_canvas_data* canvas = __mgCurrentCanvas; mg_canvas_data* canvas = __mgCurrentCanvas;
if(!canvas) if(canvas)
{ {
return;
}
canvas->textFlip = flip; canvas->textFlip = flip;
}
}
void mg_set_image(mg_image image)
{
mg_canvas_data* canvas = __mgCurrentCanvas;
if(canvas)
{
canvas->attributes.image = image;
}
} }
mg_color mg_get_color() mg_color mg_get_color()

View File

@ -105,8 +105,8 @@ MP_API void mg_surface_set_hidden(mg_surface surface, bool hidden);
//NOTE(martin): graphics canvas structs //NOTE(martin): graphics canvas structs
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
typedef struct mg_canvas { u64 h; } mg_canvas; typedef struct mg_canvas { u64 h; } mg_canvas;
typedef struct mg_stream { u64 h; } mg_stream;
typedef struct mg_font { u64 h; } mg_font; typedef struct mg_font { u64 h; } mg_font;
typedef struct mg_image { u64 h; } mg_image;
typedef struct mg_mat2x3 typedef struct mg_mat2x3
{ {
@ -193,6 +193,7 @@ MP_API void mg_set_cap(mg_cap_type cap);
MP_API void mg_set_font(mg_font font); MP_API void mg_set_font(mg_font font);
MP_API void mg_set_font_size(f32 size); MP_API void mg_set_font_size(f32 size);
MP_API void mg_set_text_flip(bool flip); MP_API void mg_set_text_flip(bool flip);
MP_API void mg_set_image(mg_image image);
MP_API mg_color mg_get_color(); MP_API mg_color mg_get_color();
MP_API f32 mg_get_width(); MP_API f32 mg_get_width();
@ -269,8 +270,6 @@ MP_API mp_rect mg_text_bounding_box(mg_font font, f32 fontSize, str8 text);
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
//NOTE(martin): images //NOTE(martin): images
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
typedef struct mg_image { u64 h; } mg_image;
MP_API mg_image mg_image_nil(); MP_API mg_image mg_image_nil();
MP_API bool mg_image_is_nil(mg_image a); MP_API bool mg_image_is_nil(mg_image a);