Re-factored part of gfx_fill_rect

Removed references to global vars that are not required. Possible bug in line 416 will require looking at.