線でカスタムカーソルを描画するポップアップウィンドウの一部があります。したがって、標準のカーソルを特定の領域 (isInDiagram) 内に表示したくありません。
これは私のコードです:
- (void)mouseMoved:(NSEvent *)theEvent {
position = [self convertPoint:[theEvent locationInWindow] fromView:nil];
if(![self isInDiagram:position]) {
[NSCursor unhide];
}
else{
[NSCursor hide];
}
[self setNeedsDisplay: YES];
}
- (bool) isInDiagram: (NSPoint) p {
return (p.x >= bborder.x + inset) && (p.y >= bborder.y + inset) &&
(p.x <= self.window.frame.size.width - bborder.x - inset) &&
(p.y <= self.window.frame.size.height - bborder.y - inset);
}
現在、カーソルの非表示は完全に正常に機能しますが、非表示の再表示は常に遅れます。最終的にカーソルが再び表示される原因がわかりませんでした。ただし、unhide コマンドをループすると、非表示が機能します。
for (int i = 0; i<100; i++) {
[NSCursor unhide];
}
この醜いループを使わずにこの問題を解決する方法はありますか?