mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-25 05:31:00 +00:00
Custom cursor in OS native backend without global variable
This commit is contained in:
parent
51afe8a541
commit
e3f92db395
1 changed files with 27 additions and 15 deletions
|
@ -93,8 +93,6 @@ namespace
|
||||||
|
|
||||||
const NSUInteger STYLE_MASK_FULLSCREEN = NSBorderlessWindowMask;
|
const NSUInteger STYLE_MASK_FULLSCREEN = NSBorderlessWindowMask;
|
||||||
const NSUInteger STYLE_MASK_WINDOWED = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
|
const NSUInteger STYLE_MASK_WINDOWED = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
|
||||||
|
|
||||||
NSCursor* s_cursor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -125,10 +123,13 @@ namespace
|
||||||
|
|
||||||
@interface CocoaView : NSOpenGLView
|
@interface CocoaView : NSOpenGLView
|
||||||
{
|
{
|
||||||
|
NSCursor* m_cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetCursorRects;
|
- (void)resetCursorRects;
|
||||||
|
|
||||||
|
- (void)setCursor:(NSCursor*)cursor;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,8 +138,18 @@ namespace
|
||||||
- (void)resetCursorRects
|
- (void)resetCursorRects
|
||||||
{
|
{
|
||||||
[super resetCursorRects];
|
[super resetCursorRects];
|
||||||
[self addCursorRect: [self bounds]
|
|
||||||
cursor: s_cursor];
|
NSCursor* const cursor = nil == m_cursor
|
||||||
|
? [NSCursor arrowCursor]
|
||||||
|
: m_cursor;
|
||||||
|
|
||||||
|
[self addCursorRect:[self bounds]
|
||||||
|
cursor:cursor];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setCursor:(NSCursor*)cursor
|
||||||
|
{
|
||||||
|
m_cursor = cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -163,7 +174,7 @@ public:
|
||||||
|
|
||||||
static bool IsFullscreen();
|
static bool IsFullscreen();
|
||||||
static void UseHiDPI(bool hiDPI);
|
static void UseHiDPI(bool hiDPI);
|
||||||
static void InvalidateCursorRects();
|
static void SetCursor(NSCursor* cursor);
|
||||||
static void SetWindowVisible(bool visible);
|
static void SetWindowVisible(bool visible);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -509,11 +520,15 @@ void CocoaVideo::UseHiDPI(const bool hiDPI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaVideo::InvalidateCursorRects()
|
void CocoaVideo::SetCursor(NSCursor* cursor)
|
||||||
{
|
{
|
||||||
if (CocoaVideo* const video = GetInstance())
|
if (CocoaVideo* const video = GetInstance())
|
||||||
{
|
{
|
||||||
[video->m_window invalidateCursorRectsForView:[video->m_window contentView]];
|
NSWindow* const window = video->m_window;
|
||||||
|
CocoaView* const view = [window contentView];
|
||||||
|
|
||||||
|
[view setCursor:cursor];
|
||||||
|
[window invalidateCursorRectsForView:view];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1141,12 +1156,9 @@ CCMD(vid_currentmode)
|
||||||
bool I_SetCursor(FTexture* cursorpic)
|
bool I_SetCursor(FTexture* cursorpic)
|
||||||
{
|
{
|
||||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
NSCursor* cursor = nil;
|
||||||
|
|
||||||
if (NULL == cursorpic || FTexture::TEX_Null == cursorpic->UseType)
|
if (NULL != cursorpic && FTexture::TEX_Null != cursorpic->UseType)
|
||||||
{
|
|
||||||
s_cursor = [NSCursor arrowCursor];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Create bitmap image representation
|
// Create bitmap image representation
|
||||||
|
|
||||||
|
@ -1191,11 +1203,11 @@ bool I_SetCursor(FTexture* cursorpic)
|
||||||
properties:nil];
|
properties:nil];
|
||||||
NSImage* cursorImage = [[NSImage alloc] initWithData:imageData];
|
NSImage* cursorImage = [[NSImage alloc] initWithData:imageData];
|
||||||
|
|
||||||
s_cursor = [[NSCursor alloc] initWithImage:cursorImage
|
cursor = [[NSCursor alloc] initWithImage:cursorImage
|
||||||
hotSpot:NSMakePoint(0.0f, 0.0f)];
|
hotSpot:NSMakePoint(0.0f, 0.0f)];
|
||||||
}
|
}
|
||||||
|
|
||||||
CocoaVideo::InvalidateCursorRects();
|
CocoaVideo::SetCursor(cursor);
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue