2 * Copyright (c) 2000 Greg Haerr <greg@censoft.com>
3 * Copyright (c) 2000 Century Software <embedded.centurysoftware.com>
5 * Scribble Handwriting Recognition for Nano-X!
9 #define MWINCLUDECOLORS
13 #define TEXTWIN_WIDTH 200 /* text window width/height*/
14 #define TEXTWIN_HEIGHT 150
16 static ScribbleWidget w;
18 static GR_BOOL bTextwin = GR_FALSE;
19 static GR_WINDOW_ID wt = 0;
20 static GR_GC_ID gct = 0;
21 static GR_GC_ID gctb = 0;
22 static GR_COORD xpos = 0;
23 static GR_COORD ypos = 0;
24 static GR_SIZE width; /* width of character */
25 static GR_SIZE height; /* height of character */
26 static GR_SIZE base; /* height of baseline */
27 static void char_out(GR_CHAR ch);
28 static void char_del(GR_COORD x, GR_COORD y);
30 void do_buttondown(GR_EVENT_BUTTON *bp);
31 void do_buttonup(GR_EVENT_BUTTON *bp);
32 void do_motion(GR_EVENT_MOUSE *mp);
33 void do_focusin(GR_EVENT_GENERAL *gp);
34 void do_keystroke(GR_EVENT_KEYSTROKE *kp);
35 void do_exposure(GR_EVENT_EXPOSURE *ep);
38 main(int argc, char **argv)
41 GR_EVENT event; /* current event */
44 if (!strcmp("-t", argv[t])) {
52 fprintf(stderr, "cannot open graphics\n");
57 /* create text output window for debugging*/
58 wt = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 20,
59 TEXTWIN_WIDTH, TEXTWIN_HEIGHT, 5, BLACK, GREEN);
61 GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_KEY_DOWN
62 | GR_EVENT_MASK_EXPOSURE);
65 GrSetGCForeground(gct, GREEN);
66 GrGetGCTextSize(gct, "A",1, GR_TFASCII, &width, &height, &base);
67 GrSetGCFont(gct, GrCreateFont(GR_FONT_OEM_FIXED, 0, NULL));
69 GrSetGCForeground(gctb, BLACK);
72 /* create scribble input window*/
73 w = create_scribble();
76 GrGetNextEvent(&event);
79 case GR_EVENT_TYPE_BUTTON_DOWN:
80 do_buttondown(&event.button);
83 case GR_EVENT_TYPE_BUTTON_UP:
84 do_buttonup(&event.button);
87 case GR_EVENT_TYPE_MOUSE_POSITION:
88 case GR_EVENT_TYPE_MOUSE_MOTION:
89 do_motion(&event.mouse);
92 case GR_EVENT_TYPE_FOCUS_IN:
93 do_focusin(&event.general);
96 case GR_EVENT_TYPE_KEY_DOWN:
97 do_keystroke(&event.keystroke);
100 case GR_EVENT_TYPE_EXPOSURE:
101 do_exposure(&event.exposure);
104 case GR_EVENT_TYPE_CLOSE_REQ:
113 * Here when a button is pressed.
116 do_buttondown(GR_EVENT_BUTTON *bp)
118 ActionStart(w, bp->x, bp->y);
123 * Here when a button is released.
126 do_buttonup(GR_EVENT_BUTTON *bp)
128 ActionEnd(w, bp->x, bp->y);
133 * Here when the mouse has a motion event.
136 do_motion(GR_EVENT_MOUSE *mp)
138 ActionMove(w, mp->x, mp->y);
143 * Here when our window gets focus
146 do_focusin(GR_EVENT_GENERAL *gp)
149 /* if the window receiving focus is scribble, remember last window*/
150 if (gp->wid == w->win && gp->wid != 1)
151 w->lastfocusid = gp->otherid;
157 * Here when an exposure event occurs.
160 do_exposure(GR_EVENT_EXPOSURE *ep)
162 if (ep->wid == w->win)
168 * Here when a keyboard press or injection occurs.
171 do_keystroke(GR_EVENT_KEYSTROKE *kp)
178 char_del(GR_COORD x, GR_COORD y)
181 GrFillRect(wt, gctb, x+1, y /*- height*/ /*+ base*/, width, height);
192 if(ypos >= TEXTWIN_HEIGHT - height) {
195 /* FIXME: changing FALSE to TRUE crashes nano-X*/
196 /* clear screen, no scroll*/
198 GrClearWindow(wt, GR_FALSE);
201 case '\007': /* bel*/
205 while((xpos/width) & 7)
208 case '\b': /* assumes fixed width font!!*/
211 char_del(xpos, ypos);
213 char_del(xpos, ypos);
216 GrText(wt, gct, xpos+1, ypos, &ch, 1, GR_TFTOP);
219 if (xpos >= TEXTWIN_WIDTH-width)