int GfuiMenuCreateProgressbarControl(void* hscr, void* hparm, const char* pszName) { 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_PROGRESS_BAR) { GfLogError("Failed to create control '%s' : section not found or not an '%s' \n", pszName, GFMNU_TYPE_PROGRESS_BAR); return -1; } const char* pszImage = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_IMAGE, "data/img/progressbar.png"); const char* pszBgImage = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_BG_IMAGE, "data/img/progressbar-bg.png"); const float* aOutlineColor = 0; const GfuiColor color = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR); if (color.alpha) aOutlineColor = color.toFloatRGBA(); 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 int w = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_WIDTH, NULL, 100.0); const int h = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_HEIGHT, NULL, 20.0); const float min = GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_MIN, NULL, 0.0); const float max = GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_MAX, NULL, 100.0); const float value = GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_VALUE, NULL, 50.0); const char* pszTip = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TIP, ""); void* userDataOnFocus = 0; tfuiCallback onFocus = 0; tfuiCallback onFocusLost = 0; 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); userDataOnFocus = (void*)cbinfo; onFocus = onFocusShowTip; onFocusLost = onFocusLostHideTip; } int id = GfuiProgressbarCreate(hscr, x, y, w, h, pszBgImage, pszImage, aOutlineColor, min, max, value, userDataOnFocus, onFocus, onFocusLost); return id; }
void GfuiComboboxSetTextColor(void *scr, int id, const GfuiColor& color) { tGfuiObject* object = gfuiGetObject(scr, id); if (object && object->widget == GFUI_COMBOBOX) { tGfuiCombobox* combo = &(object->u.combobox); gfuiLabelSetColor(&combo->label, color.toFloatRGBA()); } }
/** Actually draw the given label. @ingroup gui @param obj label to draw */ void gfuiLabelDraw(tGfuiLabel *label, const GfuiColor& color) { int of = 0; int fw = (int) label->font->getWidth("o"); // Prevent strtok weirdness char *save; char text[128]; strncpy(text, (char *) label->text, 128); char *p = strtok_r(text, "\t", &save); while (p != NULL) { // Select the right color from the state/focus. glColor4fv(color.toFloatRGBA()); // Determine the actual (bottom left corner) coordinates where to draw the text. int x; switch(label->align & GFUI_ALIGN_HMASK) { default: case GFUI_ALIGN_HL: x = label->x + (fw * of); break; case GFUI_ALIGN_HC: x = label->x + (fw * of) + (label->width - label->font->getWidth(label->text)) / 2; break; case GFUI_ALIGN_HR: x = label->x + (fw * of) + label->width - label->font->getWidth(label->text); break; } gfuiDrawString(x, label->y, label->font, p); of += strlen(p) + 1; p = strtok_r(NULL, "\t", &save); } }
static void rmRaceResults(void *prevHdle, tRmInfo *info, int start) { void *results = info->results; const char *race = info->_reRaceName; static char buf[256]; static char path[512]; char *str; GfLogTrace("Entering Race Results menu\n"); // Create screen, load menu XML descriptor and create static controls. rmScrHdle = GfuiScreenCreate(); void *hmenu = GfuiMenuLoad("raceresultsmenu.xml"); GfuiMenuCreateStaticControls(rmScrHdle, hmenu); // Create variable title label. snprintf(buf, sizeof(buf), "%s at %s", race, info->track->name); const int titleId = GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "Title"); GfuiLabelSetText(rmScrHdle, titleId, buf); // Get layout properties. const int nMaxLines = (int)GfuiMenuGetNumProperty(hmenu, "nMaxResultLines", 15); const int yTopLine = (int)GfuiMenuGetNumProperty(hmenu, "yTopLine", 400); const int yLineShift = (int)GfuiMenuGetNumProperty(hmenu, "yLineShift", 20); const GfuiColor cPlaceGain = GfuiColor::build(GfuiMenuGetStrProperty(hmenu, "colorGainedPlaces", "0x32CD32")); const float* acPlaceGain = cPlaceGain.toFloatRGBA(); const GfuiColor cPlaceLoss = GfuiColor::build(GfuiMenuGetStrProperty(hmenu, "colorLostPlaces", "0xF28500")); const float* acPlaceLoss = cPlaceLoss.toFloatRGBA(); // Never used : remove ? //Get total laps, winner time //snprintf(path, sizeof(path), "%s/%s/%s", info->track->name, RE_SECT_RESULTS, race); //int totLaps = (int)GfParmGetNum(results, path, RE_ATTR_LAPS, NULL, 0); //snprintf(path, sizeof(path), "%s/%s/%s/%s/%d", info->track->name, RE_SECT_RESULTS, race, RE_SECT_RANK, 1); //tdble refTime = GfParmGetNum(results, path, RE_ATTR_TIME, NULL, 0); //Get number of cars snprintf(path, sizeof(path), "%s/%s/%s/%s", info->track->name, RE_SECT_RESULTS, race, RE_SECT_RANK); int nbCars = (int)GfParmGetEltNb(results, path); // Display the result table. int y = yTopLine; int i; for (i = start; i < MIN(start + nMaxLines, nbCars); i++) { snprintf(path, sizeof(path), "%s/%s/%s/%s/%d", info->track->name, RE_SECT_RESULTS, race, RE_SECT_RANK, i + 1); int laps = (int)GfParmGetNum(results, path, RE_ATTR_LAPS, NULL, 0);//Laps covered //Rank snprintf(buf, sizeof(buf), "%d", i+1); GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "Rank", true, // From template. buf, GFUI_TPL_X, y); //Advance (The num.attrib 'index' holds the starting position) int advance = (int)(GfParmGetNum(results, path, RE_ATTR_INDEX, NULL, 0)) - i; snprintf(buf, sizeof(buf), "%d", advance); const float *aColor = advance > 0 ? acPlaceGain : (advance < 0 ? acPlaceLoss : GFUI_TPL_COLOR); GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "Advance", true, // From template. buf, GFUI_TPL_X, y, GFUI_TPL_FONTID, GFUI_TPL_WIDTH, GFUI_TPL_ALIGN, GFUI_TPL_MAXLEN, aColor); //Driver short name GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "DriverName", true, // From template. GfParmGetStr(results, path, RE_ATTR_SNAME, ""), GFUI_TPL_X, y); //Driver type const std::string strModName = GfParmGetStr(results, path, RE_ATTR_MODULE, ""); GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "DriverType", true, // From template. GfDriver::getType(strModName).c_str(), GFUI_TPL_X, y); //Car GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "CarModel", true, // From template. GfParmGetStr(results, path, RE_ATTR_CAR, ""), GFUI_TPL_X, y); //Total Time str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_TIME, NULL, 0), 0, false, 3); GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "TotalTime", true, // From template. str, GFUI_TPL_X, y); free(str); //Best lap str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), 0, false, 3); GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "BestLapTime", true, // From template. str, GFUI_TPL_X, y); free(str); //Laps covered snprintf(buf, sizeof(buf), "%d", laps); GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "Laps", true, // From template. buf, GFUI_TPL_X, y); //Top speed snprintf(buf, sizeof(buf), "%3.1f", (GfParmGetNum(results, path, RE_ATTR_TOP_SPEED, NULL, 0) * 3.6)); GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "TopSpeed", true, // From template. buf, GFUI_TPL_X, y); //Damage snprintf(buf, sizeof(buf), "%d", (int)(GfParmGetNum(results, path, RE_ATTR_DAMMAGES, NULL, 0))); GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "Damages", true, // From template. buf, GFUI_TPL_X, y); //Pitstops snprintf(buf, sizeof(buf), "%d", (int)(GfParmGetNum(results, path, RE_ATTR_NB_PIT_STOPS, NULL, 0))); GfuiMenuCreateLabelControl(rmScrHdle, hmenu, "Pits", true, // From template. buf, GFUI_TPL_X, y); y -= yLineShift; //Line feed }//for i //If it is not the first screen of the results, show a 'Prev' button if (start > 0) { RmPrevRace.prevHdle = prevHdle; RmPrevRace.info = info; RmPrevRace.start = start - nMaxLines; GfuiMenuCreateButtonControl(rmScrHdle, hmenu, "PreviousPageArrow", (void*)&RmPrevRace, rmChgRaceScreen); GfuiAddKey(rmScrHdle, GFUIK_PAGEUP, "Previous Results", (void*)&RmPrevRace, rmChgRaceScreen, NULL); }//if start // Add "Continue" button GfuiMenuCreateButtonControl(rmScrHdle, hmenu, "ContinueButton", prevHdle, GfuiScreenReplace); //Create 'save' button in the bottom right //rmSaveButtonId = GfuiMenuCreateButtonControl(rmScrHdle, hmenu, "SaveButton", info, rmSaveRes); //If we did not display all the results yet, let's show a 'Next' button if (i < nbCars) { RmNextRace.prevHdle = prevHdle; RmNextRace.info = info; RmNextRace.start = start + nMaxLines; GfuiMenuCreateButtonControl(rmScrHdle, hmenu, "NextPageArrow", (void*)&RmNextRace, rmChgRaceScreen); GfuiAddKey(rmScrHdle, GFUIK_PAGEDOWN, "Next Results", (void*)&RmNextRace, rmChgRaceScreen, NULL); }//if i //Link key handlers GfuiAddKey(rmScrHdle, GFUIK_ESCAPE, "Continue", prevHdle, GfuiScreenReplace, NULL); GfuiAddKey(rmScrHdle, GFUIK_RETURN, "Continue", prevHdle, GfuiScreenReplace, NULL); GfuiAddKey(rmScrHdle, GFUIK_F12, "Take a Screen Shot", NULL, GfuiScreenShot, NULL); GfuiAddKey(rmScrHdle, GFUIK_F1, "Help", rmScrHdle, GfuiHelpScreen, NULL); //Show! GfuiScreenActivate(rmScrHdle); }//rmRaceResults
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; }
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 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; }
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; }