Exemplo n.º 1
0
static void
KeyDown(AG_Event *event)
{
	AG_Button *bu = AG_SELF();
	AG_Variable *binding;
	void *pState;
	int keysym = AG_INT(1);
	
	if (AG_WidgetDisabled(bu))
		return;
	if (keysym != AG_KEY_RETURN &&		/* TODO AG_Action */
	    keysym != AG_KEY_KP_ENTER &&
	    keysym != AG_KEY_SPACE) {
		return;
	}
	binding = AG_GetVariable(bu, "state", &pState);
	SetState(bu, binding, pState, 1);
	AG_PostEvent(NULL, bu, "button-pushed", "%i", 1);
	bu->flags |= AG_BUTTON_KEYDOWN;

	if (bu->flags & AG_BUTTON_REPEAT) {
		AG_DelTimer(bu, &bu->repeatTo);
		AG_AddTimer(bu, &bu->delayTo, agKbdDelay,
		    ExpireDelay, "%i", agKbdRepeat);
	}
	AG_UnlockVariable(binding);
}
Exemplo n.º 2
0
static void
MouseButtonDown(AG_Event *event)
{
	AG_Button *bu = AG_SELF();
	int button = AG_INT(1);
	AG_Variable *binding;
	void *pState;
	int newState;
	
	if (AG_WidgetDisabled(bu))
		return;

	if (!AG_WidgetIsFocused(bu))
		AG_WidgetFocus(bu);

	if (button != AG_MOUSE_LEFT)
		return;
	
	binding = AG_GetVariable(bu, "state", &pState);
	if (!(bu->flags & AG_BUTTON_STICKY)) {
		SetState(bu, binding, pState, 1);
	} else {
		newState = !GetState(bu, binding, pState);
		SetState(bu, binding, pState, newState);
		AG_PostEvent(NULL, bu, "button-pushed", "%i", newState);
	}
	AG_UnlockVariable(binding);

	if (bu->flags & AG_BUTTON_REPEAT) {
		AG_DelTimer(bu, &bu->repeatTo);
		AG_PostEvent(NULL, bu, "button-pushed", "%i", 1);
		AG_AddTimer(bu, &bu->delayTo, agMouseSpinDelay,
		    ExpireDelay, "%i", agMouseSpinIval);
	}
}
Exemplo n.º 3
0
static void
MouseButtonUp(AG_Event *event)
{
	AG_Button *bu = AG_SELF();
	int button = AG_INT(1);
	AG_Variable *binding;
	void *pState;
	int x = AG_INT(2);
	int y = AG_INT(3);
		
	if (bu->flags & AG_BUTTON_REPEAT) {
		AG_DelTimer(bu, &bu->repeatTo);
		AG_DelTimer(bu, &bu->delayTo);
		return;
	}
	
	if (AG_WidgetDisabled(bu) ||
	    x < 0 || y < 0 ||
	    x > WIDGET(bu)->w || y > WIDGET(bu)->h) {
		return;
	}
	
	binding = AG_GetVariable(bu, "state", &pState);
	if (GetState(bu, binding, pState) && button == AG_MOUSE_LEFT &&
	    !(bu->flags & AG_BUTTON_STICKY)) {
	    	SetState(bu, binding, pState, 0);
		AG_PostEvent(NULL, bu, "button-pushed", "%i", 0);
	}
	AG_UnlockVariable(binding);
}
Exemplo n.º 4
0
Arquivo: textbox.c Projeto: adsr/agar
/* Set the text from a format string. */
void
AG_TextboxPrintf(AG_Textbox *tb, const char *fmt, ...)
{
	AG_Variable *stringb;
	va_list args;
	char *text;

	AG_ObjectLock(tb->ed);
	stringb = AG_GetVariable(tb->ed, "string", &text);
	if (fmt != NULL && fmt[0] != '\0') {
		va_start(args, fmt);
		Vsnprintf(text, stringb->info.size, fmt, args);
		va_end(args);
		tb->ed->pos = AG_LengthUTF8(text);
	} else {
		text[0] = '\0';
		tb->ed->pos = 0;
	}
	AG_TextboxBufferChanged(tb);
	AG_UnlockVariable(stringb);
	AG_ObjectUnlock(tb->ed);

	/* XXX for AG_Numerical, etc. */
	AG_Redraw(tb);
}
Exemplo n.º 5
0
/* Return the 8-bit representation of the current alpha value. */
static __inline__ Uint8
GetAlpha8(AG_HSVPal *pal)
{
	AG_Variable *bAlpha;
	Uint8 a = 255;
	void *p;

	bAlpha = AG_GetVariable(pal, "alpha", &p);
	switch (AG_VARIABLE_TYPE(bAlpha)) {
	case AG_VARIABLE_FLOAT:
		a = (Uint8)((*(float *)p)*255.0);
		break;
	case AG_VARIABLE_DOUBLE:
		a = (Uint8)((*(double *)p)*255.0);
		break;
	case AG_VARIABLE_INT:
		a = (int)((*(int *)p));
		break;
	case AG_VARIABLE_UINT8:
		a = (int)((*(Uint8 *)p));
		break;
	default:
		break;
	}
	AG_UnlockVariable(bAlpha);
	return (a);
}
Exemplo n.º 6
0
static __inline__ void
SetAlpha8(AG_HSVPal *pal, Uint8 a)
{
	AG_Variable *bAlpha;
	void *pAlpha;

	bAlpha = AG_GetVariable(pal, "alpha", &pAlpha);
	switch (AG_VARIABLE_TYPE(bAlpha)) {
	case AG_VARIABLE_FLOAT:
		*(float *)pAlpha = (float)(((float)a)/255.0);
		break;
	case AG_VARIABLE_DOUBLE:
		*(double *)pAlpha = (double)(((double)a)/255.0);
		break;
	case AG_VARIABLE_INT:
		*(int *)pAlpha = (int)a;
		break;
	case AG_VARIABLE_UINT8:
		*(Uint8 *)pAlpha = (Uint8)a;
		break;
	default:
		break;
	}
	AG_UnlockVariable(bAlpha);
	AG_Redraw(pal);
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
static __inline__ int
GetPosition(AG_Slider *sl, int *x)
{
	AG_Variable *bMin, *bMax, *bVal;
	void *pMin, *pMax, *pVal;

	bVal = AG_GetVariable(sl, "value", &pVal);
	bMin = AG_GetVariable(sl, "min", &pMin);
	bMax = AG_GetVariable(sl, "max", &pMax);

	switch (AG_VARIABLE_TYPE(bVal)) {
	case AG_VARIABLE_FLOAT:		GET_POSITION(float);		break;
	case AG_VARIABLE_DOUBLE:	GET_POSITION(double);		break;
#ifdef HAVE_LONG_DOUBLE
	case AG_VARIABLE_LONG_DOUBLE:	GET_POSITION(long double);	break;
#endif
	case AG_VARIABLE_INT:		GET_POSITION(int);		break;
	case AG_VARIABLE_UINT:		GET_POSITION(Uint);		break;
	case AG_VARIABLE_UINT8:		GET_POSITION(Uint8);		break;
	case AG_VARIABLE_SINT8:		GET_POSITION(Sint8);		break;
	case AG_VARIABLE_UINT16:	GET_POSITION(Uint16);		break;
	case AG_VARIABLE_SINT16:	GET_POSITION(Sint16);		break;
	case AG_VARIABLE_UINT32:	GET_POSITION(Uint32);		break;
	case AG_VARIABLE_SINT32:	GET_POSITION(Sint32);		break;
#ifdef HAVE_64BIT
	case AG_VARIABLE_UINT64:	GET_POSITION(Uint64);		break;
	case AG_VARIABLE_SINT64:	GET_POSITION(Sint64);		break;
#endif
	default:			*x = 0;				break;
	} 
	AG_UnlockVariable(bMax);
	AG_UnlockVariable(bMin);
	AG_UnlockVariable(bVal);
	return (0);
fail:
	AG_UnlockVariable(bMax);
	AG_UnlockVariable(bMin);
	AG_UnlockVariable(bVal);
	return (-1);
}
Exemplo n.º 9
0
static void
Decrement(AG_Slider *sl)
{
	AG_Variable *bVal, *bMin, *bMax, *bInc;
	void *pVal, *pMin, *pMax, *pInc;

	bVal = AG_GetVariable(sl, "value", &pVal);
	bMin = AG_GetVariable(sl, "min", &pMin);
	bMax = AG_GetVariable(sl, "max", &pMax);
	bInc = AG_GetVariable(sl, "inc", &pInc);

	switch (AG_VARIABLE_TYPE(bVal)) {
	case AG_VARIABLE_FLOAT:		DECREMENT(float);		break;
	case AG_VARIABLE_DOUBLE:	DECREMENT(double);	break;
#ifdef HAVE_LONG_DOUBLE
	case AG_VARIABLE_LONG_DOUBLE:	DECREMENT(long double);	break;
#endif
	case AG_VARIABLE_INT:		DECREMENT(int);		break;
	case AG_VARIABLE_UINT:		DECREMENT(Uint);		break;
	case AG_VARIABLE_UINT8:		DECREMENT(Uint8);		break;
	case AG_VARIABLE_SINT8:		DECREMENT(Sint8);		break;
	case AG_VARIABLE_UINT16:	DECREMENT(Uint16);	break;
	case AG_VARIABLE_SINT16:	DECREMENT(Sint16);	break;
	case AG_VARIABLE_UINT32:	DECREMENT(Uint32);	break;
	case AG_VARIABLE_SINT32:	DECREMENT(Sint32);	break;
#ifdef HAVE_64BIT
	case AG_VARIABLE_UINT64:	DECREMENT(Uint64);	break;
	case AG_VARIABLE_SINT64:	DECREMENT(Sint64);	break;
#endif
	default:						break;
	} 

	AG_PostEvent(NULL, sl, "slider-changed", NULL);
	AG_UnlockVariable(bVal);
	AG_UnlockVariable(bMin);
	AG_UnlockVariable(bMax);
	AG_UnlockVariable(bInc);
	AG_Redraw(sl);
}
Exemplo n.º 10
0
static __inline__ void
SeekToPosition(AG_Slider *sl, int x)
{
	AG_Variable *bMin, *bMax, *bVal;
	void *pMin, *pMax, *pVal;

	bVal = AG_GetVariable(sl, "value", &pVal);
	bMin = AG_GetVariable(sl, "min", &pMin);
	bMax = AG_GetVariable(sl, "max", &pMax);

	switch (AG_VARIABLE_TYPE(bVal)) {
	case AG_VARIABLE_FLOAT:		SEEK_TO_POSITION(float);	break;
	case AG_VARIABLE_DOUBLE:	SEEK_TO_POSITION(double);	break;
#ifdef HAVE_LONG_DOUBLE
	case AG_VARIABLE_LONG_DOUBLE:	SEEK_TO_POSITION(long double);	break;
#endif
	case AG_VARIABLE_INT:		SEEK_TO_POSITION(int);		break;
	case AG_VARIABLE_UINT:		SEEK_TO_POSITION(Uint);		break;
	case AG_VARIABLE_UINT8:		SEEK_TO_POSITION(Uint8);	break;
	case AG_VARIABLE_SINT8:		SEEK_TO_POSITION(Sint8);	break;
	case AG_VARIABLE_UINT16:	SEEK_TO_POSITION(Uint16);	break;
	case AG_VARIABLE_SINT16:	SEEK_TO_POSITION(Sint16);	break;
	case AG_VARIABLE_UINT32:	SEEK_TO_POSITION(Uint32);	break;
	case AG_VARIABLE_SINT32:	SEEK_TO_POSITION(Sint32);	break;
#ifdef HAVE_64BIT
	case AG_VARIABLE_UINT64:	SEEK_TO_POSITION(Uint64);	break;
	case AG_VARIABLE_SINT64:	SEEK_TO_POSITION(Sint64);	break;
#endif
	default:							break;
	} 

	AG_PostEvent(NULL, sl, "slider-changed", NULL);
	AG_UnlockVariable(bMax);
	AG_UnlockVariable(bMin);
	AG_UnlockVariable(bVal);
	AG_Redraw(sl);
}
Exemplo n.º 11
0
static void
Draw(void *p)
{
	AG_Button *bu = p;
	AG_Variable *binding;
	void *pState;
	int pressed;
	
	binding = AG_GetVariable(bu, "state", &pState);
	pressed = GetState(bu, binding, pState);
	AG_UnlockVariable(binding);

	if (AG_WidgetEnabled(bu)) {
		AG_DrawBox(bu,
		    AG_RECT(0, 0, WIDTH(bu), HEIGHT(bu)),
		    pressed ? -1 : 1,
		    WCOLOR(bu,0));
	} else {
		AG_DrawBoxDisabled(bu,
		    AG_RECT(0, 0, WIDTH(bu), HEIGHT(bu)),
		    pressed ? -1 : 1,
		    WCOLOR_DEF(bu,0),
		    WCOLOR_DIS(bu,0));
	}

	if (bu->lbl != NULL) {
		AG_WidgetDraw(bu->lbl);
	} else if (bu->surface != -1) {
		int w = WSURFACE(bu,bu->surface)->w;
		int h = WSURFACE(bu,bu->surface)->h;
		int x = 0, y = 0;

		switch (bu->justify) {
		case AG_TEXT_LEFT:	x = bu->lPad;			break;
		case AG_TEXT_CENTER:	x = WIDTH(bu)/2 - w/2;		break;
		case AG_TEXT_RIGHT:	x = WIDTH(bu) - w - bu->rPad;	break;
		}
		switch (bu->valign) {
		case AG_TEXT_TOP:	y = bu->tPad;			break;
		case AG_TEXT_MIDDLE:	y = HEIGHT(bu)/2 - h/2;		break;
		case AG_TEXT_BOTTOM:	y = HEIGHT(bu) - h - bu->bPad;	break;
		}
		if (pressed) {
			x++;
			y++;
		}
		AG_WidgetBlitSurface(bu, bu->surface, x, y);
	}
}
Exemplo n.º 12
0
static void
UpdateFontSelection(AG_FontSelector *fs)
{
	AG_Variable *bFont;
	AG_Font *font, **pFont;

	font = AG_FetchFont(fs->curFace, fs->curSize, fs->curStyle);
	if (font == NULL) {
		AG_TextError(_("Error opening font: %s"), AG_GetError());
		return;
	}
	bFont = AG_GetVariable(fs, "font", &pFont);
	*pFont = font;
	AG_UnlockVariable(bFont);
}
Exemplo n.º 13
0
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);
}
Exemplo n.º 14
0
static void
UpdateAlpha(AG_HSVPal *pal, int x)
{
	AG_Variable *bAlpha;
	void *pAlpha;

	bAlpha = AG_GetVariable(pal, "alpha", &pAlpha);
	switch (AG_VARIABLE_TYPE(bAlpha)) {
	case AG_VARIABLE_FLOAT:
		*(float *)pAlpha = ((float)x)/((float)pal->rAlpha.w);
		if (*(float *)pAlpha > 1.0) {
			*(float *)pAlpha = 1.0;
		} else if (*(float *)pAlpha < 0.0) {
			*(float *)pAlpha = 0.0;
		}
		break;
	case AG_VARIABLE_DOUBLE:
		*(double *)pAlpha = ((double)x)/((double)pal->rAlpha.w);
		if (*(double *)pAlpha > 1.0) {
			*(double *)pAlpha = 1.0;
		} else if (*(double *)pAlpha < 0.0) {
			*(double *)pAlpha = 0.0;
		}
		break;
	case AG_VARIABLE_INT:
		*(int *)pAlpha = x/pal->rAlpha.w;
		if (*(int *)pAlpha > 255) {
			*(int *)pAlpha = 255;
		} else if (*(int *)pAlpha < 0) {
			*(int *)pAlpha = 0;
		}
		break;
	case AG_VARIABLE_UINT8:
		*(Uint8 *)pAlpha = (Uint8)(x/pal->rAlpha.w);
		break;
	default:
		break;
	}
	AG_UnlockVariable(bAlpha);

	UpdatePixelFromHSVA(pal);
	AG_PostEvent(NULL, pal, "a-changed", NULL);
	AG_Redraw(pal);
}
Exemplo n.º 15
0
static void
MouseMotion(AG_Event *event)
{
	AG_Button *bu = AG_SELF();
	AG_Variable *binding;
	int x = AG_INT(1);
	int y = AG_INT(2);
	void *pState;

	if (AG_WidgetDisabled(bu))
		return;

	binding = AG_GetVariable(bu, "state", &pState);
	if (!AG_WidgetRelativeArea(bu, x, y)) {
		if ((bu->flags & AG_BUTTON_STICKY) == 0 &&
		    GetState(bu, binding, pState) == 1) {
			SetState(bu, binding, pState, 0);
		}
	}
	AG_UnlockVariable(binding);
}
Exemplo n.º 16
0
static void
OnShow(AG_Event *event)
{
	AG_Slider *sl = AG_SELF();
	AG_Variable *V;
	
	if ((V = AG_GetVariable(sl, "value", NULL)) == NULL) {
		V = AG_SetInt(sl, "value", 0);
		AG_LockVariable(V);
	}
	switch (AG_VARIABLE_TYPE(V)) {
	case AG_VARIABLE_FLOAT:  SET_DEF(AG_SetFloat, 0.0f, 1.0f, 0.1f); break;
	case AG_VARIABLE_DOUBLE: SET_DEF(AG_SetDouble, 0.0, 1.0, 0.1); break;
#ifdef HAVE_LONG_DOUBLE
	case AG_VARIABLE_LONG_DOUBLE: SET_DEF(AG_SetLongDouble, 0.0l, 1.0l, 0.1l); break;
#endif
	case AG_VARIABLE_INT:    SET_DEF(AG_SetInt, AG_INT_MIN+1, AG_INT_MAX-1, 1); break;
	case AG_VARIABLE_UINT:   SET_DEF(AG_SetUint, 0U, AG_UINT_MAX-1, 1U); break;
	case AG_VARIABLE_UINT8:  SET_DEF(AG_SetUint8, 0U, 0xffU, 1U); break;
	case AG_VARIABLE_SINT8:  SET_DEF(AG_SetSint8, -0x7f, 0x7f, 1); break;
	case AG_VARIABLE_UINT16: SET_DEF(AG_SetUint16, 0U, 0xffffU, 1U); break;
	case AG_VARIABLE_SINT16: SET_DEF(AG_SetSint16, -0x7fff, 0x7fff, 1); break;
	case AG_VARIABLE_UINT32: SET_DEF(AG_SetUint32, 0UL, 0xffffffffUL, 1UL); break;
	case AG_VARIABLE_SINT32: SET_DEF(AG_SetSint32, -0x7fffffffL, 0x7fffffffL, 1L); break;
#ifdef HAVE_64BIT
	case AG_VARIABLE_UINT64: SET_DEF(AG_SetUint64, 0ULL, 0xffffffffffffffffULL, 1ULL); break;
	case AG_VARIABLE_SINT64: SET_DEF(AG_SetSint64, -0x7fffffffffffffffLL, 0x7fffffffffffffffLL, 1LL); break;
#endif
	default: break;
	}
	AG_UnlockVariable(V);

	if ((sl->flags & AG_SLIDER_EXCL) == 0) {
		AG_RedrawOnChange(sl, 100, "value");
		AG_RedrawOnChange(sl, 1000, "min");
		AG_RedrawOnChange(sl, 1000, "max");
	}
}
Exemplo n.º 17
0
static void
UpdatePreview(AG_FontSelector *fs)
{
	AG_Variable *bFont;
	AG_Font **pFont;
	AG_Surface *s;
	
	bFont = AG_GetVariable(fs, "font", &pFont);
	AG_PushTextState();

	if (*pFont != NULL) {
		AG_TextFont(*pFont);
	}
	s = AG_TextRender(_("The Quick Brown Fox Jumps Over The Lazy Dog"));
	if (fs->sPreview == -1) {
		fs->sPreview = AG_WidgetMapSurfaceNODUP(fs, s);
	} else {
		AG_WidgetReplaceSurfaceNODUP(fs, fs->sPreview, s);
	}

	AG_PopTextState();
	AG_UnlockVariable(bFont);
}
Exemplo n.º 18
0
static void
UpdateFaces(AG_Event *event)
{
	AG_Variable *bFont;
	AG_Font **pFont;
	AG_FontSelector *fs = AG_SELF();
	char fontPath[AG_SEARCHPATH_MAX], *pFontPath = &fontPath[0];
	AG_TlistItem *ti;
	char *s;
	int i;
	const int stdSizes[] = { 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
	                         22,24,26,28,32,48,64 };
	const int nStdSizes = sizeof(stdSizes) / sizeof(stdSizes[0]);
	
	bFont = AG_GetVariable(fs, "font", &pFont);
	AG_PushTextState();

	fs->flags &= ~(AG_FONTSELECTOR_UPDATE);

	for (i = 0; i < agBuiltinFontCount; i++) {
		AG_StaticFont *font = agBuiltinFonts[i];

		ti = AG_TlistAdd(fs->tlFaces, NULL, "_%s", font->name);
		ti->p1 = font;
		if (*pFont != NULL &&
		    strcmp(ti->text, OBJECT(*pFont)->name) == 0)
			ti->selected++;
	}

	AG_CopyCfgString("font-path", fontPath, sizeof(fontPath));
	while ((s = AG_Strsep(&pFontPath, ":")) != NULL) {
		AG_Dir *dir;
		int i;

		if ((dir = AG_OpenDir(s)) == NULL) {
			AG_Verbose(_("Ignoring: %s\n"), AG_GetError());
			continue;
		}
		for (i = 0; i < dir->nents; i++) {
			char path[AG_FILENAME_MAX];
			AG_FileInfo info;
			char *file = dir->ents[i], *pExt;

			if (file[0] == '.' ||
			    (pExt = strrchr(file, '.')) == NULL) {
				continue;
			}
			if (strcmp(pExt, ".ttf") != 0 &&
			    strcmp(pExt, ".TTF") != 0)
				continue;

			Strlcpy(path, s, sizeof(path));
			Strlcat(path, AG_PATHSEP, sizeof(path));
			Strlcat(path, file, sizeof(path));

			if (AG_GetFileInfo(path, &info) == -1 ||
			    info.type != AG_FILE_REGULAR) {
				continue;
			}
			ti = AG_TlistAddS(fs->tlFaces, NULL, file);
			if (*pFont != NULL &&
			    strcmp(file, OBJECT(*pFont)->name) == 0)
				ti->selected++;
		}
		AG_CloseDir(dir);
	}

	/* XXX */
	for (i = 0; i < nStdSizes; i++) {
		ti = AG_TlistAdd(fs->tlSizes, NULL, "%d", stdSizes[i]);
		if (*pFont != NULL &&
		    stdSizes[i] == (*pFont)->size)
			ti->selected++;
	}
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Regular"));
	if (*pFont != NULL && (*pFont)->flags == 0) { ti->selected++; }
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Italic"));
	if (*pFont != NULL && (*pFont)->flags == AG_FONT_ITALIC) { ti->selected++; }
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Bold"));
	if (*pFont != NULL && (*pFont)->flags == AG_FONT_BOLD) { ti->selected++; }
	ti = AG_TlistAdd(fs->tlStyles, NULL, _("Bold Italic"));
	if (*pFont != NULL && (*pFont)->flags == (AG_FONT_BOLD|AG_FONT_ITALIC)) { ti->selected++; }

	UpdatePreview(fs);

	AG_UnlockVariable(bFont);
}
Exemplo n.º 19
0
static void
EditNumValues(AG_Event *event)
{
	AG_HSVPal *pal = AG_PTR(1);
	AG_Window *pwin;
	AG_Window *win;
	AG_Numerical *num;
	AG_Variable *b1, *b2;
	float v;

	if ((pwin = AG_ParentWindow(pal)) == NULL)
		return;

	if ((win = AG_WindowNewNamed(AG_WINDOW_NOMAXIMIZE, "hsvpal-%p-numedit",
	    pal)) == NULL) {
		return;
	}
	AG_WindowSetCaption(win, _("Color values"));
	AG_WindowSetPosition(win, AG_WINDOW_LOWER_LEFT, 0);
	AG_WindowSetCloseAction(win, AG_WINDOW_DETACH);
	{
		AG_Variable *bAlpha;
		void *pAlpha;

		num = AG_NumericalNew(win, 0, NULL, _("Hue: "));
		AG_NumericalSizeHint(num, "000");
		AG_WidgetCopyBinding(num, "value", pal, "hue");
		AG_NumericalSetRange(num, 0.0, 359.0);
		AG_NumericalSetIncrement(num, 1);
		AG_NumericalSetPrecision(num, "f", 0);
		
		num = AG_NumericalNew(win, 0, NULL, _("Saturation: "));
		AG_NumericalSizeHint(num, "00.00");
		AG_WidgetCopyBinding(num, "value", pal, "saturation");
		AG_NumericalSetRange(num, 0.0, 1.0);
		AG_NumericalSetIncrement(num, 0.01);
		AG_NumericalSetPrecision(num, "f", 2);

		num = AG_NumericalNew(win, 0, NULL, _("Value: "));
		AG_NumericalSizeHint(num, "00.00");
		AG_WidgetCopyBinding(num, "value", pal, "value");
		AG_NumericalSetRange(num, 0.0, 1.0);
		AG_NumericalSetIncrement(num, 0.01);
		AG_NumericalSetPrecision(num, "f", 2);

		num = AG_NumericalNew(win, 0, NULL, _("Alpha: "));
		AG_NumericalSizeHint(num, "0.000");
		AG_WidgetCopyBinding(num, "value", pal, "alpha");
		bAlpha = AG_GetVariable(pal, "alpha", &pAlpha);
		switch (AG_VARIABLE_TYPE(bAlpha)) {
		case AG_VARIABLE_FLOAT:
		case AG_VARIABLE_DOUBLE:
			AG_NumericalSetRange(num, 0.0, 1.0);
			AG_NumericalSetIncrement(num, 0.005);
			AG_NumericalSetPrecision(num, "f", 3);
			break;
		case AG_VARIABLE_INT:
		case AG_VARIABLE_UINT:
		case AG_VARIABLE_UINT8:
			AG_NumericalSetRange(num, 0.0, 255.0);
			AG_NumericalSetIncrement(num, 1.0);
			AG_NumericalSetPrecision(num, "f", 0);
			break;
		default:
			break;
		}
		AG_UnlockVariable(bAlpha);
	}

	AG_WindowAttach(pwin, win);
	AG_WindowShow(win);
}
Exemplo n.º 20
0
static __inline__ void
UpdatePixelFromHSVA(AG_HSVPal *pal)
{
	Uint8 r, g, b, a;
	AG_Variable *bFormat, *bColor, *bv;
	AG_PixelFormat **pFormat;
	AG_Color *pColor;
	void *v;

	AG_HSV2RGB(AG_GetFloat(pal, "hue"),
	           AG_GetFloat(pal, "saturation"),
		   AG_GetFloat(pal, "value"), &r, &g, &b);
	a = GetAlpha8(pal);
	
	if ((bv = AG_GetVariable(pal, "RGBv", &v)) != NULL) {
		switch (AG_VARIABLE_TYPE(bv)) {
		case AG_VARIABLE_FLOAT:
			((float *)v)[0] = (float)r/255.0;
			((float *)v)[1] = (float)g/255.0;
			((float *)v)[2] = (float)b/255.0;
			break;
		case AG_VARIABLE_DOUBLE:
			((double *)v)[0] = (double)r/255.0;
			((double *)v)[1] = (double)g/255.0;
			((double *)v)[2] = (double)b/255.0;
			break;
		case AG_VARIABLE_INT:
			((int *)v)[0] = (int)r;
			((int *)v)[1] = (int)g;
			((int *)v)[2] = (int)b;
			break;
		case AG_VARIABLE_UINT8:
			((Uint8 *)v)[0] = r;
			((Uint8 *)v)[1] = g;
			((Uint8 *)v)[2] = b;
			break;
		default:
			break;
		}
		AG_UnlockVariable(bv);
	}
	if ((bv = AG_GetVariable(pal, "RGBAv", &v)) != NULL) {
		switch (AG_VARIABLE_TYPE(bv)) {
		case AG_VARIABLE_FLOAT:
			((float *)v)[0] = (float)r/255.0;
			((float *)v)[1] = (float)g/255.0;
			((float *)v)[2] = (float)b/255.0;
			((float *)v)[3] = (float)a/255.0;
			break;
		case AG_VARIABLE_DOUBLE:
			((double *)v)[0] = (double)r/255.0;
			((double *)v)[1] = (double)g/255.0;
			((double *)v)[2] = (double)b/255.0;
			((double *)v)[3] = (double)a/255.0;
			break;
		case AG_VARIABLE_INT:
			((int *)v)[0] = (int)r;
			((int *)v)[1] = (int)g;
			((int *)v)[2] = (int)b;
			((int *)v)[3] = (int)a;
			break;
		case AG_VARIABLE_UINT8:
			((Uint8 *)v)[0] = r;
			((Uint8 *)v)[1] = g;
			((Uint8 *)v)[2] = b;
			((Uint8 *)v)[3] = a;
			break;
		default:
			break;
		}
		AG_UnlockVariable(bv);
	}
	
	bFormat = AG_GetVariable(pal, "pixel-format", &pFormat);
	AG_SetUint32(pal, "pixel", AG_MapPixelRGBA(*pFormat, r,g,b,a));
	AG_UnlockVariable(bFormat);

	bColor = AG_GetVariable(pal, "color", &pColor);
	pColor->r = r;
	pColor->g = g;
	pColor->b = b;
	pColor->a = a;
	AG_UnlockVariable(bColor);

	AG_Redraw(pal);
}
Exemplo n.º 21
0
void MainLoop(int argc, char *argv[])
{
   int c;
   char *drivers = NULL;
   char *optArg;
   char strbuf[2048];
   char homedir[2048];
   const SDL_VideoInfo *inf;
   BOOL flag;
   SDL_Surface *s;

//   mtrace();
   if(AG_GetVariable(agConfig, "font.size", NULL) == NULL) { 
	AG_SetInt(agConfig, "font.size", UI_PT);
   }
   while ((c = AG_Getopt(argc, argv, "?fWd:w:h:T:t:c:T:F:S:o:O:l:s:i:", &optArg, NULL))
          != -1) {
              switch (c) {
              case 'd':
                      drivers = optArg;
                      break;
              case 'f':
                      /* Force full screen */
                      AG_SetBool(agConfig, "view.full-screen", 1);
                      break;
              case 'W':
                      /* Force Window */
                      AG_SetBool(agConfig, "view.full-screen", 0);
                      break;
              case 'T':
                      /* Set an alternate font directory */
                      AG_SetString(agConfig, "font-path", optArg);
                      break;
              case 'F':
                      /* Set an alternate font face */
                      AG_SetString(agConfig, "font.face", optArg);
                      break;
              case 'S':
                  /* Set an alternate font face */
                  AG_SetInt(agConfig, "font.size", atoi(optArg));
                  break;
              case 'o':
                  /* Set an alternate font face */
                  AG_SetString(agConfig, "osdfont.face", optArg);
                  break;
              case 'O':
                  /* Set an alternate font face */
                  AG_SetInt(agConfig, "osdfont.size", atoi(optArg));
                  break;
              case 'l':
                  /* Set an alternate font face */
                  AG_SetString(agConfig, "load-path", optArg);
                  break;
              case 's':
                  /* Set an alternate font face */
                  AG_SetString(agConfig, "save-path", optArg);
                  break;
              case 'i':
                  /* Set an alternate font face */
                  AG_SetString(agConfig, "save-path", optArg);
                  AG_SetString(agConfig, "load-path", optArg);
                  break;
              case 't':
                  /* Change the default font */
                  AG_TextParseFontSpec(optArg);
                  break;
          case '?':
          default:
                  printf("%s [-v] [-f|-W] [-d driver] [-r fps] [-t fontspec] "
                         "[-w width] [-h height] "
                	 "[-F font.face] [-S font.size]"
			 "[-o osd-font.face] [-O osd-font.size]"
			 "[-s SavePath] [-l LoadPath] "
                         "[-T font-path]\n\n"
			 "Usage:\n"
			 "-f : FullScreen\n-W:Window Mode\n",
                         agProgName);
                  exit(0);
          }
    }
   
    if(SDL_getenv("HOME") != NULL) {
	strcpy(homedir, SDL_getenv("HOME"));
    } else {
        strcpy(homedir, ".");
    }
    XM7_DebugLog(XM7_LOG_DEBUG, "HOME = %s", homedir);

#ifdef _WINDOWS
	AG_PrtString(agConfig, "font-path", "%s:%s/xm7:%s:.",
		homedir, homedir, FONTPATH);
#else
    flag = FALSE;
    if(AG_GetString(agConfig, "font-path", strbuf, 2047) != NULL) {
       if((strlen(strbuf) <= 0) || (strncmp(strbuf, "_agFontVera", 11) == 0)){
	  flag = TRUE;
	 }
    } else {
       flag = TRUE;
    }
    if(flag) AG_PrtString(agConfig, "font-path", "%s/.fonts:%s:%s/.xm7:%s:.", 
		homedir, homedir, homedir, FONTPATH);
    flag = FALSE;
   
    XM7_DebugLog(XM7_LOG_DEBUG, "font-path = %s", strbuf);
#endif /* _WINDOWS */
    flag = FALSE;
    if(AG_GetString(agConfig, "font.face", strbuf, 511) != NULL) {
       if((strlen(strbuf) <= 0) || (strncmp(strbuf, "_agFontVera", 11) == 0)){
	  flag = TRUE;
       }
    } else {
	flag = TRUE;
    }
    if(flag) AG_SetString(agConfig, "font.face", UI_FONT);
    flag = FALSE;
    XM7_DebugLog(XM7_LOG_DEBUG, "font.face = %s", strbuf);
   
    stopreq_flag = FALSE;
    run_flag = TRUE;
    // Debug
#ifdef _XM7_FB_DEBUG // Force FB.
drivers = "sdlfb:width=1280:height=880:depth=32";
#endif
	/*
	 * Agar のメインループに入る
	 */

    if(drivers == NULL)  {
#ifdef USE_OPENGL
       if(AG_InitGraphics(NULL) == -1){
                fprintf(stderr, "%s\n", AG_GetError());
                return;
        }
#else
       if(AG_InitGraphics("cocoa,sdlfb") == -1){
                fprintf(stderr, "%s\n", AG_GetError());
                return;
        }
#endif
    } else {
        if (AG_InitGraphics(drivers) == -1) {
                fprintf(stderr, "%s\n", AG_GetError());
                return;
        }
    }
    OnCreate((AG_Widget *)NULL);
//    AG_AtExitFunc(OnDestroy);
    XM7_DebugLog(XM7_LOG_DEBUG, "Widget creation OK.");
   
   XM7_DebugLog(XM7_LOG_INFO, "Emulate version:%d", fm7_ver);
   SDL_InitSubSystem(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
   XM7_DebugLog(XM7_LOG_DEBUG, "Audio and JOYSTICK subsystem was initialised.");

   InitInstance();
   XM7_DebugLog(XM7_LOG_DEBUG, "InitInstance() OK.");
   if(agDriverSw && AG_UsingSDL(NULL)) {
      SDL_Init(SDL_INIT_VIDEO);
      XM7_DebugLog(XM7_LOG_INFO, "Start Single WM with SDL.");
      switch(fm7_ver) {
       case 1: // FM7/77
	 if(!(LoadGlobalIconPng(NULL, "tamori.png"))) {
	    LoadGlobalIconPng(NULL, "xm7.png");
	 }
	 break;
       case 2: // FM77AV
	 if(!(LoadGlobalIconPng(NULL, "fujitsu.png"))) {
	    LoadGlobalIconPng(NULL, "xm7.png");
	 }
	 break;
       case 3: // FM77AV20/40/EX/SX
	 if(!(LoadGlobalIconPng(NULL, "fujitsu2.png"))) {
	    LoadGlobalIconPng(NULL, "xm7.png");
	 }
	 break;
       default:
	 LoadGlobalIconPng(NULL, "xm7.png");
	 break;
      }
   } else { // WM function is managed by SDL, load and set icon for WM. 
      SDL_Init(SDL_INIT_VIDEO);
      XM7_DebugLog(XM7_LOG_INFO, "Start multi window mode.");
   }
       
   stopreq_flag = FALSE;
   run_flag = TRUE;
   AG_DrawInitsub();

   inf = SDL_GetVideoInfo();
   if(inf != NULL) {
      RootVideoWidth = inf->current_w;
      RootVideoHeight = inf->current_h;
   } else {
      RootVideoWidth = 640;
      RootVideoHeight = 400;
   }

   newResize = FALSE;
   nDrawTick1D = XM7_timeGetTime();
   nDrawTick1E = nDrawTick1D;

   ResizeWindow_Agar2(nDrawWidth, nDrawHeight);
   XM7_DebugLog(XM7_LOG_DEBUG, "Screen is %d x %d.", nDrawWidth, nDrawHeight);
    switch(nErrorCode) 
     {
      case 0:
	break;
      case 1:
	ErrorPopup(gettext("Error init VM.\nPlease check ROMS and system-memory.\n"));
	break;
      case 2:
	ErrorPopup(gettext("Error init Emulator.\nPlease check window system, display and more.\n"));
	break;
      default:
	ErrorPopup(gettext("Unknown error on setup.\nPlease email to author."));
	break;
     }
#if 0
   mtrace();
#endif
   if(DrawArea != NULL) {
      AG_RedrawOnTick(DrawArea, 1000 / nDrawFPS);
      XM7_DebugLog(XM7_LOG_INFO, "Direct draw mode.");
   } else if(GLDrawArea != NULL) {
      AG_RedrawOnTick(GLDrawArea, 1000 / nDrawFPS);
      XM7_DebugLog(XM7_LOG_INFO, "OpenGL mode.");
   }
   bEventRunFlag == TRUE;
   AGDrawTaskEvent(TRUE);
//   muntrace();
   XM7_DebugLog(XM7_LOG_INFO, "All End.");
}