深度画布联调
This commit is contained in:
@@ -286,14 +286,19 @@ export class AnimationManager {
|
||||
/**
|
||||
* 重置缩放(带平滑动画)
|
||||
* @param {Boolean} animated 是否使用动画
|
||||
* @param {Boolean} adaptive 是否自适应缩放
|
||||
*/
|
||||
async resetZoom(animated = true) {
|
||||
async resetZoom(animated = true, adaptive = false) {
|
||||
const canvasViewWidth = this.canvasManager.canvasViewWidth;
|
||||
const canvasViewHeight = this.canvasManager.canvasViewHeight;
|
||||
const canvasWidth = this.canvasManager.canvasWidth;
|
||||
const canvasHeight = this.canvasManager.canvasHeight;
|
||||
const panX = canvasViewWidth / 2 - canvasWidth / 2
|
||||
const panY = canvasViewHeight / 2 - canvasHeight / 2
|
||||
const scaleX = canvasViewWidth / canvasWidth * 0.8
|
||||
const scaleY = canvasViewHeight / canvasHeight * 0.8
|
||||
const scale = Math.min(scaleX, scaleY, 1)
|
||||
const panX = canvasViewWidth / 2 - canvasWidth * scale / 2
|
||||
const panY = canvasViewHeight / 2 - canvasHeight * scale / 2
|
||||
|
||||
return new Promise((resolve) => {
|
||||
if (animated) {
|
||||
// 停止任何进行中的动画
|
||||
@@ -322,7 +327,7 @@ export class AnimationManager {
|
||||
|
||||
// 使用GSAP同时动画缩放和平移
|
||||
gsap.to(viewTransform, {
|
||||
zoom: 1,
|
||||
zoom: scale,
|
||||
panX: panX,
|
||||
panY: panY,
|
||||
duration: 0.5,
|
||||
@@ -342,16 +347,16 @@ export class AnimationManager {
|
||||
},
|
||||
onComplete: () => {
|
||||
// 确保最终状态准确
|
||||
this.canvas.setViewportTransform([1, 0, 0, 1, panX, panY]);
|
||||
this.currentZoom.value = 100;
|
||||
this.canvas.setViewportTransform([scale, 0, 0, scale, panX, panY]);
|
||||
this.currentZoom.value = scale * 100;
|
||||
this._zoomAnimation = null;
|
||||
this._panAnimation = null;
|
||||
resolve();
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.canvas.setViewportTransform([1, 0, 0, 1, panX, panY]);
|
||||
this.currentZoom.value = 100;
|
||||
this.canvas.setViewportTransform([scale, 0, 0, scale, panX, panY]);
|
||||
this.currentZoom.value = scale * 100;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user