From 52a9f02ab37ced002f7c3b79f069c4f34c519a08 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 21 Aug 2020 18:38:02 -0400 Subject: [PATCH] updates --- MA2ME.xcodeproj/project.pbxproj | 18 +++ MA2ME/AppDelegate.m | 29 +++- MA2ME/Base.lproj/MainMenu.xib | 9 +- MA2ME/MA2ME/Base.lproj/MediaView.xib | 63 ++++++++ MA2ME/MA2ME/Base.lproj/SlotView.xib | 4 +- MA2ME/MediaViewController.h | 17 +++ MA2ME/MediaViewController.m | 221 +++++++++++++++++++++++++++ SlotViewController.m | 13 +- 8 files changed, 360 insertions(+), 14 deletions(-) create mode 100644 MA2ME/MA2ME/Base.lproj/MediaView.xib create mode 100644 MA2ME/MediaViewController.h create mode 100644 MA2ME/MediaViewController.m diff --git a/MA2ME.xcodeproj/project.pbxproj b/MA2ME.xcodeproj/project.pbxproj index 987b352..f85a9fa 100644 --- a/MA2ME.xcodeproj/project.pbxproj +++ b/MA2ME.xcodeproj/project.pbxproj @@ -31,6 +31,8 @@ B64979BA24EEC2DA008ABD20 /* las128ex.plist in Resources */ = {isa = PBXBuildFile; fileRef = B64979A324EEC2D9008ABD20 /* las128ex.plist */; }; B64979BB24EEC2DA008ABD20 /* apple2jp.plist in Resources */ = {isa = PBXBuildFile; fileRef = B64979A424EEC2D9008ABD20 /* apple2jp.plist */; }; B64979BC24EEC2DA008ABD20 /* apple2ee.plist in Resources */ = {isa = PBXBuildFile; fileRef = B64979A524EEC2D9008ABD20 /* apple2ee.plist */; }; + B64979BF24EF5AEA008ABD20 /* MediaView.xib in Resources */ = {isa = PBXBuildFile; fileRef = B64979BD24EF5AEA008ABD20 /* MediaView.xib */; }; + B64979C224EF6703008ABD20 /* MediaViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B64979C124EF6703008ABD20 /* MediaViewController.m */; }; B64E15A624E9B34700E8AD3D /* Models.plist in Resources */ = {isa = PBXBuildFile; fileRef = B64E15A424E9B34700E8AD3D /* Models.plist */; }; B64E15A924EA1D5300E8AD3D /* ROMBrowserDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B64E15A824EA1D5300E8AD3D /* ROMBrowserDelegate.m */; }; B64E15AC24EA1FD400E8AD3D /* SlotBrowserDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B64E15AB24EA1FD400E8AD3D /* SlotBrowserDelegate.m */; }; @@ -69,6 +71,9 @@ B64979A324EEC2D9008ABD20 /* las128ex.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = las128ex.plist; sourceTree = ""; }; B64979A424EEC2D9008ABD20 /* apple2jp.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = apple2jp.plist; sourceTree = ""; }; B64979A524EEC2D9008ABD20 /* apple2ee.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = apple2ee.plist; sourceTree = ""; }; + B64979BE24EF5AEA008ABD20 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = MA2ME/Base.lproj/MediaView.xib; sourceTree = ""; }; + B64979C024EF6703008ABD20 /* MediaViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaViewController.h; sourceTree = ""; }; + B64979C124EF6703008ABD20 /* MediaViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MediaViewController.m; sourceTree = ""; }; B64E15A524E9B34700E8AD3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Base; path = Base.lproj/Models.plist; sourceTree = ""; }; B64E15A724EA1D5300E8AD3D /* ROMBrowserDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ROMBrowserDelegate.h; sourceTree = ""; }; B64E15A824EA1D5300E8AD3D /* ROMBrowserDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ROMBrowserDelegate.m; sourceTree = ""; }; @@ -165,6 +170,8 @@ children = ( B6BA257E24E99BE9005FB8FF /* AppDelegate.h */, B6BA257F24E99BE9005FB8FF /* AppDelegate.m */, + B64979C024EF6703008ABD20 /* MediaViewController.h */, + B64979C124EF6703008ABD20 /* MediaViewController.m */, B6BA258124E99BEB005FB8FF /* Assets.xcassets */, B64E15A724EA1D5300E8AD3D /* ROMBrowserDelegate.h */, B64E15A824EA1D5300E8AD3D /* ROMBrowserDelegate.m */, @@ -176,6 +183,7 @@ B6BA258924E99BEB005FB8FF /* MA2ME.entitlements */, B6BA258324E99BEB005FB8FF /* MainMenu.xib */, B64E15B624EC912200E8AD3D /* SlotView.xib */, + B64979BD24EF5AEA008ABD20 /* MediaView.xib */, ); path = MA2ME; sourceTree = ""; @@ -254,6 +262,7 @@ B64979B324EEC2DA008ABD20 /* laser128.plist in Resources */, B64979BC24EEC2DA008ABD20 /* apple2ee.plist in Resources */, B64979B724EEC2DA008ABD20 /* apple2cp.plist in Resources */, + B64979BF24EF5AEA008ABD20 /* MediaView.xib in Resources */, B64E15B824EC912200E8AD3D /* SlotView.xib in Resources */, B64979B924EEC2DA008ABD20 /* apple2eefr.plist in Resources */, B64979B024EEC2DA008ABD20 /* apple2gs.plist in Resources */, @@ -277,6 +286,7 @@ B6BA258824E99BEB005FB8FF /* main.m in Sources */, B64E15AC24EA1FD400E8AD3D /* SlotBrowserDelegate.m in Sources */, B64E15A924EA1D5300E8AD3D /* ROMBrowserDelegate.m in Sources */, + B64979C224EF6703008ABD20 /* MediaViewController.m in Sources */, B60A6E1424EE0AE2004B7EEF /* FlippedView.m in Sources */, B6BA258024E99BE9005FB8FF /* AppDelegate.m in Sources */, B65593B124ECB61800722E0C /* SlotViewController.m in Sources */, @@ -286,6 +296,14 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ + B64979BD24EF5AEA008ABD20 /* MediaView.xib */ = { + isa = PBXVariantGroup; + children = ( + B64979BE24EF5AEA008ABD20 /* Base */, + ); + name = MediaView.xib; + sourceTree = ""; + }; B64E15A424E9B34700E8AD3D /* Models.plist */ = { isa = PBXVariantGroup; children = ( diff --git a/MA2ME/AppDelegate.m b/MA2ME/AppDelegate.m index 5e57a72..583f0b4 100644 --- a/MA2ME/AppDelegate.m +++ b/MA2ME/AppDelegate.m @@ -7,18 +7,19 @@ // #import "AppDelegate.h" -#import "SlotBrowserDelegate.h" #import "SlotViewController.h" +#import "MediaViewController.h" @interface AppDelegate () @property (weak) IBOutlet NSWindow *window; -@property (strong) IBOutlet SlotBrowserDelegate *slotDelegate; @property (strong) IBOutlet SlotViewController *slotController; +@property (strong) IBOutlet MediaViewController *mediaController; @property (weak) IBOutlet NSView *modelView; @property (weak) IBOutlet NSView *slotView; +@property (weak) IBOutlet NSView *mediaView; /* kvo */ @property NSString *commandLine; @@ -80,6 +81,7 @@ static NSString *kMyContext = @"kMyContext"; #endif [_slotView addSubview: [_slotController view]]; + [_mediaView addSubview: [_mediaController view]]; [self addObserver: self forKeyPath: @"mameROM" options:0 context: (__bridge void * _Nullable)(kMyContext)]; @@ -87,6 +89,8 @@ static NSString *kMyContext = @"kMyContext"; [self addObserver: self forKeyPath: @"mameSquarePixels" options:0 context: (__bridge void * _Nullable)(kMyContext)]; [self addObserver: self forKeyPath: @"mameDebug" options:0 context: (__bridge void * _Nullable)(kMyContext)]; [self addObserver: self forKeyPath: @"mameNoThrottle" options:0 context: (__bridge void * _Nullable)(kMyContext)]; + + [_slotController addObserver: self forKeyPath: @"args" options: 0 context: (__bridge void * _Nullable)(kMyContext)]; [self buildCommandLine]; } @@ -102,7 +106,7 @@ static NSString *kMyContext = @"kMyContext"; -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (context == (__bridge void *)kMyContext && object == self) { + if (context == (__bridge void *)kMyContext) { [self buildCommandLine]; } else { [super observeValueForKeyPath: keyPath ofObject: object change: change context: context]; @@ -126,23 +130,35 @@ static NSString *kMyContext = @"kMyContext"; if (_mameWindow) [argv addObject: @"-window"]; // -nounevenstretch -video soft - if (_mameWindow && _mameSquarePixels) { + [argv addObject: @"-skip_gameinfo"]; + if (_mameWindow && _mameSquarePixels) { + NSSize screen = [_slotController resolution]; + + NSString *res = [NSString stringWithFormat: @"%ux%u", (unsigned)screen.width, (unsigned)screen.height]; + [argv addObject: @"-nomax"]; + [argv addObject: @"-nounevenstretch"]; + if ([_mameROM hasPrefix: @"apple2gs"]) { [argv addObject: @"-resolution"]; - [argv addObject: @"704x462"]; + [argv addObject: res]; // @"704x462"]; [argv addObject: @"-video"]; [argv addObject: @"soft"]; [argv addObject: @"-aspect"]; [argv addObject: @"704:462"]; } else { [argv addObject: @"-resolution"]; - [argv addObject: @"560x384"]; + [argv addObject: res]; // @"560x384"]; } } + NSArray *args = [_slotController args]; + if ([args count]) { + [argv addObjectsFromArray: args]; + } + if (_mameNoThrottle) [argv addObject: @"-nothrottle"]; [self setCommandLine: [argv componentsJoinedByString:@" "]]; @@ -157,7 +173,6 @@ static NSString *kMyContext = @"kMyContext"; // [self buildCommandLine]; - [_slotDelegate setModel: model]; [_slotController setModel: model]; } diff --git a/MA2ME/Base.lproj/MainMenu.xib b/MA2ME/Base.lproj/MainMenu.xib index ed0d57d..d941b7c 100644 --- a/MA2ME/Base.lproj/MainMenu.xib +++ b/MA2ME/Base.lproj/MainMenu.xib @@ -15,9 +15,10 @@ + + - @@ -773,11 +774,15 @@ + + + + - + diff --git a/MA2ME/MA2ME/Base.lproj/MediaView.xib b/MA2ME/MA2ME/Base.lproj/MediaView.xib new file mode 100644 index 0000000..8131ff1 --- /dev/null +++ b/MA2ME/MA2ME/Base.lproj/MediaView.xib @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MA2ME/MA2ME/Base.lproj/SlotView.xib b/MA2ME/MA2ME/Base.lproj/SlotView.xib index 467b9bf..1d3bd73 100644 --- a/MA2ME/MA2ME/Base.lproj/SlotView.xib +++ b/MA2ME/MA2ME/Base.lproj/SlotView.xib @@ -182,7 +182,9 @@ - + + + diff --git a/MA2ME/MediaViewController.h b/MA2ME/MediaViewController.h new file mode 100644 index 0000000..81f354f --- /dev/null +++ b/MA2ME/MediaViewController.h @@ -0,0 +1,17 @@ +// +// MediaViewController.h +// MA2ME +// +// Created by Kelvin Sherlock on 8/20/2020. +// Copyright © 2020 Kelvin Sherlock. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface MediaViewController : NSViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/MA2ME/MediaViewController.m b/MA2ME/MediaViewController.m new file mode 100644 index 0000000..5d43108 --- /dev/null +++ b/MA2ME/MediaViewController.m @@ -0,0 +1,221 @@ +// +// MediaViewController.m +// MA2ME +// +// Created by Kelvin Sherlock on 8/20/2020. +// Copyright © 2020 Kelvin Sherlock. All rights reserved. +// + +#import "MediaViewController.h" + +@interface MediaCategory : NSObject { + +} +@property NSInteger validCount; +@property NSArray *children; // URLs? +@property NSString *title; + +-(NSInteger)count; +-(id)objectAtIndex:(NSInteger)index; +-(BOOL)isGroupItem; +@end + +@implementation MediaCategory + +-(instancetype)initWithTitle: (NSString *)title { + [self setTitle: title]; + return self; +} +-(NSInteger) count { + return [_children count]; +} + +-(id)objectAtIndex:(NSInteger)index { + return [_children objectAtIndex: index]; +} + +-(BOOL)isGroupItem { + return YES; +} + +-(BOOL)isExpandable { + return YES; +} + + +-(void)prepareCell: (id)cell { + [(NSTextFieldCell *)cell setTitle: _title]; +} +@end + + +@interface MediaItem : NSObject { + +} +@property NSURL *url; + +-(NSInteger)count; +-(id)objectAtIndex:(NSInteger)index; +-(BOOL)isGroupItem; +@end + +@implementation MediaItem + +-(instancetype)initWithURL: (NSURL *)url { + [self setUrl: url]; + return self; +} + +-(NSInteger) count { + return 0; +} + +-(id)objectAtIndex:(NSInteger)index { + return nil; +} + +-(BOOL)isGroupItem { + return NO; +} + +-(BOOL)isExpandable { + return NO; +} + +-(void)prepareCell: (id)cell { + [(NSTextFieldCell *)cell setTitle: @"xxx"]; +} + + + +@end + +@interface MediaViewController () { + + MediaCategory *_data[4]; + NSArray *_root; +} + +@end + +@implementation MediaViewController + +-(void)awakeFromNib { + + MediaCategory *a, *b, *c, *d; + + a = [[MediaCategory alloc] initWithTitle: @"5.25\" Floppies"]; + b = [[MediaCategory alloc] initWithTitle: @"3.5\" Floppies"]; + c = [[MediaCategory alloc] initWithTitle: @"Hard Drives"]; + d = [[MediaCategory alloc] initWithTitle: @"Casettes"]; + + + _data[0] = a; + _data[1] = b; + _data[2] = c; + _data[3] = d; + _root = @[a,b,c,d]; + + + [a setChildren: @[ + [MediaItem new], + [MediaItem new], + ]]; + + [b setChildren: @[ + [MediaItem new], + [MediaItem new], + ]]; + + [c setChildren: @[ + [MediaItem new], + [MediaItem new], + ]]; + +} + +- (void)viewDidLoad { + + [super viewDidLoad]; + + //NSOutlineView *view = [self view]; + //[view expandItem: nil expandChildren: YES]; + // Do view setup here. +} + +#pragma mark - NSOutlineViewDelegate + +#if 0 +- (void)outlineView:(NSOutlineView *)outlineView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row { + +} + +- (void)outlineView:(NSOutlineView *)outlineView didRemoveRowView:(NSTableRowView *)rowView forRow:(NSInteger)row { + +} + +//- (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item; + +- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item { + + //NSView *v = [outlineView makeViewWithIdentifier:<#(nonnull NSUserInterfaceItemIdentifier)#> owner: self]; + + NSView *v = [[NSView alloc]initWithFrame: NSZeroRect]; + + return v; +} +#endif + +- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { + return [item isExpandable]; +} + +- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item { + return [item isGroupItem]; +} + + + +- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item { + [item prepareCell: cell]; +} + +- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item { + return YES; +} + +- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowCellExpansionForTableColumn:(NSTableColumn *)tableColumn item:(id)item { + return YES; +} + + + +- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item { + return nil; +} + + + + +#pragma mark - NSOutlineViewDataSource + +// nil item indicates the root. + + +- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item { + if (item == nil) + return [_root count]; + return [item count]; +} + +- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { + + if (item == nil) { + return [_root objectAtIndex: index]; + } + return [item objectAtIndex: index]; +} + + + +@end diff --git a/SlotViewController.m b/SlotViewController.m index bf82343..7a1a4f3 100644 --- a/SlotViewController.m +++ b/SlotViewController.m @@ -202,11 +202,11 @@ static void SetDefaultMenu(NSArray *items, NSPopUpButton *button) { return; } - NSDictionary *r = [d objectForKey: @"resolution"]; + NSArray *r = [d objectForKey: @"Resolution"]; NSSize res = NSMakeSize(0, 0); if (r) { - res.height = [(NSNumber *)[r objectForKey: @"height"] doubleValue]; - res.width = [(NSNumber *)[r objectForKey: @"width"] doubleValue]; + res.width = [(NSNumber *)[r objectAtIndex: 0 /*@"width"*/] doubleValue]; + res.height = [(NSNumber *)[r objectAtIndex: 1 /*@"height"*/] doubleValue]; } [self setResolution: res]; @@ -244,9 +244,14 @@ static void SetDefaultMenu(NSArray *items, NSPopUpButton *button) { // NSDictionary *o = [[sender selectedItem] representedObject]; - [self setMemory: [o objectForKey: @"description"]]; + NSString *title = [o objectForKey: @"description"]; + [self setMemory: title]; [self setMemoryBytes: [(NSNumber *)[o objectForKey: @"value"] unsignedIntValue]]; + // if pull-down menu + if ([sender pullsDown]) + [sender setTitle: title]; + [self rebuildArgs]; }