static void UpdateSV(AG_HSVPal *pal, int ax, int ay) { float s, v; int x = ax - pal->triangle.x; int y = ay - pal->triangle.y; if (x < -y/2) { x = -y/2; } if (x > y/2) { x = y/2; } if (y > pal->triangle.h-1) { y = pal->triangle.h-1; } s = 1.0 - (float)y/(float)pal->triangle.h; v = 1.0 - (float)(x + y/2)/(float)pal->triangle.h; if (s < 0.0F) { s = 0.00001F; } else if (s > 1.0F) { s = 1.0F; } if (v < 0.0F) { v = 0.0001F; } else if (v > 1.0F) { v = 1.0F; } AG_SetFloat(pal, "saturation", s); AG_SetFloat(pal, "value", v); UpdatePixelFromHSVA(pal); AG_PostEvent(NULL, pal, "sv-changed", NULL); pal->flags |= AG_HSVPAL_DIRTY; AG_Redraw(pal); }
AG_Slider * AG_SliderNewFltR(void *parent, enum ag_slider_type type, Uint flags, float *val, float min, float max) { AG_Slider *sl = AG_SliderNew(parent, type, flags); if (val != NULL) { AG_BindFloat(sl, "value", val); } AG_SetFloat(sl, "min", min); AG_SetFloat(sl, "max", max); return (sl); }
static void UpdateHSVFromRGBAv(AG_HSVPal *hsv) { AG_Variable *bRGBAv; void *RGBAv; Uint8 r, g, b, a; float h, s, v; if ((bRGBAv = AG_GetVariable(hsv, "RGBAv", &RGBAv)) == NULL) { return; } switch (AG_VARIABLE_TYPE(bRGBAv)) { case AG_VARIABLE_FLOAT: r = (Uint8)(((float *)RGBAv)[0] * 255.0); g = (Uint8)(((float *)RGBAv)[1] * 255.0); b = (Uint8)(((float *)RGBAv)[2] * 255.0); a = (Uint8)(((float *)RGBAv)[3] * 255.0); break; case AG_VARIABLE_DOUBLE: r = (Uint8)(((double *)RGBAv)[0] * 255.0); g = (Uint8)(((double *)RGBAv)[1] * 255.0); b = (Uint8)(((double *)RGBAv)[2] * 255.0); a = (Uint8)(((double *)RGBAv)[3] * 255.0); break; case AG_VARIABLE_INT: r = (Uint8)(((int *)RGBAv)[0]); g = (Uint8)(((int *)RGBAv)[1]); b = (Uint8)(((int *)RGBAv)[2]); a = (Uint8)(((int *)RGBAv)[3]); break; case AG_VARIABLE_UINT8: r = ((Uint8 *)RGBAv)[0]; g = ((Uint8 *)RGBAv)[1]; b = ((Uint8 *)RGBAv)[2]; a = ((Uint8 *)RGBAv)[3]; break; default: r = 0; g = 0; b = 0; a = 0; break; } AG_RGB2HSV(r, g, b, &h, &s, &v); AG_SetFloat(hsv, "hue", h); AG_SetFloat(hsv, "saturation", s); AG_SetFloat(hsv, "value", v); SetAlpha8(hsv, a); AG_UnlockVariable(bRGBAv); hsv->flags |= AG_HSVPAL_DIRTY; AG_Redraw(hsv); }
static void UpdateHSVFromPixel(AG_HSVPal *hsv, Uint32 pixel) { Uint8 r, g, b, a; float h, s, v; AG_Variable *bFormat; AG_PixelFormat **pFormat; bFormat = AG_GetVariable(hsv, "pixel-format", &pFormat); AG_GetPixelRGBA(pixel, *pFormat, &r,&g,&b,&a); AG_RGB2HSV(r, g, b, &h,&s,&v); AG_SetFloat(hsv, "hue", h); AG_SetFloat(hsv, "saturation", s); AG_SetFloat(hsv, "value", v); SetAlpha8(hsv, a); AG_UnlockVariable(bFormat); AG_Redraw(hsv); }
bool GuiConfig::Write(const string &option, const float &value) { if(!option.size()) return true; if(AG_SetFloat(agConfig, option.c_str(), value) == NULL) return true; return false; }
static void PasteColor(AG_Event *event) { AG_HSVPal *pal = AG_PTR(1); AG_ObjectLock(pal); AG_MutexLock(&CopyLock); AG_SetFloat(pal, "hue", cH); AG_SetFloat(pal, "saturation", cS); AG_SetFloat(pal, "value", cV); AG_SetFloat(pal, "alpha", cA); AG_MutexUnlock(&CopyLock); UpdatePixelFromHSVA(pal); pal->flags |= AG_HSVPAL_DIRTY; AG_PostEvent(NULL, pal, "h-changed", NULL); AG_PostEvent(NULL, pal, "sv-changed", NULL); AG_ObjectUnlock(pal); AG_Redraw(pal); }
static void SetComplementaryColor(AG_Event *event) { AG_HSVPal *pal = AG_PTR(1); float hue; AG_ObjectLock(pal); hue = AG_GetFloat(pal, "hue"); AG_SetFloat(pal, "hue", ((int)hue+180) % 359); UpdatePixelFromHSVA(pal); pal->flags |= AG_HSVPAL_DIRTY; AG_PostEvent(NULL, pal, "h-changed", NULL); AG_PostEvent(NULL, pal, "sv-changed", NULL); AG_ObjectUnlock(pal); AG_Redraw(pal); }
static void UpdateHue(AG_HSVPal *pal, int x, int y) { float h; h = Atan2((float)y, (float)x); if (h < 0) { h += (float)(2*AG_PI); } AG_SetFloat(pal, "hue", h/(2*AG_PI)*360.0); UpdatePixelFromHSVA(pal); AG_PostEvent(NULL, pal, "h-changed", NULL); pal->flags |= AG_HSVPAL_DIRTY; AG_Redraw(pal); }
void agar_gui_widget_set_float (AG_Widget *w, const char *binding, float val) { AG_SetFloat (w, binding, val); }