Skip to content

Commit

Permalink
Fix #121
Browse files Browse the repository at this point in the history
  • Loading branch information
skejeton committed Jul 11, 2024
1 parent 0a271b5 commit 1f65b70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,26 +504,45 @@ umth_image_draw_nine_patch(UmkaStackSlot *p, UmkaStackSlot *r)
return;
}

float mx = 1;
float my = 1;

if (img->flipv) {
mx = -1;
src.x += outer.w - stepSrc[2].x;
float temp = stepDst[0].x;
stepDst[0].x = stepDst[2].x;
stepDst[2].x = temp;
}

if (img->fliph) {
my = -1;
src.y += outer.h - stepSrc[2].y;
float temp = stepDst[0].y;
stepDst[0].y = stepDst[2].y;
stepDst[2].y = temp;
}

float startY = src.y;

for (int x = 0; x < 3; x++) {
float ssX = stepSrc[x].x;
float sdX = stepDst[x].x;
for (int y = 0; y < 3; y++) {
float ssY = stepSrc[y].y;
float sdY = stepDst[y].y;

th_image_crop(img, (th_vf2){{src.x / imgDims.x, src.y / imgDims.y}},
(th_vf2){{(src.x + ssX) / imgDims.x, (src.y + ssY) / imgDims.y}});
th_image_render_transformed(img,
(th_transform){
.scale = {{sdX / ssX, sdY / ssY}}, .pos = {{dst.x, dst.y}}},
tint);
th_rect srcr = {src.x, src.y, ssX, ssY};
th_rect dstr = {dst.x, dst.y, sdX, sdY};

th_image_blit(img, srcr, dstr, tint, 0, (th_vf2){0});

src.y += ssY;
src.y += ssY * my;
dst.y += sdY;
}
src.x += ssX;
src.x += ssX * mx;
dst.x += sdX;
src.y = outer.y;
src.y = startY;
dst.y = dest.y;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/staembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -4438,6 +4438,7 @@ const char *th_em_moduledocs[] = {
"\n"
"\tumth_image_crop(i^, tl, br)\n"
"}\n"
"\n"
"\n"
"\n"
"---------\n"
Expand All @@ -4451,6 +4452,7 @@ const char *th_em_moduledocs[] = {
"\tdm := i.getDims()\n"
"\tumth_image_crop(i^, tr.div(dm), br.div(dm))\n"
"}\n"
"\n"
"\n"
"\n"
"---------\n"
Expand Down

0 comments on commit 1f65b70

Please sign in to comment.