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

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