Browse Source

Handle close&resize in Window, not Widget

gh-pages
falkTX 11 years ago
parent
commit
ed0d3be276
4 changed files with 43 additions and 25 deletions
  1. +0
    -1
      dgl/Widget.hpp
  2. +6
    -0
      dgl/Window.hpp
  3. +1
    -13
      dgl/src/Widget.cpp
  4. +36
    -11
      dgl/src/Window.cpp

+ 0
- 1
dgl/Widget.hpp View File

@@ -75,7 +75,6 @@ protected:
virtual bool onScroll(int x, int y, float dx, float dy); virtual bool onScroll(int x, int y, float dx, float dy);
virtual bool onSpecial(bool press, Key key); virtual bool onSpecial(bool press, Key key);
virtual void onReshape(int width, int height); virtual void onReshape(int width, int height);
virtual void onClose();


private: private:
Window& fParent; Window& fParent;


+ 6
- 0
dgl/Window.hpp View File

@@ -65,6 +65,12 @@ public:
void addIdleCallback(IdleCallback* const callback); void addIdleCallback(IdleCallback* const callback);
void removeIdleCallback(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: private:
struct PrivateData; struct PrivateData;
PrivateData* const pData; PrivateData* const pData;


+ 1
- 13
dgl/src/Widget.cpp View File

@@ -207,19 +207,7 @@ bool Widget::onSpecial(bool, Key)
return false; 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)
{ {
} }




+ 36
- 11
dgl/src/Window.cpp View File

@@ -575,10 +575,7 @@ struct Window::PrivateData {


void onDisplay() void onDisplay()
{ {
//DBG("PUGL: onDisplay\n");

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
fSelf->onDisplayBefore();


FOR_EACH_WIDGET(it) FOR_EACH_WIDGET(it)
{ {
@@ -587,6 +584,8 @@ struct Window::PrivateData {
if (widget->isVisible()) if (widget->isVisible())
widget->onDisplay(); widget->onDisplay();
} }

fSelf->onDisplayAfter();
} }


void onKeyboard(const bool press, const uint key) void onKeyboard(const bool press, const uint key)
@@ -658,7 +657,7 @@ struct Window::PrivateData {
DBGp("PUGL: onSpecial : %i %i\n", press, key); DBGp("PUGL: onSpecial : %i %i\n", press, key);


if (fModal.childFocus != nullptr) if (fModal.childFocus != nullptr)
return;
return fModal.childFocus->focus();


FOR_EACH_WIDGET_INV(rit) FOR_EACH_WIDGET_INV(rit)
{ {
@@ -673,6 +672,8 @@ struct Window::PrivateData {
{ {
DBGp("PUGL: onReshape : %i %i\n", width, height); DBGp("PUGL: onReshape : %i %i\n", width, height);


fSelf->onReshape(width, height);

FOR_EACH_WIDGET(it) FOR_EACH_WIDGET(it)
{ {
Widget* const widget(*it); Widget* const widget(*it);
@@ -687,15 +688,11 @@ struct Window::PrivateData {
if (fModal.enabled && fModal.parent != nullptr) if (fModal.enabled && fModal.parent != nullptr)
exec_fini(); exec_fini();


fSelf->onClose();

if (fModal.childFocus != nullptr) if (fModal.childFocus != nullptr)
fModal.childFocus->onClose(); fModal.childFocus->onClose();


FOR_EACH_WIDGET(it)
{
Widget* const widget(*it);
widget->onClose();
}

close(); 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 END_NAMESPACE_DGL


#undef DBG #undef DBG


Loading…
Cancel
Save