如何在GUI中处理重叠的鼠标输入? [英] How to handle overlapping mouse input in GUI?

查看:66
本文介绍了如何在GUI中处理重叠的鼠标输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个GUI系统。如果它还有一个面板,我们如何处理前面板的输入?我的意思是,如果我点击前面板,鼠标输入也会影响下面板。我怎么能避免呢?我们在网上搜索了这个问题。例如,z索引系统或分层系统。但他们并没有很好地结束。关于它没有太多资源。

We are developing a GUI system. How can we handle the input of front panel, if it has also a panel under it? I mean, if i click on the front panel, the mouse input also effects on the lower panel. How can i avoid it? We searched that problem on the net. For example, z-indexing systems or layering systems. But they are not ended up well. There are not much resources about it.

推荐答案

对于迟到的答案很抱歉,但我希望我仍然可以提供帮助。我有自己的小GUI和3D引擎项目,但是当他们放弃XNA并希望拥有Windows 8的所有内容时告别Mickeysoft。



没有一般回答你的问题。这在很大程度上取决于您的UI的工作方式以及您实现的用于存储UI当前状态的结构类型。如果UI的元素可以重叠,那么您将必须建立一些方法来确定元素的Z顺序,并在需要时将它们移动到背面或前面。



我的UI元素是控件。控件始终具有父级,并且本身可以是任意数量的子控件的父级。孩子们被夹在父母的空间里。在父母框架之外的任何孩子(或其中的一部分)将不会被呈现或被认为接受任何类型的输入。



UI的根对象是一个始终存在并占据整个屏幕空间的不可见控件。这是没有父母的唯一控制。任何表单或布局都必须是此根控件的子级。控件本身不包含任何Z顺序信息。



处理鼠标输入时,我只是走过树并测试鼠标位置与控件的边界。如果一个控件被击中,那么我会进入其子项列表,看看是否有更好的适合度。到目前为止,Z顺序只是由我的控制树的结构定义。如果我得到的结果不多,那就完成了工作。



为了处理重叠控制,我只需要一个约定: list(保存在父级中)确定了他们的Z顺序。第一个将在后面,最后的那个将在前面。改变控件的Z位置只需要在列表的开头或结尾重新定位它。



这样我就可以轻松地通过它来绘制它们从前到后的列表。鼠标输入的命中测试在第一次结果时不再停止。它必须覆盖整个对象树。如果有多个结果,后一个会在第一个结果前面呈现,所以最后的结果总是我想要的。



我希望这对你有所帮助。选择一个好的数据结构并使用它的属性可以替代显式实现。
Sorry for the late answer, but I hope I can still help. I had my own little GUI and 3D engine project going, but said goodbye to Mickeysoft when they abandoned XNA and wanted to have everything the Windows 8 way.

There is no general answer to your question. It depends very much on how your UI works and what kind of structures you have implemented to store the current state of the UI. If the elements of your UI can overlap, then you will have to establish some way to determine the Z-Order of the elements and move them to the back or to the front when needed.

The elements of my UI were controls. A control always had a parent and could itself be parent to any number of child controls. The children were clipped to the space of their parents. Any child (or part of it) outside the frame of the parent would not be rendered or considered to receive any kind of input.

The root object of the UI was an invisible control that was always present and occupied the entire screen space. It was the only control without a parent. Any forms or layouts would have to be children of this root control. The controls themselves did not contain any Z-order information.

When processing mouse input, I simply walked the tree and tested the mouse position against the boundaries of the controls. If a control was 'hit', then I followed down into the list of its children to see if there was an even better fit. Up to here the Z-order was simply defined by the structure of my control tree. The work was done if I got no more than a single result.

To deal with overlapping controls, I needed only one more convention: The order of the children in the list (which was kept in the parent) determined their Z-order. The first ones would be in the back, the ones at the end would be in the front. Changing the Z-position of a control became simply a matter of repositioning it at the beginning or end of the list.

This way I could easily draw them by going through the list from the front to the back. The hit test for mouse input could not stop anymore at the first result. It had to cover the entire object tree. If there was more than one result, the later one would be rendered in front of the first one, so the last result would always be what I was looking for.

I hope this helped you a little. Choosing a good data structure and using its properties can be an alternative to explicit implementations.


这篇关于如何在GUI中处理重叠的鼠标输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆