1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-22 12:33:29 +00:00

Ensures proper routing of mouse events from Cocoa.

This commit is contained in:
Thomas Harte 2019-06-11 18:41:41 -04:00
parent 124c7bcbb0
commit 109953ef49
7 changed files with 52 additions and 22 deletions

View File

@ -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"

View File

@ -353,8 +353,8 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
}
private:
Inputs::Mouse *get_mouse() override {
return &mouse_;
Inputs::Mouse &get_mouse() override {
return mouse_;
}
struct IWM {

View File

@ -15,7 +15,7 @@ namespace MouseMachine {
class Machine {
public:
virtual Inputs::Mouse *get_mouse() = 0;
virtual Inputs::Mouse &get_mouse() = 0;
};
}

View File

@ -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 = "<group>"; };
4B92294222B04A3D00A1458F /* MouseMachine.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = MouseMachine.hpp; sourceTree = "<group>"; };
4B92294422B04ACB00A1458F /* Mouse.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Mouse.hpp; sourceTree = "<group>"; };
4B92294522B0554800A1458F /* QuadratureMouse.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = QuadratureMouse.cpp; path = QuadratureMouse/QuadratureMouse.cpp; sourceTree = "<group>"; };
4B92294622B0554800A1458F /* QuadratureMouse.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = QuadratureMouse.hpp; path = QuadratureMouse/QuadratureMouse.hpp; sourceTree = "<group>"; };
4B92294A22B064FD00A1458F /* QuadratureMouse.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = QuadratureMouse.hpp; sourceTree = "<group>"; };
4B924E981E74D22700B76AF1 /* AtariStaticAnalyserTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AtariStaticAnalyserTests.mm; sourceTree = "<group>"; };
4B9252CD1E74D28200B76AF1 /* Atari ROMs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "Atari ROMs"; sourceTree = "<group>"; };
4B92EAC91B7C112B00246143 /* 6502TimingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 6502TimingTests.swift; sourceTree = "<group>"; };
@ -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 = "<group>";
};
4B92294922B064FD00A1458F /* QuadratureMouse */ = {
isa = PBXGroup;
children = (
4B92294A22B064FD00A1458F /* QuadratureMouse.hpp */,
);
path = QuadratureMouse;
sourceTree = "<group>";
};
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 */,

View File

@ -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

View File

@ -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<CSMachineDelegate> delegate;

View File

@ -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