xref: /inferno-os/os/ipaq1110/tstdraw.b (revision 74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a)
1implement Test;
2
3include "sys.m";
4
5include "draw.m";
6
7Test: module
8{
9	init:	fn(ctxt: ref Draw->Context, argv: list of string);
10};
11
12init(ctxt: ref Draw->Context, nil: list of string)
13{
14	sys := load Sys Sys->PATH;
15	draw := load Draw Draw->PATH;
16	Display, Font, Rect, Point, Image, Screen: import draw;
17
18	#
19	# Set up connection to display, or use the existing one
20	# if provided.
21	#
22	display: ref Display;
23	disp: ref Image;
24	if (ctxt == nil) {
25		display = draw->Display.allocate(nil);
26		disp = display.image;
27	} else {
28		display = ctxt.display;
29		disp = ctxt.screen.newwindow(display.image.r, Draw->White);
30	}
31
32	#
33	# Initialize colours.
34	#
35	red := display.color(Draw->Red);
36	blue := display.color(Draw->Blue);
37	white := display.color(Draw->White);
38	yellow := display.color(Draw->Yellow);
39	ones := display.ones;
40
41	#
42	# Paint the screen red.
43	#
44	disp.draw(disp.r, red, ones, disp.r.min);
45	sys->sleep(5000);
46
47	#
48	# Texture a region with rectangular tiles.
49	#
50	texture := display.newimage(((0,0),(2,3)), disp.ldepth, 1, 0);
51	texture.clipr = ((-10000,-10000),(10000,10000));
52	# put something in the texture
53	texture.draw(((0,0),(1,3)), blue, ones, (0,0));
54	texture.draw(((0,0),(2, 1)), blue, ones, (0,0));
55	# use texture as both source and mask to let
56	# destination colour show through
57	disp.draw(((100,100),(200,200)), texture, texture, (0,0));
58	sys->sleep(5000);
59
60	#
61	# White-out a quarter of the pixels in a region,
62	# to make the region appear shaded.
63	#
64	stipple := display.newimage(((0,0),(2,2)), disp.ldepth, 1, 0);
65	stipple.draw(((0,0),(1,1)), ones, ones, (0,0));
66	disp.draw(((100,100),(300,200)), white, stipple, (0,0));
67	sys->sleep(5000);
68
69	#
70	# Draw textured characters.
71	#
72	font := Font.open(display, "*default*");
73	disp.text((100,210), texture, (0,0), font, "Hello world");
74	sys->sleep(5000);
75
76	#
77	# Draw picture in elliptical frame.
78	#
79	delight := display.open("/icons/delight.bit");
80	piccenter := delight.r.min.add(delight.r.max).div(2);
81	disp.fillellipse((200,100), 150, 50, delight, piccenter);
82	disp.ellipse((200,100), 150, 50, 3, yellow, (0,0));
83	sys->sleep(5000);
84
85	#
86	# Draw a parabolic brush stroke using an elliptical brush
87	# to reveal more of the picture, consistent with what's
88	# already visible.
89	#
90	dx : con 15;
91	dy : con 3;
92	brush := display.newimage(((0,0),(2*dx+1,2*dy+1)), disp.ldepth,
93                               0, 0);
94	brush.fillellipse((dx,dy), dx, dy, ones, (0,0));
95	for(x:=delight.r.min.x; x<delight.r.max.x; x++){
96		y := (x-piccenter.x)*(x-piccenter.x)/80;
97		y += 2*dy+1;	# so whole brush is visible at top
98		xx := x+(200-piccenter.x)-dx;
99		yy := y+(100-piccenter.y)-dy;
100		disp.gendraw(((xx,yy),(xx+2*dx+1,yy+2*dy+1)),
101                       delight, (x-dx, y-dy), brush, (0,0));
102	}
103	for (i := 0; i < 500; i++) {
104		disp.draw(disp.r, disp, ones, (0, 10));
105		sys->sleep(5);
106	}
107}
108