Exemple #1
0
/**
Returns a reference to the dvector element at specified location (i) in dmatrix.
Bounds checking is performed.

\param i row index
*/
dvector& dmatrix::operator()(int i)
{
  //check that index i is in range
  assert((index_min <= i && i <= index_max) || is_valid_row(i));

  return *(m + i);
}
Exemple #2
0
/**
Returns a const reference to the element at specified location (i, j) in dmatrix.
Bounds checking is performed.

\param i row index
\param j col index
*/
const double& dmatrix::operator()(int i, int j) const
{
  //check that index i is in range
  assert((index_min <= i && i <= index_max) || is_valid_row(i));

  const dvector& dvi = elem(i);

  //check that index j is in range
  assert(dvi.is_valid_index(j));

  return *(dvi.v + j);
}
Exemple #3
0
/*=============================================================================
  Compute a single bitboard containing the horizontal adjacent squares to
  SQUARE
  =============================================================================*/
bitboard
Pawn::compute_side_moves (uint square, Player player) const
{
   bitboard side_moves = 0;
   int dx[PAWN_MOVES_COUNT - 1] = { -1, +1 };

   int column = (int) get_column (square);
   int row = (int) get_row (square);

   for (uint i = 0; i < PAWN_MOVES_COUNT - 1; i++)
   {
      int x = column + dx[i];
      if (IBoard::is_inside_board (row, x) && is_valid_row (row, player))
         side_moves |= (util::constants::ONE << (row * BOARD_SIZE + x));
   }
   return side_moves;
}
Exemple #4
0
void menu_ensure_cursor_valid(menu_type *m)
{
	int row;
	int count = m->filter_list ? m->filter_count : m->count;

	for (row = m->cursor; row < count; row++)
	{
		if (is_valid_row(m, row))
		{
			m->cursor = row;
			return;
		}
	}

	/* If we've run off the end, without finding a valid row, put cursor
	 * on the last row */
	m->cursor = count - 1;
}
Exemple #5
0
/*=============================================================================
  Compute a single bitboard containing non-capture moves for a pawn on SQUARE,
  assumming it is PLAYER's turn to move.
  =============================================================================*/
bitboard
Pawn::compute_simple_moves (uint square, Player player) const
{
   bitboard simple_moves = 0;
   int dy[PAWN_MOVES_COUNT - 1] = { +1, +2 };

   int column = (int) get_column (square);
   int row = (int) get_row (square);

   // Pawns on their first move can advance two squares
   uint steps_count = is_second_row (row, player) ? 2: 1;

   for (uint i = 0; i < steps_count; i++)
   {
      int y = row + (player == WHITE? -dy[i]: dy[i]);
      if (IBoard::is_inside_board (y, column) && is_valid_row (row, player))
         simple_moves |= (util::constants::ONE << (y * BOARD_SIZE + column));
   }

   return simple_moves;
}
Exemple #6
0
/**
 * Handle navigation keypresses.
 *
 * Returns TRUE if they key was intelligible as navigation, regardless of
 * whether any action was taken.
 */
bool menu_handle_keypress(menu_type *menu, const ui_event *in,
		ui_event *out)
{
	bool eat = FALSE;
	int count = menu->filter_list ? menu->filter_count : menu->count;

	/* Get the new cursor position from the menu item tags */
	//int new_cursor = get_cursor_key(menu, menu->top, in->key);
	int new_cursor = get_cursor_key(menu, menu->top, *in);
	if (new_cursor >= 0 && is_valid_row(menu, new_cursor))
	{
		if (!(menu->flags & MN_DBL_TAP) || new_cursor == menu->cursor)
			//out->type = EVT_SELECT;
			*out = EVT_SELECT;
		else
			//out->type = EVT_MOVE;
			*out = EVT_MOVE;

		menu->cursor = new_cursor;
	}

	/* Escape stops us here */
	//else if (in->key.code == ESCAPE)
	//	out->type = EVT_ESCAPE;
	else if (*in == ESCAPE)
		*out = EVT_ESCAPE;

	/* Menus with no rows can't be navigated or used, so eat all keypresses */
	else if (count <= 0)
		eat = TRUE;

	/* Try existing, known keys */
	//else if (in->key.code == ' ')
	else if (*in == ' ')
	{
		int rows = menu->active.page_rows;
		int total = count;

		if (rows < total)
		{
			/* Go to start of next page */
			menu->cursor += menu->active.page_rows;
			if (menu->cursor >= total - 1) menu->cursor = 0;
			menu->top = menu->cursor;
	
			//out->type = EVT_MOVE;
			*out = EVT_MOVE;
		}
		else
		{
			eat = TRUE;
		}
	}

	//else if (in->key.code == KC_ENTER)
	//	out->type = EVT_SELECT;
	else if ((*in == '\n') || (*in == '\r'))
		*out = EVT_SELECT;

	/* Try directional movement */
	else
	{
		//int dir = target_dir(in->key);
		int dir = get_keymap_dir(*in);

		if (dir)
		{
			*out = menu->skin->process_dir(menu, dir);

			//if (out->type == EVT_MOVE)
			if (*out == EVT_MOVE)
			{
				while (!is_valid_row(menu, menu->cursor))
				{
					/* Loop around */
					if (menu->cursor > count - 1)
						menu->cursor = 0;
					else if (menu->cursor < 0)
						menu->cursor = count - 1;
					else
						menu->cursor += ddy[dir];
				}

				assert(menu->cursor >= 0);
				assert(menu->cursor < count);
			}
		}
	}

	return eat;
}
Exemple #7
0
/*
 * Handle mouse input in a menu.
 * 
 * Mouse output is either moving, selecting, escaping, or nothing.  Returns
 * TRUE if something changes as a result of the click.
 */
bool menu_handle_mouse(menu_type *menu, const ui_event *in,
		ui_event *out)
{
	int new_cursor;
	int x,y;
	char b,p;
	int dir = 0;

	*out = EVT_NONE;

	Term_getmousepress(&p, &x, &y);
	b = p&0x7;
	//if (in->mouse.button == 2) {
	//	out->type = EVT_ESCAPE;
	if (b == 2) {
		*out = EVT_ESCAPE;
	} else
	if (b == 3) {
		*out = EVT_SELECT;
	} else
	if (b == 4) {
		*out = EVT_MOVE;
		dir = 8;
	} else
	if (b == 5) {
		*out = EVT_MOVE;
		dir = 2;
	} else
	if (b == 6) {
		*out = EVT_MOVE;
		dir = 4;
	} else
	if (b == 7) {
		*out = EVT_MOVE;
		dir = 6;
	} else
	/*if (!region_inside(&menu->active, in)) {*/
		/* A click to the left of the active region is 'back' */
	/*	if (!rect_region_inside(&menu->active, in) &&
			in->mouse.x < menu->active.col)
			out->type = EVT_ESCAPE;
	} else*/
	if (!rect_region_inside(&menu->active, y, x)) {
		/* A click outside of the active region is 'back' */
		if (menu->flags & MN_ESCAPE_OUTSIDE) {
			*out = EVT_ESCAPE;
		} else
		/* A click to the left of the active region is 'back' */
		if ((menu->flags & MN_ESCAPE_LEFT) &&
				x < menu->active.col)
		{
			*out = EVT_ESCAPE;
		}
	} else
	{
		int count = menu->filter_list ? menu->filter_count : menu->count;

		//new_cursor = menu->skin->get_cursor(in->mouse.y, in->mouse.x,
		new_cursor = menu->skin->get_cursor(menu, y, x,
				count, menu->top, &menu->active);
	
		if (is_valid_row(menu, new_cursor))
		{
			if (new_cursor == menu->cursor || !(menu->flags & MN_DBL_TAP))
				//out->type = EVT_SELECT;
				*out = EVT_SELECT;
			else
				//out->type = EVT_MOVE;
				*out = EVT_MOVE;

			menu->cursor = new_cursor;
		}
	}

	if (dir && (*out == EVT_MOVE)) {
		int count = menu->filter_list ? menu->filter_count : menu->count;
		*out = menu->skin->process_dir(menu, dir);

		/*if (out->type == EVT_MOVE) {*/
		if (*out == EVT_MOVE) {
			while (!is_valid_row(menu, menu->cursor)) {
				/* Loop around */
				if (menu->cursor > count - 1)
					menu->cursor = 0;
				else if (menu->cursor < 0)
					menu->cursor = count - 1;
				else
					menu->cursor += ddy[dir];
			}

			assert(menu->cursor >= 0);
			assert(menu->cursor < count);
		}
	}
	/*return out->type != EVT_NONE;*/
	return (*out) != (EVT_NONE);
}