DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 6f8e578ac6b3c585afb1dc8f0d8e478c3f727bd5
parent 9d8205092be9bea604746904e953cd509506d22d
Author: falkTX <falktx@falktx.com>
Date:   Sat, 14 Aug 2021 11:12:03 +0100

Implement auto-scaling for Cairo, fix repaint for auto-scaling

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdgl/src/Cairo.cpp | 28++++++++++++----------------
Mdgl/src/Window.cpp | 11++++++++++-
2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/dgl/src/Cairo.cpp b/dgl/src/Cairo.cpp @@ -726,21 +726,23 @@ void SubWidget::PrivateData::display(const uint width, const uint height, const cairo_matrix_t matrix; cairo_get_matrix(handle, &matrix); - if (needsFullViewportForDrawing || (absolutePos.isZero() && self->getSize() == Size<uint>(width, height))) - { - // full viewport size - cairo_translate(handle, 0, 0); - } - else if (needsViewportScaling) + if (needsViewportScaling) { // limit viewport to widget bounds // NOTE only used for nanovg for now, which is not relevant here + } + else if (needsFullViewportForDrawing || (absolutePos.isZero() && self->getSize() == Size<uint>(width, height))) + { + // full viewport size cairo_translate(handle, 0, 0); + + // no scaling + cairo_scale(handle, 1.0, 1.0); } else { // set viewport pos - cairo_translate(handle, absolutePos.getX(), absolutePos.getY()); + cairo_translate(handle, absolutePos.getX() * autoScaleFactor, absolutePos.getY() * autoScaleFactor); // then cut the outer bounds cairo_rectangle(handle, @@ -751,6 +753,9 @@ void SubWidget::PrivateData::display(const uint width, const uint height, const cairo_clip(handle); needsResetClip = true; + + // set viewport scaling + cairo_scale(handle, autoScaleFactor, autoScaleFactor); } // display widget @@ -777,15 +782,6 @@ void TopLevelWidget::PrivateData::display() const double autoScaleFactor = window.pData->autoScaleFactor; - // FIXME anything needed here? -#if 0 - // full viewport size - if (window.pData->autoScaling) - glViewport(0, -(height * autoScaleFactor - height), width * autoScaleFactor, height * autoScaleFactor); - else - glViewport(0, 0, width, height); -#endif - // main widget drawing self->onDisplay(); diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp @@ -269,12 +269,21 @@ void Window::repaint() noexcept void Window::repaint(const Rectangle<uint>& rect) noexcept { - const PuglRect prect = { + PuglRect prect = { static_cast<double>(rect.getX()), static_cast<double>(rect.getY()), static_cast<double>(rect.getWidth()), static_cast<double>(rect.getHeight()), }; + if (pData->autoScaling) + { + const double autoScaleFactor = pData->autoScaleFactor; + + prect.x *= autoScaleFactor; + prect.y *= autoScaleFactor; + prect.width *= autoScaleFactor; + prect.height *= autoScaleFactor; + } puglPostRedisplayRect(pData->view, prect); }