mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-02-23 15:32:17 +08:00
feat(hotkey): use mask size in store
This commit is contained in:
parent
0bb511a6c5
commit
1ad253f91b
@ -24,7 +24,6 @@ import {
|
|||||||
import { useGlobalStore } from "./store/global";
|
import { useGlobalStore } from "./store/global";
|
||||||
import { LogicalPosition, getCurrent } from "@tauri-apps/api/window";
|
import { LogicalPosition, getCurrent } from "@tauri-apps/api/window";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { UnlistenFn } from "@tauri-apps/api/event";
|
|
||||||
import { KeyToCodeMap } from "./frontcommand/KeyToCodeMap";
|
import { KeyToCodeMap } from "./frontcommand/KeyToCodeMap";
|
||||||
import {
|
import {
|
||||||
AndroidKeyEventAction,
|
AndroidKeyEventAction,
|
||||||
@ -36,13 +35,13 @@ import { sendInjectKeycode } from "./frontcommand/controlMsg";
|
|||||||
function clientxToPosx(clientx: number) {
|
function clientxToPosx(clientx: number) {
|
||||||
return clientx < 70
|
return clientx < 70
|
||||||
? 0
|
? 0
|
||||||
: Math.floor((clientx - 70) * (store.screenSizeW / maskSizeW));
|
: Math.floor((clientx - 70) * (store.screenSizeW / store.maskSizeW));
|
||||||
}
|
}
|
||||||
|
|
||||||
function clientyToPosy(clienty: number) {
|
function clientyToPosy(clienty: number) {
|
||||||
return clienty < 30
|
return clienty < 30
|
||||||
? 0
|
? 0
|
||||||
: Math.floor((clienty - 30) * (store.screenSizeH / maskSizeH));
|
: Math.floor((clienty - 30) * (store.screenSizeH / store.maskSizeH));
|
||||||
}
|
}
|
||||||
|
|
||||||
function clientxToPosOffsetx(clientx: number, posx: number, scale = 1) {
|
function clientxToPosOffsetx(clientx: number, posx: number, scale = 1) {
|
||||||
@ -59,6 +58,9 @@ function clientPosToSkillOffset(
|
|||||||
clientPos: { x: number; y: number },
|
clientPos: { x: number; y: number },
|
||||||
range: number
|
range: number
|
||||||
): { offsetX: number; offsetY: number } {
|
): { offsetX: number; offsetY: number } {
|
||||||
|
const maskSizeH = store.maskSizeH;
|
||||||
|
const maskSizeW = store.maskSizeW;
|
||||||
|
|
||||||
const maxLength = (120 / maskSizeH) * store.screenSizeH;
|
const maxLength = (120 / maskSizeH) * store.screenSizeH;
|
||||||
const centerX = maskSizeW * 0.5;
|
const centerX = maskSizeW * 0.5;
|
||||||
const centerY = maskSizeH * 0.5;
|
const centerY = maskSizeH * 0.5;
|
||||||
@ -1511,9 +1513,6 @@ export function clearShortcuts() {
|
|||||||
loopDownKeyCBMap.clear();
|
loopDownKeyCBMap.clear();
|
||||||
upKeyCBMap.clear();
|
upKeyCBMap.clear();
|
||||||
cancelAbleKeyList.length = 0;
|
cancelAbleKeyList.length = 0;
|
||||||
|
|
||||||
// unlisten to resize
|
|
||||||
unlistenResize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function applyShortcuts(
|
export function applyShortcuts(
|
||||||
@ -1528,23 +1527,11 @@ export function applyShortcuts(
|
|||||||
message = messageAPI;
|
message = messageAPI;
|
||||||
t = i18nT;
|
t = i18nT;
|
||||||
|
|
||||||
maskSizeW = maskElement.clientWidth;
|
|
||||||
maskSizeH = maskElement.clientHeight;
|
|
||||||
// listen to resize to update mask size
|
|
||||||
getCurrent()
|
|
||||||
.onResized(() => {
|
|
||||||
maskSizeW = maskElement.clientWidth;
|
|
||||||
maskSizeH = maskElement.clientHeight;
|
|
||||||
})
|
|
||||||
.then((f) => (unlistenResize = f));
|
|
||||||
|
|
||||||
addClickShortcuts("M0", 0);
|
addClickShortcuts("M0", 0);
|
||||||
|
|
||||||
return applyKeyMappingConfigShortcuts(keyMappingConfig);
|
return applyKeyMappingConfigShortcuts(keyMappingConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
let maskSizeW: number;
|
|
||||||
let maskSizeH: number;
|
|
||||||
let mouseX = 0;
|
let mouseX = 0;
|
||||||
let mouseY = 0;
|
let mouseY = 0;
|
||||||
let store: ReturnType<typeof useGlobalStore>;
|
let store: ReturnType<typeof useGlobalStore>;
|
||||||
@ -1552,8 +1539,6 @@ let maskElement: HTMLElement;
|
|||||||
let message: ReturnType<typeof useMessage>;
|
let message: ReturnType<typeof useMessage>;
|
||||||
let t: ReturnType<typeof useI18n>["t"];
|
let t: ReturnType<typeof useI18n>["t"];
|
||||||
|
|
||||||
let unlistenResize: UnlistenFn;
|
|
||||||
|
|
||||||
const downKeyMap: Map<string, boolean> = new Map();
|
const downKeyMap: Map<string, boolean> = new Map();
|
||||||
const downKeyCBMap: Map<string, () => Promise<void>> = new Map();
|
const downKeyCBMap: Map<string, () => Promise<void>> = new Map();
|
||||||
const loopDownKeyCBMap: Map<string, () => Promise<void>> = new Map();
|
const loopDownKeyCBMap: Map<string, () => Promise<void>> = new Map();
|
||||||
|
Loading…
Reference in New Issue
Block a user