Skip to content

Commit 0b6a0dd

Browse files
committed
✨ 增加了滚轮/shift+滚轮的自定义设置,缩放/纵向移动画布
1 parent 8da9f16 commit 0b6a0dd

File tree

8 files changed

+79
-13
lines changed

8 files changed

+79
-13
lines changed

app/src/core/service/Settings.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export namespace Settings {
7070
textNodeStartEditMode: "enter" | "ctrlEnter" | "altEnter" | "shiftEnter";
7171
textNodeSelectAllWhenStartEditByKeyboard: boolean;
7272
textNodeSelectAllWhenStartEditByMouseClick: boolean;
73+
mouseWheelMode: "zoom" | "move";
74+
mouseWheelWithShiftMode: "zoom" | "move";
7375
// 音效相关
7476
soundEnabled: boolean;
7577
cuttingLineStartSoundFile: string;
@@ -140,6 +142,8 @@ export namespace Settings {
140142
textNodeStartEditMode: "enter",
141143
textNodeSelectAllWhenStartEditByKeyboard: false,
142144
textNodeSelectAllWhenStartEditByMouseClick: true,
145+
mouseWheelMode: "zoom",
146+
mouseWheelWithShiftMode: "move",
143147
// 音效相关
144148
soundEnabled: true,
145149
cuttingLineStartSoundFile: "",

app/src/core/service/controlService/controller/concrete/ControllerCamera.tsx

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,24 +210,45 @@ ControllerCamera.mousewheel = (event: WheelEvent) => {
210210
// console.log(vector.toString());
211211
// // return false;
212212
// }
213-
214-
// 滚轮纵向滚动是缩放
215-
if (event.deltaY > 0) {
216-
Camera.targetScale *= 0.8;
217-
} else if (event.deltaY < 0) {
218-
Camera.targetScale *= 1.2;
213+
if (Controller.pressingKeySet.has("shift")) {
214+
if (Camera.mouseWheelWithShiftMode === "zoom") {
215+
zoomCameraByMouseWheel(event);
216+
} else {
217+
moveCameraByMouseWheel(event);
218+
}
219+
} else {
220+
if (Camera.mouseWheelMode === "zoom") {
221+
zoomCameraByMouseWheel(event);
222+
} else {
223+
moveCameraByMouseWheel(event);
224+
}
219225
}
220226

221227
// 滚轮横向滚动是水平移动
222228
if (event.deltaX > 0) {
223229
// 左移动
224-
Camera.location = Camera.location.add(new Vector((-Camera.moveAmplitude * 100) / Camera.currentScale, 0));
230+
Camera.location = Camera.location.add(new Vector((-Camera.moveAmplitude * 50) / Camera.currentScale, 0));
225231
} else if (event.deltaX < 0) {
226232
// 右移动
227-
Camera.location = Camera.location.add(new Vector((Camera.moveAmplitude * 100) / Camera.currentScale, 0));
233+
Camera.location = Camera.location.add(new Vector((Camera.moveAmplitude * 50) / Camera.currentScale, 0));
228234
}
229235
};
230-
236+
function zoomCameraByMouseWheel(event: WheelEvent) {
237+
if (event.deltaY > 0) {
238+
Camera.targetScale *= 0.8;
239+
} else if (event.deltaY < 0) {
240+
Camera.targetScale *= 1.2;
241+
}
242+
}
243+
function moveCameraByMouseWheel(event: WheelEvent) {
244+
if (event.deltaY > 0) {
245+
// 向上滚动是上移
246+
Camera.location = Camera.location.add(new Vector(0, (Camera.moveAmplitude * 50) / Camera.currentScale));
247+
} else if (event.deltaY < 0) {
248+
// 向下滚动是下移
249+
Camera.location = Camera.location.subtract(new Vector(0, (Camera.moveAmplitude * 50) / Camera.currentScale));
250+
}
251+
}
231252
/**
232253
* 如果使用了鼠标滚轮,则x或y的滚动必有一个接近100
233254
* @param event

app/src/core/stage/Camera.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ export namespace Camera {
4747
/** 当前的 画布/摄像机移动的速度矢量 */
4848
export let speed: Vector = Vector.getZero();
4949

50-
/** 当前的 移动加速度 */
51-
export const accelerate: Vector = Vector.getZero();
52-
5350
/**
5451
* 可以看成一个九宫格,主要用于处理 w s a d 按键移动,
5552
* 当同时按下w和s,这个值会是(-1,-1),表示朝着左上移动
@@ -84,6 +81,8 @@ export namespace Camera {
8481
export let limitCameraInCycleSpace = false;
8582
export let cameraCycleSpaceSizeX = 1000;
8683
export let cameraCycleSpaceSizeY = 1000;
84+
export let mouseWheelMode: "zoom" | "move" = "zoom"; // zoom or move
85+
export let mouseWheelWithShiftMode: "zoom" | "move" = "zoom"; // zoom or move
8786
let cameraKeyboardScaleRate = 0.2;
8887

8988
// IDEA: 突然有一个好点子
@@ -256,6 +255,12 @@ export namespace Camera {
256255
Settings.watch("cameraKeyboardScaleRate", (value) => {
257256
cameraKeyboardScaleRate = value;
258257
});
258+
Settings.watch("mouseWheelMode", (value) => {
259+
mouseWheelMode = value;
260+
});
261+
Settings.watch("mouseWheelWithShiftMode", (value) => {
262+
mouseWheelWithShiftMode = value;
263+
});
259264
}
260265

261266
/**

app/src/locales/en.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ settings:
364364
title: Enable Drag Auto Align Nodes
365365
description: |
366366
When enabled, nodes will automatically align with other nodes along the x-axis and y-axis when dragged and released
367+
mouseWheelMode:
368+
title: mouse Wheel Mode
369+
options:
370+
zoom: zoom
371+
move: move
372+
mouseWheelWithShiftMode:
373+
title: mouse Wheel Mode When Press Shift
374+
options:
375+
zoom: zoom
376+
move: move
367377
rectangleSelectWhenLeft:
368378
title: Strategy for Left Rectangle Selection
369379
description: |

app/src/locales/zh_CN.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,16 @@ settings:
351351
title: 鼠标拖动自动吸附对齐节点
352352
description: |
353353
开启后,拖动节点并松开时会与其他节点在x轴、y轴方向对齐
354+
mouseWheelMode:
355+
title: 鼠标滚轮模式
356+
options:
357+
zoom: 缩放
358+
move: 移动
359+
mouseWheelWithShiftMode:
360+
title: 按住Shift时,鼠标滚轮模式
361+
options:
362+
zoom: 缩放
363+
move: 移动
354364
rectangleSelectWhenLeft:
355365
title: 向左框选的策略
356366
description: |

app/src/locales/zh_TW.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ settings:
334334
title: 鼠标拖动自动对齐节点
335335
description: |
336336
开启后,拖动节点并松开时会与其他节点在x轴、y轴方向对齐
337+
mouseWheelMode:
338+
title: 鼠标滚轮模式
339+
options:
340+
zoom: 缩放
341+
move: 移动
342+
mouseWheelWithShiftMode:
343+
title: 按住Shift时,鼠标滚轮模式
344+
options:
345+
zoom: 缩放
346+
move: 移动
337347
rectangleSelectWhenLeft:
338348
title: 向左框选的策略
339349
description: |

app/src/pages/settings/control.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export default function Control() {
2626
<FieldGroup title="Mouse 鼠标设定" icon={<Mouse />}>
2727
<SettingField icon={<MousePointerClick />} settingKey="mouseRightDragBackground" type="select" />
2828
<SettingField icon={<AlignStartVertical />} settingKey="enableDragAutoAlign" type="switch" />
29+
<SettingField icon={<Mouse />} settingKey="mouseWheelMode" type="select" />
30+
<SettingField icon={<Mouse />} settingKey="mouseWheelWithShiftMode" type="select" />
2931
</FieldGroup>
3032
<FieldGroup title="RectangleSelect 框选" icon={<SquareDashedMousePointer />}>
3133
<SettingField icon={<SquareArrowDownRight />} settingKey="rectangleSelectWhenRight" type="select" />

app/src/pages/settings/visual.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ export default function Visual() {
7575
<SettingField icon={<Bug />} settingKey="showDebug" type="switch" />
7676
<SettingField icon={<VenetianMask />} settingKey="protectingPrivacy" type="switch" />
7777
</FieldGroup>
78-
<FieldGroup title="Testing Functions 实验性功能" icon={<FlaskConical />}>
78+
<FieldGroup
79+
title="Testing Functions 实验性功能"
80+
description="如果您不了解下面的设置,请不要修改它们。否则您会感觉出现灵异事件"
81+
icon={<FlaskConical />}
82+
>
7983
<SettingField icon={<Ratio />} settingKey="limitCameraInCycleSpace" type="switch" />
8084
<SettingField
8185
icon={<Scaling />}

0 commit comments

Comments
 (0)