예제 #1
0
struct menulist *new_ml()
{
	struct menulist *ret =
		(struct menulist *) malloc(sizeof(struct menulist));
		
	GrGetScreenInfo(&ret->screen_info);

	ret->gc = pz_get_gc(1);
	GrSetGCUseBackground(ret->gc, GR_FALSE);
	GrSetGCForeground(ret->gc, BLACK);
	GrSetGCBackground(ret->gc, BLACK);

	ret->wid = pz_new_window(0, HEADER_TOPLINE + 1, ret->screen_info.cols,
			ret->screen_info.rows - (HEADER_TOPLINE + 1),
			itunes_do_draw, itunes_do_keystroke);

	GrSelectEvents(ret->wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_KEY_DOWN|GR_EVENT_MASK_KEY_UP|GR_EVENT_MASK_TIMER);

	GrGetGCTextSize(ret->gc, "M", -1, GR_TFASCII, &ret->gr_width,
			&ret->gr_height, &ret->gr_base);

	ret->gr_height += 4;

	GrMapWindow(ret->wid);
	ret->itunes_menu = menu_init(ret->wid, "Music", 0, 0,
			screen_info.cols, screen_info.rows -
			(HEADER_TOPLINE + 1), NULL, NULL, UTF8);
	ret->init = 0;
	ret->prevml = NULL;

	return ret;
}
예제 #2
0
int NX_VideoInit (_THIS, SDL_PixelFormat * vformat)
{
    GR_SCREEN_INFO si ;

    Dprintf ("enter NX_VideoInit\n") ;
    
    if (GrOpen () < 0) {
        SDL_SetError ("GrOpen() fail") ;
        return -1 ;
    }

    // use share memory to speed up
#ifdef NANOX_SHARE_MEMORY
    GrReqShmCmds (0xFFFF);
#endif

    SDL_Window = 0 ;
    FSwindow = 0 ;

    GammaRamp_R = NULL ;
    GammaRamp_G = NULL ;
    GammaRamp_B = NULL ;    

    GrGetScreenInfo (& si) ;
    SDL_Visual.bpp = si.bpp ;

    // GetVideoMode
    SDL_modelist = (SDL_Rect **) malloc (sizeof (SDL_Rect *) * 2) ;
    if (SDL_modelist) {
        SDL_modelist [0] = (SDL_Rect *) malloc (sizeof(SDL_Rect)) ;
        if (SDL_modelist [0]) {
            SDL_modelist [0] -> x = 0 ;
            SDL_modelist [0] -> y = 0 ;
            SDL_modelist [0] -> w = si.cols ;
            SDL_modelist [0] -> h = si.rows ;
        }
        SDL_modelist [1] = NULL ;
    }

    pixel_type = si.pixtype;
    SDL_Visual.red_mask = si.rmask;
    SDL_Visual.green_mask = si.gmask;
    SDL_Visual.blue_mask = si.bmask;

    vformat -> BitsPerPixel = SDL_Visual.bpp ;
    if (vformat -> BitsPerPixel > 8) {
        vformat -> Rmask = SDL_Visual.red_mask ;
        vformat -> Gmask = SDL_Visual.green_mask ;
        vformat -> Bmask = SDL_Visual.blue_mask ;
    }

    // See if we have been passed a window to use
    SDL_windowid = getenv ("SDL_WINDOWID") ;
    
    // Create the fullscreen (and managed windows : no implement)
    create_aux_windows (this) ;

    Dprintf ("leave NX_VideoInit\n") ;
    return 0 ;
}
예제 #3
0
파일: widget.c 프로젝트: cgbarnwell/mvpmc
int
mvpw_init(void)
{
	GR_SCREEN_INFO si;

	if (GrOpen() < 0)
		return -1;

	GrGetScreenInfo(&si);

	root = malloc(sizeof(*root));
	memset(root, 0, sizeof(*root));

	root->type = MVPW_ROOT;
	root->wid = GR_ROOT_WINDOW_ID;
	root->width = si.cols;
	root->height = si.rows;
	add_widget(root);

	GrSetWindowBackgroundColor(GR_ROOT_WINDOW_ID, 0);

	root->event_mask = GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_TIMER |
		GR_EVENT_MASK_SCREENSAVER | GR_EVENT_MASK_FDINPUT;
	GrSelectEvents(GR_ROOT_WINDOW_ID, root->event_mask);

	return 0;
}
예제 #4
0
// Update the current mouse state and position
static void NX_UpdateMouse (_THIS)
{
    int            x, y ;
    GR_WINDOW_INFO info ;
    GR_SCREEN_INFO si ;


    Dprintf ("enter NX_UpdateMouse\n") ;

    // Lock the event thread, in multi-threading environments
    SDL_Lock_EventThread () ;
    
    GrGetScreenInfo (& si) ;
    GrGetWindowInfo (SDL_Window, & info) ;
    x = si.xpos - info.x ;
    y = si.ypos - info.y ;
    if (x >= 0 && x <= info.width && y >= 0 && y <= info.height) {
        SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ;
        SDL_PrivateMouseMotion (0, 0, x, y);
    } else {
        SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ;
    }

    SDL_Unlock_EventThread () ;
    Dprintf ("leave NX_UpdateMouse\n") ;
}
예제 #5
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;
}
예제 #6
0
static void
GrGetScreenInfoWrapper(void *r)
{
	GR_SCREEN_INFO si;

	GrGetScreenInfo(&si);
	GsWriteType(current_fd,GrNumGetScreenInfo);
	GsWrite(current_fd, &si, sizeof(si));
}
예제 #7
0
파일: widget.c 프로젝트: cgbarnwell/mvpmc
void
mvpw_get_screen_info(mvpw_screen_info_t *info)
{
	GR_SCREEN_INFO si;

	GrGetScreenInfo(&si);

	info->cols = si.cols;
	info->rows = si.rows;
	info->bpp  = si.bpp;
	info->pixtype = si.pixtype;
}
예제 #8
0
nxeyes_state *init(void)
{
	nxeyes_state *state;
	GR_REGION_ID rid1, rid2;
	GR_SCREEN_INFO si;
	GR_WM_PROPERTIES props;

	if(!(state = malloc(sizeof(nxeyes_state)))) return NULL;
	state->oldx = state->oldy = state->x = state->y = 0;
	state->button_down = state->eyes_closed = state->quit = 0;
	state->olx = state->orx = EYEMASK_WIDTH / 2;
	state->oly = state->ory = EYEMASK_HEIGHT / 2;
	GrGetScreenInfo(&si);
	state->mousex = si.xpos;
	state->mousey = si.ypos;
	state->mouse_moved = 1;
	state->gc = GrNewGC();
	GrSetGCForeground(state->gc, GR_COLOR_WHITE);
	GrSetGCBackground(state->gc, GR_COLOR_BLACK);

	state->wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, (EYEFG_HEIGHT * 2) +
			EYE_SPACING, EYEFG_HEIGHT, 0, GR_COLOR_WHITE, 0);

	rid1 = GrNewBitmapRegion(eyemask_bits, EYEMASK_WIDTH, EYEMASK_HEIGHT);
	rid2 = GrNewBitmapRegion(eyemask_bits, EYEMASK_WIDTH, EYEMASK_HEIGHT);
	GrOffsetRegion(rid2, EYEMASK_WIDTH + EYE_SPACING, 0);
	GrUnionRegion(rid1, rid1, rid2);
	GrSetWindowRegion(state->wid, rid1, GR_WINDOW_BOUNDING_MASK);
	GrDestroyRegion(rid1);
	GrDestroyRegion(rid2);

	props.flags = GR_WM_FLAGS_PROPS;
	props.props = GR_WM_PROPS_NODECORATE;
	GrSetWMProperties(state->wid, &props);

	GrSelectEvents(state->wid, GR_EVENT_MASK_CLOSE_REQ |
			GR_EVENT_MASK_MOUSE_POSITION |
			GR_EVENT_MASK_BUTTON_UP |
			GR_EVENT_MASK_BUTTON_DOWN |
			GR_EVENT_MASK_EXPOSURE |
			GR_EVENT_MASK_TIMER);

	GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_MOUSE_POSITION);

	GrMapWindow(state->wid);

	srand(123);
#if MW_FEATURE_TIMERS
	start_blink_timer(state);
#endif	
	return state;
}
예제 #9
0
/* do common startup thing for all variants */
static void lights_common_start( int mode, char * hdr )
{
    lights_hold_engaged = 0;
    GrGetScreenInfo(&lights_screen_info);
    lights_height = (lights_screen_info.rows - (HEADER_TOPLINE + 1));

    lights_mode  = mode;
    lights_max   = lights_count * lights_count;
    lights_size  = lights_height/lights_count;
    lights_x     = (lights_screen_info.cols/2) - (lights_count*lights_size/2); 

    pz_draw_header( hdr );
    new_lights_window();
}
예제 #10
0
void new_idw_window()
{
  idw_gc = GrNewGC();
	GrGetScreenInfo(&screen_info);

	init_defaults();
  init_drugs();
	init_screens();
	init_sheets();

	idw_wid = pz_new_window(0, HEADER_TOPLINE + 1, screen_info.cols, screen_info.rows - (HEADER_TOPLINE + 1), idw_do_draw, idw_do_keystroke);

	GrSelectEvents(idw_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_KEY_DOWN);
	GrMapWindow(idw_wid);
}
예제 #11
0
int NX_EnterFullScreen (_THIS)
{
    if (! currently_fullscreen) {
        GR_SCREEN_INFO si ;

        GrGetScreenInfo (& si) ;
        GrResizeWindow (FSwindow, si.cols, si.rows) ;
        GrUnmapWindow (SDL_Window) ;
        GrMapWindow (FSwindow) ;
        GrRaiseWindow (FSwindow) ;
        GrSetFocus (FSwindow) ;
        currently_fullscreen = 1 ;      
    }

    return 1 ;
}
예제 #12
0
파일: info.c 프로젝트: LucidOne/Rovio
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();
}
예제 #13
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;
}
예제 #14
0
void new_keyman_window( void )
{
	
    keyman_gc = GrNewGC();
    GrSetGCUseBackground(keyman_gc, GR_FALSE);
    GrSetGCForeground(keyman_gc, WHITE);
	GrGetScreenInfo(&screen_info);
	
	yomipict_pixmap=GrNewPixmap(384,128,NULL);
	mainmenu_pixmap=GrNewPixmap(160,128,NULL);
	shu_pixmap=GrNewPixmap(16,16,NULL);
	dialogall_pixmap=GrNewPixmap(96,80,NULL);
	dialog_pixmap=GrNewPixmap(96,80,NULL);
	
	
    keyman_wid = pz_new_window(0, 0, 
	screen_info.cols, screen_info.rows, 
	keyman_do_draw, keyman_handle_event);

		
	if (!(kmimage_id=GrLoadImageFromFile(pathimage,0))){
		GAMEN=NODATA;
		
	}
	else {
		GAMEN=MENU;
		GrDrawImageToFit(yomipict_pixmap,keyman_gc,0,0,384,128,kmimage_id);
		makedialog();
	}
	
	

    GrSelectEvents( keyman_wid, GR_EVENT_MASK_TIMER|
	GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_KEY_UP|GR_EVENT_MASK_KEY_DOWN);

    keyman_timer = GrCreateTimer( keyman_wid, 90 );
    GrMapWindow( keyman_wid );
    pz_draw_header( "KeyMan" );
}
예제 #15
0
파일: img_demo.c 프로젝트: EPiCS/reconos_v2
void
show_jpeg(int client, char *file, int show_time)
{
    GR_EVENT        event;          /* current event */
    GR_IMAGE_ID     id = 0;
    GR_SIZE         w = -1;
    GR_SIZE         h = -1;
    GR_IMAGE_INFO   info;
    GR_WINDOW_ID    w1;             /* id for large window */
    GR_GC_ID        gc1;            /* graphics context for text */
    GR_SCREEN_INFO  si;

    int time_left;
    bool ever_exposed = false;

#if !defined(HAVE_JPEG_SUPPORT) && !defined(HAVE_BMP_SUPPORT) && !defined(HAVE_GIF_SUPPORT)
    printf("Sorry, no image support compiled in\n");
    exit(1);        
#endif

    GrGetScreenInfo(&si);
    printf("Loading image: %s\n", file);
    if (access(file, F_OK) < 0) {
        fdprintf(client, "Can't access \"%s\": %s\n", file, strerror(errno));
        return;
    }
    id = GrLoadImageFromFile(file, 0);
    if (id) {
        GrGetImageInfo(id, &info);
    } else {
        // File exists, so why the error?
        int fd, len;
        char buf[64];
        fdprintf(client, "Can't load %s\n", file);
        if ((fd = open(file, O_RDONLY)) >= 0) {
            len = read(fd, buf, 64);
            if (len != 64) {
                diag_printf("Short read? len = %d\n", len);
            } else {
                diag_dump_buf(buf, len);
            }
            close(fd);
        } else {
            diag_printf("Can't oopen \"%s\": %s\n",  file, strerror(errno));
        }
        return;
    }

    w = info.width;
    h = info.height;
    if ((si.rows < info.height) || (si.cols < info.width)) {
        // Preserve aspect ratio
        if (si.cols < info.width) {
            w = si.cols;
            h = (si.cols * info.height) / info.width;
        }
        if (si.rows < h) {
            w = (si.rows * w) / h;
            h = si.rows;
        }
    }
    printf("Create window - orig %dx%d => %dx%d\n", info.width, info.height, w, h);
    fdprintf(client, "<INFO> Display \"%s\" - orig %dx%d => %dx%d\n", file, info.width, info.height, w, h);
    w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, w, h, 4, BLACK, WHITE);
    GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE);
    GrMapWindow(w1);
    gc1 = GrNewGC();
    GrSetGCForeground(gc1, WHITE);

#define TO_MS 50
    time_left = show_time * 1000;
    while (time_left > 0) {
        GrGetNextEventTimeout(&event, TO_MS);  // milliseconds
        switch(event.type) {
        case GR_EVENT_TYPE_CLOSE_REQ:
            GrDestroyWindow(w1);
            GrFreeImage(id);
            return;
            /* no return*/
        case GR_EVENT_TYPE_EXPOSURE:
            /*GrDrawImageFromFile(w1, gc1, 0, 0, w, h, argv[1],0);*/
            GrDrawImageToFit(w1, gc1, 0, 0, w, h, id);
            ever_exposed = true;
            break;
        default:
        case GR_EVENT_TYPE_NONE:
        case GR_EVENT_TYPE_TIMEOUT:
            time_left -= TO_MS;
            if ((time_left < 0) && !ever_exposed) {
                // Things get real cranky if we delete the window too fast!
                time_left = TO_MS;
            }
            break;
        }
    }    
    GrUnmapWindow(w1);
    GrDestroyWindow(w1);
    GrDestroyGC(gc1);
    GrFreeImage(id);
}
예제 #16
0
int
main(int argc, char **argv)
{
	GR_SCREEN_INFO	si;
	GR_WM_PROPERTIES props;

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

        GrReqShmCmds(65536); /* Test by Morten Rolland for shm support */

	GrGetScreenInfo(&si);
#ifdef __ECOS
/* 240x320 screen*/
COLS = si.cols - 10;
ROWS = si.rows - 40;
#else
COLS = si.cols - 40;
ROWS = si.rows - 80;
#endif

	mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, COLS, ROWS,
		0, BLACK, BLACK);

	/* set title */
	props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS;
	props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION;
	props.title = "NanoX World Map";
	GrSetWMProperties(mainwid, &props);

	mapwidth = COLS - 2;
	mapheight = ROWS - 2;
	mapxorig = mapwidth / 2;
	mapyorig = mapheight / 2;
	selectxscale = 4;
	selectyscale = 3;
	coordx = 0;
	coordy = ROWS - 1;
	mapwid = GrNewWindow(mainwid, 1, 1, mapwidth, mapheight,
#if 0
		1, BLACK, WHITE);
#else
		1, LTGRAY, BLACK);
#endif
	GrSelectEvents(mainwid, GR_EVENT_MASK_CLOSE_REQ);
	GrSelectEvents(mapwid, GR_EVENT_MASK_EXPOSURE |
		GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP |
		GR_EVENT_MASK_MOUSE_POSITION | GR_EVENT_MASK_KEY_DOWN);

	GrMapWindow(mainwid);
	GrMapWindow(mapwid);

	mapgc = GrNewGC();
	xorgc = GrNewGC();
	GrSetGCMode(xorgc, GR_MODE_XOR);

	Longitude = ITOF(0);
	Latitude = ITOF(0);
	setzoom(ITOF(1));

	while (1)
		checkevent();
}
예제 #17
0
int main(int argc, char ** argv)
{
	GR_BITMAP	bitmap1fg[7];	/* mouse cursor */
	GR_BITMAP	bitmap1bg[7];

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

	w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 30, si.cols - 120,
		si.rows - 60, 1, WHITE, LTBLUE);

	GrSelectEvents(w1, GR_EVENT_MASK_BUTTON_DOWN |
		GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE |
		GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT |
		GR_EVENT_MASK_CLOSE_REQ);

	GrMapWindow(w1);

	gc1 = GrNewGC();
	gc3 = GrNewGC();

	GrSetGCForeground(gc1, GRAY);
	GrSetGCBackground(gc1, LTBLUE);
	GrSetGCFont(gc1, GrCreateFont(GR_FONT_SYSTEM_FIXED, 0, NULL));
	/*GrSetGCFont(gc1, GrCreateFont(GR_FONT_OEM_FIXED, 0, NULL));*/
	GrSetGCForeground(gc3, WHITE);
	GrSetGCBackground(gc3, BLACK);

	bitmap1fg[0] = MASK(_,_,X,_,X,_,_);
	bitmap1fg[1] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[2] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[3] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[4] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[5] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[6] = MASK(_,_,X,_,X,_,_);

	bitmap1bg[0] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[1] = MASK(_,_,X,X,X,_,_);
	bitmap1bg[2] = MASK(_,_,X,X,X,_,_);
	bitmap1bg[3] = MASK(_,_,X,X,X,_,_);
	bitmap1bg[4] = MASK(_,_,X,X,X,_,_);
	bitmap1bg[5] = MASK(_,_,X,X,X,_,_);
	bitmap1bg[6] = MASK(_,X,X,X,X,X,_);

	GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg);

	/*GrFillRect(GR_ROOT_WINDOW_ID, gc1, 0, 0, si.cols, si.rows);*/

	GrSetGCForeground(gc1, BLACK);
	GrSetGCBackground(gc1, WHITE);
	text_init();
	if (term_init() < 0) {
		GrClose();
		exit(1);
	}

	/* we want tfd events also*/
	GrRegisterInput(tfd);

#if 1
	GrMainLoop(HandleEvent);
#else
	while(1) {
		GR_EVENT ev;

		GrGetNextEvent(&ev);
		HandleEvent(&ev);
	}
#endif
	/* notreached*/
	return 0;
}
예제 #18
0
int new_snake_window(int argc, char **argv)
{
  GR_SCREEN_INFO si;
  
  fin = 0;
  snake_count = 0;
  game_speed = start_speed;

  GrGetScreenInfo(&si); /* Get screen info */
      
  srand(time(0));
  
  game_state = SNAKE_START;

  /* Make the window */
 
  /*swindow = GrNewWindowEx(WM_PROPS, "nxsnake", GR_ROOT_WINDOW_ID, 
		       10, 10, WWIDTH, WHEIGHT, BLACK);*/
  swindow = pz_new_window (0,HEADER_TOPLINE+1,si.cols,si.rows-HEADER_TOPLINE-1,
                         do_draw,nxsnake_handle_event);
  
  GrSelectEvents(swindow, GR_EVENT_MASK_EXPOSURE | 
		 		GR_EVENT_MASK_KEY_DOWN|GR_EVENT_MASK_TIMER);

  nxsnake_timer = GrCreateTimer( swindow, 5 );
  
  offscreen = pz_new_window (0,HEADER_TOPLINE+1,si.cols,si.rows-HEADER_TOPLINE-1,
                    do_draw,nxsnake_handle_event);
                    
  //offscreen = GrNewPixmap(WWIDTH, WHEIGHT, 0);
  
  do_draw();
  GrMapWindow(swindow);
  GrMapWindow(offscreen);

  /* Draw the instructions into the buffer */
  draw_string( (char *) welcome, 1);

  while(fin != 1)
    {
      GR_EVENT event;

      /* We start at 130ms, but it goes down every */
      /* time a nibble is eaten */

      /* If they get this far, then they rock! */
      if (game_speed < 5) game_speed = 5;

      GrGetNextEventTimeout(&event, game_speed);
      
      switch(event.type)
        {
        case GR_EVENT_TYPE_EXPOSURE:
        case GR_EVENT_TYPE_KEY_DOWN:
          nxsnake_handle_event(&event);
          break;

        case GR_EVENT_TYPE_TIMER:
          handle_idle();
          break;
          
        }
    
    }
  return(1);
}
예제 #19
0
void initialise(lstate *state)
{
	GR_SCREEN_INFO si;
	GR_IMAGE_ID back_image;
	GR_IMAGE_INFO imageinfo;
	int rows = 1, columns = 1, width, height, x = 0, y = 0;
	GR_WM_PROPERTIES props;
	litem *i;

	if(GrOpen() < 0) {
		GrError("Couldn't connect to Nano-X server\n");
		exit(4);
	}

	state->window_background_mode = 0;
	state->window_background_image = NULL;
	sspid = -1;

	read_config(state);

	GrGetScreenInfo(&si);

	if(si.rows > si.cols) {
		rows = state->numlitems;
		while((((rows / columns) + rows % columns) * ITEM_HEIGHT) >
								si.rows) {
			columns++;
		}
		if((columns * ITEM_WIDTH) > si.cols) goto toomany;
		rows = (rows / columns) + (rows % columns);
		width = columns * ITEM_WIDTH + 1 + columns;
		height = rows * ITEM_HEIGHT + 1 + rows;
	} else {
		columns = state->numlitems;
		while((((columns / rows) + (columns % rows)) * ITEM_WIDTH) >
								si.cols) {
			rows++;
		}
		if((rows * ITEM_HEIGHT) > si.rows) goto toomany;
		columns = (columns / rows) + (columns % rows);
		width = columns * ITEM_WIDTH + 1 + columns;
		height = (rows * ITEM_HEIGHT) + 1 + rows;
		y = si.rows - (rows * ITEM_HEIGHT) - 1 - rows;
	}

	state->gc = GrNewGC();
	GrSetGCForeground(state->gc, ITEM_TEXT_COLOUR);
	GrSetGCBackground(state->gc, ITEM_BACKGROUND_COLOUR);

	if(state->window_background_image) {
		if(!(back_image = GrLoadImageFromFile(
					state->window_background_image, 0))) {
			GrError("Couldn't load background image\n");
		} else {
			GrGetImageInfo(back_image, &imageinfo);
			if(!(state->background_pixmap = GrNewPixmap(
							imageinfo.width,
						imageinfo.height, NULL))) {
				GrError("Couldn't allocate pixmap "	
						"for background image\n");
			} else {
				GrDrawImageToFit(state->background_pixmap,
					state->gc, 0, 0, imageinfo.width,
					imageinfo.height, back_image);
				GrFreeImage(back_image);
				GrSetBackgroundPixmap(GR_ROOT_WINDOW_ID,
					state->background_pixmap,
					state->window_background_mode);
				GrClearWindow(GR_ROOT_WINDOW_ID, GR_TRUE);
			}
		}
	}

	if(state->ssitems)
		GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_SCREENSAVER);

	state->main_window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, y, width, height,
						0, ITEM_BACKGROUND_COLOUR, 0);
	GrSelectEvents(state->main_window, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_TIMER);
	props.flags = GR_WM_FLAGS_PROPS;
	props.props = GR_WM_PROPS_NOMOVE | GR_WM_PROPS_NODECORATE | GR_WM_PROPS_NOAUTOMOVE | GR_WM_PROPS_NOAUTORESIZE;
	GrSetWMProperties(state->main_window, &props);

	i = state->lastlitem;
	y = 0;
	while(i) {
		i->wid = GrNewWindow(state->main_window,
					(x * ITEM_WIDTH) + x + 1,
					(y * ITEM_HEIGHT) + y + 1, ITEM_WIDTH,
					ITEM_HEIGHT, 1, ITEM_BACKGROUND_COLOUR, ITEM_BORDER_COLOUR);
		GrSelectEvents(i->wid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN);
		GrMapWindow(i->wid);
		i = i->prev;
		if(++x == columns) {
			x = 0;
			y++;
		}
	}

	GrMapWindow(state->main_window);

	signal(SIGCHLD, &reaper);

	do_startups(state);

	return;

toomany:
	GrError("Too many items to fit on screen\n");
	exit(6);
}
예제 #20
0
static wxNativeFont wxLoadQueryFont(float pointSize,
                                    wxFontFamily family,
                                    wxFontStyle style,
                                    int weight,
                                    bool WXUNUSED(underlined),
                                    const wxString& facename,
                                    const wxString& xregistry,
                                    const wxString& xencoding,
                                    wxString* xFontName)
{
#if wxUSE_NANOX
    int xweight;
    switch (weight)
    {
         case wxFONTWEIGHT_BOLD:
             {
                 xweight = MWLF_WEIGHT_BOLD;
                 break;
             }
        case wxFONTWEIGHT_LIGHT:
             {
                 xweight = MWLF_WEIGHT_LIGHT;
                 break;
             }
         case wxFONTWEIGHT_NORMAL:
             {
                 xweight = MWLF_WEIGHT_NORMAL;
                 break;
             }

     default:
             {
                 xweight = MWLF_WEIGHT_DEFAULT;
                 break;
             }
    }
    GR_SCREEN_INFO screenInfo;
    GrGetScreenInfo(& screenInfo);

    int yPixelsPerCM = screenInfo.ydpcm;

    // A point is 1/72 of an inch.
    // An inch is 2.541 cm.
    // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
    // In fact pointSize is 10 * the normal point size so
    // divide by 10.

    int pixelHeight = (int) ( (((float)pointSize) / 720.0) * 2.541 * (float) yPixelsPerCM) ;

    // An alternative: assume that the screen is 72 dpi.
    //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
    //int pixelHeight = (int) ((float)pointSize / 10.0) ;

    GR_LOGFONT logFont;
    logFont.lfHeight = pixelHeight;
    logFont.lfWidth = 0;
    logFont.lfEscapement = 0;
    logFont.lfOrientation = 0;
    logFont.lfWeight = xweight;
    logFont.lfItalic = (style == wxFONTSTYLE_ITALIC ? 0 : 1) ;
    logFont.lfUnderline = 0;
    logFont.lfStrikeOut = 0;
    logFont.lfCharSet = MWLF_CHARSET_DEFAULT; // TODO: select appropriate one
    logFont.lfOutPrecision = MWLF_TYPE_DEFAULT;
    logFont.lfClipPrecision = 0; // Not used
    logFont.lfRoman = (family == wxROMAN ? 1 : 0) ;
    logFont.lfSerif = (family == wxSWISS ? 0 : 1) ;
    logFont.lfSansSerif = !logFont.lfSerif ;
    logFont.lfModern = (family == wxMODERN ? 1 : 0) ;
    logFont.lfProportional = (family == wxTELETYPE ? 0 : 1) ;
    logFont.lfOblique = 0;
    logFont.lfSmallCaps = 0;
    logFont.lfPitch = 0; // 0 = default
    strcpy(logFont.lfFaceName, facename.c_str());

    XFontStruct* fontInfo = (XFontStruct*) malloc(sizeof(XFontStruct));
    fontInfo->fid = GrCreateFont((GR_CHAR*) facename.c_str(), pixelHeight, & logFont);
    GrGetFontInfo(fontInfo->fid, & fontInfo->info);
    return (wxNativeFont) fontInfo;

#else
    wxNativeFontInfo info;
    info.SetFractionalPointSize(pointSize);

    if ( !facename.empty() )
    {
        info.SetFaceName(facename);
        if ( !wxTestFontSpec(info.GetXFontName()) )
        {
            // No such face name, use just the family (we assume this will
            // never fail).
            info.SetFamily(family);
        }
    }
    else
    {
        info.SetFamily(family);
    }

    wxNativeFontInfo infoWithStyle(info);
    infoWithStyle.SetStyle(style);
    if ( wxTestFontSpec(infoWithStyle.GetXFontName()) )
        info = infoWithStyle;

    wxNativeFontInfo infoWithWeight(info);
    infoWithWeight.SetNumericWeight(weight);
    if ( wxTestFontSpec(infoWithWeight.GetXFontName()) )
        info = infoWithWeight;

    // construct the X font spec from our data
    wxString fontSpec;
    fontSpec.Printf("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s",
                    info.GetXFontComponent(wxXLFD_FAMILY),
                    info.GetXFontComponent(wxXLFD_WEIGHT),
                    info.GetXFontComponent(wxXLFD_SLANT),
                    info.GetXFontComponent(wxXLFD_POINTSIZE),
                    xregistry,
                    xencoding);

    if( xFontName )
        *xFontName = fontSpec;

    return wxLoadFont(fontSpec);
#endif
    // wxUSE_NANOX
}
예제 #21
0
int
main(int argc,char **argv)
{
	GR_EVENT	event;		/* current event */
	struct app_info	* act;
	int		width, height;

#ifdef USE_WEIRD_POINTER
	GR_BITMAP	bitmap1fg[7];	/* bitmaps for first cursor */
	GR_BITMAP	bitmap1bg[7];
#endif

	for(act = Apps; act->app_id[0] != '\0'; act++, num_apps++);

	if (GrOpen() < 0) {
		GrError("cannot open graphics\n");
		return 1;
	}
	
	GrGetScreenInfo(&si);

	signal(SIGCHLD, &reaper);

	gc = GrNewGC();
	bgc = GrNewGC();

	GrSetGCForeground(bgc, GRAY);
	GrSetGCFont(gc, GrCreateFontEx(GR_FONT_SYSTEM_FIXED, 0, 0, NULL));

	GrGetGCTextSize(gc, "A", 1, GR_TFASCII, &fwidth, &fheight, &fbase);
	width = fwidth * 8 + 4;
	height = (fheight) * num_apps + 4;

	w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 5, 5, width,
		height, 1, WHITE, BLACK);

	GrSelectEvents(w1, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN
			| GR_EVENT_MASK_CLOSE_REQ);
	GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_EXPOSURE |
					GR_EVENT_MASK_CHLD_UPDATE);

	GrMapWindow(w1);

#ifdef USE_WEIRD_POINTER
	bitmap1bg[0] = MASK(_,_,X,X,X,_,_);
	bitmap1bg[1] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[2] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[3] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[4] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[5] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[6] = MASK(X,X,X,X,X,X,X);

	bitmap1fg[0] = MASK(_,_,_,_,_,_,_);
	bitmap1fg[1] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[2] = MASK(_,_,X,X,X,_,_);
	bitmap1fg[3] = MASK(_,_,X,X,X,_,_);
	bitmap1fg[4] = MASK(_,_,X,X,X,_,_);
	bitmap1fg[5] = MASK(_,_,X,X,X,_,_);
	bitmap1fg[6] = MASK(_,X,X,X,X,X,_);

	GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg);
#endif

	GrFillRect(GR_ROOT_WINDOW_ID, bgc, 0, 0, si.cols, si.rows);

	GrSetGCForeground(gc, BLACK);
	GrSetGCBackground(gc, WHITE);

	while (1) {
		GrGetNextEvent(&event);

		switch (event.type) {
			case GR_EVENT_TYPE_EXPOSURE:
				do_exposure(&event.exposure);
				break;
			case GR_EVENT_TYPE_BUTTON_DOWN:
				do_buttondown(&event.button);
				break;
			case GR_EVENT_TYPE_BUTTON_UP:
				do_buttonup(&event.button);
				break;
			case GR_EVENT_TYPE_UPDATE:
				do_update(&event.update);
				break;
			case GR_EVENT_TYPE_MOUSE_POSITION:
				do_mouse(&event.mouse);
				break;
			case GR_EVENT_TYPE_CLOSE_REQ:
				GrClose();
				return 0;
		}
	}
}
예제 #22
0
int main()
{
	int fd = open(bri_name, O_WRONLY);
	if ( fd < 0) {
		perror(bri_name);
		return 1;
	}
	
	char buff[10];
	int notquit = 1, val= read_val(bri_name), max = read_val("/sys/class/backlight/s3c/max_brightness");
	
	if ( max <= 0) return 1;
	
	GR_WINDOW_ID	wid;		/* window id */
	GR_GC_ID	gc;		/* graphics context id */
	GR_EVENT	event;		/* current event */
	GR_SCREEN_INFO	si;		/* screen information */

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

	GrGetScreenInfo(&si);
	printf("R=%d C=%d\n", si.rows, si.cols);

	wid = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 50, max, HEIGHT, 1, BLACK, WHITE);
		
	GR_WM_PROPERTIES props;
	props.title = "Nx Light";
	props.flags = GR_WM_FLAGS_TITLE;
	GrSetWMProperties( wid, &props);

	GrSelectEvents(wid, GR_EVENT_MASK_CLOSE_REQ |
			GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_MOUSE_MOTION |
			GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_BUTTON_DOWN );
	GrMapWindow(wid);
	gc = GrNewGC();

	while (notquit) {
		GrGetNextEvent(&event);
		switch (event.type) {
			case GR_EVENT_TYPE_MOUSE_MOTION:
					if ( !((GR_EVENT_MOUSE *)&event)->buttons ) break;
					if ( (event.mouse.x > 0) && (event.mouse.x < max)) {
						snprintf(buff, 9, "%d\n", val = event.mouse.x);
						write( fd, buff, strlen(buff));
					}
					GrSetGCForeground(gc, WHITE);
					GrFillRect(wid, gc, 0, 0, val, HEIGHT);
					GrSetGCForeground(gc, BLACK);
					GrFillRect(wid, gc, val, 0, max+1, HEIGHT);
					
					break;
			case GR_EVENT_TYPE_EXPOSURE:
				if (event.exposure.wid == wid)
					GrSetGCForeground(gc, WHITE);
					GrFillRect(wid, gc, 0, 0, val, HEIGHT);
					GrSetGCForeground(gc, BLACK);
					GrFillRect(wid, gc, val, 0, max+1, HEIGHT);
				break;
			case GR_EVENT_TYPE_CLOSE_REQ: 
				notquit = 0;
		}
	}
	close(fd);
	return 0;
}
예제 #23
0
파일: nanowm.c 프로젝트: EPiCS/reconos_v2
int main(int argc, char *argv[])
#endif
{
	GR_EVENT event;
	GR_WM_PROPERTIES props;
	win window;

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

	/* pass errors through main loop, don't exit*/
	GrSetErrorHandler(NULL);

	GrGetScreenInfo(&si);

	/* add root window*/
	window.wid = GR_ROOT_WINDOW_ID;
	window.pid = GR_ROOT_WINDOW_ID;
	window.type = WINDOW_TYPE_ROOT;
	window.clientid = 1;
	window.sizing = GR_FALSE;
	window.active = 0;
	window.data = NULL;
	add_window(&window);

	GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_CHLD_UPDATE);

	/* Set new root window background color*/
	props.flags = GR_WM_FLAGS_BACKGROUND;
	props.background = GrGetSysColor(GR_COLOR_DESKTOP);
	GrSetWMProperties(GR_ROOT_WINDOW_ID, &props);

	while(1) { 
		GrGetNextEvent(&event);

		switch(event.type) {
			case GR_EVENT_TYPE_ERROR:
				printf("nanowm: error %d\n", event.error.code);
				break;
			case GR_EVENT_TYPE_EXPOSURE:
				do_exposure(&event.exposure);
				break;
			case GR_EVENT_TYPE_BUTTON_DOWN:
				do_button_down(&event.button);
				break;
			case GR_EVENT_TYPE_BUTTON_UP:
				do_button_up(&event.button);
				break;
			case GR_EVENT_TYPE_MOUSE_ENTER:
				do_mouse_enter(&event.general);
				break;
			case GR_EVENT_TYPE_MOUSE_EXIT:
				do_mouse_exit(&event.general);
				break;
			case GR_EVENT_TYPE_MOUSE_POSITION:
				do_mouse_moved(&event.mouse);
				break;
			case GR_EVENT_TYPE_KEY_DOWN:
				do_key_down(&event.keystroke);
				break;
			case GR_EVENT_TYPE_KEY_UP:
				do_key_up(&event.keystroke);
				break;
			case GR_EVENT_TYPE_FOCUS_IN:
				do_focus_in(&event.general);
				break;
			case GR_EVENT_TYPE_CHLD_UPDATE:
				do_update(&event.update);
				break;
			default:
				fprintf(stderr, "Got unexpected event %d\n",
								event.type);
				break;
		}
	}

	GrClose();
}
예제 #24
0
int
main(int argc,char **argv)
{
    GR_COORD	x;
    GR_COORD	y;
    GR_SIZE		width;
    GR_SIZE		height;
    GR_COORD	rightx;		/* x coordinate for right half stuff */
    GR_BOOL		setsize;	/* TRUE if size of board is set */
    GR_BOOL		setmines;	/* TRUE if number of mines is set */
    GR_SIZE		newsize = 10;	/* desired size of board */
    GR_COUNT	newmines = 25;	/* desired number of mines */
    GR_WM_PROPERTIES props;

    setmines = GR_FALSE;
    setsize = GR_FALSE;

    argc--;
    argv++;
    while ((argc > 0) && (**argv == '-')) {
        switch (argv[0][1]) {
        case 'm':
            if (argc <= 0) {
                fprintf(stderr, "Missing mine count\n");
                exit(1);
            }
            argc--;
            argv++;
            newmines = atoi(*argv);
            setmines = GR_TRUE;
            break;

        case 's':
            if (argc <= 0) {
                fprintf(stderr, "Missing size\n");
                exit(1);
            }
            argc--;
            argv++;
            newsize = atoi(*argv);
            setsize = GR_TRUE;
            break;

        default:
            fprintf(stderr, "Unknown option \"-%c\"\n",
                    argv[0][1]);
            exit(1);
        }
        argc--;
        argv++;
    }
    if (argc > 0)
        savefile = *argv;

    srand(time(0));

    readgame(savefile);

    if (setsize) {
        if ((newsize < MINSIZE) || (newsize > MAXSIZE)) {
            fprintf(stderr, "Illegal board size\n");
            exit(1);
        }
        if (newsize != size) {
            if (steps && playing) {
                fprintf(stderr,
                        "Cannot change size while game is in progress\n");
                exit(1);
            }
            playing = GR_FALSE;
            size = newsize;
            if (!playing)
                mines = (size * size * MINEPERCENT) / 100;
        }
    }

    if (setmines) {
        if ((newmines <= 0) || ((newmines > (size * size) / 2))) {
            fprintf(stderr, "Illegal number of mines\n");
            exit(1);
        }
        if (newmines != mines) {
            if (steps && playing) {
                fprintf(stderr,
                        "Cannot change mines while game is in progress\n");
                exit(1);
            }
            playing = GR_FALSE;
            mines = newmines;
        }
    }

    findindex();

    /*
     * Parameters of the game have been verified.
     * Now open the graphics and play the game.
     */

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

    GrReqShmCmds(655360); /* Test by Morten Rolland for shm support */

    GrGetScreenInfo(&si);
    GrGetFontInfo(0, &fi);
    charheight = fi.height;

    /*
     * Create the main window which will contain all the others.
     */
#if 0
    COLS = si.cols - 40;
#else
    COLS = si.cols;
#endif
    ROWS = si.rows - 80;
    mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, COLS, ROWS,
                          0, BLACK, WHITE);

    /* set title */
    props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS;
    props.props = GR_WM_PROPS_APPFRAME | GR_WM_PROPS_CAPTION;
    props.title = "Land Mine";
    GrSetWMProperties(mainwid, &props);

    /*
     * Create the board window which lies at the left side.
     * Make the board square, and as large as possible while still
     * leaving room to the right side for statistics and buttons.
     */
    width = COLS - RIGHTSIDE - (si.xdpcm * RIGHTGAP / 10) - BOARDBORDER * 2;
    height = (((long) width) * si.ydpcm) / si.xdpcm;
    if (height > ROWS /* - y * 2*/) {
        height = ROWS - BOARDBORDER * 2;
        width = (((long) height) * si.xdpcm) / si.ydpcm;
    }
    xp = width / size;
    yp = height / size;

    width = xp * size - 1;
    height = yp * size - 1;
    x = BOARDBORDER;
    y = (ROWS - height) / 2;

    rightx = x + width + (si.xdpcm * RIGHTGAP / 10);
    boardwid = GrNewWindow(mainwid, x, y, width, height, BOARDBORDER,
                           BLUE, WHITE);
    /*
     * Create the buttons.
     */
    x = rightx;
    y = (si.ydpcm * BOARDGAP / 10);
    quitwid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT,
                          1, RED, WHITE);

    y += (si.ydpcm * BUTTONGAP / 10);
    savewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT,
                          1, GREEN, WHITE);

    y += (si.ydpcm * BUTTONGAP / 10);
    newgamewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT,
                             1, GREEN, WHITE);

    /*
     * Create the statistics window.
     */
    x = rightx;
    y += (si.ydpcm * STATUSGAP / 10);
    width = COLS - x;
    height = ROWS - y;
    statwid = GrNewWindow(mainwid, x, y, width, height, 0,
                          0, 0);
    statwidth = width;
    statheight = height;

    /*
     * Create the GC for drawing the board.
     */
    boardgc = GrNewGC();
    cleargc = GrNewGC();
    delaygc = GrNewGC();
    redgc = GrNewGC();
    greengc = GrNewGC();
    statgc = GrNewGC();
    blackgc = GrNewGC();
    buttongc = GrNewGC();
    xorgc = GrNewGC();
    GrSetGCBackground(boardgc, BLUE);
    GrSetGCForeground(cleargc, BLUE);
    GrSetGCForeground(redgc, RED);
    GrSetGCForeground(greengc, GREEN);
    GrSetGCForeground(statgc, GRAY);
    GrSetGCForeground(delaygc, BLACK);
    GrSetGCForeground(blackgc, BLACK);
    GrSetGCMode(delaygc, GR_MODE_XOR);
    GrSetGCMode(xorgc, GR_MODE_XOR);
    GrSetGCUseBackground(boardgc, GR_FALSE);
    GrSetGCUseBackground(buttongc, GR_FALSE);

    GrSelectEvents(mainwid, GR_EVENT_MASK_CLOSE_REQ);

    GrSelectEvents(boardwid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN);

    GrSelectEvents(statwid, GR_EVENT_MASK_EXPOSURE);

    GrSelectEvents(quitwid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN);

    GrSelectEvents(newgamewid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN);

    GrSelectEvents(savewid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN);

    setcursor();

    GrMapWindow(mainwid);
    GrMapWindow(boardwid);
    GrMapWindow(statwid);
    GrMapWindow(quitwid);
    GrMapWindow(savewid);
    GrMapWindow(newgamewid);

    if (!playing)
        newgame();

    while (GR_TRUE) {
        GR_EVENT event;

        GrGetNextEvent(&event);
        handleevent(&event);
    }
}
예제 #25
0
/**
 * Map framebuffer address into client memory.
 *
 * @return Pointer to start of framebuffer,
 * or NULL if framebuffer not directly accessible by client.
 */
unsigned char *
GrOpenClientFramebuffer(void)
{
#ifdef LINUX
	int 	frame_offset;
	char *	fbdev;
	struct fb_fix_screeninfo finfo;

	LOCK(&nxGlobalLock);

	/* if already open, return fb address*/
	if (physpixels) {
		UNLOCK(&nxGlobalLock);
		return physpixels;
	}

	/*
	 * For now, we'll just check whether or not Microwindows
	 * is running its framebuffer driver to determine whether
	 * to allow direct client-side framebuffer mapping.  In
	 * the future, we could allow direct mapping for Microwindows
	 * running on top of X, and finding the address of the 
	 * window within the Microwindows X window.
	 */
	GrGetScreenInfo(&sinfo);
	sinfo_valid = GR_TRUE;
	if (!sinfo.fbdriver) {
		UNLOCK(&nxGlobalLock);
		return NULL;
	}

	/*
	 * Try to open the framebuffer directly.
	 */
	if (!(fbdev = getenv("FRAMEBUFFER")))
		fbdev = "/dev/fb0";
	frame_fd = open(fbdev, O_RDWR);
	if (frame_fd < 0) {
		printf("Can't open framebuffer device\n");
		UNLOCK(&nxGlobalLock);
		return NULL;
	}

	/* Get the type of video hardware */
	if (ioctl(frame_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) {
		printf("Couldn't get fb hardware info\n");
		goto err;
	}

	/* FIXME remove when mwin returns fb or X */
	switch (finfo.visual) {
		case FB_VISUAL_TRUECOLOR:
		case FB_VISUAL_PSEUDOCOLOR:
		case FB_VISUAL_STATIC_PSEUDOCOLOR:
		case FB_VISUAL_DIRECTCOLOR:
			break;
		default:
			printf("Unsupported fb color map\n");
			goto err;
	}

	/* Memory map the device, compensating for buggy PPC mmap() */
	frame_offset = (((long)finfo.smem_start) -
		(((long)finfo.smem_start)&~(PAGE_SIZE-1)));
	frame_len = finfo.smem_len + frame_offset;
	frame_map = (unsigned char *)mmap(NULL, frame_len, PROT_READ|PROT_WRITE,
		MAP_SHARED, frame_fd,
#ifdef ARCH_LINUX_SPARC
		CG6_RAM);
#else
		0);
#endif
	if (frame_map == (unsigned char *)-1) {
		printf("Unable to memory map the video hardware\n");
		frame_map = NULL;
		goto err;
	}
	physpixels = frame_map + frame_offset;
	UNLOCK(&nxGlobalLock);
	return physpixels;

err:
	close(frame_fd);
	UNLOCK(&nxGlobalLock);
#endif /* LINUX */
	return NULL;
}
예제 #26
0
/**
 * Return client-side mapped framebuffer info for
 * passed window.  If not running framebuffer, the
 * physpixel and winpixel members will be NULL, and
 * everything else correct.
 *
 * @param wid    Window to query
 * @param fbinfo Structure to store results.
 */
void
GrGetWindowFBInfo(GR_WINDOW_ID wid, GR_WINDOW_FB_INFO *fbinfo)
{
	int			physoffset;
	int			x, y;
	GR_WINDOW_INFO		info;
	static int		last_portrait = -1;

	LOCK(&nxGlobalLock);

	/* re-get screen info on auto-portrait switch*/
	if (!sinfo_valid || (last_portrait != sinfo.portrait)) {
		GrGetScreenInfo(&sinfo);
		sinfo_valid = GR_TRUE;
	}
	last_portrait = sinfo.portrait;

	/* must get window position anew each time*/
	GrGetWindowInfo(wid, &info);

	fbinfo->bpp = sinfo.bpp;
	fbinfo->bytespp = (sinfo.bpp+7)/8;
	fbinfo->pixtype = sinfo.pixtype;
	fbinfo->portrait_mode = sinfo.portrait;

	switch (fbinfo->portrait_mode) {
	case MWPORTRAIT_RIGHT:
	case MWPORTRAIT_LEFT:
		/*
		 * We reverse coords since Microwindows reports
		 * back the virtual xres/yres, and we want
		 * the physical xres/yres.
		 */
		/* FIXME return xres and xvirtres in SCREENINFO? */
		fbinfo->xres = sinfo.rows;	/* reverse coords*/
		fbinfo->yres = sinfo.cols;
		break;
	default:
		fbinfo->xres = sinfo.cols;
		fbinfo->yres = sinfo.rows;
		break;
	}
	fbinfo->xvirtres = sinfo.cols;
	fbinfo->yvirtres = sinfo.rows;
	fbinfo->pitch = fbinfo->xres * fbinfo->bytespp;

	/* calc absolute window coords*/
	x = info.x;
	y = info.y;
	while (info.parent != 0) {
		GrGetWindowInfo(info.parent, &info);
		x += info.x;
		y += info.y;
	}
	fbinfo->x = x;
	fbinfo->y = y;

	/* fill in memory mapped addresses*/
	fbinfo->physpixels = physpixels;

	/* winpixels only valid for non-portrait modes*/
	physoffset = fbinfo->y*fbinfo->pitch + fbinfo->x*fbinfo->bytespp;
	fbinfo->winpixels = physpixels? (physpixels + physoffset): NULL;

	UNLOCK(&nxGlobalLock);
}
예제 #27
0
파일: fontutil.cpp 프로젝트: beanhome/dev
static wxNativeFont wxLoadQueryFont(int pointSize,
                                    int family,
                                    int style,
                                    int weight,
                                    bool WXUNUSED(underlined),
                                    const wxString& facename,
                                    const wxString& xregistry,
                                    const wxString& xencoding,
                                    wxString* xFontName)
{
    wxString xfamily;
    switch (family)
    {
        case wxDECORATIVE: xfamily = wxT("lucida"); break;
        case wxROMAN:      xfamily = wxT("times");  break;
        case wxMODERN:     xfamily = wxT("courier"); break;
        case wxSWISS:      xfamily = wxT("helvetica"); break;
        case wxTELETYPE:   xfamily = wxT("lucidatypewriter"); break;
        case wxSCRIPT:     xfamily = wxT("utopia"); break;
        default:           xfamily = wxT("*");
    }
#if wxUSE_NANOX
    int xweight;
    switch (weight)
    {
         case wxBOLD:
             {
                 xweight = MWLF_WEIGHT_BOLD;
                 break;
             }
        case wxLIGHT:
             {
                 xweight = MWLF_WEIGHT_LIGHT;
                 break;
             }
         case wxNORMAL:
             {
                 xweight = MWLF_WEIGHT_NORMAL;
                 break;
             }

     default:
             {
                 xweight = MWLF_WEIGHT_DEFAULT;
                 break;
             }
    }
    GR_SCREEN_INFO screenInfo;
    GrGetScreenInfo(& screenInfo);

    int yPixelsPerCM = screenInfo.ydpcm;

    // A point is 1/72 of an inch.
    // An inch is 2.541 cm.
    // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
    // In fact pointSize is 10 * the normal point size so
    // divide by 10.

    int pixelHeight = (int) ( (((float)pointSize) / 720.0) * 2.541 * (float) yPixelsPerCM) ;

    // An alternative: assume that the screen is 72 dpi.
    //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
    //int pixelHeight = (int) ((float)pointSize / 10.0) ;

    GR_LOGFONT logFont;
    logFont.lfHeight = pixelHeight;
    logFont.lfWidth = 0;
    logFont.lfEscapement = 0;
    logFont.lfOrientation = 0;
    logFont.lfWeight = xweight;
    logFont.lfItalic = (style == wxNORMAL ? 0 : 1) ;
    logFont.lfUnderline = 0;
    logFont.lfStrikeOut = 0;
    logFont.lfCharSet = MWLF_CHARSET_DEFAULT; // TODO: select appropriate one
    logFont.lfOutPrecision = MWLF_TYPE_DEFAULT;
    logFont.lfClipPrecision = 0; // Not used
    logFont.lfRoman = (family == wxROMAN ? 1 : 0) ;
    logFont.lfSerif = (family == wxSWISS ? 0 : 1) ;
    logFont.lfSansSerif = !logFont.lfSerif ;
    logFont.lfModern = (family == wxMODERN ? 1 : 0) ;
    logFont.lfProportional = (family == wxTELETYPE ? 0 : 1) ;
    logFont.lfOblique = 0;
    logFont.lfSmallCaps = 0;
    logFont.lfPitch = 0; // 0 = default
    strcpy(logFont.lfFaceName, facename.c_str());

    XFontStruct* fontInfo = (XFontStruct*) malloc(sizeof(XFontStruct));
    fontInfo->fid = GrCreateFont((GR_CHAR*) facename.c_str(), pixelHeight, & logFont);
    GrGetFontInfo(fontInfo->fid, & fontInfo->info);
    return (wxNativeFont) fontInfo;

#else
    wxString fontSpec;
    if (!facename.empty())
    {
        fontSpec.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
                        facename.c_str());

        if ( wxTestFontSpec(fontSpec) )
        {
            xfamily = facename;
        }
        //else: no such family, use default one instead
    }

    wxString xstyle;
    switch (style)
    {
        case wxSLANT:
            fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
                    xfamily.c_str());
            if ( wxTestFontSpec(fontSpec) )
            {
                xstyle = wxT("o");
                break;
            }
            // fall through - try wxITALIC now

        case wxITALIC:
            fontSpec.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
                    xfamily.c_str());
            if ( wxTestFontSpec(fontSpec) )
            {
                xstyle = wxT("i");
            }
            else if ( style == wxITALIC ) // and not wxSLANT
            {
                // try wxSLANT
                fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
                        xfamily.c_str());
                if ( wxTestFontSpec(fontSpec) )
                {
                    xstyle = wxT("o");
                }
                else
                {
                    // no italic, no slant - leave default
                    xstyle = wxT("*");
                }
            }
            break;

        default:
            wxFAIL_MSG(wxT("unknown font style"));
            // fall back to normal

        case wxNORMAL:
            xstyle = wxT("r");
            break;
    }

    wxString xweight;
    switch (weight)
    {
         case wxBOLD:
             {
                  fontSpec.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("bold");
                       break;
                  }
                  fontSpec.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("heavy");
                       break;
                  }
                  fontSpec.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                      xweight = wxT("extrabold");
                      break;
                  }
                  fontSpec.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                      xweight = wxT("demibold");
                      break;
                  }
                  fontSpec.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                      xweight = wxT("black");
                      break;
                  }
                  fontSpec.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                      xweight = wxT("ultrablack");
                      break;
                  }
              }
              break;
        case wxLIGHT:
             {
                  fontSpec.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("light");
                       break;
                  }
                  fontSpec.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("thin");
                       break;
                  }
             }
             break;
         case wxNORMAL:
             {
                  fontSpec.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("medium");
                       break;
                  }
                  fontSpec.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("normal");
                       break;
                  }
                  fontSpec.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                      xweight = wxT("regular");
                      break;
                  }
                  xweight = wxT("*");
              }
              break;
        default:           xweight = wxT("*"); break;
    }

    // if pointSize is -1, don't specify any
    wxString sizeSpec;
    if ( pointSize == -1 )
    {
        sizeSpec = wxT('*');
    }
    else
    {
        sizeSpec.Printf(wxT("%d"), pointSize);
    }

    // construct the X font spec from our data
    fontSpec.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
                    xfamily.c_str(), xweight.c_str(), xstyle.c_str(),
                    sizeSpec.c_str(), xregistry.c_str(), xencoding.c_str());

    if( xFontName )
        *xFontName = fontSpec;

    return wxLoadFont(fontSpec);
#endif
    // wxUSE_NANOX
}
예제 #28
0
int
main(int argc,char **argv)
{
	int			t;
	GR_IMAGE_ID	image_id;
	GR_WINDOW_ID	window_id;
	GR_GC_ID	gc_id;
	GR_SIZE		w = -1;
	GR_SIZE		h = -1;
	GR_EVENT	event;
	GR_SCREEN_INFO	sinfo;
	GR_IMAGE_INFO	info;
	char		title[256];

	if (argc < 2) {
		GrError("Usage: nxview [-p] [-s] <image file>\n");
		return 1;
	}

	t = 1;
	while ( t < argc ) {
		if ( !strcmp("-p",argv[t])) {
			pflag = 1;
			++t;
			continue;
		}
		if ( !strcmp("-s",argv[t])) {
			sflag = 1;
			++t;
			continue;
		}
		break;
	}

	if (GrOpen() < 0) {
		GrError("cannot open graphics\n");
		return 1;
	}
	
	if (!(image_id = GrLoadImageFromFile(argv[t], 0))) {
		GrError("Can't load image file: %s\n", argv[t]);
		return 1;
	}

	if(sflag) {
		/* stretch to half screen size*/
		GrGetScreenInfo(&sinfo);
		w = sinfo.cols/2;
		h = sinfo.rows/2;
	} else {
		GrGetImageInfo(image_id, &info);
		w = info.width;
		h = info.height;
	}

	sprintf(title, "nxview %s", argv[t]);
	window_id = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, title, GR_ROOT_WINDOW_ID, 0, 0, w, h, GRAY);

	GrSelectEvents(window_id,
		GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE);

	GrMapWindow(window_id);

	gc_id = GrNewGC();

	while (1) {
		GrGetNextEvent(&event);
		switch(event.type) {
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrDestroyWindow(window_id);
			GrDestroyGC(gc_id);
			GrFreeImage(image_id);
			GrClose();
			return 0;
			/* no return*/
		case GR_EVENT_TYPE_EXPOSURE:
			if (pflag) {
				int x, y;
				GR_WINDOW_INFO wi;

				GrGetWindowInfo(window_id, &wi);
				for (x=0; x<wi.width; x+=CX*2)
					for (y=0; y<wi.height; y+=CY) {
						if (y & CY)
							GrFillRect(window_id, gc_id, x, y, CX, CY);
						else GrFillRect(window_id, gc_id, x+CX, y, CX, CY); 
					}
			}
			GrDrawImageToFit(window_id, gc_id, 0,0, w,h, image_id);
			break;
		}
	}

	return 0;
}
예제 #29
0
/* Initialise the game and return the state structure or NULL on failure: */
nbstate *init(int argc, char *argv[])
{
	GR_PROP *prop;
	nbstate *state;
	GR_SCREEN_INFO si;
	GR_BITMAP cursor = 0;
	GR_WM_PROPERTIES props;

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

	/* Check that the server was built with alpha blending support
	 * (necessary for the alpha blended sprites and special effects): */
	GrGetScreenInfo(&si);
	if(!si.alphablend) {
		fprintf(stderr, "Error: Nano-X server was built without alpha "
				"blending support\nSet ALPHABLENDING = 1 in "
				"include/device.h, rebuild, and try again.\n");
		return NULL;
	}

	/* Allocate the state structure and initialise it with defaults: */
	if(!(state = malloc(sizeof(nbstate)))) return NULL;
	setup_default_state(state);

	/* Try to parse the command line arguments: */
	if(parse_cmd_args(state, argc, argv)) {
		free(state);
		return NULL;
	}

	/* Try to load the game file: */
	if(load_game_file(state)) {
		free(state);
		return NULL;
	}

	/* Load the high score file: */
	load_hiscore(state);

	/* Calculate the canvas size: */
	state->canvaswidth = state->width * state->brickwidth;
	state->canvasheight = state->scores.h + state->ball.s->h +
				(2 * BALLS_BORDER) +
				(state->height * state->brickheight) +
				3 * state->brickheight + state->batheight;

	/* Place the bat in the centre of the window: */
	state->batx = state->canvaswidth / 2;

	/* Create various pixmaps and alpha channels: */
	state->scores.p = GrNewPixmap(state->canvaswidth, state->scores.h,
			NULL);
	state->scores.a = GrNewAlpha(state->canvaswidth, state->scores.h);
	state->canvas = GrNewPixmap(state->canvaswidth, state->canvasheight,
			NULL);
	/* The new and old canvasses are only used when screen fading is
	 * enabled: */
	if(state->faderate) {
		state->newcanvas = GrNewPixmap(state->canvaswidth,
					state->canvasheight, NULL);
		state->oldcanvas = GrNewPixmap(state->canvaswidth,
					state->canvasheight, NULL);
	}
	state->brickalpha = GrNewAlpha(state->brickwidth, state->brickheight);

	/* Start off with the canvas completely black: */
	GrSetGCForeground(state->gc, GR_COLOR_BLACK);
	GrFillRect(state->canvas, state->gc, 0, 0, state->canvaswidth,
						state->canvasheight);

	/* If there is a window manager running, place the window off the
	 * screen and let the window manager move it where it wants (avoids
	 * flicker if we were to draw the window on screen before the window
	 * manager moved it somewhere else): */
        if(GrGetWindowProperty(GR_ROOT_WINDOW_ID, "WINDOW_MANAGER", &prop)) {
		free(prop);
		state->winx = GR_OFF_SCREEN;
	}

	/* Create the output window: */
	state->wid = GrNewWindow(GR_ROOT_WINDOW_ID, state->winx, 0,
			state->canvaswidth, state->canvasheight, 0, 0, 0);

	/* Set the window title: */
	props.flags = GR_WM_FLAGS_TITLE;
	props.title = "NanoBreaker";
	GrSetWMProperties(state->wid, &props);

	/* Make the cursor over the output window be invisible: */
	GrSetCursor(state->wid, 1, 1, 1, 1, 0, 0, &cursor, &cursor);

	/* Select the events we want to receive for the output window: */
	GrSelectEvents(state->wid, GR_EVENT_MASK_CLOSE_REQ |
				GR_EVENT_MASK_EXPOSURE |
				GR_EVENT_MASK_BUTTON_DOWN |
				GR_EVENT_MASK_KEY_DOWN |
				GR_EVENT_MASK_KEY_UP |
				GR_EVENT_MASK_UPDATE |
				GR_EVENT_MASK_TIMER);

	/* Select for mouse position events on the root window so we can move
	 * the bat even when the pointer strays outside the window (which it
	 * often does because the cursor is invisible you don't know exactly
	 * where it is): */
	GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_MOUSE_POSITION);

	/* Map the output window (make it visible): */
	GrMapWindow(state->wid);

	/* Create the one second periodic timer that is used to decrement the
	 * power-up and power-down timers: */
	state->tid = GrCreateTimer(state->wid, 1000, GR_TRUE);

	/* Reset the game: */
	reset_game(state);

	return state; /* Return the newly allocated state structure. */
}
예제 #30
0
파일: demo2.c 프로젝트: LucidOne/Rovio
int
main(int ac,char **av)
{
	GR_WINDOW_ID 	w, w2;
	GR_GC_ID	gc;
	GR_EVENT 	event;
	GR_WM_PROPERTIES props;

	if (GrOpen() < 0) {
		printf("Can't open graphics\n");
		exit(1);
	}

	/* pass errors through main loop*/
	GrSetErrorHandler(NULL);

#define WIDTH	320
#define HEIGHT	240
	w = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 20, WIDTH, HEIGHT,
		0, GREEN, BLACK);

	w2 = GrNewWindow(w, 20, 20, 40, 40, 0, WHITE, BLACK);

	props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE;
	props.props = GR_WM_PROPS_NOBACKGROUND;
	props.title = "Nano-X Demo2";
	GrSetWMProperties(w, &props);

	gc = GrNewGC();

	GrSelectEvents(w, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ
		| GR_EVENT_MASK_BUTTON_DOWN
		| GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP);
	GrMapWindow(w);
	GrSetFocus(w);
	/* serious bug here: when wm running, w2 is mapped anyway!!*/
	/*GrMapWindow(w2);*/

	for (;;) {
		/*GR_EVENT_KEYSTROKE *kev;*/

		GrGetNextEvent(&event);
		switch (event.type) {
		case GR_EVENT_TYPE_EXPOSURE:
			GrSetGCForeground(gc,GrGetSysColor(GR_COLOR_APPWINDOW));
			GrFillRect(w, gc, event.exposure.x, event.exposure.y,
				event.exposure.width, event.exposure.height);
			GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_APPTEXT));
			GrSetGCUseBackground(gc, GR_FALSE);
			GrText(w, gc, 10, 30, "Hello World", -1, GR_TFASCII);
GrRect(w, gc, 5, 5, 300, 60);
			break;
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			exit(0);
			break;
		case GR_EVENT_TYPE_ERROR:
			printf("\7demo2: Error (%s) ", event.error.name);
			printf(nxErrorStrings[event.error.code],event.error.id);
			break;
#if 0
		case GR_EVENT_TYPE_BUTTON_DOWN:
			/* test server error on bad syscall*/
			GrMapWindow(w2);
			GrMoveWindow(GR_ROOT_WINDOW_ID, 0, 0);
			{ GR_SCREEN_INFO sinfo; GrGetScreenInfo(&sinfo); }
			break;
#endif
#if 0
		case GR_EVENT_TYPE_KEY_DOWN:
			kev = (GR_EVENT_KEYSTROKE *)&event;
			printf("DOWN %d (%04x) %04x\n",
				kev->ch, kev->ch, kev->modifiers);
			break;
		case GR_EVENT_TYPE_KEY_UP:
			kev = (GR_EVENT_KEYSTROKE *)&event;
			printf("UP %d (%04x) %04x\n",
				kev->ch, kev->ch, kev->modifiers);
			break;
#endif
		}
	}

	GrClose();
	return 0;
}