Browse Source

Set auto-scale-factor early, cleaner GL setup

Signed-off-by: falkTX <falktx@falktx.com>
pull/443/head
falkTX 2 years ago
parent
commit
e5949582e6
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 16 additions and 34 deletions
  1. +1
    -6
      dgl/src/Cairo.cpp
  2. +9
    -26
      dgl/src/OpenGL.cpp
  3. +6
    -2
      dgl/src/WindowPrivateData.cpp

+ 1
- 6
dgl/src/Cairo.cpp View File

@@ -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();


+ 9
- 26
dgl/src/OpenGL.cpp View File

@@ -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);
}

// -----------------------------------------------------------------------


+ 6
- 2
dgl/src/WindowPrivateData.cpp View File

@@ -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);



Loading…
Cancel
Save