From 4d8fad3d8042acbdd4ef2b376ac5e60fde6dc6ad Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 25 Nov 2017 17:39:44 +0100 Subject: [PATCH] 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. --- demos/bombs/bombs.cpp | 3 +-- demos/bombs/bombs.h | 2 +- demos/bombs/bombs1.cpp | 21 ++++++--------------- demos/forty/canvas.cpp | 4 ++-- demos/forty/card.cpp | 15 ++++++++++----- demos/forty/forty.cpp | 2 +- demos/forty/game.cpp | 2 +- demos/forty/scoredg.cpp | 6 +++--- demos/fractal/fractal.cpp | 8 ++++---- demos/fractal/fractal.rc | 2 -- demos/fractal/mondrian.ico | Bin 766 -> 0 bytes demos/poem/wxpoem.cpp | 6 +++--- 12 files changed, 32 insertions(+), 39 deletions(-) delete mode 100644 demos/fractal/mondrian.ico diff --git a/demos/bombs/bombs.cpp b/demos/bombs/bombs.cpp index 58671c7c06..0a903d88f9 100644 --- a/demos/bombs/bombs.cpp +++ b/demos/bombs/bombs.cpp @@ -218,8 +218,7 @@ BombsCanvas::BombsCanvas(wxFrame *parent, BombsGame *game) m_game = game; int sx, sy; wxClientDC dc(this); - wxFont font= BOMBS_FONT; - dc.SetFont(font); + dc.SetFont(BOMBS_FONT); wxCoord chw, chh; wxString buf = wxT("M"); diff --git a/demos/bombs/bombs.h b/demos/bombs/bombs.h index f3d4f77c76..a5000eb984 100644 --- a/demos/bombs/bombs.h +++ b/demos/bombs/bombs.h @@ -118,7 +118,7 @@ private: * 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_ diff --git a/demos/bombs/bombs1.cpp b/demos/bombs/bombs1.cpp index 59e67c8118..2cb950c025 100644 --- a/demos/bombs/bombs1.cpp +++ b/demos/bombs/bombs1.cpp @@ -33,14 +33,6 @@ 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; @@ -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); - wxFont font= BOMBS_FONT; - dc->SetFont(font); + dc->SetFont(BOMBS_FONT); for(x=xc1; x<=xc2; x++) 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); if (m_game->IsFocussed(x, y)) - dc->SetBrush(*focusedBrush); + dc->SetBrush(*wxMEDIUM_GREY_BRUSH); else 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); if (m_game->IsFocussed(x, y)) - dc->SetBrush(*focusedBrush); + dc->SetBrush(*wxMEDIUM_GREY_BRUSH); else 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); 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, (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, @@ -127,11 +118,11 @@ void BombsCanvas::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2) { dc->SetPen(*wxBLACK_PEN); if (m_game->IsFocussed(x, y)) - dc->SetBrush(*focusedBrush); + dc->SetBrush(*wxMEDIUM_GREY_BRUSH); else if (m_game->IsSelected(x,y)) dc->SetBrush(*wxWHITE_BRUSH); else - dc->SetBrush(*yellowBrush); + dc->SetBrush(*wxYELLOW_BRUSH); dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT, m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1); diff --git a/demos/forty/canvas.cpp b/demos/forty/canvas.cpp index 066e94c529..5698cc1a5e 100644 --- a/demos/forty/canvas.cpp +++ b/demos/forty/canvas.cpp @@ -42,9 +42,9 @@ FortyCanvas::FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& siz SetScrollbars(0, 0, 0, 0); #ifdef __WXGTK__ - m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL); + m_font = wxTheFontList->FindOrCreateFont(wxFontInfo(12).Family(wxFONTFAMILY_ROMAN)); #else - m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL); + m_font = wxTheFontList->FindOrCreateFont(wxFontInfo(10).Family(wxFONTFAMILY_SWISS)); #endif SetBackgroundColour(FortyApp::BackgroundColour()); diff --git a/demos/forty/card.cpp b/demos/forty/card.cpp index c82ef33388..316c49361b 100644 --- a/demos/forty/card.cpp +++ b/demos/forty/card.cpp @@ -127,9 +127,7 @@ void Card::SetScale(double scale) void Card::Erase(wxDC& dc, int x, int y) { wxPen* pen = wxThePenList->FindOrCreatePen( - FortyApp::BackgroundColour(), - 1, - wxSOLID + FortyApp::BackgroundColour() ); dc.SetPen(* pen); dc.SetBrush(FortyApp::BackgroundBrush()); @@ -169,7 +167,7 @@ void Card::Draw(wxDC& dc, int x, int y) dc.SetBackground(* wxRED_BRUSH); dc.SetBackgroundMode(wxSOLID); wxBrush* brush = wxTheBrushList->FindOrCreateBrush( - *wxBLACK, wxCROSSDIAG_HATCH + *wxBLACK, wxBRUSHSTYLE_CROSSDIAG_HATCH ); dc.SetBrush(* brush); @@ -283,6 +281,7 @@ void Card::Draw(wxDC& dc, int x, int y) symsize * m_suit, sympos, wxCOPY); + wxFALLTHROUGH; case 2: dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + m_height / 4), @@ -311,6 +310,7 @@ void Card::Draw(wxDC& dc, int x, int y) symsize * m_suit, sympos, wxCOPY); + wxFALLTHROUGH; case 4: dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist + m_height / 4), @@ -355,6 +355,7 @@ void Card::Draw(wxDC& dc, int x, int y) symsize * m_suit, sympos2, wxCOPY); + wxFALLTHROUGH; case 7: dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10), (wxCoord)(y - symdist + 3 * m_height / 8), @@ -364,6 +365,7 @@ void Card::Draw(wxDC& dc, int x, int y) symsize * m_suit, sympos, wxCOPY); + wxFALLTHROUGH; case 6: dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist + m_height / 4), @@ -421,6 +423,7 @@ void Card::Draw(wxDC& dc, int x, int y) symsize * m_suit, sympos2, wxCOPY); + wxFALLTHROUGH; case 9: dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist2 + m_height / 4), @@ -497,7 +500,9 @@ void Card::Draw(wxDC& dc, int x, int y) wxCOPY); break; case 11: + wxFALLTHROUGH; case 12: + wxFALLTHROUGH; case 13: memoryDC.SelectObject(*m_pictureBmap); 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) { - wxPen* pen = wxThePenList->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID); + wxPen* pen = wxThePenList->FindOrCreatePen(FortyApp::TextColour()); dc.SetBrush(FortyApp::BackgroundBrush()); dc.SetPen(*pen); dc.DrawRoundedRectangle(x, y, m_width, m_height, 4); diff --git a/demos/forty/forty.cpp b/demos/forty/forty.cpp index 4960a34652..7a2d35ab2b 100644 --- a/demos/forty/forty.cpp +++ b/demos/forty/forty.cpp @@ -112,7 +112,7 @@ const wxBrush& FortyApp::BackgroundBrush() { if (!m_backgroundBrush) { - m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID); + m_backgroundBrush = new wxBrush(BackgroundColour()); } return *m_backgroundBrush; diff --git a/demos/forty/game.cpp b/demos/forty/game.cpp index 4b137d8316..894077e8b7 100644 --- a/demos/forty/game.cpp +++ b/demos/forty/game.cpp @@ -215,7 +215,7 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest) void Game::DisplayScore(wxDC& dc) { wxColour bgColour = FortyApp::BackgroundColour(); - wxPen* pen = wxThePenList->FindOrCreatePen(bgColour, 1, wxSOLID); + wxPen* pen = wxThePenList->FindOrCreatePen(bgColour); dc.SetTextBackground(bgColour); dc.SetTextForeground(FortyApp::TextColour()); dc.SetBrush(FortyApp::BackgroundBrush()); diff --git a/demos/forty/scoredg.cpp b/demos/forty/scoredg.cpp index 32ed7a766d..60533afbe8 100644 --- a/demos/forty/scoredg.cpp +++ b/demos/forty/scoredg.cpp @@ -47,9 +47,9 @@ ScoreCanvas::ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile, const wxPoint& { SetBackgroundColour(*wxWHITE); #ifdef __WXGTK__ - m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL); + m_font = wxTheFontList->FindOrCreateFont(wxFontInfo(12).Family(wxFONTFAMILY_ROMAN)); #else - m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL); + m_font = wxTheFontList->FindOrCreateFont(wxFontInfo(10).Family(wxFONTFAMILY_SWISS)); #endif wxArrayString players; @@ -92,7 +92,7 @@ void ScoreCanvas::OnDraw(wxDC& dc) // get the line spacing for the current font int lineSpacing; { - long w, h; + wxCoord w, h; dc.GetTextExtent(wxT("Testing"), &w, &h); lineSpacing = (int)h; } diff --git a/demos/fractal/fractal.cpp b/demos/fractal/fractal.cpp index 28c232c93b..23e2a6f7d6 100644 --- a/demos/fractal/fractal.cpp +++ b/demos/fractal/fractal.cpp @@ -149,16 +149,16 @@ MyCanvas::MyCanvas(wxFrame *frame): wxWindow(frame, wxID_ANY) { wxColour wxCol1(255,255,255); - SnowPen = wxPen(wxCol1, 2, wxSOLID); + SnowPen = wxPen(wxCol1, 2); wxColour wxCol2(128,0,0); - MtnPen = wxPen(wxCol2, 1, wxSOLID); + MtnPen = wxPen(wxCol2); wxColour wxCol3(0,128,0); - GreenPen = wxPen(wxCol3, 1, wxSOLID); + GreenPen = wxPen(wxCol3); wxColour wxCol4(0,0,128); - WaterBrush = wxBrush(wxCol4, wxSOLID); + WaterBrush = wxBrush(wxCol4); } void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) diff --git a/demos/fractal/fractal.rc b/demos/fractal/fractal.rc index e3b11b0116..82bdf07561 100644 --- a/demos/fractal/fractal.rc +++ b/demos/fractal/fractal.rc @@ -1,4 +1,2 @@ -wxSTD_FRAME ICON "mondrian.ico" - #include "wx/msw/wx.rc" diff --git a/demos/fractal/mondrian.ico b/demos/fractal/mondrian.ico deleted file mode 100644 index 2310c5d275a87af295d5ea8dc79ea417a5e74c53..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 766 zcmZQzU<5)11px*Sc)`TLAO@s0fLH;D9e|jTfdxnc0ZFindOrCreateFont(pointSize, wxSWISS, wxNORMAL, wxNORMAL); - m_boldFont = wxTheFontList->FindOrCreateFont(pointSize, wxSWISS, wxNORMAL, wxBOLD); - m_italicFont = wxTheFontList->FindOrCreateFont(pointSize, wxSWISS, wxITALIC, wxNORMAL); + m_normalFont = wxTheFontList->FindOrCreateFont(wxFontInfo(pointSize).Family(wxFONTFAMILY_SWISS)); + m_boldFont = wxTheFontList->FindOrCreateFont(wxFontInfo(pointSize).Family(wxFONTFAMILY_SWISS).Bold()); + m_italicFont = wxTheFontList->FindOrCreateFont(wxFontInfo(pointSize).Family(wxFONTFAMILY_SWISS).Italic()); } wxBEGIN_EVENT_TABLE(MainWindow, wxFrame)