/*
|
/*
|
* Demonstration program for Nano-X graphics.
|
* Demonstration program for Nano-X graphics.
|
*/
|
*/
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#define MWINCLUDECOLORS
|
#define MWINCLUDECOLORS
|
#include "nano-X.h"
|
#include "nano-X.h"
|
|
|
#if DOS_TURBOC
|
#if DOS_TURBOC
|
unsigned _stklen = 32768;
|
unsigned _stklen = 32768;
|
#endif
|
#endif
|
|
|
/*
|
/*
|
* Definitions to make it easy to define cursors
|
* Definitions to make it easy to define cursors
|
*/
|
*/
|
#define _ ((unsigned) 0) /* off bits */
|
#define _ ((unsigned) 0) /* off bits */
|
#define X ((unsigned) 1) /* on bits */
|
#define X ((unsigned) 1) /* on bits */
|
#define MASK(a,b,c,d,e,f,g) \
|
#define MASK(a,b,c,d,e,f,g) \
|
(((((((((((((a * 2) + b) * 2) + c) * 2) + d) * 2) \
|
(((((((((((((a * 2) + b) * 2) + c) * 2) + d) * 2) \
|
+ e) * 2) + f) * 2) + g) << 9)
|
+ e) * 2) + f) * 2) + g) << 9)
|
|
|
#define W2_WIDTH 70
|
#define W2_WIDTH 70
|
#define W2_HEIGHT 40
|
#define W2_HEIGHT 40
|
|
|
|
|
static GR_WINDOW_ID w1; /* id for large window */
|
static GR_WINDOW_ID w1; /* id for large window */
|
static GR_WINDOW_ID w2; /* id for small window */
|
static GR_WINDOW_ID w2; /* id for small window */
|
static GR_WINDOW_ID w3; /* id for third window */
|
static GR_WINDOW_ID w3; /* id for third window */
|
static GR_WINDOW_ID w4; /* id for grabbable window */
|
static GR_WINDOW_ID w4; /* id for grabbable window */
|
static GR_WINDOW_ID w5; /* id for testing enter/exit window */
|
static GR_WINDOW_ID w5; /* id for testing enter/exit window */
|
static GR_GC_ID gc1; /* graphics context for text */
|
static GR_GC_ID gc1; /* graphics context for text */
|
static GR_GC_ID gc2; /* graphics context for rectangle */
|
static GR_GC_ID gc2; /* graphics context for rectangle */
|
static GR_GC_ID gc3; /* graphics context for circles */
|
static GR_GC_ID gc3; /* graphics context for circles */
|
static GR_GC_ID gc4; /* graphics context for lines */
|
static GR_GC_ID gc4; /* graphics context for lines */
|
static GR_COORD begxpos; /* beginning x position */
|
static GR_COORD begxpos; /* beginning x position */
|
static GR_COORD xpos; /* x position for text drawing */
|
static GR_COORD xpos; /* x position for text drawing */
|
static GR_COORD ypos; /* y position for text drawing */
|
static GR_COORD ypos; /* y position for text drawing */
|
static GR_COORD linexpos; /* x position for line drawing */
|
static GR_COORD linexpos; /* x position for line drawing */
|
static GR_COORD lineypos; /* y position for line drawing */
|
static GR_COORD lineypos; /* y position for line drawing */
|
static GR_COORD xorxpos; /* x position for xor line */
|
static GR_COORD xorxpos; /* x position for xor line */
|
static GR_COORD xorypos; /* y position for xor line */
|
static GR_COORD xorypos; /* y position for xor line */
|
static GR_BOOL lineok; /* ok to draw line */
|
static GR_BOOL lineok; /* ok to draw line */
|
static GR_SIZE COLS, ROWS;
|
static GR_SIZE COLS, ROWS;
|
static GR_SCREEN_INFO si; /* information about screen */
|
static GR_SCREEN_INFO si; /* information about screen */
|
|
|
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_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);
|
void do_focusin(GR_EVENT_GENERAL *gp);
|
void do_focusin(GR_EVENT_GENERAL *gp);
|
void do_focusout(GR_EVENT_GENERAL *gp);
|
void do_focusout(GR_EVENT_GENERAL *gp);
|
void do_enter(GR_EVENT_GENERAL *gp);
|
void do_enter(GR_EVENT_GENERAL *gp);
|
void do_exit(GR_EVENT_GENERAL *gp);
|
void do_exit(GR_EVENT_GENERAL *gp);
|
void do_idle(void);
|
void do_idle(void);
|
/* routine to handle errors */
|
/* routine to handle errors */
|
void errorcatcher(GR_EVENT *ep);
|
void errorcatcher(GR_EVENT *ep);
|
|
|
int
|
int
|
main(int argc,char **argv)
|
main(int argc,char **argv)
|
{
|
{
|
GR_EVENT event; /* current event */
|
GR_EVENT event; /* current event */
|
GR_BITMAP bitmap1fg[7]; /* bitmaps for first cursor */
|
GR_BITMAP bitmap1fg[7]; /* bitmaps for first cursor */
|
GR_BITMAP bitmap1bg[7];
|
GR_BITMAP bitmap1bg[7];
|
GR_BITMAP bitmap2fg[7]; /* bitmaps for second cursor */
|
GR_BITMAP bitmap2fg[7]; /* bitmaps for second cursor */
|
GR_BITMAP bitmap2bg[7];
|
GR_BITMAP bitmap2bg[7];
|
|
|
if (GrOpen() < 0) {
|
if (GrOpen() < 0) {
|
fprintf(stderr, "cannot open graphics\n");
|
fprintf(stderr, "cannot open graphics\n");
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
GrReqShmCmds(655360);
|
GrReqShmCmds(655360);
|
|
|
GrGetScreenInfo(&si);
|
GrGetScreenInfo(&si);
|
COLS = si.cols - 40;
|
COLS = si.cols - 40;
|
ROWS = si.rows - 80;
|
ROWS = si.rows - 80;
|
|
|
/* print error, but don't exit*/
|
/* print error, but don't exit*/
|
GrSetErrorHandler(errorcatcher);
|
GrSetErrorHandler(errorcatcher);
|
|
|
w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 100, 50, COLS - 120,
|
w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 100, 50, COLS - 120,
|
ROWS - 60, 1, BROWN, WHITE);
|
ROWS - 60, 1, BROWN, WHITE);
|
w2 = GrNewWindow(GR_ROOT_WINDOW_ID, 6, 6, W2_WIDTH, W2_HEIGHT, 2, GREEN,
|
w2 = GrNewWindow(GR_ROOT_WINDOW_ID, 6, 6, W2_WIDTH, W2_HEIGHT, 2, GREEN,
|
WHITE);
|
WHITE);
|
w3 = GrNewWindow(GR_ROOT_WINDOW_ID, 250, 30, 80, 100, 1, LTGRAY,
|
w3 = GrNewWindow(GR_ROOT_WINDOW_ID, 250, 30, 80, 100, 1, LTGRAY,
|
GREEN);
|
GREEN);
|
w4 = GrNewWindow(GR_ROOT_WINDOW_ID, 350, 20, 200, 150, 5, BLACK, WHITE);
|
w4 = GrNewWindow(GR_ROOT_WINDOW_ID, 350, 20, 200, 150, 5, BLACK, WHITE);
|
w5 = GrNewWindow(GR_ROOT_WINDOW_ID, 11, 143, 209, 100, 1, BLUE, GREEN);
|
w5 = GrNewWindow(GR_ROOT_WINDOW_ID, 11, 143, 209, 100, 1, BLUE, GREEN);
|
|
|
GrSelectEvents(w1, GR_EVENT_MASK_BUTTON_DOWN |
|
GrSelectEvents(w1, GR_EVENT_MASK_BUTTON_DOWN |
|
GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE |
|
GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE |
|
GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT |
|
GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT |
|
GR_EVENT_MASK_CLOSE_REQ);
|
GR_EVENT_MASK_CLOSE_REQ);
|
/* must select down and up for w2 to get implicit grab when
|
/* must select down and up for w2 to get implicit grab when
|
* running window manager, otherwise the wm-created parent
|
* running window manager, otherwise the wm-created parent
|
* window will get the grab, and we won't get the button up...
|
* window will get the grab, and we won't get the button up...
|
*/
|
*/
|
GrSelectEvents(w2, GR_EVENT_MASK_BUTTON_DOWN |
|
GrSelectEvents(w2, GR_EVENT_MASK_BUTTON_DOWN |
|
GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_CLOSE_REQ);
|
GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_CLOSE_REQ);
|
GrSelectEvents(w3, GR_EVENT_MASK_BUTTON_DOWN |
|
GrSelectEvents(w3, GR_EVENT_MASK_BUTTON_DOWN |
|
GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_CLOSE_REQ);
|
GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_CLOSE_REQ);
|
GrSelectEvents(w4, GR_EVENT_MASK_BUTTON_DOWN |
|
GrSelectEvents(w4, GR_EVENT_MASK_BUTTON_DOWN |
|
GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION |
|
GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION |
|
GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_CLOSE_REQ);
|
GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_CLOSE_REQ);
|
GrSelectEvents(w5, GR_EVENT_MASK_MOUSE_ENTER |
|
GrSelectEvents(w5, GR_EVENT_MASK_MOUSE_ENTER |
|
GR_EVENT_MASK_MOUSE_EXIT | GR_EVENT_MASK_CLOSE_REQ);
|
GR_EVENT_MASK_MOUSE_EXIT | GR_EVENT_MASK_CLOSE_REQ);
|
GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_BUTTON_DOWN |
|
GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_BUTTON_DOWN |
|
GR_EVENT_MASK_CLOSE_REQ);
|
GR_EVENT_MASK_CLOSE_REQ);
|
|
|
GrMapWindow(w1);
|
GrMapWindow(w1);
|
GrMapWindow(w2);
|
GrMapWindow(w2);
|
GrMapWindow(w3);
|
GrMapWindow(w3);
|
GrMapWindow(w4);
|
GrMapWindow(w4);
|
GrMapWindow(w5);
|
GrMapWindow(w5);
|
|
|
gc1 = GrNewGC();
|
gc1 = GrNewGC();
|
gc2 = GrNewGC();
|
gc2 = GrNewGC();
|
gc3 = GrNewGC();
|
gc3 = GrNewGC();
|
gc4 = GrNewGC();
|
gc4 = GrNewGC();
|
|
|
GrSetGCForeground(gc1, RED);
|
GrSetGCForeground(gc1, RED);
|
GrSetGCBackground(gc1, BROWN);
|
GrSetGCBackground(gc1, BROWN);
|
GrSetGCForeground(gc2, MAGENTA);
|
GrSetGCForeground(gc2, MAGENTA);
|
GrSetGCMode(gc4, GR_MODE_XOR);
|
GrSetGCMode(gc4, GR_MODE_XOR);
|
|
|
bitmap1fg[0] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[0] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[1] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[1] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[2] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[2] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[3] = MASK(X,X,X,X,X,X,X);
|
bitmap1fg[3] = MASK(X,X,X,X,X,X,X);
|
bitmap1fg[4] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[4] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[5] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[5] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[6] = MASK(_,_,_,X,_,_,_);
|
bitmap1fg[6] = MASK(_,_,_,X,_,_,_);
|
|
|
bitmap1bg[0] = MASK(_,_,X,X,X,_,_);
|
bitmap1bg[0] = MASK(_,_,X,X,X,_,_);
|
bitmap1bg[1] = MASK(_,_,X,X,X,_,_);
|
bitmap1bg[1] = MASK(_,_,X,X,X,_,_);
|
bitmap1bg[2] = MASK(X,X,X,X,X,X,X);
|
bitmap1bg[2] = MASK(X,X,X,X,X,X,X);
|
bitmap1bg[3] = MASK(X,X,X,X,X,X,X);
|
bitmap1bg[3] = MASK(X,X,X,X,X,X,X);
|
bitmap1bg[4] = MASK(X,X,X,X,X,X,X);
|
bitmap1bg[4] = MASK(X,X,X,X,X,X,X);
|
bitmap1bg[5] = MASK(_,_,X,X,X,_,_);
|
bitmap1bg[5] = MASK(_,_,X,X,X,_,_);
|
bitmap1bg[6] = MASK(_,_,X,X,X,_,_);
|
bitmap1bg[6] = MASK(_,_,X,X,X,_,_);
|
|
|
bitmap2fg[0] = MASK(_,_,X,X,X,_,_);
|
bitmap2fg[0] = MASK(_,_,X,X,X,_,_);
|
bitmap2fg[1] = MASK(_,X,_,_,_,X,_);
|
bitmap2fg[1] = MASK(_,X,_,_,_,X,_);
|
bitmap2fg[2] = MASK(X,_,_,_,_,_,X);
|
bitmap2fg[2] = MASK(X,_,_,_,_,_,X);
|
bitmap2fg[3] = MASK(X,_,_,_,_,_,X);
|
bitmap2fg[3] = MASK(X,_,_,_,_,_,X);
|
bitmap2fg[4] = MASK(_,X,_,_,_,X,_);
|
bitmap2fg[4] = MASK(_,X,_,_,_,X,_);
|
bitmap2fg[5] = MASK(_,_,X,X,X,_,_);
|
bitmap2fg[5] = MASK(_,_,X,X,X,_,_);
|
|
|
bitmap2bg[0] = MASK(_,_,X,X,X,_,_);
|
bitmap2bg[0] = MASK(_,_,X,X,X,_,_);
|
bitmap2bg[1] = MASK(_,X,X,X,X,X,_);
|
bitmap2bg[1] = MASK(_,X,X,X,X,X,_);
|
bitmap2bg[2] = MASK(X,X,X,X,X,X,X);
|
bitmap2bg[2] = MASK(X,X,X,X,X,X,X);
|
bitmap2bg[3] = MASK(X,X,X,X,X,X,X);
|
bitmap2bg[3] = MASK(X,X,X,X,X,X,X);
|
bitmap2bg[4] = MASK(_,X,X,X,X,X,_);
|
bitmap2bg[4] = MASK(_,X,X,X,X,X,_);
|
bitmap2bg[5] = MASK(_,_,X,X,X,_,_);
|
bitmap2bg[5] = MASK(_,_,X,X,X,_,_);
|
|
|
GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg);
|
GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg);
|
GrSetCursor(w2, 7, 7, 3, 3, WHITE, BLACK, bitmap2fg, bitmap2bg);
|
GrSetCursor(w2, 7, 7, 3, 3, WHITE, BLACK, bitmap2fg, bitmap2bg);
|
|
|
while (1) {
|
while (1) {
|
GrCheckNextEvent(&event);
|
GrCheckNextEvent(&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_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_FOCUS_IN:
|
case GR_EVENT_TYPE_FOCUS_IN:
|
do_focusin(&event.general);
|
do_focusin(&event.general);
|
break;
|
break;
|
|
|
case GR_EVENT_TYPE_FOCUS_OUT:
|
case GR_EVENT_TYPE_FOCUS_OUT:
|
do_focusout(&event.general);
|
do_focusout(&event.general);
|
break;
|
break;
|
|
|
case GR_EVENT_TYPE_MOUSE_ENTER:
|
case GR_EVENT_TYPE_MOUSE_ENTER:
|
do_enter(&event.general);
|
do_enter(&event.general);
|
break;
|
break;
|
|
|
case GR_EVENT_TYPE_MOUSE_EXIT:
|
case GR_EVENT_TYPE_MOUSE_EXIT:
|
do_exit(&event.general);
|
do_exit(&event.general);
|
break;
|
break;
|
|
|
case GR_EVENT_TYPE_CLOSE_REQ:
|
case GR_EVENT_TYPE_CLOSE_REQ:
|
GrClose();
|
GrClose();
|
exit(0);
|
exit(0);
|
|
|
case GR_EVENT_TYPE_NONE:
|
case GR_EVENT_TYPE_NONE:
|
do_idle();
|
do_idle();
|
break;
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* 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)
|
{
|
{
|
GR_PIXELVAL intable[W2_WIDTH * W2_HEIGHT];
|
GR_PIXELVAL intable[W2_WIDTH * W2_HEIGHT];
|
GR_PIXELVAL outtable[W2_WIDTH * W2_HEIGHT * 6];
|
GR_PIXELVAL outtable[W2_WIDTH * W2_HEIGHT * 6];
|
GR_PIXELVAL *inp;
|
GR_PIXELVAL *inp;
|
GR_PIXELVAL *outp;
|
GR_PIXELVAL *outp;
|
GR_PIXELVAL *oldinp;
|
GR_PIXELVAL *oldinp;
|
GR_COORD row;
|
GR_COORD row;
|
GR_COORD col;
|
GR_COORD col;
|
|
|
/*static int xx = 100;
|
/*static int xx = 100;
|
static int yy = 50;*/
|
static int yy = 50;*/
|
|
|
if (bp->wid == w3) {
|
if (bp->wid == w3) {
|
GrRaiseWindow(w3);
|
GrRaiseWindow(w3);
|
GrReadArea(w2, 0, 0, W2_WIDTH, W2_HEIGHT, intable);
|
GrReadArea(w2, 0, 0, W2_WIDTH, W2_HEIGHT, intable);
|
inp = intable;
|
inp = intable;
|
outp = outtable;
|
outp = outtable;
|
for (row = 0; row < W2_HEIGHT; row++) {
|
for (row = 0; row < W2_HEIGHT; row++) {
|
oldinp = inp;
|
oldinp = inp;
|
for (col = 0; col < W2_WIDTH; col++) {
|
for (col = 0; col < W2_WIDTH; col++) {
|
*outp++ = *inp;
|
*outp++ = *inp;
|
*outp++ = *inp++;
|
*outp++ = *inp++;
|
}
|
}
|
inp = oldinp;
|
inp = oldinp;
|
for (col = 0; col < W2_WIDTH; col++) {
|
for (col = 0; col < W2_WIDTH; col++) {
|
*outp++ = *inp;
|
*outp++ = *inp;
|
*outp++ = *inp++;
|
*outp++ = *inp++;
|
}
|
}
|
inp = oldinp;
|
inp = oldinp;
|
for (col = 0; col < W2_WIDTH; col++) {
|
for (col = 0; col < W2_WIDTH; col++) {
|
*outp++ = *inp;
|
*outp++ = *inp;
|
*outp++ = *inp++;
|
*outp++ = *inp++;
|
}
|
}
|
}
|
}
|
GrArea(w1, gc1, 0, 0, W2_WIDTH * 2, W2_HEIGHT * 3, outtable,
|
GrArea(w1, gc1, 0, 0, W2_WIDTH * 2, W2_HEIGHT * 3, outtable,
|
MWPF_PIXELVAL);
|
MWPF_PIXELVAL);
|
return;
|
return;
|
}
|
}
|
|
|
if (bp->wid == w4) {
|
if (bp->wid == w4) {
|
GrRaiseWindow(w4);
|
GrRaiseWindow(w4);
|
linexpos = bp->x;
|
linexpos = bp->x;
|
lineypos = bp->y;
|
lineypos = bp->y;
|
xorxpos = bp->x;
|
xorxpos = bp->x;
|
xorypos = bp->y;
|
xorypos = bp->y;
|
GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
|
GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
|
lineok = GR_TRUE;
|
lineok = GR_TRUE;
|
return;
|
return;
|
}
|
}
|
|
|
if (bp->wid != w1) {
|
if (bp->wid != w1) {
|
/*
|
/*
|
* Cause a fatal error for testing if more than one
|
* Cause a fatal error for testing if more than one
|
* button is pressed.
|
* button is pressed.
|
*/
|
*/
|
if ((bp->buttons & -((int) bp->buttons)) != bp->buttons)
|
if ((bp->buttons & -((int) bp->buttons)) != bp->buttons)
|
GrClearWindow(-1, 0);
|
GrClearWindow(-1, 0);
|
return;
|
return;
|
}
|
}
|
|
|
GrRaiseWindow(w1);
|
GrRaiseWindow(w1);
|
/*GrMoveWindow(w1, ++xx, yy);*/
|
/*GrMoveWindow(w1, ++xx, yy);*/
|
|
|
if (bp->buttons & GR_BUTTON_L) {
|
if (bp->buttons & GR_BUTTON_L) {
|
GrClearWindow(w1, GR_TRUE);
|
GrClearWindow(w1, GR_TRUE);
|
return;
|
return;
|
}
|
}
|
|
|
begxpos = bp->x;
|
begxpos = bp->x;
|
xpos = bp->x;
|
xpos = bp->x;
|
ypos = bp->y;
|
ypos = 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)
|
{
|
{
|
if (bp->wid == w4) {
|
if (bp->wid == w4) {
|
if (lineok) {
|
if (lineok) {
|
GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
|
GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
|
GrLine(w4, gc3, bp->x, bp->y, linexpos, lineypos);
|
GrLine(w4, gc3, bp->x, bp->y, linexpos, lineypos);
|
}
|
}
|
lineok = GR_FALSE;
|
lineok = GR_FALSE;
|
return;
|
return;
|
}
|
}
|
|
|
if (bp->wid == w2) {
|
if (bp->wid == w2) {
|
GrClose();
|
GrClose();
|
exit(0);
|
exit(0);
|
}
|
}
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* 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)
|
{
|
{
|
if (mp->wid == w4) {
|
if (mp->wid == w4) {
|
if (lineok) {
|
if (lineok) {
|
GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
|
GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
|
xorxpos = mp->x;
|
xorxpos = mp->x;
|
xorypos = mp->y;
|
xorypos = mp->y;
|
GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
|
GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
|
}
|
}
|
return;
|
return;
|
}
|
}
|
|
|
if (mp->wid == w3) {
|
if (mp->wid == w3) {
|
GrPoint(w3, gc3, mp->x, mp->y);
|
GrPoint(w3, gc3, mp->x, mp->y);
|
return;
|
return;
|
}
|
}
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here when a keyboard press occurs.
|
* Here when a keyboard press occurs.
|
*/
|
*/
|
void
|
void
|
do_keystroke(GR_EVENT_KEYSTROKE *kp)
|
do_keystroke(GR_EVENT_KEYSTROKE *kp)
|
{
|
{
|
GR_SIZE width; /* width of character */
|
GR_SIZE width; /* width of character */
|
GR_SIZE height; /* height of character */
|
GR_SIZE height; /* height of character */
|
GR_SIZE base; /* height of baseline */
|
GR_SIZE base; /* height of baseline */
|
|
|
if (kp->wid == w4) {
|
if (kp->wid == w4) {
|
if (lineok) {
|
if (lineok) {
|
GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
|
GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
|
lineok = GR_FALSE;
|
lineok = GR_FALSE;
|
}
|
}
|
return;
|
return;
|
}
|
}
|
|
|
GrGetGCTextSize(gc1, &kp->ch, 1, GR_TFASCII, &width, &height, &base);
|
GrGetGCTextSize(gc1, &kp->ch, 1, GR_TFASCII, &width, &height, &base);
|
if ((kp->ch == '\r') || (kp->ch == '\n')) {
|
if ((kp->ch == '\r') || (kp->ch == '\n')) {
|
xpos = begxpos;
|
xpos = begxpos;
|
ypos += height;
|
ypos += height;
|
return;
|
return;
|
}
|
}
|
if (kp->ch == '\b') { /* assumes fixed width font!! */
|
if (kp->ch == '\b') { /* assumes fixed width font!! */
|
if (xpos <= begxpos)
|
if (xpos <= begxpos)
|
return;
|
return;
|
xpos -= width;
|
xpos -= width;
|
GrSetGCForeground(gc3, BROWN);
|
GrSetGCForeground(gc3, BROWN);
|
GrFillRect(w1, gc3, xpos, ypos - height + base + 1,
|
GrFillRect(w1, gc3, xpos, ypos - height + base + 1,
|
width, height);
|
width, height);
|
return;
|
return;
|
}
|
}
|
GrText(w1, gc1, xpos, ypos + base, &kp->ch, 1, 0);
|
GrText(w1, gc1, xpos, ypos + base, &kp->ch, 1, 0);
|
xpos += width;
|
xpos += width;
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* 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)
|
{
|
{
|
GR_POINT points[3];
|
GR_POINT points[3];
|
|
|
if (ep->wid != w1)
|
if (ep->wid != w1)
|
return;
|
return;
|
points[0].x = 311;
|
points[0].x = 311;
|
points[0].y = 119;
|
points[0].y = 119;
|
points[1].x = 350;
|
points[1].x = 350;
|
points[1].y = 270;
|
points[1].y = 270;
|
points[2].x = 247;
|
points[2].x = 247;
|
points[2].y = 147;
|
points[2].y = 147;
|
|
|
GrFillRect(w1, gc2, 50, 50, 150, 200);
|
GrFillRect(w1, gc2, 50, 50, 150, 200);
|
GrFillPoly(w1, gc2, 3, points);
|
GrFillPoly(w1, gc2, 3, points);
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here when a focus in event occurs.
|
* Here when a focus in event occurs.
|
*/
|
*/
|
void
|
void
|
do_focusin(GR_EVENT_GENERAL *gp)
|
do_focusin(GR_EVENT_GENERAL *gp)
|
{
|
{
|
if (gp->wid != w1)
|
if (gp->wid != w1)
|
return;
|
return;
|
GrSetBorderColor(w1, WHITE);
|
GrSetBorderColor(w1, WHITE);
|
}
|
}
|
|
|
/*
|
/*
|
* Here when a focus out event occurs.
|
* Here when a focus out event occurs.
|
*/
|
*/
|
void
|
void
|
do_focusout(GR_EVENT_GENERAL *gp)
|
do_focusout(GR_EVENT_GENERAL *gp)
|
{
|
{
|
if (gp->wid != w1)
|
if (gp->wid != w1)
|
return;
|
return;
|
GrSetBorderColor(w1, GRAY);
|
GrSetBorderColor(w1, GRAY);
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here when a enter window event occurs.
|
* Here when a enter window event occurs.
|
*/
|
*/
|
void
|
void
|
do_enter(GR_EVENT_GENERAL *gp)
|
do_enter(GR_EVENT_GENERAL *gp)
|
{
|
{
|
if (gp->wid != w5)
|
if (gp->wid != w5)
|
return;
|
return;
|
GrSetBorderColor(w5, WHITE);
|
GrSetBorderColor(w5, WHITE);
|
GrRaiseWindow(w5);
|
GrRaiseWindow(w5);
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here when a exit window event occurs.
|
* Here when a exit window event occurs.
|
*/
|
*/
|
void
|
void
|
do_exit(GR_EVENT_GENERAL *gp)
|
do_exit(GR_EVENT_GENERAL *gp)
|
{
|
{
|
if (gp->wid != w5)
|
if (gp->wid != w5)
|
return;
|
return;
|
GrSetBorderColor(w5, GREEN);
|
GrSetBorderColor(w5, GREEN);
|
GrLowerWindow(w5);
|
GrLowerWindow(w5);
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here to do an idle task when nothing else is happening.
|
* Here to do an idle task when nothing else is happening.
|
* Just draw a randomly colored filled circle in the small window.
|
* Just draw a randomly colored filled circle in the small window.
|
*/
|
*/
|
void
|
void
|
do_idle(void)
|
do_idle(void)
|
{
|
{
|
GR_COORD x;
|
GR_COORD x;
|
GR_COORD y;
|
GR_COORD y;
|
GR_SIZE rx;
|
GR_SIZE rx;
|
GR_SIZE ry;
|
GR_SIZE ry;
|
GR_COLOR color;
|
GR_COLOR color;
|
|
|
x = rand() % 70;
|
x = rand() % 70;
|
y = rand() % 40;
|
y = rand() % 40;
|
rx = (rand() % 10) + 5;
|
rx = (rand() % 10) + 5;
|
ry = (rx * si.ydpcm) / si.xdpcm; /* make it appear circular */
|
ry = (rx * si.ydpcm) / si.xdpcm; /* make it appear circular */
|
|
|
color = rand() % si.ncolors;
|
color = rand() % si.ncolors;
|
|
|
GrSetGCForeground(gc3, MWPALINDEX(color));
|
GrSetGCForeground(gc3, MWPALINDEX(color));
|
GrFillEllipse(w2, gc3, x, y, rx, ry);
|
GrFillEllipse(w2, gc3, x, y, rx, ry);
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Here on a server error. Print the std message but don't exit.
|
* Here on a server error. Print the std message but don't exit.
|
*/
|
*/
|
void
|
void
|
errorcatcher(GR_EVENT *ep)
|
errorcatcher(GR_EVENT *ep)
|
{
|
{
|
printf("nxclient: Error (%s) ", ep->error.name);
|
printf("nxclient: Error (%s) ", ep->error.name);
|
printf(nxErrorStrings[ep->error.code], ep->error.id);
|
printf(nxErrorStrings[ep->error.code], ep->error.id);
|
}
|
}
|
|
|