Exemple #1
0
void table_clean_and_set(void) {
	Customer *c_list = table.customers;
	Customer *c = NULL;
	unsigned char cnt = get_customer_list_size(c_list);
	DBG("%U Customers to remove from table\n", cnt);

	c = pop_customer_from_list(&c_list);
	while (NULL != c) {
		DBG("Customer %U left the table\n", c->id);
		free(c);
		c = pop_customer_from_list(&c_list);
	}

	table_setup();
}
Exemple #2
0
static void table_show_player_box(int player, int write_to_screen)
{
	int x, y, w, h;
	const char *name = player_names[player];
	const char *message = player_messages[player];
	int string_y;
	int max_width = 0;
	static PangoLayout *layout = NULL;
	PangoRectangle rect;
	GdkGC *gc = table_style->fg_gc[GTK_WIDGET_STATE(table)];

	static int max_height = 0;

	assert(table_ready);

	if (!layout) {
		/* This variable is static so we only allocate it once. */
		layout = pango_layout_new(gdk_pango_context_get());
	}

	pango_layout_set_font_description(layout, table_style->font_desc);

	get_text_box_pos(player, &x, &y);
	x++;
	y++;

	/* Clear the text box */
	gdk_draw_rectangle(table_buf,
			   table_style->bg_gc[GTK_WIDGET_STATE(table)],
			   TRUE, x, y, TEXT_BOX_WIDTH - 1,
			   TEXT_BOX_WIDTH - 1);

	x += XWIDTH;
	y += XWIDTH;
	w = h = TEXT_WIDTH;

	string_y = y;	/* The y values we're going to draw at. */

	/* Draw the name. */
	if (name) {
		assert(strchr(name, '\n') == NULL);

		pango_layout_set_text(layout, name, -1);
		pango_layout_get_pixel_extents(layout, NULL, &rect);

		max_width = MAX(max_width, rect.width);
		max_height = MAX(max_height, rect.height);

		gdk_draw_layout(table_buf, gc,
				x + (w - rect.width) / 2, string_y,
				layout);

		string_y += max_height + 5;
	}

	/* Draw player message. */
	if (message) {
		char *my_message = ggz_strdup(message);
		char *next = my_message;

		/* This is so ugly!! Is there no better way?? */
		do {
			char *next_after_this = strchr(next, '\n');

			if (next_after_this) {
				*next_after_this = '\0';
				next_after_this++;
			}

			string_y += 3;

			pango_layout_set_text(layout, next, -1);
			pango_layout_get_pixel_extents(layout, NULL,
						       &rect);

			max_height = MAX(max_height, rect.height);
			max_width = MAX(max_width, rect.width);

			gdk_draw_layout(table_buf, gc,
					x + 3, string_y, layout);

			string_y += rect.height;

			next = next_after_this;
		} while (next && *next);

		ggz_free(my_message);
	}

	/* FIXME: we shouldn't call table_setup() from *within* the drawing
	   code */
	if (set_min_text_width(string_y - y)
	    || set_min_text_width(max_width)) {
		table_setup();
	}

	if (write_to_screen)
		table_show_table(x, y, TEXT_BOX_WIDTH - 1,
				 TEXT_BOX_WIDTH - 1);
}