92 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { globalLookup } from '@/hook/global';
import formatTime from '@/hook/wave-view/format-time';
import { reactive } from 'vue';
/**
* @typedef {(event: MouseEvent) => void} MousemoveFn
*/
export const MovingPivot = reactive({
color: '#CB81DA',
label: '',
left: 0,
currentTime: 0,
show: true,
enterUserPivot: false,
/**
* @type {import('./pivot-view').UserPivot | undefined}
*/
currentTakenPivot: undefined,
dragEnable: false
});
export const SystemPivot = reactive({
label: '',
show: false,
currentTime: 0,
left: 0,
color: '#CB81DA',
updateLabel(timescale) {
this.label = formatTime(this.currentTime, timescale);
},
updateLeft() {
this.left = time2cursorX(this.currentTime);
}
});
/**
* @description 左击改变系统信标的位置
*/
export function changeCursorLocation() {
if (MovingPivot.dragEnable || !MovingPivot.show) {
return;
}
SystemPivot.show = true;
const pstate = globalLookup.pstate;
if (pstate) {
const { xCursor, timescale } = pstate;
const currentTime = cursorX2time(xCursor);
SystemPivot.currentTime = currentTime;
SystemPivot.updateLabel(timescale);
SystemPivot.updateLeft();
}
}
/**
* @description 给出当前左侧偏移亮,计算出它实际上代表的时间
* @param {number} cursorX
* @returns {number}
*/
export function cursorX2time(cursorX) {
const pstate = globalLookup.pstate;
if (pstate) {
const { xOffset, xScale, tgcd } = pstate;
const currentTime = Math.round((cursorX - xOffset) / xScale) * tgcd;
return currentTime;
}
return 0;
}
/**
* @description 给出当前的时间,比如 23ns计算当前这个点应该相对于左侧偏移多少
* @param {number} currentTime
* @returns {number}
*/
export function time2cursorX(currentTime) {
const pstate = globalLookup.pstate;
if (pstate) {
const { xOffset, xScale, tgcd, timescale } = pstate;
const xCursor = (currentTime / tgcd) * xScale + xOffset;
return xCursor;
}
return 0;
}
/**
* @type {Map<number, MousemoveFn>}
*/
export const mousemoveEventPipes = new Map();