Skip to content

Commit

Permalink
v8.1.14, #304: fix regression in capture mode
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Jul 6, 2024
1 parent bce4163 commit 8e8f890
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
// url: "https://cdn.dos.zone/original/2X/7/744842062905f72648a4d492ccc2526d039b3702.jsdos", // sim-city
// url: "https://cdn.dos.zone/custom/dos/war2.jsdos", // warcraft-2
// url: "https://cdn.dos.zone/original/2X/5/5f21f221e023bbca253396824c5f652438eeef8c.jsdos", // поле чудес
// url: "https://cdn.dos.zone/custom/dos/homm_2.jsdos",
// dosboxConf: diabloConf,
// loginUrl: "http://localhost:8080/subscription.html",
// autoStart: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-dos",
"version": "8.1.12",
"version": "8.1.14",
"description": "Full-featured DOS player with multiple emulator backends",
"type": "module",
"keywords": [
Expand Down
11 changes: 4 additions & 7 deletions src/window/dos/controls/mouse/mount.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { pointer, getPointerState } from "./pointer";

export function mount(el: HTMLElement,
pointerButton: number,
onMouseDown: (x: number, y: number, button: number) => void,
onMouseDown: (x: number, y: number, button?: number) => void,
onMouseMove: (x: number, y: number, mX: number, mY: number) => void,
onMouseUp: (x: number, y: number, button: number) => void,
onMouseUp: (x: number, y: number, button?: number) => void,
onMouseLeave: (x: number, y: number) => void) {
// eslint-disable-next-line
function preventDefaultIfNeeded(e: Event) {
// not needed yet
}

let pressedButton = 0;
const onStart = (e: Event) => {
if (e.target !== el) {
return;
}

const state = getPointerState(e, el);
pressedButton = state.button === undefined ? pointerButton : state.button;
onMouseDown(state.x, state.y, pressedButton);
onMouseDown(state.x, state.y, state.button);

e.stopPropagation();
preventDefaultIfNeeded(e);
Expand All @@ -38,7 +35,7 @@ export function mount(el: HTMLElement,

const onEnd = (e: Event) => {
const state = getPointerState(e, el);
onMouseUp(state.x, state.y, pressedButton);
onMouseUp(state.x, state.y, state.button);
e.stopPropagation();
preventDefaultIfNeeded(e);
};
Expand Down
12 changes: 6 additions & 6 deletions src/window/dos/controls/mouse/mouse-not-locked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mount } from "./mount";

const insensitivePadding = 1 / 100;

export function mouseDefault(pointerNumber: number,
export function mouseDefault(pointerButton: number,
el: HTMLElement,
ci: CommandInterface) {
const mapXY = (x: number, y: number) => doMapXY(x, y, el, ci);
Expand All @@ -12,16 +12,16 @@ export function mouseDefault(pointerNumber: number,
document.exitPointerLock();
}

function onMouseDown(x: number, y: number, button: number) {
function onMouseDown(x: number, y: number, button?: number) {
const xy = mapXY(x, y);
ci.sendMouseMotion(xy.x, xy.y);
ci.sendMouseButton(button, true);
ci.sendMouseButton(button ?? pointerButton, true);
}

function onMouseUp(x: number, y: number, button: number) {
function onMouseUp(x: number, y: number, button?: number) {
const xy = mapXY(x, y);
ci.sendMouseMotion(xy.x, xy.y);
ci.sendMouseButton(button, false);
ci.sendMouseButton(button ?? pointerButton, false);
}

function onMouseMove(x: number, y: number, mX: number, mY: number) {
Expand All @@ -34,7 +34,7 @@ export function mouseDefault(pointerNumber: number,
ci.sendMouseMotion(xy.x, xy.y);
}

return mount(el, pointerNumber, onMouseDown, onMouseMove, onMouseUp, onMouseLeave);
return mount(el, onMouseDown, onMouseMove, onMouseUp, onMouseLeave);
}

function doMapXY(eX: number,
Expand Down
27 changes: 18 additions & 9 deletions src/window/dos/controls/mouse/mouse-swipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ export function mouseSwipe(sensitivity: number,
let prevX = 0;
let prevY = 0;

const onMouseDown = (x: number, y: number) => {
const onMouseDown = (x: number, y: number, mouseButton?: number) => {
startedAt = Date.now();
acc = 0;
prevX = x;
prevY = y;

if (mouseButton !== undefined) {
ci.sendMouseButton(mouseButton, true);
}
};

function onMouseMove(x: number, y: number, mX: number, mY: number) {
Expand All @@ -37,20 +41,25 @@ export function mouseSwipe(sensitivity: number,
}

acc += Math.abs(mX) + Math.abs(mY);
(ci as any).sendMouseRelativeMotion(mX * sensitivity * 2, mY * sensitivity * 2);

ci.sendMouseRelativeMotion(mX * sensitivity * 2, mY * sensitivity * 2);
}

const onMouseUp = (x: number, y: number) => {
const delay = Date.now() - startedAt;
const onMouseUp = (x: number, y: number, mouseButton?: number) => {
if (mouseButton !== undefined) {
ci.sendMouseButton(mouseButton, false);
} else {
const delay = Date.now() - startedAt;

if (delay < clickDelay && acc < clickThreshold) {
const button = pointerButton ?? 0;
ci.sendMouseButton(button, true);
setTimeout(() => ci.sendMouseButton(button, false), 60);
if (delay < clickDelay && acc < clickThreshold) {
const button = mouseButton ?? pointerButton;
ci.sendMouseButton(button, true);
setTimeout(() => ci.sendMouseButton(button, false), 60);
}
}
};

const noop = () => {};

return mount(el, pointerButton, onMouseDown, onMouseMove, onMouseUp, noop);
return mount(el, onMouseDown, onMouseMove, onMouseUp, noop);
}

0 comments on commit 8e8f890

Please sign in to comment.