Skip to content

Commit

Permalink
Fixed|UI|Client: Initial viewResized event to mewly added children
Browse files Browse the repository at this point in the history
Hitherto widgets have received a viewResized event only when the
actual Canvas size has changed. This has only accidentally worked
correctly because most widgets are present before the window is
ready for GL drawing.

Now widgets get sent viewResized whenever they become part of the
widget tree.
  • Loading branch information
skyjake committed Aug 31, 2013
1 parent f5c9e2c commit 5e64739
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
14 changes: 12 additions & 2 deletions doomsday/client/src/ui/framework/guirootwidget.cpp
Expand Up @@ -30,7 +30,8 @@

using namespace de;

DENG2_PIMPL(GuiRootWidget)
DENG2_PIMPL(GuiRootWidget),
DENG2_OBSERVES(Widget, ChildAddition)
{
ClientWindow *window;
QScopedPointer<AtlasTexture> atlas; ///< Shared atlas for most UI graphics/text.
Expand All @@ -49,7 +50,9 @@ DENG2_PIMPL(GuiRootWidget)
atlas(0),
uTexAtlas("uTex", GLUniform::Sampler2D),
noFramesDrawnYet(true)
{}
{
self.audienceForChildAddition += this;
}

~Instance()
{
Expand Down Expand Up @@ -166,6 +169,13 @@ DENG2_PIMPL(GuiRootWidget)
}
}
}

void widgetChildAdded(Widget &child)
{
// Make sure newly added children know the view size.
child.viewResized();
child.notifyTree(&Widget::viewResized);
}
};

GuiRootWidget::GuiRootWidget(ClientWindow *window)
Expand Down
12 changes: 12 additions & 0 deletions doomsday/client/src/ui/framework/guiwidget.cpp
Expand Up @@ -29,6 +29,7 @@
using namespace de;

DENG2_PIMPL(GuiWidget),
DENG2_OBSERVES(Widget, ChildAddition),
DENG2_OBSERVES(ui::Margins, Change)
#ifdef DENG2_DEBUG
, DENG2_OBSERVES(Widget, ParentChange)
Expand Down Expand Up @@ -76,6 +77,7 @@ DENG2_OBSERVES(ui::Margins, Change)
uBlurStep ("uBlurStep", GLUniform::Vec2),
uBlurWindow ("uWindow", GLUniform::Vec4)
{
self.audienceForChildAddition += this;
margins.audienceForChange += this;

#ifdef DENG2_DEBUG
Expand Down Expand Up @@ -118,6 +120,16 @@ DENG2_OBSERVES(ui::Margins, Change)
}
#endif

void widgetChildAdded(Widget &child)
{
if(self.hasRoot())
{
// Make sure newly added children know the view size.
child.viewResized();
child.notifyTree(&Widget::viewResized);
}
}

void initBlur()
{
if(blurInited) return;
Expand Down
5 changes: 1 addition & 4 deletions doomsday/client/src/ui/widgets/dialogwidget.cpp
Expand Up @@ -490,10 +490,6 @@ void DialogWidget::prepare()

d->updateContentHeight();

// Make sure the newly added widget knows the view size.
viewResized();
notifyTree(&Widget::viewResized);

PopupWidget::open();
}

Expand All @@ -507,6 +503,7 @@ void DialogWidget::preparePopupForOpening()

void DialogWidget::finish(int)
{
root().setFocus(0);
close();
}

Expand Down
7 changes: 6 additions & 1 deletion doomsday/client/src/ui/widgets/legacywidget.cpp
Expand Up @@ -18,6 +18,7 @@

#include "de_platform.h"
#include "ui/widgets/legacywidget.h"
#include "clientapp.h"
#include "ui/dd_input.h"
#include "ui/ui_main.h"
#include "ui/ui2_main.h"
Expand Down Expand Up @@ -147,7 +148,11 @@ LegacyWidget::LegacyWidget(String const &name)

void LegacyWidget::viewResized()
{
if(BusyMode_Active() || isDisabled() || Sys_IsShuttingDown()) return;
if(BusyMode_Active() || isDisabled() || Sys_IsShuttingDown() ||
!ClientApp::windowSystem().hasMain())
{
return;
}

LOG_AS("LegacyWidget");
LOG_TRACE("View resized to ") << root().viewSize().asText();
Expand Down
19 changes: 13 additions & 6 deletions doomsday/client/src/ui/widgets/popupwidget.cpp
Expand Up @@ -201,7 +201,7 @@ DENG_GUI_PIMPL(PopupWidget)
}
};

PopupWidget::PopupWidget(String const &name) : d(new Instance(this))
PopupWidget::PopupWidget(String const &name) : GuiWidget(name), d(new Instance(this))
{
setBehavior(ChildHitClipping);

Expand Down Expand Up @@ -337,7 +337,8 @@ void PopupWidget::viewResized()

d->uMvpMatrix = root().projMatrix2D();

update();
requestGeometry();
//update();
}

void PopupWidget::update()
Expand Down Expand Up @@ -400,8 +401,11 @@ void PopupWidget::open()

// Reparent the popup into the root widget, on top of everything else.
d->realParent = Widget::parent();
d->realParent->remove(*this);
d->realParent->root().add(this);
if(d->realParent != &d->realParent->root())
{
d->realParent->remove(*this);
d->realParent->root().add(this);
}

unsetBehavior(DisableEventDispatchToChildren);

Expand Down Expand Up @@ -439,8 +443,11 @@ void PopupWidget::dismiss()
d->dismissTimer.stop();

// Move back to the original parent widget.
root().remove(*this);
d->realParent->add(this);
if(d->realParent != &root())
{
root().remove(*this);
d->realParent->add(this);
}

popupDismissed();

Expand Down
5 changes: 3 additions & 2 deletions doomsday/client/src/ui/widgets/sliderwidget.cpp
Expand Up @@ -459,9 +459,10 @@ bool SliderWidget::handleEvent(Event const &event)
d->updateHover(event.as<MouseEvent>().pos());
}

if(d->state != Instance::Inert && event.type() == Event::MouseButton)
// Left mouse button can be used to drag/step the value.
if(d->state != Instance::Inert)
{
switch(handleMouseClick(event))
switch(handleMouseClick(event, MouseEvent::Left))
{
case MouseClickStarted:
d->startGrab(event.as<MouseEvent>());
Expand Down

0 comments on commit 5e64739

Please sign in to comment.