コード例 #1
0
ファイル: guimenu.cpp プロジェクト: rongzhou/speed-dreams
int 
GfuiMenuCreateEditControl(void* hscr, void* hparm, const char* pszName,
						  void* userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
{
	std::string strControlPath(GFMNU_SECT_DYNAMIC_CONTROLS"/");
	strControlPath += pszName;

	const char* pszType = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TYPE, "");
	if (strcmp(pszType, GFMNU_TYPE_EDIT_BOX))
	{
		GfLogError("Failed to create control '%s' : section not found or not an '%s' \n",
				   pszName, GFMNU_TYPE_EDIT_BOX);
		return -1;
	}

	// TODO : Add real support for tips (the onFocus/onFocusLost system is already used
	//        for user input management)
	//         const char* pszTip = GfParmGetStr(hparm, pszName, GFMNU_ATTR_TIP, "");
	//         if (strlen(pszTip) > 0)
	//         {
	//                 tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo));
	//                 cbinfo->screen = hscr;
	//                 cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip));
	//                 GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE);
	//
	//                 // TODO: In this case, we simply ignore onFocus/onFocusLost !
	//                 userDataOnFocus = (void*)cbinfo;
	//                 onFocus = onFocusShowTip;
	//                 onFocusLost = onFocusLostHideTip;
	//         }

	const char* pszText = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TEXT, "");
	const int x = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_X, NULL, 0.0);
	const int y = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_Y, NULL, 0.0);
	const char* pszFontName = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_FONT, "");
	const int font = gfuiMenuGetFontId(pszFontName);
	const int width = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_WIDTH, NULL, 0.0);
	const int maxlen = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_MAX_LEN, NULL, 0.0);
	const char* pszAlignH = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_H_ALIGN, "");
	const int align = gfuiMenuGetAlignment(pszAlignH);

	const GfuiColor c = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR);
	const GfuiColor fc = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR_FOCUSED);
	const GfuiColor dc = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR_DISABLED);
	const GfuiColor bc = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_BG_COLOR);
	const GfuiColor bfc = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_BG_COLOR_FOCUSED);
	const GfuiColor bdc = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_BG_COLOR_DISABLED);

	int id = GfuiEditboxCreate(hscr, pszText, font, x, y, width, maxlen, align,
							   userDataOnFocus, onFocus, onFocusLost);

	GfuiEditboxSetColors(hscr, id, c, fc, dc);
	GfuiEditboxSetBGColors(hscr, id, bc, bfc, bdc);

	return id;
}
コード例 #2
0
ファイル: guilabel.cpp プロジェクト: 702nADOS/speed-dreams
void
gfuiInitLabel(void)
{
	char path[512];

	// Get tip layout properties from the screen config file.
	sprintf(path, "%s%s", GfLocalDir(), GFSCR_CONF_FILE);
	void* hparmScr = GfParmReadFile(path, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);

	sprintf(path, "%s/%s", GFSCR_SECT_MENUSETTINGS, GFSCR_SECT_TIP);
	NTipX = (int)GfParmGetNum(hparmScr, path, GFSCR_ATT_X, 0, 10.0);
	NTipY = (int)GfParmGetNum(hparmScr, path, GFSCR_ATT_Y, 0, 10.0);
	NTipWidth = (int)GfParmGetNum(hparmScr, path, GFSCR_ATT_WIDTH, 0, 620.0);
	NTipFontId = gfuiMenuGetFontId(GfParmGetStr(hparmScr, path, GFSCR_ATT_FONT, "small"));
	NTipAlign = gfuiMenuGetAlignment(GfParmGetStr(hparmScr, path, GFSCR_ATT_ALIGN, "center"));

	GfParmReleaseHandle(hparmScr);
}
コード例 #3
0
ファイル: guimenu.cpp プロジェクト: rongzhou/speed-dreams
static int 
createTextButton(void* hscr, void* hparm, const char* pszPath,
				 void* userDataOnPush, tfuiCallback onPush,
				 void* userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost,
				 bool bFromTemplate = false,
				 const char* text = GFUI_TPL_TEXT,
				 const char* tip = GFUI_TPL_TIP,
				 int x = GFUI_TPL_X, int y = GFUI_TPL_Y,
				 int width = GFUI_TPL_WIDTH,
				 int font = GFUI_TPL_FONTID, int textHAlign = GFUI_TPL_ALIGN,
				 const float* aFgColor = GFUI_TPL_COLOR,
				 const float* aFgFocusColor = GFUI_TPL_FOCUSCOLOR,
				 const float* aFgPushedColor = GFUI_TPL_PUSHEDCOLOR)
{
	if (strcmp(GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TYPE, ""), GFMNU_TYPE_TEXT_BUTTON))
	{
		GfLogError("Failed to create text button control '%s' : section not found or not a '%s'\n",
				   pszPath, GFMNU_TYPE_TEXT_BUTTON);
		return -1;
	}
        
	const char* pszText =
		bFromTemplate && text != GFUI_TPL_TEXT
		? text : GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TEXT, "");
	const char* pszTip =
		bFromTemplate && tip != GFUI_TPL_TIP
		? tip : GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TIP, "");
	const int nX = 
		bFromTemplate && x != GFUI_TPL_X
		? x : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_X, NULL, 0);
	const int nY = 
		bFromTemplate && y != GFUI_TPL_Y
		? y : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_Y, NULL, 0);
	int nWidth = 
		bFromTemplate && width != GFUI_TPL_WIDTH
		? width : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_WIDTH, NULL, 0);
	if (nWidth <= 0)
		nWidth = GFUI_BTNSZ; // TODO: Get default from screen.xml
	const int nFontId = 
		bFromTemplate && font != GFUI_TPL_FONTID
		? font : gfuiMenuGetFontId(GfParmGetStr(hparm, pszPath, GFMNU_ATTR_FONT, ""));
	const char* pszAlignH = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_H_ALIGN, "");
	//const char* pszAlignV = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_V_ALIGN, "");
	const int nAlign = 
		bFromTemplate && textHAlign != GFUI_TPL_ALIGN
		? textHAlign : gfuiMenuGetAlignment(pszAlignH); //, pszAlignV);
	
	GfuiColor color;
	const float* aColor = 0;
	if (bFromTemplate && aFgColor != GFUI_TPL_COLOR)
		aColor = aFgColor;
	else
	{
		color = getControlColor(hparm, pszPath, GFMNU_ATTR_COLOR);
		if (color.alpha)
			aColor = color.toFloatRGBA();
	}

	GfuiColor focusColor;
	const float* aFocusColor = 0;
	if (bFromTemplate && aFgFocusColor != GFUI_TPL_FOCUSCOLOR)
		aFocusColor = aFgFocusColor;
	else
	{
		focusColor = getControlColor(hparm, pszPath, GFMNU_ATTR_COLOR_FOCUSED);
		if (focusColor.alpha)
			aFocusColor = focusColor.toFloatRGBA();
	}

	GfuiColor pushedColor;
	const float* aPushedColor = 0;
	if (bFromTemplate && aFgPushedColor != GFUI_TPL_PUSHEDCOLOR)
		aPushedColor = aFgPushedColor;
	else
	{
		pushedColor = getControlColor(hparm, pszPath, GFMNU_ATTR_COLOR_PUSHED);
		if (pushedColor.alpha)
			aPushedColor = pushedColor.toFloatRGBA();
	}

	if (pszTip && strlen(pszTip) > 0)
	{
		tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo));
		cbinfo->screen = hscr;
		cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip));
		GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE);

		// TODO: In this case, we crudely overwrite onFocus/onFocusLost !
		userDataOnFocus = (void*)cbinfo;
		onFocus = onFocusShowTip;
		onFocusLost = onFocusLostHideTip;
	}

	const bool bShowbox = getControlBoolean(hparm, pszPath, GFMNU_ATTR_BOX_SHOW, true);

	const char* pszDisabledImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_DISABLED, 0);
	const char* pszEnabledImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_ENABLED, 0);
	const char* pszFocusedImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_FOCUSED, 0);
	const char* pszPushedImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_PUSHED, 0);

	const int imgX = (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_IMAGE_X, NULL, 0.0);
	const int imgY = (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_IMAGE_Y, NULL, 0.0);
	const int imgWidth = (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_IMAGE_WIDTH, NULL, 20.0);
	const int imgHeight = (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_IMAGE_HEIGHT, NULL, 20.0);

	int butId = GfuiButtonCreate(hscr, pszText, nFontId,
								 nX, nY, nWidth, nAlign, GFUI_MOUSE_UP,
								 userDataOnPush, onPush,
								 userDataOnFocus, onFocus, onFocusLost);

	GfuiButtonShowBox(hscr, butId, bShowbox);

	if (pszDisabledImage || pszEnabledImage || pszFocusedImage || pszPushedImage)
		GfuiButtonSetImage(hscr, butId, imgX, imgY, imgWidth, imgHeight,
						   pszDisabledImage, pszEnabledImage,
						   pszFocusedImage, pszPushedImage);

	GfuiButtonSetColors(hscr, butId,
						GfuiColor::build(aColor), GfuiColor::build(aFocusColor),
						GfuiColor::build(aPushedColor));
        
	return butId;
}
コード例 #4
0
ファイル: guimenu.cpp プロジェクト: rongzhou/speed-dreams
static int 
createLabel(void* hscr, void* hparm, const char* pszPath,
			bool bFromTemplate = false,
			const char* text = GFUI_TPL_TEXT, int x = GFUI_TPL_X, int y = GFUI_TPL_Y,
			int font = GFUI_TPL_FONTID, int width = GFUI_TPL_WIDTH, int hAlign = GFUI_TPL_ALIGN,
			int maxlen = GFUI_TPL_MAXLEN, 
			const float* aFgColor = GFUI_TPL_COLOR,
			const float* aFgFocusColor = GFUI_TPL_FOCUSCOLOR)
{
	if (strcmp(GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TYPE, ""), GFMNU_TYPE_LABEL))
	{
		GfLogError("Failed to create label control '%s' : section not found or not a '%s'\n",
				   pszPath, GFMNU_TYPE_LABEL);
		return -1;
	}
        
	const char* pszText =
		bFromTemplate && text != GFUI_TPL_TEXT
		? text : GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TEXT, "");
	const int nX = 
		bFromTemplate && x != GFUI_TPL_X
		? x : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_X, NULL, 0);
	const int nY = 
		bFromTemplate && y != GFUI_TPL_Y
		? y : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_Y, NULL, 0);
	const int nWidth =
		bFromTemplate && width != GFUI_TPL_WIDTH
		? width : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_WIDTH, NULL, 0);
	const int nFontId = 
		bFromTemplate && font != GFUI_TPL_FONTID
		? font : gfuiMenuGetFontId(GfParmGetStr(hparm, pszPath, GFMNU_ATTR_FONT, ""));
	const char* pszAlignH = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_H_ALIGN, "");
	//const char* pszAlignV = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_V_ALIGN, "");
	const int nAlign = 
		bFromTemplate && hAlign != GFUI_TPL_ALIGN
		? hAlign : gfuiMenuGetAlignment(pszAlignH); //, pszAlignV);
	int nMaxLen = 
		bFromTemplate && maxlen != GFUI_TPL_MAXLEN
		? maxlen : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_MAX_LEN, NULL, 0);
	
	GfuiColor color;
	const float* aColor = 0;
	if (bFromTemplate && aFgColor != GFUI_TPL_COLOR)
		aColor = aFgColor;
	else
	{
		color = getControlColor(hparm, pszPath, GFMNU_ATTR_COLOR);
		if (color.alpha)
			aColor = color.toFloatRGBA();
	}

	GfuiColor focusColor;
	const float* aFocusColor = 0;
	if (bFromTemplate && aFgFocusColor != GFUI_TPL_FOCUSCOLOR)
		aFocusColor = aFgFocusColor;
	else
	{
		focusColor = getControlColor(hparm, pszPath, GFMNU_ATTR_COLOR_FOCUSED);
		if (focusColor.alpha)
			aFocusColor = focusColor.toFloatRGBA();
	}

	void* userDataOnFocus = 0;
	tfuiCallback onFocus = 0;
	tfuiCallback onFocusLost = 0;
	const char* pszTip = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TIP, 0);
	if (pszTip && strlen(pszTip) > 0)
	{
		tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo));
		cbinfo->screen = hscr;
		cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip));
		GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE);

		userDataOnFocus = (void*)cbinfo;
		onFocus = onFocusShowTip;
		onFocusLost = onFocusLostHideTip;
	}

	int labelId = GfuiLabelCreate(hscr, pszText, nFontId, nX, nY, nWidth, nAlign, nMaxLen,
								  aColor, aFocusColor, userDataOnFocus, onFocus, onFocusLost);

    return labelId;
}