code: 9ferno

ref: 568002402f2e2c18e807e80903c20337af523412
dir: /tests/drawcontext.b/

View raw version
# File: drawcontext.b

implement DrawContext;

include "sys.m";
include "draw.m";

sys : Sys;
draw : Draw;
Screen, Display : import draw;

DrawContext : module
{
	init : fn(ctxt : ref Draw->Context, args : list of string);
};

init (ctxt : ref Draw->Context, nil : list of string)
{
	sys = load Sys Sys->PATH;
	draw = load Draw Draw->PATH;
	if(draw == nil){
		sys->fprint(sys->filedes(2), "cannot load Draw module\n");
		raise "fail: bad module";
	}

	if (ctxt == nil)
	{
		sys->print("No valid graphics contetx, allocating a new one...\n");
		display := Display.allocate(nil);
		screen := Screen.allocate(display.image, display.rgb(99,99,99), 1);
		ctxt = ref (screen, display, nil, nil, nil, nil, nil);
	}
}