Dock 下窗口化 opengl 游戏中的双光标

发布于 2024-11-18 13:50:08 字数 437 浏览 1 评论 0原文

我在 opengl 中创建了游戏,但在窗口模式下双光标(我的和系统)有问题。 我隐藏系统光标并在游戏中仅使用我的光标。

当窗口位于停靠栏下方并且我将光标移动到停靠栏上(光标仍在窗口内)时,会显示系统光标。从这一刻起,我有了双光标(我的和系统)。

我尝试了三种解决方案:

  1. 当光标结束时和光标离开停靠区时使用事件,但我没有找到这样的事件:(
  2. 当系统光标取消隐藏或隐藏时使用事件,但我也没有找到这样的事件:(
  3. 获取有关隐藏光标计数的信息。当我使“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:

  1. Use events when cursor is over and when cursor is out dock, but i didn't find such events :(
  2. Use events when system cursor is unhide or hide, but i didn't find such events, too :(
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再让梦枯萎 2024-11-25 13:50:08

您可以尝试以下任何操作:

  • 不要在窗口模式下显示游戏光标(尽管这可能不适合您的游戏)
  • 将游戏窗口置于最顶层,使其位于扩展坞上方(不确定在 Mac 上是否可行
  • )不允许您的游戏窗口在扩展坞下渲染任何内容,因此用户不需要单击那里(或者首先不允许您的游戏窗口位于扩展坞下)
  • 使用计时器轮询光标屏幕坐标以确定是否光标是否位于停靠点上

这不是严格意义上的编程问题,而是可用性问题。您应该决定希望用户做什么并实施它。我相信在窗口模式下不显示游戏光标是可以的(除非您正在编写例如需要许多不同光标的策略游戏)。

you could try any of the following:

  • Do not display game cursor in windowed mode (although that might not be ok for your game)
  • Make the game window top-most so it is above the dock (not sure it is possible on mac)
  • Do not allow your game window to render anything under the dock, so the user does not need to click there (or do not allow your game window to be positioned under the dock in the first place)
  • Use timer to poll cursor screen coordinates to determine whether the cursor is over dock or not

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).

寂寞笑我太脆弱 2024-11-25 13:50:08

解决方案是设置一个光标矩形,用透明光标覆盖整个窗口,而不是使用 CGDisplayHideCursor(其神秘的不可读隐藏计数)。这非常强大 - 当鼠标位于窗口内时它可靠地隐藏光标并在所有其他时间显示它。

我最终通过查看 Simple DirectMedia Layer (SDL) 2 源代码弄清楚了这一点 - 这是从那里提取的一个工作最小示例。

在你的 NSView 子类实现中重写 resetCursorRects :

static NSCursor* invisibleCursor()
{
    static NSCursor *invisibleCursor = NULL;
    if (!invisibleCursor) {
        /* RAW 16x16 transparent GIF */
        static unsigned char cursorBytes[] = {
            0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
            0x01, 0x00, 0x00, 0x01, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x10,
            0x00, 0x10, 0x00, 0x00, 0x02, 0x0E, 0x8C, 0x8F, 0xA9, 0xCB, 0xED,
            0x0F, 0xA3, 0x9C, 0xB4, 0xDA, 0x8B, 0xB3, 0x3E, 0x05, 0x00, 0x3B
        };

        NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0]
                                                  length:sizeof(cursorBytes)
                                            freeWhenDone:NO];
        NSImage *cursorImage = [[[NSImage alloc] initWithData:cursorData] autorelease];
        invisibleCursor = [[NSCursor alloc] initWithImage:cursorImage
                                                  hotSpot:NSZeroPoint];
    }

    return invisibleCursor;
}

- (void)resetCursorRects
{
    [super resetCursorRects];

    [self addCursorRect:[self bounds] cursor:invisibleCursor()];
}

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:

static NSCursor* invisibleCursor()
{
    static NSCursor *invisibleCursor = NULL;
    if (!invisibleCursor) {
        /* RAW 16x16 transparent GIF */
        static unsigned char cursorBytes[] = {
            0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
            0x01, 0x00, 0x00, 0x01, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x10,
            0x00, 0x10, 0x00, 0x00, 0x02, 0x0E, 0x8C, 0x8F, 0xA9, 0xCB, 0xED,
            0x0F, 0xA3, 0x9C, 0xB4, 0xDA, 0x8B, 0xB3, 0x3E, 0x05, 0x00, 0x3B
        };

        NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0]
                                                  length:sizeof(cursorBytes)
                                            freeWhenDone:NO];
        NSImage *cursorImage = [[[NSImage alloc] initWithData:cursorData] autorelease];
        invisibleCursor = [[NSCursor alloc] initWithImage:cursorImage
                                                  hotSpot:NSZeroPoint];
    }

    return invisibleCursor;
}

- (void)resetCursorRects
{
    [super resetCursorRects];

    [self addCursorRect:[self bounds] cursor:invisibleCursor()];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文