2019-10-19 16:26:04 +00:00
|
|
|
#import <IOKit/pwr_mgt/IOPMLib.h>
|
2016-03-30 20:07:55 +00:00
|
|
|
#import "GBView.h"
|
2018-06-11 17:23:51 +00:00
|
|
|
#import "GBViewGL.h"
|
2018-06-15 09:58:33 +00:00
|
|
|
#import "GBViewMetal.h"
|
2016-04-13 19:43:16 +00:00
|
|
|
#import "GBButtons.h"
|
|
|
|
#import "NSString+StringForKey.h"
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2018-06-26 16:36:14 +00:00
|
|
|
#define JOYSTICK_HIGH 0x4000
|
|
|
|
#define JOYSTICK_LOW 0x3800
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
@implementation GBView
|
|
|
|
{
|
|
|
|
uint32_t *image_buffers[3];
|
|
|
|
unsigned char current_buffer;
|
2016-07-05 20:34:33 +00:00
|
|
|
BOOL mouse_hidden;
|
|
|
|
NSTrackingArea *tracking_area;
|
|
|
|
BOOL _mouseHidingEnabled;
|
2018-06-26 16:36:14 +00:00
|
|
|
bool axisActive[2];
|
2018-02-10 21:30:30 +00:00
|
|
|
bool underclockKeyDown;
|
|
|
|
double clockMultiplier;
|
2019-10-19 16:26:04 +00:00
|
|
|
double analogClockMultiplier;
|
|
|
|
bool analogClockMultiplierValid;
|
2018-02-10 21:30:30 +00:00
|
|
|
NSEventModifierFlags previousModifiers;
|
2019-10-19 16:26:04 +00:00
|
|
|
JOYController *lastController;
|
2020-03-26 18:54:18 +00:00
|
|
|
GB_frame_blending_mode_t _frameBlendingMode;
|
2016-03-30 20:07:55 +00:00
|
|
|
}
|
|
|
|
|
2018-06-11 17:23:51 +00:00
|
|
|
+ (instancetype)alloc
|
2016-06-14 11:11:37 +00:00
|
|
|
{
|
2018-06-15 09:58:33 +00:00
|
|
|
return [self allocWithZone:NULL];
|
2018-06-11 17:23:51 +00:00
|
|
|
}
|
2016-06-14 11:11:37 +00:00
|
|
|
|
2018-06-11 17:23:51 +00:00
|
|
|
+ (instancetype)allocWithZone:(struct _NSZone *)zone
|
|
|
|
{
|
|
|
|
if (self == [GBView class]) {
|
2018-06-15 17:03:59 +00:00
|
|
|
if ([GBViewMetal isSupported]) {
|
|
|
|
return [GBViewMetal allocWithZone: zone];
|
|
|
|
}
|
|
|
|
return [GBViewGL allocWithZone: zone];
|
2018-06-11 17:23:51 +00:00
|
|
|
}
|
|
|
|
return [super allocWithZone:zone];
|
2016-06-14 11:11:37 +00:00
|
|
|
}
|
|
|
|
|
2018-06-11 17:23:51 +00:00
|
|
|
- (void) createInternalView
|
|
|
|
{
|
|
|
|
assert(false && "createInternalView must not be inherited");
|
|
|
|
}
|
2016-06-14 11:11:37 +00:00
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
- (void) _init
|
2020-03-26 18:54:18 +00:00
|
|
|
{
|
2016-07-05 18:23:55 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ratioKeepingChanged) name:@"GBAspectChanged" object:nil];
|
2016-07-05 20:34:33 +00:00
|
|
|
tracking_area = [ [NSTrackingArea alloc] initWithRect:(NSRect){}
|
|
|
|
options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect
|
|
|
|
owner:self
|
|
|
|
userInfo:nil];
|
|
|
|
[self addTrackingArea:tracking_area];
|
2018-02-10 21:30:30 +00:00
|
|
|
clockMultiplier = 1.0;
|
2018-06-11 17:23:51 +00:00
|
|
|
[self createInternalView];
|
|
|
|
[self addSubview:self.internalView];
|
|
|
|
self.internalView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
2019-10-19 16:26:04 +00:00
|
|
|
[JOYController registerListener:self];
|
2016-03-30 20:07:55 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 22:21:21 +00:00
|
|
|
- (void)screenSizeChanged
|
|
|
|
{
|
|
|
|
if (image_buffers[0]) free(image_buffers[0]);
|
|
|
|
if (image_buffers[1]) free(image_buffers[1]);
|
|
|
|
if (image_buffers[2]) free(image_buffers[2]);
|
|
|
|
|
|
|
|
size_t buffer_size = sizeof(image_buffers[0][0]) * GB_get_screen_width(_gb) * GB_get_screen_height(_gb);
|
|
|
|
|
2020-02-08 11:28:46 +00:00
|
|
|
image_buffers[0] = calloc(1, buffer_size);
|
|
|
|
image_buffers[1] = calloc(1, buffer_size);
|
|
|
|
image_buffers[2] = calloc(1, buffer_size);
|
2018-11-14 22:21:21 +00:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self setFrame:self.superview.frame];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-05 18:23:55 +00:00
|
|
|
- (void) ratioKeepingChanged
|
|
|
|
{
|
|
|
|
[self setFrame:self.superview.frame];
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:54:18 +00:00
|
|
|
- (void) setFrameBlendingMode:(GB_frame_blending_mode_t)frameBlendingMode
|
2016-06-08 21:06:55 +00:00
|
|
|
{
|
2020-03-26 18:54:18 +00:00
|
|
|
_frameBlendingMode = frameBlendingMode;
|
2016-06-08 21:06:55 +00:00
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:54:18 +00:00
|
|
|
|
|
|
|
- (GB_frame_blending_mode_t)frameBlendingMode
|
|
|
|
{
|
|
|
|
if (_frameBlendingMode == GB_FRAME_BLENDING_MODE_ACCURATE) {
|
2020-03-27 14:22:50 +00:00
|
|
|
if (!_gb || GB_is_sgb(_gb)) {
|
2020-03-26 18:54:18 +00:00
|
|
|
return GB_FRAME_BLENDING_MODE_SIMPLE;
|
|
|
|
}
|
|
|
|
return GB_is_odd_frame(_gb)? GB_FRAME_BLENDING_MODE_ACCURATE_ODD : GB_FRAME_BLENDING_MODE_ACCURATE_EVEN;
|
|
|
|
}
|
|
|
|
return _frameBlendingMode;
|
|
|
|
}
|
2016-03-30 20:07:55 +00:00
|
|
|
- (unsigned char) numberOfBuffers
|
|
|
|
{
|
2020-03-26 18:54:18 +00:00
|
|
|
return _frameBlendingMode? 3 : 2;
|
2016-03-30 20:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
free(image_buffers[0]);
|
|
|
|
free(image_buffers[1]);
|
|
|
|
free(image_buffers[2]);
|
2016-07-05 20:34:33 +00:00
|
|
|
if (mouse_hidden) {
|
|
|
|
mouse_hidden = false;
|
|
|
|
[NSCursor unhide];
|
|
|
|
}
|
2016-04-28 20:07:05 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
2020-05-30 15:43:09 +00:00
|
|
|
[self setRumble:0];
|
2019-10-19 16:26:04 +00:00
|
|
|
[JOYController unregisterListener:self];
|
2016-03-30 20:07:55 +00:00
|
|
|
}
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)coder
|
|
|
|
{
|
2020-04-24 17:37:57 +00:00
|
|
|
if (!(self = [super initWithCoder:coder])) {
|
2016-03-30 20:07:55 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
[self _init];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithFrame:(NSRect)frameRect
|
|
|
|
{
|
2020-04-24 17:37:57 +00:00
|
|
|
if (!(self = [super initWithFrame:frameRect])) {
|
2016-03-30 20:07:55 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
[self _init];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-07-03 17:58:25 +00:00
|
|
|
- (void)setFrame:(NSRect)frame
|
|
|
|
{
|
|
|
|
frame = self.superview.frame;
|
2018-11-23 17:59:15 +00:00
|
|
|
if (_gb && ![[NSUserDefaults standardUserDefaults] boolForKey:@"GBAspectRatioUnkept"]) {
|
2016-07-05 18:23:55 +00:00
|
|
|
double ratio = frame.size.width / frame.size.height;
|
2018-11-14 22:21:21 +00:00
|
|
|
double width = GB_get_screen_width(_gb);
|
|
|
|
double height = GB_get_screen_height(_gb);
|
|
|
|
if (ratio >= width / height) {
|
|
|
|
double new_width = round(frame.size.height / height * width);
|
2016-07-05 18:23:55 +00:00
|
|
|
frame.origin.x = floor((frame.size.width - new_width) / 2);
|
|
|
|
frame.size.width = new_width;
|
|
|
|
frame.origin.y = 0;
|
|
|
|
}
|
|
|
|
else {
|
2018-11-14 22:21:21 +00:00
|
|
|
double new_height = round(frame.size.width / width * height);
|
2016-07-05 18:23:55 +00:00
|
|
|
frame.origin.y = floor((frame.size.height - new_height) / 2);
|
|
|
|
frame.size.height = new_height;
|
|
|
|
frame.origin.x = 0;
|
|
|
|
}
|
2016-07-03 17:58:25 +00:00
|
|
|
}
|
2016-07-05 20:34:33 +00:00
|
|
|
|
2016-07-03 17:58:25 +00:00
|
|
|
[super setFrame:frame];
|
|
|
|
}
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
- (void) flip
|
|
|
|
{
|
2019-10-19 16:26:04 +00:00
|
|
|
if (analogClockMultiplierValid && [[NSUserDefaults standardUserDefaults] boolForKey:@"GBAnalogControls"]) {
|
|
|
|
GB_set_clock_multiplier(_gb, analogClockMultiplier);
|
|
|
|
if (analogClockMultiplier == 1.0) {
|
|
|
|
analogClockMultiplierValid = false;
|
|
|
|
}
|
2018-02-10 21:30:30 +00:00
|
|
|
}
|
2019-10-19 16:26:04 +00:00
|
|
|
else {
|
|
|
|
if (underclockKeyDown && clockMultiplier > 0.5) {
|
|
|
|
clockMultiplier -= 1.0/16;
|
|
|
|
GB_set_clock_multiplier(_gb, clockMultiplier);
|
|
|
|
}
|
|
|
|
if (!underclockKeyDown && clockMultiplier < 1.0) {
|
|
|
|
clockMultiplier += 1.0/16;
|
|
|
|
GB_set_clock_multiplier(_gb, clockMultiplier);
|
|
|
|
}
|
2018-02-10 21:30:30 +00:00
|
|
|
}
|
2016-03-30 20:07:55 +00:00
|
|
|
current_buffer = (current_buffer + 1) % self.numberOfBuffers;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint32_t *) pixels
|
|
|
|
{
|
|
|
|
return image_buffers[(current_buffer + 1) % self.numberOfBuffers];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)keyDown:(NSEvent *)theEvent
|
|
|
|
{
|
2017-01-24 19:00:56 +00:00
|
|
|
unsigned short keyCode = theEvent.keyCode;
|
2016-04-13 19:43:16 +00:00
|
|
|
bool handled = false;
|
|
|
|
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
2018-12-15 16:55:41 +00:00
|
|
|
unsigned player_count = GB_get_player_count(_gb);
|
2018-12-04 22:00:16 +00:00
|
|
|
for (unsigned player = 0; player < player_count; player++) {
|
|
|
|
for (GBButton button = 0; button < GBButtonCount; button++) {
|
|
|
|
NSNumber *key = [defaults valueForKey:button_to_preference_name(button, player)];
|
|
|
|
if (!key) continue;
|
|
|
|
|
|
|
|
if (key.unsignedShortValue == keyCode) {
|
|
|
|
handled = true;
|
|
|
|
switch (button) {
|
|
|
|
case GBTurbo:
|
|
|
|
GB_set_turbo_mode(_gb, true, self.isRewinding);
|
2019-10-19 16:26:04 +00:00
|
|
|
analogClockMultiplierValid = false;
|
2018-12-04 22:00:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GBRewind:
|
|
|
|
self.isRewinding = true;
|
|
|
|
GB_set_turbo_mode(_gb, false, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GBUnderclock:
|
|
|
|
underclockKeyDown = true;
|
2019-10-19 16:26:04 +00:00
|
|
|
analogClockMultiplierValid = false;
|
2018-12-04 22:00:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
GB_set_key_state_for_player(_gb, (GB_key_t)button, player, true);
|
|
|
|
break;
|
|
|
|
}
|
2016-04-13 19:43:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 17:37:40 +00:00
|
|
|
if (!handled && [theEvent type] != NSEventTypeFlagsChanged) {
|
2016-04-13 19:43:16 +00:00
|
|
|
[super keyDown:theEvent];
|
2016-03-30 20:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)keyUp:(NSEvent *)theEvent
|
|
|
|
{
|
2017-01-24 19:00:56 +00:00
|
|
|
unsigned short keyCode = theEvent.keyCode;
|
2016-04-13 19:43:16 +00:00
|
|
|
bool handled = false;
|
|
|
|
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
2018-12-15 16:55:41 +00:00
|
|
|
unsigned player_count = GB_get_player_count(_gb);
|
2018-12-04 22:00:16 +00:00
|
|
|
for (unsigned player = 0; player < player_count; player++) {
|
|
|
|
for (GBButton button = 0; button < GBButtonCount; button++) {
|
|
|
|
NSNumber *key = [defaults valueForKey:button_to_preference_name(button, player)];
|
|
|
|
if (!key) continue;
|
|
|
|
|
|
|
|
if (key.unsignedShortValue == keyCode) {
|
|
|
|
handled = true;
|
|
|
|
switch (button) {
|
|
|
|
case GBTurbo:
|
|
|
|
GB_set_turbo_mode(_gb, false, false);
|
2019-10-19 16:26:04 +00:00
|
|
|
analogClockMultiplierValid = false;
|
2018-12-04 22:00:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GBRewind:
|
|
|
|
self.isRewinding = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GBUnderclock:
|
|
|
|
underclockKeyDown = false;
|
2019-10-19 16:26:04 +00:00
|
|
|
analogClockMultiplierValid = false;
|
2018-12-04 22:00:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
GB_set_key_state_for_player(_gb, (GB_key_t)button, player, false);
|
|
|
|
break;
|
|
|
|
}
|
2016-04-13 19:43:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 17:37:40 +00:00
|
|
|
if (!handled && [theEvent type] != NSEventTypeFlagsChanged) {
|
2016-04-13 19:43:16 +00:00
|
|
|
[super keyUp:theEvent];
|
2016-03-30 20:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 13:05:31 +00:00
|
|
|
- (void)setRumble:(double)amp
|
2017-12-30 14:23:17 +00:00
|
|
|
{
|
2020-05-30 19:18:32 +00:00
|
|
|
[lastController setRumbleAmplitude:amp];
|
2019-10-19 16:26:04 +00:00
|
|
|
}
|
2018-12-15 16:55:41 +00:00
|
|
|
|
2019-10-19 16:26:04 +00:00
|
|
|
- (void)controller:(JOYController *)controller movedAxis:(JOYAxis *)axis
|
|
|
|
{
|
|
|
|
if (![self.window isMainWindow]) return;
|
|
|
|
|
|
|
|
NSDictionary *mapping = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"JoyKitInstanceMapping"][controller.uniqueID];
|
|
|
|
if (!mapping) {
|
|
|
|
mapping = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"JoyKitNameMapping"][controller.deviceName];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((axis.usage == JOYAxisUsageR1 && !mapping) ||
|
|
|
|
axis.uniqueID == [mapping[@"AnalogUnderclock"] unsignedLongValue]){
|
|
|
|
analogClockMultiplier = MIN(MAX(1 - axis.value + 0.2, 1.0 / 3), 1.0);
|
|
|
|
analogClockMultiplierValid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ((axis.usage == JOYAxisUsageL1 && !mapping) ||
|
|
|
|
axis.uniqueID == [mapping[@"AnalogTurbo"] unsignedLongValue]){
|
|
|
|
analogClockMultiplier = MIN(MAX(axis.value * 3 + 0.8, 1.0), 3.0);
|
|
|
|
analogClockMultiplierValid = true;
|
2017-12-30 14:23:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-19 16:26:04 +00:00
|
|
|
- (void)controller:(JOYController *)controller buttonChangedState:(JOYButton *)button
|
2017-12-30 14:23:17 +00:00
|
|
|
{
|
2019-10-19 16:26:04 +00:00
|
|
|
if (![self.window isMainWindow]) return;
|
|
|
|
if (controller != lastController) {
|
2020-05-30 15:43:09 +00:00
|
|
|
[self setRumble:0];
|
2019-10-19 16:26:04 +00:00
|
|
|
lastController = controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-15 16:55:41 +00:00
|
|
|
unsigned player_count = GB_get_player_count(_gb);
|
|
|
|
|
2019-10-19 16:26:04 +00:00
|
|
|
IOPMAssertionID assertionID;
|
|
|
|
IOPMAssertionDeclareUserActivity(CFSTR(""), kIOPMUserActiveLocal, &assertionID);
|
|
|
|
|
2018-12-15 16:55:41 +00:00
|
|
|
for (unsigned player = 0; player < player_count; player++) {
|
2019-10-19 16:26:04 +00:00
|
|
|
NSString *preferred_joypad = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"JoyKitDefaultControllers"]
|
|
|
|
objectForKey:n2s(player)];
|
2018-12-15 16:55:41 +00:00
|
|
|
if (player_count != 1 && // Single player, accpet inputs from all joypads
|
|
|
|
!(player == 0 && !preferred_joypad) && // Multiplayer, but player 1 has no joypad configured, so it takes inputs from all joypads
|
2019-10-19 16:26:04 +00:00
|
|
|
![preferred_joypad isEqualToString:controller.uniqueID]) {
|
2018-12-15 16:55:41 +00:00
|
|
|
continue;
|
2018-06-26 16:36:14 +00:00
|
|
|
}
|
2020-05-30 15:43:09 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[controller setPlayerLEDs:1 << player];
|
|
|
|
});
|
2019-10-19 16:26:04 +00:00
|
|
|
NSDictionary *mapping = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"JoyKitInstanceMapping"][controller.uniqueID];
|
|
|
|
if (!mapping) {
|
|
|
|
mapping = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"JoyKitNameMapping"][controller.deviceName];
|
|
|
|
}
|
2018-12-15 16:55:41 +00:00
|
|
|
|
2019-10-19 16:26:04 +00:00
|
|
|
JOYButtonUsage usage = ((JOYButtonUsage)[mapping[n2s(button.uniqueID)] unsignedIntValue]) ?: button.usage;
|
|
|
|
if (!mapping && usage >= JOYButtonUsageGeneric0) {
|
|
|
|
usage = (const JOYButtonUsage[]){JOYButtonUsageY, JOYButtonUsageA, JOYButtonUsageB, JOYButtonUsageX}[(usage - JOYButtonUsageGeneric0) & 3];
|
2018-06-26 16:36:14 +00:00
|
|
|
}
|
2019-10-19 16:26:04 +00:00
|
|
|
|
|
|
|
switch (usage) {
|
|
|
|
|
|
|
|
case JOYButtonUsageNone: break;
|
|
|
|
case JOYButtonUsageA: GB_set_key_state_for_player(_gb, GB_KEY_A, player, button.isPressed); break;
|
|
|
|
case JOYButtonUsageB: GB_set_key_state_for_player(_gb, GB_KEY_B, player, button.isPressed); break;
|
|
|
|
case JOYButtonUsageC: break;
|
|
|
|
case JOYButtonUsageStart:
|
|
|
|
case JOYButtonUsageX: GB_set_key_state_for_player(_gb, GB_KEY_START, player, button.isPressed); break;
|
|
|
|
case JOYButtonUsageSelect:
|
|
|
|
case JOYButtonUsageY: GB_set_key_state_for_player(_gb, GB_KEY_SELECT, player, button.isPressed); break;
|
|
|
|
case JOYButtonUsageR2:
|
|
|
|
case JOYButtonUsageL2:
|
|
|
|
case JOYButtonUsageZ: {
|
|
|
|
self.isRewinding = button.isPressed;
|
|
|
|
if (button.isPressed) {
|
|
|
|
GB_set_turbo_mode(_gb, false, false);
|
|
|
|
}
|
|
|
|
break;
|
2018-12-15 16:55:41 +00:00
|
|
|
}
|
2019-10-19 16:26:04 +00:00
|
|
|
|
|
|
|
case JOYButtonUsageL1: GB_set_turbo_mode(_gb, button.isPressed, button.isPressed && self.isRewinding); break;
|
2017-12-30 14:23:17 +00:00
|
|
|
|
2019-10-19 16:26:04 +00:00
|
|
|
case JOYButtonUsageR1: underclockKeyDown = button.isPressed; break;
|
|
|
|
case JOYButtonUsageDPadLeft: GB_set_key_state_for_player(_gb, GB_KEY_LEFT, player, button.isPressed); break;
|
|
|
|
case JOYButtonUsageDPadRight: GB_set_key_state_for_player(_gb, GB_KEY_RIGHT, player, button.isPressed); break;
|
|
|
|
case JOYButtonUsageDPadUp: GB_set_key_state_for_player(_gb, GB_KEY_UP, player, button.isPressed); break;
|
|
|
|
case JOYButtonUsageDPadDown: GB_set_key_state_for_player(_gb, GB_KEY_DOWN, player, button.isPressed); break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2019-06-14 15:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-30 14:23:17 +00:00
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2016-07-05 20:34:33 +00:00
|
|
|
|
|
|
|
- (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;
|
|
|
|
}
|
2017-12-30 14:23:17 +00:00
|
|
|
|
2018-02-10 21:30:30 +00:00
|
|
|
- (void) flagsChanged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
if (event.modifierFlags > previousModifiers) {
|
|
|
|
[self keyDown:event];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[self keyUp:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
previousModifiers = event.modifierFlags;
|
|
|
|
}
|
|
|
|
|
2018-06-11 17:23:51 +00:00
|
|
|
- (uint32_t *)currentBuffer
|
|
|
|
{
|
|
|
|
return image_buffers[current_buffer];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint32_t *)previousBuffer
|
|
|
|
{
|
|
|
|
return image_buffers[(current_buffer + 2) % self.numberOfBuffers];
|
|
|
|
}
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
@end
|