xform_from_rect
This commit is contained in:
parent
91f89ac65b
commit
1072f3225c
@ -437,8 +437,7 @@ struct rect draw_text(struct gpu_cmd_store store, struct draw_text_params params
|
|||||||
struct drawable_glyph *tg = &line->glyphs[i];
|
struct drawable_glyph *tg = &line->glyphs[i];
|
||||||
struct v2 pos = V2(draw_pos.x + tg->off_x, draw_pos.y + tg->off_y);
|
struct v2 pos = V2(draw_pos.x + tg->off_x, draw_pos.y + tg->off_y);
|
||||||
struct v2 size = V2(tg->width, tg->height);
|
struct v2 size = V2(tg->width, tg->height);
|
||||||
struct v2 pos_center = v2_add(pos, v2_mul(size, 0.5));
|
struct xform xf = xform_from_rect(RECT_FROM_V2(pos, size));
|
||||||
struct xform xf = XFORM_TRS(.t = pos_center, size);
|
|
||||||
draw_texture(store, DRAW_TEXTURE_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip));
|
draw_texture(store, DRAW_TEXTURE_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip));
|
||||||
draw_pos.x += tg->advance;
|
draw_pos.x += tg->advance;
|
||||||
|
|
||||||
|
|||||||
10
src/math.h
10
src/math.h
@ -986,6 +986,16 @@ INLINE struct xform xform_from_trs(struct trs trs)
|
|||||||
return xf;
|
return xf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INLINE struct xform xform_from_rect(struct rect rect)
|
||||||
|
{
|
||||||
|
struct v2 half_size = v2_mul(rect.size, 0.5);
|
||||||
|
struct xform xf = ZI;
|
||||||
|
xf.bx = V2(rect.size.x, 0);
|
||||||
|
xf.by = V2(0, rect.size.y);
|
||||||
|
xf.og = v2_add(rect.pos, half_size);
|
||||||
|
return xf;
|
||||||
|
}
|
||||||
|
|
||||||
INLINE struct xform xform_translated(struct xform xf, struct v2 v)
|
INLINE struct xform xform_translated(struct xform xf, struct v2 v)
|
||||||
{
|
{
|
||||||
xf.og = V2(xf.bx.x * v.x + xf.by.x * v.y + xf.og.x, xf.bx.y * v.x + xf.by.y * v.y + xf.og.y);
|
xf.og = V2(xf.bx.x * v.x + xf.by.x * v.y + xf.og.x, xf.bx.y * v.x + xf.by.y * v.y + xf.og.y);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user