예제 #1
0
파일: table.c 프로젝트: ralight/ggz
/* Setup some of the table data structures.  This is called just once
   immediately upon startup. */
void table_initialize(void)
{
	static int call_count = 0;

	/* Just a sanity check; we don't want to call this function twice. */
	assert(call_count == 0);
	call_count++;

	ggz_debug(DBG_TABLE, "Initializing table.");

	/* This starts our drawing code */
	table = g_object_get_data(G_OBJECT(dlg_main), "fixed1");
	table_style = gtk_widget_get_style(table);
	gtk_widget_show(table);

	table_drawing_area = gtk_drawing_area_new();
	gtk_widget_set_size_request(table_drawing_area,
				    get_table_width(), get_table_height());
	gtk_fixed_put(GTK_FIXED(table), table_drawing_area, 0, 0);
	gtk_widget_show(table_drawing_area);
	g_signal_connect(table_drawing_area, "expose_event",
			 GTK_SIGNAL_FUNC(on_table_expose_event), NULL);

	assert(table_drawing_area->window);
	assert(get_table_width() > 0 && get_table_height() > 0);
	table_buf = gdk_pixmap_new(table->window,
				   get_table_width(), get_table_height(),
				   -1);
	assert(table_buf);

	/* Redraw and display the table. */
	table_redraw();

	table_show_player_list();
}
예제 #2
0
파일: table.c 프로젝트: ralight/ggz
/* Handle a redraw of necessary items, for instance when a Gtk style change is 
   signaled. */
void table_redraw(void)
{
	ggz_debug(DBG_TABLE, "Redrawing table. ");
	if (table_ready) {
		int p;

		/* Complete (zip) any animation in process */
		animation_stop(TRUE);

		/* I really don't know why these are necessary... */
		gtk_widget_grab_focus(dlg_main);
		table_style = gtk_widget_get_style(table);

		/* Redraw everything to the buffer */
		table_clear_table(FALSE);
		draw_card_areas(FALSE);
		table_display_all_hands(FALSE);
		table_show_cards(FALSE);
		for (p = 0; p < ggzcards.num_players; p++)
			table_show_player_box(p, FALSE);

		/* Then draw the whole buffer to the window */
		table_show_table(0, 0, get_table_width(),
				 get_table_height());

		/* There has GOT to be a better way to force the redraw! */
		gdk_window_hide(table_drawing_area->window);
		gdk_window_show(table_drawing_area->window);
	} else {	/* not if (table_ready) */
		if (table_buf)
			draw_splash_screen();
	}
}
예제 #3
0
파일: table.c 프로젝트: ralight/ggz
static void table_clear_table(int write_to_screen)
{
	assert(table_buf && table_style);

	/* There's no real reason why write_to_screen shouldn't be used, but
	   it's probably not a good idea. */
	assert(!write_to_screen);

	/* Clear the buffer to the style's background color */
	gdk_draw_rectangle(table_buf,
			   table_style->bg_gc[GTK_WIDGET_STATE(table)],
			   TRUE, 0, 0, get_table_width(),
			   get_table_height());

	if (write_to_screen)
		table_show_table(0, 0, get_table_width(),
				 get_table_height());
}
예제 #4
0
void CSSTableSizeGrid::expand_table_width(CSSUsedValue width)
{
	CSSUsedValue available_width = get_table_width();
	if (available_width < width)
	{
		for (size_t col = 0; col < content_widths.size(); col++)
			content_widths[col] += (width-available_width)/content_widths.size();
	}
}
예제 #5
0
파일: table.c 프로젝트: ralight/ggz
/* Draws a "splash screen" that is shown before the game is initialized. */
static void draw_splash_screen(void)
{
#if 0
	card_t card = { ACE_HIGH, SPADES, 0 };
#endif

	ggz_debug(DBG_TABLE, "Drawing splash screen.");

	assert(!game_started && !table_ready);
	assert(table_buf);

	table_clear_table(FALSE);

#if 0
	/* This is temporarily disabled until I can figure out how to get it
	   to work with the player list. */
	draw_card(card, 0,
		  (get_table_width() - CARDWIDTH) / 2,
		  (get_table_height() - CARDHEIGHT) / 2, table_buf);
#endif

	table_show_table(0, 0, get_table_width(), get_table_height());
}
예제 #6
0
파일: table.c 프로젝트: ralight/ggz
/* Setup all table data that's not initialized by table_initialize.  This may
   be called multiple times (for instance, to resize the table), and it's not
   called until the server tells us how big the table must be. */
void table_setup(void)
{
	/* TODO: we really should draw something before this point, since the
	   player needs to see who's playing.  However, for now this will
	   work.  The problem is that before you choose what game you're
	   playing, the server doesn't know how many seats there are so it
	   just tells us 0 - even if there are players already connected. */
	if (ggzcards.num_players == 0) {
		ggz_error_msg("table_setup: num_players is zero.");
		return;
	}
	if (get_max_hand_size() == 0) {
		ggz_error_msg("table_setup: max hand size is zero.");
		return;
	}
	if (get_card_width(0) == 0 || get_card_height(0) == 0) {
		ggz_error_msg("table_setup: max card size is zero.");
		return;
	}

	if (!game_started) {
		/* If we join a game in progress, this can happen.  Probably
		   it should be fixed... */
		ggz_error_msg("ERROR - table_setup() called "
			      "without a game started.");
		game_started = TRUE;
	}

	ggz_debug(DBG_TABLE,
		  "Setting up table." "  Width and height are %d."
		  "  %d players.", get_table_width(),
		  ggzcards.num_players);

	/* We may need to resize the table */
	gtk_widget_set_size_request(table, get_table_width(),
				    get_table_height());
	gtk_widget_set_size_request(table_drawing_area,
				    get_table_width(), get_table_height());

	/* And resize the table buffer... */
	/* Note: I'm not entirely sure how reference counts work for gdk. I
	   assume that when I create a new pixmap (as below), it starts with a 
	   refcount of 1.  In that case, this code should correctly free the
	   pixmap when it is discarded. */
	assert(table_buf);
	g_object_unref(table_buf);
	table_buf = gdk_pixmap_new(table->window,
				   get_table_width(), get_table_height(),
				   -1);

	/* Resize the animation buffer. */
	anim_setup();

	/* _Now_ we're ready to draw stuff. */
	table_ready = TRUE;

	/* Revert to having no selected card. */
	selected_card = -1;

	/* Redraw and display the table. */
	table_redraw();
}
예제 #7
0
파일: html_tbl.c 프로젝트: ebichu/dd-wrt
void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof, unsigned char **end, void *f)
{
	struct part *p = f;
	int border, cellsp, vcellpd, cellpd, align;
	int frame, rules, width, wf;
	struct rgb bgcolor;
	struct table *t;
	char *al;
	int cye;
	int x;
	int i;
	/*int llm = last_link_to_move;*/
	struct s_e *bad_html;
	int bad_html_n;
	struct node *n, *nn;
	int cpd_pass, cpd_width, cpd_last;
	/*if (!p->data) {
		debug("nested tables not supported");
		return;
	}*/
	table_level++;
	memcpy(&bgcolor, &par_format.bgcolor, sizeof(struct rgb));
	get_bgcolor(attr, &bgcolor);
	if ((border = get_num(attr, "border")) == -1) border = has_attr(attr, "border") || has_attr(attr, "rules") || has_attr(attr, "frame");
	/*if (!border) border = 1;*/

	if ((cellsp = get_num(attr, "cellspacing")) == -1) cellsp = 1;
	if ((cellpd = get_num(attr, "cellpadding")) == -1) {
		vcellpd = 0;
		cellpd = !!border;
	} else {
		vcellpd = cellpd >= HTML_CHAR_HEIGHT / 2 + 1;
		cellpd = cellpd >= HTML_CHAR_WIDTH / 2 + 1;
	}
	if (!border) cellsp = 0;
	else if (!cellsp) cellsp = 1;
	if (border > 2) border = 2;
	if (cellsp > 2) cellsp = 2;
	align = par_format.align;
	if (align == AL_NO || align == AL_BLOCK) align = AL_LEFT;
	if ((al = get_attr_val(attr, "align"))) {
		if (!strcasecmp(al, "left")) align = AL_LEFT;
		if (!strcasecmp(al, "center")) align = AL_CENTER;
		if (!strcasecmp(al, "right")) align = AL_RIGHT;
		mem_free(al);
	}
	frame = F_BOX;
	if ((al = get_attr_val(attr, "frame"))) {
		if (!strcasecmp(al, "void")) frame = F_VOID;
		if (!strcasecmp(al, "above")) frame = F_ABOVE;
		if (!strcasecmp(al, "below")) frame = F_BELOW;
		if (!strcasecmp(al, "hsides")) frame = F_HSIDES;
		if (!strcasecmp(al, "vsides")) frame = F_VSIDES;
		if (!strcasecmp(al, "lhs")) frame = F_LHS;
		if (!strcasecmp(al, "rhs")) frame = F_RHS;
		if (!strcasecmp(al, "box")) frame = F_BOX;
		if (!strcasecmp(al, "border")) frame = F_BOX;
		mem_free(al);
	}
	rules = border ? R_ALL : R_NONE;
	if ((al = get_attr_val(attr, "rules"))) {
		if (!strcasecmp(al, "none")) rules = R_NONE;
		if (!strcasecmp(al, "groups")) rules = R_GROUPS;
		if (!strcasecmp(al, "rows")) rules = R_ROWS;
		if (!strcasecmp(al, "cols")) rules = R_COLS;
		if (!strcasecmp(al, "all")) rules = R_ALL;
		mem_free(al);
	}
	if (!border) frame = F_VOID;
	wf = 0;
	if ((width = get_width(attr, "width", p->data || p->xp)) == -1) {
		width = par_format.width - par_format.leftmargin - par_format.rightmargin;
		if (width < 0) width = 0;
		wf = 1;
	}
	if (!(t = parse_table(html, eof, end, &bgcolor, p->data || p->xp, &bad_html, &bad_html_n))) {
		mem_free(bad_html);
		goto ret0;
	}
	for (i = 0; i < bad_html_n; i++) {
		while (bad_html[i].s < bad_html[i].e && WHITECHAR(*bad_html[i].s)) bad_html[i].s++;
		while (bad_html[i].s < bad_html[i].e && WHITECHAR(bad_html[i].e[-1])) bad_html[i].e--;
		if (bad_html[i].s < bad_html[i].e) parse_html(bad_html[i].s, bad_html[i].e, put_chars_f, line_break_f, special_f, p, NULL);
	}
	mem_free(bad_html);
	html_stack_dup();
	html_top.dontkill = 1;
	par_format.align = AL_LEFT;
	t->p = p;
	t->border = border;
	t->cellpd = cellpd;
	t->vcellpd = vcellpd;
	t->cellsp = cellsp;
	t->frame = frame;
	t->rules = rules;
	t->width = width;
	t->wf = wf;
	cpd_pass = 0;
	cpd_last = t->cellpd;
	cpd_width = 0;	/* not needed, but let the warning go away */
	again:
	get_cell_widths(t);
	if (get_column_widths(t)) goto ret2;
	get_table_width(t);
	if (!p->data && !p->xp) {
		if (!wf && t->max_t > width) t->max_t = width;
		if (t->max_t < t->min_t) t->max_t = t->min_t;
		if (t->max_t + par_format.leftmargin + par_format.rightmargin > p->xmax) p->xmax = t->max_t + par_format.leftmargin + par_format.rightmargin;
		if (t->min_t + par_format.leftmargin + par_format.rightmargin > p->x) p->x = t->min_t + par_format.leftmargin + par_format.rightmargin;
		goto ret2;
	}
	if (!cpd_pass && t->min_t > width && t->cellpd) {
		t->cellpd = 0;
		cpd_pass = 1;
		cpd_width = t->min_t;
		goto again;
	}
	if (cpd_pass == 1 && t->min_t > cpd_width) {
		t->cellpd = cpd_last;
		cpd_pass = 2;
		goto again;
	}
	/*debug("%d %d %d", t->min_t, t->max_t, width);*/
	if (t->min_t >= width) distribute_widths(t, t->min_t);
	else if (t->max_t < width && wf) distribute_widths(t, t->max_t);
	else distribute_widths(t, width);
	if (!p->data && p->xp == 1) {
		int ww = t->rw + par_format.leftmargin + par_format.rightmargin;
		if (ww > par_format.width) ww = par_format.width;
		if (ww < t->rw) ww = t->rw;
		if (ww > p->x) p->x = ww;
		p->cy += t->rh;
		goto ret2;
	}
#ifdef HTML_TABLE_2ND_PASS
	check_table_widths(t);
#endif
	x = par_format.leftmargin;
	if (align == AL_CENTER) x = (par_format.width + par_format.leftmargin - par_format.rightmargin - t->rw) / 2;
	if (align == AL_RIGHT) x = par_format.width - par_format.rightmargin - t->rw;
	if (x + t->rw > par_format.width) x = par_format.width - t->rw;
	if (x < 0) x = 0;
	/*display_table(t, x, p->cy, &cye);*/
	get_table_heights(t);
	if (!p->data) {
		if (t->rw + par_format.leftmargin + par_format.rightmargin > p->x) p->x = t->rw + par_format.leftmargin + par_format.rightmargin;
		p->cy += t->rh;
		goto ret2;
	}
	n = p->data->nodes.next;
	n->yw = p->yp - n->y + p->cy;
	display_complicated_table(t, x, p->cy, &cye);
	display_table_frames(t, x, p->cy);
	nn = mem_alloc(sizeof(struct node));
	nn->x = n->x;
	nn->y = p->yp + cye;
	nn->xw = n->xw;
	add_to_list(p->data->nodes, nn);
	/*sdbg(p->data);*/
	/*for (y = p->cy; y < cye; y++) {
		last_link_to_move = llm;
		align_line(p, y);
	}*/
	/*if (p->cy + t->rh != cye) internal("size does not match; 1:%d, 2:%d", p->cy + t->rh, cye);*/
	p->cy = cye;
	p->cx = -1;

	ret2:
	p->link_num = t->link_num;
	if (p->cy > p->y) p->y = p->cy;
	/*ret1:*/
	free_table(t);
	kill_html_stack_item(&html_top);
	ret0:
	/*ret:*/
	table_level--;
	if (!table_level) free_table_cache();
}