显卡完善
This commit is contained in:
parent
2355147ed5
commit
7236a95236
@ -2483,6 +2483,7 @@ export default {
|
||||
this.addProgramForm.zones.forEach((zone, zIdx) => {
|
||||
const asset = this.addProgramPreviewAssets[zIdx];
|
||||
if (!asset) return;
|
||||
const state = this.addProgramPreviewAnimState[zIdx] || {};
|
||||
|
||||
// 计算分区在画布中的位置(角度为90或270时,x/y/width/height互换)
|
||||
let zoneX, zoneY, zoneWidth, zoneHeight;
|
||||
@ -2512,12 +2513,9 @@ export default {
|
||||
ctx.rect(zoneX, zoneY, zoneWidth, zoneHeight);
|
||||
ctx.clip();
|
||||
|
||||
// 获取动画状态
|
||||
const state = this.addProgramPreviewAnimState[zIdx];
|
||||
|
||||
if (zone.playType === 0 && asset.isText) {
|
||||
// 文本类型分区
|
||||
const page = state && typeof state.currentPage === 'number' ? state.currentPage : 0;
|
||||
// 获取当前页(使用状态中的当前页)
|
||||
const page = state.currentPage || 0;
|
||||
const pageLines = asset.pages[page] || [];
|
||||
|
||||
// 设置字体样式
|
||||
@ -2589,7 +2587,7 @@ export default {
|
||||
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));
|
||||
ctx.fillText(line, startX + animOffsetX, startY + lineIdx * lineHeight + animOffsetY);
|
||||
}
|
||||
});
|
||||
} else if (zone.playType === 1 && asset.isImage) {
|
||||
@ -2795,7 +2793,7 @@ export default {
|
||||
zoneRenderHeight: (swapWH ? zone.width : zone.height) * scale
|
||||
};
|
||||
});
|
||||
},
|
||||
},
|
||||
resetAddProgramPreviewPage() {
|
||||
this.addProgramPreviewPage = this.addProgramForm.zones.map(() => 0);
|
||||
},
|
||||
@ -2864,17 +2862,20 @@ export default {
|
||||
return { lines, maxLines };
|
||||
},
|
||||
resetAddProgramPreviewAnimState() {
|
||||
// 初始化每个分区动画状态
|
||||
this.addProgramPreviewAnimState = this.addProgramForm.zones.map((zone, idx) => {
|
||||
return {
|
||||
currentX: 0,
|
||||
currentY: 0,
|
||||
currentPage: this.addProgramPreviewPage[idx] || 0,
|
||||
pageTimer: null,
|
||||
currentPage: 0,
|
||||
isMoving: false,
|
||||
isPausing: false,
|
||||
moveStart: 0,
|
||||
pauseStart: 0,
|
||||
currentChar: 0, // 当前显示的字符索引
|
||||
effect: zone.effect,
|
||||
};
|
||||
});
|
||||
},
|
||||
},
|
||||
stopAddProgramPreviewAnimLoop() {
|
||||
if (this.addProgramPreviewAnimFrame) {
|
||||
cancelAnimationFrame(this.addProgramPreviewAnimFrame);
|
||||
@ -2910,8 +2911,7 @@ export default {
|
||||
if (!asset || !state || !asset.isText) return;
|
||||
|
||||
const effect = zone.effect;
|
||||
const page = this.addProgramPreviewPage[idx] || 0;
|
||||
const pageLines = asset.pages[page] || [];
|
||||
const pageLines = asset.pages[state.currentPage] || [];
|
||||
const lineHeight = asset.lineHeight;
|
||||
const totalHeight = asset.totalHeight;
|
||||
const totalWidth = asset.totalWidth;
|
||||
@ -2928,70 +2928,186 @@ export default {
|
||||
const pauseMs = this.getPauseTime(zone.stayTime);
|
||||
|
||||
// 确保初始状态值存在
|
||||
if (typeof state.isMoving !== 'boolean') state.isMoving = false;
|
||||
if (typeof state.isPausing !== 'boolean') state.isPausing = false;
|
||||
if (typeof state.pauseStart !== 'number') state.pauseStart = 0;
|
||||
if (typeof state.pausePhase !== 'string') state.pausePhase = 'start'; // 'start' | 'move'
|
||||
if (typeof state.moveStart !== 'number') state.moveStart = 0;
|
||||
|
||||
switch (effect) {
|
||||
case 0: // 立即显示
|
||||
if (!state.isPausing && !state.isMoving) {
|
||||
// 初始状态:直接进入停留阶段
|
||||
state.isPausing = true;
|
||||
state.pauseStart = Date.now();
|
||||
} else if (state.isPausing) {
|
||||
// 检查停留时间是否结束
|
||||
if (Date.now() - state.pauseStart >= pauseMs) {
|
||||
state.isPausing = false;
|
||||
state.isMoving = true; // 准备翻页
|
||||
}
|
||||
} else if (state.isMoving) {
|
||||
// 翻页操作
|
||||
state.currentPage = (state.currentPage + 1) % asset.pages.length;
|
||||
state.isMoving = false;
|
||||
state.isPausing = true;
|
||||
state.pauseStart = Date.now();
|
||||
}
|
||||
// 位置保持不变
|
||||
state.currentX = 0;
|
||||
state.currentY = 0;
|
||||
break;
|
||||
|
||||
case 1: // 左移
|
||||
if (typeof state.currentX !== 'number') state.currentX = zoneWidth;
|
||||
state.currentX -= animSpeed;
|
||||
if (state.currentX < -totalWidth) {
|
||||
if (asset.pages.length > 1) {
|
||||
state.currentPage = (state.currentPage + 1) % asset.pages.length;
|
||||
}
|
||||
if (!state.isMoving && !state.isPausing) {
|
||||
// 初始状态:设置初始位置(右侧外部)
|
||||
state.currentX = zoneWidth;
|
||||
state.isMoving = true;
|
||||
state.moveStart = Date.now();
|
||||
} else if (state.isMoving) {
|
||||
// 移动阶段
|
||||
const elapsed = Date.now() - state.moveStart;
|
||||
const progress = Math.min(1, elapsed / (totalWidth * 1000 / animSpeed));
|
||||
|
||||
// 计算移动位置(从右侧移动到左侧)
|
||||
state.currentX = zoneWidth - progress * (zoneWidth + totalWidth);
|
||||
|
||||
// 检查是否到达目标位置
|
||||
if (progress >= 1) {
|
||||
state.isMoving = false;
|
||||
state.isPausing = true;
|
||||
state.pauseStart = Date.now();
|
||||
}
|
||||
} else if (state.isPausing) {
|
||||
// 停留阶段
|
||||
if (Date.now() - state.pauseStart >= pauseMs) {
|
||||
state.isPausing = false;
|
||||
state.isMoving = true; // 准备翻页
|
||||
}
|
||||
} else if (!state.isPausing && state.isMoving) {
|
||||
// 翻页操作
|
||||
state.currentPage = (state.currentPage + 1) % asset.pages.length;
|
||||
state.currentX = zoneWidth; // 重置位置
|
||||
state.isMoving = true;
|
||||
state.moveStart = Date.now();
|
||||
}
|
||||
state.currentY = 0;
|
||||
break;
|
||||
|
||||
case 2: // 右移
|
||||
if (typeof state.currentX !== 'number') state.currentX = -totalWidth;
|
||||
state.currentX += animSpeed;
|
||||
if (state.currentX > zoneWidth) {
|
||||
if (asset.pages.length > 1) {
|
||||
state.currentPage = (state.currentPage + 1) % asset.pages.length;
|
||||
}
|
||||
if (!state.isMoving && !state.isPausing) {
|
||||
state.currentX = -totalWidth;
|
||||
state.isMoving = true;
|
||||
state.moveStart = Date.now();
|
||||
} else if (state.isMoving) {
|
||||
const elapsed = Date.now() - state.moveStart;
|
||||
const progress = Math.min(1, elapsed / (totalWidth * 1000 / animSpeed));
|
||||
|
||||
state.currentX = -totalWidth + progress * (zoneWidth + totalWidth);
|
||||
|
||||
if (progress >= 1) {
|
||||
state.isMoving = false;
|
||||
state.isPausing = true;
|
||||
state.pauseStart = Date.now();
|
||||
}
|
||||
} else if (state.isPausing) {
|
||||
if (Date.now() - state.pauseStart >= pauseMs) {
|
||||
state.isPausing = false;
|
||||
state.isMoving = true; // 准备翻页
|
||||
}
|
||||
} else if (!state.isPausing && state.isMoving) {
|
||||
state.currentPage = (state.currentPage + 1) % asset.pages.length;
|
||||
state.currentX = -totalWidth;
|
||||
state.isMoving = true;
|
||||
state.moveStart = Date.now();
|
||||
}
|
||||
state.currentY = 0;
|
||||
break;
|
||||
|
||||
case 3: // 上移
|
||||
if (typeof state.currentY !== 'number') state.currentY = zoneHeight;
|
||||
state.currentY -= animSpeed;
|
||||
if (state.currentY < -totalHeight) {
|
||||
if (asset.pages.length > 1) {
|
||||
state.currentPage = (state.currentPage + 1) % asset.pages.length;
|
||||
}
|
||||
if (!state.isMoving && !state.isPausing) {
|
||||
state.currentY = zoneHeight;
|
||||
state.isMoving = true;
|
||||
state.moveStart = Date.now();
|
||||
} else if (state.isMoving) {
|
||||
const elapsed = Date.now() - state.moveStart;
|
||||
const progress = Math.min(1, elapsed / (totalHeight * 1000 / animSpeed));
|
||||
|
||||
state.currentY = zoneHeight - progress * (zoneHeight + totalHeight);
|
||||
|
||||
if (progress >= 1) {
|
||||
state.isMoving = false;
|
||||
state.isPausing = true;
|
||||
state.pauseStart = Date.now();
|
||||
}
|
||||
state.currentX = 0;
|
||||
break;
|
||||
case 4: // 下移
|
||||
if (typeof state.currentY !== 'number') state.currentY = -totalHeight;
|
||||
state.currentY += animSpeed;
|
||||
if (state.currentY > zoneHeight) {
|
||||
if (asset.pages.length > 1) {
|
||||
} else if (state.isPausing) {
|
||||
if (Date.now() - state.pauseStart >= pauseMs) {
|
||||
state.isPausing = false;
|
||||
state.isMoving = true; // 准备翻页
|
||||
}
|
||||
} else if (!state.isPausing && state.isMoving) {
|
||||
state.currentPage = (state.currentPage + 1) % asset.pages.length;
|
||||
}
|
||||
state.currentY = -totalHeight;
|
||||
state.currentY = zoneHeight;
|
||||
state.isMoving = true;
|
||||
state.moveStart = Date.now();
|
||||
}
|
||||
state.currentX = 0;
|
||||
break;
|
||||
|
||||
case 4: // 下移
|
||||
if (!state.isMoving && !state.isPausing) {
|
||||
state.currentY = -totalHeight;
|
||||
state.isMoving = true;
|
||||
state.moveStart = Date.now();
|
||||
} else if (state.isMoving) {
|
||||
const elapsed = Date.now() - state.moveStart;
|
||||
const progress = Math.min(1, elapsed / (totalHeight * 1000 / animSpeed));
|
||||
|
||||
state.currentY = -totalHeight + progress * (zoneHeight + totalHeight);
|
||||
|
||||
if (progress >= 1) {
|
||||
state.isMoving = false;
|
||||
state.isPausing = true;
|
||||
state.pauseStart = Date.now();
|
||||
}
|
||||
} else if (state.isPausing) {
|
||||
if (Date.now() - state.pauseStart >= pauseMs) {
|
||||
state.isPausing = false;
|
||||
state.isMoving = true; // 准备翻页
|
||||
}
|
||||
} else if (!state.isPausing && state.isMoving) {
|
||||
state.currentPage = (state.currentPage + 1) % asset.pages.length;
|
||||
state.currentY = -totalHeight;
|
||||
state.isMoving = true;
|
||||
state.moveStart = Date.now();
|
||||
}
|
||||
state.currentX = 0;
|
||||
break;
|
||||
|
||||
case 5: // 连续左移 (跑马灯效果)
|
||||
// 确保初始位置在分区右侧外部
|
||||
// 特殊处理 - 不分页
|
||||
if (typeof state.currentX !== 'number') state.currentX = zoneWidth;
|
||||
// 向左移动文本
|
||||
state.currentX -= animSpeed;
|
||||
// 当文本完全移出左侧边界时,重置到右侧重新开始(无缝循环)
|
||||
if (state.currentX < -totalWidth) {
|
||||
state.currentX += totalWidth;
|
||||
}
|
||||
// Y轴居中显示
|
||||
state.currentY = (zoneHeight - totalHeight) / 2;
|
||||
break;
|
||||
|
||||
case 6: // 闪烁换页
|
||||
// 由自动翻页定时器控制,此处不处理动画位移
|
||||
if (!state.isPausing && !state.isMoving) {
|
||||
state.isPausing = true;
|
||||
state.pauseStart = Date.now();
|
||||
} else if (state.isPausing) {
|
||||
if (Date.now() - state.pauseStart >= pauseMs) {
|
||||
state.isPausing = false;
|
||||
state.isMoving = true; // 准备翻页
|
||||
}
|
||||
} else if (state.isMoving) {
|
||||
state.currentPage = (state.currentPage + 1) % asset.pages.length;
|
||||
state.isMoving = false;
|
||||
state.isPausing = true;
|
||||
state.pauseStart = Date.now();
|
||||
}
|
||||
state.currentX = 0;
|
||||
state.currentY = 0;
|
||||
break;
|
||||
@ -3002,7 +3118,7 @@ export default {
|
||||
break;
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
measureTextWidth(text, asset) {
|
||||
// 用于动画宽度测量
|
||||
const canvas = document.createElement('canvas');
|
||||
|
Loading…
x
Reference in New Issue
Block a user