Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8113661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:53:58+00:00 2026-06-06T02:53:58+00:00

I’m trying to reproduce the simple window interface objects in C# XNA like labels,

  • 0

I’m trying to reproduce the simple window interface objects in C# XNA like labels, listboxes, textboxes and panels. All objects consequentially derive from basic abstract class (XNAInterfaceObject) that draws an object and updates it. In update method it interacts with a mouse and keyboard and raises various events.
The problem is when two interface objects are one over another (e.g. popup context menu over listbox) and both have non-null events – the code fires both events, when I just need the event of the topmost object. How can I check which object is the topmost? Or make somehow the top object overlap the lower. I thought about global variable which would keep the reference for the last clicked object, and other objects would check if this variable is null to proceed with their events, but I think it is a rough solution and there exists far more elegant one.

Sorry for my language, I’m not a native English-speaker.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:54:01+00:00Added an answer on June 6, 2026 at 2:54 am

    I would probably break this issue down into two components:

    1. Determining the order of interface objects.
    2. Only triggering the events on the top-most object when there’s an overlap.

    Addressing part one is simple. Include a ‘layer’ field/property in the base class that specifies the depth of the object. In most game node classes I include this regardless, as it’s useful in drawing. You may want a separate layering system for interface ordering if things get a bit more complex, and the downside to this approach is that you can get overlaps in which the layers are the same.

    As @Attila has suggested, you can otherwise manage a Z-Ordered list of interface elements. In this case ordering is managed by index, and it’s easy to manage but you can’t also use this information for drawing without some additional processing and it won’t be as quick as a simple value comparison.

    Property

    public class InterfaceComponent
    {
        // Class members...
        private float layer;
        public float Layer { get { return layer; } set { layer = Math.Abs(value); } }
    
        public bool InFrontOf(InterfaceComponent other) { return this.Layer < other.Layer; }
    }
    

    Z-Ordered List

    public class InterfaceComponent
    {
        private static List<InterfaceComponent> zOrder = new List<InterfaceComponent>();
    
        // Class Members....
    
        public InterfaceComponent()
        {
            // Construct class...
            zOrder.Add(this);
        }
    
        private void SetZOrder(int order)
        {
            if (order < 0 || order >= zOrder.Count)
                return;
    
            zOrder.Remove(this);
            zOrder.Insert(order, this);
            // There are more efficient ways, but you get the idea.
        }
    
        public void SendBack() { SetZOrder(zOrder.indexOf(this) + 1); }
        public void SendToFront() { SetZOrder(0); }
        // etc...
    }
    

    Part Two
    There are multiple ways to approach part two. The most obvious is to run a check against all interface components for intersection and layer property, or in the case of a Z-Ordered list, all components higher up the list (approaching 0 in my example) for intersection.

    This can end up being pretty expensive, even if you use screens to make the list smaller. Instead you can manage a list of raised events and process them after you handle input. For example…

    public static class InterfaceEvents
    {
        public static List<EventData> List = new List<EventData>();
    
        public static void Resolve()
        {
            while (List.Count > 0)
            {
                for (int i = List.Count - 1; i > 0; i--)
                {
                    if (List[i].EventType == List[0].EventType && List[i].Sender.Intersects(List[0].Sender))
                    {
                        if (List[i].Sender.Layer < List[0].Layer) // However you choose to manage it.
                        {
                            List[0] = List[i];
                            List.RemoveAt(i);
                        }
                        else
                            List.RemoveAt(i);
                    }
                }
                // Toggle event from List[0]
                List.RemoveAt(0);
            }
        }
    }
    
    public struct EventData
    {
        public InterfaceComponent Sender;
        public int EventType;
    }
    

    Anyway, those are my thoughts. It’s pretty late at night, so I hope everything’s remained sensible and there are no glaring mistakes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.