commit ed0d3be276d8b0beaa28dc38eeb79a86db16e425
parent 142af3edcb598e0293f3637b0bad8f4af4158f24
Author: falkTX <falktx@gmail.com>
Date: Thu, 15 May 2014 19:54:11 +0100
Handle close&resize in Window, not Widget
Diffstat:
4 files changed, 43 insertions(+), 25 deletions(-)
diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp
@@ -75,7 +75,6 @@ protected:
virtual bool onScroll(int x, int y, float dx, float dy);
virtual bool onSpecial(bool press, Key key);
virtual void onReshape(int width, int height);
- virtual void onClose();
private:
Window& fParent;
diff --git a/dgl/Window.hpp b/dgl/Window.hpp
@@ -65,6 +65,12 @@ public:
void addIdleCallback(IdleCallback* const callback);
void removeIdleCallback(IdleCallback* const callback);
+protected:
+ virtual void onDisplayBefore();
+ virtual void onDisplayAfter();
+ virtual void onClose();
+ virtual void onReshape(int width, int height);
+
private:
struct PrivateData;
PrivateData* const pData;
diff --git a/dgl/src/Widget.cpp b/dgl/src/Widget.cpp
@@ -207,19 +207,7 @@ bool Widget::onSpecial(bool, Key)
return false;
}
-void Widget::onReshape(int width, int height)
-{
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, width, height, 0, 0.0f, 1.0f);
- glViewport(0, 0, width, height);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-void Widget::onClose()
+void Widget::onReshape(int, int)
{
}
diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp
@@ -575,10 +575,7 @@ struct Window::PrivateData {
void onDisplay()
{
- //DBG("PUGL: onDisplay\n");
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
+ fSelf->onDisplayBefore();
FOR_EACH_WIDGET(it)
{
@@ -587,6 +584,8 @@ struct Window::PrivateData {
if (widget->isVisible())
widget->onDisplay();
}
+
+ fSelf->onDisplayAfter();
}
void onKeyboard(const bool press, const uint key)
@@ -658,7 +657,7 @@ struct Window::PrivateData {
DBGp("PUGL: onSpecial : %i %i\n", press, key);
if (fModal.childFocus != nullptr)
- return;
+ return fModal.childFocus->focus();
FOR_EACH_WIDGET_INV(rit)
{
@@ -673,6 +672,8 @@ struct Window::PrivateData {
{
DBGp("PUGL: onReshape : %i %i\n", width, height);
+ fSelf->onReshape(width, height);
+
FOR_EACH_WIDGET(it)
{
Widget* const widget(*it);
@@ -687,15 +688,11 @@ struct Window::PrivateData {
if (fModal.enabled && fModal.parent != nullptr)
exec_fini();
+ fSelf->onClose();
+
if (fModal.childFocus != nullptr)
fModal.childFocus->onClose();
- FOR_EACH_WIDGET(it)
- {
- Widget* const widget(*it);
- widget->onClose();
- }
-
close();
}
@@ -943,6 +940,34 @@ void Window::removeIdleCallback(IdleCallback* const callback)
// -----------------------------------------------------------------------
+void Window::onDisplayBefore()
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+}
+
+void Window::onDisplayAfter()
+{
+}
+
+void Window::onClose()
+{
+}
+
+void Window::onReshape(int width, int height)
+{
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, width, height, 0, 0.0f, 1.0f);
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+// -----------------------------------------------------------------------
+
END_NAMESPACE_DGL
#undef DBG