Dock 下窗口化 opengl 游戏中的双光标
我在 opengl 中创建了游戏,但在窗口模式下双光标(我的和系统)有问题。 我隐藏系统光标并在游戏中仅使用我的光标。
当窗口位于停靠栏下方并且我将光标移动到停靠栏上(光标仍在窗口内)时,会显示系统光标。从这一刻起,我有了双光标(我的和系统)。
我尝试了三种解决方案:
- 当光标结束时和光标离开停靠区时使用事件,但我没有找到这样的事件:(
- 当系统光标取消隐藏或隐藏时使用事件,但我也没有找到这样的事件:(
- 获取有关隐藏光标计数的信息。当我使“CGDisplayHideCursor”隐藏光标计数递减时,当光标在停靠栏上取消隐藏时,我不知道,因为我没有任何事件,但我可以检查计时器是否应该。是隐藏,这样我就可以隐藏它,但通过这种方式,我将多次隐藏光标,所以我不知道光标隐藏计数,并且我没有正确取消隐藏:(
也许这应该以完全不同的方式解决。
I created game in opengl and i have problem with double cursor (my and system) in windowed mode.
I hide system cursor and use only my cursor in game.
When window is under dock and i move cursor over dock (cursor is still inside window) system cursor is shown. From this moment i have double cursor (my and system).
I try three solutions:
- Use events when cursor is over and when cursor is out dock, but i didn't find such events :(
- Use events when system cursor is unhide or hide, but i didn't find such events, too :(
- Get information about hide cursor count. When i make "CGDisplayHideCursor" hide cursor count is decrement. When cursor is unhide over dock i don't know about it because i havn't any event, but i could check in my timer if cursor should be hide so i could hide it, but in this way i will have many times hide cursor, so i don't know about cursor hide count and i don't make correctly unhide :(
Maybe this should be solved in completely different way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试以下任何操作:
这不是严格意义上的编程问题,而是可用性问题。您应该决定希望用户做什么并实施它。我相信在窗口模式下不显示游戏光标是可以的(除非您正在编写例如需要许多不同光标的策略游戏)。
you could try any of the following:
This is not strictly a programming problem, but a usability problem. You should decide what you want the user to do and implement that. I believe it is ok to not display game cursor in windowed mode (unless you are writing e.g. a strategy game where you need many different cursors).
解决方案是设置一个光标矩形,用透明光标覆盖整个窗口,而不是使用 CGDisplayHideCursor(其神秘的不可读隐藏计数)。这非常强大 - 当鼠标位于窗口内时它可靠地隐藏光标并在所有其他时间显示它。
我最终通过查看 Simple DirectMedia Layer (SDL) 2 源代码弄清楚了这一点 - 这是从那里提取的一个工作最小示例。
在你的 NSView 子类实现中重写 resetCursorRects :
Instead of dorking with CGDisplayHideCursor, with its mysterious unreadable hide count, the solution is to set up a cursor rect covering your whole window with a transparent cursor. This is really robust - it reliably hides the cursor when the mouse is inside the window and shows it at all other times.
I eventually figured this out by looking at the Simple DirectMedia Layer (SDL) 2 source code - here is a working minimal example extracted from there.
Override resetCursorRects in your NSView subclass implementation: