void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
{
    const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
                                                      : e.getDistanceFromDragStartY());


    if (layout->getItemCurrentPosition (itemIndex) != desiredPos)
    {
        layout->setItemPosition (itemIndex, desiredPos);
        hasBeenMoved();
    }
}
Esempio n. 2
0
void PAWN::legalMoves
  (
    POSITION start,
    const BOARD &board,
    POSITIONLIST &moves
  ) const
  {
    int delta, limit;
    POSITION doubleMovedPawn;

    if (promotePiece)
      {
        promotePiece->legalMoves(start, board, moves);
        return;
      }
    
    if (whatColor() == WHITE)
      {
        delta = 1;
        limit = NUMCOLS;
      }
    else
      {
        delta = -1;
        limit = -1;
      }

    moves.nMoves = 0;

    // check if en passant capture possible
    if (board.lastMoveDoublePawn(doubleMovedPawn))
      if ((start.col == doubleMovedPawn.col) &&
          (whatColor() != board.whatPiece(doubleMovedPawn)->whatColor()))
        {
          if ((start.row - 1) == doubleMovedPawn.row)
            {
              moves.end[moves.nMoves].row = start.row - 1;
              moves.end[moves.nMoves++].col = start.col + delta;
            }
          else if ((start.row + 1) == doubleMovedPawn.row)
            {
              moves.end[moves.nMoves].row = start.row + 1;
              moves.end[moves.nMoves++].col = start.col + delta;
            }
        }

    start.col += delta;

    if (start.col == limit)
      return;

    // check for moves ahead
    if (!board.whatPiece(start))
      {
        moves.end[moves.nMoves++] = start;
        // check if initial double move possible
        if (!hasBeenMoved())
          if (!board.whatPiece(start.row, start.col + delta))
            {
              moves.end[moves.nMoves].row = start.row;
              moves.end[moves.nMoves++].col = start.col + delta;
            }
      }

    // check for captures

    if (start.row > 0)
      if (board.whatPiece(start.row - 1, start.col))
        if (board.whatPiece(start.row - 1, start.col)->whatColor() !=
            whatColor())
          {
            moves.end[moves.nMoves].row = start.row - 1;
            moves.end[moves.nMoves++].col = start.col;
          }

    if (start.row < (NUMROWS - 1))
      if (board.whatPiece(start.row + 1, start.col))
        if (board.whatPiece(start.row + 1, start.col)->whatColor() !=
            whatColor())
          {
            moves.end[moves.nMoves].row = start.row + 1;
            moves.end[moves.nMoves++].col = start.col;
          }

    return;
  }