Browse Source

Fixes for widget bounds (plus NanoVG)

gh-pages
falkTX 11 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) NanoWidget(Window& parent)
: Widget(parent), : Widget(parent),
NanoVG() {}
NanoVG()
{
setNeedsScaling(true);
}


protected: protected:
/** /**


+ 10
- 1
dgl/Widget.hpp View File

@@ -297,16 +297,25 @@ protected:
virtual void onResize(const ResizeEvent&); 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. When enabled, the local widget coordinates are ignored.
@note: This is an internal function; @note: This is an internal function;
You do not need it under normal circumstances. You do not need it under normal circumstances.
*/ */
void setNeedsFullViewport(bool yesNo) noexcept; 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: private:
Window& fParent; Window& fParent;
bool fNeedsFullViewport; bool fNeedsFullViewport;
bool fNeedsScaling;
bool fVisible; bool fVisible;
Rectangle<int> fArea; Rectangle<int> fArea;




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

@@ -25,6 +25,7 @@ START_NAMESPACE_DGL
Widget::Widget(Window& parent) Widget::Widget(Window& parent)
: fParent(parent), : fParent(parent),
fNeedsFullViewport(false), fNeedsFullViewport(false),
fNeedsScaling(false),
fVisible(true) fVisible(true)
{ {
fParent._addWidget(this); fParent._addWidget(this);
@@ -230,6 +231,11 @@ void Widget::setNeedsFullViewport(bool yesNo) noexcept
fNeedsFullViewport = yesNo; fNeedsFullViewport = yesNo;
} }


void Widget::setNeedsScaling(bool yesNo) noexcept
{
fNeedsScaling = yesNo;
}

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


END_NAMESPACE_DGL END_NAMESPACE_DGL

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

@@ -584,21 +584,28 @@ struct Window::PrivateData {
// display widget // display widget
widget->onDisplay(); 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 else
{ {
// limit viewport to widget bounds // 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 // 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 // display widget
widget->onDisplay(); widget->onDisplay();


// done // done
//glPopMatrix();
glPopMatrix();
} }
} }
} }


Loading…
Cancel
Save