Signed-off-by: falkTX <falktx@falktx.com>pull/272/head
@@ -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 | |||
@@ -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<uint>(w, h), format); }; | |||
inline void loadFromMemory(const char* rdata, uint w, uint h, ImageFormat fmt = kImageFormatBGRA) | |||
{ loadFromMemory(rdata, Size<uint>(w, h), fmt); }; | |||
inline void draw(const GraphicsContext& context) | |||
{ drawAt(context, Point<int>(0, 0)); }; | |||
inline void drawAt(const GraphicsContext& context, int x, int y) | |||
@@ -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<uint>(w, h), format); }; | |||
inline void loadFromMemory(const char* rdata, uint w, uint h, ImageFormat fmt = kImageFormatBGRA) | |||
{ loadFromMemory(rdata, Size<uint>(w, h), fmt); }; | |||
inline void draw(const GraphicsContext& context) | |||
{ drawAt(context, Point<int>(0, 0)); }; | |||
inline void drawAt(const GraphicsContext& context, int x, int y) | |||
@@ -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<uint>(w, h), format); }; | |||
inline void loadFromMemory(const char* rdata, uint w, uint h, ImageFormat fmt = kImageFormatBGRA) | |||
{ loadFromMemory(rdata, Size<uint>(w, h), fmt); }; | |||
inline void draw(const GraphicsContext& context) | |||
{ drawAt(context, Point<int>(0, 0)); }; | |||
inline void drawAt(const GraphicsContext& context, int x, int y) | |||
@@ -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<uint>& size, const ImageFormat format) | |||
: ImageBase(rawData, size, format), | |||
CairoImage::CairoImage(const char* const rdata, const Size<uint>& 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<uint>& 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<int>(s.getWidth()); | |||
const int height = static_cast<int>(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<size_t>(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<uint>& 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<uchar>(rdata[h*width*3+w*3+0]); | |||
newdata[h*width*4+w*4+1] = static_cast<uchar>(rdata[h*width*3+w*3+1]); | |||
newdata[h*width*4+w*4+2] = static_cast<uchar>(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<uint>& 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<uchar>(rdata[h*width*4+w*4+0]); | |||
newdata[h*width*4+w*4+1] = static_cast<uchar>(rdata[h*width*4+w*4+1]); | |||
newdata[h*width*4+w*4+2] = static_cast<uchar>(rdata[h*width*4+w*4+2]); | |||
newdata[h*width*4+w*4+3] = static_cast<uchar>(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<uint>(cairo_image_surface_get_width(newsurface), cairo_image_surface_get_height(newsurface)); | |||
size = Size<uint>(static_cast<uint>(newwidth), static_cast<uint>(newheight)); | |||
} | |||
void CairoImage::drawAt(const GraphicsContext& context, const Point<int>& pos) | |||
@@ -597,7 +602,7 @@ void ImageBaseKnob<CairoImage>::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<CairoImage>::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<int>(pData->imgLayerWidth); | |||
const int layerH = static_cast<int>(pData->imgLayerHeight); | |||
int layerNum = 0; | |||
if (pData->rotationAngle == 0) | |||
layerNum = uint(normValue * float(pData->imgLayerCount-1)); | |||
layerNum = static_cast<int>(normValue * static_cast<double>(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<CairoImage>::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); | |||
} | |||
@@ -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<int>(ev.button); | |||
state = kStateDown; | |||
self->repaint(); | |||
return true; | |||
@@ -135,8 +135,8 @@ struct ImageBaseKnob<ImageType>::PrivateData { | |||
int rotationAngle; | |||
bool dragging; | |||
int lastX; | |||
int lastY; | |||
double lastX; | |||
double lastY; | |||
Callback* callback; | |||
@@ -164,18 +164,18 @@ struct ImageBaseKnob<ImageType>::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) | |||
@@ -249,7 +249,22 @@ bool Size<T>::isInvalid() const noexcept | |||
template<typename T> | |||
Size<int> Size<T>::toInt() const noexcept | |||
{ | |||
return Size<int>(fWidth, fHeight); | |||
return Size<int>(static_cast<int>(fWidth), | |||
static_cast<int>(fHeight)); | |||
} | |||
template<> | |||
Size<int> Size<double>::toInt() const noexcept | |||
{ | |||
return Size<int>(static_cast<int>(fWidth + 0.5), | |||
static_cast<int>(fHeight + 0.5)); | |||
} | |||
template<> | |||
Size<int> Size<float>::toInt() const noexcept | |||
{ | |||
return Size<int>(static_cast<int>(fWidth + 0.5f), | |||
static_cast<int>(fHeight + 0.5f)); | |||
} | |||
template<typename T> | |||
@@ -645,10 +660,10 @@ Triangle<T>::Triangle(const T& x1, const T& y1, const T& x2, const T& y2, const | |||
pos3(x3, y3) {} | |||
template<typename T> | |||
Triangle<T>::Triangle(const Point<T>& pos1, const Point<T>& pos2, const Point<T>& pos3) noexcept | |||
: pos1(pos1), | |||
pos2(pos2), | |||
pos3(pos3) {} | |||
Triangle<T>::Triangle(const Point<T>& p1, const Point<T>& p2, const Point<T>& p3) noexcept | |||
: pos1(p1), | |||
pos2(p2), | |||
pos3(p3) {} | |||
template<typename T> | |||
Triangle<T>::Triangle(const Triangle<T>& tri) noexcept | |||
@@ -710,24 +725,24 @@ Rectangle<T>::Rectangle() noexcept | |||
size(0, 0) {} | |||
template<typename T> | |||
Rectangle<T>::Rectangle(const T& x, const T& y, const T& width, const T& height) noexcept | |||
Rectangle<T>::Rectangle(const T& x, const T& y, const T& w, const T& h) noexcept | |||
: pos(x, y), | |||
size(width, height) {} | |||
size(w, h) {} | |||
template<typename T> | |||
Rectangle<T>::Rectangle(const T& x, const T& y, const Size<T>& size) noexcept | |||
Rectangle<T>::Rectangle(const T& x, const T& y, const Size<T>& s) noexcept | |||
: pos(x, y), | |||
size(size) {} | |||
size(s) {} | |||
template<typename T> | |||
Rectangle<T>::Rectangle(const Point<T>& pos, const T& width, const T& height) noexcept | |||
: pos(pos), | |||
size(width, height) {} | |||
Rectangle<T>::Rectangle(const Point<T>& p, const T& w, const T& h) noexcept | |||
: pos(p), | |||
size(w, h) {} | |||
template<typename T> | |||
Rectangle<T>::Rectangle(const Point<T>& pos, const Size<T>& size) noexcept | |||
: pos(pos), | |||
size(size) {} | |||
Rectangle<T>::Rectangle(const Point<T>& p, const Size<T>& s) noexcept | |||
: pos(p), | |||
size(s) {} | |||
template<typename T> | |||
Rectangle<T>::Rectangle(const Rectangle<T>& rect) noexcept | |||
@@ -865,9 +880,9 @@ bool Rectangle<T>::contains(const T& x, const T& y) const noexcept | |||
} | |||
template<typename T> | |||
bool Rectangle<T>::contains(const Point<T>& pos) const noexcept | |||
bool Rectangle<T>::contains(const Point<T>& p) const noexcept | |||
{ | |||
return contains(pos.x, pos.y); | |||
return contains(p.x, p.y); | |||
} | |||
template<typename T> | |||
@@ -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<uint>(width, height), format); | |||
loadFromMemory(rdata, Size<uint>(width, height), fmt); | |||
} | |||
void ImageBase::loadFromMemory(const char* const rdata, const Size<uint>& s, const ImageFormat fmt) noexcept | |||
@@ -201,8 +201,8 @@ ImageBaseKnob<ImageType>::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<ImageType>::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 <class ImageType> | |||
void ImageBaseKnob<ImageType>::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<ImageType>::onMotion(const MotionEvent& ev) | |||
if (pData->orientation == ImageBaseKnob<ImageType>::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<ImageType>::onMotion(const MotionEvent& ev) | |||
} | |||
else if (pData->orientation == ImageBaseKnob<ImageType>::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<ImageType>::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<float>(ev.delta.getY())); | |||
if (pData->usingLog) | |||
value = pData->logscale(value); | |||
@@ -569,8 +570,8 @@ struct ImageBaseSlider<ImageType>::PrivateData { | |||
bool dragging; | |||
bool inverted; | |||
bool valueIsSet; | |||
int startedX; | |||
int startedY; | |||
double startedX; | |||
double startedY; | |||
Callback* callback; | |||
@@ -590,8 +591,8 @@ struct ImageBaseSlider<ImageType>::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<ImageType>::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<ImageType>::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)) | |||
{ | |||
@@ -60,7 +60,7 @@ void Line<T>::draw(const GraphicsContext&, const T width) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(width != 0,); | |||
glLineWidth(width); | |||
glLineWidth(static_cast<GLfloat>(width)); | |||
drawLine<T>(posStart, posEnd); | |||
} | |||
@@ -120,7 +120,7 @@ void Circle<T>::drawOutline(const GraphicsContext&, const T lineWidth) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); | |||
glLineWidth(lineWidth); | |||
glLineWidth(static_cast<GLfloat>(lineWidth)); | |||
drawCircle<T>(fPos, fNumSegments, fSize, fSin, fCos, true); | |||
} | |||
@@ -177,7 +177,7 @@ void Triangle<T>::drawOutline(const GraphicsContext&, const T lineWidth) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); | |||
glLineWidth(lineWidth); | |||
glLineWidth(static_cast<GLfloat>(lineWidth)); | |||
drawTriangle<T>(pos1, pos2, pos3, true); | |||
} | |||
@@ -244,7 +244,7 @@ void Rectangle<T>::drawOutline(const GraphicsContext&, const T lineWidth) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(lineWidth != 0,); | |||
glLineWidth(lineWidth); | |||
glLineWidth(static_cast<GLfloat>(lineWidth)); | |||
drawRectangle<T>(*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<uint>& size, const ImageFormat format) | |||
: ImageBase(rawData, size, format), | |||
OpenGLImage::OpenGLImage(const char* const rdata, const Size<uint>& 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<uint>& size, const GLenum format) | |||
: ImageBase(rawData, size, asDISTRHOImageFormat(format)), | |||
OpenGLImage::OpenGLImage(const char* const rdata, const Size<uint>& 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<int>(height * autoScaleFactor - height + 0.5), | |||
static_cast<int>(width * autoScaleFactor + 0.5), | |||
static_cast<int>(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<int>(height - self->getHeight()) - absolutePos.getY(), | |||
static_cast<int>(self->getWidth()), | |||
static_cast<int>(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<int>(absolutePos.getX() * autoScaleFactor + 0.5), | |||
-static_cast<int>(std::round((height * autoScaleFactor - height) | |||
+ (absolutePos.getY() * autoScaleFactor))), | |||
static_cast<int>(std::round(width * autoScaleFactor)), | |||
static_cast<int>(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<int>(absolutePos.getX() * autoScaleFactor + 0.5), | |||
static_cast<int>(height - std::round((static_cast<int>(self->getHeight()) + absolutePos.getY()) | |||
* autoScaleFactor)), | |||
static_cast<int>(std::round(self->getWidth() * autoScaleFactor)), | |||
static_cast<int>(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<int>(height * autoScaleFactor - height), | |||
static_cast<int>(width * autoScaleFactor), | |||
static_cast<int>(height * autoScaleFactor)); | |||
} | |||
else | |||
glViewport(0, 0, width, height); | |||
{ | |||
glViewport(0, 0, static_cast<int>(width), static_cast<int>(height)); | |||
} | |||
// main widget drawing | |||
self->onDisplay(); | |||
@@ -64,8 +64,8 @@ Rectangle<int> SubWidget::getAbsoluteArea() const noexcept | |||
Rectangle<uint> SubWidget::getConstrainedAbsoluteArea() const noexcept | |||
{ | |||
return Rectangle<uint>(std::max(0, getAbsoluteX()), | |||
std::max(0, getAbsoluteY()), | |||
return Rectangle<uint>(static_cast<uint>(std::max(0, getAbsoluteX())), | |||
static_cast<uint>(std::max(0, getAbsoluteY())), | |||
getSize()); | |||
} | |||
@@ -170,11 +170,11 @@ template class Rectangle<ushort>; | |||
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<uint>& size, const ImageFormat format) | |||
: ImageBase(rawData, size, format) {} | |||
VulkanImage::VulkanImage(const char* const rdata, const Size<uint>& s, const ImageFormat fmt) | |||
: ImageBase(rdata, s, fmt) {} | |||
VulkanImage::VulkanImage(const VulkanImage& image) | |||
: ImageBase(image.rawData, image.size, image.format) {} | |||
@@ -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<uint>(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<uint>(height + 0.5); | |||
} | |||
Size<uint> Window::getSize() const noexcept | |||
{ | |||
const PuglRect rect = puglGetFrame(pData->view); | |||
return Size<uint>(rect.width, rect.height); | |||
DISTRHO_SAFE_ASSERT_RETURN(rect.width >= 0.0, Size<uint>()); | |||
DISTRHO_SAFE_ASSERT_RETURN(rect.height >= 0.0, Size<uint>()); | |||
return Size<uint>(static_cast<uint>(rect.width + 0.5), | |||
static_cast<uint>(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<int>(width), static_cast<int>(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<uint>(minimumWidth * scaleFactor + 0.5), | |||
static_cast<uint>(minimumHeight * scaleFactor + 0.5), | |||
keepAspectRatio); | |||
if (scaleFactor != 1.0) | |||
{ | |||
const Size<uint> size(getSize()); | |||
setSize(size.getWidth() * scaleFactor, | |||
size.getHeight() * scaleFactor); | |||
setSize(static_cast<uint>(size.getWidth() * scaleFactor + 0.5), | |||
static_cast<uint>(size.getHeight() * scaleFactor + 0.5)); | |||
} | |||
} | |||
@@ -146,7 +146,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, | |||
{ | |||
if (isEmbed) | |||
{ | |||
puglSetDefaultSize(view, width, height); | |||
puglSetDefaultSize(view, static_cast<int>(width), static_cast<int>(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<int>(rect.width), static_cast<int>(rect.height)); | |||
puglSetWindowSize(view, static_cast<uint>(rect.width), static_cast<uint>(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<int>(rect.width), static_cast<int>(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<double>(width) / static_cast<double>(minWidth); | |||
const double scaleVertical = static_cast<double>(height) / static_cast<double>(minHeight); | |||
const double scaleHorizontal = width / static_cast<double>(minWidth); | |||
const double scaleVertical = height / static_cast<double>(minHeight); | |||
autoScaleFactor = scaleHorizontal < scaleVertical ? scaleHorizontal : scaleVertical; | |||
} | |||
self->onReshape(width, height); | |||
const uint uwidth = static_cast<uint>(width + 0.5); | |||
const uint uheight = static_cast<uint>(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 | |||
@@ -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); | |||
@@ -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) | |||