Browse Source

Allow to automatically scale nanovg viewport, used in blendish

Signed-off-by: falkTX <falktx@falktx.com>
pull/282/head
falkTX 4 years ago
parent
commit
13d6c3bfae
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
5 changed files with 31 additions and 16 deletions
  1. +1
    -1
      dgl/SubWidget.hpp
  2. +24
    -12
      dgl/src/OpenGL.cpp
  3. +2
    -1
      dgl/src/SubWidget.cpp
  4. +2
    -1
      dgl/src/SubWidgetPrivateData.cpp
  5. +2
    -1
      dgl/src/SubWidgetPrivateData.hpp

+ 1
- 1
dgl/SubWidget.hpp View File

@@ -129,7 +129,7 @@ public:
/** /**
Indicate that this subwidget will always draw at its own internal size and needs scaling to fit target size. Indicate that this subwidget will always draw at its own internal size and needs scaling to fit target size.
*/ */
void setNeedsViewportScaling(bool needsViewportScaling = true);
void setNeedsViewportScaling(bool needsViewportScaling = true, double autoScaleFactor = 0.0);


/** /**
Indicate that this subwidget should not be drawn on screen, typically because it is managed by something else. Indicate that this subwidget should not be drawn on screen, typically because it is managed by something else.


+ 24
- 12
dgl/src/OpenGL.cpp View File

@@ -575,21 +575,33 @@ void SubWidget::PrivateData::display(const uint width, const uint height, const


bool needsDisableScissor = false; bool needsDisableScissor = false;


if (needsFullViewportForDrawing || (absolutePos.isZero() && self->getSize() == Size<uint>(width, height)))
if (needsViewportScaling)
{ {
// 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));
// limit viewport to widget bounds
const int x = absolutePos.getX();
const int w = static_cast<int>(self->getWidth());
const int h = static_cast<int>(self->getHeight());

if (viewportScaleFactor != 0.0)
{
glViewport(x,
-static_cast<int>(height * viewportScaleFactor - height + absolutePos.getY() + 0.5),
static_cast<int>(width * viewportScaleFactor + 0.5),
static_cast<int>(height * viewportScaleFactor + 0.5));
}
else
{
const int y = static_cast<int>(height - self->getHeight()) - absolutePos.getY();
glViewport(x, y, w, h);
}
} }
else if (needsViewportScaling)
else if (needsFullViewportForDrawing || (absolutePos.isZero() && self->getSize() == Size<uint>(width, height)))
{ {
// limit viewport to widget bounds
glViewport(absolutePos.getX(),
static_cast<int>(height - self->getHeight()) - absolutePos.getY(),
static_cast<int>(self->getWidth()),
static_cast<int>(self->getHeight()));
// full viewport size
glViewport(0,
-static_cast<int>(height - height + 0.5),
static_cast<int>(width + 0.5),
static_cast<int>(height + 0.5));
} }
else else
{ {


+ 2
- 1
dgl/src/SubWidget.cpp View File

@@ -123,9 +123,10 @@ void SubWidget::setNeedsFullViewportDrawing(const bool needsFullViewportForDrawi
pData->needsFullViewportForDrawing = needsFullViewportForDrawing; pData->needsFullViewportForDrawing = needsFullViewportForDrawing;
} }


void SubWidget::setNeedsViewportScaling(const bool needsViewportScaling)
void SubWidget::setNeedsViewportScaling(const bool needsViewportScaling, const double autoScaleFactor)
{ {
pData->needsViewportScaling = needsViewportScaling; pData->needsViewportScaling = needsViewportScaling;
pData->viewportScaleFactor = autoScaleFactor;
} }


void SubWidget::setSkipDrawing(const bool skipDrawing) void SubWidget::setSkipDrawing(const bool skipDrawing)


+ 2
- 1
dgl/src/SubWidgetPrivateData.cpp View File

@@ -28,7 +28,8 @@ SubWidget::PrivateData::PrivateData(SubWidget* const s, Widget* const pw)
absolutePos(), absolutePos(),
needsFullViewportForDrawing(false), needsFullViewportForDrawing(false),
needsViewportScaling(false), needsViewportScaling(false),
skipDrawing(false)
skipDrawing(false),
viewportScaleFactor(0.0)
{ {
parentWidget->pData->subWidgets.push_back(self); parentWidget->pData->subWidgets.push_back(self);
} }


+ 2
- 1
dgl/src/SubWidgetPrivateData.hpp View File

@@ -30,7 +30,8 @@ struct SubWidget::PrivateData {
Point<int> absolutePos; Point<int> absolutePos;
bool needsFullViewportForDrawing; // needed for widgets drawing out of bounds bool needsFullViewportForDrawing; // needed for widgets drawing out of bounds
bool needsViewportScaling; // needed for NanoVG bool needsViewportScaling; // needed for NanoVG
bool skipDrawing;
bool skipDrawing; // for context reuse in NanoVG based guis
double viewportScaleFactor; // auto-scaling for NanoVG


explicit PrivateData(SubWidget* const s, Widget* const pw); explicit PrivateData(SubWidget* const s, Widget* const pw);
~PrivateData(); ~PrivateData();


Loading…
Cancel
Save