ID:1319737
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Currently, the only way to remove an icon state is to create a New() icon and then Insert() all but the state(s) that you don't want. This doesn't seem very intuitive.

icon.AddBlank(icon_state="") - for lack of a better name - would add a masked/empty icon state to an icon as the icon_state specified. Currently the only way to do this is to either import an existing icon from the rsc (one that already has just single blank state - problematic for dmb-only projects) or to import any icon state and then mask it out using DrawBox() - not a very efficient solution.

As an alternative, icon.Insert() could take null as an argument. e.g. icon.Insert(null,"")
Icon's definitely need more functions and features

In the meantime, here's some stuff I've put together with help of some others as well:

/*
Written by: FIREking
*/


#define TRANSPARENT_PIXEL "#ff00cc"

icon
proc/xGetPixel(x, y)
//uses standard coordinate system instead of BYOND's coordinate system
return src.GetPixel(x, src.Height() + 1 - y)

proc/SetPixel(pixel, x, y)
//wrapper function
src.DrawBox(pixel, x, y)

proc/xSetPixel(pixel, x, y)
//uses standard coordinate system instead of BYOND's coordinate system
src.DrawBox(pixel, x, src.Height() + 1 - y)

proc/tileCrop(x, y, w, h, unit = 32)
//allows you to crop the icon using tile units instead of pixel units
Crop(((x - 1) * unit) + 1, ((y - 1) * unit) + 1, (((x - 1) * unit) + (w * unit)) + 1, (((y - 1) * unit) + (h * unit)) + 1)

proc/DrawTo(icon/i, sx, sy, dx, dy, w, h)
for(var/ix = sx to sx + w step 1)
for(var/iy = sy to sy + h step 1)
var/pixel = src.GetPixel(ix, iy)
if(pixel != TRANSPARENT_PIXEL)
i.SetPixel(pixel, ix - sx + dx, iy - sy + dy)

proc/Save(path)
//save the icon to disk
//if no path is supplied, a dialog will ask for filename and where to save
//otherwise, save to path
if(usr)
usr.icon = src
else
CRASH("Invalid usr in icon.Save()")

ASSERT(usr.icon)

if(path)
fcopy(file(usr.icon), path)
else
usr << ftp(file(usr.icon), "untitled.dmi")

proc/newicon(w, h)
//initializes a new icon of any size
//requires blank.dmi that contains a blank unlabled 32x32 icon_state
var/icon/ic = icon('blank.dmi')
ic.Scale(w, h)
return ic

proc/merge_icon(icon/a, icon/b)
//returns the result of merging a and b
var/icon/ic = new(a)
var/icon/m = icon(b, moving = 1)
var/icon/n = icon(b, moving = 0)
for(var/s in icon_states(m))
if(s != "")
ic.Insert(icon(m, s), s, moving = 1)
for(var/s in icon_states(n))
if(s != "")
ic.Insert(icon(n, s), s, moving = 0)
return ic

proc/remove_blanks(icon/a)
//removes any icon states that are not labeled
var/icon/ic = new
var/icon/m = icon(a, moving = 1)
var/icon/n = icon(a, moving = 0)
for(var/s in icon_states(m))
if(s != "")
ic.Insert(icon(m, s), s, moving = 1)
for(var/s in icon_states(n))
if(s != "")
ic.Insert(icon(n, s), s, moving = 0)
return ic