OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mw/] [src/] [demos/] [nanox/] [demo2.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
#define MWINCLUDECOLORS
2
#include <stdio.h>
3 716 simons
/* SIMON: we use exit */
4
#include <stdlib.h>
5 673 markom
#include "nano-X.h"
6
 
7
#include <signal.h>
8
 
9
int
10
main(int ac,char **av)
11
{
12
        GR_WINDOW_ID    w, w2;
13
        GR_GC_ID        gc;
14
        GR_EVENT        event;
15
        GR_WM_PROPERTIES props;
16
 
17
        if (GrOpen() < 0) {
18
                printf("Can't open graphics\n");
19
                exit(1);
20
        }
21
 
22
        /* pass errors through main loop*/
23
        GrSetErrorHandler(NULL);
24
 
25
#define WIDTH   320
26
#define HEIGHT  240
27
        w = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 20, WIDTH, HEIGHT,
28
                0, GREEN, BLACK);
29
 
30
        w2 = GrNewWindow(w, 20, 20, 40, 40, 0, WHITE, BLACK);
31
 
32
        props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE;
33
        props.props = GR_WM_PROPS_NOBACKGROUND;
34
        props.title = "Nano-X Demo2";
35
        GrSetWMProperties(w, &props);
36
 
37
        gc = GrNewGC();
38
 
39
        GrSelectEvents(w, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ
40
                | GR_EVENT_MASK_BUTTON_DOWN
41
                | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP);
42
        GrMapWindow(w);
43
        GrSetFocus(w);
44
        /* serious bug here: when wm running, w2 is mapped anyway!!*/
45
        /*GrMapWindow(w2);*/
46
 
47
        for (;;) {
48
                /*GR_EVENT_KEYSTROKE *kev;*/
49
 
50
                GrGetNextEvent(&event);
51
                switch (event.type) {
52
                case GR_EVENT_TYPE_EXPOSURE:
53
                        GrSetGCForeground(gc,GrGetSysColor(GR_COLOR_APPWINDOW));
54
                        GrFillRect(w, gc, event.exposure.x, event.exposure.y,
55
                                event.exposure.width, event.exposure.height);
56
                        GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_APPTEXT));
57
                        GrSetGCUseBackground(gc, GR_FALSE);
58
                        GrText(w, gc, 10, 30, "Hello World", -1, GR_TFASCII);
59
GrRect(w, gc, 5, 5, 300, 60);
60
                        break;
61
                case GR_EVENT_TYPE_CLOSE_REQ:
62
                        GrClose();
63
                        exit(0);
64
                        break;
65
                case GR_EVENT_TYPE_ERROR:
66
                        printf("\7demo2: Error (%s) ", event.error.name);
67
                        printf(nxErrorStrings[event.error.code],event.error.id);
68
                        break;
69
#if 0
70
                case GR_EVENT_TYPE_BUTTON_DOWN:
71
                        /* test server error on bad syscall*/
72
                        GrMapWindow(w2);
73
                        GrMoveWindow(GR_ROOT_WINDOW_ID, 0, 0);
74
                        { GR_SCREEN_INFO sinfo; GrGetScreenInfo(&sinfo); }
75
                        break;
76
#endif
77
#if 0
78
                case GR_EVENT_TYPE_KEY_DOWN:
79
                        kev = (GR_EVENT_KEYSTROKE *)&event;
80
                        printf("DOWN %d (%04x) %04x\n",
81
                                kev->ch, kev->ch, kev->modifiers);
82
                        break;
83
                case GR_EVENT_TYPE_KEY_UP:
84
                        kev = (GR_EVENT_KEYSTROKE *)&event;
85
                        printf("UP %d (%04x) %04x\n",
86
                                kev->ch, kev->ch, kev->modifiers);
87
                        break;
88
#endif
89
                }
90
        }
91
 
92
        GrClose();
93
        return 0;
94
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.