]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/demos/nanox/nxview.c
Initial revision
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / demos / nanox / nxview.c
1 /*
2  * Copyright (c) 2000, 2001 Greg Haerr <greg@censoft.com>
3  *
4  * nxview - Nano-X image viewer
5  *
6  * Autorecognizes and displays BMP, GIF, JPEG, PNG and XPM files
7  */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #define MWINCLUDECOLORS
12 #include "nano-X.h"
13
14 int
15 main(int argc,char **argv)
16 {
17         GR_IMAGE_ID     image_id;
18         GR_WINDOW_ID    window_id;
19         GR_GC_ID        gc_id;
20         GR_SIZE         w = -1;
21         GR_SIZE         h = -1;
22         GR_EVENT        event;
23         GR_SCREEN_INFO  sinfo;
24         GR_IMAGE_INFO   info;
25         char            title[256];
26
27         if (argc < 2) {
28                 printf("Usage: nxview <image file> [stretch]\n");
29                 exit(1);
30         }
31
32         if (GrOpen() < 0) {
33                 fprintf(stderr, "cannot open graphics\n");
34                 exit(1);
35         }
36         
37         if (!(image_id = GrLoadImageFromFile(argv[1], 0))) {
38                 fprintf(stderr, "Can't load image file: %s\n", argv[1]);
39                 exit(1);
40         }
41
42         if(argc > 2) {
43                 /* stretch to half screen size*/
44                 GrGetScreenInfo(&sinfo);
45                 w = sinfo.cols/2;
46                 h = sinfo.rows/2;
47         } else {
48                 GrGetImageInfo(image_id, &info);
49                 w = info.width;
50                 h = info.height;
51         }
52
53         sprintf(title, "nxview %s", argv[1]);
54         window_id = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, title,
55                 GR_ROOT_WINDOW_ID, 0, 0, w, h, BLACK);
56
57         GrSelectEvents(window_id,
58                 GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE);
59
60         GrMapWindow(window_id);
61
62         gc_id = GrNewGC();
63
64         while (1) {
65                 GrGetNextEvent(&event);
66                 switch(event.type) {
67                 case GR_EVENT_TYPE_CLOSE_REQ:
68                         GrDestroyWindow(window_id);
69                         GrDestroyGC(gc_id);
70                         GrFreeImage(image_id);
71                         GrClose();
72                         exit(0);
73                         /* no return*/
74                 case GR_EVENT_TYPE_EXPOSURE:
75                         GrDrawImageToFit(window_id, gc_id, 0,0, w,h, image_id);
76                         break;
77                 }
78         }
79
80         return 0;
81 }