Esempio n. 1
0
File: ui.c Progetto: JBarrada/fancy
void draw_menu(MENU *menu) {
	int i;

	uint32_t height = menu->vpad;
	uint32_t width=0, text_width;
	for (i=0; i<10; i++) {
		if (menu->items[i].active) {
			height += menu->vpad + menu->items[i].size.height;
			text_width = get_str_width_big(menu->items[i].header_text.text1);
			if ((text_width + (2*menu->hpad)) > width) {
				width = text_width + (2*menu->hpad);
			} 
		}
	}
	
	uint32_t absolute_x = menu->pos.x + (WIDTH_W/2) - (width/2);
	uint32_t absolute_y = menu->pos.y + (HEIGHT_W/2) - (height/2);
	rectangle_filled(absolute_x, absolute_y, width, height, menu->bg);
	
	if (menu->header.active)
		absolute_y += draw_item(&menu->header, absolute_x, absolute_y);
	
	absolute_x += menu->hpad;
	absolute_y += menu->vpad;
	for (i=0; i<10; i++) {
		if (menu->items[i].active)
			absolute_y += menu->vpad + draw_menuitem(&menu->items[i], absolute_x, absolute_y);
	}
}
Esempio n. 2
0
unsigned int update_menuitem(int mousex)
{
	static unsigned int last_item; // retain value from last call
	unsigned int i;
	if (mousex == INT_MAX) // entered function to set last_item
	{
		last_item = num_menuitems;
		return UINT_MAX;
	}
	for (i = 0; i < num_menuitems; i++)
	{
		if ((mousex >= menuitems[i].x) && (mousex <= (menuitems[i].x + menuitems[i].width)))
		{
			break;
		}
	}

	if (i != last_item) // don't redraw if same
	{
		if (last_item != num_menuitems)
		{
			draw_menuitem(last_item, 0);
		}
		if (i != num_menuitems)
		{
			draw_menuitem(i, 1);
		}
		last_item = i; // set to new menu item
	}

	if (i != num_menuitems)
	{
		return i;
	}
	else // no item selected
	{
		return UINT_MAX;
	}
}