Esempio n. 1
0
/** 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;
}
Esempio n. 2
0
void
gfuiInit(void)
{
	gfuiButtonInit();
	gfuiHelpInit();
	gfuiLabelInit();
	gfuiObjectInit();
	gfuiColorInit();
	gfuiLoadFonts();

/*     glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF); */
}
Esempio n. 3
0
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;
}