Skip to content

Commit

Permalink
UI|Client|PopupWidget: Added method for setting anchor and opening di…
Browse files Browse the repository at this point in the history
…rection

Sets the anchor to the appropriate side of a rule rectangle.
  • Loading branch information
skyjake committed Aug 17, 2013
1 parent 078e767 commit 1cfbd4b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/widgets/popupwidget.h
Expand Up @@ -48,6 +48,8 @@ class PopupWidget : public GuiWidget

GuiWidget &content() const;

void setAnchorAndOpeningDirection(de::RuleRectangle const &rule, ui::Direction dir);

void setAnchor(de::Vector2i const &pos);
void setAnchorX(int xPos);
void setAnchorY(int yPos);
Expand Down
22 changes: 3 additions & 19 deletions doomsday/client/src/ui/widgets/menuwidget.cpp
Expand Up @@ -37,9 +37,9 @@ public ContextWidgetOrganizer::IWidgetFactory
/**
* Action owned by the button that represents a SubmenuItem.
*/
struct SubmenuAction : public de::Action,
DENG2_OBSERVES(Widget, Deletion)
class SubmenuAction : public de::Action, DENG2_OBSERVES(Widget, Deletion)
{
public:
SubmenuAction(Instance *inst, ui::SubmenuItem const &parentItem)
: d(inst), _submenu(parentItem)
{
Expand Down Expand Up @@ -75,23 +75,7 @@ public ContextWidgetOrganizer::IWidgetFactory
GuiWidget *parent = d->organizer.itemWidget(_submenu);
DENG2_ASSERT(parent != 0);

// Update the anchor of the submenu.
ui::Direction const dir = _submenu.openingDirection();
if(dir == ui::Left || dir == ui::Right)
{
_widget->setAnchorY(parent->hitRule().top() + parent->hitRule().height() / 2);

_widget->setAnchorX(dir == ui::Left? parent->hitRule().left() :
parent->hitRule().right());
}
else if(dir == ui::Up || dir == ui::Down)
{
_widget->setAnchorX(parent->hitRule().left() + parent->hitRule().width() / 2);

_widget->setAnchorY(dir == ui::Up? parent->hitRule().top() :
parent->hitRule().bottom());
}
_widget->setOpeningDirection(dir);
_widget->setAnchorAndOpeningDirection(parent->hitRule(), _submenu.openingDirection());

d->openPopups.insert(_widget);
_widget->audienceForClose += d;
Expand Down
16 changes: 16 additions & 0 deletions doomsday/client/src/ui/widgets/popupwidget.cpp
Expand Up @@ -239,6 +239,22 @@ GuiWidget &PopupWidget::content() const
return *d->content;
}

void PopupWidget::setAnchorAndOpeningDirection(RuleRectangle const &rule, ui::Direction dir)
{
if(dir == ui::Left || dir == ui::Right)
{
setAnchorY(rule.top() + rule.height() / 2);
setAnchorX(dir == ui::Left? rule.left() : rule.right());
}
else if(dir == ui::Up || dir == ui::Down)
{
setAnchorX(rule.left() + rule.width() / 2);
setAnchorY(dir == ui::Up? rule.top() : rule.bottom());
}

setOpeningDirection(dir);
}

void PopupWidget::setAnchor(Vector2i const &pos)
{
setAnchor(Const(pos.x), Const(pos.y));
Expand Down

0 comments on commit 1cfbd4b

Please sign in to comment.