From 8de6cd3f44c88e2e6ad27f0f9d75761271c3d4c0 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 22 Jul 2019 17:18:31 -0400 Subject: [PATCH] Ensures that ROM files can be dragged and dropped into Swift. Also adjusts the main window background colour, better to bridge the time between selecting a machine and it starting. --- .../Clock Signal.xcodeproj/project.pbxproj | 10 ++++- .../Base.lproj/MachineDocument.xib | 13 ++++-- .../ClockSignal-Bridging-Header.h | 3 +- .../Documents/MachineDocument.swift | 9 ++++- .../ROMRequester/CSROMReceiverView.h | 27 +++++++++++++ .../ROMRequester/CSROMReceiverView.m | 40 +++++++++++++++++++ .../ROMRequester/ROMRequester.xib | 7 ++-- 7 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 OSBindings/Mac/Clock Signal/ROMRequester/CSROMReceiverView.h create mode 100644 OSBindings/Mac/Clock Signal/ROMRequester/CSROMReceiverView.m diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 09108b7b7..aaef85a1f 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -666,8 +666,9 @@ 4BD67DD0209BF27B00AB2146 /* Encoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BD67DCE209BF27B00AB2146 /* Encoder.cpp */; }; 4BD67DD1209BF27B00AB2146 /* Encoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BD67DCE209BF27B00AB2146 /* Encoder.cpp */; }; 4BDA00DA22E60EE300AC3CD0 /* ROMRequester.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4BDA00D922E60EE300AC3CD0 /* ROMRequester.xib */; }; - 4BDA00DC22E622BF00AC3CD0 /* ROMImages in Resources */ = {isa = PBXBuildFile; fileRef = 4BC9DF441D044FCA00F44158 /* ROMImages */; }; 4BDA00DD22E622C200AC3CD0 /* ROMImages in Resources */ = {isa = PBXBuildFile; fileRef = 4BC9DF441D044FCA00F44158 /* ROMImages */; }; + 4BDA00E022E644AF00AC3CD0 /* CSROMReceiverView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BDA00DF22E644AF00AC3CD0 /* CSROMReceiverView.m */; }; + 4BDA00E122E64ABE00AC3CD0 /* ROMImages in Resources */ = {isa = PBXBuildFile; fileRef = 4BC9DF441D044FCA00F44158 /* ROMImages */; }; 4BDB61EB2032806E0048AF91 /* CSAtari2600.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B2A539A1D117D36003C6002 /* CSAtari2600.mm */; }; 4BDB61EC203285AE0048AF91 /* Atari2600OptionsPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE21F1DA19D7C0090D3CE /* Atari2600OptionsPanel.swift */; }; 4BDDBA991EF3451200347E61 /* Z80MachineCycleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BDDBA981EF3451200347E61 /* Z80MachineCycleTests.swift */; }; @@ -1476,6 +1477,8 @@ 4BD67DCF209BF27B00AB2146 /* Encoder.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Encoder.hpp; sourceTree = ""; }; 4BD9137D1F311BC5009BCF85 /* i8255.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = i8255.hpp; path = 8255/i8255.hpp; sourceTree = ""; }; 4BDA00D922E60EE300AC3CD0 /* ROMRequester.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ROMRequester.xib; sourceTree = ""; }; + 4BDA00DE22E644AF00AC3CD0 /* CSROMReceiverView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSROMReceiverView.h; sourceTree = ""; }; + 4BDA00DF22E644AF00AC3CD0 /* CSROMReceiverView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CSROMReceiverView.m; sourceTree = ""; }; 4BDB3D8522833321002D3CEE /* Keyboard.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Keyboard.hpp; sourceTree = ""; }; 4BDCC5F81FB27A5E001220C5 /* ROMMachine.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ROMMachine.hpp; sourceTree = ""; }; 4BDDBA981EF3451200347E61 /* Z80MachineCycleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Z80MachineCycleTests.swift; sourceTree = ""; }; @@ -3305,6 +3308,8 @@ isa = PBXGroup; children = ( 4BDA00D922E60EE300AC3CD0 /* ROMRequester.xib */, + 4BDA00DE22E644AF00AC3CD0 /* CSROMReceiverView.h */, + 4BDA00DF22E644AF00AC3CD0 /* CSROMReceiverView.m */, ); path = ROMRequester; sourceTree = ""; @@ -3567,7 +3572,7 @@ 4B79E4441E3AF38600141F11 /* cassette.png in Resources */, 4BB73EAC1B587A5100552FC2 /* MainMenu.xib in Resources */, 4B8FE21D1DA19D5F0090D3CE /* QuickLoadCompositeOptions.xib in Resources */, - 4BDA00DC22E622BF00AC3CD0 /* ROMImages in Resources */, + 4BDA00E122E64ABE00AC3CD0 /* ROMImages in Resources */, 4B79E4461E3AF38600141F11 /* floppy525.png in Resources */, 4BEEE6BD20DC72EB003723BF /* CompositeOptions.xib in Resources */, 4B1497981EE4B97F00CE2596 /* ZX8081Options.xib in Resources */, @@ -4134,6 +4139,7 @@ 4B4518851F75E91A00926311 /* DiskController.cpp in Sources */, 4B8334841F5DA0360097E338 /* Z80Storage.cpp in Sources */, 4BA61EB01D91515900B3C876 /* NSData+StdVector.mm in Sources */, + 4BDA00E022E644AF00AC3CD0 /* CSROMReceiverView.m in Sources */, 4BD191F42191180E0042E144 /* ScanTarget.cpp in Sources */, 4BCD634922D6756400F567F1 /* MacintoshDoubleDensityDrive.cpp in Sources */, 4B0F94FE208C1A1600FE41D9 /* NIB.cpp in Sources */, diff --git a/OSBindings/Mac/Clock Signal/Base.lproj/MachineDocument.xib b/OSBindings/Mac/Clock Signal/Base.lproj/MachineDocument.xib index b5225926c..0ed43edf8 100644 --- a/OSBindings/Mac/Clock Signal/Base.lproj/MachineDocument.xib +++ b/OSBindings/Mac/Clock Signal/Base.lproj/MachineDocument.xib @@ -1,8 +1,8 @@ - + - + @@ -14,7 +14,7 @@ - + @@ -25,7 +25,7 @@ - @@ -36,6 +36,11 @@ + + + + + diff --git a/OSBindings/Mac/Clock Signal/ClockSignal-Bridging-Header.h b/OSBindings/Mac/Clock Signal/ClockSignal-Bridging-Header.h index 314208601..58bd8225d 100644 --- a/OSBindings/Mac/Clock Signal/ClockSignal-Bridging-Header.h +++ b/OSBindings/Mac/Clock Signal/ClockSignal-Bridging-Header.h @@ -10,8 +10,9 @@ #import "CSStaticAnalyser.h" -#import "CSOpenGLView.h" #import "CSAudioQueue.h" +#import "CSOpenGLView.h" +#import "CSROMReceiverView.h" #import "CSBestEffortUpdater.h" #import "CSJoystickManager.h" diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index a102cd546..57959a255 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -16,7 +16,8 @@ class MachineDocument: CSOpenGLViewDelegate, CSOpenGLViewResponderDelegate, CSBestEffortUpdaterDelegate, - CSAudioQueueDelegate + CSAudioQueueDelegate, + CSROMReciverViewDelegate { fileprivate let actionLock = NSLock() fileprivate let drawLock = NSLock() @@ -323,9 +324,11 @@ class MachineDocument: // MARK: User ROM provision. @IBOutlet var romRequesterPanel: NSWindow? @IBOutlet var romRequesterText: NSTextField? + @IBOutlet var romReceiverView: CSROMReceiverView? func requestRoms(missingROMs: NSMutableArray) { // Load the ROM requester dialogue. Bundle.main.loadNibNamed("ROMRequester", owner: self, topLevelObjects: nil) + self.romReceiverView!.delegate = self // Fill in the missing details; first build a list of all the individual // line items. @@ -361,6 +364,10 @@ class MachineDocument: close() } + func romReceiverView(_ view: CSROMReceiverView, didReceiveFileAt URL: URL) { + Swift.print("Should test " + URL.absoluteString) + } + // MARK: Joystick-via-the-keyboard selection @IBAction func useKeyboardAsKeyboard(_ sender: NSMenuItem?) { machine.inputMode = .keyboard diff --git a/OSBindings/Mac/Clock Signal/ROMRequester/CSROMReceiverView.h b/OSBindings/Mac/Clock Signal/ROMRequester/CSROMReceiverView.h new file mode 100644 index 000000000..9a489c2dd --- /dev/null +++ b/OSBindings/Mac/Clock Signal/ROMRequester/CSROMReceiverView.h @@ -0,0 +1,27 @@ +// +// CSROMReceiverView.h +// Clock Signal +// +// Created by Thomas Harte on 22/07/2019. +// Copyright © 2019 Thomas Harte. All rights reserved. +// + +#import + +@class CSROMReceiverView; + +@protocol CSROMReciverViewDelegate +/*! + Announces receipt of a file by drag and drop to the delegate. + @param view The view making the request. + @param URL The file URL of the received file. +*/ +- (void)romReceiverView:(nonnull CSROMReceiverView *)view didReceiveFileAtURL:(nonnull NSURL *)URL; + +@end + +@interface CSROMReceiverView : NSView + +@property(nonatomic, weak, nullable) id delegate; + +@end diff --git a/OSBindings/Mac/Clock Signal/ROMRequester/CSROMReceiverView.m b/OSBindings/Mac/Clock Signal/ROMRequester/CSROMReceiverView.m new file mode 100644 index 000000000..cf1af86ec --- /dev/null +++ b/OSBindings/Mac/Clock Signal/ROMRequester/CSROMReceiverView.m @@ -0,0 +1,40 @@ +// +// CSROMReceiverView.m +// Clock Signal +// +// Created by Thomas Harte on 22/07/2019. +// Copyright © 2019 Thomas Harte. All rights reserved. +// + +#import "CSROMReceiverView.h" + +@interface CSROMReceiverView () +@end + + +@implementation CSROMReceiverView + +- (void)awakeFromNib { + [super awakeFromNib]; + + // Accept file URLs by drag and drop. + [self registerForDraggedTypes:@[(__bridge NSString *)kUTTypeFileURL]]; +} + +#pragma mark - NSDraggingDestination + +- (BOOL)performDragOperation:(id )sender { + // Just forward the URLs. + for(NSPasteboardItem *item in [[sender draggingPasteboard] pasteboardItems]) { + NSURL *URL = [NSURL URLWithString:[item stringForType:(__bridge NSString *)kUTTypeFileURL]]; + [self.delegate romReceiverView:self didReceiveFileAtURL:URL]; + } + return YES; +} + +- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender { + // The emulator will take a copy of any deposited ROM files. + return NSDragOperationCopy; +} + +@end diff --git a/OSBindings/Mac/Clock Signal/ROMRequester/ROMRequester.xib b/OSBindings/Mac/Clock Signal/ROMRequester/ROMRequester.xib index 9153b1bdb..ca28efdaf 100644 --- a/OSBindings/Mac/Clock Signal/ROMRequester/ROMRequester.xib +++ b/OSBindings/Mac/Clock Signal/ROMRequester/ROMRequester.xib @@ -8,6 +8,7 @@ + @@ -19,13 +20,13 @@ - + - + - + Clock Signal requires you to provide images of the system ROMs for this machine. They will be stored permanently; you need do this only once.

Please drag and drop the following over this view: