Implemented setting of window title in Cocoa backend

# Conflicts:
#	src/posix/cocoa/i_video.mm
This commit is contained in:
alexey.lysiuk 2017-11-18 13:24:17 +02:00 committed by Rachael Alexanderson
parent c3c637a0cc
commit 35bb9ba9d3

View file

@ -197,9 +197,12 @@ namespace
@interface CocoaWindow : NSWindow @interface CocoaWindow : NSWindow
{ {
NSString* m_title;
} }
- (BOOL)canBecomeKeyWindow; - (BOOL)canBecomeKeyWindow;
- (void)setTitle:(NSString*)title;
- (void)updateTitle;
@end @end
@ -211,6 +214,23 @@ namespace
return true; return true;
} }
- (void)setTitle:(NSString*)title
{
m_title = title;
[self updateTitle];
}
- (void)updateTitle
{
if (nil == m_title)
{
m_title = [NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()];
}
[super setTitle:m_title];
}
@end @end
@ -271,6 +291,7 @@ public:
static void UseHiDPI(bool hiDPI); static void UseHiDPI(bool hiDPI);
static void SetCursor(NSCursor* cursor); static void SetCursor(NSCursor* cursor);
static void SetWindowVisible(bool visible); static void SetWindowVisible(bool visible);
static void SetWindowTitle(const char* title);
private: private:
struct ModeIterator struct ModeIterator
@ -717,6 +738,16 @@ void CocoaVideo::SetWindowVisible(bool visible)
} }
} }
void CocoaVideo::SetWindowTitle(const char* title)
{
if (CocoaVideo* const video = GetInstance())
{
NSString* const nsTitle = nullptr == title ? nil :
[NSString stringWithCString:title encoding:NSISOLatin1StringEncoding];
[video->m_window setTitle:nsTitle];
}
}
void CocoaVideo::SetFullscreenMode(const int width, const int height) void CocoaVideo::SetFullscreenMode(const int width, const int height)
{ {
@ -813,9 +844,7 @@ void CocoaVideo::SetMode(const int width, const int height, const bool fullscree
[[NSOpenGLContext currentContext] flushBuffer]; [[NSOpenGLContext currentContext] flushBuffer];
static NSString* const TITLE_STRING = [m_window updateTitle];
[NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()];
[m_window setTitle:TITLE_STRING];
if (![m_window isKeyWindow]) if (![m_window isKeyWindow])
{ {
@ -1523,16 +1552,5 @@ void I_SetMainWindowVisible(bool visible)
// each platform has its own specific version of this function. // each platform has its own specific version of this function.
void I_SetWindowTitle(const char* title) void I_SetWindowTitle(const char* title)
{ {
if (title) CocoaVideo::SetWindowTitle(title);
{
static NSString* const TITLE_STRING =
[NSString stringWithFormat:@"%s", title];
[m_window setTitle:TITLE_STRING];
}
else
{
static NSString* const TITLE_STRING =
[NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()];
[m_window setTitle:TITLE_STRING];
}
} }