-/*-------- BombCanvasClass::DrawField(dc, xc1, yc1, xc2, yc2) -------*/
-/* Draws the field on the device context dc */
-/* xc1,yc1 etc. are the (inclusive) limits of the area to be drawn, */
-/* expressed in cells. */
-/*---------------------------------------------------------------------*/
-void BombsCanvasClass::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2)
-{ int x,y,xmax,ymax;
- char buf[2];
- long chw, chh;
-
- wxColour *wxBlack = wxTheColourDatabase->FindColour("BLACK");
- wxColour *wxWhite = wxTheColourDatabase->FindColour("WHITE");
- wxColour *wxRed = wxTheColourDatabase->FindColour("RED");
- wxColour *wxBlue = wxTheColourDatabase->FindColour("BLUE");
- wxColour *wxGrey = wxTheColourDatabase->FindColour("LIGHT GREY");
- wxColour *wxGreen = wxTheColourDatabase->FindColour("GREEN");
-
- wxPen *blackPen = wxThePenList->FindOrCreatePen(*wxBlack, 1, wxSOLID);
- wxPen *redPen = wxThePenList->FindOrCreatePen(*wxRed, 1, wxSOLID);
- wxPen *bluePen = wxThePenList->FindOrCreatePen(*wxBlue, 1, wxSOLID);
- wxBrush *whiteBrush = wxTheBrushList->FindOrCreateBrush(*wxWhite, wxSOLID);
- wxBrush *greyBrush = wxTheBrushList->FindOrCreateBrush(*wxGrey, wxSOLID);
- wxBrush *redBrush = wxTheBrushList->FindOrCreateBrush(*wxRed, wxSOLID);
-
- xmax=field_width*x_cell*X_UNIT;
- ymax=field_height*y_cell*Y_UNIT;
-
-
- dc->SetPen(* blackPen);
- for(x=xc1; x<=xc2; x++)
- dc->DrawLine(x*x_cell*X_UNIT, 0, x*x_cell*X_UNIT, ymax);
- for(y=xc1; y<=yc2; y++)
- dc->DrawLine(0, y*y_cell*Y_UNIT, xmax, y*y_cell*Y_UNIT);
-
-
- wxFont font= BOMBS_FONT;
- dc->SetFont(font);
-
- buf[1]='\0';
- for(x=xc1; x<=xc2; x++)
- for(y=yc1; y<=yc2; y++)
- { if (wxGetApp().Game.IsMarked(x,y))
- { dc->SetPen(* blackPen);
- dc->SetBrush(* greyBrush);
- dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
- x_cell*X_UNIT+1, y_cell*Y_UNIT+1);
- *buf='M';
- if (!wxGetApp().Game.IsHidden(x,y) && wxGetApp().Game.IsBomb(x,y))
- dc->SetTextForeground(*wxBlue);
- else
- dc->SetTextForeground(*wxRed);
- dc->SetTextBackground(*wxGrey);
- dc->GetTextExtent(buf, &chw, &chh);
- dc->DrawText( buf,
- x*x_cell*X_UNIT + (x_cell*X_UNIT-chw)/2,
- y*y_cell*Y_UNIT + (y_cell*Y_UNIT-chh)/2
- );
- if (!wxGetApp().Game.IsHidden(x,y) && wxGetApp().Game.IsBomb(x,y))
- { dc->SetPen(*redPen);
- dc->DrawLine(x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
- (x+1)*x_cell*X_UNIT, (y+1)*y_cell*Y_UNIT);
- dc->DrawLine(x*x_cell*X_UNIT, (y+1)*y_cell*Y_UNIT,
- (x+1)*x_cell*X_UNIT, y*y_cell*Y_UNIT);
- }
- }
- else if (wxGetApp().Game.IsHidden(x,y))
- { dc->SetPen(*blackPen);
- dc->SetBrush(*greyBrush);
- dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
- x_cell*X_UNIT+1, y_cell*Y_UNIT+1);
- }
- else if (wxGetApp().Game.IsBomb(x,y))
- { dc->SetPen(* blackPen);
- dc->SetBrush(* redBrush);
- dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
- x_cell*X_UNIT+1, y_cell*Y_UNIT+1);
- *buf='B';
- dc->SetTextForeground(* wxBlack);
- dc->SetTextBackground(* wxRed);
- dc->GetTextExtent(buf, &chw, &chh);
- dc->DrawText( buf,
- x*x_cell*X_UNIT + (x_cell*X_UNIT-chw)/2,
- y*y_cell*Y_UNIT + (y_cell*Y_UNIT-chh)/2
- );
- if (wxGetApp().Game.IsExploded(x,y))
- { dc->SetPen(* bluePen);
- dc->DrawLine(x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
- (x+1)*x_cell*X_UNIT, (y+1)*y_cell*Y_UNIT);
- dc->DrawLine(x*x_cell*X_UNIT, (y+1)*y_cell*Y_UNIT,
- (x+1)*x_cell*X_UNIT, y*y_cell*Y_UNIT);
- }
- }
- else // Display a digit
- { dc->SetPen(* blackPen);
- dc->SetBrush(* whiteBrush);
- dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
- x_cell*X_UNIT+1, y_cell*Y_UNIT+1);
- *buf = (wxGetApp().Game.Get(x,y) & BG_MASK) + '0';
+// Draws the field on the device context dc
+// xc1,yc1 etc. are the (inclusive) limits of the area to be drawn,
+// expressed in cells.
+void BombsCanvas::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2)
+{
+ wxString buf;
+ wxCoord chw, chh;
+
+ wxColour wxYellow = wxTheColourDatabase->Find(wxT("YELLOW"));
+ wxColour wxFocused = wxTheColourDatabase->Find(wxT("GREY"));
+
+ wxPen *bluePen = wxThePenList->FindOrCreatePen(*wxBLUE, 1, wxSOLID);
+
+ wxBrush *focusedBrush = wxTheBrushList->FindOrCreateBrush(wxFocused, wxSOLID);
+ wxBrush *yellowBrush = wxTheBrushList->FindOrCreateBrush(wxYellow, wxSOLID);
+
+ dc->SetPen(*wxBLACK_PEN);
+
+ int x, y;
+ int xMax = this->GetGridSizeInPixels().GetWidth();
+ int yMax = this->GetGridSizeInPixels().GetHeight();
+ for(x=xc1; x<=xc2; x++)
+ dc->DrawLine(x*m_cellWidth*X_UNIT, 0, x*m_cellWidth*X_UNIT, yMax);
+ for(y=xc1; y<=yc2; y++)
+ dc->DrawLine(0, y*m_cellHeight*Y_UNIT, xMax, y*m_cellHeight*Y_UNIT);
+
+
+ wxFont font= BOMBS_FONT;
+ dc->SetFont(font);
+
+ for(x=xc1; x<=xc2; x++)
+ for(y=yc1; y<=yc2; y++)
+ {
+ if (m_game->IsMarked(x,y))
+ {
+ dc->SetPen(*wxBLACK_PEN);
+
+ if (m_game->IsFocussed(x, y))
+ dc->SetBrush(*focusedBrush);
+ else
+ dc->SetBrush(*wxLIGHT_GREY_BRUSH);
+
+ dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
+ m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1);
+ buf = wxT("M");
+ if (!m_game->IsHidden(x,y) && m_game->IsBomb(x,y))
+ dc->SetTextForeground(*wxBLUE);
+ else
+ dc->SetTextForeground(*wxRED);
+
+ dc->SetTextBackground(*wxLIGHT_GREY);
+ dc->GetTextExtent(buf, &chw, &chh);
+ dc->DrawText( buf,
+ x*m_cellWidth*X_UNIT + (m_cellWidth*X_UNIT-chw)/2,
+ y*m_cellHeight*Y_UNIT + (m_cellHeight*Y_UNIT-chh)/2 );
+
+ if (!m_game->IsHidden(x,y) && m_game->IsBomb(x,y))
+ {
+ dc->SetPen(*wxRED_PEN);
+ dc->DrawLine(x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
+ (x+1)*m_cellWidth*X_UNIT, (y+1)*m_cellHeight*Y_UNIT);
+ dc->DrawLine(x*m_cellWidth*X_UNIT, (y+1)*m_cellHeight*Y_UNIT,
+ (x+1)*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT);
+ }
+ }
+ else if (m_game->IsHidden(x,y))
+ {
+ dc->SetPen(*wxBLACK_PEN);
+ if (m_game->IsFocussed(x, y))
+ dc->SetBrush(*focusedBrush);
+ else
+ dc->SetBrush(*wxLIGHT_GREY_BRUSH);
+
+ dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
+ m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1);
+ }
+ else if (m_game->IsBomb(x,y))
+ {
+ dc->SetPen(*wxBLACK_PEN);
+ dc->SetBrush(*wxRED_BRUSH);
+ dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
+ m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1);
+ buf = wxT("B");
+ dc->SetTextForeground(*wxBLACK);
+ dc->SetTextBackground(*wxRED);
+ dc->GetTextExtent(buf, &chw, &chh);
+ dc->DrawText( buf,
+ x*m_cellWidth*X_UNIT + (m_cellWidth*X_UNIT-chw)/2,
+ y*m_cellHeight*Y_UNIT + (m_cellHeight*Y_UNIT-chh)/2);
+ if (m_game->IsExploded(x,y))
+ {
+ dc->SetPen(*bluePen);
+ dc->DrawLine(x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
+ (x+1)*m_cellWidth*X_UNIT, (y+1)*m_cellHeight*Y_UNIT);
+ dc->DrawLine(x*m_cellWidth*X_UNIT, (y+1)*m_cellHeight*Y_UNIT,
+ (x+1)*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT);
+ }
+ }
+ else // Display a digit
+ {
+ dc->SetPen(*wxBLACK_PEN);
+ if (m_game->IsFocussed(x, y))
+ dc->SetBrush(*focusedBrush);
+ else if (m_game->IsSelected(x,y))
+ dc->SetBrush(*wxWHITE_BRUSH);
+ else
+ dc->SetBrush(*yellowBrush);
+ dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
+ m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1);
+
+ int digit_value = m_game->Get(x,y) & BG_MASK;
+ switch(digit_value)
+ {
+ case 0:
+ buf = wxT("0");
+ dc->SetTextForeground(*wxGREEN);
+ break;
+ case 1:
+ buf = wxT("1");
+ dc->SetTextForeground(*wxBLUE);
+ break;
+ default:
+ buf.Printf(wxT("%d"),digit_value);
+ dc->SetTextForeground(*wxBLACK);
+ break;
+ }