Browse Source

Fixes for widget bounds (plus NanoVG)

gh-pages
falkTX 9 years ago
parent
commit
7936e6f1d0
4 changed files with 32 additions and 7 deletions
  1. +4
    -1
      dgl/NanoVG.hpp
  2. +10
    -1
      dgl/Widget.hpp
  3. +6
    -0
      dgl/src/Widget.cpp
  4. +12
    -5
      dgl/src/Window.cpp

+ 4
- 1
dgl/NanoVG.hpp View File

@@ -794,7 +794,10 @@ public:
*/
NanoWidget(Window& parent)
: Widget(parent),
NanoVG() {}
NanoVG()
{
setNeedsScaling(true);
}

protected:
/**


+ 10
- 1
dgl/Widget.hpp View File

@@ -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<int> fArea;



+ 6
- 0
dgl/src/Widget.cpp View File

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

+ 12
- 5
dgl/src/Window.cpp View File

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


Loading…
Cancel
Save