commit e5949582e6b5d60f9a4aa1285668efdb598ed28b
parent 9b62626d8cd56f8b4407b873a2f6b1a6cd38c846
Author: falkTX <falktx@falktx.com>
Date: Wed, 11 Oct 2023 15:17:45 +0200
Set auto-scale-factor early, cleaner GL setup
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
3 files changed, 16 insertions(+), 34 deletions(-)
diff --git a/dgl/src/Cairo.cpp b/dgl/src/Cairo.cpp
@@ -784,18 +784,13 @@ void TopLevelWidget::PrivateData::display()
cairo_matrix_t matrix;
cairo_get_matrix(handle, &matrix);
+ cairo_translate(handle, 0, 0);
// full viewport size
if (window.pData->autoScaling)
- {
- cairo_translate(handle, 0, 0);
cairo_scale(handle, autoScaleFactor, autoScaleFactor);
- }
else
- {
- cairo_translate(handle, 0, 0);
cairo_scale(handle, 1.0, 1.0);
- }
// main widget drawing
self->onDisplay();
diff --git a/dgl/src/OpenGL.cpp b/dgl/src/OpenGL.cpp
@@ -707,26 +707,21 @@ void SubWidget::PrivateData::display(const uint width, const uint height, const
else if (needsFullViewportForDrawing || (absolutePos.isZero() && self->getSize() == Size<uint>(width, height)))
{
// full viewport size
- glViewport(0,
- -static_cast<int>(height * autoScaleFactor - height + 0.5),
- static_cast<int>(width * autoScaleFactor + 0.5),
- static_cast<int>(height * autoScaleFactor + 0.5));
+ glViewport(0, 0, static_cast<int>(width), static_cast<int>(height));
}
else
{
// set viewport pos
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)));
+ -static_cast<int>(absolutePos.getY() * autoScaleFactor + 0.5),
+ static_cast<int>(width),
+ static_cast<int>(height));
// then cut the outer bounds
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)));
+ static_cast<int>(height - (self->getHeight() + absolutePos.getY()) * autoScaleFactor + 0.5),
+ static_cast<int>(self->getWidth() * autoScaleFactor + 0.5),
+ static_cast<int>(self->getHeight() * autoScaleFactor + 0.5));
glEnable(GL_SCISSOR_TEST);
needsDisableScissor = true;
@@ -752,26 +747,14 @@ void TopLevelWidget::PrivateData::display()
const uint width = size.getWidth();
const uint height = size.getHeight();
- const double autoScaleFactor = window.pData->autoScaleFactor;
-
// full viewport size
- if (window.pData->autoScaling)
- {
- glViewport(0,
- -static_cast<int>(height * autoScaleFactor - height + 0.5),
- static_cast<int>(width * autoScaleFactor + 0.5),
- static_cast<int>(height * autoScaleFactor + 0.5));
- }
- else
- {
- glViewport(0, 0, static_cast<int>(width), static_cast<int>(height));
- }
+ glViewport(0, 0, static_cast<int>(width), static_cast<int>(height));
// main widget drawing
self->onDisplay();
// now draw subwidgets if there are any
- selfw->pData->displaySubWidgets(width, height, autoScaleFactor);
+ selfw->pData->displaySubWidgets(width, height, window.pData->autoScaleFactor);
}
// -----------------------------------------------------------------------
diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp
@@ -577,9 +577,13 @@ void Window::PrivateData::onPuglConfigure(const double width, const double heigh
const double scaleVertical = height / static_cast<double>(minHeight);
autoScaleFactor = scaleHorizontal < scaleVertical ? scaleHorizontal : scaleVertical;
}
+ else
+ {
+ autoScaleFactor = 1.0;
+ }
- const uint uwidth = static_cast<uint>(width + 0.5);
- const uint uheight = static_cast<uint>(height + 0.5);
+ const uint uwidth = static_cast<uint>(width / autoScaleFactor + 0.5);
+ const uint uheight = static_cast<uint>(height / autoScaleFactor + 0.5);
self->onReshape(uwidth, uheight);