Exemplo n.º 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;
}
Exemplo n.º 2
0
int gui_init(int argc, char *argv[])
{
	memset(frame_time, 0, sizeof(long)*MAX_FRAMES);
	stash = sth_create(512,512);
	if (!stash)
	{
		printf("Could not create stash.\n");
		return -1;
	}
	font_load(0,"data/gui/SourceCodePro-Regular.ttf");
	font_load(1,"data/gui/SourceCodePro-Bold.ttf");
	font_load(2,"data/gui/SourceSansPro-Regular.ttf");
	font_load(3,"data/gui/SourceSansPro-Bold.ttf");

	widget *w;
	widget *menu = widget_menu_new();
	widget *item = widget_menu_add(menu, "File");
	widget_menu_item_add(item, "Open", spawn_open);
	widget_menu_item_add(item, "Voxel Open", spawn_voxopen);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "Exit", menu_killme);

	item = widget_menu_add(menu, "Display");
	w = widget_menu_item_add(item, "	 Fullscreen - F11", menu_fullscreen);
	w->draw = widget_menu_bool_draw;
	w->data2 = &fullscreen;
	w = widget_menu_item_add(item, "	 Draw 3D Texture", menu_texdraw);
	w->draw = widget_menu_bool_draw;
	extern int texdraw;
	w->data2 = &texdraw;
	widget_menu_item_add(item, "GPU Information", spawn_gpuinfo);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "Rebuild Shaders", voxel_rebuildshader);

	item = widget_menu_add(menu, "Input");
	w = widget_menu_item_add(item, "	 Accepting Tablets",
		menu_http_toggle);
	w->draw = widget_menu_bool_draw;
	w->data2 = &http_accepting_new_clients;
	w = widget_menu_item_add(item, "Authorised Devices", spawn_http_auth );
	w = widget_menu_item_add(item, "Pending Authorisation", spawn_http_pend);

	item = widget_menu_add(menu, "Help");
	widget_menu_item_add(item, "Overview \u2560", 0);
	widget_menu_item_add(item, "Wiki \u26a0", 0);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "Credits \u2623", spawn_credits);
	widget_menu_item_add(item, "License", spawn_license);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "About", spawn_about);

	widget_add(menu);

	last_time = sys_time();
	return 0;
}