Skip to content

Commit ac824eb

Browse files
committed
🚸 增加改变涂鸦粗细的快捷键
1 parent 9f2aed2 commit ac824eb

File tree

5 files changed

+97
-8
lines changed

5 files changed

+97
-8
lines changed

app/src/core/render/canvas2d/renderer.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,22 @@ export namespace Renderer {
566566
}
567567
}
568568
if (Stage.drawingControlMachine.isAdjusting) {
569+
const circleCenter = transformWorld2View(Stage.drawingControlMachine.startAdjustWidthLocation);
569570
// 鼠标正在调整状态
570571
ShapeRenderer.renderCircle(
571-
transformWorld2View(Stage.drawingControlMachine.startAdjustWidthLocation),
572+
circleCenter,
572573
(Stage.drawingMachine.currentStrokeWidth / 2) * Camera.currentScale,
573574
currentStrokeColor.a === 0 ? StageStyleManager.currentStyle.StageObjectBorder : currentStrokeColor,
574575
Color.Transparent,
575576
0,
576577
);
578+
// 当前粗细显示
579+
TextRenderer.renderTextFromCenter(
580+
`2R: ${Stage.drawingMachine.currentStrokeWidth}px`,
581+
circleCenter.add(new Vector(0, (-(Stage.drawingMachine.currentStrokeWidth / 2) - 40) * Camera.currentScale)),
582+
24,
583+
currentStrokeColor.a === 0 ? StageStyleManager.currentStyle.StageObjectBorder : currentStrokeColor,
584+
);
577585
} else {
578586
// 画跟随鼠标的笔头
579587
// 如果粗细大于一定程度,则渲染成空心的

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CuttingControllerClass extends ControllerClass {
4848
if (!(event.button == 2 || event.button == 0)) {
4949
return;
5050
}
51+
5152
// 左键按下的
5253
if (event.button === 0 && Stage.leftMouseMode === LeftMouseModeEnum.connectAndCut) {
5354
this.mouseDownEvent(event);
@@ -85,6 +86,10 @@ class CuttingControllerClass extends ControllerClass {
8586
if (!this.isUsing) {
8687
return;
8788
}
89+
if (Stage.drawingControlMachine.isAdjusting) {
90+
this.isUsing = false;
91+
return;
92+
}
8893
// 正在切断线
8994
this.cuttingLine = new Line(this.cuttingStartLocation, this.lastMoveLocation);
9095

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

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export class ControllerPenStrokeControl extends ControllerClass {
1414
* Alt键右键按下时的位置
1515
*/
1616
public startAdjustWidthLocation: Vector = Vector.getZero();
17+
/**
18+
* 在右键移动的过程中,记录上一次的位置
19+
*/
20+
public lastAdjustWidthLocation: Vector = Vector.getZero();
1721

1822
public mousedown: (event: MouseEvent) => void = (event) => {
1923
if (!(event.button === 2 && Stage.leftMouseMode === LeftMouseModeEnum.draw)) {
@@ -24,6 +28,7 @@ export class ControllerPenStrokeControl extends ControllerClass {
2428
// 右键按下时,开始调整笔刷粗细
2529
this.startAdjustWidthLocation = pressWorldLocation.clone();
2630
this.isAdjusting = true;
31+
this.lastAdjustWidthLocation = pressWorldLocation.clone();
2732
}
2833
};
2934

@@ -55,14 +60,50 @@ export class ControllerPenStrokeControl extends ControllerClass {
5560
}
5661
};
5762

63+
// public mousewheel: (event: WheelEvent) => void = (event) => {
64+
// if (Stage.leftMouseMode !== LeftMouseModeEnum.draw) {
65+
// return;
66+
// }
67+
// if (Controller.pressingKeySet.has("control")) {
68+
// // 控制放大缩小
69+
// if (isMac) {
70+
// // mac暂不支持滚轮缩放大小
71+
// return;
72+
// } else {
73+
// let newWidth;
74+
// if (event.deltaY > 0) {
75+
// newWidth = Stage.drawingMachine.currentStrokeWidth + 1;
76+
// } else {
77+
// newWidth = Stage.drawingMachine.currentStrokeWidth - 1;
78+
// }
79+
// Stage.drawingMachine.currentStrokeWidth = Math.max(1, Math.min(newWidth, 1000));
80+
// }
81+
// }
82+
// };
83+
5884
private onMouseMoveWhenAdjusting = (event: MouseEvent) => {
5985
// 更改宽度,检测鼠标上下移动的距离(模仿PS的笔刷粗细调整)
60-
const worldLocation = Renderer.transformView2World(new Vector(event.clientX, event.clientY));
61-
const delta = this.startAdjustWidthLocation.distance(worldLocation);
62-
// Stage.effectMachine.addEffect(LineEffect.default(this.startAdjustWidthLocation, worldLocation.clone()));
63-
if (delta > 1) {
64-
Stage.drawingMachine.currentStrokeWidth = Math.min(Math.round(delta * 2), 1000);
86+
const currentWorldLocation = Renderer.transformView2World(new Vector(event.clientX, event.clientY));
87+
88+
// const delta = this.startAdjustWidthLocation.distance(currentWorldLocation);
89+
let change = 1;
90+
if (currentWorldLocation.y > this.lastAdjustWidthLocation.y) {
91+
change *= -1;
6592
}
93+
// let delta = this.lastAdjustWidthLocation.distance(currentWorldLocation);
94+
// // 如果鼠标在往下走,就减小
95+
// if (currentWorldLocation.y > this.lastAdjustWidthLocation.y) {
96+
// delta = -delta;
97+
// }
98+
const lastWidth = Stage.drawingMachine.currentStrokeWidth;
99+
// Stage.effectMachine.addEffect(LineEffect.default(this.startAdjustWidthLocation, worldLocation.clone()));
100+
const newWidth = Math.round(lastWidth + change);
101+
102+
// 限制宽度范围
103+
Stage.drawingMachine.currentStrokeWidth = Math.max(1, Math.min(newWidth, 1000));
104+
105+
// 记录上一次位置
106+
this.lastAdjustWidthLocation = currentWorldLocation.clone();
66107
};
67108
}
68109

app/src/locales/zh_CN.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,4 +809,9 @@ keyBinds:
809809
checkoutLeftMouseToConnectAndCutting:
810810
title: 设置左键为“连线/斩断”模式
811811
description: |
812-
也就是鼠标左键切换为连线/斩断 模式,在工具栏中有对应按钮
812+
也就是鼠标左键切换为连线/斩断 模式,在工具栏中有对应按钮
813+
penStrokeWidthIncrease:
814+
title: 涂鸦笔画变粗
815+
description: 按下后,笔画变粗
816+
penStrokeWidthDecrease:
817+
description: 按下后,笔画变细

app/src/main.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { LastLaunch } from "./core/service/LastLaunch";
3333
import { Settings } from "./core/service/Settings";
3434
import { Tourials } from "./core/service/Tourials";
3535
import { Camera } from "./core/stage/Camera";
36-
import { Stage } from "./core/stage/Stage";
36+
import { LeftMouseModeEnum, Stage } from "./core/stage/Stage";
3737
import { StageLoader } from "./core/stage/StageLoader";
3838
import { StageEntityMoveManager } from "./core/stage/stageManager/concreteMethods/StageEntityMoveManager";
3939
import { StageSectionPackManager } from "./core/stage/stageManager/concreteMethods/StageSectionPackManager";
@@ -660,6 +660,36 @@ async function registerKeyBinds() {
660660
Settings.set("windowBackgroundAlpha", Math.max(0, currentValue - 0.2));
661661
}
662662
});
663+
664+
(
665+
await KeyBinds.create("penStrokeWidthIncrease", "=", {
666+
control: false,
667+
meta: false,
668+
alt: false,
669+
shift: false,
670+
})
671+
).down(async () => {
672+
if (Stage.leftMouseMode === LeftMouseModeEnum.draw) {
673+
const newWidth = Stage.drawingMachine.currentStrokeWidth + 4;
674+
Stage.drawingMachine.currentStrokeWidth = Math.max(1, Math.min(newWidth, 1000));
675+
Stage.effectMachine.addEffect(TextRiseEffect.default(`${Stage.drawingMachine.currentStrokeWidth}px`));
676+
}
677+
});
678+
(
679+
await KeyBinds.create("penStrokeWidthDecrease", "-", {
680+
control: false,
681+
meta: false,
682+
alt: false,
683+
shift: false,
684+
})
685+
).down(async () => {
686+
if (Stage.leftMouseMode === LeftMouseModeEnum.draw) {
687+
const newWidth = Stage.drawingMachine.currentStrokeWidth - 4;
688+
Stage.drawingMachine.currentStrokeWidth = Math.max(1, Math.min(newWidth, 1000));
689+
Stage.effectMachine.addEffect(TextRiseEffect.default(`${Stage.drawingMachine.currentStrokeWidth}px`));
690+
}
691+
});
692+
663693
(
664694
await KeyBinds.create("copy", "c", {
665695
control: isMac ? false : true,

0 commit comments

Comments
 (0)