Example #1
0
// draw 2 line deep 3d inset roundrect
void graphics_api::draw3dInsetRoundRect(MWCOORD x, MWCOORD y, MWCOORD w, MWCOORD h, MWCOORD r)
{
	MWCOLORVAL BTNSHADOW = MWRGB(162, 141, 104);
	MWCOLORVAL BTNHIGHLIGHT = MWRGB(234, 230, 221);
	MWCOLORVAL WINDOWFRAME = MWRGB(  0,   0,   0);
	MWCOLORVAL C3DLIGHT = MWRGB(213, 204, 187);
	MWPIXELVAL orgPixelVal = gr_foreground;

	draw3dRoundRect(x, y, w, h, r, BTNSHADOW, BTNHIGHLIGHT);
	++x; ++y; w -= 2; h -= 2;
	draw3dRoundRect(x, y, w, h, r-2, WINDOWFRAME, C3DLIGHT);

	gr_foreground = orgPixelVal;
}
Example #2
0
GR_COLOR get_random_colour(int min_brightness)
{
	int r, g, b;

	do {	
		r = RANDRANGE(0, 255);
		g = RANDRANGE(0, 255);
		b = RANDRANGE(0, 255);
	} while((r + g + b) / 3 < min_brightness);

	return(MWRGB(r, g, b));
}
Example #3
0
/*
 * Clear the specified area of a window and possibly make an exposure event.
 * This sets the area window to its background color or pixmap.  If the
 * exposeflag is 1, then this also creates an exposure event for the window.
 * For buffered windows, mark drawing finalized and draw if
 * exposeflag = 2.
 */
void
GsClearWindow(GR_WINDOW *wp, GR_COORD x, GR_COORD y, GR_SIZE width, GR_SIZE  height, int exposeflag)
{
	if (!wp->realized || !wp->output)
		return;

	/*
	 * Reduce the arguments so that they actually lie within the window.
	 */
	if (x < 0) {
		width += x;
		x = 0;
	}
	if (y < 0) {
		height += y;
		y = 0;
	}
	if (x + width > wp->width)
		width = wp->width - x;
	if (y + height > wp->height)
		height = wp->height - y;

	/*
	 * Now see if the region is really in the window.  If not, then
	 * do nothing.
	 */
	if (x >= wp->width || y >= wp->height || width <= 0 || height <= 0)
		return;

	/*
	 * Buffered window drawing. First check if drawing finalized and
	 * set flag.  Physical window background erase is never performed
	 * with buffered windows, all drawing is postponed until the application
	 * is finished by calling GrClearWindow(..., 2), ie. GrFlushWindow()
	 */
	if (exposeflag == 2)
		wp->props |= GR_WM_PROPS_DRAWING_DONE;

	if (wp->props & GR_WM_PROPS_BUFFERED) {

		/* nothing to do until drawing finalized*/
		if (!(wp->props & GR_WM_PROPS_DRAWING_DONE))
			return;

		/* prepare clipping to window boundaries*/
		GsSetClipWindow(wp, NULL, 0);
		clipwp = NULL;		/* reset clip cache since no user regions used*/

#if DEBUG_EXPOSE
curgcp = NULL;
GdSetFillMode(GR_FILL_SOLID);
GdSetMode(GR_MODE_COPY);
GdSetForegroundColor(wp->psd, MWRGB(255,255,0)); /* yellow*/
GdFillRect(wp->psd, wp->x+x, wp->y+y, width, height);
usleep(500000);
#endif

		/* copy window pixmap buffer to window*/
		GdBlit(wp->psd, wp->x + x, wp->y + y, width, height, wp->buffer->psd, x, y, MWROP_COPY);
		return;				/* don't deliver exposure events*/
	}

	/*
	 * Unbuffered window: erase background unless nobackground flag set
	 */
	if (!(wp->props & GR_WM_PROPS_NOBACKGROUND)) {
		/* perhaps find a better way of determining whether pixmap needs src_over*/
		int hasalpha = wp->bgpixmap && (wp->bgpixmap->psd->data_format & MWIF_HASALPHA);

		/*
	 	 * Draw the background of the window.
	 	 * Invalidate the current graphics context since
	 	 * we are changing the foreground color and mode.
	 	 */
		GsSetClipWindow(wp, NULL, 0);
		clipwp = NULL;		/* reset clip cache since no user regions used*/

#if DEBUG_EXPOSE
GdSetFillMode(GR_FILL_SOLID);
GdSetMode(GR_MODE_COPY);
GdSetForegroundColor(wp->psd, MWRGB(255,255,0)); /* yellow*/
GdFillRect(wp->psd, wp->x+x, wp->y+y, width, height);
usleep(500000);
#endif

		curgcp = NULL;
		GdSetFillMode(GR_FILL_SOLID);
		GdSetMode(GR_MODE_COPY);
		GdSetForegroundColor(wp->psd, wp->background);

		/* if background pixmap w/alpha channel and stretchblit, fill entire (clipped) window*/
		if (hasalpha && wp->bgpixmapflags == GR_BACKGROUND_STRETCH)
				GdFillRect(wp->psd, wp->x, wp->y, wp->width, wp->height);
		else /* if no pixmap background clear exposed area*/
			if (!wp->bgpixmap || hasalpha)	/* FIXME will flash with pixmap, should check src_over*/
				if (!(wp->bgpixmapflags & GR_BACKGROUND_TRANS))
					GdFillRect(wp->psd, wp->x + x, wp->y + y, width, height);

		if (wp->bgpixmap)
			GsDrawBackgroundPixmap(wp, wp->bgpixmap, x, y, width, height);
	}

	/*
	 * Do the exposure if required for unbuffered windows.
	 */
	if (exposeflag)
		GsDeliverExposureEvent(wp, x, y, width, height);
}
Example #4
0
/*
 * Open low level graphics driver
 */
PSD
GdOpenScreen(void)
{
	PSD			psd;
	MWPALENTRY *		stdpal;
	MWSCREENINFO		sinfo;	    

	psd = scrdev.Open(&scrdev);
	if (!psd)
		return NULL;
	GdGetScreenInfo(psd, &sinfo);
	gr_pixtype = sinfo.pixtype;
	gr_ncolors = sinfo.ncolors;

	/* assume no user changable palette entries*/
	gr_firstuserpalentry = (int)psd->ncolors;

	/* set palette according to system colors and devpalX.c*/
	switch((int)psd->ncolors) {

#if !defined(NOSTDPAL1) /* don't require stdpal1 if not needed */
	case 2:		/* 1bpp*/
	{
		extern MWPALENTRY	mwstdpal1[2];
		stdpal = mwstdpal1;
	}
	break;
#endif

#if !defined(NOSTDPAL2) /* don't require stdpal2 if not needed */
	case 4:		/* 2bpp*/
	{
		extern MWPALENTRY	mwstdpal2[4];
		stdpal = mwstdpal2;
	}
	break;
#endif

#if !defined(NOSTDPAL4)
	/* don't require stdpal4 if not needed */
	case 8:		/* 3bpp - not fully supported*/
	case 16:	/* 4bpp*/
	{
		extern MWPALENTRY	mwstdpal4[16];
		stdpal = mwstdpal4;
	}
	break;
#endif

#if !defined(NOSTDPAL8) /* don't require large stdpal8 if not needed */
	case 256:	/* 8bpp*/
	{
		extern MWPALENTRY	mwstdpal8[256];
#if xxxALPHABLEND
		/* don't change uniform palette if alpha blending*/
		gr_firstuserpalentry = 256;
#else
		/* start after last system-reserved color*/
		gr_firstuserpalentry = FIRSTUSERPALENTRY;
#endif
		stdpal = mwstdpal8;
	} 
	break;
#endif	/* !defined(NOSTDPAL8)*/

	default:	/* truecolor*/
		/* no palette*/
		gr_firstuserpalentry = 0;
		stdpal = NULL;
	}

	/* reset next user palette entry, write hardware palette*/
	GdResetPalette();
	GdSetPalette(psd, 0, (int)psd->ncolors, stdpal);
#if xxxALPHABLEND
	/* one-time create alpha lookup table for 8bpp systems (takes ~1 sec)*/
	if(psd->ncolors == 256)
		init_alpha_lookup();
#endif

#if !NOFONTSORCLIPPING
	/* init local vars*/
	GdSetMode(MWMODE_COPY);
	GdSetForeground(GdFindColor(MWRGB(255, 255, 255)));	/* WHITE*/
	GdSetBackground(GdFindColor(MWRGB(0, 0, 0)));		/* BLACK*/
	GdSetUseBackground(TRUE);
	GdSetFont(GdCreateFont(psd, MWFONT_SYSTEM_VAR, 0, NULL));
#if DYNAMICREGIONS
	GdSetClipRegion(psd, 
		GdAllocRectRegion(0, 0, psd->xvirtres, psd->yvirtres));
#else
	GdSetClipRects(psd, 0, NULL);
#endif /* DYNAMICREGIONS*/
#endif /* NOFONTSORCLIPPING*/

	/* fill black (actually fill to first palette entry or truecolor 0*/
	psd->FillRect(psd, 0, 0, psd->xvirtres-1, psd->yvirtres-1, 0);
	return psd;
}
Example #5
0
/**
 * Open low level graphics driver.
 *
 * @return The screen drawing surface.
 */
PSD
GdOpenScreen(void)
{
	PSD			psd;
	MWPALENTRY *		stdpal;

	psd = scrdev.Open(&scrdev);
	if (!psd)
		return NULL;

	/* assume no user changable palette entries*/
	gr_firstuserpalentry = (int)psd->ncolors;

	/* set palette according to system colors and devpalX.c*/
	switch((int)psd->ncolors) {

#if !defined(NOSTDPAL1) /* don't require stdpal1 if not needed */
	case 2:		/* 1bpp*/
	{
		extern MWPALENTRY	mwstdpal1[2];
		stdpal = mwstdpal1;
	}
	break;
#endif

#if !defined(NOSTDPAL2) /* don't require stdpal2 if not needed */
	case 4:		/* 2bpp*/
	{
		extern MWPALENTRY	mwstdpal2[4];
		stdpal = mwstdpal2;
	}
	break;
#endif

#if !defined(NOSTDPAL4)
	/* don't require stdpal4 if not needed */
	case 8:		/* 3bpp - not fully supported*/
	case 16:	/* 4bpp*/
	{
		extern MWPALENTRY	mwstdpal4[16];
		stdpal = mwstdpal4;
	}
	break;
#endif

#if !defined(NOSTDPAL8) /* don't require large stdpal8 if not needed */
	case 256:	/* 8bpp*/
	{
		extern MWPALENTRY	mwstdpal8[256];
#if UNIFORMPALETTE
		/* don't change uniform palette if alpha blending*/
		gr_firstuserpalentry = 256;
#else
		/* start after last system-reserved color*/
		gr_firstuserpalentry = FIRSTUSERPALENTRY;
#endif
		stdpal = mwstdpal8;
	} 
	break;
#endif	/* !defined(NOSTDPAL8)*/

	default:	/* truecolor*/
		/* no palette*/
		gr_firstuserpalentry = 0;
		stdpal = NULL;
	}

	/* reset next user palette entry, write hardware palette*/
	GdResetPalette();
	GdSetPalette(psd, 0, (int)psd->ncolors, stdpal);

	/* init local vars*/
	GdSetMode(MWROP_COPY);
	GdSetFillMode(MWFILL_SOLID);  /* Set the fill mode to solid */

	GdSetForegroundColor(psd, MWRGB(255, 255, 255));	/* WHITE*/
	GdSetBackgroundColor(psd, MWRGB(0, 0, 0));		/* BLACK*/
	GdSetUseBackground(TRUE);
	/* select first builtin font (usually MWFONT_SYSTEM_VAR)*/
	//GdSetFont(GdCreateFont(psd, NULL, 0, 0, NULL));

	GdSetDash(0, 0);  /* No dashing to start */
	GdSetStippleBitmap(0,0,0);  /* No stipple to start */

#if !NOCLIPPING
#if DYNAMICREGIONS
	GdSetClipRegion(psd, GdAllocRectRegion(0, 0, psd->xvirtres, psd->yvirtres));
#else
	GdSetClipRects(psd, 0, NULL);
#endif /* DYNAMICREGIONS*/
#endif /* NOCLIPPING*/

	/* fill black (actually fill to first palette entry or truecolor 0*/
	psd->FillRect(psd, 0, 0, psd->xvirtres-1, psd->yvirtres-1, 0);
	return psd;
}