Exemplo n.º 1
0
void print_properties(struct properties *props) {
  if (props == NULL || list_size(props->props) == 0)
    printf("()");
  else {
    struct property* prop;
    for (int i = 0; i < list_size(props->props); i++) {
      prop = (struct property*) list_element_at(props->props, i);
      printf("(%s,%s)", prop->key, prop->value);
    }
  }
}
Exemplo n.º 2
0
/**
 * Inserts an element at the specified index in the list. This performs poorly
 * and where possible list_append() and list_prepend() should be used instead.
 *
 * If index is 0, the result will be equivalent to list_prepend().
 *
 * If index is >= the length of the list, nothing is added.
 *
 * @param list	The list to perform the insert in.
 * @param index	The position at which to insert the element in the list.
 * @param e	The element to insert.
 * @see		list_prepend_element(list, e)
 * @see		list_append_element(list, e)
 * @return	The index assigned to the element. Notably, this index will
 *		differ from the specified one if the list does not contain
 *		so many elements.
 */
int list_insert_element_at(struct list *list, int index, struct element *e)
{
	struct element *curr = list_element_at(list, index);

	/* Sanity check. */
	if(curr == NULL) {
		/* Specified index beyond current range, or the list is empty.
		 * In either case: append element last in list instead. */
		list_append_element(list, e);
		return list_count(list);
	} else {
		/* Prepend to curr. */
		e->next = curr;
		e->prev = curr->prev;
		curr->prev->next = e;
		curr->prev = e;
		return index;
	}
}
Exemplo n.º 3
0
void
ui_render_move_history(void)
{
	const struct font_render_info *const font = ui.font_small;
	const struct list *const move_history = ui.move_history;
	static int cur_move, i, y, x, x0, y0, x1, y1;
	char str[20];
	static int row_width_0, row_width_1;

	glColor4f(1.f, 1.f, 1.f, 1.f);

	row_width_0 = string_width_in_pixels(font, "XXX");
	row_width_1 = string_width_in_pixels(font, "XXXXXXXXX");

	x = ui.cur_width - (row_width_0 + 2*row_width_1 +
	  3*MOVE_HISTORY_BORDER);
	y = ui.cur_height - (MOVE_TABLE_ROWS + 1)*
	  (font->char_height + 2);

	/* render background */

	glPushAttrib(GL_ALL_ATTRIB_BITS);

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	glShadeModel(GL_FLAT);
	glDisable(GL_CULL_FACE);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0.f, ui.cur_width, ui.cur_height, 0.f, -1.f,
	  1.f);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	glColor4f(.4f, .4f, .4f, .5f);

	x0 = x - MOVE_HISTORY_BORDER;
	x1 = x + row_width_0 + 2*row_width_1 + MOVE_HISTORY_BORDER;

	/* HACK */
	y0 = y - font->char_height;
	y1 = y + font->char_height*MOVE_TABLE_ROWS + 2*MOVE_HISTORY_BORDER;

	glBegin(GL_QUADS);
	glVertex2f(x0, y0);
	glVertex2f(x1, y0);
	glVertex2f(x1, y1);
	glVertex2f(x0, y1);
	glEnd();

	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	glPopAttrib();

	/* render text */

	cur_move = (ui.board_state.cur_ply - 1)/2;

	i = cur_move < MOVE_TABLE_ROWS - 1 ? 0 :
	  cur_move - (MOVE_TABLE_ROWS - 1);

	for (; i <= cur_move; i++) {
		sprintf(str, "%d.", i + 1);
		render_string(font, str, x, y);

		if (i*2 < ui.board_state.cur_ply)
			render_string(font,
			  (char *)list_element_at(move_history, i*2),
			  x + row_width_0, y);

		if (i*2 + 1 < ui.board_state.cur_ply)
			render_string(font,
			  (char *)list_element_at(move_history, i*2 + 1),
			  x + row_width_0 + row_width_1, y);

		y += font->char_height + 2;
	}
}