From 3902b643d09ebe59330b6e2a0c56ca671ed03e92 Mon Sep 17 00:00:00 2001 From: Markolie Date: Sun, 13 Sep 2015 22:48:14 +0200 Subject: [PATCH] Add center_image proc --- code/__HELPERS/unsorted.dm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index d399cd3de67..4d733de8320 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -1,3 +1,4 @@ + //This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:31 /* @@ -1765,3 +1766,38 @@ var/mob/dview/dview_mob = new if(orbiting) loc = get_turf(orbiting) orbiting = null + +//Centers an image. +//Requires: +//The Image +//The x dimension of the icon file used in the image +//The y dimension of the icon file used in the image +// eg: center_image(I, 32,32) +// eg2: center_image(I, 96,96) +/proc/center_image(var/image/I, x_dimension = 0, y_dimension = 0) + if(!I) + return + + if(!x_dimension || !y_dimension) + return + + //Get out of here, punk ass kids calling procs needlessly + if((x_dimension == world.icon_size) && (y_dimension == world.icon_size)) + return I + + //Offset the image so that it's bottom left corner is shifted this many pixels + //This makes it infinitely easier to draw larger inhands/images larger than world.iconsize + //but still use them in game + var/x_offset = -((x_dimension/world.icon_size)-1)*(world.icon_size*0.5) + var/y_offset = -((y_dimension/world.icon_size)-1)*(world.icon_size*0.5) + + //Correct values under world.icon_size + if(x_dimension < world.icon_size) + x_offset *= -1 + if(y_dimension < world.icon_size) + y_offset *= -1 + + I.pixel_x = x_offset + I.pixel_y = y_offset + + return I