Events bubble down the frame stack until it finds a frame with a handler.
For example, this allows you to have an OnClick handler on a parent frame, and child frames who cover the parent frame, but the parent frame still receives the click events (unless the child subscribes to the event).
This commit is contained in:
@@ -138,6 +138,13 @@ namespace DepthsBelow.GUI
|
||||
/// </summary>
|
||||
public event OnClickHandler OnClick;
|
||||
/// <summary>
|
||||
/// Gets the number of subscribers to the <see cref="OnClickHandler" /> event.
|
||||
/// </summary>
|
||||
public int OnClickCount
|
||||
{
|
||||
get { return (OnClick != null) ? OnClick.GetInvocationList().Length : 0; }
|
||||
}
|
||||
/// <summary>
|
||||
/// <see cref="OnClickHandler" /> event arguments.
|
||||
/// </summary>
|
||||
public class OnClickArgs : EventArgs
|
||||
|
||||
@@ -29,14 +29,9 @@ namespace DepthsBelow
|
||||
{
|
||||
var clickRectangle = new Rectangle(position.X, position.Y, 1, 1);
|
||||
|
||||
var intersections = new List<Frame>();
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user