Skip to content

Commit 9f67ec1

Browse files
committed
feat: 质点新增特性:当广视野的情况下,质点的详细信息文字渲染大小不随镜头缩放
1 parent 79b0d95 commit 9f67ec1

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

app/src/core/render/canvas2d/entityRenderer/EntityRenderer.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Section } from "@/core/stage/stageObject/entity/Section";
99
import { SvgNode } from "@/core/stage/stageObject/entity/SvgNode";
1010
import { TextNode } from "@/core/stage/stageObject/entity/TextNode";
1111
import { UrlNode } from "@/core/stage/stageObject/entity/UrlNode";
12+
import { DetailsManager } from "@/core/stage/stageObject/tools/entityDetailsManager";
1213
import { Color, Vector } from "@graphif/data-structures";
1314
import { Rectangle } from "@graphif/shapes";
1415

@@ -192,6 +193,15 @@ export class EntityRenderer {
192193
this.project.stageStyleManager.currentStyle.CollideBoxSelected,
193194
);
194195
}
196+
if (this.project.camera.currentScale < 0.2 && !connectPoint.detailsManager.isEmpty()) {
197+
const detailsText = DetailsManager.detailsToMarkdown(connectPoint.details);
198+
this.project.textRenderer.renderTextFromCenter(
199+
detailsText,
200+
this.project.renderer.transformWorld2View(connectPoint.geometryCenter),
201+
12, // 不随视野缩放而变化
202+
this.project.stageStyleManager.currentStyle.StageObjectBorder,
203+
);
204+
}
195205
}
196206

197207
private renderImageNode(imageNode: ImageNode) {

app/src/core/stage/stageManager/concreteMethods/StageSectionPackManager.tsx

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class SectionPackManager {
8181
if (!textNode.isSelected) {
8282
continue;
8383
}
84-
this.targetTextNodeToSection(textNode);
84+
this.targetTextNodeToSection(textNode, false, true);
8585
}
8686
this.project.historyManager.recordStep();
8787
}
@@ -152,8 +152,13 @@ export class SectionPackManager {
152152
* 将指定的文本节点转换成Section,自动删除原来的TextNode
153153
* @param textNode 要转换的节点
154154
* @param ignoreEdges 是否忽略边的影响
155+
* @param addConnectPoints 是否添加质点
155156
*/
156-
targetTextNodeToSection(textNode: TextNode, ignoreEdges: boolean = false): Section {
157+
targetTextNodeToSection(
158+
textNode: TextNode,
159+
ignoreEdges: boolean = false,
160+
addConnectPoints: boolean = false,
161+
): Section {
157162
// 获取这个节点的父级Section
158163
const fatherSections = this.project.sectionMethods.getFatherSections(textNode);
159164
const newSection = new Section(this.project, {
@@ -165,40 +170,40 @@ export class SectionPackManager {
165170
newSection.adjustLocationAndSize();
166171

167172
// 创建左上角和右下角的质点
168-
const radius = ConnectPoint.CONNECT_POINT_SHRINK_RADIUS;
169-
const sectionRectangle = newSection.collisionBox.getRectangle();
173+
if (addConnectPoints) {
174+
const radius = ConnectPoint.CONNECT_POINT_SHRINK_RADIUS;
175+
const sectionRectangle = newSection.collisionBox.getRectangle();
176+
177+
// 左上角质点
178+
const topLeftLocation = sectionRectangle.location.clone();
179+
const topLeftCollisionBox = new CollisionBox([new Rectangle(topLeftLocation, Vector.same(radius * 2))]);
180+
const topLeftPoint = new ConnectPoint(this.project, {
181+
collisionBox: topLeftCollisionBox,
182+
});
170183

171-
// 左上角质点
172-
const topLeftLocation = sectionRectangle.location.clone();
173-
const topLeftCollisionBox = new CollisionBox([new Rectangle(topLeftLocation, Vector.same(radius * 2))]);
174-
const topLeftPoint = new ConnectPoint(this.project, {
175-
collisionBox: topLeftCollisionBox,
176-
});
184+
// 右下角质点
185+
const bottomRightLocation = sectionRectangle.location
186+
.clone()
187+
.add(new Vector(sectionRectangle.size.x - radius * 2, sectionRectangle.size.y - radius * 2));
188+
const bottomRightCollisionBox = new CollisionBox([new Rectangle(bottomRightLocation, Vector.same(radius * 2))]);
189+
const bottomRightPoint = new ConnectPoint(this.project, {
190+
collisionBox: bottomRightCollisionBox,
191+
});
177192

178-
// 右下角质点
179-
const bottomRightLocation = sectionRectangle.location
180-
.clone()
181-
.add(new Vector(sectionRectangle.size.x - radius * 2, sectionRectangle.size.y - radius * 2));
182-
const bottomRightCollisionBox = new CollisionBox([new Rectangle(bottomRightLocation, Vector.same(radius * 2))]);
183-
const bottomRightPoint = new ConnectPoint(this.project, {
184-
collisionBox: bottomRightCollisionBox,
185-
});
193+
// 将质点添加到舞台
194+
this.project.stageManager.add(topLeftPoint);
195+
this.project.stageManager.add(bottomRightPoint);
186196

187-
// 将质点添加到舞台
188-
this.project.stageManager.add(topLeftPoint);
189-
this.project.stageManager.add(bottomRightPoint);
197+
// 将质点放入Section
198+
this.project.sectionInOutManager.goInSection([topLeftPoint, bottomRightPoint], newSection);
199+
}
190200

191201
// 将新的Section加入舞台
192202
this.project.stageManager.add(newSection);
193203
for (const fatherSection of fatherSections) {
194204
this.project.sectionInOutManager.goInSection([newSection], fatherSection);
195-
// 将质点放入Section
196-
// this.project.sectionInOutManager.goInSection([topLeftPoint, bottomRightPoint], fatherSection);
197205
}
198206

199-
// 将质点放入Section
200-
this.project.sectionInOutManager.goInSection([topLeftPoint, bottomRightPoint], newSection);
201-
202207
if (!ignoreEdges) {
203208
for (const edge of this.project.stageManager.getAssociations()) {
204209
if (edge instanceof Edge) {

0 commit comments

Comments
 (0)