Example #1
0
/* Destroy every sprite in the sprite list in one go. More efficient than
 * calling destroy_sprite() for every use of every sprite. */
void destroy_all_sprites(nbstate *state)
{
	sprite *s, *snext = state->spritelist;

	while((s = snext)) { /* Iterate through the list. */
		myfree(s->fname); /* Free the file name. */
		GrDestroyWindow(s->p); /* Destroy the pixmap. */
		GrDestroyWindow(s->a); /* Destroy the alpha channel. */
		snext = s->next;
		free(s); /* Free the structure itself. */
	}
	state->spritelist = 0; /* Set the list head empty. */
}
Example #2
0
void CContextWeather::DeInit()
{
	CContext::DeInit();

	GrDestroyWindow(m_pixmap_ment);

//	GrUnmapWindow(m_wid_ment);
	GrDestroyWindow(m_wid_ment);

	//Ment Scroll Window 영역이 까맣게 보이는 증상이 있어서 배경으로 다시 덮어줌
	RedrawImage(g_wid, g_gc, MENT_AREA_X, MENT_AREA_Y, MENT_AREA_WIDTH, MENT_AREA_HEIGHT, 
				MENT_AREA_X, MENT_AREA_Y, MENT_AREA_WIDTH, MENT_AREA_HEIGHT, WEATHER_OBJ_BG);
	
	m_ObjectList.RemoveAll();
}
Example #3
0
// clean up & quit
static void mandel_quit() {
	int i;
	rendering=0;
	paused=0;
	
	pz_close_window (mandel_wid);
#ifdef MANDELPOD_STATUS
	pz_close_window (status_wid);
#endif
	for (i=0;i<max_depth+1;i++) 
		GrDestroyWindow(level[i].mandel_buffer);
	for (i=0;i<16;i++) 
		GrDestroyWindow(status_image[i]);
	GrDestroyGC(mandel_gc);
	
}
Example #4
0
/* exit, release all created stuff */
void lights_exit( void ) 
{
	GrDestroyTimer( lights_timer );
	GrDestroyGC( lights_gc );
	pz_close_window( lights_wid );
	GrDestroyWindow( lights_bufwid );
}
Example #5
0
int
XFreePixmap(Display * display, Pixmap pixmap)
{

	GrDestroyWindow(pixmap);
	return 1;
}
Example #6
0
/* Destroy the specified sprite. Should be called whenever you don't need a
 * particular sprite any more, even though it doesn't actually destroy the
 * sprite until all users of the sprite have called destroy_sprite(). */
void destroy_sprite(nbstate *state, sprite *s)
{
	if(!s) return; /* Sanity check. */

	if(!--s->usage) { /* Decrement the usage count. */
		/* The usage count is zero, so destroy the sprite: */
		myfree(s->fname); /* Free the file name. */
		GrDestroyWindow(s->p); /* Destroy the pixmap. */
		GrDestroyWindow(s->a); /* Destroy the alpha channel. */
		/* Unlink it from the sprite list: */
		if(s == state->spritelist) state->spritelist = s->next;
		else s->prev->next = s->next;
		if(s->next) s->next->prev = s->prev;
		free(s); /* Free the structure itself. */
	}
}
Example #7
0
static void create_aux_windows (_THIS)
{
    GR_WM_PROPERTIES props ;

    Dprintf ("enter create_aux_windows\n") ;

    // Don't create any extra windows if we are being managed
    if (SDL_windowid) {
        FSwindow = 0 ;
        return ;
    }
    
    if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) {
        GrDestroyWindow (FSwindow) ;
    }
    
    FSwindow = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK) ;
    props.flags = GR_WM_FLAGS_PROPS ;
    props.props = GR_WM_PROPS_NODECORATE ;
    GrSetWMProperties (FSwindow, & props) ;

    GrSelectEvents (FSwindow, (GR_EVENT_MASK_EXPOSURE         |
        GR_EVENT_MASK_BUTTON_DOWN  | GR_EVENT_MASK_BUTTON_UP  |
        GR_EVENT_MASK_FOCUS_IN     | GR_EVENT_MASK_FOCUS_OUT  |
        GR_EVENT_MASK_KEY_DOWN     | GR_EVENT_MASK_KEY_UP     |
        GR_EVENT_MASK_MOUSE_ENTER  | GR_EVENT_MASK_MOUSE_EXIT |
        GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE     |
        GR_EVENT_MASK_CLOSE_REQ)) ;

    Dprintf ("leave create_aux_windows\n") ;
}
Example #8
0
static void
GrDestroyWindowWrapper(void *r)
{
	nxDestroyWindowReq *req = r;

	GrDestroyWindow(req->windowid);
}
Example #9
0
static void
do_update(GR_EVENT_UPDATE *ep)
{
	mwin *	mwp;
	mwin *	tmwp;
	GR_WINDOW_INFO winfo;

	if (IsDecoration(ep->wid)) return;

	if ((mwp = FindWindow(ep->wid)) == NULL) {
		/* We have a new window */
		if (ep->utype != GR_UPDATE_MAP) return;
		if ((mwp = NewWindow(ep->wid)) == NULL) {
			GrError("malloc failed\n");
			return;
		}
		GrGetWindowInfo(ep->wid, &winfo);
		mwp->x = ep->x - winfo.bordersize;
		mwp->y = ep->y - winfo.bordersize;
		mwp->width = ep->width + 2 * winfo.bordersize;
		GrMoveWindow(mwp->wid, mwp->x + winfo.bordersize,
					mwp->y + DEC_HEIGHT +
						2 * winfo.bordersize);
		mwp->fid = GrNewWindow(GR_ROOT_WINDOW_ID, mwp->x + 1,
				mwp->y + 1, mwp->width - 2,
				DEC_HEIGHT - 2, 1, BLUE, BLACK);
		GrSelectEvents(mwp->fid, GR_EVENT_MASK_BUTTON_DOWN |
			GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION);
		GrMapWindow(mwp->fid);
	} else {
		switch (ep->utype) {
			case GR_UPDATE_UNMAP:
				GrUnmapWindow(mwp->fid);
				GrDestroyWindow(mwp->fid);
				if (mwins == mwp) {
					mwins = mwp->next;
				} else for(tmwp = mwins; tmwp; tmwp = tmwp->next) {
					if (tmwp->next == mwp) {
						tmwp->next = mwp->next;
					}
				}
				free(mwp);
				break;
			case GR_UPDATE_MOVE:
				GrGetWindowInfo(ep->wid, &winfo);
				if ((ep->x == (mwp->x + winfo.bordersize)) &&
					(ep->y == (mwp->y + winfo.bordersize
							+ DEC_HEIGHT))) {
					return;
				}
				mwp->x = ep->x - winfo.bordersize;
				mwp->y = ep->y - winfo.bordersize - DEC_HEIGHT;
				GrMoveWindow(mwp->fid, mwp->x + 1, mwp->y + 1);
			default:
				break;
		}
	}
}
Example #10
0
GR_WINDOW_ID
resize(GR_SIZE w, GR_SIZE h, GR_WINDOW_ID pmap)
{
    width = w;
    height = h;
    if (pmap)
	GrDestroyWindow(pmap);
    return GrNewPixmap(w, h, NULL);
}
Example #11
0
/* Make an empty sprite structure with the specified file name, width, and
 * height. It is expected that you will probably already have tried calling
 * load_sprite() first and it failed, so you want to create the sprite
 * manually. */
sprite *make_empty_sprite(nbstate *state, unsigned char *fname, int width, int height)
{
	sprite *s;
	GR_DRAW_ID a;
	GR_DRAW_ID p;

	/* Allocate the alpha channel and pixmap with the specified
	 * dimensions (which must be valid): */
	if(!(a = GrNewPixmap(width, height, 0)))
		return 0;
	if(!(p = GrNewPixmap(width, height, 0))) {
		GrDestroyWindow(a);
		return 0;
	}

	/* Make the sprite itself and return it to the caller: */
	if(!(s = make_sprite(state, fname, width, height, p, a))) {
		GrDestroyWindow(a);
		GrDestroyWindow(p);
		return 0;
	} else return s;
}
Example #12
0
/* if you are apt enough to use this to clean-up, everyone profits */
menu_st *menu_destroy(menu_st *menulist)
{
	int i;
	menu_st *parent = menulist->parent;

	if(parent != NULL)
		menu_left_transition(menulist);

	/* make sure its not a static menu we are trying to free */
	if(menulist->alloc_items != 0)
		free(menulist->items);
	if(menulist->timer)
		GrDestroyTimer(menulist->timer);
	GrDestroyGC(menulist->menu_gc);
	for(i=0; i<menulist->screen_items; i++)
		GrDestroyWindow(menulist->pixmaps[i]);
	GrDestroyWindow(menulist->transition);
	free(menulist->pixmaps);
	free(menulist->pixmap_pos);
	free(menulist);

	return parent;
}
Example #13
0
void
mvpw_destroy(mvp_widget_t *widget)
{
	mvpw_hide(widget);

	if (widget->callback_destroy)
		widget->callback_destroy(widget);
	if (widget->destroy)
		widget->destroy(widget);

	remove_widget(widget);

	GrDestroyWindow(widget->wid);

	free(widget);
}
Example #14
0
void menu_update_menu(menu_st *menulist)
{
	int i;

	/* wipe all of the pixmaps */
	for (i = 0; i < menulist->screen_items; i++) {
		menu_clear_pixmap(menulist, i);
	}

	if (get_current_font() != menulist->font) {
		int items;
		int h = menulist->height;
		GrDestroyGC(menulist->menu_gc);
		menulist->menu_gc = pz_get_gc(1);
		GrGetGCTextSize(menulist->menu_gc, "abcdefghijhlmnopqrstuvwxyz"
				"ABCDEFGHIJKLMNOPQRSTUVWXYZ", -1, GR_TFASCII,
				&menulist->width, &menulist->height,
				&menulist->base);
		/* add a 2px padding to the text */
		menulist->height += 4;
		items = (int)menulist->h/menulist->height;
		if (menulist->height != h) {
			for (i = 0; i < menulist->screen_items; i++)
				GrDestroyWindow(menulist->pixmaps[i]);
			free(menulist->pixmaps);
			free(menulist->pixmap_pos);
			create_pixmaps(menulist, items);
		}
		menulist->screen_items = items;
		menulist->font = get_current_font();
		if (menulist->sel > menulist->top_item + menulist->screen_items)
			menu_select_item(menulist, menulist->sel);

	}
	
	/* force the rest of the redraw */
	menulist->scheme_no = appearance_get_color_scheme();
	/* NOTE: if "color scheme" is anywhere other than on the first
	   screen's worth of menu items, this doesn't work correctly,
	   but that's not an issue right now */
	menulist->init = 0;
}
Example #15
0
int periodic_handle_event(GR_EVENT * event)
{
	if (event->type == GR_EVENT_TYPE_KEY_DOWN) {
		switch (event->keystroke.ch) {
		case 'l':
			if (periodic_sel > 0) {
				periodic_sel--;
			} else {
				periodic_sel = 117;
			}
			periodic_draw();
			break;
		case 'r':
			if (periodic_sel < 117) {
				periodic_sel++;
			} else {
				periodic_sel = 0;
			}
			periodic_draw();
			break;
		case '\n':
		case '\r':
			periodic_element_info(periodic_sel);
			break;
		case 'm':
		case 'q':
			pz_close_window(periodic_wid);
			GrDestroyWindow(periodic_bufwid);
			GrDestroyGC(periodic_gc);
			break;
		default:
			return 0;
			break;
		}
		return 1;
	} else {
		return 0;
	}
}
Example #16
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 #17
0
static void NX_DestroyWindow (_THIS, SDL_Surface * screen)
{
    Dprintf ("enter NX_DestroyWindow\n") ;

    if (! SDL_windowid) {
        if (screen && (screen -> flags & SDL_FULLSCREEN)) {
            screen -> flags &= ~ SDL_FULLSCREEN ;
            NX_LeaveFullScreen (this) ;
        }

        // Destroy the output window
        if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) {
            GrDestroyWindow (SDL_Window) ;
        }
    }
    
    // Free the graphics context
    if (! SDL_GC) {
        GrDestroyGC (SDL_GC) ;
        SDL_GC = 0;
    }

    Dprintf ("leave NX_DestroyWindow\n") ;
}
Example #18
0
/*
 * Destroy windows and eventclient structures used by client.
 * Called by GsDropClient after a client has exited to clean
 * up resources.
 */
void
GsDestroyClientResources(GR_CLIENT * client)
{
	GR_WINDOW     * wp, *nwp;
	GR_PIXMAP     * pp, *npp;
	GR_GC 	      * gp, *ngp;
	GR_REGION     * rp, *nrp;
	GR_FONT       * fp, *nfp;
	GR_IMAGE      * ip, *nip;
	GR_CURSOR     *	cp, *ncp;
	GR_EVENT_CLIENT *ecp, *necp;
	GR_EVENT_CLIENT *pecp = NULL;
	GR_EVENT_LIST	*evp;

printf("Destroy client %d resources\n", client->id);
	/* search window list, destroy windows owned by client*/
	for(wp=listwp; wp; wp=nwp) {
		nwp = wp->next;
		/*
		 * Remove eventclient structures for this client
		 */
		ecp = wp->eventclients;
		while (ecp) {
			necp = ecp->next;
			if (ecp->client == client) {
printf( "  Destroy window %d eventclient mask %08lx\n", wp->id, ecp->eventmask);
				if (ecp == wp->eventclients)
					wp->eventclients = ecp->next;
				else
					pecp->next = ecp->next;
				free(ecp);
			} else
				pecp = ecp;
			ecp = necp;
		}
		if (wp->owner == client) {
printf("  Destroy window %d\n", wp->id);
			GrDestroyWindow(wp->id);
		}
	}

	/* search pixmap list, destroy pixmaps owned by client*/
	for(pp=listpp; pp; pp=npp) {
		npp = pp->next;
		if (pp->owner == client) {
printf("  Destroy pixmap %d\n", pp->id);
			GrDestroyWindow(pp->id);
		}
	}

	/* free gc's owned by client*/
	for(gp=listgcp; gp; gp=ngp) {
		ngp = gp->next;
		if (gp->owner == client) {
printf("  Destroy gc %d\n", gp->id);
			GrDestroyGC(gp->id);
		}
	}

	/* free fonts owned by client*/
	for(fp=listfontp; fp; fp=nfp) {
		nfp = fp->next;
		if (fp->owner == client) {
printf("  Destroy font %d\n", fp->id);
			GrDestroyFont(fp->id);
		}
	}

	/* free regions owned by client*/
	for(rp=listregionp; rp; rp=nrp) {
		nrp = rp->next;
		if (rp->owner == client) {
printf("  Destroy region %d\n", rp->id);
			GrDestroyRegion(rp->id);
		}
	}

	/* free images owned by client*/
	for(ip=listimagep; ip; ip=nip) {
		nip = ip->next;
		if (ip->owner == client) {
printf("  Destroy image %d\n", ip->id);
			GrFreeImage(ip->id);
		}
	}

	/* free cursors owned by client*/
	for(cp=listcursorp; cp; cp=ncp) {
		ncp = cp->next;
		if (cp->owner == client) {
printf("  Destroy cursor %d\n", cp->id);
			GrDestroyCursor(cp->id);
		}
	}

	/* Free events associated with client*/
	evp = client->eventhead;
	while (evp) {
printf("  Destroy event %d\n", evp->event.type);
		client->eventhead = evp->next;
		evp->next = eventfree;
		eventfree = evp;
		evp = client->eventhead;
	}
}
Example #19
0
/* Create a new sprite from the specified image file. Returns the address of
 * the new sprite on success or 0 on failure. If width is -1, the real
 * dimensions of the image file will be used, otherwise the image will be
 * scaled up or down to the specified dimensions. */
sprite *load_sprite(nbstate *state, unsigned char *fname, int width, int height)
{
	sprite *s;
	GR_DRAW_ID a;
	GR_DRAW_ID p;
	GR_IMAGE_ID img;
	GR_IMAGE_INFO ii;

	/* Make sure the file name has been specified: */
	if (! fname) return 0;

	/* Try to find a sprite in the list with the specified filename and
	 * dimensions (any dimensions are OK if width is -1). If one is found,
	 * increment its usage count and return its address. */
	for(s = state->spritelist; s; s = s->next) {
		if ((width == -1 || (width == s->w && height == s->h)) &&
		    s->fname && !strcmp(fname, s->fname)) {
			s->usage++;
			return s;
		}
	}
#ifdef HAVE_FILEIO
	{
	/* Make the full path to the filename because the Nano-X server
	 * probably isn't running from the game data directory: */
	char buf[256];
	if (snprintf(buf, 256, "%s/%s", state->gamedir, fname) >= 256){
		debug_printf ("Warning: image path \"%s/%s\" is too long\n",
				state->gamedir, fname);
		return 0;
	}

	/* Try to load the image file, and return 0 on failure: */
	img = GrLoadImageFromFile (buf, 0);
	}
#else
	if      (strcmp (fname, (unsigned char*)   "nbb1.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb1_data, sizeof(   nbb1_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb2.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb2_data, sizeof(   nbb2_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb3.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb3_data, sizeof(   nbb3_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb4.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb4_data, sizeof(   nbb4_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb5.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb5_data, sizeof(   nbb5_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb6.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb6_data, sizeof(   nbb6_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb7.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb7_data, sizeof(   nbb7_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb8.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb8_data, sizeof(   nbb8_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb9.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb9_data, sizeof(   nbb9_data), 0);
	else if (strcmp (fname, (unsigned char*)"nbball1.gif") == 0) img = GrLoadImageFromBuffer ((char*)nbball1_data, sizeof(nbball1_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbat1.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbat1_data, sizeof( nbbat1_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbat2.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbat2_data, sizeof( nbbat2_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbat3.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbat3_data, sizeof( nbbat3_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbg10.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbg10_data, sizeof( nbbg10_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg1.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg1_data, sizeof(  nbbg1_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg2.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg2_data, sizeof(  nbbg2_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg3.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg3_data, sizeof(  nbbg3_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg4.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg4_data, sizeof(  nbbg4_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg5.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg5_data, sizeof(  nbbg5_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg6.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg6_data, sizeof(  nbbg6_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg7.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg7_data, sizeof(  nbbg7_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg8.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg8_data, sizeof(  nbbg8_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg9.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg9_data, sizeof(  nbbg9_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpf.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpf_data, sizeof(   nbpf_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpn.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpn_data, sizeof(   nbpn_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpp.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpp_data, sizeof(   nbpp_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbps.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbps_data, sizeof(   nbps_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpt.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpt_data, sizeof(   nbpt_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpw.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpw_data, sizeof(   nbpw_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbsp1.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbsp1_data, sizeof(  nbsp1_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbsp2.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbsp2_data, sizeof(  nbsp2_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbsp3.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbsp3_data, sizeof(  nbsp3_data), 0);
	else {
		debug_printf ("No such image: \"%s\"\n", fname);
		uos_halt (0);
		return 0;
	}
#endif
	if (! img) {
		debug_printf ("Warning: failed to load image \"%s\"- make "
				"sure it is where the server can find it and "
				"that support for loading the relevant image "
				"type has been built into the server\n", fname);
		return 0;
	}

	/* If a size wasn't specified, get the real image size from the server
	 * instead: */
	if(width == -1 || height == -1) {
		GrGetImageInfo(img, &ii);
		width = ii.width;
		height = ii.height;
	}

	/* Make the alpha channel and pixmap to store the image in: */
	if(!(a = GrNewPixmap(width, height, 0))) {
		GrFreeImage(img);
		return 0;
	}
	if(!(p = GrNewPixmap(width, height, 0))) {
		GrFreeImage(img);
		GrDestroyWindow(a);
		return 0;
	}

	/* Draw the image into the specified pixmap and alpha channel, scaling
	 * it up or down if necessary: */
	GrDrawImageToFit(p, state->gc, 0, 0, width, height, img);
	GrFreeImage(img); /* Destroy the server image object. */

	/* Make a new sprite and link it into the list, then return its
	 * address to the caller: */
	s = make_sprite(state, fname, width, height, p, a);
	if (! s) {
		GrDestroyWindow(a);
		GrDestroyWindow(p);
		return 0;
	}

	return s;
}
Example #20
0
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);
}
Example #21
0
/* Assign an arbitrary char to the cursor */
Cursor
XCreateGlyphCursor(Display * display, Font source_font, Font mask_font,
		   unsigned int source_char, unsigned int mask_char,
		   XColor XCONST * foreground, XColor XCONST * background)
{
	Cursor		ret;
	int		tw[2], th[2], tb[2];
	unsigned char	ch[2];
	GR_GC_ID	gc;
	GR_WINDOW_ID	cursor;
	GR_COLOR	fc, bc;
	GR_RECT		cbb, mbb;
	GR_FONT_INFO	srcinfo, maskinfo;

	gc = GrNewGC();
	/*GrSetGCUseBackground(gc, GR_FALSE);*/ /* assume NewGC defaults TRUE*/
	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	GrSetGCBackground(gc, GR_RGB(  0,   0,   0));

	/* Draw both the fonts into their appropriate pixmap, and create the cursor */
	GrGetFontInfo((GR_FONT_ID) source_font, &srcinfo);
	GrGetFontInfo((GR_FONT_ID) mask_font, &maskinfo);

	ch[0] = srcinfo.firstchar + source_char;
	ch[1] = maskinfo.firstchar + mask_char;

	/* Use the mask as the determining size */
	GrSetGCFont(gc, (GR_FONT_ID) mask_font);

	GrGetGCTextSize(gc, &ch[0], 1, GR_TFTOP, &tw[0], &th[0], &tb[0]);
	GrGetGCTextSize(gc, &ch[1], 1, GR_TFTOP, &tw[1], &th[1], &tb[1]);

	cursor = GrNewPixmap(tw[1] * 2, th[1], 0);

	/* Draw the mask first, to avoid having to switch fonts in the GC */
	GrText(cursor, gc, tw[1], 0, &ch[1], 1, GR_TFTOP|GR_TFASCII);

	/* Offset the first char by 1 1 */
	GrSetGCFont(gc, (GR_FONT_ID) source_font);
	GrText(cursor, gc, 1, 1, &ch[0], 1, GR_TFTOP|GR_TFASCII);

	/* Calculate the bounding box */
	cbb.x = 0;
	cbb.y = 0;
	cbb.width = tw[0];
	cbb.height = th[0];

	mbb.x = tw[1];
	mbb.y = 0;
	mbb.width = tw[1];
	mbb.height = th[1];

	fc = GR_RGB(foreground->red >> 8, foreground->green >> 8,
			foreground->blue >> 8);
	bc = GR_RGB(background->red >> 8, background->green >> 8,
			background->blue >> 8);
	/* cursor hotspot is (leftbearing, ascent)*/
	ret = _nxCreateCursor(cursor, &cbb, cursor, &mbb, 0, tb[1],
			fc, bc);

	GrDestroyWindow(cursor);
	GrDestroyGC(gc);
	return ret;
}
Example #22
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;
}
Example #23
0
static int keyman_handle_event(GR_EVENT * event)
{
	int ret = 0;
    switch( event->type )
    {
    case( GR_EVENT_TYPE_TIMER ):
	
	switch(GAMEN){
		
		
		case MENU:
			makemenu();
			
			MINIPHOTO(0,0,160,128);
			wlastkey.AR=0;wlastkey.AL=0;wlastkey.AU=0;wlastkey.AD=0;wlastkey.REE=0;wlastkey.PAU=0;
			break;
		case INGAME:
			
		
		
		
			if (wlastkey.AL==1){wnow.LR=-1;wnow.MUKI=-1;}
			else if(wlastkey.AR==1){wnow.LR=1;wnow.MUKI=1;}
			else {wnow.LR=0;}
			
			
			if(wlastkey.REE==1){
					if(wnow.JIMEN==ZIM){
					wnow.YKANSEI=-9;
					wnow.JIMEN=SORA;
					}
					else if (wnow.HASIGO==1){
					wnow.YKANSEI=-9;
					wnow.JIMEN=SORA;
					wnow.HASIGO=0;
					
					}
			}
			
			if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')==FALSE){wnow.HASIGO=0;}
			
			
			
			if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')== TRUE && wlastkey.AU !=0){
				wnow.HASIGO=1;
				wnow.shupict=2;
				//GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,32,112,0);
				wnow.XKANSEI=0;
				//wnow.YLOC=wnow.YLOC-3;
				}
			else if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')== TRUE && wlastkey.AD !=0){
				wnow.HASIGO=0;
				//GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,32,112,0);
				wnow.XKANSEI=0;
				//wnow.YLOC=wnow.YLOC+3;	
				}
				
			
			if (wnow.JIMEN==ZIM){wnow.XKANSEI=(0.9*wnow.XKANSEI)+(1*wnow.LR);}
			else {
				if (wnow.LR != 0){
				wnow.XKANSEI=(0.99*wnow.XKANSEI)+(0.3*wnow.LR);
				}
			}
			if (wnow.HASIGO==0 ){
				if (wnow.YKANSEI <= 6){
					wnow.YKANSEI++;
				}
			}
			else {wnow.YKANSEI=0;}
			
			
			

			
			wnow.XLOC=wnow.XLOC+wnow.XKANSEI;
			wnow.YLOC=wnow.YLOC+wnow.YKANSEI;
			
			
			if (wnow.NUPDW==-1 && ((wnow.MAPSCROLL) % 16)==0){wnow.YLOC=wnow.YLOC+16;}
			else if (wnow.NUPDW==1 && (wnow.MAPSCROLL % 16)==15){wnow.YLOC=wnow.YLOC-16;}
			
			
			
			if (wnow.MAPSCROLL>0 && wnow.MAPSCROLL<TATEHABA*16){
				wnow.MAPSCROLL=wnow.MAPSCROLL+wnow.NUPDW;
			}
			scr= (wnow.MAPSCROLL/16);
			ATARI2();
						
			
			if (wlastkey.AU != 1 && wlastkey.AD != 1){
			 if (wnow.MUKI==1){
			 wnow.shupict=0;
			 //GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,0,112,0);
			 }
			 else {
			 wnow.shupict=1;
			 //GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,16,112,0);
			 }
			}			
			
						
			if (wnow.NUPDW==-1 && wnow.YLOC>136){
				wdeady.sp=-20;
				wdeady.g=1.6;
				wdeady.nowt=128;
				GAMEN=END;
				wdeady.kaiten=0;
				ketumatu=0;
				wdeady.deadcount=1;}
				
			else if(wnow.NUPDW==1 && wnow.YLOC<0){
				wdeady.sp=12;
				wdeady.g=0;
				wdeady.nowt=-16;
				GAMEN=END;
				wdeady.kaiten=0;
				ketumatu=0;
				wdeady.deadcount=1;}
			else if (wnow.NUPDW==0 && (wnow.YLOC>136)) {
			
				wdeady.sp=-10;
				wdeady.g=1.6;
				wdeady.nowt=128;
				GAMEN=END;
				wdeady.kaiten=0;
				ketumatu=0;
				wdeady.deadcount=1;}
					
				
			
			GrCopyArea(mainmenu_pixmap,keyman_gc,0,0,160,128,allmap_pixmap,0,wnow.MAPSCROLL,0);
			kmbitmap();
			//GrCopyArea(mainmenu_pixmap,keyman_gc,wnow.XLOC,(wnow.YLOC-(wnow.MAPSCROLL % 16)),160,128,shu_pixmap,0,0,0);
			hensu();		
			
			MINIPHOTO(0,0,160,128);
			if (wlastkey.PAU==1){GAMEN=PAUSE;}
			
			wlastkey.AR=0;wlastkey.AL=0;wlastkey.AU=0;wlastkey.AD=0;wlastkey.REE=0;wlastkey.PAU=0;
			break;
		case PAUSE:
			GrCopyArea(dialogall_pixmap,keyman_gc,0,0,96,80,dialog_pixmap,0,0,0);
			GrCopyArea(dialogall_pixmap,keyman_gc,3,24+(dialogkey*24),13,16,yomipict_pixmap,115,48,0);
			GrCopyArea(keyman_wid,keyman_gc,32+((screen_info.cols-160)/2),24+((screen_info.rows-128)/2),96,80,dialogall_pixmap,0,0,0);
			
			break;
		case END:
				if (ketumatu==0){
					wdeady.sp=wdeady.sp+wdeady.g;
					wdeady.nowt=wdeady.nowt+wdeady.sp;
					//sprintf(hensuu,"%d",wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW));
					
					if (wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW)>0 && wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW)<TATEHABA*16){
						GrCopyArea(mainmenu_pixmap,keyman_gc,0,0,160,128,allmap_pixmap,0,wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW),0);
					}
					
					GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,wdeady.kaiten*16,16,0);
					GrCopyArea(mainmenu_pixmap,keyman_gc,wnow.XLOC,wdeady.nowt,160,128,shu_pixmap,0,0,0);
					hensu();
					
					MINIPHOTO(0,0,160,128);
					if (wdeady.kaiten<7){wdeady.kaiten++;}else{wdeady.kaiten=0;}
					if (training==0){
						if (wdeady.deadcount>31){GAMEN=MENU;
					
						}   
					}
					else if (training==1){
						if (wdeady.deadcount>15){opencard();GAMEN=INGAME;
						}
						
					}
					wdeady.deadcount++;
				}
				else if (ketumatu==1){
					if (training==0){
					GAMEN=MENU;
					}
					if (training==1){
						if (tranum>=MAXTRA){
							GAMEN=MENU;
						}
						else{
							startgame();
							GAMEN=INGAME;
						}
					
					}
				}
			break;
		case NODATA:
			GrSetGCForeground(keyman_gc, WHITE);
			GrFillRect(keyman_wid,keyman_gc,0,0,160,128);
			
			GrSetGCForeground(keyman_gc, GRAY);
			GrLine(keyman_wid,keyman_gc,80,20,34,100);
			GrLine(keyman_wid,keyman_gc,80,20,126,100);
			GrLine(keyman_wid,keyman_gc,34,100,126,100);
			GrEllipse(keyman_wid,keyman_gc,80,55,5,20);
			GrEllipse(keyman_wid,keyman_gc,80,85,5,5);
			
			GrSetGCForeground(keyman_gc, BLACK);
			GrText(keyman_wid,keyman_gc,50,48,"Please Copy",-1,GR_TFASCII|GR_TFTOP);
			GrText(keyman_wid,keyman_gc,30,68,"KMData folder to /etc",-1,GR_TFASCII|GR_TFTOP);
			GrText(keyman_wid,keyman_gc,50,100,"Click to Quit",-1,GR_TFASCII|GR_TFTOP);
			break;
		}
		
			
	break;
	

    case( GR_EVENT_TYPE_KEY_DOWN ):
	
	switch(GAMEN){
		case INGAME:
			if (event->keystroke.ch==wsetkey.KLEFT){wlastkey.AL=1;}else{wlastkey.AL=0;}
			if (event->keystroke.ch==wsetkey.KRIGHT){wlastkey.AR=1;}else{wlastkey.AR=0;}
			if (event->keystroke.ch==wsetkey.KUP){wlastkey.AU=1;}else{wlastkey.AU=0;}
			if (event->keystroke.ch==wsetkey.KDOWN){wlastkey.AD=1;}else{wlastkey.AD=0;}
			if (event->keystroke.ch==wsetkey.KJUMP){wlastkey.REE=1;}else{wlastkey.REE=0;}
			if (event->keystroke.ch==wsetkey.KPAUSE){wlastkey.PAU=1;}else{wlastkey.PAU=0;}
			break;
		case MENU:
			switch( event->keystroke.ch )
			{
	    
			case '\r': /* action */
				switch (wmenukey.BA){
				case 0:if (wmenukey.KEY<2){wmenukey.KEY++;}else{wmenukey.KEY=1;}break;	
				case 1:if (wmenukey.STAGE<MAXSTAGE){wmenukey.STAGE++;}
						else {wmenukey.STAGE=1;}
						break;
				
				case 2: GAMEN=INGAME; 
					training=0;
					startgame();
					break;
				case 3:GAMEN=INGAME;
					tranum=0;
					training=1;
					startgame();
					break;
				case 4: pz_close_window(keyman_wid);
					GrDestroyTimer(keyman_timer);
					GrUnmapWindow(keyman_wid);
					GrDestroyWindow(keyman_wid);
					GrFreeImage(kmimage_id);
					GrDestroyGC(keyman_gc);
					ret = 1;
					break;
				}
			break;
			case 'r': /* CCW spin */
			if (wmenukey.BA<4){ipod_beep();wmenukey.BA++;}		
			break;

			case 'l': /* CW spin */
			if (wmenukey.BA>0){ipod_beep();wmenukey.BA--;}
			break;
			
			case 'm': /* menu */
					pz_close_window(keyman_wid);
					GrDestroyTimer(keyman_timer);
					GrUnmapWindow(keyman_wid);
					GrDestroyWindow(keyman_wid);
					GrFreeImage(kmimage_id);
					GrDestroyGC(keyman_gc);
					ret = 1;		
			break;
			}
			break;
			
					
		case PAUSE:
			if (event->keystroke.ch==wsetkey.KLEFT && dialogkey == 1){ipod_beep();dialogkey=0;}
			if (event->keystroke.ch==wsetkey.KRIGHT && dialogkey == 0){ipod_beep();dialogkey=1;}
			if (event->keystroke.ch==wsetkey.KJUMP && dialogkey == 0){GAMEN=INGAME;}
			else if (event->keystroke.ch==wsetkey.KJUMP && dialogkey == 1){GAMEN=MENU;}
			
			break;
		case END:break;
		case NODATA:
			if (event->keystroke.ch=='\r'){
			GrDestroyTimer(keyman_timer);
			GrUnmapWindow(keyman_wid);
			GrDestroyWindow(keyman_wid);
			GrFreeImage(kmimage_id);
			GrDestroyGC(keyman_gc);
			ret = 1;
			}
			break;
		}
	
	
	
	break;
    }

    return ret;
}
Example #24
0
/*
 * Destroy windows and eventclient structures used by client.
 * Called by GsDropClient after a client has exited to clean
 * up resources.
 */
void
GsDestroyClientResources(GR_CLIENT * client)
{
	GR_WINDOW     * wp, *nwp;
	GR_PIXMAP     * pp, *npp;
	GR_GC 	      * gp, *ngp;
	GR_REGION     * rp, *nrp;
	GR_FONT       * fp, *nfp;
	GR_CURSOR     *	cp, *ncp;
	GR_EVENT_CLIENT *ecp, *necp;
	GR_EVENT_CLIENT *pecp = NULL;
	GR_EVENT_LIST	*evp;
	GR_GRABBED_KEY	*kp, *nkp;
#if MW_FEATURE_IMAGES
	GR_IMAGE      * ip, *nip;
#endif
#if MW_FEATURE_TIMERS
	GR_TIMER      * tp, *ntp;
#endif

DPRINTF("Destroy client %d resources\n", client->id);
	/* search window list, destroy windows owned by client*/
	for(wp=listwp; wp; wp=nwp) {
		nwp = wp->next;
		/*
		 * Remove eventclient structures for this client
		 */
		ecp = wp->eventclients;
		while (ecp) {
			necp = ecp->next;
			if (ecp->client == client) {
DPRINTF( "  Destroy window %d eventclient mask %08lx\n", wp->id, ecp->eventmask);
				if (ecp == wp->eventclients)
					wp->eventclients = ecp->next;
				else
					pecp->next = ecp->next;
				free(ecp);
			} else
				pecp = ecp;
			ecp = necp;
		}
		if (wp->owner == client) {
DPRINTF("  Destroy window %d\n", wp->id);
			GrDestroyWindow(wp->id);
		}
	}

	/* search pixmap list, destroy pixmaps owned by client*/
	for(pp=listpp; pp; pp=npp) {
		npp = pp->next;
		if (pp->owner == client) {
DPRINTF("  Destroy pixmap %d\n", pp->id);
			GrDestroyWindow(pp->id);
		}
	}

	/* free gc's owned by client*/
	for(gp=listgcp; gp; gp=ngp) {
		ngp = gp->next;
		if (gp->owner == client) {
DPRINTF("  Destroy gc %d\n", gp->id);
			GrDestroyGC(gp->id);
		}
	}

	/* free fonts owned by client*/
	for(fp=listfontp; fp; fp=nfp) {
		nfp = fp->next;
		if (fp->owner == client) {
DPRINTF("  Destroy font %d\n", fp->id);
			GrDestroyFont(fp->id);
		}
	}

	/* free regions owned by client*/
	for(rp=listregionp; rp; rp=nrp) {
		nrp = rp->next;
		if (rp->owner == client) {
DPRINTF("  Destroy region %d\n", rp->id);
			GrDestroyRegion(rp->id);
		}
	}

#if MW_FEATURE_IMAGES
	/* free images owned by client*/
	for(ip=listimagep; ip; ip=nip) {
		nip = ip->next;
		if (ip->owner == client) {
DPRINTF("  Destroy image %d\n", ip->id);
			GrFreeImage(ip->id);
		}
	}
#endif

#if MW_FEATURE_TIMERS
	/* free timers owned by client*/
	for(tp=list_timer; tp; tp=ntp) {
		ntp = tp->next;
		if (tp->owner == client) {
DPRINTF("  Destroy timer %d\n", tp->id);
			GrDestroyTimer(tp->id);
		}
	}
#endif

	/* free cursors owned by client*/
	for(cp=listcursorp; cp; cp=ncp) {
		ncp = cp->next;
		if (cp->owner == client) {
DPRINTF("  Destroy cursor %d\n", cp->id);
			GrDestroyCursor(cp->id);
		}
	}

	/* Free key grabs associated with client*/
	for (kp=list_grabbed_keys; kp; kp = nkp) {
		nkp = kp->next;
		if (kp->owner == curclient) {
DPRINTF("  Destroy grabkey %d,%d\n", kp->wid, kp->key);
			GrUngrabKey(kp->wid, kp->key);
		}
	}

	/* Free events associated with client*/
	evp = client->eventhead;
	while (evp) {
DPRINTF("  Destroy event %d\n", evp->event.type);
		client->eventhead = evp->next;
		evp->next = eventfree;
		eventfree = evp;
		evp = client->eventhead;
	}
}
Example #25
0
static int invaders_handle_event(GR_EVENT *event)
{
	int ret = 0;
	static int paused;
	if(game_status) {
		switch(event->type) {
		case ( GR_EVENT_TYPE_TIMER ):
			if (!paused)
				invaders_Game_Loop();
			break;
		case( GR_EVENT_TYPE_KEY_DOWN ):
			switch(event->keystroke.ch) {
			case '\r': /* push button */
				if(me_firing < ME_MAX_FIRES) {
					me_firing++;
					myfire[me_firing - 1].posx = me_posx;
					myfire[me_firing - 1].posy = me_posy -4;
					myfire[me_firing - 1].dir = -2;
				}
				ret |= KEY_CLICK;
				break;

			case 'l':
				GrSetGCForeground(invaders_gc, GR_RGB(255,255,255));
				me_draw();
				GrSetGCForeground(invaders_gc, GR_RGB(0,0,0));

				if(me_still == 'l'){
					me_accel_counter++;
					me_accel = (me_accel_counter < 20) ?
						me_accel_counter / 5 : me_accel;
				} else {
					me_still = 'l';
					me_accel_counter = 0;
					me_accel = 2;
				}
				me_posx = (me_posx <= me_left) ? me_left :
					(me_posx - me_accel);
				me_draw();
				ret |= KEY_CLICK;
				break;
			case 'r':
				GrSetGCForeground(invaders_gc, GR_RGB(255,255,255));
				me_draw();
				GrSetGCForeground(invaders_gc, GR_RGB(0,0,0));

				if(me_still == 'r'){
					me_accel_counter++;
					me_accel = (me_accel_counter < 20) ?
						me_accel_counter / 5 : me_accel;
				} else {
					me_still = 'r';
					me_accel_counter = 0;
					me_accel = 2;
				}
				me_posx = (me_posx >= me_right) ? me_right :
					me_posx + me_accel;
				me_draw();
				ret |= KEY_CLICK;
				break;	
			case 'm':
				/* if Menu Button destroy all dynamically
				 * created */
				pz_close_window(invaders_wid);
				GrDestroyWindow(invaders_score_pix);
				GrDestroyTimer (invaders_timer_id);
				GrDestroyGC(invaders_gc);
				break;
			case 'h':
				paused = 1;
				break;
			default:
				me_still = 0; /* for what key? */
				ret |= KEY_UNUSED; /* right? */
				break;
			}
			break;
		case( GR_EVENT_TYPE_KEY_UP ):
			switch(event->keystroke.ch) {
			case 'h': /* push button */
				paused = 0;
				break;
			default:
				ret |= KEY_UNUSED;
			}
			break;
		default:
			ret |= KEY_UNUSED;
		}
		return ret;
	}/* if game status play */
	
	/* END OF GAME */
	if(onetime == 0){
		char game_over[] = "GAME OVER";
		int x = screen_info.cols / 2;
		int y = ((screen_info.rows - 21) / 4) * 3;
		int xp = x - (vector_string_pixel_width(game_over, 1, 2) / 2);
		int yp = y - 8;
		GrSetGCForeground(invaders_gc, GR_RGB(255,255,255));
		GrFillRect(invaders_wid, invaders_gc, xp - 2, yp - 2,
				(x - xp + 2) * 2, (y - yp + 2) * 2);
		GrSetGCForeground(invaders_gc, GR_RGB(0,0,0));
		vector_render_string(invaders_wid, invaders_gc,
				game_over, 1, 2,
				xp, yp);
		gameover_waitcounter = 30;
	}
	onetime = 1;
	gameover_waitcounter--;
	switch(event->type) {
	case( GR_EVENT_TYPE_KEY_DOWN ):
		switch(event->keystroke.ch) {
		case '\r': /* push button */
			if(gameover_waitcounter <= 0) {
				score = 0;
				GrSetGCForeground(invaders_gc, GR_RGB(255,255,255));
				GrFillRect(invaders_wid,invaders_gc,
					0, 0, screen_info.cols,
					screen_info.rows);
				GrSetGCForeground(invaders_gc, GR_RGB(0,0,0));
				level = 0;
				score = 0;
				invaders_create_board(level);
				game_status=GAME_STATUS_PLAY;
				draw_first();
			}
			ret |= KEY_CLICK;
			break;
				
		case 'm':
			/* if Menu Button then destroy all
			 * dynamically created */
			pz_close_window(invaders_wid);
			GrDestroyWindow(invaders_score_pix);
			GrDestroyTimer(invaders_timer_id);
			GrDestroyGC(invaders_gc);
			break;
		default:
			ret |= KEY_UNUSED;
			break;	
		}
		break;
	default:
		ret |= EVENT_UNUSED;
		break;
	}
	return ret;
}