diff --git a/DepthsBelow/DepthsBelow/GUI/Frame.cs b/DepthsBelow/DepthsBelow/GUI/Frame.cs
index 9c0e47e..843b49f 100755
--- a/DepthsBelow/DepthsBelow/GUI/Frame.cs
+++ b/DepthsBelow/DepthsBelow/GUI/Frame.cs
@@ -138,6 +138,13 @@ namespace DepthsBelow.GUI
///
public event OnClickHandler OnClick;
///
+ /// Gets the number of subscribers to the event.
+ ///
+ public int OnClickCount
+ {
+ get { return (OnClick != null) ? OnClick.GetInvocationList().Length : 0; }
+ }
+ ///
/// event arguments.
///
public class OnClickArgs : EventArgs
diff --git a/DepthsBelow/DepthsBelow/GUIManager.cs b/DepthsBelow/DepthsBelow/GUIManager.cs
index c95de15..b5cfe48 100755
--- a/DepthsBelow/DepthsBelow/GUIManager.cs
+++ b/DepthsBelow/DepthsBelow/GUIManager.cs
@@ -29,14 +29,9 @@ namespace DepthsBelow
{
var clickRectangle = new Rectangle(position.X, position.Y, 1, 1);
- var intersections = new List();
-
- foreach (var frame in Frames)
- {
- if (clickRectangle.Intersects(frame.AbsoluteRectangle))
- intersections.Add(frame);
- }
-
+ // Create a list of all frames which have an OnClick handler and intersects with the click position
+ var intersections = Frames.Where(frame => frame.OnClickCount > 0).Where(frame => clickRectangle.Intersects(frame.AbsoluteRectangle)).ToList();
+ // Get the topmost frame of that list
var topFrame = GetTopFrame(intersections);
if (topFrame != null)