implement Drawimg; include "sys.m"; sys: Sys; include "draw.m"; draw: Draw; Display, Image, Rect, Point: import draw; stderr: ref Sys->FD; # usage: draw xpos ypos img.bit [xpos ypos img.bit]... Drawimg: module { init: fn(ctxt: ref Draw->Context, argv: list of string); }; init(ctxt: ref Draw->Context, argv: list of string) { sys = load Sys Sys->PATH; stderr = sys->fildes(2); draw = load Draw Draw->PATH; argv = tl argv; if (argv == nil || len argv % 3 != 0) { sys->fprint(stderr, "usage: draw xpos ypos img.bit [xpos ypos img.bit]...\n"); raise "fail:usage"; } displ := ctxt.display; base := displ.readimage(sys->fildes(0)); if (base == nil) { sys->fprint(stderr, "draw: cannot read base image: %r\n"); raise "fail:error"; } for (; argv != nil; argv = tl tl tl argv) { (xpos, ypos, imgfile) := (int hd argv, int hd tl argv, hd tl tl argv); img := displ.open(imgfile); if (img == nil) { sys->fprint(stderr, "draw: cannot open %s: %r\n", imgfile); raise "fail:error"; } r := Rect((xpos, ypos), (xpos + img.r.dx(), ypos + img.r.dy())); base.draw(r, img, nil, img.r.min); } displ.writeimage(sys->fildes(1), base); }