More macOS Cocoa improvements.

This commit is contained in:
byuu 2019-07-27 01:27:56 +09:00
parent cdf4784468
commit 4d2244ed5f
7 changed files with 24 additions and 12 deletions

View File

@ -294,6 +294,13 @@ auto Program::reset() -> void {
auto Program::unload() -> void { auto Program::unload() -> void {
if(!emulator->loaded()) return; if(!emulator->loaded()) return;
//todo: video.clear() is not working on macOS/OpenGL 3.2
if(auto [output, length] = video.acquire(1, 1); output) {
*output = 0;
video.release();
video.output();
}
audio.clear();
rewindReset(); //free up memory that is no longer needed rewindReset(); //free up memory that is no longer needed
movieStop(); //in case a movie is currently being played or recorded movieStop(); //in case a movie is currently being played or recorded
cheatEditor.saveCheats(); cheatEditor.saveCheats();

View File

@ -7,7 +7,9 @@
menuRadioItem = &menuRadioItemReference; menuRadioItem = &menuRadioItemReference;
[self setTarget:self]; [self setTarget:self];
[self setOnStateImage:[NSImage imageNamed:@"NSMenuRadio"]]; //todo: the default image is a check mark, which is not indicative of radio states.
//however, NSMenuRadio does not respect macOS' dark theme, and is barely visible.
//[self setOnStateImage:[NSImage imageNamed:@"NSMenuRadio"]];
} }
return self; return self;
} }

View File

@ -3,9 +3,9 @@ auto NSMakeColor(const hiro::Color& color) -> NSColor* {
} }
auto NSMakeCursor(const hiro::MouseCursor& mouseCursor) -> NSCursor* { auto NSMakeCursor(const hiro::MouseCursor& mouseCursor) -> NSCursor* {
if(mouseCursor == MouseCursor::Hand) return [NSCursor pointingHandCursor]; if(mouseCursor == hiro::MouseCursor::Hand) return [NSCursor pointingHandCursor];
if(mouseCursor == MouseCursor::HorizontalResize) return [NSCursor resizeLeftRightCursor]; if(mouseCursor == hiro::MouseCursor::HorizontalResize) return [NSCursor resizeLeftRightCursor];
if(mouseCursor == MouseCursor::VerticalResize) return [NSCursor resizeUpDownCursor]; if(mouseCursor == hiro::MouseCursor::VerticalResize) return [NSCursor resizeUpDownCursor];
return nil; return nil;
} }

View File

@ -16,7 +16,7 @@
} }
-(void) resetCursorRects { -(void) resetCursorRects {
if(auto mouseCursor = NSMakeCursor(label->mouseCursor())) { if(auto mouseCursor = NSMakeCursor(canvas->mouseCursor())) {
[self addCursorRect:self.bounds cursor:mouseCursor]; [self addCursorRect:self.bounds cursor:mouseCursor];
} }
} }

View File

@ -16,13 +16,10 @@
} }
-(void) drawRect:(NSRect)dirtyRect { -(void) drawRect:(NSRect)dirtyRect {
auto geometry = label->geometry();
NSRect rect = {{geometry.x(), geometry.y()}, {geometry.width(), geometry.height()}};
if(auto backgroundColor = label->backgroundColor()) { if(auto backgroundColor = label->backgroundColor()) {
NSColor* color = NSMakeColor(backgroundColor); NSColor* color = NSMakeColor(backgroundColor);
[color setFill]; [color setFill];
NSRectFill(rect); NSRectFill(dirtyRect);
} }
NSFont* font = hiro::pFont::create(label->font(true)); NSFont* font = hiro::pFont::create(label->font(true));
@ -43,6 +40,8 @@
auto alignment = label->alignment(); auto alignment = label->alignment();
if(!alignment) alignment = {0.0, 0.5}; if(!alignment) alignment = {0.0, 0.5};
auto geometry = label->geometry();
NSRect rect = {{geometry.x(), geometry.y()}, {geometry.width(), geometry.height()}};
rect.origin.x = max(0, (geometry.width() - size.width()) * alignment.horizontal()); rect.origin.x = max(0, (geometry.width() - size.width()) * alignment.horizontal());
rect.origin.y = max(0, (geometry.height() - size.height()) * alignment.vertical()); rect.origin.y = max(0, (geometry.height() - size.height()) * alignment.vertical());
rect.size.width = min(geometry.width(), size.width()); rect.size.width = min(geometry.width(), size.width());
@ -128,8 +127,8 @@ auto pLabel::construct() -> void {
pWidget::construct(); pWidget::construct();
setAlignment(state().alignment); setAlignment(state().alignment);
setBackgroundColor(state().backgroundColor()); setBackgroundColor(state().backgroundColor);
setForegroundColor(state().foregroundColor()); setForegroundColor(state().foregroundColor);
setText(state().text); setText(state().text);
} }
} }

View File

@ -10,7 +10,7 @@
} }
-(void) resetCursorRects { -(void) resetCursorRects {
if(auto mouseCursor = NSMakeCursor(label->mouseCursor())) { if(auto mouseCursor = NSMakeCursor(viewport->mouseCursor())) {
[self addCursorRect:self.bounds cursor:mouseCursor]; [self addCursorRect:self.bounds cursor:mouseCursor];
} }
} }

View File

@ -98,7 +98,11 @@ template<typename... P> inline auto invoke(const string& name, P&&... p) -> void
*argp++ = nullptr; *argp++ = nullptr;
if(execvp(name, (char* const*)argv) < 0) { if(execvp(name, (char* const*)argv) < 0) {
#if defined(PLATFORM_MACOS)
execlp("open", "open", (const char*)name, nullptr);
#else
execlp("xdg-open", "xdg-open", (const char*)name, nullptr); execlp("xdg-open", "xdg-open", (const char*)name, nullptr);
#endif
} }
exit(0); exit(0);
} }