/*
|
/*
|
* Copyright (c) 2000 Greg Haerr <greg@censoft.com>
|
* Copyright (c) 2000 Greg Haerr <greg@censoft.com>
|
* Copyright (c) 2000 Century Software <embedded.centurysoftware.com>
|
* Copyright (c) 2000 Century Software <embedded.centurysoftware.com>
|
*
|
*
|
* Scribble Handwriting Recognition for Nano-X!
|
* Scribble Handwriting Recognition for Nano-X!
|
*/
|
*/
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#define MWINCLUDECOLORS
|
#define MWINCLUDECOLORS
|
#include "nano-X.h"
|
#include "nano-X.h"
|
#include "scrib.h"
|
#include "scrib.h"
|
|
|
#define TEXTWIN_WIDTH 200 /* text window width/height*/
|
#define TEXTWIN_WIDTH 200 /* text window width/height*/
|
#define TEXTWIN_HEIGHT 150
|
#define TEXTWIN_HEIGHT 150
|
|
|
static ScribbleWidget w;
|
static ScribbleWidget w;
|
|
|
static GR_BOOL bTextwin = GR_FALSE;
|
static GR_BOOL bTextwin = GR_FALSE;
|
static GR_WINDOW_ID wt = 0;
|
static GR_WINDOW_ID wt = 0;
|
static GR_GC_ID gct = 0;
|
static GR_GC_ID gct = 0;
|
static GR_GC_ID gctb = 0;
|
static GR_GC_ID gctb = 0;
|
static GR_COORD xpos = 0;
|
static GR_COORD xpos = 0;
|
static GR_COORD ypos = 0;
|
static GR_COORD ypos = 0;
|
static GR_SIZE width; /* width of character */
|
static GR_SIZE width; /* width of character */
|
static GR_SIZE height; /* height of character */
|
static GR_SIZE height; /* height of character */
|
static GR_SIZE base; /* height of baseline */
|
static GR_SIZE base; /* height of baseline */
|
static void char_out(GR_CHAR ch);
|
static void char_out(GR_CHAR ch);
|
static void char_del(GR_COORD x, GR_COORD y);
|
static void char_del(GR_COORD x, GR_COORD y);
|
|
|
void do_buttondown(GR_EVENT_BUTTON *bp);
|
void do_buttondown(GR_EVENT_BUTTON *bp);
|
void do_buttonup(GR_EVENT_BUTTON *bp);
|
void do_buttonup(GR_EVENT_BUTTON *bp);
|
void do_motion(GR_EVENT_MOUSE *mp);
|
void do_motion(GR_EVENT_MOUSE *mp);
|
void do_focusin(GR_EVENT_GENERAL *gp);
|
void do_focusin(GR_EVENT_GENERAL *gp);
|
void do_keystroke(GR_EVENT_KEYSTROKE *kp);
|
void do_keystroke(GR_EVENT_KEYSTROKE *kp);
|
void do_exposure(GR_EVENT_EXPOSURE *ep);
|
void do_exposure(GR_EVENT_EXPOSURE *ep);
|
|
|
int
|
int
|
main(int argc, char **argv)
|
main(int argc, char **argv)
|
{
|
{
|
int t = 1;
|
int t = 1;
|
GR_EVENT event; /* current event */
|
GR_EVENT event; /* current event */
|
|
|
while (t < argc) {
|
while (t < argc) {
|
if (!strcmp("-t", argv[t])) {
|
if (!strcmp("-t", argv[t])) {
|
bTextwin = GR_TRUE;
|
bTextwin = GR_TRUE;
|
++t;
|
++t;
|
continue;
|
continue;
|
}
|
}
|
}
|
}
|
|
|
if (GrOpen() < 0) {
|
if (GrOpen() < 0) {
|
fprintf(stderr, "cannot open graphics\n");
|
fprintf(stderr, "cannot open graphics\n");
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
if (bTextwin) {
|
if (bTextwin) {
|
/* create text output window for debugging*/
|
/* create text output window for debugging*/
|
wt = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 20,
|
wt = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 20,
|
TEXTWIN_WIDTH, TEXTWIN_HEIGHT, 5, BLACK, GREEN);
|
TEXTWIN_WIDTH, TEXTWIN_HEIGHT, 5, BLACK, GREEN);
|
GrSelectEvents(wt,
|
GrSelectEvents(wt,
|
GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_KEY_DOWN
|
GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_KEY_DOWN
|
| GR_EVENT_MASK_EXPOSURE);
|
| GR_EVENT_MASK_EXPOSURE);
|
GrMapWindow(wt);
|
GrMapWindow(wt);
|
gct = GrNewGC();
|
gct = GrNewGC();
|
GrSetGCForeground(gct, GREEN);
|
GrSetGCForeground(gct, GREEN);
|
GrGetGCTextSize(gct, "A",1, GR_TFASCII, &width, &height, &base);
|
GrGetGCTextSize(gct, "A",1, GR_TFASCII, &width, &height, &base);
|
GrSetGCFont(gct, GrCreateFont(GR_FONT_OEM_FIXED, 0, NULL));
|
GrSetGCFont(gct, GrCreateFont(GR_FONT_OEM_FIXED, 0, NULL));
|
gctb = GrNewGC();
|
gctb = GrNewGC();
|
GrSetGCForeground(gctb, BLACK);
|
GrSetGCForeground(gctb, BLACK);
|
}
|
}
|
|
|
/* create scribble input window*/
|
/* create scribble input window*/
|
w = create_scribble();
|
w = create_scribble();
|
|
|
while (1) {
|
while (1) {
|
GrGetNextEvent(&event);
|
GrGetNextEvent(&event);
|
|
|
switch (event.type) {
|
switch (event.type) {
|
case GR_EVENT_TYPE_BUTTON_DOWN:
|
case GR_EVENT_TYPE_BUTTON_DOWN:
|
do_buttondown(&event.button);
|
do_buttondown(&event.button);
|
break;
|
break;
|
|
|
case GR_EVENT_TYPE_BUTTON_UP:
|
case GR_EVENT_TYPE_BUTTON_UP:
|
do_buttonup(&event.button);
|
do_buttonup(&event.button);
|
break;
|
break;
|
|
|
case GR_EVENT_TYPE_MOUSE_POSITION:
|
case GR_EVENT_TYPE_MOUSE_POSITION:
|
case GR_EVENT_TYPE_MOUSE_MOTION:
|
case GR_EVENT_TYPE_MOUSE_MOTION:
|
do_motion(&event.mouse);
|
do_motion(&event.mouse);
|
break;
|
break;
|
|
|
case GR_EVENT_TYPE_FOCUS_IN:
|
case GR_EVENT_TYPE_FOCUS_IN:
|
do_focusin(&event.general);
|
do_focusin(&event.general);
|
break;
|
break;
|
|
|
case GR_EVENT_TYPE_KEY_DOWN:
|
case GR_EVENT_TYPE_KEY_DOWN:
|
do_keystroke(&event.keystroke);
|
do_keystroke(&event.keystroke);
|
break;
|
break;
|
|
|
case GR_EVENT_TYPE_EXPOSURE:
|
case GR_EVENT_TYPE_EXPOSURE:
|
do_exposure(&event.exposure);
|
do_exposure(&event.exposure);
|
break;
|
break;
|
|
|
case GR_EVENT_TYPE_CLOSE_REQ:
|
case GR_EVENT_TYPE_CLOSE_REQ:
|
GrClose();
|
GrClose();
|
exit(0);
|
exit(0);
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here when a button is pressed.
|
* Here when a button is pressed.
|
*/
|
*/
|
void
|
void
|
do_buttondown(GR_EVENT_BUTTON *bp)
|
do_buttondown(GR_EVENT_BUTTON *bp)
|
{
|
{
|
ActionStart(w, bp->x, bp->y);
|
ActionStart(w, bp->x, bp->y);
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here when a button is released.
|
* Here when a button is released.
|
*/
|
*/
|
void
|
void
|
do_buttonup(GR_EVENT_BUTTON *bp)
|
do_buttonup(GR_EVENT_BUTTON *bp)
|
{
|
{
|
ActionEnd(w, bp->x, bp->y);
|
ActionEnd(w, bp->x, bp->y);
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here when the mouse has a motion event.
|
* Here when the mouse has a motion event.
|
*/
|
*/
|
void
|
void
|
do_motion(GR_EVENT_MOUSE *mp)
|
do_motion(GR_EVENT_MOUSE *mp)
|
{
|
{
|
ActionMove(w, mp->x, mp->y);
|
ActionMove(w, mp->x, mp->y);
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here when our window gets focus
|
* Here when our window gets focus
|
*/
|
*/
|
void
|
void
|
do_focusin(GR_EVENT_GENERAL *gp)
|
do_focusin(GR_EVENT_GENERAL *gp)
|
{
|
{
|
#if 0
|
#if 0
|
/* if the window receiving focus is scribble, remember last window*/
|
/* if the window receiving focus is scribble, remember last window*/
|
if (gp->wid == w->win && gp->wid != 1)
|
if (gp->wid == w->win && gp->wid != 1)
|
w->lastfocusid = gp->otherid;
|
w->lastfocusid = gp->otherid;
|
#endif
|
#endif
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here when an exposure event occurs.
|
* Here when an exposure event occurs.
|
*/
|
*/
|
void
|
void
|
do_exposure(GR_EVENT_EXPOSURE *ep)
|
do_exposure(GR_EVENT_EXPOSURE *ep)
|
{
|
{
|
if (ep->wid == w->win)
|
if (ep->wid == w->win)
|
Redisplay(w);
|
Redisplay(w);
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here when a keyboard press or injection occurs.
|
* Here when a keyboard press or injection occurs.
|
*/
|
*/
|
void
|
void
|
do_keystroke(GR_EVENT_KEYSTROKE *kp)
|
do_keystroke(GR_EVENT_KEYSTROKE *kp)
|
{
|
{
|
if (bTextwin)
|
if (bTextwin)
|
char_out(kp->ch);
|
char_out(kp->ch);
|
}
|
}
|
|
|
static void
|
static void
|
char_del(GR_COORD x, GR_COORD y)
|
char_del(GR_COORD x, GR_COORD y)
|
{
|
{
|
xpos -= width;
|
xpos -= width;
|
GrFillRect(wt, gctb, x+1, y /*- height*/ /*+ base*/, width, height);
|
GrFillRect(wt, gctb, x+1, y /*- height*/ /*+ base*/, width, height);
|
}
|
}
|
|
|
static void
|
static void
|
char_out(GR_CHAR ch)
|
char_out(GR_CHAR ch)
|
{
|
{
|
switch(ch) {
|
switch(ch) {
|
case '\r':
|
case '\r':
|
case '\n':
|
case '\n':
|
xpos = 0;
|
xpos = 0;
|
ypos += height;
|
ypos += height;
|
if(ypos >= TEXTWIN_HEIGHT - height) {
|
if(ypos >= TEXTWIN_HEIGHT - height) {
|
ypos -= height;
|
ypos -= height;
|
|
|
/* FIXME: changing FALSE to TRUE crashes nano-X*/
|
/* FIXME: changing FALSE to TRUE crashes nano-X*/
|
/* clear screen, no scroll*/
|
/* clear screen, no scroll*/
|
ypos = 0;
|
ypos = 0;
|
GrClearWindow(wt, GR_FALSE);
|
GrClearWindow(wt, GR_FALSE);
|
}
|
}
|
return;
|
return;
|
case '\007': /* bel*/
|
case '\007': /* bel*/
|
return;
|
return;
|
case '\t':
|
case '\t':
|
xpos += width;
|
xpos += width;
|
while((xpos/width) & 7)
|
while((xpos/width) & 7)
|
char_out(' ');
|
char_out(' ');
|
return;
|
return;
|
case '\b': /* assumes fixed width font!!*/
|
case '\b': /* assumes fixed width font!!*/
|
if (xpos <= 0)
|
if (xpos <= 0)
|
return;
|
return;
|
char_del(xpos, ypos);
|
char_del(xpos, ypos);
|
char_out(' ');
|
char_out(' ');
|
char_del(xpos, ypos);
|
char_del(xpos, ypos);
|
return;
|
return;
|
}
|
}
|
GrText(wt, gct, xpos+1, ypos, &ch, 1, GR_TFTOP);
|
GrText(wt, gct, xpos+1, ypos, &ch, 1, GR_TFTOP);
|
xpos += width;
|
xpos += width;
|
|
|
if (xpos >= TEXTWIN_WIDTH-width)
|
if (xpos >= TEXTWIN_WIDTH-width)
|
char_out('\n');
|
char_out('\n');
|
}
|
}
|
|
|