aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/draw/img.c
blob: 01caa3c49dfec81dce6aff77b6613a1b919beaaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>

void
usage(void)
{
	fprint(2, "usage: img [-W winsize] [file]\n");
	exits("usage");
}

Image *image;

void
eresized(int new)
{
	if(new && getwindow(display, Refnone) < 0)
		sysfatal("can't reattach to window: %r");

	draw(screen, screen->r, display->white, nil, ZP);
	drawop(screen, screen->r, image, nil, image->r.min, S);
}

void
main(int argc, char **argv)
{
	int fd;
	Event e;

	ARGBEGIN{
	case 'W':
		winsize = EARGF(usage());
		break;
	default:
		usage();
	}ARGEND

	if(argc > 1)
		usage();

	if(argc == 1){
		if((fd = open(argv[0], OREAD)) < 0)
			sysfatal("open %s: %r");
	}else
		fd = 0;

	if(initdraw(0, nil, nil) < 0)
		sysfatal("initdraw: %r");

	if((image=readimage(display, fd, 0)) == nil)
		sysfatal("readimage: %r");

	drawresizewindow(Rect(0,0,Dx(image->r),Dy(image->r)));

	einit(Emouse|Ekeyboard);
	eresized(0);
	for(;;){
		switch(event(&e)){
		case Ekeyboard:
			if(e.kbdc == 'q' || e.kbdc == 0x7F)
				exits(nil);
			break;
		case Emouse:
			break;
		}
	}
}