显卡分页逻辑以及移动逻辑修复

This commit is contained in:
1 2025-07-25 16:25:33 +08:00
parent 830f16a9f5
commit 2355147ed5

View File

@ -752,7 +752,7 @@ export default {
imageSize: 1, // 32x32
imageColor: 0, //
effect: 0,
speed: 4,
speed: 0,
stayTime: 5,
hAlign: 1,
vAlign: 1,
@ -1053,7 +1053,7 @@ export default {
imageSize: 1,
imageColor: 0, //
effect: 0,
speed: 4,
speed: 0,
stayTime: 5,
hAlign: 1,
vAlign: 1,
@ -1093,7 +1093,7 @@ export default {
//
if (item.anim) {
zone.effect = item.anim.typ ? item.anim.typ - 1 : 0; // 1
zone.speed = item.anim.spd || 4; //
zone.speed = item.anim.spd || 0; //
zone.stayTime = item.anim.pauseT ? this.getStayTimeIndex(item.anim.pauseT) : 5; //
}
}
@ -1117,7 +1117,7 @@ export default {
imageSize: 1,
imageColor: 0, //
effect: 0,
speed: 4,
speed: 0,
stayTime: 5,
hAlign: 1,
vAlign: 1,
@ -2231,7 +2231,7 @@ export default {
imageSize: 1,
imageColor: 0, //
effect: 0,
speed: 4,
speed: 0,
stayTime: 5,
hAlign: 1,
vAlign: 1,
@ -2275,7 +2275,7 @@ export default {
imageSize: 1,
imageColor: 0, //
effect: 0,
speed: 4,
speed: 0,
stayTime: 5,
hAlign: 1,
vAlign: 1,
@ -2413,7 +2413,7 @@ export default {
//
const programData = {
del_prog: 0, //
// del_prog: 0, //
prog_list: [programObj]
};
@ -2517,7 +2517,7 @@ export default {
if (zone.playType === 0 && asset.isText) {
//
const page = this.addProgramPreviewPage[zIdx] || 0;
const page = state && typeof state.currentPage === 'number' ? state.currentPage : 0;
const pageLines = asset.pages[page] || [];
//
@ -2580,7 +2580,17 @@ export default {
if (effect === 3 || effect === 4) animOffsetY = state.currentY;
}
ctx.fillText(line, startX + animOffsetX, startY + lineIdx * lineHeight + animOffsetY);
//
if (zone.effect === 5 && state) {
let x1 = zoneX + state.currentX;
let x2 = x1 + textWidth;
//
let y = zoneY + (zoneHeight - lineHeight) / 2;
ctx.fillText(line, x1, y);
ctx.fillText(line, x2, y);
} else {
ctx.fillText(line, startX + (state ? state.currentX : 0), startY + lineIdx * lineHeight + (state ? state.currentY : 0));
}
});
} else if (zone.playType === 1 && asset.isImage) {
//
@ -2685,10 +2695,8 @@ export default {
this.addProgramPreviewAssets = this.addProgramForm.zones.map(zone => {
if (zone.playType === 1 && zone.image) {
console.log('加载图片', zone.image);
//
const img = new window.Image();
// img.crossOrigin = 'Anonymous';
const asset = { img, isImage: true, loaded: false };
img.onload = () => {
asset.loaded = true;
@ -2720,27 +2728,27 @@ export default {
// canvas
const measureCanvas = document.createElement('canvas');
const measureCtx = measureCanvas.getContext('2d');
const fontFamilies2 = [
'SimSun, 宋体, Songti SC, serif',
'SimHei, 黑体, Heiti SC, sans-serif',
'KaiTi, 楷体, Kaiti SC, serif'
];
const enFontMap2 = [
const enFontMap = [
'Courier New', 'Arial Black', 'Arial Italic', 'Lucida Console', 'Impact', 'Gothic', 'Arial Narrow', 'Comic Sans MS', 'Brush Script MT', 'Century Gothic', 'Times New Roman'
];
let fontFamily2;
let fontFamilyUsed;
if (/^[A-Za-z0-9\s]+$/.test(zone.displayText)) {
fontFamily2 = enFontMap2[zone.fontEn] || fontFamilies2[0];
fontFamilyUsed = enFontMap[zone.fontEn] || fontFamily[0];
} else {
fontFamily2 = fontFamilies2[zone.font] || fontFamilies2[0];
fontFamilyUsed = fontFamily[zone.font] || fontFamily[0];
}
measureCtx.font = `${fontWeight} ${scaledFontSize}px ${fontFamily2}`;
measureCtx.font = `${fontWeight} ${scaledFontSize}px ${fontFamilyUsed}`;
//
// -
let lines = [];
if (zone.effect === 5) { //
//
lines = [zone.displayText];
} else {
//
const zoneRenderWidth = swapWH ? zone.height : zone.width;
const maxWidth = zoneRenderWidth * scale - 4; // 4px
let currentLine = '';
const lines = [];
for (const char of zone.displayText) {
const testLine = currentLine + char;
@ -2755,6 +2763,7 @@ export default {
}
if (currentLine) lines.push(currentLine);
}
//
const zoneRenderHeight = swapWH ? zone.width : zone.height;
@ -2769,23 +2778,24 @@ export default {
if (pages.length === 0) pages.push([]);
//
const totalWidth = Math.max(...lines.map(line => measureCtx.measureText(line).width), 0);
const totalHeight = lines.length * lineHeight;
//
const totalWidth = Math.max(...pages.flat().map(line => measureCtx.measureText(line).width), 0);
const totalHeight = Math.min(lines.length, maxLines) * lineHeight;
return {
pages,
isText: true,
scaledFontSize,
fontFamily: fontFamily2,
fontFamily: fontFamilyUsed,
fontWeight,
lineHeight,
totalWidth,
totalHeight,
zoneRenderWidth: zoneRenderWidth * scale,
zoneRenderHeight: zoneRenderHeight * scale
zoneRenderWidth: (swapWH ? zone.height : zone.width) * scale,
zoneRenderHeight: (swapWH ? zone.width : zone.height) * scale
};
});
},
},
resetAddProgramPreviewPage() {
this.addProgramPreviewPage = this.addProgramForm.zones.map(() => 0);
},
@ -2884,8 +2894,6 @@ export default {
//
const renderWidth = 640;
const renderHeight = 240;
// const scale = Math.min(renderWidth / 32, renderHeight / 64);
// 使 prepareAddProgramPreviewAssets scale
let screenW = this.screenParams.width || 32;
let screenH = this.screenParams.height || 64;
const angle = this.screenParams.angle;
@ -2895,7 +2903,6 @@ export default {
}
const scale = Math.min(renderWidth / screenW, renderHeight / screenH);
this.addProgramForm.zones.forEach((zone, idx) => {
const asset = this.addProgramPreviewAssets[idx];
const state = this.addProgramPreviewAnimState[idx];
@ -2906,13 +2913,9 @@ export default {
const page = this.addProgramPreviewPage[idx] || 0;
const pageLines = asset.pages[page] || [];
const lineHeight = asset.lineHeight;
// const totalHeight = pageLines.length * lineHeight; //
// const totalWidth = Math.max(...pageLines.map(line => measureCtx.measureText(line).width), 0); //
// 使 prepareAddProgramPreviewAssets
const totalHeight = asset.totalHeight;
const totalWidth = asset.totalWidth;
//
const speedMap = [1, 2, 3, 4, 5];
const animSpeed = (speedMap[zone.speed] || 3) * scale * 0.5; // /
@ -2929,217 +2932,62 @@ export default {
if (typeof state.pauseStart !== 'number') state.pauseStart = 0;
if (typeof state.pausePhase !== 'string') state.pausePhase = 'start'; // 'start' | 'move'
switch (effect) {
case 1: //
// state.currentX
if (typeof state.currentX !== 'number') state.currentX = 0;
// pausePhase
if (!state.pausePhase) state.pausePhase = 'start'; // 'start' | 'move'
//
if (!state.isPausing && state.pausePhase === 'start') {
state.isPausing = true;
state.pauseStart = Date.now();
}
//
if (state.isPausing && state.pausePhase === 'start') {
if (Date.now() - state.pauseStart >= pauseMs) {
state.isPausing = false;
state.pausePhase = 'move';
}
//
} else if (!state.isPausing && state.pausePhase === 'move') {
// --- ---
// !!! !!!
// : if (state.currentX + totalWidth > 0)
// : (0) (-state.currentX)
// ""
const pixelsMoved = -state.currentX; // X=0
const distanceToTriggerReset = zoneWidth + 100; // <--- +
// 32 + 100 = 132
// 100
if (pixelsMoved < distanceToTriggerReset) {
//
if (typeof state.currentX !== 'number') state.currentX = zoneWidth;
state.currentX -= animSpeed;
} else {
//
// console.log(`Zone ${idx} - Left Move: Forcefully reset after moving ${pixelsMoved.toFixed(2)} pixels.`); //
state.currentX = 0; //
state.pausePhase = 'start'; //
if (state.currentX < -totalWidth) {
if (asset.pages.length > 1) {
state.currentPage = (state.currentPage + 1) % asset.pages.length;
}
// --- ---
state.currentX = zoneWidth;
}
// Y
state.currentY = 0;
break;
case 2: //
// state.currentX
if (typeof state.currentX !== 'number') state.currentX = 0; //
// pausePhase
if (!state.pausePhase) state.pausePhase = 'start'; // 'start' | 'move'
//
if (!state.isPausing && state.pausePhase === 'start') {
state.isPausing = true;
state.pauseStart = Date.now();
}
//
if (state.isPausing && state.pausePhase === 'start') {
if (Date.now() - state.pauseStart >= pauseMs) {
state.isPausing = false;
state.pausePhase = 'move';
}
//
} else if (!state.isPausing && state.pausePhase === 'move') {
// --- ---
//
// (currentX < zoneWidth)
if (state.currentX < zoneWidth) {
if (typeof state.currentX !== 'number') state.currentX = -totalWidth;
state.currentX += animSpeed;
//
// if (state.currentX > zoneWidth) {
// state.currentX = zoneWidth; //
// }
} else {
//
// 'end'
state.currentX = 0; //
state.pausePhase = 'start'; //
if (state.currentX > zoneWidth) {
if (asset.pages.length > 1) {
state.currentPage = (state.currentPage + 1) % asset.pages.length;
}
// --- ---
state.currentX = -totalWidth;
}
// Y
state.currentY = 0;
break;
case 3: //
// state.currentY
if (typeof state.currentY !== 'number') state.currentY = 0;
// pausePhase
if (!state.pausePhase) state.pausePhase = 'start'; // 'start' | 'move'
//
if (!state.isPausing && state.pausePhase === 'start') {
state.isPausing = true;
state.pauseStart = Date.now();
}
//
if (state.isPausing && state.pausePhase === 'start') {
if (Date.now() - state.pauseStart >= pauseMs) {
state.isPausing = false;
state.pausePhase = 'move';
}
//
} else if (!state.isPausing && state.pausePhase === 'move') {
// --- ---
//
// (currentY + totalHeight > 0)
if (state.currentY + totalHeight > 0) {
if (typeof state.currentY !== 'number') state.currentY = zoneHeight;
state.currentY -= animSpeed;
//
// if (state.currentY + totalHeight < 0) {
// state.currentY = -totalHeight;
// }
} else {
//
// 'end'
state.currentY = 0; //
state.pausePhase = 'start'; //
if (state.currentY < -totalHeight) {
if (asset.pages.length > 1) {
state.currentPage = (state.currentPage + 1) % asset.pages.length;
}
// --- ---
state.currentY = zoneHeight;
}
// X
state.currentX = 0;
break;
case 4: //
// state.currentY
if (typeof state.currentY !== 'number') state.currentY = 0; //
// pausePhase
if (!state.pausePhase) state.pausePhase = 'start'; // 'start' | 'move'
//
if (!state.isPausing && state.pausePhase === 'start') {
state.isPausing = true;
state.pauseStart = Date.now();
}
//
if (state.isPausing && state.pausePhase === 'start') {
if (Date.now() - state.pauseStart >= pauseMs) {
state.isPausing = false;
state.pausePhase = 'move';
}
//
} else if (!state.isPausing && state.pausePhase === 'move') {
// --- ---
//
// (currentY < zoneHeight)
if (state.currentY < zoneHeight) {
if (typeof state.currentY !== 'number') state.currentY = -totalHeight;
state.currentY += animSpeed;
//
// if (state.currentY > zoneHeight) {
// state.currentY = zoneHeight;
// }
} else {
//
// 'end'
state.currentY = 0; //
state.pausePhase = 'start'; //
if (state.currentY > zoneHeight) {
if (asset.pages.length > 1) {
state.currentPage = (state.currentPage + 1) % asset.pages.length;
}
// --- ---
state.currentY = -totalHeight;
}
// X
state.currentX = 0;
break;
case 5: // ( -> -> -> ...)
// state.currentX
if (typeof state.currentX !== 'number') state.currentX = 0;
// pausePhase
if (!state.pausePhase) state.pausePhase = 'start'; // 'start' | 'move'
// ()
if (!state.isPausing && state.pausePhase === 'start') {
// pauseMs
state.isPausing = true;
state.pauseStart = Date.now();
}
//
if (state.isPausing && state.pausePhase === 'start') {
if (Date.now() - state.pauseStart >= pauseMs) {
state.isPausing = false;
state.pausePhase = 'move'; //
}
// ()
} else if (!state.isPausing && state.pausePhase === 'move') {
// --- () ---
//
if (state.currentX > -totalWidth) {
case 5: // ()
//
if (typeof state.currentX !== 'number') state.currentX = zoneWidth;
//
state.currentX -= animSpeed;
//
// if (state.currentX < -totalWidth) {
// state.currentX = -totalWidth;
// }
} else {
//
// pauseMs
state.isPausing = true;
state.pauseStart = Date.now();
state.currentX = 0; //
state.pausePhase = 'start'; // 'start'
//
if (state.currentX < -totalWidth) {
state.currentX += totalWidth;
}
// --- ---
}
state.currentY = 0; // Y
// Y
state.currentY = (zoneHeight - totalHeight) / 2;
break;
case 6: //
@ -3151,22 +2999,10 @@ export default {
default: // (effect === 0)
state.currentX = 0;
state.currentY = 0;
//
// if (!state.isPausing && state.pausePhase === 'start') {
// state.isPausing = true;
// state.pauseStart = Date.now();
// }
// if (state.isPausing && state.pausePhase === 'start') {
// if (Date.now() - state.pauseStart >= pauseMs) {
// state.isPausing = false;
// state.pausePhase = 'end'; // 'start'
// }
// }
// state.pausePhase = 'start'; // 便
break;
}
});
},
},
measureTextWidth(text, asset) {
//
const canvas = document.createElement('canvas');