最佳实践:2D HUD 屏幕导航的设计模式
如果您有一个完全用于 2D 绘图的 GUI 应用程序,那么处理绘制内容和触摸位置的最佳实践应该是什么?
一个更好理解的例子:
我有一个带地图的游戏。在这张地图上我可以建造房屋和其他东西。
我还有一个可以扩展的信息栏。在扩展栏上我画了一些有关游戏的信息,它还提供了更改不同值的界面。如果发生触摸,我必须检查信息栏是否扩展,以确定是否要更改地图上的某些内容或信息栏上的某些内容。
这是由状态模式完成的,但我怀疑这是否正确,因为我认为由于可能存在“子状态”,它可能有点复杂。
所以基本上问题是:状态模式(来自 GoF)是处理纯图形 GUI 的最佳实践吗?
If you have an application with a GUI totally working on 2D drawing, what should be the best practice to handle what to draw and where to touch?
An example for better understanding:
I have a game with a map. On this map I can build houses and stuff.
I also have an information bar which can be extended. On the extended bar I draw some information about the game and it also offers the interface to change different values. If a touch occurs, I have to check if the information bar is extended or not, to determine if I want to change something on the map or something on the bar.
That's done by the State Pattern, but I have some doubt if that's the right one because I think it can be a bit complex because of possible "sub-states".
So basically the question: Is the State Pattern (from GoF) the best practice to handle a pure graphical GUI?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常的工作方式是 UI 是 Control 对象的树。每个控件都有一些边界框,并且可能有许多浮动在其上方的子控件。当单击发生时,树会从上到下遍历(这意味着孩子在父母之前,兄弟姐妹按顺序)。对于每个控件,您可以查看该点是否与其边界框相交。如果是这样,请给控件一个处理点击的机会(即一些虚拟的
OnClick
方法)。如果是,则停止处理,单击完成。否则,请继续行走,直到找到可以处理该问题的控件。The way this typically works is that the UI is a tree of Control objects. Each Control has some bounding box, and potentially a number of child controls which float above it. When a click occurs, the tree is walked from top-down (which means children before parents, and siblings in order). For each control, you see if the point intersects its bounding box. If so, give the control a chance to handle the click (i.e. some virtual
OnClick
method). If it does, stop processing, that click is done. Otherwise, keep walking until you get to a control that does handle it.