feat: enable midpoint inside linear element editor (#5564)
* feat: enable midpoint inside linear element editor * fix * fix * hack to set pointerDownState.hit.hasHitElementInside when mid point added * remove hacks as not needed :) * remove newline * fix * add doc
This commit is contained in:
parent
f4b1a30bef
commit
46a61ad4df
@ -364,9 +364,6 @@ export class LinearElementEditor {
|
|||||||
scenePointer: { x: number; y: number },
|
scenePointer: { x: number; y: number },
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
) => {
|
) => {
|
||||||
if (appState.editingLinearElement) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const { elementId } = linearElementEditor;
|
const { elementId } = linearElementEditor;
|
||||||
const element = LinearElementEditor.getElement(elementId);
|
const element = LinearElementEditor.getElement(elementId);
|
||||||
if (!element) {
|
if (!element) {
|
||||||
|
@ -162,6 +162,7 @@ const renderSingleLinearPoint = (
|
|||||||
appState: AppState,
|
appState: AppState,
|
||||||
renderConfig: RenderConfig,
|
renderConfig: RenderConfig,
|
||||||
point: Point,
|
point: Point,
|
||||||
|
radius: number,
|
||||||
isSelected: boolean,
|
isSelected: boolean,
|
||||||
isPhantomPoint = false,
|
isPhantomPoint = false,
|
||||||
) => {
|
) => {
|
||||||
@ -173,10 +174,7 @@ const renderSingleLinearPoint = (
|
|||||||
} else if (isPhantomPoint) {
|
} else if (isPhantomPoint) {
|
||||||
context.fillStyle = "rgba(177, 151, 252, 0.7)";
|
context.fillStyle = "rgba(177, 151, 252, 0.7)";
|
||||||
}
|
}
|
||||||
const { POINT_HANDLE_SIZE } = LinearElementEditor;
|
|
||||||
const radius = appState.editingLinearElement
|
|
||||||
? POINT_HANDLE_SIZE
|
|
||||||
: POINT_HANDLE_SIZE / 2;
|
|
||||||
fillCircle(
|
fillCircle(
|
||||||
context,
|
context,
|
||||||
point[0],
|
point[0],
|
||||||
@ -205,32 +203,61 @@ const renderLinearPointHandles = (
|
|||||||
if (!centerPoint) {
|
if (!centerPoint) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const { POINT_HANDLE_SIZE } = LinearElementEditor;
|
||||||
|
const radius = appState.editingLinearElement
|
||||||
|
? POINT_HANDLE_SIZE
|
||||||
|
: POINT_HANDLE_SIZE / 2;
|
||||||
points.forEach((point, idx) => {
|
points.forEach((point, idx) => {
|
||||||
const isSelected =
|
const isSelected =
|
||||||
!!appState.editingLinearElement?.selectedPointsIndices?.includes(idx);
|
!!appState.editingLinearElement?.selectedPointsIndices?.includes(idx);
|
||||||
renderSingleLinearPoint(context, appState, renderConfig, point, isSelected);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!appState.editingLinearElement && points.length < 3) {
|
|
||||||
if (appState.selectedLinearElement.midPointHovered) {
|
|
||||||
const centerPoint = LinearElementEditor.getMidPoint(
|
|
||||||
appState.selectedLinearElement,
|
|
||||||
)!;
|
|
||||||
highlightPoint(centerPoint, context, appState, renderConfig);
|
|
||||||
|
|
||||||
|
renderSingleLinearPoint(
|
||||||
|
context,
|
||||||
|
appState,
|
||||||
|
renderConfig,
|
||||||
|
point,
|
||||||
|
radius,
|
||||||
|
isSelected,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (points.length < 3) {
|
||||||
|
if (appState.selectedLinearElement.midPointHovered) {
|
||||||
|
const centerPoint = LinearElementEditor.getMidPoint(
|
||||||
|
appState.selectedLinearElement,
|
||||||
|
)!;
|
||||||
|
// The order of renderingSingleLinearPoint and highLight points is different
|
||||||
|
// inside vs outside editor as hover states are different,
|
||||||
|
// in editor when hovered the original point is not visible as hover state fully covers it whereas outside the
|
||||||
|
// editor original point is visible and hover state is just an outer circle.
|
||||||
|
if (appState.editingLinearElement) {
|
||||||
renderSingleLinearPoint(
|
renderSingleLinearPoint(
|
||||||
context,
|
context,
|
||||||
appState,
|
appState,
|
||||||
renderConfig,
|
renderConfig,
|
||||||
centerPoint,
|
centerPoint,
|
||||||
|
radius,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
highlightPoint(centerPoint, context, renderConfig);
|
||||||
|
} else {
|
||||||
|
highlightPoint(centerPoint, context, renderConfig);
|
||||||
|
renderSingleLinearPoint(
|
||||||
|
context,
|
||||||
|
appState,
|
||||||
|
renderConfig,
|
||||||
|
centerPoint,
|
||||||
|
radius,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
renderSingleLinearPoint(
|
renderSingleLinearPoint(
|
||||||
context,
|
context,
|
||||||
appState,
|
appState,
|
||||||
renderConfig,
|
renderConfig,
|
||||||
centerPoint,
|
centerPoint,
|
||||||
|
POINT_HANDLE_SIZE / 2,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
@ -243,7 +270,6 @@ const renderLinearPointHandles = (
|
|||||||
const highlightPoint = (
|
const highlightPoint = (
|
||||||
point: Point,
|
point: Point,
|
||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
appState: AppState,
|
|
||||||
renderConfig: RenderConfig,
|
renderConfig: RenderConfig,
|
||||||
) => {
|
) => {
|
||||||
context.fillStyle = "rgba(105, 101, 219, 0.4)";
|
context.fillStyle = "rgba(105, 101, 219, 0.4)";
|
||||||
@ -280,7 +306,7 @@ const renderLinearElementPointHighlight = (
|
|||||||
context.save();
|
context.save();
|
||||||
context.translate(renderConfig.scrollX, renderConfig.scrollY);
|
context.translate(renderConfig.scrollX, renderConfig.scrollY);
|
||||||
|
|
||||||
highlightPoint(point, context, appState, renderConfig);
|
highlightPoint(point, context, renderConfig);
|
||||||
context.restore();
|
context.restore();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user