mirror of https://github.com/bsnes-emu/bsnes.git
Hide mouse cursor when running (Cocoa)
This commit is contained in:
parent
1268bf3a35
commit
dce0e5fdeb
|
@ -94,6 +94,7 @@ static uint32_t rgbEncode(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b)
|
|||
|
||||
- (void) vblank
|
||||
{
|
||||
self.view.mouseHidingEnabled = YES;
|
||||
[self.view flip];
|
||||
GB_set_pixels_output(&gb, self.view.pixels);
|
||||
}
|
||||
|
@ -107,11 +108,13 @@ static uint32_t rgbEncode(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b)
|
|||
self.audioClient = [[GBAudioClient alloc] initWithRendererBlock:^(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer) {
|
||||
GB_apu_copy_buffer(&gb, buffer, nFrames);
|
||||
} andSampleRate:96000];
|
||||
self.view.mouseHidingEnabled = YES;
|
||||
[self.audioClient start];
|
||||
while (running) {
|
||||
GB_run(&gb);
|
||||
}
|
||||
[self.audioClient stop];
|
||||
self.view.mouseHidingEnabled = NO;
|
||||
GB_save_battery(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"sav"] UTF8String]);
|
||||
stopping = false;
|
||||
}
|
||||
|
@ -309,6 +312,10 @@ static uint32_t rgbEncode(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b)
|
|||
return;
|
||||
}
|
||||
pendingLogLines++;
|
||||
|
||||
/* Make sure mouse is not hidden while debugging */
|
||||
self.view.mouseHidingEnabled = NO;
|
||||
|
||||
NSString *nsstring = @(string); // For ref-counting
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSFont *font = [NSFont userFixedPitchFontOfSize:12];
|
||||
|
|
|
@ -8,4 +8,5 @@
|
|||
@property GB_gameboy_t *gb;
|
||||
@property (nonatomic) BOOL shouldBlendFrameWithPrevious;
|
||||
@property GBShader *shader;
|
||||
@property (getter=isMouseHidingEnabled) BOOL mouseHidingEnabled;
|
||||
@end
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
{
|
||||
uint32_t *image_buffers[3];
|
||||
unsigned char current_buffer;
|
||||
BOOL mouse_hidden;
|
||||
NSTrackingArea *tracking_area;
|
||||
BOOL _mouseHidingEnabled;
|
||||
}
|
||||
|
||||
- (void) awakeFromNib
|
||||
|
@ -42,6 +45,11 @@
|
|||
_shouldBlendFrameWithPrevious = 1;
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(filterChanged) name:@"GBFilterChanged" object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ratioKeepingChanged) name:@"GBAspectChanged" object:nil];
|
||||
tracking_area = [ [NSTrackingArea alloc] initWithRect:(NSRect){}
|
||||
options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect
|
||||
owner:self
|
||||
userInfo:nil];
|
||||
[self addTrackingArea:tracking_area];
|
||||
}
|
||||
|
||||
- (void) filterChanged
|
||||
|
@ -71,6 +79,10 @@
|
|||
free(image_buffers[0]);
|
||||
free(image_buffers[1]);
|
||||
free(image_buffers[2]);
|
||||
if (mouse_hidden) {
|
||||
mouse_hidden = false;
|
||||
[NSCursor unhide];
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder
|
||||
|
@ -111,6 +123,7 @@
|
|||
frame.origin.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
[super setFrame:frame];
|
||||
}
|
||||
|
||||
|
@ -223,4 +236,46 @@
|
|||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)mouseEntered:(NSEvent *)theEvent
|
||||
{
|
||||
if (!mouse_hidden) {
|
||||
mouse_hidden = true;
|
||||
if (_mouseHidingEnabled) {
|
||||
[NSCursor hide];
|
||||
}
|
||||
}
|
||||
[super mouseEntered:theEvent];
|
||||
}
|
||||
|
||||
- (void)mouseExited:(NSEvent *)theEvent
|
||||
{
|
||||
if (mouse_hidden) {
|
||||
mouse_hidden = false;
|
||||
if (_mouseHidingEnabled) {
|
||||
[NSCursor unhide];
|
||||
}
|
||||
}
|
||||
[super mouseExited:theEvent];
|
||||
}
|
||||
|
||||
- (void)setMouseHidingEnabled:(BOOL)mouseHidingEnabled
|
||||
{
|
||||
if (mouseHidingEnabled == _mouseHidingEnabled) return;
|
||||
|
||||
_mouseHidingEnabled = mouseHidingEnabled;
|
||||
|
||||
if (mouse_hidden && _mouseHidingEnabled) {
|
||||
[NSCursor hide];
|
||||
}
|
||||
|
||||
if (mouse_hidden && !_mouseHidingEnabled) {
|
||||
[NSCursor unhide];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isMouseHidingEnabled
|
||||
{
|
||||
return _mouseHidingEnabled;
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue