Skip to content
Browse files

add Container::GetWidgetAt and implement GetWidgetAtAbsolute in terms…

… of it

This avoids walking both ways through the tree with its attendant quadratic
growth characteristics (not that we'd ever notice with the depths of tree
that we'll be dealing with).
  • Loading branch information...
1 parent a7636a4 commit 217ed2447c0aeaad1d56c058579e8f1c0659c5ad @johnbartholomew johnbartholomew committed Sep 27, 2012
Showing with 15 additions and 13 deletions.
  1. +8 −8 src/ui/Container.cpp
  2. +2 −1 src/ui/Container.h
  3. +4 −3 src/ui/Context.cpp
  4. +1 −1 src/ui/Context.h
View
16 src/ui/Container.cpp
@@ -80,18 +80,18 @@ void Container::SetWidgetDimensions(Widget *widget, const Point &position, const
widget->SetDimensions(position, size);
}
-Widget *Container::GetWidgetAtAbsolute(const Point &pos)
+Widget *Container::GetWidgetAt(const Point &pos)
{
- if (!ContainsAbsolute(pos)) return 0;
+ if (!Contains(pos)) return 0;
for (WidgetIterator i = WidgetsBegin(); i != WidgetsEnd(); ++i) {
Widget *widget = (*i).Get();
- if (widget->ContainsAbsolute(pos)) {
- if (widget->IsContainer())
- return static_cast<Container*>(widget)->GetWidgetAtAbsolute(pos);
- else
- return widget;
- }
+ const Point relpos = pos - widget->GetPosition() - widget->GetDrawOffset();
+ if (widget->IsContainer()) {
+ Widget* w = static_cast<Container*>(widget)->GetWidgetAt(relpos);
+ if (w) return w;
+ } else if (widget->Contains(relpos))
+ return widget;
}
return this;
View
3 src/ui/Container.h
@@ -32,7 +32,8 @@ class Container: public Widget {
virtual bool IsContainer() const { return true; }
- virtual Widget *GetWidgetAtAbsolute(const Point &pos);
+ Widget *GetWidgetAtAbsolute(const Point &pos) { return GetWidgetAt(pos - GetAbsolutePosition()); }
+ virtual Widget *GetWidgetAt(const Point &pos);
typedef std::vector< RefCountedPtr<Widget> >::const_iterator WidgetIterator;
const WidgetIterator WidgetsBegin() const { return m_widgets.begin(); }
View
7 src/ui/Context.cpp
@@ -39,10 +39,11 @@ Context::~Context() {
m_float->Detach();
}
-Widget *Context::GetWidgetAtAbsolute(const Point &pos) {
- Widget *w = m_float->GetWidgetAtAbsolute(pos);
+Widget *Context::GetWidgetAt(const Point &pos)
+{
+ Widget *w = m_float->GetWidgetAt(pos);
if (!w || w == m_float.Get())
- w = Single::GetWidgetAtAbsolute(pos);
+ w = Single::GetWidgetAt(pos);
return w;
}
View
2 src/ui/Context.h
@@ -94,7 +94,7 @@ class Context : public Single {
Context *RemoveFloatingWidget(Widget *w) { m_float->RemoveWidget(w); return this; }
// considers floating widgets also
- virtual Widget *GetWidgetAtAbsolute(const Point &pos);
+ virtual Widget *GetWidgetAt(const Point &pos);
// event dispatch delegates
bool Dispatch(const Event &event) { return m_eventDispatcher.Dispatch(event); }

0 comments on commit 217ed24

Please sign in to comment.
Something went wrong with that request. Please try again.