mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 17:59:50 +02:00
refactor(scrcpy): rewrite option classes to improve tree-shaking
This commit is contained in:
parent
92472007db
commit
cc5d52912e
63 changed files with 595 additions and 325 deletions
|
@ -2,16 +2,16 @@ import { getInt16, setInt16 } from "@yume-chan/no-data-view";
|
|||
import type { Field, StructInit } from "@yume-chan/struct";
|
||||
import { bipedal, struct, u16, u32, u8 } from "@yume-chan/struct";
|
||||
|
||||
import { ScrcpyControlMessageType } from "../../base/index.js";
|
||||
import type { ScrcpyScrollController } from "../../base/index.js";
|
||||
import type { ScrcpyInjectScrollControlMessage } from "../../latest.js";
|
||||
|
||||
import { PrevImpl } from "./prev.js";
|
||||
import { clamp } from "../../utils/index.js";
|
||||
|
||||
export const SignedFloat: Field<number, never, never> = {
|
||||
size: 2,
|
||||
serialize(value, { buffer, index, littleEndian }) {
|
||||
// https://github.com/Genymobile/scrcpy/blob/1f138aef41de651668043b32c4effc2d4adbfc44/app/src/util/binary.h#L51
|
||||
value = PrevImpl.clamp(value, -1, 1);
|
||||
value = clamp(value, -1, 1);
|
||||
value = value === 1 ? 0x7fff : value * 0x8000;
|
||||
setInt16(buffer, index, value, littleEndian);
|
||||
},
|
||||
|
@ -23,19 +23,20 @@ export const SignedFloat: Field<number, never, never> = {
|
|||
}),
|
||||
};
|
||||
|
||||
export const InjectScrollControlMessage = struct(
|
||||
{
|
||||
type: u8,
|
||||
pointerX: u32,
|
||||
pointerY: u32,
|
||||
screenWidth: u16,
|
||||
screenHeight: u16,
|
||||
scrollX: SignedFloat,
|
||||
scrollY: SignedFloat,
|
||||
buttons: u32,
|
||||
},
|
||||
{ littleEndian: false },
|
||||
);
|
||||
export const InjectScrollControlMessage = /* #__PURE__ */ (() =>
|
||||
struct(
|
||||
{
|
||||
type: u8(ScrcpyControlMessageType.InjectScroll),
|
||||
pointerX: u32,
|
||||
pointerY: u32,
|
||||
screenWidth: u16,
|
||||
screenHeight: u16,
|
||||
scrollX: SignedFloat,
|
||||
scrollY: SignedFloat,
|
||||
buttons: u32,
|
||||
},
|
||||
{ littleEndian: false },
|
||||
))();
|
||||
|
||||
export type InjectScrollControlMessage = StructInit<
|
||||
typeof InjectScrollControlMessage
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue