Skip to content

Commit

Permalink
Fixed Wrong Rendering When Input-Sprite Is Non-Square + Added Support…
Browse files Browse the repository at this point in the history
… For Separate Border Width/Height
  • Loading branch information
WangleLine committed Jul 3, 2022
1 parent 0031566 commit 6b9866f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
6 changes: 3 additions & 3 deletions objects/o_example/Draw_0.gml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NiceSlice Examples
draw_niceslice(s_example,0,100,100,140,100,6,internal_scale);
draw_niceslice(s_example,0,260,100,300,300,6,internal_scale);
draw_niceslice(s_example,0,100,220,80,300,6,internal_scale);
draw_niceslice(s_example,0,100,100,140,100,6,6,internal_scale);
draw_niceslice(s_example,0,260,100,300,300,6,6,internal_scale);
draw_niceslice(s_example,0,100,220,80,300,6,6,internal_scale);

// Text
draw_set_halign(fa_right);
Expand Down
2 changes: 1 addition & 1 deletion options/windows/options_windows.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 26 additions & 14 deletions scripts/niceslice/niceslice.gml
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
// Draw Sprite Nine Sliced
function draw_niceslice(sprite,subimg,x,y,width,height,border,internal_scale,color=c_white,alpha=1)
/// @arg {Asset.GMSprite} sprite
/// @arg {Real} subimg
/// @arg {Real} x
/// @arg {Real} y
/// @arg {Real} width
/// @arg {Real} height
/// @arg {Real} border_width
/// @arg {Real} border_height
/// @arg {Real} internal_scale
/// @arg {Asset.GMColor} color
/// @arg {Real} alpha
/// @pure
function draw_niceslice(sprite,subimg,x,y,width,height,border_width,border_height,internal_scale,color=c_white,alpha=1)
{
var scale = internal_scale;
var sprite_w = sprite_get_width(sprite);
var sprite_h = sprite_get_height(sprite);
var side_length_raw_w = sprite_h-(border*2);
var side_length_raw_h = sprite_w-(border*2);
var side_scale_factor_w = (1/side_length_raw_w)*(width-((border*scale)*2));
var side_scale_factor_h = (1/side_length_raw_h)*(height-((border*scale)*2));
var side_length_raw_w = sprite_w-(border_width*2);
var side_length_raw_h = sprite_h-(border_height*2);
var side_scale_factor_w = (1/side_length_raw_w)*(width-((border_width*scale)*2));
var side_scale_factor_h = (1/side_length_raw_h)*(height-((border_height*scale)*2));

// Top Left
draw_sprite_part_ext(sprite,subimg,0,0,border,border,x,y,scale,scale,color,alpha);
draw_sprite_part_ext(sprite,subimg,0,0,border_width,border_height,x,y,scale,scale,color,alpha);

// Top Right
draw_sprite_part_ext(sprite,subimg,sprite_w-border,0,border,border,x+width-(border*scale),y,scale,scale,color,alpha);
draw_sprite_part_ext(sprite,subimg,sprite_w-border_width,0,border_width,border_height,x+width-(border_width*scale),y,scale,scale,color,alpha);

// Bottom Left
draw_sprite_part_ext(sprite,subimg,0,sprite_h-border,border,border,x,y+height-(border*scale),scale,scale,color,alpha);
draw_sprite_part_ext(sprite,subimg,0,sprite_h-border_height,border_width,border_height,x,y+height-(border_height*scale),scale,scale,color,alpha);

// Bottom Right
draw_sprite_part_ext(sprite,subimg,sprite_w-border,sprite_h-border,border,border,x+width-(border*scale),y+height-(border*scale),scale,scale,color,alpha);
draw_sprite_part_ext(sprite,subimg,sprite_w-border_width,sprite_h-border_height,border_width,border_height,x+width-(border_width*scale),y+height-(border_height*scale),scale,scale,color,alpha);

// Left
draw_sprite_part_ext(sprite,subimg,0,border,border,side_length_raw_h,x,y+(border*scale),scale,side_scale_factor_h,color,alpha);
draw_sprite_part_ext(sprite,subimg,0,border_height,border_width,side_length_raw_h,x,y+(border_height*scale),scale,side_scale_factor_h,color,alpha);

// Right
draw_sprite_part_ext(sprite,subimg,sprite_w-border,border,border,side_length_raw_h,x+width-(border*scale),y+(border*scale),scale,side_scale_factor_h,color,alpha);
draw_sprite_part_ext(sprite,subimg,sprite_w-border_width,border_height,border_width,side_length_raw_h,x+width-(border_width*scale),y+(border_height*scale),scale,side_scale_factor_h,color,alpha);

// Top
draw_sprite_part_ext(sprite,subimg,border,0,side_length_raw_w,border,x+(border*scale),y,side_scale_factor_w,scale,color,alpha);
draw_sprite_part_ext(sprite,subimg,border_width,0,side_length_raw_w,border_height,x+(border_width*scale),y,side_scale_factor_w,scale,color,alpha);

// Bottom
draw_sprite_part_ext(sprite,subimg,border,sprite_h-border,side_length_raw_w,border,x+(border*scale),y+height-(border*scale),side_scale_factor_w,scale,color,alpha);
draw_sprite_part_ext(sprite,subimg,border_width,sprite_h-border_height,side_length_raw_w,border_height,x+(border_width*scale),y+height-(border_height*scale),side_scale_factor_w,scale,color,alpha);

// Inside
draw_sprite_part_ext(sprite,subimg,border,border,side_length_raw_w,side_length_raw_h,x+(border*scale),y+(border*scale),side_scale_factor_w,side_scale_factor_h,color,alpha);
draw_sprite_part_ext(sprite,subimg,border_width,border_height,side_length_raw_w,side_length_raw_h,x+(border_width*scale),y+(border_height*scale),side_scale_factor_w,side_scale_factor_h,color,alpha);
}
Binary file modified sprites/s_example/0a1cd7ff-d8e6-4fbb-adaf-2f23a9d93b8c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions sprites/s_example/s_example.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b9866f

Please sign in to comment.