Added input locking info to titlebar

This commit is contained in:
Akop Karapetyan 2019-10-28 02:48:11 -07:00
parent c77c24e443
commit 1fdafab521
5 changed files with 79 additions and 13 deletions

View File

@ -8,9 +8,12 @@
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="FBEmulatorController">
<connections>
<outlet property="accView" destination="tAE-oU-84p" id="STJ-Bl-aOY"/>
<outlet property="label" destination="r9V-Zc-ar6" id="m5W-Nb-eKU"/>
<outlet property="lockIcon" destination="e2Z-og-5sM" id="m2t-2S-SAX"/>
<outlet property="lockText" destination="faS-dc-o2e" id="Z0S-o0-j4Q"/>
<outlet property="screen" destination="NMq-dl-ima" id="DmS-4G-KTJ"/>
<outlet property="spinner" destination="tAE-oU-84p" id="Nux-fu-lkz"/>
<outlet property="spinner" destination="9M6-12-JcO" id="h8L-zo-cgm"/>
<outlet property="window" destination="iUn-Rc-9rO" id="NmU-Wm-wrs"/>
</connections>
</customObject>
@ -47,15 +50,38 @@
<point key="canvasLocation" x="130" y="-102"/>
</window>
<customView id="tAE-oU-84p">
<rect key="frame" x="0.0" y="0.0" width="24" height="16"/>
<rect key="frame" x="0.0" y="0.0" width="111" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="faS-dc-o2e">
<rect key="frame" x="18" y="5" width="46" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" controlSize="small" lineBreakMode="clipping" alignment="right" title="⌘+click" id="Hsh-02-gGV">
<font key="font" metaFont="menu" size="11"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="e2Z-og-5sM">
<rect key="frame" x="63" y="4" width="24" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="NSLockLockedTemplate" imagePosition="only" alignment="center" controlSize="small" imageScaling="proportionallyUpOrDown" inset="2" id="kDJ-ul-fJ3">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu" size="11"/>
</buttonCell>
<connections>
<action selector="activateCursorLock:" target="-2" id="gdb-de-U7o"/>
</connections>
</button>
<progressIndicator wantsLayer="YES" fixedFrame="YES" maxValue="100" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="9M6-12-JcO">
<rect key="frame" x="0.0" y="0.0" width="16" height="16"/>
<rect key="frame" x="87" y="4" width="16" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</progressIndicator>
</subviews>
<point key="canvasLocation" x="66" y="-511"/>
<point key="canvasLocation" x="69.5" y="-511"/>
</customView>
</objects>
<resources>
<image name="NSLockLockedTemplate" width="10" height="14"/>
</resources>
</document>

View File

@ -14,10 +14,15 @@
@interface FBEmulatorController : NSWindowController<FBScreenViewDelegate, FBMainThreadDelegate>
{
IBOutlet FBScreenView *screen;
IBOutlet NSView *spinner;
IBOutlet NSView *accView;
IBOutlet NSProgressIndicator *spinner;
IBOutlet NSButton *lockIcon;
IBOutlet NSTextField *lockText;
IBOutlet NSTextField *label;
}
- (IBAction) activateCursorLock:(id) sender;
- (IBAction) resetEmulation:(id) sender;
- (IBAction) togglePause:(id) sender;

View File

@ -27,7 +27,6 @@
BOOL isCursorLocked;
BOOL isCursorVisible;
BOOL isAutoPaused;
NSTitlebarAccessoryViewController *tbAccessory;
NSArray *defaultsToObserve;
}
@ -53,9 +52,15 @@
{
defaultsToObserve = @[ @"pauseWhenInactive" ];
tbAccessory = [NSTitlebarAccessoryViewController new];
tbAccessory.view = spinner;
tbAccessory.layoutAttribute = NSLayoutAttributeRight;
NSTitlebarAccessoryViewController *tba = [NSTitlebarAccessoryViewController new];
tba.view = accView;
tba.layoutAttribute = NSLayoutAttributeRight;
lockText.stringValue = NSLocalizedString(@"⌘+click", nil);
lockText.hidden = YES;
lockIcon.image = [NSImage imageNamed:@"NSLockUnlockedTemplate"];
lockIcon.enabled = NO;
spinner.hidden = YES;
[self.window addTitlebarAccessoryViewController:tba];
screen.delegate = self;
self.video.delegate = screen;
@ -243,6 +248,7 @@
screen.hidden = NO;
label.hidden = YES;
lockIcon.enabled = YES;
[self.window makeFirstResponder:screen];
}
@ -252,6 +258,7 @@
NSLog(@"gameSessionDidEnd");
screen.hidden = YES;
label.hidden = NO;
lockIcon.enabled = NO;
[self unlockCursor];
self.window.title = NSBundle.mainBundle.infoDictionary[@"CFBundleName"];
@ -259,8 +266,8 @@
- (void) driverInitDidStart
{
[spinner.subviews.firstObject startAnimation:self];
[self.window addTitlebarAccessoryViewController:tbAccessory];
[spinner startAnimation:self];
spinner.hidden = NO;
label.stringValue = NSLocalizedString(@"Please wait...", nil);
self.window.title = NSLocalizedString(@"Loading...", nil);
@ -269,8 +276,8 @@
- (void) driverInitDidEnd:(NSString *) name
success:(BOOL) success
{
[spinner.subviews.firstObject stopAnimation:self];
[tbAccessory removeFromParentViewController];
[spinner stopAnimation:self];
spinner.hidden = YES;
if (success) {
label.stringValue = NSLocalizedString(@"Starting...", nil);
@ -330,6 +337,12 @@
animate:YES];
}
- (void) activateCursorLock:(id) sender
{
if (!isCursorLocked)
[self lockCursor];
}
#pragma mark - Private
- (void) resizeFrame:(NSSize) newSize
@ -381,7 +394,16 @@
{
if (!isCursorLocked) {
CGAssociateMouseAndMouseCursorPosition(false);
CGFloat offset = self.window.screen.frame.size.height + self.window.screen.frame.origin.y;
NSPoint centerScreen = [self.window convertPointToScreen:NSMakePoint(NSMidX(screen.bounds),
NSMidY(screen.bounds))];
NSPoint screenCoords = NSMakePoint(centerScreen.x, offset - centerScreen.y);
CGWarpMouseCursorPosition(NSPointToCGPoint(screenCoords));
isCursorLocked = YES;
lockIcon.image = [NSImage imageNamed:@"NSLockLockedTemplate"];
lockText.hidden = NO;
#ifdef DEBUG
NSLog(@"lockCursor");
#endif
@ -395,6 +417,8 @@
if (isCursorLocked) {
CGAssociateMouseAndMouseCursorPosition(true);
isCursorLocked = NO;
lockIcon.image = [NSImage imageNamed:@"NSLockUnlockedTemplate"];
lockText.hidden = YES;
#ifdef DEBUG
NSLog(@"unlockCursor");
#endif

View File

@ -18,6 +18,7 @@
@property uint8 mouseButtonStates;
- (void) simReset;
- (BOOL) usesMouse;
- (void) keyDown:(NSEvent *) theEvent;
- (void) keyUp:(NSEvent *) theEvent;
- (void) flagsChanged:(NSEvent *) theEvent;

View File

@ -185,6 +185,16 @@ static unsigned char simKeyState[256];
{
}
- (BOOL) usesMouse
{
struct BurnInputInfo bii;
for (int i = 0; BurnDrvGetInputInfo(&bii, i) == 0; i++)
if (bii.nType == BIT_ANALOG_REL && strstr(bii.szName, "mouse") == 0)
return YES;
return NO;
}
@end
#pragma mark - FinalBurn