Example #1
0
void ExceptionExit(int sig)
{
    closeLeds();
    printf("ExceptionExit(%d)", sig);
    GrClose();
    exit(0);
}
Example #2
0
int
main(int argc, char **argv)
{
	int COLS, ROWS;

	if (GrOpen() < 0) {
		GrError("Cannot open graphics\n");
		return 1;
	}

	COLS = 350;
	ROWS = 300;

	g_main = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "dashdemo",
		GR_ROOT_WINDOW_ID, 100, 50, COLS - 120, ROWS - 60, BLUE);

	GrSelectEvents(g_main, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
	GrMapWindow(g_main);

	while (1) {
		GR_EVENT event;
		GrGetNextEvent(&event);

		switch (event.type) {
		case GR_EVENT_TYPE_EXPOSURE:
			draw_screen();
			break;

		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			return 0;
		}
	}
}
Example #3
0
static void
pexit(char *why)
{
    printf("Image demo thread exiting - %s\n", why);
    GrClose();
    cyg_thread_exit();
}
Example #4
0
static void
checkevent(void)
{
	GR_EVENT	event;

	GrGetNextEvent(&event);
	switch (event.type) {
		case GR_EVENT_TYPE_EXPOSURE:
			doexposure(&event.exposure);
			break;
		case GR_EVENT_TYPE_BUTTON_DOWN:
			dobuttondown(&event.button);
			break;
		case GR_EVENT_TYPE_BUTTON_UP:
			dobuttonup(&event.button);
			break;
		case GR_EVENT_TYPE_MOUSE_POSITION:
			doposition(&event.mouse);
			break;
		case GR_EVENT_TYPE_KEY_DOWN:
			dokeydown(&event.keystroke);
			break;
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			exit(0);
	}
}
Example #5
0
void
HandleEvent(GR_EVENT *ep)
{
	switch (ep->type) {
		case GR_EVENT_TYPE_KEY_DOWN:
			do_keystroke(&ep->keystroke);
			break;

		case GR_EVENT_TYPE_FOCUS_IN:
			do_focusin(&ep->general);
			break;

		case GR_EVENT_TYPE_FOCUS_OUT:
			do_focusout(&ep->general);
			break;

		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			exit(0);

		case GR_EVENT_TYPE_FDINPUT:
			do_fdinput();
			break;
	}
}
Example #6
0
/*
 * Initialize graphics and open a window for the viewer
 */
Bool
CreateXWindow(void)
{
    int fd;
    GR_SIZE w, h;
    GR_SCREEN_INFO si;

    if ((fd = GrOpen()) < 0)
        return(False);
    nx_dpy.fd = fd;
    dpy = &nx_dpy;

    GrGetScreenInfo(&si);
    /* pass screen details to RFB handler */
    myFormat.bitsPerPixel = si.bpp;
    myFormat.depth = si.bpp;	/* is this right? */
    myFormat.bigEndian = 0;		/* how do I find this out? */
    myFormat.trueColour = (myFormat.depth == 8 && !useBGR233) ? 0 : 1;
    if (myFormat.trueColour) {
        myFormat.redMax = myFormat.greenMax = 7;
        myFormat.blueMax = 3;
        myFormat.redShift = 0;
        myFormat.greenShift = 3;
        myFormat.blueShift = 6;
    }
    pixtype = si.pixtype;
    /* get the initial server palette */
    GrGetSystemPalette(&srv_pal);
#if 0
    /* DEBUG */
    for (i = 0; i < srv_pal.count; i++) {
        printf("0x%02x  %03d  %03d  %03d\n", i, \
               srv_pal.palette[i].r, srv_pal.palette[i].g, \
               srv_pal.palette[i].b );
    }
#endif
    /* create the top-level window */
    w = (VW_WIDTH > (si.cols - VW_X)) ? (si.cols - VW_X) : VW_WIDTH;
    h = (VW_HEIGHT > (si.rows - VW_Y)) ? (si.rows - VW_Y) : VW_HEIGHT;
    if ((wid = GrNewWindow(GR_ROOT_WINDOW_ID, VW_X, VW_Y, w, h,
                           2, LTGRAY, BLACK)) == 0) {
        fprintf(stderr, "Unable to create top-level window\n");
        GrClose();
        return False;
    }
    /* select events to receive */
    GrSelectEvents(wid, GR_EVENT_MASK_BUTTON_DOWN |
                   GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_KEY_DOWN |
                   GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_MOUSE_POSITION);
    /* make thw window visible */
    GrMapWindow(wid);
    canvas = wid;
    /* create the graphics contexts */
    gc = GrNewGC();
    srcGC = GrNewGC();
    dstGC = GrNewGC();

    return True;
}
Example #7
0
// Microwin driver bootstrap functions
static int NX_Available ()
{
    Dprintf ("enter NX_Available\n") ;

    if (GrOpen () < 0) return 0 ;
        GrClose () ;
    
    Dprintf ("leave NX_Available\n") ;
    return 1 ;
}
Example #8
0
/* 
 * The default error handler which is called when the server
 * reports an error event and the client hasn't set a handler for error events.
 */
void 
GrDefaultErrorHandler(GR_EVENT *ep)
{
	if (ep->type == GR_EVENT_TYPE_ERROR) {
		EPRINTF("nxclient: Error (%s) ", ep->error.name);
		EPRINTF(nxErrorStrings[ep->error.code], ep->error.id);
		GrClose();
		exit(1);
	}
}
Example #9
0
int main(int argc, char *argv[])
{
	nstate *state = my_malloc(sizeof(nstate));

	init_game(state);
	main_game_loop(state);

	write_hiscore(state);

	GrClose();

	return 0;
}
Example #10
0
void event_handler (GR_EVENT *event)
{
    switch (event->type)
    {
    case GR_EVENT_TYPE_EXPOSURE:
        GrText (wid, gc, 50, 50, "Hello World",  -1, GR_TFASCII);
        break;

    case GR_EVENT_TYPE_CLOSE_REQ:
        GrClose();
        exit (0);
    }
} 
Example #11
0
int start(int argc, char **argv)
{
	GR_EVENT event;
	nxeyes_state *state;

	if(GrOpen() < 0) {
		printf("Couldn't connect to Nano-X server\n");
		return 1;
	}

	if(!(state = init())) {
		printf("Couldn't allocate state structure\n");
		return 1;
	}

	while(!state->quit) {
		GrGetNextEvent(&event);
		switch(event.type) {
			case GR_EVENT_TYPE_CLOSE_REQ:
				state->quit = 1;
				break;
			case GR_EVENT_TYPE_MOUSE_POSITION:
				position_event(&event.mouse, state);
				break;
			case GR_EVENT_TYPE_BUTTON_UP:
			case GR_EVENT_TYPE_BUTTON_DOWN:
				button_event(&event.button, state);
				break;
			case GR_EVENT_TYPE_EXPOSURE:
				draw_eyes(state, 1);
				break;
#if MW_FEATURE_TIMERS
			case GR_EVENT_TYPE_TIMER:
				timer_event(&event.timer, state);
				break;
#endif
			default:
				break;
		}
		if(state->mouse_moved) {
			draw_eyes(state, 0);
			state->mouse_moved = 0;
		}
	}

	GrClose();
	free(state);
	
	return 0;
}
Example #12
0
int
main(int ac, char **av)
{
    GR_EVENT event;
    GR_GC_ID gc;
    GR_WINDOW_ID pmap;
    GR_WINDOW_ID window;
    GR_WINDOW_INFO info;

    if (GrOpen() < 0) {
	fprintf(stderr, "cannot open graphics\n");
	exit(1);
    }

    window = nxCreateAppWindow(&ac, &av, args);
    gc = GrNewGC();
    GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_WINDOW));
    GrSetGCBackground(gc, GrGetSysColor(GR_COLOR_WINDOWTEXT));

    GrSelectEvents(window, GR_EVENT_MASK_EXPOSURE |
		   GR_EVENT_MASK_UPDATE | GR_EVENT_MASK_CLOSE_REQ);

    GrGetWindowInfo(window, &info);
    pmap = resize(info.width, info.height, 0);

    GrMapWindow(window);

    while (1) {
	GrGetNextEventTimeout(&event, 500L);

	switch (event.type) {
	case GR_EVENT_TYPE_EXPOSURE:
	case GR_EVENT_TYPE_TIMEOUT:
	    draw_clock(0, 0, width, height, pmap, gc, window);
	    break;

	case GR_EVENT_TYPE_CLOSE_REQ:
	    GrClose();
	    exit(0);

	case GR_EVENT_TYPE_UPDATE:
	    switch (event.update.utype) {
	    case GR_UPDATE_SIZE:
		pmap = resize(event.update.width, event.update.height, pmap);
		break;
	    }
	}
    }
    return 0;
}
Example #13
0
void
SigHandler(int sig)
{
    /*
       If we are blocked, no roaches are visible and we can just bail
       out.  If we are not blocked, then let the main procedure clean
       up the root window.
    */
    if (eventBlock) {
	GrClose();
	exit(0);
    }
    else {
	done = GR_TRUE;
    }
}
Example #14
0
int main()
{
	GR_SCREEN_INFO  si;
	GR_FONT_INFO    fi;
	GR_GC_INFO      gi;
	GR_FONT         fonts;
	int             x, y;

	GrOpen();
	GrGetScreenInfo(&si);

	printf("rows = %d\n", si.rows);
	printf("cols = %d\n", si.cols);
	printf("bpp = %d\n", si.bpp);
	printf("planes = %d\n", si.planes);
	printf("ncolors = %d\n", si.ncolors);
	printf("buttons = 0x%x\n", si.buttons);
	printf("modifiers = 0x%x\n", si.modifiers);
	printf("fonts = %d\n", si.fonts);

	getch();

	for(fonts = 0; fonts < si.fonts; fonts++) {
/*		if(!GrGetFontInfo(fonts, &fi)) { */
		GrGetFontInfo(fonts, &fi);
		if(1) {
			printf("\nfont = %d\n", fi.font);
			printf("height = %d\n", fi.height);
			printf("maxwidth = %d\n", fi.maxwidth);
			printf("baseline = %d\n", fi.baseline);
			printf("fixed = %s\n", fi.fixed ? "TRUE" : "FALSE");
			printf("widths =\n");
			for(y = 0; y != 3; y++) {
				for(x = 0; x != 7; x++)
					printf("%2d", fi.widths[x * y]);
				printf("\n");

				getch();

			}
		}
	}

	getch();

	GrClose();
}
Example #15
0
int main(int argc, char *argv[])
{
	lstate *state;

	if(argc != 2) usage();

	state = my_malloc(sizeof(lstate));
	state->config_file = strdup(argv[1]);

	initialise(state);

	do_event_loop(state);

	GrClose();

	return 0;
}
Example #16
0
/*
 * Here when a button is released.
 */
void
do_buttonup(GR_EVENT_BUTTON	*bp)
{
	if (bp->wid == w4) {
		if (lineok) {
			GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
			GrLine(w4, gc3, bp->x, bp->y, linexpos, lineypos);
		}
		lineok = GR_FALSE;
		return;
	}

	if (bp->wid == w2) {
		GrClose();
		exit(0);
	}
}
Example #17
0
//------------------------------------------------------------------------------
// Function Name  : init_ui_manager()
// Description    : 
//------------------------------------------------------------------------------
BOOL init_ui_manager(void)
{
	CObject* pObject;
	UINT id;

	PRINT_FUNC_CO();
	
	// start nano-x service
	if (GrOpen() < 0) {
	//	DBGMSG(DBG_MAIN, "[Failure]\r\n--> %s: GrOpen Failed!!\r\n", __func__);
		return FALSE;
	}

	GrSetErrorHandler(error_handler);
	GrGetScreenInfo(&g_scr_info);

	// prepare g_font
	g_font = GrCreateFontEx((GR_CHAR *)FONT_PATH, 18, 18, NULL);
	GrSetFontAttr(g_font, (GR_TFKERNING | GR_TFANTIALIAS), 0);

	g_wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, g_scr_info.cols, g_scr_info.rows, 0, BLACK, 0);
	if (g_wid == 0) {
	//	DBGMSG(DBG_MAIN, "[Failure]\r\n--> %s: GrNewWindow failure\r\n", __func__);
		GrClose();
		return FALSE;
	}

	g_gc = GrNewGC();

	GrRaiseWindow(g_wid);
	GrMapWindow(g_wid);

	GrSelectEvents(g_wid, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_EXPOSURE);

	GrSetGCUseBackground(g_gc, FALSE);
//	GrSetGCUseBackground(g_gc, TRUE);
	GrSetGCFont(g_gc, g_font);

//	GrSetGCBackground(g_gc, BLACK);
	GrSetGCForeground(g_gc, WHITE);

//	BuildObject();

	return TRUE;
}
Example #18
0
/*
 * Here when a button is released.
 */
void
do_buttonup(GR_EVENT_BUTTON	*bp)
{
	if (bp->wid == w4) {
		if (lineok) {
			GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos);
			GrLine(w4, gc3, bp->x, bp->y, linexpos, lineypos);
		}
		lineok = GR_FALSE;
	        GrCopyArea(w1, gc4, 200,200, 200,200, p1,0,0,MWROP_COPY);
		return;
	}

	if (bp->wid == w2) {
		GrClose();
		exit(0);
	}
}
Example #19
0
File: demo2.c Project: Mellvik/elks
int main()
{
	GR_WINDOW_ID 	window;
	GR_EVENT 	event;

	if (GrOpen() < 0) {
		fprintf(stderr, "cannot open graphics\n");
		exit(1);
	}

	window = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 20, 100, 60, 4, WHITE, BLUE);

	GrMapWindow(window);

	while(1)
		GrCheckNextEvent(&event);

	GrClose();
}
Example #20
0
/*
 * Here when we get a button down event.
 */
static void
dobutton(GR_EVENT_BUTTON *bp)
{
    if (bp->wid == boardwid) {
        movetopos(findcell(bp->x, bp->y));
        return;
    }

    if (bp->wid == quitwid) {
        GrFillRect(quitwid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        if (savefile)
            writegame(savefile);
        GrClose();
        exit(0);
    }

    if (bp->wid == savewid) {
        GrFillRect(savewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        if (savefile == NULL)
            savefile = SAVEFILE;
        if (writegame(savefile))
            write(1, "\007", 1);
        else
            delay();
        GrFillRect(savewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
    }

    if (bp->wid == newgamewid) {
        GrFillRect(newgamewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        /*if (playing)
        	write(1, "\007", 1);
        else {*/
        newgame();
        delay();
        /*}*/
        GrFillRect(newgamewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
    }
}
Example #21
0
/*
 * Read the next event and handle it.
 */
static void
handleevent(GR_EVENT *ep)
{
    switch (ep->type) {
    case GR_EVENT_TYPE_BUTTON_DOWN:
        dobutton(&ep->button);
        break;

    case GR_EVENT_TYPE_EXPOSURE:
        doexposure(&ep->exposure);
        break;

    case GR_EVENT_TYPE_KEY_DOWN:
        dokey(&ep->keystroke);
        break;

    case GR_EVENT_TYPE_CLOSE_REQ:
        GrClose();
        exit(0);
    }
}
Example #22
0
int
main(int argc, char **argv)
{
	int COLS, ROWS;

	if (GrOpen() == -1)
		exit(1);

	COLS = 480;
	ROWS = 300;

	load_pixmap();

	g_main = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "tsdemo",
		    GR_ROOT_WINDOW_ID, 100, 50, COLS - 120, ROWS - 60, GRAY);

	GrSelectEvents(g_main,
		       GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ);
	GrMapWindow(g_main);

	while (1) {
		GR_EVENT event;

		GrGetNextEvent(&event);

		switch (event.type) {
		case GR_EVENT_TYPE_EXPOSURE:
			g_x = 5;
			draw_set("GR_FILL_STIPPLE", GR_FILL_STIPPLE);
			draw_set("GR_FILL_OPAQUE_STIPPLE", GR_FILL_OPAQUE_STIPPLE);
			draw_set("GR_FILL_TILE", GR_FILL_TILE);
			break;

		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			exit(0);
		}
	}
}
Example #23
0
int main(int argc, char **argv)
{
	GR_WINDOW_ID wid;
	GR_GC_ID gc[NUMGCS];
	GR_EVENT event;

	if(GrOpen() < 0) {
		fprintf(stderr, "Couldn't connect to the Nano-X server\n");
		return 1;
	}

	wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "rgndemo",
		GR_ROOT_WINDOW_ID, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,
		GR_COLOR_GRAY80);

	GrSelectEvents(wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE);

	gc[0] = setup_single_rect_region();
	gc[1] = setup_multi_rect_region();
	gc[2] = setup_simple_poly_region();
	gc[3] = setup_bitmap_region();
	gc[4] = setup_complex_poly_region();

	GrMapWindow(wid);

	while(1) {
		GrGetNextEvent(&event);
		switch(event.type) {
			case GR_EVENT_TYPE_EXPOSURE:
				redraw(wid, gc);
				break;
			case GR_EVENT_TYPE_CLOSE_REQ:
				GrClose();
				return 0;
			default:
				break;
		}
	}
}
Example #24
0
void NX_VideoQuit (_THIS)
{
    Dprintf ("enter NX_VideoQuit\n") ;

    // Start shutting down the windows
    NX_DestroyImage (this, this -> screen) ;
    NX_DestroyWindow (this, this -> screen) ;
    if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) {
        GrDestroyWindow (FSwindow) ;
    }
    NX_FreeVideoModes (this) ;
    free (GammaRamp_R) ;
    free (GammaRamp_G) ;
    free (GammaRamp_B) ;

#ifdef ENABLE_NANOX_DIRECT_FB
    if (Clientfb)
        GrCloseClientFramebuffer();
#endif
    GrClose () ;

    Dprintf ("leave NX_VideoQuit\n") ;
}
Example #25
0
static void
dokeydown(GR_EVENT_KEYSTROKE *kp)
{
	if (kp->wid != mapwid)
		return;

	if (selectmode != SELECT_NONE) {
		switch (kp->ch) {
			case 's':	/* scale selection */
				selectmode = SELECT_SCALE;
				break;

			case 'm':	/* move selection */
				selectmode = SELECT_MOVE;
				break;

			case '\033':	/* cancel selection */
				showselection(GR_FALSE);
				selectmode = SELECT_NONE;
				break;
		}
		return;
	}

	switch (kp->ch) {
		case 'q':		/* quit */
		case 'Q':
			GrClose();
			exit(0);

		case 't':		/* redraw total map */
			Longitude = ITOF(0);
			Latitude = ITOF(0);
			setzoom(ITOF(1));
			GrClearWindow(mapwid, GR_TRUE);
	}
}
Example #26
0
int main(void)
{
    GR_WINDOW_ID wid;
    GR_GC_ID gc;
    GR_EVENT event;

    if(GrOpen() < 0) {
        fprintf(stderr, "Couldn't connect to the Nano-X server\n");
        return 1;
    }

    wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, BITMAPWIDTH, BITMAPHEIGHT,
                      0, GR_COLOR_WHITE, 0);

    GrSelectEvents(wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE);

    gc = GrNewGC();
    GrSetGCForeground(gc, GR_COLOR_BLACK);
    GrSetGCBackground(gc, GR_COLOR_WHITE);

    GrMapWindow(wid);

    while(1) {
        GrGetNextEvent(&event);
        switch(event.type) {
        case GR_EVENT_TYPE_EXPOSURE:
            redraw(wid, gc);
            break;
        case GR_EVENT_TYPE_CLOSE_REQ:
            GrClose();
            return 0;
        default:
            break;
        }
    }
}
Example #27
0
static void
GrCloseWrapper(void *r)
{
	GrClose();
}
Example #28
0
/*
 * Read the next event and handle it.
 */
static void
HandleEvents(GR_EVENT *ep)
{
int hole_x_pos, hole_y_pos;
int tempx, tempy;

	switch (ep->type) {
		case GR_EVENT_TYPE_BUTTON_DOWN:
			if (ep->button.wid == buttons) {
 				if (ep->button.x < (calc_width/2)) {
					/* 'Again' */
					RandomiseTiles();
					RefreshWindow();
 				} else {
					/* 'Quit' */
					GrClose();
#if USE_IMAGE
					if (using_image)
						free(image_addr);
#endif
					exit(0);
				}
			}

			if (ep->button.wid == tiles) {
				/* Try to move selected tile */
				MoveTile( (int)(ep->button.x / tile_width),
					(int)(ep->button.y / tile_height) );
			}
			break;

		case GR_EVENT_TYPE_KEY_DOWN:
			if (ep->keystroke.wid == master) {
				hole_x_pos = 0;
				hole_y_pos = 0;

				/* Find hole position */
				for (tempx = 0; tempx < WIDTH_IN_TILES; tempx++)
					for (tempy = 0; tempy < HEIGHT_IN_TILES; tempy++)
						if (value[tempx][tempy] == MAX_TILES) {
							hole_x_pos = tempx;
							hole_y_pos = tempy;
						}
	
				switch (ep->keystroke.ch) {
					case 'q':
					case 'Q':
					case MWKEY_CANCEL:
						GrClose();
#if USE_IMAGE
						if (using_image)
							free(image_addr);
#endif
						exit(0);

					case 'r':
					case 'R':
						RandomiseTiles();
						RefreshWindow();
						break;

					/* remember you are moving the tile. not the hole */
					case MWKEY_DOWN:
						if (hole_y_pos != 0) {
							MoveTile(hole_x_pos, hole_y_pos - 1);
						}
						break;
							
					case MWKEY_UP:
						if (hole_y_pos != (HEIGHT_IN_TILES-1) ) {
							MoveTile(hole_x_pos, hole_y_pos + 1);
						}
						break;

					case MWKEY_RIGHT:
						if (hole_x_pos != 0) {
							MoveTile(hole_x_pos - 1, hole_y_pos);
						}
						break;

					case MWKEY_LEFT:
						if (hole_x_pos != (WIDTH_IN_TILES-1) ) {
							MoveTile(hole_x_pos + 1, hole_y_pos);
						}
						break;
				}
			}
			break;

		case GR_EVENT_TYPE_EXPOSURE:
			RefreshWindow();
			break;
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			exit(0);
	}

}
Example #29
0
int
ui_loop(int argc, char **argv, const char *name) {
	GR_EVENT	event;		/* current event */
	GR_IMAGE_ID	id = 0;
	NGLXContext cx;
	int width, height, k;

	if (GrOpen() < 0) {
		fprintf(stderr, "cannot open graphics\n");
		exit(1);
	}

	width = 400;
	height = 300;

	GrSetErrorHandler(errorcatcher);

	w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, width, height, 4, BLACK, WHITE);

	GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_KEY_DOWN);

	GrMapWindow(w1);

	gc1 = GrNewGC();

	GrSetGCForeground(gc1, WHITE);

	cx = nglXCreateContext(NULL, 0);
	nglXMakeCurrent(w1, cx);

	init();
	reshape(width, height);

	while (1) {
		GrCheckNextEvent(&event);

		switch (event.type) {
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrFreeImage(id);
			GrClose();
			exit(0);

		case GR_EVENT_TYPE_EXPOSURE:
			break;

		case GR_EVENT_TYPE_KEY_DOWN: {
			GR_EVENT_KEYSTROKE *kp = &event.keystroke;

			/* XXX: nanoX special keys are totally bugged ! */
			switch (kp->ch) {
			case 81:
				k = KEY_LEFT;
				break;

			case 83:
				k = KEY_RIGHT;
				break;

			case 82:
				k = KEY_UP;
				break;

			case 84:
				k = KEY_DOWN;
				break;

			default:
				k = kp->ch;
				break;
			}

			key(k, 0);
		}
		break;

		default:
			idle();
			break;
		}
	}

	return 0;
}
Example #30
0
/* ***********************************************************/
int main(int argc, char* argv[])
{
        GR_EVENT event;
	GR_WM_PROPERTIES props;

	int computer_side;
	char s[256];
	int i;
	BOOL found;
	char temp[50];	

        if (GrOpen() < 0) {
                fprintf(stderr, "tuxchess: cannot open graphics\n");
                exit(1);
        }

	load_images();

        master = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, BM_WIDTH, BM_HEIGHT, 0, WHITE, WHITE);
        board = GrNewWindow((GR_WINDOW_ID) master, 0, 0, 394, 394, 0, WHITE, WHITE);
        text = GrNewWindow((GR_WINDOW_ID) master, 0, 393, 394, 20, 0, BLACK, BLACK); 

        GrSelectEvents(master, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN);

	props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE;
	props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION | GR_WM_PROPS_CLOSEBOX;
	props.title = TITLE;
	GrSetWMProperties(master, &props);

	/* eliminate white background*/
	props.flags = GR_WM_FLAGS_PROPS;
	props.props = GR_WM_PROPS_NOBACKGROUND;
	GrSetWMProperties(board, &props);

        GrMapWindow(master);
        GrMapWindow(board);
        GrMapWindow(text);
                                   
        gc = GrNewGC();
        text_gc = GrNewGC();

	init();
	gen();
	max_time = 1 << 25;
	max_depth = 4;

	if (argc > 1)
		computer_side = side;	/* computer plays white */
	else
	{
		computer_side = EMPTY;	/* human plays white */
		gprintf("Make a move...");
	}

        for (;;) 
	{

		if (side == computer_side) 
		{
			/* think about the move and make it */
			think(0);
			if (!pv[0][0].u) {
				gprintf("No legal moves");
				computer_side = EMPTY;
				continue;
			}
			
			sprintf(temp,"Computer's move: %s\n", move_str(pv[0][0].b));
			gprintf(temp);
			makemove(pv[0][0].b);
			ply = 0;
			gen();
			print_board();
			print_result();
			continue;
		}
		
                GrGetNextEvent(&event);
                switch(event.type) 
		{
			case GR_EVENT_TYPE_CLOSE_REQ:
				GrClose();
				exit(0);
				/* no return*/
			case GR_EVENT_TYPE_EXPOSURE:
				print_board();
				gprintf(NULL);
				break;
			case GR_EVENT_TYPE_BUTTON_DOWN:
				mouse_hit(event.button.x, event.button.y);
				break;
		}

		if (to != 999)
		{

			/* loop through the moves to see if it's legal */
			found = FALSE;
			for (i = 0; i < first_move[1]; ++i)
				if (gen_dat[i].m.b.from == from && gen_dat[i].m.b.to == to) 
				{
					found = TRUE;

					/* get the promotion piece right */
					if (gen_dat[i].m.b.bits & 32)
						switch (s[4]) 
						{
							case 'N':
								break;
							case 'B':
								i += 1;
								break;
							case 'R':
								i += 2;
								break;
							default:
								i += 3;
								break;
						}
					break;
				} /* if */

			if (!found || !makemove(gen_dat[i].m.b))
				gprintf("Illegal move.\n");
			else 
			{
				ply = 0;
				gen();
				print_board();
				print_result();
				computer_side = side;
				to = 999;
			}
		} /* if to != 999 */
	} /* for (;;) */

	return(0); /* never reached */
}