git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit 500e767247c22ee7e014de296f3776fca4a2ec39
parent f9401300b57f8946d9f51f133c61b2a2081a7a8c
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Sat, 16 Jul 2022 18:54:16 +0300

And the same feature in Cocoa as well. Closes #472

Diffstat:
MCocoa/GBPreferencesWindow.h63++++++++++++++++++++++++++++++++-------------------------------
MCocoa/GBPreferencesWindow.m18++++++++++++++++++
MCocoa/GBView.m15+++++++++++++--
MCocoa/Preferences.xib50+++++++++++++++++++++++++++++++-------------------
4 files changed, 94 insertions(+), 52 deletions(-)

diff --git a/Cocoa/GBPreferencesWindow.h b/Cocoa/GBPreferencesWindow.h @@ -3,35 +3,36 @@ #import "GBPaletteEditorController.h" @interface GBPreferencesWindow : NSWindow <NSTableViewDelegate, NSTableViewDataSource, JOYListener> -@property (nonatomic, strong) IBOutlet NSTableView *controlsTableView; -@property (nonatomic, strong) IBOutlet NSPopUpButton *graphicsFilterPopupButton; -@property (nonatomic, strong) IBOutlet NSButton *analogControlsCheckbox; -@property (nonatomic, strong) IBOutlet NSButton *aspectRatioCheckbox; -@property (nonatomic, strong) IBOutlet NSPopUpButton *highpassFilterPopupButton; -@property (nonatomic, strong) IBOutlet NSPopUpButton *colorCorrectionPopupButton; -@property (nonatomic, strong) IBOutlet NSPopUpButton *frameBlendingModePopupButton; -@property (nonatomic, strong) IBOutlet NSPopUpButton *colorPalettePopupButton; -@property (nonatomic, strong) IBOutlet NSPopUpButton *displayBorderPopupButton; -@property (nonatomic, strong) IBOutlet NSPopUpButton *rewindPopupButton; -@property (nonatomic, strong) IBOutlet NSPopUpButton *rtcPopupButton; -@property (nonatomic, strong) IBOutlet NSButton *configureJoypadButton; -@property (nonatomic, strong) IBOutlet NSButton *skipButton; -@property (nonatomic, strong) IBOutlet NSMenuItem *bootROMsFolderItem; -@property (nonatomic, strong) IBOutlet NSPopUpButtonCell *bootROMsButton; -@property (nonatomic, strong) IBOutlet NSPopUpButton *rumbleModePopupButton; -@property (nonatomic, weak) IBOutlet NSSlider *temperatureSlider; -@property (nonatomic, weak) IBOutlet NSSlider *interferenceSlider; -@property (nonatomic, weak) IBOutlet NSPopUpButton *dmgPopupButton; -@property (nonatomic, weak) IBOutlet NSPopUpButton *sgbPopupButton; -@property (nonatomic, weak) IBOutlet NSPopUpButton *cgbPopupButton; -@property (nonatomic, weak) IBOutlet NSPopUpButton *preferredJoypadButton; -@property (nonatomic, weak) IBOutlet NSPopUpButton *playerListButton; -@property (nonatomic, weak) IBOutlet NSButton *autoUpdatesCheckbox; -@property (weak) IBOutlet NSSlider *volumeSlider; -@property (weak) IBOutlet NSButton *OSDCheckbox; -@property (weak) IBOutlet NSButton *screenshotFilterCheckbox; -@property (weak) IBOutlet GBPaletteEditorController *paletteEditorController; -@property (strong) IBOutlet NSWindow *paletteEditor; -@property (weak) IBOutlet NSButton *joystickMBC7Checkbox; -@property (weak) IBOutlet NSButton *mouseMBC7Checkbox; +@property IBOutlet NSTableView *controlsTableView; +@property IBOutlet NSPopUpButton *graphicsFilterPopupButton; +@property IBOutlet NSButton *analogControlsCheckbox; +@property IBOutlet NSButton *controllersFocusCheckbox; +@property IBOutlet NSButton *aspectRatioCheckbox; +@property IBOutlet NSPopUpButton *highpassFilterPopupButton; +@property IBOutlet NSPopUpButton *colorCorrectionPopupButton; +@property IBOutlet NSPopUpButton *frameBlendingModePopupButton; +@property IBOutlet NSPopUpButton *colorPalettePopupButton; +@property IBOutlet NSPopUpButton *displayBorderPopupButton; +@property IBOutlet NSPopUpButton *rewindPopupButton; +@property IBOutlet NSPopUpButton *rtcPopupButton; +@property IBOutlet NSButton *configureJoypadButton; +@property IBOutlet NSButton *skipButton; +@property IBOutlet NSMenuItem *bootROMsFolderItem; +@property IBOutlet NSPopUpButtonCell *bootROMsButton; +@property IBOutlet NSPopUpButton *rumbleModePopupButton; +@property IBOutlet NSSlider *temperatureSlider; +@property IBOutlet NSSlider *interferenceSlider; +@property IBOutlet NSPopUpButton *dmgPopupButton; +@property IBOutlet NSPopUpButton *sgbPopupButton; +@property IBOutlet NSPopUpButton *cgbPopupButton; +@property IBOutlet NSPopUpButton *preferredJoypadButton; +@property IBOutlet NSPopUpButton *playerListButton; +@property IBOutlet NSButton *autoUpdatesCheckbox; +@property IBOutlet NSSlider *volumeSlider; +@property IBOutlet NSButton *OSDCheckbox; +@property IBOutlet NSButton *screenshotFilterCheckbox; +@property IBOutlet GBPaletteEditorController *paletteEditorController; +@property IBOutlet NSWindow *paletteEditor; +@property IBOutlet NSButton *joystickMBC7Checkbox; +@property IBOutlet NSButton *mouseMBC7Checkbox; @end diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m @@ -23,6 +23,7 @@ NSPopUpButton *_rtcPopupButton; NSButton *_aspectRatioCheckbox; NSButton *_analogControlsCheckbox; + NSButton *_controllersFocusCheckbox; NSEventModifierFlags previousModifiers; NSPopUpButton *_dmgPopupButton, *_sgbPopupButton, *_cgbPopupButton; @@ -345,6 +346,12 @@ forKey:@"GBAnalogControls"]; } +- (IBAction)changeControllerFocus:(id)sender +{ + [[NSUserDefaults standardUserDefaults] setBool: [(NSButton *)sender state] == NSOnState + forKey:@"GBAllowBackgroundControllers"]; +} + - (IBAction)changeAspectRatio:(id)sender { [[NSUserDefaults standardUserDefaults] setBool: [(NSButton *)sender state] != NSOnState @@ -620,6 +627,17 @@ [_analogControlsCheckbox setState: [[NSUserDefaults standardUserDefaults] boolForKey:@"GBAnalogControls"]]; } +- (NSButton *)controllersFocusCheckbox +{ + return _controllersFocusCheckbox; +} + +- (void)setControllersFocusCheckbox:(NSButton *)controllersFocusCheckbox +{ + _controllersFocusCheckbox = controllersFocusCheckbox; + [_controllersFocusCheckbox setState: [[NSUserDefaults standardUserDefaults] boolForKey:@"GBAllowBackgroundControllers"]]; +} + - (NSButton *)aspectRatioCheckbox { return _aspectRatioCheckbox; diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m @@ -474,10 +474,21 @@ static const uint8_t workboy_vk_to_key[] = { return true; } +- (bool)allowController +{ + if ([self.window isMainWindow]) return true; + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"GBAllowBackgroundControllers"]) { + if ([(Document *)[NSApplication sharedApplication].orderedDocuments.firstObject mainWindow] == self.window) { + return true; + } + } + return false; +} + - (void)controller:(JOYController *)controller movedAxis:(JOYAxis *)axis { if (!_gb) return; - if (![self.window isMainWindow]) return; + if (![self allowController]) return; NSDictionary *mapping = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"JoyKitInstanceMapping"][controller.uniqueID]; if (!mapping) { @@ -532,7 +543,7 @@ static const uint8_t workboy_vk_to_key[] = { - (void)controller:(JOYController *)controller buttonChangedState:(JOYButton *)button { if (!_gb) return; - if (![self.window isMainWindow]) return; + if (![self allowController]) return; _mouseControlEnabled = false; if (button.type == JOYButtonTypeAxes2DEmulated && [self shouldControllerUseJoystickForMotion:controller]) return; diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib @@ -77,6 +77,7 @@ <outlet property="colorCorrectionPopupButton" destination="VEz-N4-uP6" id="EO2-Vt-JFJ"/> <outlet property="colorPalettePopupButton" destination="Iwr-eI-SD1" id="Xzc-RZ-JtV"/> <outlet property="configureJoypadButton" destination="Qa7-Z7-yfO" id="RaX-P3-oCX"/> + <outlet property="controllersFocusCheckbox" destination="I0d-Gm-KBg" id="yQ5-70-6oL"/> <outlet property="controlsTableView" destination="UDd-IJ-fxX" id="a1D-Md-yXv"/> <outlet property="delegate" destination="-2" id="ASc-vN-Zbq"/> <outlet property="displayBorderPopupButton" destination="R9D-FV-bpd" id="VfO-b4-gqH"/> @@ -611,11 +612,11 @@ <point key="canvasLocation" x="-854" y="627"/> </customView> <customView id="8TU-6J-NCg"> - <rect key="frame" x="0.0" y="0.0" width="320" height="537"/> + <rect key="frame" x="0.0" y="0.0" width="320" height="560"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <subviews> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Utu-t4-cLx"> - <rect key="frame" x="18" y="500" width="122" height="17"/> + <rect key="frame" x="18" y="523" width="122" height="17"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Control settings for" id="YqW-Ds-VIC"> <font key="font" metaFont="system"/> @@ -623,17 +624,8 @@ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> </textFieldCell> </textField> - <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zYm-Ov-RHL"> - <rect key="frame" x="18" y="157" width="273" height="17"/> - <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> - <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="When playing motion-control games:" id="sgY-3F-qld"> - <font key="font" metaFont="system"/> - <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> - <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> - </textFieldCell> - </textField> <scrollView focusRingType="none" fixedFrame="YES" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" hasHorizontalScroller="NO" hasVerticalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" verticalScrollElasticity="none" translatesAutoresizingMaskIntoConstraints="NO" id="PBp-dj-EIa"> - <rect key="frame" x="32" y="278" width="257" height="211"/> + <rect key="frame" x="32" y="301" width="257" height="211"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> <clipView key="contentView" focusRingType="none" ambiguous="YES" drawsBackground="NO" id="AMs-PO-nid"> <rect key="frame" x="1" y="1" width="255" height="209"/> @@ -691,7 +683,7 @@ </scroller> </scrollView> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fcF-wc-KwM"> - <rect key="frame" x="30" y="253" width="231" height="17"/> + <rect key="frame" x="30" y="276" width="231" height="17"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Controller for multiplayer games:" id="AJA-9b-VKI"> <font key="font" metaFont="system"/> @@ -700,7 +692,7 @@ </textFieldCell> </textField> <popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0Az-0R-oNw"> - <rect key="frame" x="42" y="220" width="250" height="26"/> + <rect key="frame" x="42" y="243" width="250" height="26"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> <popUpButtonCell key="cell" type="push" title="None" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingMiddle" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="hy8-cr-RrE" id="uEC-vN-8Jq"> <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/> @@ -716,11 +708,11 @@ </connections> </popUpButton> <box verticalHuggingPriority="750" fixedFrame="YES" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="VEc-Ed-Z6f"> - <rect key="frame" x="12" y="209" width="296" height="5"/> + <rect key="frame" x="12" y="232" width="296" height="5"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> </box> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ReM-uo-H0r"> - <rect key="frame" x="227" y="501" width="8" height="17"/> + <rect key="frame" x="227" y="524" width="8" height="17"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title=":" id="VhO-3T-glt"> <font key="font" metaFont="system"/> @@ -729,7 +721,7 @@ </textFieldCell> </textField> <popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gWx-7h-0xq"> - <rect key="frame" x="140" y="495" width="87" height="26"/> + <rect key="frame" x="140" y="518" width="87" height="26"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <popUpButtonCell key="cell" type="push" title="Player 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="TO3-R7-9HN" id="pbt-Lr-bU1"> <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/> @@ -748,7 +740,7 @@ </connections> </popUpButton> <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="RuW-Db-dzW"> - <rect key="frame" x="18" y="180" width="292" height="25"/> + <rect key="frame" x="18" y="203" width="292" height="25"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> <buttonCell key="cell" type="check" title="Analog turbo and slow-motion controls" bezelStyle="regularSquare" imagePosition="left" lineBreakMode="charWrapping" inset="2" id="Mvp-oc-N3t"> <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/> @@ -758,6 +750,26 @@ <action selector="changeAnalogControls:" target="QvC-M9-y7g" id="1xR-gY-WKo"/> </connections> </button> + <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="I0d-Gm-KBg"> + <rect key="frame" x="18" y="180" width="288" height="21"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> + <buttonCell key="cell" type="check" title="Enable controllers when in background" bezelStyle="regularSquare" imagePosition="left" lineBreakMode="charWrapping" inset="2" id="mAi-1P-aSl"> + <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/> + <font key="font" metaFont="system"/> + </buttonCell> + <connections> + <action selector="changeControllerFocus:" target="QvC-M9-y7g" id="Fmi-4C-2hg"/> + </connections> + </button> + <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zYm-Ov-RHL"> + <rect key="frame" x="18" y="157" width="273" height="17"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> + <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="When playing motion-control games:" id="sgY-3F-qld"> + <font key="font" metaFont="system"/> + <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> + <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> + </textFieldCell> + </textField> <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="i7F-1r-NkQ"> <rect key="frame" x="30" y="130" width="272" height="21"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> @@ -830,7 +842,7 @@ </connections> </button> </subviews> - <point key="canvasLocation" x="-854" y="223"/> + <point key="canvasLocation" x="-854" y="213"/> </customView> <customView id="ffn-ie-9C3"> <rect key="frame" x="0.0" y="0.0" width="320" height="95"/>

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.