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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (C) 2000 by VTech Informations LTD
3
 *
4
 * This program is released under MPL
5
 *
6
 * Vladimir Cotfas <vladimircotfas@vtech.ca>, Nov 7, 2000
7
 */
8
 
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <string.h>
12
#define MWINCLUDECOLORS
13
#include "nano-X.h"
14
 
15
 
16
static  GR_WINDOW_ID    w1;             /* id for large window */
17
static  GR_WINDOW_ID    w2;             /* id for child window */
18
static  GR_GC_ID        gc1;            /* graphics context for text */
19
 
20
#define ALT_CURSOR
21
 
22
#define WIDTH   100
23
#define HEIGHT  100
24
 
25
#ifdef ALT_CURSOR
26
/*
27
 * Definitions to make it easy to define cursors
28
 */
29
#define _       ((unsigned) 0)          /* off bits */
30
#define X       ((unsigned) 1)          /* on bits */
31
#define MASK(a,b,c,d,e,f,g) \
32
        (((((((((((((a * 2) + b) * 2) + c) * 2) + d) * 2) \
33
        + e) * 2) + f) * 2) + g) << 9)
34
#endif
35
 
36
struct _xlat {
37
        GR_UPDATE_TYPE type;
38
        const char* name;
39
};
40
typedef struct _xlat XLAT;
41
 
42
static XLAT update_types[] = {
43
        { 0,                     "none" },
44
        { GR_UPDATE_MAP,        "GR_UPDATE_MAP" },
45
        { GR_UPDATE_UNMAP,      "GR_UPDATE_UNMAP" },
46
        { GR_UPDATE_MOVE,       "GR_UPDATE_MOVE" },
47
        { GR_UPDATE_SIZE,       "GR_UPDATE_SIZE" },
48
        { GR_UPDATE_UNMAPTEMP,  "GR_UPDATE_UNMAPTEMP" },
49
        { GR_UPDATE_ACTIVATE,   "GR_UPDATE_ACTIVATE" },
50
        { GR_UPDATE_DESTROY,    "GR_UPDATE_DESTROY" }
51
};
52
#define NR_UPDATES      7       
53
 
54
struct XLAT {
55
        int event_type;
56
        char* event_desc;
57
};
58
 
59
static struct XLAT table[] = {
60
        { GR_EVENT_TYPE_ERROR,          "GR_EVENT_TYPE_ERROR"           },
61
        { GR_EVENT_TYPE_NONE,           "GR_EVENT_TYPE_NONE"            },
62
        { GR_EVENT_TYPE_EXPOSURE,       "GR_EVENT_TYPE_EXPOSURE"        },
63
        { GR_EVENT_TYPE_BUTTON_DOWN,    "GR_EVENT_TYPE_BUTTON_DOWN"     },
64
        { GR_EVENT_TYPE_BUTTON_UP,      "GR_EVENT_TYPE_BUTTON_UP"       },
65
        { GR_EVENT_TYPE_MOUSE_ENTER,    "GR_EVENT_TYPE_MOUSE_ENTER"     },
66
        { GR_EVENT_TYPE_MOUSE_EXIT,     "GR_EVENT_TYPE_MOUSE_EXIT"      },
67
        { GR_EVENT_TYPE_MOUSE_MOTION,   "GR_EVENT_TYPE_MOUSE_MOTION"    },
68
        { GR_EVENT_TYPE_MOUSE_POSITION, "GR_EVENT_TYPE_MOUSE_POSITION"  },
69
        { GR_EVENT_TYPE_KEY_DOWN,       "GR_EVENT_TYPE_KEY_DOWN"        },
70
        { GR_EVENT_TYPE_KEY_UP,         "GR_EVENT_TYPE_KEY_UP"          },
71
        { GR_EVENT_TYPE_FOCUS_IN,       "GR_EVENT_TYPE_FOCUS_IN"        },
72
        { GR_EVENT_TYPE_FOCUS_OUT,      "GR_EVENT_TYPE_FOCUS_OUT"       },
73
        { GR_EVENT_TYPE_FDINPUT,        "GR_EVENT_TYPE_FDINPUT"         },
74
        { GR_EVENT_TYPE_UPDATE,         "GR_EVENT_TYPE_UPDATE"          },
75
        { GR_EVENT_TYPE_CHLD_UPDATE,    "GR_EVENT_TYPE_CHLD_UPDATE"     },
76
        { GR_EVENT_TYPE_CLOSE_REQ,      "GR_EVENT_TYPE_CLOSE_REQ"       },
77
};
78
 
79
#define table_SZ        (sizeof(table) / sizeof(table[0]))
80
 
81
char*
82
lookupEvent(int type)
83
{
84
        int i;
85
 
86
        for (i = 0; i < table_SZ; i++)
87
                if (table[i].event_type == type)
88
                        return table[i].event_desc;
89
 
90
        return NULL;
91
}
92
 
93
int
94
main(int argc, char **argv)
95
{
96
        GR_EVENT        event;          /* current event */
97
 
98
        if (GrOpen() < 0) {
99
                fprintf(stderr, "cannot open graphics\n");
100
                exit(1);
101
        }
102
 
103
        GrReqShmCmds(65536); /* shared mem is suposed to be faster */
104
 
105
        w1 = GrNewWindow(GR_ROOT_WINDOW_ID,
106
                        0, 0,
107
                        WIDTH, HEIGHT,
108
                        4,
109
                        WHITE, BLACK);
110
        GrSelectEvents(w1, 0xffffffffl); /* all events :) */
111
 
112
        w2 = GrNewWindow(w1,
113
                        10, 10,
114
                        WIDTH / 4, HEIGHT / 4,
115
                        4,
116
                        WHITE, BLACK);
117
        GrSelectEvents(w2, 0xffffffffl); /* all events :) */
118
 
119
 
120
        {
121
          GR_WM_PROPERTIES props;
122
 
123
          props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE;
124
 
125
          props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION | \
126
                        GR_WM_PROPS_CAPTION | GR_WM_PROPS_CLOSEBOX;
127
          props.title = "nano-X Events";
128
          GrSetWMProperties(w1, &props);
129
        }
130
 
131
        GrMapWindow(w1);
132
        GrMapWindow(w2);
133
 
134
        gc1 = GrNewGC();
135
 
136
        GrSetGCForeground(gc1, BLACK);
137
        GrSetGCBackground(gc1, WHITE);
138
 
139
 
140
#ifdef ALT_CURSOR
141
        {
142
                GR_BITMAP       bitmap1fg[7];   /* bitmaps for cursor */
143
                GR_BITMAP       bitmap1bg[7];
144
 
145
                bitmap1bg[0] = MASK(X,X,X,X,X,X,X);
146
                bitmap1bg[1] = MASK(_,X,X,X,X,X,_);
147
                bitmap1bg[2] = MASK(_,_,X,X,X,_,_);
148
                bitmap1bg[3] = MASK(_,_,_,X,_,_,_);
149
                bitmap1bg[4] = MASK(_,_,X,X,X,_,_);
150
                bitmap1bg[5] = MASK(_,X,X,X,X,X,_);
151
                bitmap1bg[6] = MASK(X,X,X,X,X,X,X);
152
 
153
                bitmap1fg[0] = MASK(X,X,X,X,X,X,X);
154
                bitmap1fg[1] = MASK(_,X,X,X,X,X,_);
155
                bitmap1fg[2] = MASK(_,_,X,X,X,_,_);
156
                bitmap1fg[3] = MASK(_,_,_,X,_,_,_);
157
                bitmap1fg[4] = MASK(_,_,X,X,X,_,_);
158
                bitmap1fg[5] = MASK(_,X,X,X,X,X,_);
159
                bitmap1fg[6] = MASK(X,X,X,X,X,X,X);
160
 
161
                GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg);
162
        }
163
#endif
164
 
165
 
166
        for (;;) {
167
                GrGetNextEvent(&event);
168
 
169
                printf("%s (0x%x)\n", \
170
                       lookupEvent(event.type), event.type);
171
 
172
                switch(event.type) {
173
                  case GR_EVENT_TYPE_EXPOSURE:
174
                        {
175
                          printf("\twid = %d\n", event.exposure.wid);
176
                          printf("\t(X, Y) = (%d, %d)\n", \
177
                                 event.exposure.x, event.exposure.y);
178
                          printf("\twidth = %d, height = %d\n", \
179
                                 event.exposure.width, event.exposure.height);
180
                        }
181
                        break;
182
                  case GR_EVENT_TYPE_BUTTON_DOWN:
183
                  case GR_EVENT_TYPE_BUTTON_UP:
184
                        {
185
                          printf("\twid = %d\n", event.button.wid);
186
                          printf("\tsub-window id = %d\n", event.button.subwid);
187
                          printf("\troot window (X, Y) coordinates = (%d, %d)\n", \
188
                                 event.button.rootx, event.button.rooty);
189
                          printf("\t(X, Y) = (%d, %d)\n", \
190
                                 event.button.x, event.button.y);
191
                          printf("\tbuttons: %04X, ", event.button.buttons);
192
                          printf("changed buttons: %04X\n", event.button.changebuttons);
193
                          printf("\tmodifiers: %04X\n", event.button.modifiers);
194
                        }
195
                        break;
196
                  case GR_EVENT_TYPE_MOUSE_ENTER:
197
                  case GR_EVENT_TYPE_MOUSE_EXIT:
198
                  case GR_EVENT_TYPE_MOUSE_MOTION:
199
                  case GR_EVENT_TYPE_MOUSE_POSITION:
200
                        {
201
                          printf("\twid = %d\n", event.mouse.wid);
202
                          printf("\tsub-window id = %d\n", event.mouse.subwid);
203
                          printf("\troot window (X, Y) coordinates = (%d, %d)\n", \
204
                                 event.mouse.rootx, event.mouse.rooty);
205
                          printf("\t(X, Y) = (%d, %d)\n", \
206
                                 event.mouse.x, event.mouse.y);
207
                          printf("\tbuttons: %04X\n", event.mouse.buttons);
208
                          printf("\tmodifiers: %04X\n", event.mouse.modifiers);
209
                        }
210
                        break;
211
                  case GR_EVENT_TYPE_KEY_DOWN:
212
                  case GR_EVENT_TYPE_KEY_UP:
213
                        {
214
                          printf("\twid = %d\n", event.keystroke.wid);
215
                          printf("\tsub-window id = %d\n", event.keystroke.subwid);
216
                          printf("\troot window (X, Y) coordinates = (%d, %d)\n", \
217
                                 event.keystroke.rootx, event.keystroke.rooty);
218
                          printf("\t(X, Y) = (%d, %d)\n", \
219
                                 event.keystroke.x, event.keystroke.y);
220
                          printf("\tbuttons: %04X\n", event.keystroke.buttons);
221
                          printf("\tmodifiers: %04X\n", event.keystroke.modifiers);
222
                          printf("\tUnicode-16 keyvalue: %d, ASCII: %d\n", \
223
                                 (int)event.keystroke.ch, event.keystroke.ch);
224
                          printf("\tscancode: %02X\n",
225
                                (int)event.keystroke.scancode);
226
                        }
227
                        break;
228
                  case GR_EVENT_TYPE_FOCUS_IN:
229
                        printf("\twid = %d\n", event.general.wid);
230
                        printf("\told focus = %d\n", event.general.otherid);
231
                        break;
232
                  case GR_EVENT_TYPE_FOCUS_OUT:
233
                        printf("\twid = %d\n", event.general.wid);
234
                        printf("\tnew focus = %d\n", event.general.otherid);
235
                        break;
236
                  case GR_EVENT_TYPE_UPDATE:
237
                  case GR_EVENT_TYPE_CHLD_UPDATE:
238
                        {
239
                          printf("\twid = %d\n", event.update.wid);
240
                          printf("\tsub-window id = %d\n", event.update.subwid);
241
                          printf("\t(X, Y) = (%d, %d)\n", \
242
                                 event.update.x, event.update.y);
243
                          printf("\twidth = %d, height = %d\n", \
244
                                 event.update.width, event.update.height);
245
                          {
246
                                  GR_UPDATE_TYPE u = event.update.utype;
247
                                  const char* p;
248
 
249
                                  p =  (u > NR_UPDATES)? \
250
                                          "<unknown>": \
251
                                          update_types[u].name;
252
 
253
                                  printf("\tupdate_type: %s (%d)\n",
254
                                          p, u);
255
                          }
256
                        }
257
                        break;
258
                  case GR_EVENT_TYPE_TIMEOUT:
259
                        printf("\ttimeout?\n");
260
                        break;
261
                  case GR_EVENT_TYPE_CLOSE_REQ:
262
                        GrClose();
263
                        exit(0);
264
                        /* no return*/
265
                }
266
        }
267
 
268
        return 0;
269
}

powered by: WebSVN 2.1.0

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