Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Client|GuiWidget: Added virtual methods about child addition/removal
  • Loading branch information
skyjake committed Jun 20, 2013
1 parent a4627c0 commit bb90834
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
6 changes: 6 additions & 0 deletions doomsday/client/include/ui/widgets/guiwidget.h
Expand Up @@ -200,6 +200,12 @@ class GuiWidget : public QObject, public de::Widget
MouseClickStatus handleMouseClick(de::Event const &event);

protected:
virtual void addedChildWidget(Widget &widget) /*final*/;
virtual void removedChildWidget(Widget &widget) /*final*/;

virtual void addedChildWidget(GuiWidget &widget);
virtual void removedChildWidget(GuiWidget &widget);

/**
* Called by GuiWidget::update() the first time an update is being carried
* out. Native GL is guaranteed to be available at this time, so the widget
Expand Down
63 changes: 60 additions & 3 deletions doomsday/client/src/ui/widgets/guiwidget.cpp
Expand Up @@ -29,6 +29,9 @@
using namespace de;

DENG2_PIMPL(GuiWidget)
#ifdef DENG2_DEBUG
, DENG2_OBSERVES(Widget, ParentChange)
#endif
{
RuleRectangle rule;
Rectanglei savedPos;
Expand Down Expand Up @@ -70,14 +73,26 @@ DENG2_PIMPL(GuiWidget)
uBlurTex("uTex", GLUniform::Sampler2D),
uBlurStep("uBlurStep", GLUniform::Vec2),
uBlurWindow("uWindow", GLUniform::Vec4)
{}
{
#ifdef DENG2_DEBUG
self.audienceForParentChange += this;
rule.setDebugName(self.path());
#endif
}

~Instance()
{
{
// Deinitialize now if it hasn't been done already.
self.deinitialize();
}

#ifdef DENG2_DEBUG
void widgetParentChanged(Widget &, Widget *, Widget *)
{
rule.setDebugName(self.path());
}
#endif

void initBlur()
{
if(blurInited) return;
Expand Down Expand Up @@ -202,7 +217,9 @@ DENG2_PIMPL(GuiWidget)
};

GuiWidget::GuiWidget(String const &name) : Widget(name), d(new Instance(this))
{}
{
d->rule.setDebugName(name);
}

GuiRootWidget &GuiWidget::root()
{
Expand Down Expand Up @@ -404,6 +421,22 @@ bool GuiWidget::hitTest(Vector2i const &pos) const
// Can never be hit by anything.
return false;
}

Widget const *w = Widget::parent();
while(w)
{
GuiWidget const *gui = dynamic_cast<GuiWidget const *>(w);
if(gui)
{
if(gui->behavior().testFlag(ChildHitClipping) && !gui->hitTest(pos))
{
// Must hit clipped parent widgets as well.
return false;
}
}
w = w->Widget::parent();
}

return rule().recti().contains(pos);
}

Expand Down Expand Up @@ -443,6 +476,30 @@ GuiWidget::MouseClickStatus GuiWidget::handleMouseClick(Event const &event)
return MouseClickUnrelated;
}

void GuiWidget::addedChildWidget(Widget &widget)
{
GuiWidget *gw = dynamic_cast<GuiWidget *>(&widget);
if(gw)
{
addedChildWidget(*gw);
}
}

void GuiWidget::removedChildWidget(Widget &widget)
{
GuiWidget *gw = dynamic_cast<GuiWidget *>(&widget);
if(gw)
{
removedChildWidget(*gw);
}
}

void GuiWidget::addedChildWidget(GuiWidget &widget)
{}

void GuiWidget::removedChildWidget(GuiWidget &widget)
{}

void GuiWidget::glInit()
{}

Expand Down

0 comments on commit bb90834

Please sign in to comment.