Esempio n. 1
0
void
AG_ButtonSurface(AG_Button *bu, AG_Surface *su)
{
	AG_Surface *suDup = (su != NULL) ? AG_SurfaceDup(su) : NULL;

	AG_ObjectLock(bu);
	if (bu->lbl != NULL) {
		AG_ObjectDetach(bu->lbl);
		AG_ObjectDestroy(bu->lbl);
		bu->lbl = NULL;
	}
	if (bu->surface != -1) {
		AG_WidgetReplaceSurface(bu, bu->surface, suDup);
	} else {
		bu->surface = AG_WidgetMapSurface(bu, suDup);
	}
	AG_ObjectUnlock(bu);
	AG_Redraw(bu);
}
Esempio n. 2
0
/*
 * Draw function. Invoked from GUI rendering context to draw the widget
 * at its current location. All primitive and surface operations operate
 * on widget coordinates.
 */
static void
Draw(void *p)
{
	formaText *my = (formaText*)p;


	/*
	 * Render some text into a new surface. In OpenGL mode, the
	 * AG_WidgetMapSurface() call involves a texture upload.
	 */
	if (my->mySurface == -1) {
		my->mySurface = AG_WidgetMapSurface(my,
		    surf1);
	};


  //AG_WidgetUpdateSurface(my,my->mySurface);
	/* Blit the mapped surface at [0,0]. */
	AG_WidgetBlitSurface(my, my->mySurface, 0, 0);
}
Esempio n. 3
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();
	}
}