diff --git a/dgl/NanoVG.hpp b/dgl/NanoVG.hpp index f3b1b1de..ad6d6708 100644 --- a/dgl/NanoVG.hpp +++ b/dgl/NanoVG.hpp @@ -794,7 +794,10 @@ public: */ NanoWidget(Window& parent) : Widget(parent), - NanoVG() {} + NanoVG() + { + setNeedsScaling(true); + } protected: /** diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp index 5d112aa1..74b4f809 100644 --- a/dgl/Widget.hpp +++ b/dgl/Widget.hpp @@ -297,16 +297,25 @@ protected: virtual void onResize(const ResizeEvent&); /** - Tell the parent window this widget this the full viewport. + Tell the parent window this widget needs the full viewport. When enabled, the local widget coordinates are ignored. @note: This is an internal function; You do not need it under normal circumstances. */ void setNeedsFullViewport(bool yesNo) noexcept; + /** + Tell the parent window this widget needs scaling. + When enabled, the widget viewport is scaled to match width&height. + @note: This is an internal function; + You do not need it under normal circumstances. + */ + void setNeedsScaling(bool yesNo) noexcept; + private: Window& fParent; bool fNeedsFullViewport; + bool fNeedsScaling; bool fVisible; Rectangle fArea; diff --git a/dgl/src/Widget.cpp b/dgl/src/Widget.cpp index aee727b8..a494d1b3 100644 --- a/dgl/src/Widget.cpp +++ b/dgl/src/Widget.cpp @@ -25,6 +25,7 @@ START_NAMESPACE_DGL Widget::Widget(Window& parent) : fParent(parent), fNeedsFullViewport(false), + fNeedsScaling(false), fVisible(true) { fParent._addWidget(this); @@ -230,6 +231,11 @@ void Widget::setNeedsFullViewport(bool yesNo) noexcept fNeedsFullViewport = yesNo; } +void Widget::setNeedsScaling(bool yesNo) noexcept +{ + fNeedsScaling = yesNo; +} + // ----------------------------------------------------------------------- END_NAMESPACE_DGL diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index 3badce02..58b3495a 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -584,21 +584,28 @@ struct Window::PrivateData { // display widget widget->onDisplay(); } + else if (! widget->fNeedsScaling) + { + // only set viewport pos + glViewport(widget->getAbsoluteX(), fView->height - widget->getHeight() - widget->getAbsoluteY(), fView->width, fView->height); + + // display widget + widget->onDisplay(); + } else { // limit viewport to widget bounds - //glViewport(widget->getAbsoluteX(), fView->height - widget->getHeight() - widget->getAbsoluteY(), widget->getWidth(), widget->getHeight()); - glViewport(widget->getAbsoluteX(), fView->height - widget->getHeight() - widget->getAbsoluteY(), fView->width, fView->height); + glViewport(widget->getAbsoluteX(), fView->height - widget->getHeight() - widget->getAbsoluteY(), widget->getWidth(), widget->getHeight()); // scale contents to match viewport size - //glPushMatrix(); - //glScalef(float(fView->width)/float(widget->getWidth()), float(fView->height)/float(widget->getHeight()), 1.0f); + glPushMatrix(); + glScalef(float(fView->width)/float(widget->getWidth()), float(fView->height)/float(widget->getHeight()), 1.0f); // display widget widget->onDisplay(); // done - //glPopMatrix(); + glPopMatrix(); } } }