Fix warnings and modernize demo code

Fix wxFont, wxPen and wxBrush style deprecation warnings.
Add wxFALLTHROUGH to resolve implicit fallthrough warnings in switch statements.
Fix build error when using long for GetTextExtent (with wxUSE_GRID 0).
Remove unused icon from fractal demo.
This commit is contained in:
Maarten Bent
2017-11-25 17:39:44 +01:00
parent dc6858d905
commit 4d8fad3d80
12 changed files with 32 additions and 39 deletions

View File

@@ -218,8 +218,7 @@ BombsCanvas::BombsCanvas(wxFrame *parent, BombsGame *game)
m_game = game; m_game = game;
int sx, sy; int sx, sy;
wxClientDC dc(this); wxClientDC dc(this);
wxFont font= BOMBS_FONT; dc.SetFont(BOMBS_FONT);
dc.SetFont(font);
wxCoord chw, chh; wxCoord chw, chh;
wxString buf = wxT("M"); wxString buf = wxT("M");

View File

@@ -118,7 +118,7 @@ private:
* BombsCanvas::x_cell and y_cell * BombsCanvas::x_cell and y_cell
*/ */
#define BOMBS_FONT wxFont(14, wxROMAN, wxNORMAL, wxNORMAL) #define BOMBS_FONT wxFont(wxFontInfo(14).Family(wxFONTFAMILY_ROMAN))
#endif // #ifndef _WX_DEMOS_BOMBS_BOMBS_H_ #endif // #ifndef _WX_DEMOS_BOMBS_BOMBS_H_

View File

@@ -33,14 +33,6 @@ void BombsCanvas::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2)
wxString buf; wxString buf;
wxCoord chw, chh; 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); dc->SetPen(*wxBLACK_PEN);
int x, y; int x, y;
@@ -52,8 +44,7 @@ void BombsCanvas::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2)
dc->DrawLine(0, y*m_cellHeight*Y_UNIT, xMax, y*m_cellHeight*Y_UNIT); dc->DrawLine(0, y*m_cellHeight*Y_UNIT, xMax, y*m_cellHeight*Y_UNIT);
wxFont font= BOMBS_FONT; dc->SetFont(BOMBS_FONT);
dc->SetFont(font);
for(x=xc1; x<=xc2; x++) for(x=xc1; x<=xc2; x++)
for(y=yc1; y<=yc2; y++) for(y=yc1; y<=yc2; y++)
@@ -63,7 +54,7 @@ void BombsCanvas::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2)
dc->SetPen(*wxBLACK_PEN); dc->SetPen(*wxBLACK_PEN);
if (m_game->IsFocussed(x, y)) if (m_game->IsFocussed(x, y))
dc->SetBrush(*focusedBrush); dc->SetBrush(*wxMEDIUM_GREY_BRUSH);
else else
dc->SetBrush(*wxLIGHT_GREY_BRUSH); dc->SetBrush(*wxLIGHT_GREY_BRUSH);
@@ -94,7 +85,7 @@ void BombsCanvas::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2)
{ {
dc->SetPen(*wxBLACK_PEN); dc->SetPen(*wxBLACK_PEN);
if (m_game->IsFocussed(x, y)) if (m_game->IsFocussed(x, y))
dc->SetBrush(*focusedBrush); dc->SetBrush(*wxMEDIUM_GREY_BRUSH);
else else
dc->SetBrush(*wxLIGHT_GREY_BRUSH); dc->SetBrush(*wxLIGHT_GREY_BRUSH);
@@ -116,7 +107,7 @@ void BombsCanvas::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2)
y*m_cellHeight*Y_UNIT + (m_cellHeight*Y_UNIT-chh)/2); y*m_cellHeight*Y_UNIT + (m_cellHeight*Y_UNIT-chh)/2);
if (m_game->IsExploded(x,y)) if (m_game->IsExploded(x,y))
{ {
dc->SetPen(*bluePen); dc->SetPen(*wxBLUE_PEN);
dc->DrawLine(x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT, dc->DrawLine(x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
(x+1)*m_cellWidth*X_UNIT, (y+1)*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, dc->DrawLine(x*m_cellWidth*X_UNIT, (y+1)*m_cellHeight*Y_UNIT,
@@ -127,11 +118,11 @@ void BombsCanvas::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2)
{ {
dc->SetPen(*wxBLACK_PEN); dc->SetPen(*wxBLACK_PEN);
if (m_game->IsFocussed(x, y)) if (m_game->IsFocussed(x, y))
dc->SetBrush(*focusedBrush); dc->SetBrush(*wxMEDIUM_GREY_BRUSH);
else if (m_game->IsSelected(x,y)) else if (m_game->IsSelected(x,y))
dc->SetBrush(*wxWHITE_BRUSH); dc->SetBrush(*wxWHITE_BRUSH);
else else
dc->SetBrush(*yellowBrush); dc->SetBrush(*wxYELLOW_BRUSH);
dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT, dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1); m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1);

View File

@@ -42,9 +42,9 @@ FortyCanvas::FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& siz
SetScrollbars(0, 0, 0, 0); SetScrollbars(0, 0, 0, 0);
#ifdef __WXGTK__ #ifdef __WXGTK__
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL); m_font = wxTheFontList->FindOrCreateFont(wxFontInfo(12).Family(wxFONTFAMILY_ROMAN));
#else #else
m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL); m_font = wxTheFontList->FindOrCreateFont(wxFontInfo(10).Family(wxFONTFAMILY_SWISS));
#endif #endif
SetBackgroundColour(FortyApp::BackgroundColour()); SetBackgroundColour(FortyApp::BackgroundColour());

View File

@@ -127,9 +127,7 @@ void Card::SetScale(double scale)
void Card::Erase(wxDC& dc, int x, int y) void Card::Erase(wxDC& dc, int x, int y)
{ {
wxPen* pen = wxThePenList->FindOrCreatePen( wxPen* pen = wxThePenList->FindOrCreatePen(
FortyApp::BackgroundColour(), FortyApp::BackgroundColour()
1,
wxSOLID
); );
dc.SetPen(* pen); dc.SetPen(* pen);
dc.SetBrush(FortyApp::BackgroundBrush()); dc.SetBrush(FortyApp::BackgroundBrush());
@@ -169,7 +167,7 @@ void Card::Draw(wxDC& dc, int x, int y)
dc.SetBackground(* wxRED_BRUSH); dc.SetBackground(* wxRED_BRUSH);
dc.SetBackgroundMode(wxSOLID); dc.SetBackgroundMode(wxSOLID);
wxBrush* brush = wxTheBrushList->FindOrCreateBrush( wxBrush* brush = wxTheBrushList->FindOrCreateBrush(
*wxBLACK, wxCROSSDIAG_HATCH *wxBLACK, wxBRUSHSTYLE_CROSSDIAG_HATCH
); );
dc.SetBrush(* brush); dc.SetBrush(* brush);
@@ -283,6 +281,7 @@ void Card::Draw(wxDC& dc, int x, int y)
symsize * m_suit, symsize * m_suit,
sympos, sympos,
wxCOPY); wxCOPY);
wxFALLTHROUGH;
case 2: case 2:
dc.Blit((wxCoord)(x - symdist + m_width / 2), dc.Blit((wxCoord)(x - symdist + m_width / 2),
(wxCoord)(y - symdist + m_height / 4), (wxCoord)(y - symdist + m_height / 4),
@@ -311,6 +310,7 @@ void Card::Draw(wxDC& dc, int x, int y)
symsize * m_suit, symsize * m_suit,
sympos, sympos,
wxCOPY); wxCOPY);
wxFALLTHROUGH;
case 4: case 4:
dc.Blit((wxCoord)(x - symdist + m_width / 4), dc.Blit((wxCoord)(x - symdist + m_width / 4),
(wxCoord)(y - symdist + m_height / 4), (wxCoord)(y - symdist + m_height / 4),
@@ -355,6 +355,7 @@ void Card::Draw(wxDC& dc, int x, int y)
symsize * m_suit, symsize * m_suit,
sympos2, sympos2,
wxCOPY); wxCOPY);
wxFALLTHROUGH;
case 7: case 7:
dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10), dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10),
(wxCoord)(y - symdist + 3 * m_height / 8), (wxCoord)(y - symdist + 3 * m_height / 8),
@@ -364,6 +365,7 @@ void Card::Draw(wxDC& dc, int x, int y)
symsize * m_suit, symsize * m_suit,
sympos, sympos,
wxCOPY); wxCOPY);
wxFALLTHROUGH;
case 6: case 6:
dc.Blit((wxCoord)(x - symdist + m_width / 4), dc.Blit((wxCoord)(x - symdist + m_width / 4),
(wxCoord)(y - symdist + m_height / 4), (wxCoord)(y - symdist + m_height / 4),
@@ -421,6 +423,7 @@ void Card::Draw(wxDC& dc, int x, int y)
symsize * m_suit, symsize * m_suit,
sympos2, sympos2,
wxCOPY); wxCOPY);
wxFALLTHROUGH;
case 9: case 9:
dc.Blit((wxCoord)(x - symdist + m_width / 4), dc.Blit((wxCoord)(x - symdist + m_width / 4),
(wxCoord)(y - symdist2 + m_height / 4), (wxCoord)(y - symdist2 + m_height / 4),
@@ -497,7 +500,9 @@ void Card::Draw(wxDC& dc, int x, int y)
wxCOPY); wxCOPY);
break; break;
case 11: case 11:
wxFALLTHROUGH;
case 12: case 12:
wxFALLTHROUGH;
case 13: case 13:
memoryDC.SelectObject(*m_pictureBmap); memoryDC.SelectObject(*m_pictureBmap);
int picwidth = 40,picheight = 45; int picwidth = 40,picheight = 45;
@@ -544,7 +549,7 @@ void Card::Draw(wxDC& dc, int x, int y)
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
void Card::DrawNullCard(wxDC& dc, int x, int y) void Card::DrawNullCard(wxDC& dc, int x, int y)
{ {
wxPen* pen = wxThePenList->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID); wxPen* pen = wxThePenList->FindOrCreatePen(FortyApp::TextColour());
dc.SetBrush(FortyApp::BackgroundBrush()); dc.SetBrush(FortyApp::BackgroundBrush());
dc.SetPen(*pen); dc.SetPen(*pen);
dc.DrawRoundedRectangle(x, y, m_width, m_height, 4); dc.DrawRoundedRectangle(x, y, m_width, m_height, 4);

View File

@@ -112,7 +112,7 @@ const wxBrush& FortyApp::BackgroundBrush()
{ {
if (!m_backgroundBrush) if (!m_backgroundBrush)
{ {
m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID); m_backgroundBrush = new wxBrush(BackgroundColour());
} }
return *m_backgroundBrush; return *m_backgroundBrush;

View File

@@ -215,7 +215,7 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest)
void Game::DisplayScore(wxDC& dc) void Game::DisplayScore(wxDC& dc)
{ {
wxColour bgColour = FortyApp::BackgroundColour(); wxColour bgColour = FortyApp::BackgroundColour();
wxPen* pen = wxThePenList->FindOrCreatePen(bgColour, 1, wxSOLID); wxPen* pen = wxThePenList->FindOrCreatePen(bgColour);
dc.SetTextBackground(bgColour); dc.SetTextBackground(bgColour);
dc.SetTextForeground(FortyApp::TextColour()); dc.SetTextForeground(FortyApp::TextColour());
dc.SetBrush(FortyApp::BackgroundBrush()); dc.SetBrush(FortyApp::BackgroundBrush());

View File

@@ -47,9 +47,9 @@ ScoreCanvas::ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile, const wxPoint&
{ {
SetBackgroundColour(*wxWHITE); SetBackgroundColour(*wxWHITE);
#ifdef __WXGTK__ #ifdef __WXGTK__
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL); m_font = wxTheFontList->FindOrCreateFont(wxFontInfo(12).Family(wxFONTFAMILY_ROMAN));
#else #else
m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL); m_font = wxTheFontList->FindOrCreateFont(wxFontInfo(10).Family(wxFONTFAMILY_SWISS));
#endif #endif
wxArrayString players; wxArrayString players;
@@ -92,7 +92,7 @@ void ScoreCanvas::OnDraw(wxDC& dc)
// get the line spacing for the current font // get the line spacing for the current font
int lineSpacing; int lineSpacing;
{ {
long w, h; wxCoord w, h;
dc.GetTextExtent(wxT("Testing"), &w, &h); dc.GetTextExtent(wxT("Testing"), &w, &h);
lineSpacing = (int)h; lineSpacing = (int)h;
} }

View File

@@ -149,16 +149,16 @@ MyCanvas::MyCanvas(wxFrame *frame):
wxWindow(frame, wxID_ANY) wxWindow(frame, wxID_ANY)
{ {
wxColour wxCol1(255,255,255); wxColour wxCol1(255,255,255);
SnowPen = wxPen(wxCol1, 2, wxSOLID); SnowPen = wxPen(wxCol1, 2);
wxColour wxCol2(128,0,0); wxColour wxCol2(128,0,0);
MtnPen = wxPen(wxCol2, 1, wxSOLID); MtnPen = wxPen(wxCol2);
wxColour wxCol3(0,128,0); wxColour wxCol3(0,128,0);
GreenPen = wxPen(wxCol3, 1, wxSOLID); GreenPen = wxPen(wxCol3);
wxColour wxCol4(0,0,128); wxColour wxCol4(0,0,128);
WaterBrush = wxBrush(wxCol4, wxSOLID); WaterBrush = wxBrush(wxCol4);
} }
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))

View File

@@ -1,4 +1,2 @@
wxSTD_FRAME ICON "mondrian.ico"
#include "wx/msw/wx.rc" #include "wx/msw/wx.rc"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

View File

@@ -99,9 +99,9 @@ MainWindow *TheMainWindow = NULL;
// Create the fonts // Create the fonts
void MainWindow::CreateFonts() void MainWindow::CreateFonts()
{ {
m_normalFont = wxTheFontList->FindOrCreateFont(pointSize, wxSWISS, wxNORMAL, wxNORMAL); m_normalFont = wxTheFontList->FindOrCreateFont(wxFontInfo(pointSize).Family(wxFONTFAMILY_SWISS));
m_boldFont = wxTheFontList->FindOrCreateFont(pointSize, wxSWISS, wxNORMAL, wxBOLD); m_boldFont = wxTheFontList->FindOrCreateFont(wxFontInfo(pointSize).Family(wxFONTFAMILY_SWISS).Bold());
m_italicFont = wxTheFontList->FindOrCreateFont(pointSize, wxSWISS, wxITALIC, wxNORMAL); m_italicFont = wxTheFontList->FindOrCreateFont(wxFontInfo(pointSize).Family(wxFONTFAMILY_SWISS).Italic());
} }
wxBEGIN_EVENT_TABLE(MainWindow, wxFrame) wxBEGIN_EVENT_TABLE(MainWindow, wxFrame)