diff --git a/Makefile.base.mk b/Makefile.base.mk index 83d64e65..59433f83 100644 --- a/Makefile.base.mk +++ b/Makefile.base.mk @@ -197,7 +197,7 @@ endif ifeq ($(TESTBUILD),true) BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings -BASE_FLAGS += -Wpointer-arith -Wabi -Winit-self -Wuninitialized -Wstrict-overflow=5 +BASE_FLAGS += -Wpointer-arith -Wabi=98 -Winit-self -Wuninitialized -Wstrict-overflow=5 # BASE_FLAGS += -Wfloat-equal ifeq ($(CC),clang) BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command diff --git a/dgl/Cairo.hpp b/dgl/Cairo.hpp index 8857e126..567aa63f 100644 --- a/dgl/Cairo.hpp +++ b/dgl/Cairo.hpp @@ -106,8 +106,8 @@ public: CairoImage& operator=(const CairoImage& image) noexcept; // FIXME this should not be needed - inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format = kImageFormatBGRA) - { loadFromMemory(rawData, Size(w, h), format); }; + inline void loadFromMemory(const char* rdata, uint w, uint h, ImageFormat fmt = kImageFormatBGRA) + { loadFromMemory(rdata, Size(w, h), fmt); }; inline void draw(const GraphicsContext& context) { drawAt(context, Point(0, 0)); }; inline void drawAt(const GraphicsContext& context, int x, int y) diff --git a/dgl/OpenGL.hpp b/dgl/OpenGL.hpp index f28f2277..deb677fc 100644 --- a/dgl/OpenGL.hpp +++ b/dgl/OpenGL.hpp @@ -222,8 +222,8 @@ public: OpenGLImage& operator=(const OpenGLImage& image) noexcept; // FIXME this should not be needed - inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format = kImageFormatBGRA) - { loadFromMemory(rawData, Size(w, h), format); }; + inline void loadFromMemory(const char* rdata, uint w, uint h, ImageFormat fmt = kImageFormatBGRA) + { loadFromMemory(rdata, Size(w, h), fmt); }; inline void draw(const GraphicsContext& context) { drawAt(context, Point(0, 0)); }; inline void drawAt(const GraphicsContext& context, int x, int y) diff --git a/dgl/Vulkan.hpp b/dgl/Vulkan.hpp index d7b73056..4fd7c45a 100644 --- a/dgl/Vulkan.hpp +++ b/dgl/Vulkan.hpp @@ -88,8 +88,8 @@ public: VulkanImage& operator=(const VulkanImage& image) noexcept; // FIXME this should not be needed - inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format = kImageFormatBGRA) - { loadFromMemory(rawData, Size(w, h), format); }; + inline void loadFromMemory(const char* rdata, uint w, uint h, ImageFormat fmt = kImageFormatBGRA) + { loadFromMemory(rdata, Size(w, h), fmt); }; inline void draw(const GraphicsContext& context) { drawAt(context, Point(0, 0)); }; inline void drawAt(const GraphicsContext& context, int x, int y) diff --git a/dgl/src/Cairo.cpp b/dgl/src/Cairo.cpp index f92e3bd2..c505099f 100644 --- a/dgl/src/Cairo.cpp +++ b/dgl/src/Cairo.cpp @@ -326,22 +326,22 @@ CairoImage::CairoImage() surfacedata(nullptr), datarefcount(nullptr) {} -CairoImage::CairoImage(const char* const rawData, const uint width, const uint height, const ImageFormat format) - : ImageBase(rawData, width, height, format), +CairoImage::CairoImage(const char* const rdata, const uint w, const uint h, const ImageFormat fmt) + : ImageBase(rdata, w, h, fmt), surface(nullptr), surfacedata(nullptr), datarefcount(nullptr) { - loadFromMemory(rawData, width, height, format); + loadFromMemory(rdata, w, h, fmt); } -CairoImage::CairoImage(const char* const rawData, const Size& size, const ImageFormat format) - : ImageBase(rawData, size, format), +CairoImage::CairoImage(const char* const rdata, const Size& s, const ImageFormat fmt) + : ImageBase(rdata, s, fmt), surface(nullptr), surfacedata(nullptr), datarefcount(nullptr) { - loadFromMemory(rawData, size, format); + loadFromMemory(rdata, s, fmt); } CairoImage::CairoImage(const CairoImage& image) @@ -368,11 +368,11 @@ CairoImage::~CairoImage() void CairoImage::loadFromMemory(const char* const rdata, const Size& s, const ImageFormat fmt) noexcept { const cairo_format_t cairoformat = asCairoImageFormat(fmt); - const uint width = s.getWidth(); - const uint height = s.getHeight(); - const int stride = cairo_format_stride_for_width(cairoformat, width); + const int width = static_cast(s.getWidth()); + const int height = static_cast(s.getHeight()); + const int stride = cairo_format_stride_for_width(cairoformat, width); - uchar* const newdata = (uchar*)std::malloc(width * height * stride * 4); + uchar* const newdata = (uchar*)std::malloc(static_cast(width * height * stride * 4)); DISTRHO_SAFE_ASSERT_RETURN(newdata != nullptr,); cairo_surface_t* const newsurface = cairo_image_surface_create_for_data(newdata, cairoformat, width, height, stride); @@ -401,13 +401,13 @@ void CairoImage::loadFromMemory(const char* const rdata, const Size& s, co break; case kImageFormatBGR: // BGR8 to CAIRO_FORMAT_RGB24 - for (uint h = 0; h < height; ++h) + for (int h = 0; h < height; ++h) { - for (uint w = 0; w < width; ++w) + for (int w = 0; w < width; ++w) { - newdata[h*width*4+w*4+0] = rdata[h*width*3+w*3+0]; - newdata[h*width*4+w*4+1] = rdata[h*width*3+w*3+1]; - newdata[h*width*4+w*4+2] = rdata[h*width*3+w*3+2]; + newdata[h*width*4+w*4+0] = static_cast(rdata[h*width*3+w*3+0]); + newdata[h*width*4+w*4+1] = static_cast(rdata[h*width*3+w*3+1]); + newdata[h*width*4+w*4+2] = static_cast(rdata[h*width*3+w*3+2]); newdata[h*width*4+w*4+3] = 0; } } @@ -415,16 +415,16 @@ void CairoImage::loadFromMemory(const char* const rdata, const Size& s, co case kImageFormatBGRA: // BGRA8 to CAIRO_FORMAT_ARGB32 // FIXME something is wrong here... - for (uint h = 0, t; h < height; ++h) + for (int h = 0, t; h < height; ++h) { - for (uint w = 0; w < width; ++w) + for (int w = 0; w < width; ++w) { if ((t = rdata[h*width*4+w*4+3]) != 0) { - newdata[h*width*4+w*4+0] = rdata[h*width*4+w*4+0]; - newdata[h*width*4+w*4+1] = rdata[h*width*4+w*4+1]; - newdata[h*width*4+w*4+2] = rdata[h*width*4+w*4+2]; - newdata[h*width*4+w*4+3] = t; + newdata[h*width*4+w*4+0] = static_cast(rdata[h*width*4+w*4+0]); + newdata[h*width*4+w*4+1] = static_cast(rdata[h*width*4+w*4+1]); + newdata[h*width*4+w*4+2] = static_cast(rdata[h*width*4+w*4+2]); + newdata[h*width*4+w*4+3] = static_cast(t); } else { @@ -476,6 +476,11 @@ void CairoImage::loadFromPNG(const char* const pngData, const uint pngSize) noex cairo_surface_t* const newsurface = cairo_image_surface_create_from_png_stream(PngReaderData::read, &readerData); DISTRHO_SAFE_ASSERT_RETURN(newsurface != nullptr,); + const int newwidth = cairo_image_surface_get_width(newsurface); + const int newheight = cairo_image_surface_get_height(newsurface); + DISTRHO_SAFE_ASSERT_INT_RETURN(newwidth > 0, newwidth,); + DISTRHO_SAFE_ASSERT_INT_RETURN(newheight > 0, newheight,); + cairo_surface_destroy(surface); if (datarefcount != nullptr && --(*datarefcount) == 0) @@ -489,7 +494,7 @@ void CairoImage::loadFromPNG(const char* const pngData, const uint pngSize) noex rawData = nullptr; format = kImageFormatNull; // asCairoImageFormat(cairo_image_surface_get_format(newsurface)); - size = Size(cairo_image_surface_get_width(newsurface), cairo_image_surface_get_height(newsurface)); + size = Size(static_cast(newwidth), static_cast(newheight)); } void CairoImage::drawAt(const GraphicsContext& context, const Point& pos) @@ -597,7 +602,7 @@ void ImageBaseKnob::PrivateData::cleanup() Get the pixel size in bytes. @return pixel size, or 0 if the format is unknown, or pixels are not aligned to bytes. */ -static uint getBytesPerPixel(cairo_format_t format) noexcept +static int getBytesPerPixel(const cairo_format_t format) noexcept { switch (format) { @@ -617,17 +622,17 @@ static uint getBytesPerPixel(cairo_format_t format) noexcept } } -static cairo_surface_t* getRegion(cairo_surface_t* origsurface, uint x, uint y, uint width, uint height) noexcept +static cairo_surface_t* getRegion(cairo_surface_t* origsurface, int x, int y, int width, int height) noexcept { const cairo_format_t format = cairo_image_surface_get_format(origsurface); - const uint bpp = getBytesPerPixel(format); + const int bpp = getBytesPerPixel(format); if (bpp == 0) return nullptr; - const uint fullWidth = cairo_image_surface_get_width(origsurface); - const uint fullHeight = cairo_image_surface_get_height(origsurface); - const uint stride = cairo_image_surface_get_stride(origsurface); + const int fullWidth = cairo_image_surface_get_width(origsurface); + const int fullHeight = cairo_image_surface_get_height(origsurface); + const int stride = cairo_image_surface_get_stride(origsurface); uchar* const fullData = cairo_image_surface_get_data(origsurface); x = (x < fullWidth) ? x : fullWidth; @@ -635,7 +640,7 @@ static cairo_surface_t* getRegion(cairo_surface_t* origsurface, uint x, uint y, width = (x + width < fullWidth) ? width : (fullWidth - x); height = (x + height < fullHeight) ? height : (fullHeight - x); - uchar* const data = fullData + x * bpp + y * stride; + uchar* const data = fullData + (x * bpp + y * stride); return cairo_image_surface_create_for_data(data, format, width, height, stride); } @@ -644,22 +649,22 @@ void ImageBaseKnob::onDisplay() { const GraphicsContext& context(getGraphicsContext()); cairo_t* const handle = ((const CairoGraphicsContext&)context).handle; - const float normValue = ((pData->usingLog ? pData->invlogscale(pData->value) : pData->value) - pData->minimum) + const double normValue = ((pData->usingLog ? pData->invlogscale(pData->value) : pData->value) - pData->minimum) / (pData->maximum - pData->minimum); cairo_surface_t* surface = (cairo_surface_t*)pData->cairoSurface; if (! pData->isReady) { - const uint layerW = pData->imgLayerWidth; - const uint layerH = pData->imgLayerHeight; - uint layerNum = 0; + const int layerW = static_cast(pData->imgLayerWidth); + const int layerH = static_cast(pData->imgLayerHeight); + int layerNum = 0; if (pData->rotationAngle == 0) - layerNum = uint(normValue * float(pData->imgLayerCount-1)); + layerNum = static_cast(normValue * static_cast(pData->imgLayerCount - 1) + 0.5); - const uint layerX = pData->isImgVertical ? 0 : layerNum * layerW; - const uint layerY = !pData->isImgVertical ? 0 : layerNum * layerH; + const int layerX = pData->isImgVertical ? 0 : layerNum * layerW; + const int layerY = !pData->isImgVertical ? 0 : layerNum * layerH; cairo_surface_t* newsurface; @@ -672,8 +677,8 @@ void ImageBaseKnob::onDisplay() newsurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, layerW, layerH); cairo_t* const cr = cairo_create(newsurface); cairo_translate(cr, 0.5 * layerW, 0.5 * layerH); - cairo_rotate(cr, normValue * pData->rotationAngle * (float)(M_PI / 180)); - cairo_set_source_surface(cr, pData->image.getSurface(), -0.5f * layerW, -0.5f * layerH); + cairo_rotate(cr, normValue * pData->rotationAngle * (M_PI / 180)); + cairo_set_source_surface(cr, pData->image.getSurface(), -0.5 * layerW, -0.5 * layerH); cairo_paint(cr); cairo_destroy(cr); } diff --git a/dgl/src/Common.hpp b/dgl/src/Common.hpp index b55a62ac..b0f86629 100644 --- a/dgl/src/Common.hpp +++ b/dgl/src/Common.hpp @@ -75,7 +75,7 @@ struct ButtonImpl { // button was pressed, wait for release if (ev.press && self->contains(ev.pos)) { - button = ev.button; + button = static_cast(ev.button); state = kStateDown; self->repaint(); return true; @@ -135,8 +135,8 @@ struct ImageBaseKnob::PrivateData { int rotationAngle; bool dragging; - int lastX; - int lastY; + double lastX; + double lastY; Callback* callback; @@ -164,18 +164,18 @@ struct ImageBaseKnob::PrivateData { void init(); void cleanup(); - inline float logscale(float value) const + inline float logscale(const float v) const { const float b = std::log(maximum/minimum)/(maximum-minimum); const float a = maximum/std::exp(maximum*b); - return a * std::exp(b*value); + return a * std::exp(b*v); } - inline float invlogscale(float value) const + inline float invlogscale(const float v) const { const float b = std::log(maximum/minimum)/(maximum-minimum); const float a = maximum/std::exp(maximum*b); - return std::log(value/a)/b; + return std::log(v/a)/b; } DISTRHO_DECLARE_NON_COPYABLE(PrivateData) diff --git a/dgl/src/Geometry.cpp b/dgl/src/Geometry.cpp index 4ad25db4..f2c44c44 100644 --- a/dgl/src/Geometry.cpp +++ b/dgl/src/Geometry.cpp @@ -249,7 +249,22 @@ bool Size::isInvalid() const noexcept template Size Size::toInt() const noexcept { - return Size(fWidth, fHeight); + return Size(static_cast(fWidth), + static_cast(fHeight)); +} + +template<> +Size Size::toInt() const noexcept +{ + return Size(static_cast(fWidth + 0.5), + static_cast(fHeight + 0.5)); +} + +template<> +Size Size::toInt() const noexcept +{ + return Size(static_cast(fWidth + 0.5f), + static_cast(fHeight + 0.5f)); } template @@ -645,10 +660,10 @@ Triangle::Triangle(const T& x1, const T& y1, const T& x2, const T& y2, const pos3(x3, y3) {} template -Triangle::Triangle(const Point& pos1, const Point& pos2, const Point& pos3) noexcept - : pos1(pos1), - pos2(pos2), - pos3(pos3) {} +Triangle::Triangle(const Point& p1, const Point& p2, const Point& p3) noexcept + : pos1(p1), + pos2(p2), + pos3(p3) {} template Triangle::Triangle(const Triangle& tri) noexcept @@ -710,24 +725,24 @@ Rectangle::Rectangle() noexcept size(0, 0) {} template -Rectangle::Rectangle(const T& x, const T& y, const T& width, const T& height) noexcept +Rectangle::Rectangle(const T& x, const T& y, const T& w, const T& h) noexcept : pos(x, y), - size(width, height) {} + size(w, h) {} template -Rectangle::Rectangle(const T& x, const T& y, const Size& size) noexcept +Rectangle::Rectangle(const T& x, const T& y, const Size& s) noexcept : pos(x, y), - size(size) {} + size(s) {} template -Rectangle::Rectangle(const Point& pos, const T& width, const T& height) noexcept - : pos(pos), - size(width, height) {} +Rectangle::Rectangle(const Point& p, const T& w, const T& h) noexcept + : pos(p), + size(w, h) {} template -Rectangle::Rectangle(const Point& pos, const Size& size) noexcept - : pos(pos), - size(size) {} +Rectangle::Rectangle(const Point& p, const Size& s) noexcept + : pos(p), + size(s) {} template Rectangle::Rectangle(const Rectangle& rect) noexcept @@ -865,9 +880,9 @@ bool Rectangle::contains(const T& x, const T& y) const noexcept } template -bool Rectangle::contains(const Point& pos) const noexcept +bool Rectangle::contains(const Point& p) const noexcept { - return contains(pos.x, pos.y); + return contains(p.x, p.y); } template diff --git a/dgl/src/ImageBase.cpp b/dgl/src/ImageBase.cpp index ea3477b6..ae04b147 100644 --- a/dgl/src/ImageBase.cpp +++ b/dgl/src/ImageBase.cpp @@ -81,12 +81,12 @@ ImageFormat ImageBase::getFormat() const noexcept return format; } -void ImageBase::loadFromMemory(const char* const rawData, - const uint width, - const uint height, - const ImageFormat format) noexcept +void ImageBase::loadFromMemory(const char* const rdata, + const uint width, + const uint height, + const ImageFormat fmt) noexcept { - loadFromMemory(rawData, Size(width, height), format); + loadFromMemory(rdata, Size(width, height), fmt); } void ImageBase::loadFromMemory(const char* const rdata, const Size& s, const ImageFormat fmt) noexcept diff --git a/dgl/src/ImageBaseWidgets.cpp b/dgl/src/ImageBaseWidgets.cpp index fcf04b1c..2d056446 100644 --- a/dgl/src/ImageBaseWidgets.cpp +++ b/dgl/src/ImageBaseWidgets.cpp @@ -201,8 +201,8 @@ ImageBaseKnob::PrivateData::PrivateData(const ImageType& img, const O orientation(o), rotationAngle(0), dragging(false), - lastX(0), - lastY(0), + lastX(0.0), + lastY(0.0), callback(nullptr), alwaysRepaint(false), isImgVertical(img.getHeight() > img.getWidth()), @@ -228,8 +228,8 @@ ImageBaseKnob::PrivateData::PrivateData(PrivateData* const other) orientation(other->orientation), rotationAngle(other->rotationAngle), dragging(false), - lastX(0), - lastY(0), + lastX(0.0), + lastY(0.0), callback(other->callback), alwaysRepaint(other->alwaysRepaint), isImgVertical(other->isImgVertical), @@ -245,21 +245,21 @@ template void ImageBaseKnob::PrivateData::assignFrom(PrivateData* const other) { cleanup(); - image = other->image; - minimum = other->minimum; - maximum = other->maximum; - step = other->step; - value = other->value; - valueDef = other->valueDef; - valueTmp = value; - usingDefault = other->usingDefault; - usingLog = other->usingLog; - orientation = other->orientation; - rotationAngle = other->rotationAngle; - dragging = false; - lastX = 0; - lastY = 0; - callback = other->callback; + image = other->image; + minimum = other->minimum; + maximum = other->maximum; + step = other->step; + value = other->value; + valueDef = other->valueDef; + valueTmp = value; + usingDefault = other->usingDefault; + usingLog = other->usingLog; + orientation = other->orientation; + rotationAngle = other->rotationAngle; + dragging = false; + lastX = 0.0; + lastY = 0.0; + callback = other->callback; alwaysRepaint = other->alwaysRepaint; isImgVertical = other->isImgVertical; imgLayerWidth = other->imgLayerWidth; @@ -476,7 +476,7 @@ bool ImageBaseKnob::onMotion(const MotionEvent& ev) if (pData->orientation == ImageBaseKnob::Horizontal) { - if (const int movX = ev.pos.getX() - pData->lastX) + if (const double movX = ev.pos.getX() - pData->lastX) { d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f; value = (pData->usingLog ? pData->invlogscale(pData->valueTmp) : pData->valueTmp) + (float(pData->maximum - pData->minimum) / d * float(movX)); @@ -485,7 +485,7 @@ bool ImageBaseKnob::onMotion(const MotionEvent& ev) } else if (pData->orientation == ImageBaseKnob::Vertical) { - if (const int movY = pData->lastY - ev.pos.getY()) + if (const double movY = pData->lastY - ev.pos.getY()) { d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f; value = (pData->usingLog ? pData->invlogscale(pData->valueTmp) : pData->valueTmp) + (float(pData->maximum - pData->minimum) / d * float(movY)); @@ -529,7 +529,8 @@ bool ImageBaseKnob::onScroll(const ScrollEvent& ev) return false; const float d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f; - float value = (pData->usingLog ? pData->invlogscale(pData->valueTmp) : pData->valueTmp) + (float(pData->maximum - pData->minimum) / d * 10.f * ev.delta.getY()); + float value = (pData->usingLog ? pData->invlogscale(pData->valueTmp) : pData->valueTmp) + + ((pData->maximum - pData->minimum) / d * 10.f * static_cast(ev.delta.getY())); if (pData->usingLog) value = pData->logscale(value); @@ -569,8 +570,8 @@ struct ImageBaseSlider::PrivateData { bool dragging; bool inverted; bool valueIsSet; - int startedX; - int startedY; + double startedX; + double startedY; Callback* callback; @@ -590,8 +591,8 @@ struct ImageBaseSlider::PrivateData { dragging(false), inverted(false), valueIsSet(false), - startedX(0), - startedY(0), + startedX(0.0), + startedY(0.0), callback(nullptr), startPos(), endPos(), @@ -814,8 +815,8 @@ bool ImageBaseSlider::onMouse(const MouseEvent& ev) } float vper; - const int x = ev.pos.getX(); - const int y = ev.pos.getY(); + const double x = ev.pos.getX(); + const double y = ev.pos.getY(); if (pData->startPos.getY() == pData->endPos.getY()) { @@ -880,8 +881,8 @@ bool ImageBaseSlider::onMotion(const MotionEvent& ev) return false; const bool horizontal = pData->startPos.getY() == pData->endPos.getY(); - const int x = ev.pos.getX(); - const int y = ev.pos.getY(); + const double x = ev.pos.getX(); + const double y = ev.pos.getY(); if ((horizontal && pData->sliderArea.containsX(x)) || (pData->sliderArea.containsY(y) && ! horizontal)) { diff --git a/dgl/src/OpenGL.cpp b/dgl/src/OpenGL.cpp index ad179532..5af0588a 100644 --- a/dgl/src/OpenGL.cpp +++ b/dgl/src/OpenGL.cpp @@ -60,7 +60,7 @@ void Line::draw(const GraphicsContext&, const T width) { DISTRHO_SAFE_ASSERT_RETURN(width != 0,); - glLineWidth(width); + glLineWidth(static_cast(width)); drawLine(posStart, posEnd); } @@ -120,7 +120,7 @@ void Circle::drawOutline(const GraphicsContext&, const T lineWidth) { DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); - glLineWidth(lineWidth); + glLineWidth(static_cast(lineWidth)); drawCircle(fPos, fNumSegments, fSize, fSin, fCos, true); } @@ -177,7 +177,7 @@ void Triangle::drawOutline(const GraphicsContext&, const T lineWidth) { DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); - glLineWidth(lineWidth); + glLineWidth(static_cast(lineWidth)); drawTriangle(pos1, pos2, pos3, true); } @@ -244,7 +244,7 @@ void Rectangle::drawOutline(const GraphicsContext&, const T lineWidth) { DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); - glLineWidth(lineWidth); + glLineWidth(static_cast(lineWidth)); drawRectangle(*this, true); } @@ -348,8 +348,8 @@ OpenGLImage::OpenGLImage() DISTRHO_SAFE_ASSERT(textureId != 0); } -OpenGLImage::OpenGLImage(const char* const rawData, const uint width, const uint height, const ImageFormat format) - : ImageBase(rawData, width, height, format), +OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, const ImageFormat fmt) + : ImageBase(rdata, w, h, fmt), textureId(0), setupCalled(false) { @@ -357,8 +357,8 @@ OpenGLImage::OpenGLImage(const char* const rawData, const uint width, const uint DISTRHO_SAFE_ASSERT(textureId != 0); } -OpenGLImage::OpenGLImage(const char* const rawData, const Size& size, const ImageFormat format) - : ImageBase(rawData, size, format), +OpenGLImage::OpenGLImage(const char* const rdata, const Size& s, const ImageFormat fmt) + : ImageBase(rdata, s, fmt), textureId(0), setupCalled(false) { @@ -402,8 +402,8 @@ OpenGLImage& OpenGLImage::operator=(const OpenGLImage& image) noexcept } // deprecated calls -OpenGLImage::OpenGLImage(const char* const rawData, const uint width, const uint height, const GLenum format) - : ImageBase(rawData, width, height, asDISTRHOImageFormat(format)), +OpenGLImage::OpenGLImage(const char* const rdata, const uint w, const uint h, const GLenum fmt) + : ImageBase(rdata, w, h, asDISTRHOImageFormat(fmt)), textureId(0), setupCalled(false) { @@ -411,8 +411,8 @@ OpenGLImage::OpenGLImage(const char* const rawData, const uint width, const uint DISTRHO_SAFE_ASSERT(textureId != 0); } -OpenGLImage::OpenGLImage(const char* const rawData, const Size& size, const GLenum format) - : ImageBase(rawData, size, asDISTRHOImageFormat(format)), +OpenGLImage::OpenGLImage(const char* const rdata, const Size& s, const GLenum fmt) + : ImageBase(rdata, s, asDISTRHOImageFormat(fmt)), textureId(0), setupCalled(false) { @@ -568,31 +568,33 @@ void SubWidget::PrivateData::display(const uint width, const uint height, const { // full viewport size glViewport(0, - -(height * autoScaleFactor - height), - width * autoScaleFactor, - height * autoScaleFactor); + -static_cast(height * autoScaleFactor - height + 0.5), + static_cast(width * autoScaleFactor + 0.5), + static_cast(height * autoScaleFactor + 0.5)); } else if (needsViewportScaling) { // limit viewport to widget bounds glViewport(absolutePos.getX(), - height - self->getHeight() - absolutePos.getY(), - self->getWidth(), - self->getHeight()); + static_cast(height - self->getHeight()) - absolutePos.getY(), + static_cast(self->getWidth()), + static_cast(self->getHeight())); } else { // set viewport pos - glViewport(absolutePos.getX() * autoScaleFactor, - -std::round((height * autoScaleFactor - height) + (absolutePos.getY() * autoScaleFactor)), - std::round(width * autoScaleFactor), - std::round(height * autoScaleFactor)); + glViewport(static_cast(absolutePos.getX() * autoScaleFactor + 0.5), + -static_cast(std::round((height * autoScaleFactor - height) + + (absolutePos.getY() * autoScaleFactor))), + static_cast(std::round(width * autoScaleFactor)), + static_cast(std::round(height * autoScaleFactor))); // then cut the outer bounds - glScissor(absolutePos.getX() * autoScaleFactor, - height - std::round((self->getHeight() + absolutePos.getY()) * autoScaleFactor), - std::round(self->getWidth() * autoScaleFactor), - std::round(self->getHeight() * autoScaleFactor)); + glScissor(static_cast(absolutePos.getX() * autoScaleFactor + 0.5), + static_cast(height - std::round((static_cast(self->getHeight()) + absolutePos.getY()) + * autoScaleFactor)), + static_cast(std::round(self->getWidth() * autoScaleFactor)), + static_cast(std::round(self->getHeight() * autoScaleFactor))); glEnable(GL_SCISSOR_TEST); needsDisableScissor = true; @@ -622,9 +624,16 @@ void TopLevelWidget::PrivateData::display() // full viewport size if (window.pData->autoScaling) - glViewport(0, -(height * autoScaleFactor - height), width * autoScaleFactor, height * autoScaleFactor); + { + glViewport(0, + -static_cast(height * autoScaleFactor - height), + static_cast(width * autoScaleFactor), + static_cast(height * autoScaleFactor)); + } else - glViewport(0, 0, width, height); + { + glViewport(0, 0, static_cast(width), static_cast(height)); + } // main widget drawing self->onDisplay(); diff --git a/dgl/src/SubWidget.cpp b/dgl/src/SubWidget.cpp index b22360ca..3e0ef59d 100644 --- a/dgl/src/SubWidget.cpp +++ b/dgl/src/SubWidget.cpp @@ -64,8 +64,8 @@ Rectangle SubWidget::getAbsoluteArea() const noexcept Rectangle SubWidget::getConstrainedAbsoluteArea() const noexcept { - return Rectangle(std::max(0, getAbsoluteX()), - std::max(0, getAbsoluteY()), + return Rectangle(static_cast(std::max(0, getAbsoluteX())), + static_cast(std::max(0, getAbsoluteY())), getSize()); } diff --git a/dgl/src/Vulkan.cpp b/dgl/src/Vulkan.cpp index 5f15d4b2..d18b3c32 100644 --- a/dgl/src/Vulkan.cpp +++ b/dgl/src/Vulkan.cpp @@ -170,11 +170,11 @@ template class Rectangle; VulkanImage::VulkanImage() : ImageBase() {} -VulkanImage::VulkanImage(const char* const rawData, const uint width, const uint height, const ImageFormat format) - : ImageBase(rawData, width, height, format) {} +VulkanImage::VulkanImage(const char* const rdata, const uint w, const uint h, const ImageFormat fmt) + : ImageBase(rdata, w, h, fmt) {} -VulkanImage::VulkanImage(const char* const rawData, const Size& size, const ImageFormat format) - : ImageBase(rawData, size, format) {} +VulkanImage::VulkanImage(const char* const rdata, const Size& s, const ImageFormat fmt) + : ImageBase(rdata, s, fmt) {} VulkanImage::VulkanImage(const VulkanImage& image) : ImageBase(image.rawData, image.size, image.format) {} diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index 66a02ef4..9866d606 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -93,18 +93,25 @@ void Window::setResizable(const bool resizable) uint Window::getWidth() const noexcept { - return puglGetFrame(pData->view).width; + const double width = puglGetFrame(pData->view).width; + DISTRHO_SAFE_ASSERT_RETURN(width >= 0.0, 0); + return static_cast(width + 0.5); } uint Window::getHeight() const noexcept { - return puglGetFrame(pData->view).height; + const double height = puglGetFrame(pData->view).height; + DISTRHO_SAFE_ASSERT_RETURN(height >= 0.0, 0); + return static_cast(height + 0.5); } Size Window::getSize() const noexcept { const PuglRect rect = puglGetFrame(pData->view); - return Size(rect.width, rect.height); + DISTRHO_SAFE_ASSERT_RETURN(rect.width >= 0.0, Size()); + DISTRHO_SAFE_ASSERT_RETURN(rect.height >= 0.0, Size()); + return Size(static_cast(rect.width + 0.5), + static_cast(rect.height + 0.5)); } void Window::setWidth(const uint width) @@ -123,7 +130,7 @@ void Window::setSize(const uint width, const uint height) // FIXME add default and min props for this if (pData->minWidth == 0 && pData->minHeight == 0) - puglSetDefaultSize(pData->view, width, height); + puglSetDefaultSize(pData->view, static_cast(width), static_cast(height)); puglSetWindowSize(pData->view, width, height); } @@ -237,16 +244,16 @@ void Window::setGeometryConstraints(const uint minimumWidth, const double scaleFactor = pData->scaleFactor; puglSetGeometryConstraints(pData->view, - minimumWidth * scaleFactor, - minimumHeight * scaleFactor, + static_cast(minimumWidth * scaleFactor + 0.5), + static_cast(minimumHeight * scaleFactor + 0.5), keepAspectRatio); if (scaleFactor != 1.0) { const Size size(getSize()); - setSize(size.getWidth() * scaleFactor, - size.getHeight() * scaleFactor); + setSize(static_cast(size.getWidth() * scaleFactor + 0.5), + static_cast(size.getHeight() * scaleFactor + 0.5)); } } diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp index 302d3ac4..e4dd6e4c 100644 --- a/dgl/src/WindowPrivateData.cpp +++ b/dgl/src/WindowPrivateData.cpp @@ -146,7 +146,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, { if (isEmbed) { - puglSetDefaultSize(view, width, height); + puglSetDefaultSize(view, static_cast(width), static_cast(height)); puglSetParentWindow(view, parentWindowHandle); } @@ -246,8 +246,8 @@ void Window::PrivateData::show() // FIXME PuglRect rect = puglGetFrame(view); - puglSetDefaultSize(view, rect.width, rect.height); - puglSetWindowSize(view, rect.width, rect.height); + puglSetDefaultSize(view, static_cast(rect.width), static_cast(rect.height)); + puglSetWindowSize(view, static_cast(rect.width), static_cast(rect.height)); #ifdef DISTRHO_OS_WINDOWS puglWin32ShowWindowCentered(view); @@ -395,7 +395,7 @@ void Window::PrivateData::startModal() // FIXME? PuglRect rect = puglGetFrame(view); - puglSetDefaultSize(view, rect.width, rect.height); + puglSetDefaultSize(view, static_cast(rect.width), static_cast(rect.height)); // make sure both parent and ourselves are visible modal.parent->show(); @@ -464,7 +464,7 @@ void Window::PrivateData::runAsModal(const bool blockWait) // ----------------------------------------------------------------------- // pugl events -void Window::PrivateData::onPuglConfigure(const int width, const int height) +void Window::PrivateData::onPuglConfigure(const double width, const double height) { DISTRHO_SAFE_ASSERT_INT2_RETURN(width > 1 && height > 1, width, height,); @@ -472,16 +472,18 @@ void Window::PrivateData::onPuglConfigure(const int width, const int height) if (autoScaling) { - const double scaleHorizontal = static_cast(width) / static_cast(minWidth); - const double scaleVertical = static_cast(height) / static_cast(minHeight); + const double scaleHorizontal = width / static_cast(minWidth); + const double scaleVertical = height / static_cast(minHeight); autoScaleFactor = scaleHorizontal < scaleVertical ? scaleHorizontal : scaleVertical; } - self->onReshape(width, height); + const uint uwidth = static_cast(width + 0.5); + const uint uheight = static_cast(height + 0.5); + self->onReshape(uwidth, uheight); #ifndef DPF_TEST_WINDOW_CPP if (topLevelWidget != nullptr) - topLevelWidget->setSize(width, height); + topLevelWidget->setSize(uwidth, uheight); #endif // always repaint after a resize diff --git a/dgl/src/WindowPrivateData.hpp b/dgl/src/WindowPrivateData.hpp index 47dbf9ab..934a6222 100644 --- a/dgl/src/WindowPrivateData.hpp +++ b/dgl/src/WindowPrivateData.hpp @@ -91,6 +91,9 @@ struct Window::PrivateData : IdleCallback { { DISTRHO_SAFE_ASSERT(! enabled); } + + DISTRHO_DECLARE_NON_COPYABLE(Modal) + DISTRHO_PREVENT_HEAP_ALLOCATION } modal; /** Constructor for a regular, standalone window. */ @@ -144,7 +147,7 @@ struct Window::PrivateData : IdleCallback { void runAsModal(bool blockWait); // pugl events - void onPuglConfigure(int width, int height); + void onPuglConfigure(double width, double height); void onPuglExpose(); void onPuglClose(); void onPuglFocus(bool focus, CrossingMode mode); diff --git a/dgl/src/pugl.cpp b/dgl/src/pugl.cpp index d7dac469..7372b830 100644 --- a/dgl/src/pugl.cpp +++ b/dgl/src/pugl.cpp @@ -194,14 +194,14 @@ void puglSetMatchingBackendForCurrentBuild(PuglView* const view) PuglStatus puglSetGeometryConstraints(PuglView* const view, const uint width, const uint height, const bool aspect) { - view->minWidth = width; - view->minHeight = height; + view->minWidth = (int)width; + view->minHeight = (int)height; if (aspect) { - view->minAspectX = width; - view->minAspectY = height; - view->maxAspectX = width; - view->maxAspectY = height; + view->minAspectX = (int)width; + view->minAspectY = (int)height; + view->maxAspectX = (int)width; + view->maxAspectY = (int)height; } #if defined(DISTRHO_OS_HAIKU)