Skip to content

Commit 22cb269

Browse files
committed
Fix some of -Wnarrowing warnings
1 parent 472cf22 commit 22cb269

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

include/GfxPrimitives.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ bool OneSideClip(T1& c, T2& d, const T3 clip_c, const T4 clip_d) {
275275
// Create a SDL rect
276276
INLINE SDL_Rect MakeRect(int x, int y, int w, int h)
277277
{
278-
SDL_Rect r = {x, y, w, h};
278+
SDL_Rect r = {(Sint16)x, (Sint16)y, (Uint16)w, (Uint16)h};
279279
return r;
280280
}
281281

@@ -408,8 +408,8 @@ INLINE void DrawImageAdv(SDL_Surface * bmpDest, const SmartPointer<SDL_Surface>
408408
//////////////
409409
// Draw the image with a huge amount of options
410410
INLINE void DrawImageAdv(SDL_Surface * bmpDest, SDL_Surface * bmpSrc, int sx, int sy, int dx, int dy, int w, int h) {
411-
SDL_Rect r1 = { dx, dy, 0, 0 };
412-
SDL_Rect r2 = { sx, sy, w, h };
411+
SDL_Rect r1 = { (Sint16)dx, (Sint16)dy, 0, 0 };
412+
SDL_Rect r2 = { (Sint16)sx, (Sint16)sy, (Uint16)w, (Uint16)h };
413413
DrawImageAdv( bmpDest, bmpSrc, r1, r2);
414414
}
415415
INLINE void DrawImageAdv(SDL_Surface * bmpDest, const SmartPointer<SDL_Surface> & bmpSrc, int sx, int sy, int dx, int dy, int w, int h) {
@@ -433,7 +433,7 @@ INLINE void DrawImage(SDL_Surface * bmpDest, SDL_Surface * bmpSrc, SDL_Rect& rDe
433433
errors << "DrawImage: bmpSrc == NULL" << endl;
434434
return;
435435
}
436-
SDL_Rect rSource = { 0, 0, bmpSrc->w, bmpSrc->h };
436+
SDL_Rect rSource = { 0, 0, (Uint16)bmpSrc->w, (Uint16)bmpSrc->h };
437437
DrawImageAdv(bmpDest, bmpSrc, rDest, rSource);
438438
}
439439
INLINE void DrawImage(SDL_Surface * bmpDest, const SmartPointer<SDL_Surface> & bmpSrc, SDL_Rect& rDest) {
@@ -443,7 +443,7 @@ INLINE void DrawImage(SDL_Surface * bmpDest, const SmartPointer<SDL_Surface> & b
443443
///////////////
444444
// Simply draw the image
445445
INLINE void DrawImage(SDL_Surface * bmpDest, SDL_Surface * bmpSrc, int x, int y) {
446-
SDL_Rect r = { x, y, 0, 0 };
446+
SDL_Rect r = { (Sint16)x, (Sint16)y, 0, 0 };
447447
DrawImage( bmpDest, bmpSrc, r);
448448
}
449449
INLINE void DrawImage(SDL_Surface * bmpDest, const SmartPointer<SDL_Surface> & bmpSrc, int x, int y) {

include/SkinnedGUI/CGuiSkinnedLayout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class CGuiSkinnedLayout: public CContainerWidget
111111
virtual void MoveTo( int x, int y );
112112
virtual void Resize( int x, int y, int w, int h);
113113

114-
SDL_Rect getClientRect() { SDL_Rect r = { iClientX, iClientY, iClientWidth, iClientHeight }; return r; }
114+
SDL_Rect getClientRect() { SDL_Rect r = { (Sint16)iClientX, (Sint16)iClientY, (Uint16)iClientWidth, (Uint16)iClientHeight }; return r; }
115115

116116
void incModalsRunning();
117117
void decModalsRunning();

include/SkinnedGUI/CWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class CWidget {
275275

276276
WidgetType getType() { return iType; }
277277

278-
SDL_Rect getRect() { SDL_Rect r = { getX(), getY(), getWidth(), getHeight() }; return r; }
278+
SDL_Rect getRect() { SDL_Rect r = { (Sint16)getX(), (Sint16)getY(), (Uint16)getWidth(), (Uint16)getHeight() }; return r; }
279279

280280
const std::string& getName() { return sName; }
281281
void setName(const std::string& _n) { sName = _n; }

src/client/CClient_Draw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2681,7 +2681,7 @@ void CClient::DrawPlayerWaitingColumn(SDL_Surface * bmpDest, int x, int y, std::
26812681
{
26822682
const int h = getBottomBarTop() - y;
26832683

2684-
SDL_Rect newclip = {x, y, WAIT_COL_W, h};
2684+
SDL_Rect newclip = { (Sint16)x, (Sint16)y, (Uint16)WAIT_COL_W, (Uint16)h };
26852685
ScopedSurfaceClip clip(bmpDest, newclip);
26862686

26872687
DrawRectFill(bmpDest, x, y, x + WAIT_COL_W, y + h, tLX->clScoreBackground);

src/client/GfxPrimitives.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ void DrawImageAdv(SDL_Surface * bmpDest, SDL_Surface * bmpSrc, SDL_Rect& rDest,
772772
// Draw the image tiled on the dest surface
773773
void DrawImageTiled(SDL_Surface *bmpDest, SDL_Surface *bmpSrc, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
774774
{
775-
SDL_Rect newClip = {dx,dy,dw,dh};
775+
SDL_Rect newClip = { (Sint16)dx, (Sint16)dy, (Uint16)dw, (Uint16)dh };
776776
ScopedSurfaceClip clip(bmpDest,newClip);
777777
MOD(sx, (int)bmpSrc->w); MOD(sy, (int)bmpSrc->h);
778778

@@ -1256,8 +1256,8 @@ void DrawImageResampledAdv(SDL_Surface * bmpDest, SDL_Surface * bmpSrc, int sx,
12561256
{
12571257
if(!bmpSrc || !bmpDest) return;
12581258

1259-
SDL_Rect src = { sx, sy, sw, sh };
1260-
SDL_Rect dst = { dx, dy, (int)((float)sw * xratio), (int)((float)sh * yratio) };
1259+
SDL_Rect src = { (Sint16)sx, (Sint16)sy, (Uint16)sw, (Uint16)sh };
1260+
SDL_Rect dst = { (Sint16)dx, (Sint16)dy, (Uint16)((float)sw * xratio), (Uint16)((float)sh * yratio) };
12611261

12621262
// Source clipping
12631263
if (!ClipRefRectWith((SDLRect&)src, (SDLRect&)bmpSrc->clip_rect))
@@ -1277,8 +1277,8 @@ void DrawImageResampledAdv(SDL_Surface * bmpDest, SDL_Surface * bmpSrc, int sx,
12771277
{
12781278
if(!bmpSrc || !bmpDest) return;
12791279

1280-
SDL_Rect src = { sx, sy, sw, sh };
1281-
SDL_Rect dst = { dx, dy, dw, dh };
1280+
SDL_Rect src = { (Sint16)sx, (Sint16)sy, (Uint16)sw, (Uint16)sh };
1281+
SDL_Rect dst = { (Sint16)dx, (Sint16)dy, (Uint16)dw, (Uint16)dh };
12821282

12831283
// Source clipping
12841284
if (!ClipRefRectWith((SDLRect&)src, (SDLRect&)bmpSrc->clip_rect))
@@ -2348,7 +2348,7 @@ static void DrawRectFill_Overlay(SDL_Surface *bmpDest, const SDL_Rect& r, Color
23482348
// Draws a filled rectangle
23492349
void DrawRectFill(SDL_Surface *bmpDest, int x, int y, int x2, int y2, Color color)
23502350
{
2351-
SDL_Rect r = { x, y, x2 - x, y2 - y };
2351+
SDL_Rect r = { (Sint16)x, (Sint16)y, (Uint16)(x2 - x), (Uint16)(y2 - y) };
23522352

23532353
switch (color.a) {
23542354
case SDL_ALPHA_OPAQUE:

src/client/SkinnedGUI/CListview.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ CWidgetSubitem::~CWidgetSubitem()
104104
SDL_Rect CWidgetSubitem::getWidgetRect(int item_h)
105105
{
106106
CItemStyle *style = getCurrentStyle();
107-
SDL_Rect r = {style->cBorder.getLeftW(), 0, cWidget->getWidth(), cWidget->getHeight()};
107+
SDL_Rect r = { (Sint16)style->cBorder.getLeftW(), 0, (Uint16)cWidget->getWidth(), (Uint16)cWidget->getHeight()};
108108
switch (iVAlign) {
109109
case algTop:
110110
r.y = style->cBorder.getTopW();
@@ -412,10 +412,10 @@ void CListviewColumn::Draw(SDL_Surface *bmpDest, int x, int y, int w, int h)
412412
style->cBackground.Draw(bmpDest, x, y, w, h);
413413

414414
// Text
415-
SDL_Rect r = {x + style->cBorder.getLeftW(), y + style->cBorder.getTopW(),
416-
w - ((style->bmpSortArrow.get().get() && iSortDirection != sort_None) ? style->bmpSortArrow->w : 0) -
417-
style->cBorder.getLeftW() - style->cBorder.getRightW(),
418-
h - style->cBorder.getTopW() - style->cBorder.getBottomW()};
415+
SDL_Rect r = { (Sint16)(x + style->cBorder.getLeftW()), (Sint16)(y + style->cBorder.getTopW()),
416+
(Uint16)(w - ((style->bmpSortArrow.get().get() && iSortDirection != sort_None) ? style->bmpSortArrow->w : 0) -
417+
style->cBorder.getLeftW() - style->cBorder.getRightW()),
418+
(Uint16)(h - style->cBorder.getTopW() - style->cBorder.getBottomW()) };
419419

420420
style->cText.tFontRect = &r;
421421
DrawGameText(bmpDest, sText, style->cFont, style->cText);

src/gusanos/allegro.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ void rectfill(ALLEGRO_BITMAP *bmp, int x1, int y1, int x2, int y2, Uint32 color)
382382
sub_to_abs_coords(bmp, x2, y2);
383383
if(bmp->surf->format->BitsPerPixel == 8) {
384384
// currently, DrawRectFill cannot handle 8bit and/or allegcol_to_Col is wrong
385-
SDL_Rect r = { x1, y1, x2-x1, y2-y1 };
385+
SDL_Rect r = { (Sint16)x1, (Sint16)y1, (Uint16)(x2-x1), (Uint16)(y2-y1) };
386386
SDL_FillRect(bmp->surf.get(), &r, color);
387387
}
388388
else
@@ -425,8 +425,8 @@ void dumpUsedColors(SDL_Surface* surf) {
425425
void blit(ALLEGRO_BITMAP *source, ALLEGRO_BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height) {
426426
sub_to_abs_coords(source, source_x, source_y);
427427
sub_to_abs_coords(dest, dest_x, dest_y);
428-
SDL_Rect srcrect = { source_x, source_y, width, height };
429-
SDL_Rect dstrect = { dest_x, dest_y, width, height };
428+
SDL_Rect srcrect = { (Sint16)source_x, (Sint16)source_y, (Uint16)width, (Uint16)height };
429+
SDL_Rect dstrect = { (Sint16)dest_x, (Sint16)dest_y, (Uint16)width, (Uint16)height };
430430
DrawImageAdv(dest->surf.get(), source->surf.get(), dstrect, srcrect);
431431
// This doesn' work. We need colorkey handling:
432432
// CopySurface(dest->surf.get(), source->surf.get(), source_x, source_y, dest_x, dest_y, width, height);

0 commit comments

Comments
 (0)