fix draw.image
Some checks failed
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled

This commit is contained in:
2025-04-26 08:08:15 -05:00
parent b93a5a3ac0
commit ee4ec2fc39
3 changed files with 33 additions and 14 deletions

View File

@@ -58,7 +58,7 @@ render.image = function(image, rect, rotation, anchor, shear, info)
{ {
rect.width = image.rect_px.width; rect.width = image.rect_px.width;
rect.height = image.rect_px.height; rect.height = image.rect_px.height;
context.texture(image.texture, image.rect_px, rect, rotation * 360, anchor); context.texture(image.texture, image.rect_px, rect, rotation, anchor);
} }
render.clip = function(rect) render.clip = function(rect)

View File

@@ -1674,9 +1674,6 @@ shader_globals camera_globals(JSContext *js, JSValue camera)
bottom, top, bottom, top,
-1.0f, 1.0f -1.0f, 1.0f
); );
proj.Columns[3].x += size.x * anchor.x;
proj.Columns[3].y += size.y * anchor.y;
} }
else { else {
proj = HMM_Perspective_RH_NO(fov, size.x/size.y,near_z,far_z); proj = HMM_Perspective_RH_NO(fov, size.x/size.y,near_z,far_z);
@@ -2725,18 +2722,28 @@ static inline SDL_FPoint renderer_world_to_screen(renderer_ctx *ctx, HMM_Vec2 p)
return (SDL_FPoint){ scr_x, scr_y }; return (SDL_FPoint){ scr_x, scr_y };
} }
static inline rect renderer_worldrect_to_screen(renderer_ctx *ctx, rect r) static inline rect renderer_worldrect_to_screen(renderer_ctx *ctx, rect r_world)
{ {
SDL_FPoint tl = renderer_world_to_screen(ctx, (HMM_Vec2){r.x, r.y}); SDL_FPoint bl = renderer_world_to_screen(
SDL_FPoint br = renderer_world_to_screen(ctx, (HMM_Vec2){r.x+r.w, r.y+r.h}); ctx, (HMM_Vec2){ r_world.x,
r_world.y });
r.x = tl.x; SDL_FPoint tr = renderer_world_to_screen(
r.y = tl.y; ctx, (HMM_Vec2){ r_world.x + r_world.w,
r.w = br.x-tl.x; r_world.y + r_world.h });
r.h = br.y-tl.y;
return r; /* SDL wants the *top-left* corner, and y grows down. */
rect out;
out.x = SDL_min(bl.x, tr.x); /* left edge */
out.y = SDL_min(bl.y, tr.y); /* top edge */
/* always positive width / height */
out.w = fabsf(tr.x - bl.x);
out.h = fabsf(tr.y - bl.y);
return out;
} }
JSC_CCALL(SDL_Renderer_clear, JSC_CCALL(SDL_Renderer_clear,
SDL_Renderer *renderer = js2renderer_ctx(js,self)->sdl; SDL_Renderer *renderer = js2renderer_ctx(js,self)->sdl;
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
@@ -3059,9 +3066,17 @@ JSC_CCALL(renderer_texture,
SDL_Texture *tex = js2SDL_Texture(js,argv[0]); SDL_Texture *tex = js2SDL_Texture(js,argv[0]);
rect src = js2rect(js,argv[1]); rect src = js2rect(js,argv[1]);
rect dst = js2rect(js,argv[2]); rect dst = js2rect(js,argv[2]);
dst = renderer_worldrect_to_screen(ctx, dst);
double angle; double angle;
JS_ToFloat64(js, &angle, argv[3]); JS_ToFloat64(js, &angle, argv[3]);
angle *= -360;
HMM_Vec2 anchor = js2vec2(js, argv[4]); HMM_Vec2 anchor = js2vec2(js, argv[4]);
anchor.y = dst.h - anchor.y*dst.h;
anchor.x *= dst.w;
// anchor.x *= dst.w;
// anchor.y *= dst.h;
// anchor.x += dst.x;
// anchor.y += dst.y;
SDL_RenderTextureRotated(ctx->sdl, tex, &src, &dst, angle, &anchor, SDL_FLIP_NONE); SDL_RenderTextureRotated(ctx->sdl, tex, &src, &dst, angle, &anchor, SDL_FLIP_NONE);
) )

View File

@@ -35,8 +35,10 @@ var hudcam = {
anchor:[0,0], anchor:[0,0],
} }
var angle = 0
function loop() function loop()
{ {
angle += 1/240
render.clear(Color.red) render.clear(Color.red)
render.camera(hudcam) render.camera(hudcam)
/* draw.line([[0,0],[100,50]]) /* draw.line([[0,0],[100,50]])
@@ -48,8 +50,10 @@ function loop()
draw.ellipse([100,80], [40,25], {thickness:1,color:Color.blue}) draw.ellipse([100,80], [40,25], {thickness:1,color:Color.blue})
draw.rectangle({x:150,y:150,width:50,height:50}) draw.rectangle({x:150,y:150,width:50,height:50})
draw.rectangle({x:100, y:60, width:200, height:60}, {radius: 20, thickness:-3}) draw.rectangle({x:100, y:60, width:200, height:60}, {radius: 20, thickness:-3})
draw.rectangle({x:350, y:60, width:200, height:120}, {radius:10,thickness:3})*/ draw.rectangle({x:350, y:60, width:200, height:120}, {radius:10,thickness:3})
draw.image("button_grey", [100,100],0.25) */
draw.image("diddy", [0,0], angle, [0,0])
draw.image("panel_beige", [300,300])
render.present() render.present()
$_.delay(loop, 1/60) $_.delay(loop, 1/60)
} }