示例#1
0
文件: nxdraw.c 项目: LucidOne/Rovio
/*
 * Draw 2 line deep 3d outset
 */
void
nxDraw3dOutset(GR_DRAW_ID id,int x,int y,int w,int h)
{
	nxDraw3dBox(id, x, y, w, h,
		GrGetSysColor(GR_COLOR_3DLIGHT),
		GrGetSysColor(GR_COLOR_WINDOWFRAME));
	++x; ++y; w -= 2; h -= 2;
	nxDraw3dBox(id, x, y, w, h,
		GrGetSysColor(GR_COLOR_BTNHIGHLIGHT),
		GrGetSysColor(GR_COLOR_BTNSHADOW));
}
示例#2
0
int
main(int ac, char **av)
{
    GR_EVENT event;
    GR_GC_ID gc;
    GR_WINDOW_ID pmap;
    GR_WINDOW_ID window;
    GR_WINDOW_INFO info;

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

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

    GrSelectEvents(window, GR_EVENT_MASK_EXPOSURE |
		   GR_EVENT_MASK_UPDATE | GR_EVENT_MASK_CLOSE_REQ);

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

    GrMapWindow(window);

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

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

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

	case GR_EVENT_TYPE_UPDATE:
	    switch (event.update.utype) {
	    case GR_UPDATE_SIZE:
		pmap = resize(event.update.width, event.update.height, pmap);
		break;
	    }
	}
    }
    return 0;
}
示例#3
0
void wm_init(void)
{
	GR_WM_PROPERTIES props;
	win window;
	static int init = 0;
  
	if(!init) {
		init = 1;

		/* 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;
		wm_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);
	}
}
示例#4
0
static void
GrGetSysColorWrapper(void *r)
{
	nxGetSysColorReq *req = r;
	GR_COLOR color = GrGetSysColor(req->index);

	GsWriteType(current_fd, GrNumGetSysColor);
	GsWrite(current_fd, &color, sizeof(color));
}
示例#5
0
文件: nxdraw.c 项目: LucidOne/Rovio
void
nxDraw3dUpFrame(GR_DRAW_ID id, int l, int t, int r, int b)
{
	RECT	rc;
	HBRUSH	hbr;

	SetRect(&rc, l, t, r, b);
	nxDraw3dBox(hDC, rc.left, rc.top,
		rc.right-rc.left, rc.bottom-rc.top,
		GrGetSysColor(GR_COLOR_3DLIGHT),
		GrGetSysColor(GR_COLOR_WINDOWFRAME));
	nxInflateRect(&rc, -1, -1);
	nxDraw3dBox(hDC, rc.left, rc.top,
		rc.right-rc.left, rc.bottom-rc.top,
		GrGetSysColor(GR_COLOR_BTNHIGHLIGHT),
		GrGetSysColor(GR_COLOR_BTNSHADOW));
	nxInflateRect(&rc, -1, -1);

	hbr = CreateSolidBrush(GrGetSysColor(GR_COLOR_APPWINDOW));
	FillRect(hDC, &rc, hbr);
	DeleteObject(hbr);
}
示例#6
0
void
draw_clock(int x, int y, int w, int h, GR_WINDOW_ID pmap, GR_GC_ID gc,
	   GR_WINDOW_ID window)
{
    int i;

    GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_WINDOW));
    GrFillRect(pmap, gc, 0, 0, w, h);

    tick();
    push_matrix();
    translate(x + w / 2.0 - .5, y + h / 2.0 - .5);
    scale_xy((w - 1) / 28.0, (h - 1) / 28.0);
    if (type() == ROUND_CLOCK) {
	GrSetGCForeground(gc, BLACK);
	begin_polygon();
	circle(0, 0, 14, pmap, gc, w, h);
	end_polygon(pmap, gc);
	GrSetGCForeground(gc, BLACK);
	begin_loop();
	circle(0, 0, 14, pmap, gc, w, h);
	end_loop(pmap, gc);
    }
    //draw the shadows
    push_matrix();
    translate(0.60, 0.60);
    draw_clock_hands(LTGRAY, LTGRAY, pmap, gc);
    pop_matrix();
    //draw the tick marks
    push_matrix();
    GrSetGCForeground(gc, BLACK);
    for (i = 0; i < 12; i++) {
	if (6 == i)
	    rect(-0.5, 9, 1, 2, pmap, gc);
	else if (3 == i || 0 == i || 9 == i)
	    rect(-0.5, 9.5, 1, 1, pmap, gc);
	else
	    rect(-0.25, 9.5, .5, 1, pmap, gc);
	rotate(-30);
    }
    pop_matrix();
    //draw the hands
    draw_clock_hands(GRAY, BLACK, pmap, gc);
    pop_matrix();
    GrCopyArea(window, gc, 0, 0, w, h, pmap, 0, 0, MWROP_SRCCOPY);
}
示例#7
0
int
main(int ac, char **av)
{
	GR_EVENT	event;		/* current event */
	GR_BITMAP	bitmap1fg[7];	/* bitmaps for first cursor */
	GR_BITMAP	bitmap1bg[7];

	if (GrOpen() < 0) {
		fprintf(stderr, "cannot open graphics\n");
		exit(1);
	}
	
	/* create window*/
	w1 = GrNewWindowEx(
		GR_WM_PROPS_NOAUTOMOVE|GR_WM_PROPS_BORDER|GR_WM_PROPS_CAPTION|
		GR_WM_PROPS_CLOSEBOX, "nxclock", GR_ROOT_WINDOW_ID, 
		10, 10, CWIDTH, CHEIGHT, GrGetSysColor(GR_COLOR_WINDOW));
		
	GrSelectEvents(w1, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ);

	gc1 = GrNewGC();
	gc2 = GrNewGC();

	GrSetGCForeground(gc1, GrGetSysColor(GR_COLOR_WINDOW));
	GrSetGCBackground(gc1, GrGetSysColor(GR_COLOR_WINDOWTEXT));
	GrSetGCForeground(gc2, GrGetSysColor(GR_COLOR_WINDOWTEXT));
	GrSetGCBackground(gc2, GrGetSysColor(GR_COLOR_WINDOW));

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

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

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

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

		switch (event.type) {
			case GR_EVENT_TYPE_EXPOSURE:
				do_exposure(&event.exposure);
				break;

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

			case GR_EVENT_TYPE_TIMEOUT:
				do_clock();
				break;
		}
	}
}
示例#8
0
int
main(int ac,char **av)
{
	GR_WINDOW_ID 	w;
	GR_GC_ID	gc;
	GR_FONT_ID	font;
	GR_WINDOW_INFO wi;

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

	//w = GrNewWindowEx(GR_WM_PROPS_APPWINDOW|GR_WM_PROPS_NOBACKGROUND, "Nano-X Demo2",
		//GR_ROOT_WINDOW_ID, 20, 20, 320, 240, BLACK);
	w = GrNewWindowEx(GR_WM_PROPS_BORDER|GR_WM_PROPS_NOBACKGROUND, "Nano-X Demo2",
		GR_ROOT_WINDOW_ID, 20, 20, 320, 240, BLACK);

	gc = GrNewGC();
	//font = GrCreateFontEx("lubI24.pcf", 0, 0, NULL);
	font = GrCreateFontEx("helvB12.pcf.gz", 0, 0, NULL);
	GrSetGCFont(gc, font);

	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);

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

	for (;;) {
		GR_EVENT 	event;

		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);
			GrGetWindowInfo(w, &wi);
			GrError("Exposure:wi.width:%d,wi.height:%d,wi.x:%d,wi.y:%d,wi.parent:%d\n",wi.width,wi.height,wi.x,wi.y,wi.parent);
			break;

		case GR_EVENT_TYPE_BUTTON_DOWN:
			// FIXME unmap window is broken
			GrUnmapWindow(w);
			GrFlush();
			GrMapWindow(w);

			//uncomment to test server error on bad syscall
			//GrMoveWindow(GR_ROOT_WINDOW_ID, 0, 0);

			GrGetWindowInfo(w, &wi);
			GrError("Button:  wi.width:%d,wi.height:%d,wi.x:%d,wi.y:%d,wi.parent:%d\n",wi.width,wi.height,wi.x,wi.y,wi.parent);
			break;

		case GR_EVENT_TYPE_ERROR:
			GrError("demo2: Error (%s) ", event.error.name);
			GrError(nxErrorStrings[event.error.code], event.error.id);
			break;

		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			return 0;
		}
	}
	return 0;
}
示例#9
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;
}
示例#10
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();
}
示例#11
0
文件: nxdraw.c 项目: LucidOne/Rovio
/*
 * Draw 1 line pushed down rectangle
 */
void
nxDraw3dPushDown(GR_DRAW_ID id, int x, int y, int w, int h)
{
	nxDraw3dBox(id, x, y, w, h, GrGetSysColor(GR_COLOR_BTNSHADOW),
		GrGetSysColor(GR_COLOR_BTNSHADOW));
}
示例#12
0
文件: nxdraw.c 项目: LucidOne/Rovio
void
nxPaintNCArea(GR_DRAW_ID id, int w, int h, GR_CHAR *title, GR_BOOL active,
	GR_WM_PROPS props)
{
	int		x = 0;
	int		y = 0;
	GR_GC_ID	gc = GrNewGC();
	GR_FONT_ID	fontid;
	GR_RECT		r;


	if (props & GR_WM_PROPS_APPFRAME) {
		/* draw 2-line 3d border around window*/
		nxDraw3dOutset(id, x, y, w, h);
		x += 2; y += 2; w -= 4; h -= 4;

		/* draw 1-line inset inside border*/
		GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_APPWINDOW));
		GrRect(id, gc, x, y, w, h);
		x += 1; y += 1; w -= 2; h -= 2;
	} else if (props & GR_WM_PROPS_BORDER) {
		/* draw 1-line black border around window*/
		GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_WINDOWFRAME));
		GrRect(id, gc, x, y, w, h);
		x += 1; y += 1; w -= 2; h -= 2;
	}

	if (!(props & GR_WM_PROPS_CAPTION))
		goto out;

	/* fill caption*/
	GrSetGCForeground(gc, 
		GrGetSysColor(active? GR_COLOR_ACTIVECAPTION:
			GR_COLOR_INACTIVECAPTION));
	GrFillRect(id, gc, x, y, w, CYCAPTION);

	/* draw caption text*/
	if (title) {
		GrSetGCForeground(gc,
			GrGetSysColor(active? GR_COLOR_ACTIVECAPTIONTEXT:
				GR_COLOR_INACTIVECAPTIONTEXT));
		GrSetGCUseBackground(gc, GR_FALSE);
		fontid = GrCreateFont(GR_FONT_GUI_VAR, 0, NULL);
		GrSetGCFont(gc, fontid);
		GrText(id, gc, x+4, y-1, title, -1, GR_TFASCII|GR_TFTOP);
		GrDestroyFont(fontid);
	}
	y += CYCAPTION;

	/* draw one line under caption*/
	if (props & GR_WM_PROPS_APPFRAME) {
		GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_APPWINDOW));
		GrLine(id, gc, x, y, x+w-1, y);
	}

	if (props & GR_WM_PROPS_CLOSEBOX) {
		/* draw close box*/
		r.x = x + w - CXCLOSEBOX - 2;
		r.y = y - CYCAPTION + 2;
		r.width = CXCLOSEBOX;
		r.height = CYCLOSEBOX;

		nxDraw3dBox(id, r.x, r.y, r.width, r.height,
			GrGetSysColor(GR_COLOR_BTNHIGHLIGHT),
			GrGetSysColor(GR_COLOR_WINDOWFRAME));
		nxInflateRect(&r, -1, -1);
		GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_APPWINDOW));
		GrFillRect(id, gc, r.x, r.y, r.width, r.height);

		nxInflateRect(&r, -1, -1);
		GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_BTNTEXT));
		GrLine(id, gc, r.x, r.y, r.x+r.width-1, r.y+r.height-1);
		GrLine(id, gc, r.x, r.y+r.height-1, r.x+r.width-1, r.y);
	}

#if 0
	/* fill in client area*/
	y++;
	h -= CYCAPTION+1;
	GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_APPWINDOW));
	GrFillRect(id, gc, x, y, w, h);
#endif

out:
	GrDestroyGC(gc);
}