示例#1
0
widget* widget_menu_item_add(widget *w, char* label, void (*action)(widget*))
{
	if(!w)return 0;
	widget *wdata = (widget*)w->data2;
	if(!wdata)
	{
		wdata = widget_menu_new();
		w->data2 = wdata;
		wdata->draw = 0;
		wdata->size.x = w->size.x;
		wdata->pos.x = w->pos.x;
		wdata->pos.y = w->pos.y + w->size.y;
	}
	widget *ret = widget_button_new(0, 0, label);
	ret->draw = widget_menu_draw;
	ret->action = action;
	ret->parent = wdata;
	if(wdata->child)
	{
		wdata->child->prev = ret;
		ret->pos.y = wdata->child->pos.y + wdata->child->size.y;
	}
	ret->next = wdata->child;
	wdata->child = ret;

	float x1, x2, y1, y2;
	sth_dim_text(stash, ret->fontface, ret->fontsize,
			label, &x1, &y1, &x2, &y2);
	ret->size.x = 20+ x2 - x1;
	if(wdata->size.x < ret->size.x)wdata->size.x = ret->size.x;

	return ret;
}
示例#2
0
ofRectangle ofxFontStash::getBBox( string text, float size, float xx, float yy ){

	ofRectangle r;

	if (stash != NULL){
		stringstream ss(text);
		string s;
		int line = 0;
		float totalH = 0;
		vector<ofRectangle> rects;
		while ( getline(ss, s, '\n') ) {
			float dx = 0;
			float w, h, x, y;
			sth_dim_text( stash, stashFontID, size, s.c_str(), &x, &y, &w, &h);
			r.x = x + xx;
			r.y = yy + y ;
			w = fabs (w - x);
			h = fabs(y - h);
			if(w > r.width) r.width = w;
			if(h > r.height) r.height = h;
			ofRectangle r2 = r;
			r2.y -= r2.height;
			r2.y += size * lineHeight * OFX_FONT_STASH_LINE_HEIGHT_MULT * line;
			rects.push_back(r2);
			//ofSetColor(255,32); //debug
			//ofRect(r2);
			line ++;
		}

		if(line > 1){ //if multiline
			r.y -= rects[0].height;
			for(int i = 0; i < rects.size(); i++){
				#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR == 8
				r = r.getUnion(rects[i]);	//TODO
				#endif
			}
		}else{
			r.y -= r.height;
		}

	}else{
		ofLogError("ofxFontStash", "can't getBoundingBoxSize() without having been setup first!");
	}
	return r;
}
示例#3
0
widget* widget_menu_add(widget *w, char* label)
{
	if(!w)return 0;
	widget *ret = widget_button_new(0, 0, label);
	ret->onclick = widget_menu_onclick;
	ret->release = widget_menu_release;
	ret->parent = w;
	if(w->child)
	{
		ret->pos.x = w->child->pos.x + w->child->size.x;
		ret->next = w->child;
		w->child->prev = ret;
	}
	w->child = ret;
	float x1, x2, y1, y2;
	sth_dim_text(stash, w->fontface, w->fontsize, label, &x1, &y1, &x2, &y2);
	ret->size.x = 20+ x2 - x1;

	return ret;
}
示例#4
0
void gui_http_draw(void)
{
	if(!http_accepting_new_clients)return;

	float shade = 0.1;

	glColor4f(shade,shade,shade,0.5);
	int x = 20;
	int y = vid_height - 200;

	int min_w = 10;

	char stop[] = "Stop accepting connections";

	float x1, x2, y1, y2;
	sth_dim_text(stash, 3, 20.0f, stop, &x1, &y1, &x2, &y2);

	min_w = x2 - x1;


	for(int i=0; i< http_num_pending; i++)
	{
		sth_dim_text(stash, 3, 20.0f,
			http_get_name_pending(i), &x1, &y1, &x2, &y2);

		int tmp_w = x2 - x1;

		if(min_w < tmp_w)min_w = tmp_w;



	}

	min_w += 20;

	glLoadIdentity();
	glTranslatef(x, y, 0);

	draw_rect( min_w+20, 40 * (http_num_pending+1) + 20);
	glTranslatef(10, -10, 0);



	for(int i=0; i<= http_num_pending; i++)
	{
		draw_rect( min_w, 30);
		glTranslatef(0, -40, 0);
	}

	glLoadIdentity();
	glTranslatef(x, y, 0);


	sth_begin_draw(stash);
	glColor4f(1,1,1,1);
	sth_draw_text(stash, 3, 20, 20, -30, stop, 0);
	for(int i=0; i< http_num_pending; i++)
	{
		sth_draw_text(stash, 3, 20, 20, -i*40-70, http_get_name_pending(i), 0);
	}

	sth_end_draw(stash);

	glLoadIdentity();

}