【问题标题】:NSApplication sendEvent does not return while in live reziseNSApplication sendEvent 在实时调整大小时不返回
【发布时间】:2014-07-11 22:30:13
【问题描述】:

我在 c++(opengl 游戏)中有一个轮询主循环,使用 objC 中的代码进行输入和处理 mac 细节。 我想在调整大小操作期间继续进行绘图,但我的轮询在“sendEvent”中停止以获取鼠标左键消息,并且在释放鼠标和调整大小完成之前不会退出,并且不进行重绘。

[每个主循环运行一次]

int FsPollDeviceC()
{
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   while(1)
   {
      [pool release];
      pool = [[NSAutoreleasePool alloc] init];
      NSEvent *event;
      event = [NSApp
      nextEventMatchingMask:NSAnyEventMask
      untilDate: [NSDate distantPast]
      inMode: NSDefaultRunLoopMode
      dequeue:YES];
      if(event!=nil)
      {
         [NSApp sendEvent:event];
         [NSApp updateWindows];
      }
      else
      {
         break;
      }
   }
   [pool release];
   return windowclosed==0 ? 1 : 0;
} 

代码https://sourceforge.net/p/galaxyv2/code/HEAD/tree/ext_include/mac/fsmacosxwrapper.m [第 1147 行] 基于 FsSimpleWindow (http://ysflight.in.coocan.jp/programming/fssimplewindow/e.html) 但已扩展。

整个项目源码在https://sourceforge.net/projects/galaxyv2/files/galaxyv2/galaxyv2_1.81/

【问题讨论】:

    标签: macos opengl resize draw polling


    【解决方案1】:

    我能够通过重绘回调回到 c 代码来实现这一点

    @implementation YsOpenGLView
    -(void) drawRect: (NSRect) bounds
    

    在调整大小期间每次更改大小时都会调用此函数(按下鼠标按钮时,正常的轮询操作会停止)。

    完整代码可以在http://sourceforge.net/projects/galaxyv2/files/galaxyv2/galaxyv2_1.82/galaxyv2_1.82_src.zip/download找到

    对于实施: fsmacosxwrapper.m fsmacosxwrappercpp.cpp fssimplewindow.h

    用法: Galaxy.cpp@1202 和 @1270

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-28
      • 1970-01-01
      • 2012-07-14
      • 1970-01-01
      • 1970-01-01
      • 2016-09-14
      • 1970-01-01
      相关资源
      最近更新 更多