diff --git a/Inputs/QuadratureMouse/QuadratureMouse.cpp b/Inputs/QuadratureMouse/QuadratureMouse.cpp deleted file mode 100644 index 111c62ec5..000000000 --- a/Inputs/QuadratureMouse/QuadratureMouse.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// QuadratureMouse.cpp -// Clock Signal -// -// Created by Thomas Harte on 11/06/2019. -// Copyright © 2019 Thomas Harte. All rights reserved. -// - -#include "QuadratureMouse.hpp" diff --git a/Machines/Apple/Macintosh/Macintosh.cpp b/Machines/Apple/Macintosh/Macintosh.cpp index 7b77edab9..26cbdfd0a 100644 --- a/Machines/Apple/Macintosh/Macintosh.cpp +++ b/Machines/Apple/Macintosh/Macintosh.cpp @@ -353,8 +353,8 @@ template class ConcreteMachin } private: - Inputs::Mouse *get_mouse() override { - return &mouse_; + Inputs::Mouse &get_mouse() override { + return mouse_; } struct IWM { diff --git a/Machines/MouseMachine.hpp b/Machines/MouseMachine.hpp index 7b4ce9a9d..e9e235aab 100644 --- a/Machines/MouseMachine.hpp +++ b/Machines/MouseMachine.hpp @@ -15,7 +15,7 @@ namespace MouseMachine { class Machine { public: - virtual Inputs::Mouse *get_mouse() = 0; + virtual Inputs::Mouse &get_mouse() = 0; }; } diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index ed7eee384..446546b3f 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -295,8 +295,6 @@ 4B8FE21D1DA19D5F0090D3CE /* QuickLoadCompositeOptions.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B8FE2171DA19D5F0090D3CE /* QuickLoadCompositeOptions.xib */; }; 4B8FE2221DA19FB20090D3CE /* MachinePanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE2211DA19FB20090D3CE /* MachinePanel.swift */; }; 4B8FE2271DA1DE2D0090D3CE /* NSBundle+DataResource.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE2261DA1DE2D0090D3CE /* NSBundle+DataResource.m */; }; - 4B92294722B0554800A1458F /* QuadratureMouse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B92294522B0554800A1458F /* QuadratureMouse.cpp */; }; - 4B92294822B0554800A1458F /* QuadratureMouse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B92294522B0554800A1458F /* QuadratureMouse.cpp */; }; 4B924E991E74D22700B76AF1 /* AtariStaticAnalyserTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B924E981E74D22700B76AF1 /* AtariStaticAnalyserTests.mm */; }; 4B9252CE1E74D28200B76AF1 /* Atari ROMs in Resources */ = {isa = PBXBuildFile; fileRef = 4B9252CD1E74D28200B76AF1 /* Atari ROMs */; }; 4B92EACA1B7C112B00246143 /* 6502TimingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B92EAC91B7C112B00246143 /* 6502TimingTests.swift */; }; @@ -1046,8 +1044,7 @@ 4B8FE2261DA1DE2D0090D3CE /* NSBundle+DataResource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+DataResource.m"; sourceTree = ""; }; 4B92294222B04A3D00A1458F /* MouseMachine.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = MouseMachine.hpp; sourceTree = ""; }; 4B92294422B04ACB00A1458F /* Mouse.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Mouse.hpp; sourceTree = ""; }; - 4B92294522B0554800A1458F /* QuadratureMouse.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = QuadratureMouse.cpp; path = QuadratureMouse/QuadratureMouse.cpp; sourceTree = ""; }; - 4B92294622B0554800A1458F /* QuadratureMouse.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = QuadratureMouse.hpp; path = QuadratureMouse/QuadratureMouse.hpp; sourceTree = ""; }; + 4B92294A22B064FD00A1458F /* QuadratureMouse.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = QuadratureMouse.hpp; sourceTree = ""; }; 4B924E981E74D22700B76AF1 /* AtariStaticAnalyserTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AtariStaticAnalyserTests.mm; sourceTree = ""; }; 4B9252CD1E74D28200B76AF1 /* Atari ROMs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "Atari ROMs"; sourceTree = ""; }; 4B92EAC91B7C112B00246143 /* 6502TimingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 6502TimingTests.swift; sourceTree = ""; }; @@ -2309,8 +2306,7 @@ 4B70412A1F92C2A700735E45 /* Joystick.hpp */, 4B86E25A1F8C628F006FAA45 /* Keyboard.hpp */, 4B92294422B04ACB00A1458F /* Mouse.hpp */, - 4B92294522B0554800A1458F /* QuadratureMouse.cpp */, - 4B92294622B0554800A1458F /* QuadratureMouse.hpp */, + 4B92294922B064FD00A1458F /* QuadratureMouse */, ); name = Inputs; path = ../../Inputs; @@ -2503,6 +2499,14 @@ path = Implementation; sourceTree = ""; }; + 4B92294922B064FD00A1458F /* QuadratureMouse */ = { + isa = PBXGroup; + children = ( + 4B92294A22B064FD00A1458F /* QuadratureMouse.hpp */, + ); + path = QuadratureMouse; + sourceTree = ""; + }; 4B9F11C72272375400701480 /* QL Startup */ = { isa = PBXGroup; children = ( @@ -3821,7 +3825,6 @@ 4B055ACB1FAE9AFB0060FFFF /* SerialBus.cpp in Sources */, 4B055AA41FAE85E50060FFFF /* DigitalPhaseLockedLoop.cpp in Sources */, 4B055A9B1FAE85DA0060FFFF /* AcornADF.cpp in Sources */, - 4B92294822B0554800A1458F /* QuadratureMouse.cpp in Sources */, 4B0E04F11FC9EA9500F43484 /* MSX.cpp in Sources */, 4B055AD51FAE9B0B0060FFFF /* Video.cpp in Sources */, 4B894521201967B4007DE474 /* StaticAnalyser.cpp in Sources */, @@ -4038,7 +4041,6 @@ 4BCE0060227D39AB000CA200 /* Video.cpp in Sources */, 4B4518A51F75FD1C00926311 /* SSD.cpp in Sources */, 4B55CE5F1C3B7D960093A61B /* MachineDocument.swift in Sources */, - 4B92294722B0554800A1458F /* QuadratureMouse.cpp in Sources */, 4B2B3A4C1F9B8FA70062DABF /* MemoryFuzzer.cpp in Sources */, 4B7913CC1DFCD80E00175A82 /* Video.cpp in Sources */, 4B4518831F75E91A00926311 /* PCMTrack.cpp in Sources */, diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index 0561eea8a..c4b42aa0a 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -286,12 +286,21 @@ class MachineDocument: } func mouseMoved(_ event: NSEvent) { + if let machine = self.machine { + machine.addMouseMotionX(event.deltaX, y: event.deltaY) + } } func mouseUp(_ event: NSEvent) { + if let machine = self.machine { + machine.setMouseButton(Int32(event.buttonNumber), isPressed: false) + } } func mouseDown(_ event: NSEvent) { + if let machine = self.machine { + machine.setMouseButton(Int32(event.buttonNumber), isPressed: true) + } } // MARK: New machine creation diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.h b/OSBindings/Mac/Clock Signal/Machine/CSMachine.h index f51f49cf6..5f1bd5da0 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.h +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.h @@ -61,6 +61,9 @@ typedef NS_ENUM(NSInteger, CSMachineKeyboardInputMode) { - (void)setKey:(uint16_t)key characters:(nullable NSString *)characters isPressed:(BOOL)isPressed; - (void)clearAllKeys; +- (void)setMouseButton:(int)button isPressed:(BOOL)isPressed; +- (void)addMouseMotionX:(CGFloat)deltaX y:(CGFloat)deltaY; + @property (nonatomic, strong, nullable) CSAudioQueue *audioQueue; @property (nonatomic, readonly, nonnull) CSOpenGLView *view; @property (nonatomic, weak, nullable) id delegate; diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm index c65169366..c2077baef 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm @@ -410,14 +410,14 @@ struct ActivityObserver: public Activity::Observer { } - (void)clearAllKeys { - auto keyboard_machine = _machine->keyboard_machine(); + const auto keyboard_machine = _machine->keyboard_machine(); if(keyboard_machine) { @synchronized(self) { keyboard_machine->get_keyboard().reset_all_keys(); } } - auto joystick_machine = _machine->joystick_machine(); + const auto joystick_machine = _machine->joystick_machine(); if(joystick_machine) { @synchronized(self) { for(auto &joystick : joystick_machine->get_joysticks()) { @@ -425,6 +425,31 @@ struct ActivityObserver: public Activity::Observer { } } } + + const auto mouse_machine = _machine->mouse_machine(); + if(mouse_machine) { + @synchronized(self) { + mouse_machine->get_mouse().reset_all_buttons(); + } + } +} + +- (void)setMouseButton:(int)button isPressed:(BOOL)isPressed { + auto mouse_machine = _machine->mouse_machine(); + if(mouse_machine) { + @synchronized(self) { + mouse_machine->get_mouse().set_button_pressed(button % mouse_machine->get_mouse().get_number_of_buttons(), isPressed); + } + } +} + +- (void)addMouseMotionX:(CGFloat)deltaX y:(CGFloat)deltaY { + auto mouse_machine = _machine->mouse_machine(); + if(mouse_machine) { + @synchronized(self) { + mouse_machine->get_mouse().move(int(deltaX), int(deltaY)); + } + } } #pragma mark - Options