commit b4146e6121dcfacfd890d5eb837bf3a80b74bdc5
parent f1c3e35272631e31e033db1fe51f08d134841372
Author: falkTX <falktx@gmail.com>
Date: Sat, 24 May 2014 07:51:27 +0100
Fix up widget bounds within the window
Diffstat:
5 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/dgl/NanoVG.hpp b/dgl/NanoVG.hpp
@@ -279,7 +279,6 @@ public:
return fContext;
}
-protected:
/**
Begin drawing a new frame.
@param withAlha Controls if drawing the shapes to the render target should be done using straight or pre-multiplied alpha.
@@ -696,6 +695,13 @@ protected:
void textAlign(Align align);
/**
+ Sets the text align of current text style.
+ Overloaded function for convenience.
+ @see Align
+ */
+ void textAlign(int align);
+
+ /**
Sets the font face based on specified id of current text style.
*/
void fontFaceId(FontId font);
diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp
@@ -296,6 +296,12 @@ protected:
*/
virtual void onResize(const ResizeEvent&);
+ /**
+ Wherever the Y position is inverted.
+ (starts at the bottom)
+ */
+ bool fInvertedY;
+
private:
Window& fParent;
bool fVisible;
diff --git a/dgl/src/NanoVG.cpp b/dgl/src/NanoVG.cpp
@@ -529,6 +529,11 @@ void NanoVG::textAlign(NanoVG::Align align)
nvgTextAlign(fContext, align);
}
+void NanoVG::textAlign(int align)
+{
+ nvgTextAlign(fContext, align);
+}
+
void NanoVG::fontFaceId(FontId font)
{
nvgFontFaceId(fContext, font);
diff --git a/dgl/src/Widget.cpp b/dgl/src/Widget.cpp
@@ -23,7 +23,8 @@ START_NAMESPACE_DGL
// Widget
Widget::Widget(Window& parent)
- : fParent(parent),
+ : fInvertedY(false),
+ fParent(parent),
fVisible(true)
{
fParent._addWidget(this);
diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp
@@ -575,8 +575,23 @@ struct Window::PrivateData {
if (widget->isVisible())
{
- glViewport(widget->getAbsoluteX(), -widget->getAbsoluteY(), fView->width, fView->height);
+ const int ypos = widget->fInvertedY ? fView->height - widget->getHeight() - widget->getAbsoluteY() : widget->getAbsoluteY();
+
+ // reset color
+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+
+ // limit viewport to widget bounds
+ glViewport(widget->getAbsoluteX(), ypos, widget->getWidth(), widget->getHeight());
+
+ // need scale contents to match viewport
+ glPushMatrix();
+ glScalef(float(fView->width)/float(widget->getWidth()), float(fView->height)/float(widget->getHeight()), 1.0f);
+
+ // display widget
widget->onDisplay();
+
+ // pop
+ glPopMatrix();
}
}