From 27b59f601ed9636382037916773120d5b90a0776 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 10 Mar 2017 19:39:55 +0000 Subject: [PATCH] Fix type conversion warnings. --- extlib/libdxfrw | 2 +- src/importdxf.cpp | 6 +++--- src/platform/headless.cpp | 5 +++-- src/platform/w32main.cpp | 2 +- src/platform/w32util.cpp | 14 ++++++++------ src/render/render.cpp | 2 +- src/render/render2d.cpp | 4 ++-- src/render/rendercairo.cpp | 4 ++-- src/resource.cpp | 14 +++++++------- src/toolbar.cpp | 6 +++--- src/ttf.cpp | 2 +- 11 files changed, 32 insertions(+), 29 deletions(-) diff --git a/extlib/libdxfrw b/extlib/libdxfrw index 3475a9bf..6f362317 160000 --- a/extlib/libdxfrw +++ b/extlib/libdxfrw @@ -1 +1 @@ -Subproject commit 3475a9bf811afddde7d0638fbcc2b0200d542b07 +Subproject commit 6f362317bf3f176b613be48512a88b78125c79f4 diff --git a/src/importdxf.cpp b/src/importdxf.cpp index b41107d6..38b0aab0 100644 --- a/src/importdxf.cpp +++ b/src/importdxf.cpp @@ -633,16 +633,16 @@ public: if(data.space != DRW::ModelSpace) return; if(addPendingBlockEntity(data)) return; - int vNum = data.vertlist.size(); + size_t vNum = data.vertlist.size(); // Check for closed polyline. if((data.flags & 1) != 1) vNum--; // Correct coordinate system for the case where z=-1, as described in // http://paulbourke.net/dataformats/dxf/dxf10.html. - bool needSwapX = data.extPoint.z == -1.0; + bool needSwapX = (data.extPoint.z == -1.0); - for(int i = 0; i < vNum; i++) { + for(size_t i = 0; i < vNum; i++) { DRW_Coord c0 = data.vertlist[i]->basePoint; DRW_Coord c1 = data.vertlist[(i + 1) % data.vertlist.size()]->basePoint; diff --git a/src/platform/headless.cpp b/src/platform/headless.cpp index 4bd3d861..efb12363 100644 --- a/src/platform/headless.cpp +++ b/src/platform/headless.cpp @@ -120,11 +120,12 @@ void PaintGraphics() { pixmap->format = Pixmap::Format::BGRA; pixmap->width = camera.width; pixmap->height = camera.height; - pixmap->stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, camera.width); + pixmap->stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, (int)camera.width); pixmap->data = std::vector(pixmap->stride * pixmap->height); cairo_surface_t *surface = cairo_image_surface_create_for_data(&pixmap->data[0], CAIRO_FORMAT_RGB24, - pixmap->width, pixmap->height, pixmap->stride); + (int)pixmap->width, (int)pixmap->height, + (int)pixmap->stride); cairo_t *context = cairo_create(surface); CairoRenderer canvas; diff --git a/src/platform/w32main.cpp b/src/platform/w32main.cpp index 8142e742..9067a34f 100644 --- a/src/platform/w32main.cpp +++ b/src/platform/w32main.cpp @@ -867,7 +867,7 @@ void SolveSpace::ToggleFullScreen() } bool SolveSpace::FullScreenIsActive() { - return GetWindowLong(GraphicsWnd, GWL_STYLE) & WS_OVERLAPPEDWINDOW; + return (GetWindowLong(GraphicsWnd, GWL_STYLE) & WS_OVERLAPPEDWINDOW) != 0; } void SolveSpace::InvalidateText() diff --git a/src/platform/w32util.cpp b/src/platform/w32util.cpp index ef6936ab..26fef6e9 100644 --- a/src/platform/w32util.cpp +++ b/src/platform/w32util.cpp @@ -61,9 +61,10 @@ std::string Narrow(const std::wstring &in) if(in == L"") return ""; std::string out; - out.resize(WideCharToMultiByte(CP_UTF8, 0, &in[0], in.length(), NULL, 0, NULL, NULL)); - ssassert(WideCharToMultiByte(CP_UTF8, 0, &in[0], in.length(), - &out[0], out.length(), NULL, NULL), + out.resize(WideCharToMultiByte(CP_UTF8, 0, &in[0], (int)in.length(), + NULL, 0, NULL, NULL)); + ssassert(WideCharToMultiByte(CP_UTF8, 0, &in[0], (int)in.length(), + &out[0], (int)out.length(), NULL, NULL), "Invalid UTF-16"); return out; } @@ -83,8 +84,9 @@ std::wstring Widen(const std::string &in) if(in == "") return L""; std::wstring out; - out.resize(MultiByteToWideChar(CP_UTF8, 0, &in[0], in.length(), NULL, 0)); - ssassert(MultiByteToWideChar(CP_UTF8, 0, &in[0], in.length(), &out[0], out.length()), + out.resize(MultiByteToWideChar(CP_UTF8, 0, &in[0], (int)in.length(), NULL, 0)); + ssassert(MultiByteToWideChar(CP_UTF8, 0, &in[0], (int)in.length(), + &out[0], (int)out.length()), "Invalid UTF-8"); return out; } @@ -125,7 +127,7 @@ std::string PathFromCurrentDirectory(const std::string &relFilename) std::wstring relFilenameW = Widen(relFilename); std::wstring absFilenameW; absFilenameW.resize(GetFullPathNameW(relFilenameW.c_str(), 0, NULL, NULL)); - DWORD length = GetFullPathNameW(relFilenameW.c_str(), absFilenameW.length(), + DWORD length = GetFullPathNameW(relFilenameW.c_str(), (int)absFilenameW.length(), &absFilenameW[0], NULL); ssassert(length != 0, "Expected GetFullPathName to succeed"); absFilenameW.resize(length); diff --git a/src/render/render.cpp b/src/render/render.cpp index b6ca6c7c..a9e5e27a 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -335,7 +335,7 @@ void UiCanvas::DrawBitmapText(const std::string &str, int x, int y, RgbaColor co for(char32_t codepoint : ReadUTF8(str)) { DrawBitmapChar(codepoint, x, y, color, zIndex); - x += font->GetWidth(codepoint) * 8; + x += (int)font->GetWidth(codepoint) * 8; } } diff --git a/src/render/render2d.cpp b/src/render/render2d.cpp index efee571a..9a8995cd 100644 --- a/src/render/render2d.cpp +++ b/src/render/render2d.cpp @@ -318,9 +318,9 @@ void SurfaceRenderer::OutputInPaintOrder() { int aZIndex = a.second, bZIndex = b.second; - int aLayerIndex = + size_t aLayerIndex = std::find(std::begin(stackup), std::end(stackup), aLayer) - std::begin(stackup); - int bLayerIndex = + size_t bLayerIndex = std::find(std::begin(stackup), std::end(stackup), bLayer) - std::begin(stackup); if(aLayerIndex == bLayerIndex) { return aZIndex < bZIndex; diff --git a/src/render/rendercairo.cpp b/src/render/rendercairo.cpp index 82704884..0aeb946b 100644 --- a/src/render/rendercairo.cpp +++ b/src/render/rendercairo.cpp @@ -12,7 +12,7 @@ void CairoRenderer::OutputStart() { cairo_save(context); RgbaColor bgColor = lighting.backgroundColor; - cairo_rectangle(context, 0.0, 0.0, camera.width, camera.height); + cairo_rectangle(context, 0.0, 0.0, (double)camera.width, (double)camera.height); cairo_set_source_rgba(context, bgColor.redF(), bgColor.greenF(), bgColor.blueF(), bgColor.alphaF()); cairo_fill(context); @@ -47,7 +47,7 @@ void CairoRenderer::SelectStroke(hStroke hcs) { dash *= stroke->StippleScalePx(camera); } cairo_set_line_width(context, stroke->WidthPx(camera)); - cairo_set_dash(context, dashes.data(), dashes.size(), 0); + cairo_set_dash(context, dashes.data(), (int)dashes.size(), 0); cairo_set_source_rgba(context, color.redF(), color.greenF(), color.blueF(), color.alphaF()); if(antialias) { diff --git a/src/resource.cpp b/src/resource.cpp index 0b0319e8..1362db3e 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -49,9 +49,9 @@ std::string LoadStringFromGzip(const std::string &name) { result.resize(inflatedSize); stream.next_in = (Bytef *)data; - stream.avail_in = deflatedSize; + stream.avail_in = (uInt)deflatedSize; stream.next_out = (Bytef *)&result[0]; - stream.avail_out = result.length(); + stream.avail_out = (uInt)result.length(); ssassert(inflate(&stream, Z_NO_FLUSH) == Z_STREAM_END, "Cannot inflate resource"); ssassert(stream.avail_out == 0, "Inflated resource larger than what trailer indicates"); @@ -302,9 +302,9 @@ bool Pixmap::WritePng(FILE *f, bool flip) { if(setjmp(png_jmpbuf(png_ptr))) goto exit; png_init_io(png_ptr, f); - png_set_IHDR(png_ptr, info_ptr, width, height, 8, - colorType, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + png_set_IHDR(png_ptr, info_ptr, + (png_uint_32)width, (png_uint_32)height, 8, colorType, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); if(bgr) png_set_bgr(png_ptr); png_write_info(png_ptr, info_ptr); png_write_image(png_ptr, &rows[0]); @@ -528,7 +528,7 @@ void BitmapFont::AddGlyph(char32_t codepoint, std::shared_ptr pixm "Too many glyphs for current texture size"); BitmapFont::Glyph glyph = {}; - glyph.advanceCells = pixmap->width / 8; + glyph.advanceCells = (uint8_t)(pixmap->width / 8); glyph.position = nextPosition++; glyphs.emplace(codepoint, std::move(glyph)); @@ -590,7 +590,7 @@ const BitmapFont::Glyph &BitmapFont::GetGlyph(char32_t codepoint) { // Read glyph bits. unsigned short glyphBits[16]; - int glyphLength = reader.CountUntilEol(); + size_t glyphLength = reader.CountUntilEol(); if(glyphLength == 4 * 16) { glyph.advanceCells = 2; for(size_t i = 0; i < 16; i++) { diff --git a/src/toolbar.cpp b/src/toolbar.cpp index 6fadfab2..6000be74 100644 --- a/src/toolbar.cpp +++ b/src/toolbar.cpp @@ -187,8 +187,8 @@ bool GraphicsWindow::ToolbarDrawOrHitTest(int mx, int my, if(canvas) { canvas->DrawPixmap(icon.pixmap, - x - icon.pixmap->width / 2, - y - icon.pixmap->height / 2); + x - (int)icon.pixmap->width / 2, + y - (int)icon.pixmap->height / 2); if(toolbarHovered == icon.command || (pending.operation == Pending::COMMAND && @@ -239,7 +239,7 @@ bool GraphicsWindow::ToolbarDrawOrHitTest(int mx, int my, } } - int tw = canvas->canvas->GetBitmapFont()->GetWidth(tooltip) * 8 + 10, + int tw = (int)canvas->canvas->GetBitmapFont()->GetWidth(tooltip) * 8 + 10, th = SS.TW.LINE_HEIGHT + 2; int ox = toolbarMouseX + 3, oy = toolbarMouseY + 3; diff --git a/src/ttf.cpp b/src/ttf.cpp index e32dc5ea..5d644675 100644 --- a/src/ttf.cpp +++ b/src/ttf.cpp @@ -332,7 +332,7 @@ void TtfFont::PlotString(const std::string &str, data.u = u; data.v = v; data.beziers = sbl; - data.factor = 1.0 / capHeight; + data.factor = (float)(1.0 / capHeight); data.bx = bx; if(int fterr = FT_Outline_Decompose(&fontFace->glyph->outline, &outlineFuncs, &data)) { dbp("freetype: bezier decomposition failed (gid %d): %s",