示例#1
0
/** 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);
    }
}
示例#2
0
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);
	}
}