From 2e508c73e95ef50947e3ed6e941b67b1f6b5bed4 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 14 Aug 2021 13:34:33 +0100 Subject: [PATCH] Fix fullviewport-drawing auto-scaling for Cairo Signed-off-by: falkTX --- dgl/src/Cairo.cpp | 23 ++++++++++++++++++++--- dgl/src/OpenGL.cpp | 6 +++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/dgl/src/Cairo.cpp b/dgl/src/Cairo.cpp index 66ccf86e..ebefaa56 100644 --- a/dgl/src/Cairo.cpp +++ b/dgl/src/Cairo.cpp @@ -735,9 +735,7 @@ void SubWidget::PrivateData::display(const uint width, const uint height, const { // full viewport size cairo_translate(handle, 0, 0); - - // no scaling - cairo_scale(handle, 1.0, 1.0); + cairo_scale(handle, autoScaleFactor, autoScaleFactor); } else { @@ -776,15 +774,34 @@ void TopLevelWidget::PrivateData::display() if (! selfw->pData->visible) return; + cairo_t* const handle = static_cast(self->getGraphicsContext()).handle; + const Size size(window.getSize()); const uint width = size.getWidth(); const uint height = size.getHeight(); const double autoScaleFactor = window.pData->autoScaleFactor; + cairo_matrix_t matrix; + cairo_get_matrix(handle, &matrix); + + // 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(); + cairo_set_matrix(handle, &matrix); + // now draw subwidgets if there are any selfw->pData->displaySubWidgets(width, height, autoScaleFactor); } diff --git a/dgl/src/OpenGL.cpp b/dgl/src/OpenGL.cpp index 8cc6d889..098c33e6 100644 --- a/dgl/src/OpenGL.cpp +++ b/dgl/src/OpenGL.cpp @@ -649,9 +649,9 @@ void TopLevelWidget::PrivateData::display() if (window.pData->autoScaling) { glViewport(0, - -static_cast(height * autoScaleFactor - height), - static_cast(width * autoScaleFactor), - static_cast(height * autoScaleFactor)); + -static_cast(height * autoScaleFactor - height + 0.5), + static_cast(width * autoScaleFactor + 0.5), + static_cast(height * autoScaleFactor + 0.5)); } else {