/** Create a new label @ingroup gui @param scr Screen where to add the label @param text Text of the label @param font Font id @param x Position of the label on the screen @param y Position of the label on the screen @param align Horizontal alignment: <br>GFUI_ALIGN_HR right <br>GFUI_ALIGN_HC center <br>GFUI_ALIGN_HL left @param maxlen Maximum length of the button string (used when the label is changed) <br>0 for the text length. @param fgColor Pointer on static RGBA color array (0 => default) @param fgFocusColor Pointer on static RGBA focused color array (0 => fgColor) @param userDataOnFocus User data given to the onFocus[Lost] call back functions @param onFocus Call back function called when getting the focus @param onFocusLost Call back function called when loosing the focus @return label Id @see GfuiSetLabelText */ int GfuiLabelCreate(void *scr, const char *text, int font, int x, int y, int width, int align, int maxlen, const float *fgColor, const float *fgFocusColor, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost) { tGfuiLabel *label; tGfuiObject *object; tGfuiScreen *screen = (tGfuiScreen*)scr; object = (tGfuiObject*)calloc(1, sizeof(tGfuiObject)); object->widget = GFUI_LABEL; object->focusMode = (onFocus || onFocusLost) ? GFUI_FOCUS_MOUSE_MOVE : GFUI_FOCUS_NONE; object->visible = 1; object->id = screen->curId++; label = &(object->u.label); gfuiLabelInit(label, text, maxlen, x, y, width, align, font, screen->bgColor.toFloatRGBA(), fgColor, screen->bgColor.toFloatRGBA(), fgFocusColor, userDataOnFocus, onFocus, onFocusLost); width = label->width; const int height = gfuiFont[font]->getHeight(); object->xmin = x; object->ymin = y; object->xmax = object->xmin + width; object->ymax = object->ymin + height; gfuiAddObject(screen, object); return object->id; }
/** Create a new scroll list. @ingroup gui @param scr Current screen @param font Current font @param x X Position (pixels) @param y Y Position (pixels) @param width Total width of the box (pixels) @param height Total height of the box (pixels) @param scrollBarPos Position of the scrollbar: <br>GFUI_SB_NONE No scroll bar <br>GFUI_SB_RIGHT Right scroll bar <br>GFUI_SB_LEFT Left scroll bar @param scrollBarWidth Width of the scroll-bar (pixels) @param scrollBarButHeight Height of the scroll-bar buttons (pixels) @param userDataOnSelect User data to pass to the onSelect callback @param onSelect Callback when the selection is done @return Scroll List Id */ int GfuiScrollListCreate(void *scr, int font, int x, int y, int width, int height, int scrollBarPos, int scrollBarWidth, int scrollBarButHeight, void *userDataOnSelect, tfuiCallback onSelect) { tGfuiScrollList *scrollist; tGfuiObject *object; tGfuiScreen *screen = (tGfuiScreen*)scr; object = (tGfuiObject*)calloc(1, sizeof(tGfuiObject)); object->widget = GFUI_SCROLLIST; object->focusMode = GFUI_FOCUS_MOUSE_MOVE; object->id = screen->curId++; object->visible = 1; object->xmin = x; object->xmax = x + width; object->ymin = y; object->ymax = y + height; scrollist = &(object->u.scrollist); scrollist->fgColor[0] = GfuiColor::build(GFUI_FGSCROLLIST); scrollist->bgColor[0] = GfuiColor::build(GFUI_BGSCROLLIST); scrollist->fgSelectColor[0] = GfuiColor::build(GFUI_FGSELSCROLLIST); scrollist->bgSelectColor[0] = GfuiColor::build(GFUI_BGSELSCROLLIST); scrollist->font = gfuiFont[font]; scrollist->nbVisible = height / scrollist->font->getHeight(); scrollist->selectedElt = -1; scrollist->userDataOnSelect = userDataOnSelect; scrollist->onSelect = onSelect; switch (scrollBarPos) { case GFUI_SB_RIGHT: scrollist->scrollBar = GfuiScrollBarCreate(scr, x + width, y, height, scrollBarWidth, scrollBarButHeight, GFUI_VERT_SCROLLBAR, GFUI_SB_RIGHT, 0, 10, 10, 10, (void *)(long)(object->id), gfuiScroll); break; case GFUI_SB_LEFT: scrollist->scrollBar = GfuiScrollBarCreate(scr, x - scrollBarWidth, y, height, scrollBarWidth, scrollBarButHeight, GFUI_VERT_SCROLLBAR, GFUI_SB_LEFT, 0, 10, 10, 10, (void *)(long)(object->id), gfuiScroll); break; case GFUI_SB_NONE: default: break; } gfuiAddObject(screen, object); return object->id; }
/** Create a new static image (source image doesn't need to be a square or of POT sizes). This kind of image is not clickable. @ingroup gui @param scr Screen where to add the label @param x Position of the left of the image on the screen @param y Position of the bottom of the image on the screen @param w Width of the image on the screen @param h Height of the image on the screen @param name Filename on the source image (png) @param canDeform If true, full X and Y autoscale, otherwise, keep aspect ratio but cut sides or top/bottom to fill target w,h rectangle (default: true) @return Image Id <br>-1 Error*/ int GfuiStaticImageCreate(void *scr, int x, int y, int w, int h, const char *name, bool canDeform) { int pow2Width, pow2Height; tGfuiImage *image; tGfuiObject *object; tGfuiScreen *screen = (tGfuiScreen*)scr; object = (tGfuiObject*)calloc(1, sizeof(tGfuiObject)); object->widget = GFUI_IMAGE; object->focusMode = GFUI_FOCUS_NONE; object->visible = 1; object->id = screen->curId++; image = &(object->u.image); for (int i=0;i<GFUI_MAXSTATICIMAGES;i++) image->texture[i] = 0; image->activeimage = 0; image->canDeform = canDeform; // We don't use returned POT width and height, but passing non NULL pointers // for them enforces POT sizes for the loaded texture. image->texture[0] = GfTexReadTexture(name, &image->srcWidth, &image->srcHeight, &pow2Width, &pow2Height); if (!image->texture) { free(object); return -1; } object->xmin = x; object->xmax = x + w; object->ymin = y; object->ymax = y + h; gfuiAddObject(screen, object); return object->id; }
int GfuiComboboxCreate(void *scr, int font, int x, int y, int width, int arrowsWidth, int arrowsHeight, const char *pszText, int maxlen, const float *fgColor, const float *fgFocusColor, void *userData, tfuiComboboxCallback onChange, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost) { tGfuiCombobox *combobox; tGfuiObject *object; tGfuiScreen *screen = (tGfuiScreen*)scr; object = (tGfuiObject*)calloc(1, sizeof(tGfuiObject)); object->widget = GFUI_COMBOBOX; object->focusMode = GFUI_FOCUS_MOUSE_MOVE; object->id = screen->curId++; object->visible = 1; combobox = &(object->u.combobox); combobox->userDataOnFocus = userDataOnFocus; combobox->onFocus = onFocus; combobox->onFocusLost = onFocusLost; combobox->onChange = onChange; combobox->pInfo = new tComboBoxInfo; combobox->pInfo->nPos = 0; combobox->pInfo->userData = userData; combobox->scr = scr; // Initialize the left and right arrow button children. // Warning: All the arrow images are supposed to be the same size. // TODO: Make image files customizable. gfuiGrButtonInit(&combobox->leftButton, "data/img/arrow-left-disabled.png", "data/img/arrow-left.png", "data/img/arrow-left-focused.png", "data/img/arrow-left-pushed.png", x, y, arrowsWidth, arrowsHeight, GFUI_MIRROR_NONE, GFUI_MOUSE_UP, (void*)(long)(object->id), gfuiLeftArrow, 0, 0, 0); gfuiGrButtonInit(&combobox->rightButton, "data/img/arrow-right-disabled.png", "data/img/arrow-right.png", "data/img/arrow-right-focused.png", "data/img/arrow-right-pushed.png", x + width - combobox->leftButton.width, y, arrowsWidth, arrowsHeight, GFUI_MIRROR_NONE, GFUI_MOUSE_UP, (void*)(long)(object->id), gfuiRightArrow, 0, 0, 0); // Compute total height (text or buttons) int height = gfuiFont[font]->getHeight(); if (height < combobox->leftButton.height) height = combobox->leftButton.height; // Fix button y coordinate if text is higher than the buttons else combobox->leftButton.y = combobox->rightButton.y = y + (gfuiFont[font]->getHeight() - combobox->leftButton.height) / 2; // Bounding box object->xmin = x; object->xmax = x + width; object->ymin = y; object->ymax = y + height; // Initialize the label child (beware of y if the buttons are higher than the text). int yl = y; if (height > gfuiFont[font]->getHeight()) yl += (height - gfuiFont[font]->getHeight()) / 2; gfuiLabelInit(&combobox->label, pszText, maxlen, x + combobox->leftButton.width, yl, width - 2 * combobox->leftButton.width, GFUI_ALIGN_HC, font, 0, fgColor, 0, fgFocusColor, 0, 0, 0); // Add the combo control to the display list. gfuiAddObject(screen, object); return object->id; }
/** Create a new scroll bar. @ingroup gui @param scr Screen where to create the scroll bar @param x X position (pixels) @param y Y position (pixels) @param length Length on the screen (arrows included) (pixels) @param thickness Thickness on the screen (pixels) @param butLength Length of the buttons on the screen (pixels) @param orientation Scroll bar orientation: <br>GFUI_HORI_SCROLLBAR Horizontal <br>GFUI_VERT_SCROLLBAR Vertical @param position Scroll bar position <br>GFUI_SB_RIGHT Right <br>GFUI_SB_LEFT Left <br>GFUI_SB_TOP Top <br>GFUI_SB_BOTTOM Bottom @param min Minimum value for the "current position" @param max Maximum value for the "current position" @param visLen Visible length (as of "position") @param start Starting position @param userData User data given to the call back function @param onScroll Call back function called when the position change @return Scroll Bar Id <br>-1 Error */ int GfuiScrollBarCreate(void *scr, int x, int y, int length, int thickness, int butLength, int orientation, int position, int min, int max, int visLen, int start, void *userData, tfuiSBCallback onScroll) { tGfuiScreen* screen = (tGfuiScreen*)scr; tGfuiObject* object = (tGfuiObject*)calloc(1, sizeof(tGfuiObject)); object->widget = GFUI_SCROLLBAR; object->focusMode = GFUI_FOCUS_MOUSE_CLICK; object->id = screen->curId++; object->visible = 1; tGfuiScrollBar* scrollbar = &(object->u.scrollbar); scrollbar->userData = userData; scrollbar->onScroll = onScroll; // Warning: All the arrow images are supposed to be the same size. switch (orientation) { case GFUI_HORI_SCROLLBAR: { const int butMirror = (position == GFUI_SB_BOTTOM) ? GFUI_MIRROR_HORI : GFUI_MIRROR_NONE; const int arrowButId = GfuiGrButtonCreate(scr, "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left-focused.png", "data/img/arrow-left-pushed.png", x, y, butLength, thickness, butMirror, false, 1, (void*)(long)(object->id), gfuiScrollMinus, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); const tGfuiGrButton* pArrowBut = &(gfuiGetObject(scr, arrowButId)->u.grbutton); GfuiGrButtonCreate(scr, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-focused.png", "data/img/arrow-right-pushed.png", x + length - pArrowBut->width, y, butLength, thickness, butMirror, false, 1, (void*)(long)(object->id), gfuiScrollPlus, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); break; } case GFUI_VERT_SCROLLBAR: { const int butMirror = (position == GFUI_SB_LEFT) ? GFUI_MIRROR_VERT : GFUI_MIRROR_NONE; const int arrowButId = GfuiGrButtonCreate(scr, "data/img/arrow-down.png", "data/img/arrow-down.png", "data/img/arrow-down-focused.png", "data/img/arrow-down-pushed.png", x, y, thickness, butLength, butMirror, false, 1, (void*)(long)(object->id), gfuiScrollPlus, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); const tGfuiGrButton* pArrowBut = &(gfuiGetObject(scr, arrowButId)->u.grbutton); GfuiGrButtonCreate(scr, "data/img/arrow-up.png", "data/img/arrow-up.png", "data/img/arrow-up-focused.png", "data/img/arrow-up-pushed.png", x, y + length - pArrowBut->height, thickness, butLength, butMirror, false, 1, (void*)(long)(object->id), gfuiScrollMinus, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); break; } default: break; } gfuiAddObject(screen, object); GfuiScrollBarPosSet(scr, object->id, min, max, visLen, start); return object->id; }