From 8f57afcf53421b98b163a3aa2c7a2ed3d29dd44e Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Tue, 10 Apr 2012 23:01:16 +0200 Subject: [PATCH] Explicitly convert 32-bit integers to 16-bit. GCC 4.7.0 warns that C++11 considers doing this implicitly ill-formed. --- src/asfont.cpp | 5 ++++- src/asfont.h | 2 +- src/browsedialog.cpp | 14 ++++++++++++-- src/gmenu2x.cpp | 9 +++++++-- src/iconbutton.cpp | 10 +++++----- src/inputdialog.cpp | 17 +++++++++++++---- src/settingsdialog.cpp | 14 ++++++++++++-- src/surface.cpp | 7 +++++-- 8 files changed, 59 insertions(+), 19 deletions(-) diff --git a/src/asfont.cpp b/src/asfont.cpp index b13da9e..7fb2b55 100644 --- a/src/asfont.cpp +++ b/src/asfont.cpp @@ -46,7 +46,10 @@ ASFont::ASFont(const std::string &fontImagePath) // Scan height of "0" glyph. std::string::size_type pos = characters.find("0") * 2; SDL_Rect srcrect = { - charpos[pos], 1, charpos[pos + 2] - charpos[pos], surface->h - 1 + static_cast(charpos[pos]), + 1, + static_cast(charpos[pos + 2] - charpos[pos]), + static_cast(surface->h - 1) }; const unsigned alphaMask = surface->format->Amask; unsigned y = srcrect.h; diff --git a/src/asfont.h b/src/asfont.h index a205cca..80e08e7 100644 --- a/src/asfont.h +++ b/src/asfont.h @@ -41,7 +41,7 @@ private: void writeLine(Surface *surface, const std::vector &text, int x, int y, HAlign halign, VAlign valign); SDL_Surface *surface; - std::vector charpos; + std::vector charpos; std::string characters; int lineHeight; }; diff --git a/src/browsedialog.cpp b/src/browsedialog.cpp index fed2216..c8cbc60 100644 --- a/src/browsedialog.cpp +++ b/src/browsedialog.cpp @@ -61,8 +61,18 @@ bool BrowseDialog::exec() const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"]; rowHeight = gmenu2x->font->getHeight() + 1; // gp2x=15+1 / pandora=19+1 numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight; - clipRect = (SDL_Rect) { 0, topBarHeight + 1, gmenu2x->resX - 9, gmenu2x->resY - topBarHeight - 25 }; - touchRect = (SDL_Rect) { 2, topBarHeight + 4, gmenu2x->resX - 12, clipRect.h }; + clipRect = (SDL_Rect) { + 0, + static_cast(topBarHeight + 1), + static_cast(gmenu2x->resX - 9), + static_cast(gmenu2x->resY - topBarHeight - 25) + }; + touchRect = (SDL_Rect) { + 2, + static_cast(topBarHeight + 4), + static_cast(gmenu2x->resX - 12), + clipRect.h + }; selected = 0; close = false; diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 60b1bbe..625d388 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -1556,7 +1556,12 @@ void GMenu2X::contextMenu() { box.x = halfX - box.w/2; box.y = halfY - box.h/2; - SDL_Rect selbox = {box.x+4, 0, box.w-8, h+2}; + SDL_Rect selbox = { + static_cast(box.x + 4), + 0, + static_cast(box.w - 8), + static_cast(h + 2) + }; long tickNow, tickStart = SDL_GetTicks(); Surface bg(s); @@ -2146,7 +2151,7 @@ int GMenu2X::drawButton(Button *btn, int x, int y) { int GMenu2X::drawButton(Surface *s, const string &btn, const string &text, int x, int y) { if (y<0) y = resY+y; - SDL_Rect re = {x, y-7, 0, 16}; + SDL_Rect re = { static_cast(x), static_cast(y - 7), 0, 16 }; if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { sc["imgs/buttons/"+btn+".png"]->blit(s, x, y-7); re.w = sc["imgs/buttons/"+btn+".png"]->width() + 3; diff --git a/src/iconbutton.cpp b/src/iconbutton.cpp index 4a6cd72..25a2fa8 100644 --- a/src/iconbutton.cpp +++ b/src/iconbutton.cpp @@ -45,7 +45,7 @@ bool IconButton::paintHover() { } void IconButton::recalcSize() { - uint h = 0, w = 0; + Uint16 h = 0, w = 0; if (iconSurface) { w += iconSurface->width(); h += iconSurface->height(); @@ -57,10 +57,10 @@ void IconButton::recalcSize() { if (label != "") { uint margin = iconSurface ? 2 : 0; labelRect = (SDL_Rect) { - iconRect.x + iconRect.w + margin, - rect.y + h / 2, - gmenu2x->font->getTextWidth(label), - gmenu2x->font->getHeight() + static_cast(iconRect.x + iconRect.w + margin), + static_cast(rect.y + h / 2), + static_cast(gmenu2x->font->getTextWidth(label)), + static_cast(gmenu2x->font->getHeight()) }; w += margin + labelRect.w; } diff --git a/src/inputdialog.cpp b/src/inputdialog.cpp index f333952..ac2d0a9 100644 --- a/src/inputdialog.cpp +++ b/src/inputdialog.cpp @@ -138,7 +138,9 @@ void InputDialog::setKeyboard(int kb) { } bool InputDialog::exec() { - SDL_Rect box = { 0, 60, 0, gmenu2x->font->getHeight() + 4 }; + SDL_Rect box = { + 0, 60, 0, static_cast(gmenu2x->font->getHeight() + 4) + }; Uint32 caretTick = 0, curTick; bool caretOn = true; @@ -286,8 +288,10 @@ void InputDialog::drawVirtualKeyboard() { charX = line[x]; SDL_Rect re = { - kbLeft + xc * KEY_WIDTH - 1, KB_TOP + l * KEY_HEIGHT, - KEY_WIDTH - 1, KEY_HEIGHT - 2 + static_cast(kbLeft + xc * KEY_WIDTH - 1), + static_cast(KB_TOP + l * KEY_HEIGHT), + KEY_WIDTH - 1, + KEY_HEIGHT - 2 }; //if ts on rect, change selection @@ -307,7 +311,12 @@ void InputDialog::drawVirtualKeyboard() { } //Ok/Cancel - SDL_Rect re = {kbLeft-1, KB_TOP+kb->size()*KEY_HEIGHT, kbLength*KEY_WIDTH/2-1, KEY_HEIGHT-1}; + SDL_Rect re = { + static_cast(kbLeft - 1), + static_cast(KB_TOP + kb->size() * KEY_HEIGHT), + static_cast(kbLength * KEY_WIDTH / 2 - 1), + KEY_HEIGHT - 1 + }; gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); if (ts.available() && ts.pressed() && ts.inRect(re)) { selCol = 0; diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 507f325..974ac6d 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -59,8 +59,18 @@ bool SettingsDialog::exec() { voices[sel]->adjustInput(); const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"]; - SDL_Rect clipRect = { 0, topBarHeight + 1, gmenu2x->resX - 9, gmenu2x->resY - topBarHeight - 25 }; - SDL_Rect touchRect = { 2, topBarHeight + 4, gmenu2x->resX - 12, clipRect.h }; + SDL_Rect clipRect = { + 0, + static_cast(topBarHeight + 1), + static_cast(gmenu2x->resX - 9), + static_cast(gmenu2x->resY - topBarHeight - 25) + }; + SDL_Rect touchRect = { + 2, + static_cast(topBarHeight + 4), + static_cast(gmenu2x->resX - 12), + static_cast(clipRect.h) + }; uint rowHeight = gmenu2x->font->getHeight() + 1; // gp2x=15+1 / pandora=19+1 uint numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight; diff --git a/src/surface.cpp b/src/surface.cpp index 182f9f7..a4cdac8 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -115,7 +115,7 @@ void Surface::flip() { bool Surface::blit(SDL_Surface *destination, int x, int y, int w, int h, int a) { if (destination == NULL || a==0) return false; - SDL_Rect src = {0,0,w,h}; + SDL_Rect src = { 0, 0, static_cast(w), static_cast(h) }; SDL_Rect dest; dest.x = x; dest.y = y; @@ -181,7 +181,10 @@ void Surface::clearClipRect() { } void Surface::setClipRect(int x, int y, int w, int h) { - SDL_Rect rect = {x,y,w,h}; + SDL_Rect rect = { + static_cast(x), static_cast(y), + static_cast(w), static_cast(h) + }; setClipRect(rect); }