Esempio n. 1
0
/********************************************************************************************
>	void BitmapExportPaletteControl::Render(ReDrawInfoType *pInfo)
	Author:		Jonathan_Payne (Xara Group Ltd) <*****@*****.**>
	Created:	19/12/2000
	Returns:	Draw the palette.  This assumes that the pInfo struct contains a DC to draw
				with.
********************************************************************************************/
void BitmapExportPaletteControl::Render(ReDrawInfoType *pInfo)
{
	DocRect PaletteSize(0, 0, pInfo->dx, pInfo->dy);

	//  Create a RenderRegion so that we can draw the control
	RenderRegion *pRender = CreateOSRenderRegion(&PaletteSize, pInfo);
	if (pRender == 0)
		return;	// Could not create a RenderRegion

	// Decide if we are going to render the palette
	if (!m_Palette.GetNumberOfColours())
	{
		// We are not rendering a palette so just draw a grey box
		RenderGrey(&PaletteSize, pRender);
	}
	else
	{
		// Check the selection and mouse over colour are valid
		if (m_SelectedCell > m_Palette.GetNumberOfColours())
			m_SelectedCell = INVALID_COLOUR_VALUE;
		if (m_MouseOverCell > m_Palette.GetNumberOfColours())
			m_MouseOverCell = INVALID_COLOUR_VALUE;

		// We are rendering a full palette
		RenderPalette(&PaletteSize, pRender, pInfo->dy, pInfo->pClipRect);
	}

	DestroyOSRenderRegion(pRender);
}
Esempio n. 2
0
static void
Draw(void *obj)
{
	AG_HSVPal *pal = obj;
	float cur_h, cur_s, cur_v;
	Uint8 r, g, b, a;
	int x, y;

	if (pal->surface == NULL) {
		if ((pal->surface = AG_SurfaceStdGL(WIDTH(pal), HEIGHT(pal)))
		    == NULL) {
			return;
		}
		pal->surfaceId = AG_WidgetMapSurface(pal, pal->surface);
	}
	if (pal->flags & AG_HSVPAL_DIRTY) {
		pal->flags &= ~(AG_HSVPAL_DIRTY);
		RenderPalette(pal);
		AG_WidgetUpdateSurface(pal, pal->surfaceId);
	}

	cur_h = (AG_GetFloat(pal, "hue") / 360.0) * 2*AG_PI;
	cur_s = AG_GetFloat(pal, "saturation");
	cur_v = AG_GetFloat(pal, "value");
	a = (Uint8)(AG_GetFloat(pal, "alpha")*255);

	AG_WidgetBlitFrom(pal, pal, pal->surfaceId, NULL, 0, 0);

	/* Indicate the current selection. */
	AG_DrawCircle(pal,
	    pal->circle.x + (pal->circle.rin + pal->circle.width/2)*Cos(cur_h),
	    pal->circle.y + (pal->circle.rin + pal->circle.width/2)*Sin(cur_h),
	    pal->selcircle_r,
	    AG_ColorRGB(0,0,0));
	
	/* The rendering routine uses (v = 1 - x/h), so (x = -v*h + h). */
	y = (int)((1.0 - cur_s) * (float)pal->triangle.h);
	x = (int)(-(cur_v*(float)pal->triangle.h - (float)pal->triangle.h));
	if (x < 0) { x = 0; }
	if (x > y) { x = y; }
	AG_DrawCircle(pal,
	    pal->triangle.x + x - y/2,
	    pal->triangle.y + y,
	    pal->selcircle_r,
	    AG_ColorRGB(0,0,0));

	x = a*pal->rAlpha.w/255;
	if (x > pal->rAlpha.w-3) { x = pal->rAlpha.w-3; }
	
	AG_HSV2RGB((cur_h*360.0)/(2*AG_PI), cur_s, cur_v, &r, &g, &b);

	/* Draw the color preview. */
	if (!(pal->flags & AG_HSVPAL_NOPREVIEW)) {
		AG_DrawRectFilled(pal,
		    AG_RECT(pal->rAlpha.x, pal->rAlpha.y, pal->rAlpha.w, 8),
		    AG_ColorRGB(r,g,b));
	}

	/* Draw the transparency color preview. */
	if (!(pal->flags & AG_HSVPAL_NOALPHA)) {
		AG_DrawLineV(pal,
		    pal->rAlpha.x + x,
		    pal->rAlpha.y + 1,
		    pal->rAlpha.y + pal->rAlpha.h,
		    AG_ColorRGBA(0,0,0,0));
		AG_DrawLineV(pal,
		    pal->rAlpha.x + x + 1,
		    pal->rAlpha.y + 1,
		    pal->rAlpha.y + pal->rAlpha.h,
		    AG_ColorRGBA(240,240,240,0));
		AG_DrawLineV(pal,
		    pal->rAlpha.x + x + 2,
		    pal->rAlpha.y + 1,
		    pal->rAlpha.y + pal->rAlpha.h,
		    AG_ColorRGBA(0,0,0,0));
	}

	/* Display RGB/HSV values */
	if (pal->flags & (AG_HSVPAL_SHOW_RGB|AG_HSVPAL_SHOW_HSV)) {
		AG_Surface *s;

		/* XXX inefficient */
		AG_PushTextState();
		AG_TextBGColorRGB(0,0,0);
		AG_TextColorRGB(255,255,255);
		if ((pal->flags & AG_HSVPAL_SHOW_RGB) &&
		    (pal->flags & AG_HSVPAL_SHOW_HSV)) {
			s = AG_TextRenderf(
			    "RGB: %u,%u,%u\n"
			    "HSV: %.02f,%.02f,%.02f",
			    r, g, b,
			    (cur_h*360.0)/(2.0*AG_PI),
			    cur_s, cur_v);
		} else if (pal->flags & AG_HSVPAL_SHOW_RGB) {
			s = AG_TextRenderf("RGB: %u,%u,%u", r, g, b);
		} else {
			s = AG_TextRenderf("HSV: %.01f,%.02f,%.02f",
			    (cur_h*360.0)/(2.0*AG_PI),
			    cur_s, cur_v);
		}
		AG_WidgetBlit(pal, s,
		    WIDTH(pal)/2 - s->w/2,
		    pal->rAlpha.y + pal->rAlpha.h/2 - s->h/2);
		AG_SurfaceFree(s);
		AG_PopTextState();
	}
}