Exemplo n.º 1
0
void ClientBoard::OnPaint(wxPaintEvent& event)
{
    printf("this = %p,ClientBoard::OnPaint()\n",this);

    wxPaintDC dc(this);

    wxString sDraw = m_LogicBoard.szDrawText;
    dc.DrawText(sDraw,0,0);
    wxSize size = GetClientSize();
    int boardTop = size.GetHeight() - BoardHeight * SquareHeight();


    for (int i = 0; i < BoardHeight; ++i) {
        for (int j = 0; j < BoardWidth; ++j) {
            Tetrominoes shape = m_LogicBoard.ShapeAt(j, BoardHeight - i - 1);
            if (shape != NoShape)
                DrawSquare(dc, 0 + j * SquareWidth(),
                           boardTop + i * SquareHeight(), shape);
        }
    }

    if (m_LogicBoard.curPiece.GetShape() != NoShape) {
        for (int i = 0; i < 4; ++i) {
            int x = m_LogicBoard.curX + m_LogicBoard.curPiece.x(i);
            int y = m_LogicBoard.curY - m_LogicBoard.curPiece.y(i);
            DrawSquare(dc, 0 + x * SquareWidth(),
                       boardTop + (BoardHeight - y - 1) * SquareHeight(),
                       m_LogicBoard.curPiece.GetShape());
        }
    }
}
Exemplo n.º 2
0
void Board::OnPaint(wxPaintEvent& event)
{
    wxPaintDC dc(this);

    wxSize size = GetClientSize();
    int boardTop = size.GetHeight() - BoardHeight * SquareHeight();


    for (int i = 0; i < BoardHeight; ++i) {
        for (int j = 0; j < BoardWidth; ++j) {
            Tetrominoes shape = ShapeAt(j, BoardHeight - i - 1);
            if (shape != NoShape)
                DrawSquare(dc, 0 + j * SquareWidth(),
                           boardTop + i * SquareHeight(), shape);
        }
    }

    if (curPiece.GetShape() != NoShape) {
        for (int i = 0; i < 4; ++i) {
            int x = curX + curPiece.x(i);
            int y = curY - curPiece.y(i);
            DrawSquare(dc, 0 + x * SquareWidth(),
                       boardTop + (BoardHeight - y - 1) * SquareHeight(),
                       curPiece.GetShape());
        }
    }
}
Exemplo n.º 3
0
void Board::DrawSquare (wxPaintDC &dc, int x, int y, Tetrominoes shape)
{
    static wxColour colors[] = { wxColour (0, 0, 0), wxColour (204, 102, 102),
                                 wxColour (102, 204, 102), wxColour (102, 102, 204),
                                 wxColour (204, 204, 102), wxColour (204, 102, 204),
                                 wxColour (102, 204, 204), wxColour (218, 170, 0)
                               };
    static wxColour light[] = { wxColour (0, 0, 0), wxColour (248, 159, 171),
                                wxColour (121, 252, 121), wxColour (121, 121, 252),
                                wxColour (252, 252, 121), wxColour (252, 121, 252),
                                wxColour (121, 252, 252), wxColour (252, 198, 0)
                              };
    static wxColour dark[] = { wxColour (0, 0, 0), wxColour (128, 59, 59),
                               wxColour (59, 128, 59), wxColour (59, 59, 128),
                               wxColour (128, 128, 59), wxColour (128, 59, 128),
                               wxColour (59, 128, 128), wxColour (128, 98, 0)
                             };
    wxPen pen (light[int (shape)]);
    pen.SetCap (wxCAP_PROJECTING);
    dc.SetPen (pen);
    dc.DrawLine (x, y + SquareHeight() - 1, x, y);
    dc.DrawLine (x, y, x + SquareWidth() - 1, y);
    wxPen darkpen (dark[int (shape)]);
    darkpen.SetCap (wxCAP_PROJECTING);
    dc.SetPen (darkpen);
    dc.DrawLine (x + 1, y + SquareHeight() - 1,
                 x + SquareWidth() - 1, y + SquareHeight() - 1);
    dc.DrawLine (x + SquareWidth() - 1,
                 y + SquareHeight() - 1, x + SquareWidth() - 1, y + 1);
    dc.SetPen (*wxTRANSPARENT_PEN);
    dc.SetBrush (wxBrush (colors[int (shape)]));
    dc.DrawRectangle (x + 1, y + 1, SquareWidth() - 2,
                      SquareHeight() - 2);
}