Skip to content

Commit

Permalink
libdeng2|Widgets: Root widget keeps track of the focus widget
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 23, 2013
1 parent c698657 commit c5c5e3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 13 additions & 0 deletions doomsday/libdeng2/include/de/widgets/rootwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ class RootWidget : public Widget
*/
virtual void setViewSize(Vector2i const &viewSize);

/**
* Sets the focus widget. It is the first widget to be offered input
* events.
*
* @param widget Widget to have focus. Set to @c NULL to clear focus.
*/
void setFocus(Widget *widget);

/**
* Returns the current focus widget.
*/
Widget *focus() const;

void initialize();
void draw();

Expand Down
13 changes: 12 additions & 1 deletion doomsday/libdeng2/src/widgets/rootwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ namespace de {
struct RootWidget::Instance
{
RectangleRule *viewRect;
Widget *focus;

Instance()
Instance() : focus(0)
{
viewRect = new RectangleRule(
refless(new ConstantRule(0)),
Expand Down Expand Up @@ -90,6 +91,16 @@ void RootWidget::setViewSize(Vector2i const &size)
notifyTree(&Widget::viewResized);
}

void RootWidget::setFocus(Widget *widget)
{
d->focus = widget;
}

Widget *RootWidget::focus() const
{
return d->focus;
}

Rule const *RootWidget::viewWidth() const
{
return d->viewRect->right();
Expand Down

0 comments on commit c5c5e3e

Please sign in to comment.