Signed-off-by: falkTX <falktx@falktx.com>pull/282/head
@@ -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. | ||||
@@ -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 | ||||
{ | { | ||||
@@ -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) | ||||
@@ -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); | ||||
} | } | ||||
@@ -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(); | ||||