Skip to content

Commit

Permalink
null checking and comment at Traverse widget
Browse files Browse the repository at this point in the history
  • Loading branch information
PJensen committed Mar 20, 2013
1 parent 9d55264 commit 3af18ab
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/DotNetHack.GUI/Widget.cs
Expand Up @@ -103,6 +103,8 @@ public Widget(int x, int y, int width, int height, Widget parent = null)

/// <summary>
/// Traverse widgets given a root widget
/// - The widget location is temporarily shifted relative to the parent widget.
/// - The predicate if passed is used otherwise skipped.
/// </summary>
/// <param name="action">the action to take for each</param>
/// <param name="root">the root widget to start at</param>
Expand All @@ -118,13 +120,19 @@ internal static void Traverse(Action<Widget> action, Widget root, Predicate<Widg
{
lock (w)
{
w.Location.X += w.Parent.Location.X;
w.Location.Y += w.Parent.Location.Y;
if (w.Parent != null)
{
w.Location.X += w.Parent.Location.X;
w.Location.Y += w.Parent.Location.Y;
}

action(w);

w.Location.X -= w.Parent.Location.X;
w.Location.Y -= w.Parent.Location.Y;
if (w.Parent != null)
{
w.Location.X -= w.Parent.Location.X;
w.Location.Y -= w.Parent.Location.Y;
}
}
}

Expand Down

0 comments on commit 3af18ab

Please sign in to comment.