Пример #1
0
static void
draw_screen(void)
{
	GR_POINT tri[4] = { {5, 115}, {105, 115}, {55, 200}, {5, 115} };
	GR_WINDOW_INFO winfo;
	GR_GC_ID gc;
	char dash1[2] = { 10, 5 };
	char dash2[4] = { 5, 2, 1, 2 };
	char dash3[4] = { 5, 2, 5, 5 };
	char dash4[2] = { 2, 2 };

	GrGetWindowInfo(g_main, &winfo);

	/* Draw several lines and a few boxes */
	gc = GrNewGC();
	GrSetGCLineAttributes(gc, GR_LINE_ONOFF_DASH);

	/* Draw a dashed box */

	GrSetGCDash(gc, dash1, 2);
	GrRect(g_main, gc, 5, 5, 100, 100);

	GrSetGCDash(gc, dash2, 4);
	GrLine(g_main, gc, 10, 10, 95, 95);

	GrSetGCDash(gc, dash3, 4);
	GrEllipse(g_main, gc, 160, 55, 50, 50);

	GrSetGCDash(gc, dash4, 2);
	GrPoly(g_main, gc, 4, tri);

	GrDestroyGC(gc);
}
Пример #2
0
static void credits_exit(void)
{
	credits_free_var();
	GrDestroyGC(credits_gc);
	GrDestroyTimer(credits_timer);
	pz_close_window(credits_wid);
}
Пример #3
0
void drawText(GR_WINDOW_ID id, char **text, int count) {

    int tw, th, tb;
    int xpos, ypos;
    int i;

    GR_GC_ID gc = GrNewGC();
    GR_FONT_ID font = GrCreateFont(GR_FONT_GUI_VAR, 12, 0);
    GR_WINDOW_INFO info;

    GrGetWindowInfo(id, &info);

    GrSetGCFont(gc, font);
    GrSetGCForeground(gc, FGCOLOR);
    GrSetGCBackground(gc, BGCOLOR);

    /* Get the first line of text from the array, and check the size */
    GrGetGCTextSize(gc, text[0], -1, GR_TFTOP, &tw, &th, &tb);

    ypos = (info.height - ((count * th)+ 3)) / 2;

    /* Draw each line of the instructions */

    for(i = 0; i < count; i++) {
        GrGetGCTextSize(gc, text[i], -1, GR_TFTOP, &tw, &th, &tb);
        xpos = (info.width - tw) / 2;
        GrText(id, gc, xpos, ypos, text[i], -1, GR_TFTOP);

        ypos += th + 3;
    }

    GrDestroyGC(gc);
    GrDestroyFont(font);
}
Пример #4
0
static void
GrDestroyGCWrapper(void *r)
{
	nxDestroyGCReq *req = r;

	GrDestroyGC(req->gcid);
}
Пример #5
0
/* exit, release all created stuff */
void lights_exit( void ) 
{
	GrDestroyTimer( lights_timer );
	GrDestroyGC( lights_gc );
	pz_close_window( lights_wid );
	GrDestroyWindow( lights_bufwid );
}
Пример #6
0
void generator_destruct()
{
	if(lookup_table != NULL) 
		free(lookup_table);
	dsp_close(&dspz);
	pz_close_window( generator_wid );
	GrDestroyGC( generator_gc );
}
Пример #7
0
void
draw_set(char *name, int mode)
{
	int x;
	int tw, th, tb;
	GR_POINT points[4];
	GR_GC_ID gc = GrNewGC();

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

	GrGetGCTextSize(gc, name, -1, GR_TFTOP, &tw, &th, &tb);

	x = g_x + (tw - 50) / 2;

	GrText(g_main, gc, g_x, 5, name, -1, GR_TFTOP);

	g_x += (tw + 10);

	GrSetGCFillMode(gc, mode);

	if (mode == GR_FILL_STIPPLE)
		GrSetGCForeground(gc, YELLOW);
	else {
		GrSetGCForeground(gc, WHITE);
		GrSetGCBackground(gc, BLUE);
	}

	if (mode == GR_FILL_TILE) {
		GrSetGCTile(gc, g_pixmap, 16, 16);
	}

	if (mode == GR_FILL_STIPPLE || mode == GR_FILL_OPAQUE_STIPPLE)
		GrSetGCStipple(gc, g_stipple2, 2, 2);

	GrFillRect(g_main, gc, x, 25, 50, 50);

	if (mode == GR_FILL_STIPPLE || mode == GR_FILL_OPAQUE_STIPPLE)
		GrSetGCStipple(gc, g_stipple1, 7, 7);

	GrFillEllipse(g_main, gc, x + 25, 105, 25, 25);

	if (mode == GR_FILL_STIPPLE || mode == GR_FILL_OPAQUE_STIPPLE)
		GrSetGCStipple(gc, g_stipple3, 3, 2);

	points[0].x = points[3].x = x;
	points[0].y = points[3].y = 165;

	points[1].x = x + 50;
	points[1].y = 165;

	points[2].x = x + 25;
	points[2].y = 215;

	GrFillPoly(g_main, gc, 4, points);

	GrDestroyGC(gc);
}
Пример #8
0
void show_buffer(void)
{
  GR_GC_ID gc = GrNewGC();

  GrCopyArea(swindow, gc, 0, 0, WWIDTH, WHEIGHT, 
			offscreen, 0, 0, MWROP_SRCCOPY);

  GrDestroyGC(gc);
}
Пример #9
0
void
load_pixmap(void)
{
	GR_GC_ID gc = GrNewGC();

	g_pixmap = GrNewPixmap(16, 16, 0);
	GrDrawImageFromFile(g_pixmap, gc, 0, 0, -1, -1, "bin/nxroach.pgm", 0);

	GrDestroyGC(gc);
}
Пример #10
0
static void msg_destroy_msg()
{
	int i;

	pz_close_window(msg_wid);
	GrDestroyGC(msg_gc);
	GrDestroyTimer(msg_timer);
	for(i = linenum; i; i--)
		free(msglines[i-1]);
	free(msglines);
}
Пример #11
0
static int dialer_do_keystroke(GR_EVENT * event) {
    int ret = 0;

    switch(event->type) {
    case GR_EVENT_TYPE_KEY_DOWN:
        switch (event->keystroke.ch) {
        case IPOD_BUTTON_ACTION:
            dialer_press_button(current_dialer_button);
            draw_dialer();
            ret |= KEY_CLICK;
            break;

        case IPOD_WHEEL_ANTICLOCKWISE:
            last_bouvet_item = current_dialer_button;
            current_dialer_button--;
            draw_dialer();
            ret |= KEY_CLICK;
            break;

        case IPOD_WHEEL_CLOCKWISE:
            last_bouvet_item = current_dialer_button;
            current_dialer_button++;
            draw_dialer();
            ret |= KEY_CLICK;
            break;

        case IPOD_BUTTON_MENU:
        case 'q':
#ifdef __linux__
            dsp_close(&dspz);
#endif
            GrDestroyGC(dialer_gc);
            pz_close_window(dialer_wid);
            ret |= KEY_CLICK;
            break;

        default:
            ret |= KEY_UNUSED;
            break;
        }
        break;

    default:
        ret |= EVENT_UNUSED;
        break;
    }
    return ret;
}
Пример #12
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);
	
}
Пример #13
0
/* When pressing menu - quits*/
void do_menu(void)
{
	int i;
	FILE *writefile;

	readint = 0;

	/* Save last board */
	printf("Save last board \n");
	pz_draw_header("Saving board...");
	if ((writefile = fopen(LASTGAME, "w"))) {
		for (i = 0; i < 64; i++) {
			writeint = piece[i];
			fwrite(&writeint,sizeof(writeint),1,writefile);
		}
		for (i = 0; i < 64; i++) {
			writeint = color[i];
			fwrite(&writeint,sizeof(writeint),1,writefile);
		}
		fwrite(&historic_line1, sizeof(historic_line1), 1, writefile);
		fwrite(&historic_line2, sizeof(historic_line2), 1, writefile);
		fwrite(&historic_line3, sizeof(historic_line3), 1, writefile);
		fwrite(&historic_line4, sizeof(historic_line4), 1, writefile);
		fwrite(&historic_line5, sizeof(historic_line5), 1, writefile);
		fwrite(&historic_line6, sizeof(historic_line6), 1, writefile);
		fclose(writefile);
	}
	else {
		printf("Cant write %s\n", LASTGAME);
	}

	if (end == 2) {
		pz_close_window(end_wid);
	}

	if (is_mini) {
		pz_close_window(message_wid);
	}
	else {
		pz_close_window(historic_wid);
	}

	pz_close_window(tuxchess_wid);

	GrDestroyGC(tuxchess_gc);
}
Пример #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;
}
Пример #15
0
static void
draw_string(GR_WINDOW_ID wid)
{
	int count = 0;
	int x = border;
	int y = border;
	unsigned int start, end;
	unsigned int ch;
	GR_GC_ID gc = GrNewGC();

	GrSetGCBackground(gc, GR_RGB(0, 0, 0));
	GrSetGCFont(gc, font);

	if (first_char > finfo.lastchar)
		first_char = 0;
	if (first_char + chars_to_show <= finfo.firstchar)
		first_char = (finfo.firstchar / line_width) * line_width;

	start = first_char;
	end = first_char + chars_to_show;

	printf("drawing chars %d to %d\n", start, end - 1);

	for (ch = start; ch < end; ch++) {
		GrSetGCForeground(gc, GR_RGB(64, 64, 64));
		GrFillRect(wid, gc, x-1, y-1, finfo.maxwidth+2, finfo.height+2);
		GrSetGCForeground(gc, GR_RGB(255, 255, 255));

		if (ch >= finfo.firstchar && ch <= finfo.lastchar)
			GrText(wid, gc, x, y, &ch, 1, GR_TFTOP | GR_TFUC32);

		if (++count >= line_width) {
			x = border;
			y += finfo.height + spacer;
			count = 0;
		} else
			x += finfo.maxwidth + spacer;
	}

	GrDestroyGC(gc);
}
Пример #16
0
/**
 * Load image from filename and return its ID
*/
GR_WINDOW_ID theme_load_image(char * filename)
{
	GR_GC_ID gc;
	GR_IMAGE_ID iid;
	GR_WINDOW_ID pid;
	GR_IMAGE_INFO iif;

	gc = GrNewGC();
	if(!(iid = GrLoadImageFromFile(filename, 0))) {
		fprintf(stderr, "Failed to load image file \"%s\"\n", filename);
		return 0;
	}
	GrGetImageInfo(iid, &iif);
	pid = GrNewPixmap(iif.width, iif.height, NULL);

	GrDrawImageToFit(pid, gc, 0, 0, iif.width, iif.height, iid);
	GrDestroyGC(gc);
	GrFreeImage(iid);

	return pid;
}
Пример #17
0
/*
 * nxDraw3dShadow
 * 	NOINDENT_BLACK	T=white, B=black
 * 	NOINDENT_GRAY	T=white, B=dkgray
 * 	INDENT_BLACK	T=black, B=white
 * 	INDENT_GRAY		T=dkgray, B=white
 *
 *	TTTTTTTTTTTTTT
 *	T             B
 *	T             B
 *	 BBBBBBBBBBBBBB
 */
void
nxDraw3dShadow(GR_DRAW_ID id,int x,int y,int w,int h,GR_COLOR crTop,
	GR_COLOR crBottom)
{
	GR_GC_ID	gc = GrNewGC();

	GrSetGCForeground(gc, crTop);
	/*MoveToEx( hDC, x, y+h-2, NULL);*/
	/*LineTo( hDC, x, y);*/				/* left side*/
	GrLine(id, gc, x, y+h-2, x, y);			/* left*/
	/*LineTo( hDC, x+w-1, y);*/			/* top side*/
	GrLine(id, gc, x, y, x+w-2, y);			/* top*/

	GrSetGCForeground(gc, crBottom);
	/*MoveToEx( hDC, x+w-1, y+1, NULL);*/
	/*LineTo( hDC, x+w-1, y+h-1);*/			/* right side*/
	GrLine(id, gc, x+w-1, y+1, x+w-1, y+h-2);	/* right*/
	/*LineTo( hDC, x, y+h-1);*/			/* bottom side*/
	GrLine(id, gc, x+w-1, y+h-1, x, y+h-1);		/* bottom*/

	GrDestroyGC(gc);
}
Пример #18
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;
	}
}
Пример #19
0
static int chopHandleEvent (GR_EVENT *event)
{
    switch (event->type)
    {
    case GR_EVENT_TYPE_TIMER:
        chopGameLoop();
        break;
	
	case GR_EVENT_TYPE_KEY_UP:
	if(event->keystroke.ch == '\r')
		bPlayerPressingUp = 0;
		break;

    case GR_EVENT_TYPE_KEY_DOWN:
    	if(bWaitingToStart == 1)
	{
	
	iPlayerSpeedY = 5;
    	bWaitingToStart = 0;
	
	}
        switch (event->keystroke.ch)
        {
        case '\r': /* Wheel button */
            bPlayerPressingUp = 1;
	    break;
         case 'm': /* Menu button */
            pz_close_window (chopWindow);
            GrDestroyTimer (chopTimer);
            GrDestroyGC(chopGC);
            break;
        default:
            break;
        }
        break;   /* key down */
    }
    return 1;
}
Пример #20
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;
}
Пример #21
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") ;
}
Пример #22
0
static int browser_do_keystroke(GR_EVENT * event)
{
	int ret = 0;

	switch(event->type) {
	case GR_EVENT_TYPE_TIMER:
		if(((GR_EVENT_TIMER *)event)->tid == browser_key_timer) {
			GrDestroyTimer(browser_key_timer);
			browser_key_timer = 0;
			menu_handle_timer(browser_menu, 1);
			browser_action(browser_menu->items[browser_menu->sel].orig_pos);
			browser_do_draw();
		}
		else
			menu_draw_timer(browser_menu);
		break;

	case GR_EVENT_TYPE_KEY_DOWN:
		switch (event->keystroke.ch) {
		case '\r':
		case '\n':
			if(browser_menu->parent == NULL)
				browser_key_timer = GrCreateTimer(browser_wid,
						500);
			else {
				menu_handle_timer(browser_menu, 1);
				browser_menu = menu_handle_item(browser_menu, 
						browser_menu->sel);
				if(browser_menu_overlay) {
					browser_menu = browser_menu_overlay;
					browser_menu_overlay = 0;
				}
				browser_do_draw();
			}	
			break;

		case 'm':
		case 'q':
			browser_menu = menu_destroy(browser_menu);
			ret |= KEY_CLICK;
			if(browser_menu != NULL) {
				browser_do_draw();
				break;
			}
			browser_exit();
			GrDestroyGC(browser_gc);
			pz_close_window(browser_wid);
			break;

		case 'r':
			if (menu_shift_selected(browser_menu, 1)) {
				menu_draw(browser_menu);
				ret |= KEY_CLICK;
			}
			break;

		case 'l':
			if (menu_shift_selected(browser_menu, -1)) {
				menu_draw(browser_menu);
				ret |= KEY_CLICK;
			}
			break;
		default:
			ret |= KEY_UNUSED;
		}
		break;
	case GR_EVENT_TYPE_KEY_UP:
		switch (event->keystroke.ch) {
		case '\r':
		case '\n':
			if(browser_key_timer) {
				GrDestroyTimer(browser_key_timer);
				browser_key_timer = 0;
				menu_handle_timer(browser_menu, 1);
				browser_selection_activated(browser_menu->items[browser_menu->sel].orig_pos);
				browser_do_draw();
			}
			break;
		}
		break;
	default:
		ret |= EVENT_UNUSED;
		break;
	}
	return ret;
}
Пример #23
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;
	}
}
Пример #24
0
void wm_container_buttondown(win *window, GR_EVENT_BUTTON *event)
{
	struct pos_size *pos;
	GR_RECT		r;
	GR_COORD	cxborder = 0, cyborder = 0;
	GR_WINDOW_INFO	info;
	GR_WINDOW_INFO	cinfo;
	GR_GC_ID        gc;
	Dprintf("wm_container_buttondown window %d\n", window->wid);

	if(window->active)
		return;

	GrGetWindowInfo(window->wid, &info);
	GrGetWindowInfo(window->clientid, &cinfo);

	/* calc border sizes*/
	if (info.props & GR_WM_PROPS_BORDER) {
		cxborder = 1;
		cyborder = 1;
	}
	if (info.props & GR_WM_PROPS_APPFRAME) {
		cxborder = CXBORDER;
		cyborder = CYBORDER;
	}

	/* Check for close box press*/
	if ((info.props & (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) ==
	    (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) {

		/* Get close box rect*/
		r.x = info.width - CXCLOSEBOX - cxborder - 2;
		r.y = cyborder + 2;
		r.width = CXCLOSEBOX;
		r.height = CYCLOSEBOX;

		/* Check mousedn in close box*/
		if (PtInRect(&r, event->x, event->y)) {
			/* close on button up*/
			window->close = GR_TRUE;
      		return;
		}
	}

	/* 
	 * Set focus to the window only if client 
	 * or the container itself is clicked.
	 * if any of the  children (of the client)
	 * are clicked better not take the focus 
	 * away from them. They might require handling
	 * the focus themself.
	 * -- Amit Kulkarni
	 */
	if(window->wid==event->subwid)
		GrSetFocus(window->wid);

	/* check for corner resize */
	r.x = info.width - 5;
	r.y = info.height - 5;
	r.width = 5;
	r.height = 5;

	if (PtInRect(&r,event->x, event->y)
	   && !(info.props & GR_WM_PROPS_NORESIZE) && !(cinfo.props & GR_WM_PROPS_NORESIZE)) {
#if !NO_CORNER_RESIZE
	  struct pos_size * pos;

	  if(!window->data)
	    if(!(window->data = malloc(sizeof(struct pos_size))))
			return;

	  window->sizing = GR_TRUE;
	  
	  /* save off the width/height offset from the window manager */
	  GrGetWindowInfo(window->clientid,&info);
	  pos = (struct pos_size*)window->data;
	  pos->xoff = -info.width;
	  pos->yoff = -info.height;

	  GrGetWindowInfo(window->wid,&info);
	  pos->xoff += info.width;
	  pos->yoff += info.height;

	  gc = GrNewGC();
	  GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	  GrRect(GR_ROOT_WINDOW_ID,gc,info.x, info.y, info.width, info.height);
	  GrDestroyGC(gc);

	  /* save this rectangle's width/height so we can erase it later */
	  pos->width = info.width;
	  pos->height = info.height;
      pos->xorig = event->x;
      pos->yorig = event->y;

	  /*
	   * This window is being resized.
	   * The client should have focus now.
	   * -- Amit Kulkarni
	   */
	  GrSetFocus(window->clientid);	  

	  return;
#endif /* !NO_CORNER_RESIZE*/
	} else
		GrSetWindowCursor(window->wid, 0);

	/* if not in caption, return (FIXME, not calc'd exactly)*/
	if (!(info.props & GR_WM_PROPS_CAPTION))
		return;

	/* Get caption box rect*/
	r.x = cxborder;
	r.y = cyborder;
	r.width = info.width - cxborder*2;
	r.height = CYCAPTION;

	/* Check for mousedn in caption box*/
	if (!PtInRect(&r, event->x, event->y))
		return;
	
	/*
	 * Now we have a click on the caption. 
	 * So window is active. 
	 * Set focus to the client
	 * --Amit Kulkarni
	 */	
	GrSetFocus(window->clientid);

	/* Raise window if mouse down and allowed*/
	if (!(info.props & GR_WM_PROPS_NORAISE) && !(cinfo.props & GR_WM_PROPS_NORAISE))
		GrRaiseWindow(window->wid);

	/* Don't allow window move if NOMOVE property set*/
	if ((info.props & GR_WM_PROPS_NOMOVE) || (cinfo.props & GR_WM_PROPS_NOMOVE))
		return;

	if(!window->data)
		if(!(window->data = malloc(sizeof(struct pos_size))))
			return;

	GrGetWindowInfo(window->wid,&info);
	pos = (struct pos_size *)window->data;
	pos->xoff = event->x;
	pos->yoff = event->y;

#if OUTLINE_MOVE
	pos->xorig = info.x;
	pos->yorig = info.y;
	pos->width = info.width;
	pos->height = info.height;

	gc = GrNewGC();
	GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	GrRect(GR_ROOT_WINDOW_ID, gc,info.x, info.y, info.width, info.height);
	GrDestroyGC(gc);
#endif	
	window->active = GR_TRUE;
}
Пример #25
0
void wm_container_mousemoved(win *window, GR_EVENT_MOUSE *event)
{
	struct pos_size *pos;
	GR_GC_ID gc;
	GR_RECT r;
	GR_WINDOW_INFO info;

	Dprintf("wm_container_mousemoved window %d\n", window->wid);

	GrGetWindowInfo(window->wid, &info);

	if(window->sizing) {
	  struct pos_size * pos = (struct pos_size*)window->data;

	  /* erase old rectangle */
	  gc = GrNewGC();
	  GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	  GrRect(GR_ROOT_WINDOW_ID, gc, info.x, info.y, pos->width, pos->height);

	  /* draw new one */
	  GrRect(GR_ROOT_WINDOW_ID,gc,info.x, info.y, event->rootx - info.x, event->rooty - info.y);
	  GrDestroyGC(gc);

	  /* save this new rectangle's width, height */
	  /* I know, this shouldn't be stored in x/y, but... */
	  pos->width = event->rootx - info.x;
	  pos->height = event->rooty - info.y;
	  return;
	}

#if !NO_CORNER_RESIZE
	/* check corner resize cursor on/off*/
	r.x = info.width - 5;
	r.y = info.height - 5;
	r.width = 5;
	r.height = 5;
	if (PtInRect(&r,event->x, event->y))
		set_resize_cursor(window->wid);
	else
		GrSetWindowCursor(window->wid, 0);
#endif

	if(!window->active)
		return;

	pos = (struct pos_size *)window->data;
#if OUTLINE_MOVE
	gc = GrNewGC();
	GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	GrRect(GR_ROOT_WINDOW_ID,gc,pos->xorig, pos->yorig, pos->width, pos->height);
	GrRect(GR_ROOT_WINDOW_ID,gc,event->rootx - pos->xoff, event->rooty - pos->yoff,
	       pos->width, pos->height);

	pos->xorig = event->rootx - pos->xoff;
	pos->yorig = event->rooty - pos->yoff;
	
	GrDestroyGC(gc);
#else	
	GrMoveWindow(window->wid, event->rootx - pos->xoff, event->rooty - pos->yoff);
#endif
}
Пример #26
0
void wm_container_buttonup(win *window, GR_EVENT_BUTTON *event)
{
	GR_RECT		r;
	GR_COORD	cxborder = 0, cyborder = 0;
	GR_WINDOW_INFO	info;

	Dprintf("wm_container_buttonup window %d\n", window->wid);

	GrGetWindowInfo(window->wid, &info);

	/* Check for close box press*/
	if ((info.props & (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) ==
	    (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) {

		/* calc border sizes*/
		if (info.props & GR_WM_PROPS_BORDER) {
			cxborder = 1;
			cyborder = 1;
		}
		if (info.props & GR_WM_PROPS_APPFRAME) {
			cxborder = CXBORDER;
			cyborder = CYBORDER;
		}

		/* Get close box rect*/
		r.x = info.width - CXCLOSEBOX - cxborder - 2;
		r.y = cyborder + 2;
		r.width = CXCLOSEBOX;
		r.height = CYCLOSEBOX;

		/* Check mouseup in close box*/
		if (PtInRect(&r, event->x, event->y)) {
			if(window->close == GR_TRUE) {
				/*
				 * This sends a CLOSE_REQ event to the window.
				 * NXLIB clients catch this and convert it
				 * to an X11 ClientMessage with a WM_DELETE_WINDOW
				 * atom, causing the window to close.
				 */
				GrCloseWindow(window->clientid);
        		window->close = GR_FALSE;
        		return;
      		}
		}
	}
	window->close = GR_FALSE;

	if(window->active) {
#if OUTLINE_MOVE
	  struct pos_size * pos = (struct pos_size *)window->data;
	  GR_GC_ID gc = GrNewGC();

	  GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	  GrRect(GR_ROOT_WINDOW_ID, gc, pos->xorig, pos->yorig, pos->width, pos->height);
	  GrMoveWindow(window->wid, pos->xorig, pos->yorig);
	  GrDestroyGC(gc);
#endif
	  free(window->data);
	  window->active = GR_FALSE;
	  window->data = 0;
	}
	
	if(window->sizing) {
	  struct pos_size * pos = (struct pos_size *)window->data;
	  GR_GC_ID gc = GrNewGC();
	  GR_WINDOW_INFO info;
	  GR_SIZE w, h;

	  GrGetWindowInfo(window->wid, &info);
	  GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	  GrRect(GR_ROOT_WINDOW_ID, gc, info.x, info.y, pos->width, pos->height);
	  GrDestroyGC(gc);

	  w = info.width + (event->x - pos->xorig);
	  h = info.height + (event->y - pos->yorig);
	  GrResizeWindow(window->wid, w, h);
	  GrResizeWindow(window->clientid, w - pos->xoff, h - pos->yoff);

	  free(window->data);
	  window->sizing = GR_FALSE;
	  window->data = 0;
	}
}
Пример #27
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;
	}
}
Пример #28
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);
}
Пример #29
0
static int cube_handle_event(GR_EVENT * event)
{
	int ret = 0;
	switch( event->type )
	{
		case( GR_EVENT_TYPE_TIMER ):
			if (!paused) cube_loop();
			break;
		case( GR_EVENT_TYPE_KEY_DOWN ):
			switch( event->keystroke.ch )
			{
				case '\r':
				case '\n': /* action */
					switch( xy_or_z ) {
						case 'x':
							xy_or_z ='y';
							strncpy(t_ax[0], "x", 4);
							strncpy(t_ax[1], "[y]", 4);
							break;
						case 'y':
							xy_or_z ='z';
							strncpy(t_ax[1], "y", 4);
							strncpy(t_ax[2], "[z]", 4);
							break;
						case 'z':
							xy_or_z ='x';
							strncpy(t_ax[2], "z", 4);
							strncpy(t_ax[0], "[x]", 4);
							break;
					}
					ret |= KEY_CLICK;
					break;
				case 'p': /* play/pause */
				case 'd': /*or this */
					if (t_disp) { t_disp=0; } else { t_disp=1; }
					if (solid) { solid=0; } else { solid=1; }
					break;
				case 'f': /* >>| */
					zoom_in = 1;
					break;
				case 'w': /* |<< */
					zoom_out = 1;
					break;
				case 'l': /* CCW spin */
					switch( xy_or_z )
					{
						case 'x':
							xs-=1;
							if (xs<-10) { xs=-10;}
							break;
						case 'y':
							ys-=1;
							if (ys<-10) { ys=-10;}
							break;
						case 'z':
							zs-=1;
							if (zs<-10) { zs=-10;}
							break;
					}
					break;
				case 'r': /* CW spin */
					switch( xy_or_z )
					{
						case 'x':
							xs+=1;
							if (xs>10) { xs=10;}
							break;
						case 'y':
							ys+=1;
							if (ys>10) { ys=10;}
							break;
						case 'z':
							zs+=1;
							if (zs>10) { zs=10;}
							break;
					}
					break;
				case 'h': /* hold */
					paused=1;
					break;
				case 'm':
					GrDestroyTimer( cube_timer );
					GrDestroyGC( cube_gc );
					pz_close_window( cube_wid );
					ret |= KEY_CLICK;
					break;
			}
			break;
		case( GR_EVENT_TYPE_KEY_UP ):
			switch( event->keystroke.ch )
			{
				case 'f': /* >>| */
					zoom_in = 0;
					break;
				case 'w': /* |<< */
					zoom_out = 0;
					break;
				case 'h': /* hold */
					paused = 0;
					break;
			}
			break;
	}
	return ret;
}
Пример #30
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;
}