void gfuiDrawScrollist(tGfuiObject *obj) { tGfuiScrollList* scrollist = &(obj->u.scrollist); GfuiColor fgColor; GfuiColor bgColor; if (scrollist->selectedElt < 0) { fgColor = scrollist->fgColor[0]; bgColor = scrollist->bgColor[0]; } else { fgColor = scrollist->fgSelectColor[0]; bgColor = scrollist->bgSelectColor[0]; } if (bgColor.alpha) { glBegin(GL_QUADS); glColor4fv(bgColor.toFloatRGBA()); glVertex2i(obj->xmin, obj->ymin); glVertex2i(obj->xmin, obj->ymax); glVertex2i(obj->xmax, obj->ymax); glVertex2i(obj->xmax, obj->ymin); glEnd(); } glBegin(GL_LINE_STRIP); glColor4fv(fgColor.toFloatRGBA()); glVertex2i(obj->xmin, obj->ymin); glVertex2i(obj->xmin, obj->ymax); glVertex2i(obj->xmax, obj->ymax); glVertex2i(obj->xmax, obj->ymin); glVertex2i(obj->xmin, obj->ymin); glEnd(); const int h = scrollist->font->getHeight(); const int x = obj->xmin; int y = obj->ymax; int index = 0; tGfuiListElement* elt = scrollist->elts; if (elt) { do { elt = elt->next; if (index < scrollist->firstVisible) { index++; continue; } if (index == scrollist->selectedElt) { glColor4fv(scrollist->fgSelectColor[0].toFloatRGBA()); } else { glColor4fv(scrollist->fgColor[0].toFloatRGBA()); } index++; if (index > (scrollist->firstVisible + scrollist->nbVisible)) { break; } y -= h; gfuiDrawString(x+5, y, scrollist->font, elt->label); } while (elt != scrollist->elts); } }
void* RmResScreenInit() { if (rmResScreenHdle) GfuiScreenRelease(rmResScreenHdle); tRmInfo* reInfo = LmRaceEngine().inData(); // Create screen, load menu XML descriptor and create static controls. rmResScreenHdle = GfuiScreenCreate(black, 0, rmResScreenActivate, 0, rmResScreenDeactivate, 0); void *hmenu = GfuiMenuLoad("raceblindscreen.xml"); GfuiMenuCreateStaticControls(rmResScreenHdle, hmenu); // Create variable main title (race session) label. rmResTitleId = GfuiMenuCreateLabelControl(rmResScreenHdle, hmenu, "Title"); // Create background image if any specified. const char* img = GfParmGetStr(reInfo->params, RM_SECT_HEADER, RM_ATTR_RUNIMG, 0); if (img) GfuiScreenAddBgImg(rmResScreenHdle, img); // Create variable subtitle (driver and race name, lap number) label. rmResSubTitleId = GfuiMenuCreateLabelControl(rmResScreenHdle, hmenu, "SubTitle"); // Create table header label. rmResHeaderId = GfuiMenuCreateLabelControl(rmResScreenHdle, hmenu, "Header"); // Get layout properties, except for nMaxResultRows (see below). const int yTopRow = (int)GfuiMenuGetNumProperty(hmenu, "yTopRow", 400); const int yRowShift = (int)GfuiMenuGetNumProperty(hmenu, "yRowShift", 20); // Allocate row info arrays, if not already done. if (!rmResRowLabelId) { // Load nMaxResultRows/colors only the first time (ignore any later change, // otherwize, we'd have to realloc the row info arrays). rmNMaxResRows = (int)GfuiMenuGetNumProperty(hmenu, "nMaxResultRows", 20); const GfuiColor cNormal = GfuiColor::build(GfuiMenuGetStrProperty(hmenu, "rowColorNormal", "0x0000FF")); const GfuiColor cHighlighted = GfuiColor::build(GfuiMenuGetStrProperty(hmenu, "rowColorHighlighted", "0x00FF00")); memcpy(rmColors[0], cNormal.toFloatRGBA(), sizeof(rmColors[0])); memcpy(rmColors[1], cHighlighted.toFloatRGBA(), sizeof(rmColors[1])); rmResRowLabelId = (int*)calloc(rmNMaxResRows, sizeof(int)); rmResRowText = (char**)calloc(rmNMaxResRows, sizeof(char*)); rmResRowColor = (float**)calloc(rmNMaxResRows, sizeof(float*)); } // Create result rows (1 label for each). int y = yTopRow; for (int i = 0; i < rmNMaxResRows; i++) { freez(rmResRowText[i]); rmResRowColor[i] = rmColors[0]; rmResRowLabelId[i] = GfuiMenuCreateLabelControl(rmResScreenHdle, hmenu, "Row", true, // from template "", GFUI_TPL_X, y, GFUI_TPL_FONTID, GFUI_TPL_WIDTH, GFUI_TPL_ALIGN, GFUI_TPL_MAXLEN, rmResRowColor[i]); y -= yRowShift; } // Close menu XML descriptor. GfParmReleaseHandle(hmenu); // Register keyboard shortcuts. GfuiAddKey(rmResScreenHdle, GFUIK_F1, "Help", rmResScreenHdle, GfuiHelpScreen, NULL); GfuiAddKey(rmResScreenHdle, GFUIK_F12, "Screen shot", NULL, GfuiScreenShot, NULL); GfuiAddKey(rmResScreenHdle, GFUIK_ESCAPE, "Stop current race", (void*)RE_STATE_RACE_STOP, rmApplyState, NULL); GfuiAddKey(rmResScreenHdle, 'q', GFUIM_ALT, "Quit game now, save nothing", (void*)RE_STATE_EXIT, rmApplyState, NULL); // Initialize current result row. rmCurRowIndex = 0; return rmResScreenHdle; }
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; }
int GfuiMenuCreateComboboxControl(void* hscr, void* hparm, const char* pszName, void* userData, tfuiComboboxCallback onChange) { std::string strControlPath(GFMNU_SECT_DYNAMIC_CONTROLS"/"); strControlPath += pszName; const std::string strType = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TYPE, ""); if (strType != GFMNU_TYPE_COMBO_BOX) { GfLogError("Failed to create control '%s' : section not found or not an '%s' \n", pszName, GFMNU_TYPE_COMBO_BOX); return -1; } int id = -1; 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); std::string strFontName = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_FONT, ""); const int font = gfuiMenuGetFontId(strFontName.c_str()); int width = (int)GfParmGetNum(hparm,strControlPath.c_str(), GFMNU_ATTR_WIDTH, NULL, 0.0); if (width == 0) width = 200; const int nArrowsWidth = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_ARROWS_WIDTH, NULL, 0); const int nArrowsHeight = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_ARROWS_HEIGHT, NULL, 0); const char* pszText = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TEXT, ""); const int maxlen = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_MAX_LEN, 0, 0); const char* pszTip = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TIP, 0); void* userDataOnFocus = 0; tfuiCallback onFocus = 0; tfuiCallback onFocusLost = 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; } const float* aColor = 0; const GfuiColor color = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR); if (color.alpha) aColor = color.toFloatRGBA(); const float* aFocusColor = 0; const GfuiColor focusColor = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR_FOCUSED); if (focusColor.alpha) aFocusColor = focusColor.toFloatRGBA(); id = GfuiComboboxCreate(hscr, font, x, y, width, nArrowsWidth, nArrowsHeight, pszText, maxlen, aColor, aFocusColor, userData, onChange, userDataOnFocus, onFocus, onFocusLost); return id; }
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; }