Skip to content

Commit

Permalink
Prevent accidental dragging of drawings with guidelines.
Browse files Browse the repository at this point in the history
  • Loading branch information
anickle060193 committed Feb 28, 2018
1 parent a18ca9f commit 8053fce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
17 changes: 11 additions & 6 deletions src/components/DrawField/Drawings/DrawingComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,25 @@ interface LineDrawingProps extends LineStyle
y1: number;
x2: number;
y2: number;
hitEnabled: boolean;
}

export const LineDrawing: React.SFC<LineDrawingProps> = ( { x1, y1, x2, y2, color, strokeWidth, dash } ) => (
export const LineDrawing: React.SFC<LineDrawingProps> = ( { x1, y1, x2, y2, color, strokeWidth, dash, hitEnabled } ) => (
<>
<Line
points={[ x1, y1, x2, y2 ]}
stroke="transparent"
strokeWidth={5}
/>
{hitEnabled && (
<Line
points={[ x1, y1, x2, y2 ]}
stroke="transparent"
strokeWidth={5}
strokeHitEnabled={hitEnabled}
/>
)}
<Line
points={[ x1, y1, x2, y2 ]}
stroke={color}
strokeWidth={strokeWidth}
dash={dashStyles[ dash ]}
strokeHitEnabled={hitEnabled}
/>
</>
);
1 change: 1 addition & 0 deletions src/components/DrawField/Drawings/PathLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const PathLine: React.SFC<Props> = ( { drawing, onClick, onMouseDown, drawings,
color={drawing.color}
strokeWidth={drawing.strokeWidth}
dash={drawing.dash}
hitEnabled={true}
/>
{cursor && (
<>
Expand Down
20 changes: 15 additions & 5 deletions src/components/DrawField/Drawings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ interface BasicGuideLineProps extends LineStyle
interface VerticalGuideLineProps extends BasicGuideLineProps
{
x: number;
hitEnabled: boolean;
}

interface HorizontalGuideLineProps extends BasicGuideLineProps
{
y: number;
hitEnabled: boolean;
}

const VerticalGuideLine: React.SFC<VerticalGuideLineProps> = ( { x, color, dash, strokeWidth } ) => (
const VerticalGuideLine: React.SFC<VerticalGuideLineProps> = ( { x, color, dash, strokeWidth, hitEnabled } ) => (
<LineDrawing
x1={x}
y1={-LINE_LENGTH}
Expand All @@ -54,10 +56,11 @@ const VerticalGuideLine: React.SFC<VerticalGuideLineProps> = ( { x, color, dash,
color={color}
dash={dash}
strokeWidth={strokeWidth}
hitEnabled={hitEnabled}
/>
);

const HorizontalGuideLine: React.SFC<HorizontalGuideLineProps> = ( { y, color, strokeWidth, dash } ) => (
const HorizontalGuideLine: React.SFC<HorizontalGuideLineProps> = ( { y, color, strokeWidth, dash, hitEnabled } ) => (
<LineDrawing
x1={-LINE_LENGTH}
y1={y}
Expand All @@ -66,6 +69,7 @@ const HorizontalGuideLine: React.SFC<HorizontalGuideLineProps> = ( { y, color, s
color={color}
dash={dash}
strokeWidth={strokeWidth}
hitEnabled={hitEnabled}
/>
);

Expand All @@ -74,13 +78,13 @@ interface GuideLineProps extends VerticalGuideLineProps, HorizontalGuideLineProp
vertical: boolean;
}

const GuideLine: React.SFC<GuideLineProps> = ( { x, y, vertical, color, dash, strokeWidth } ) => (
const GuideLine: React.SFC<GuideLineProps> = ( { x, y, vertical, color, dash, strokeWidth, hitEnabled } ) => (
vertical ?
(
<VerticalGuideLine x={x} color={color} strokeWidth={strokeWidth} dash={dash} />
<VerticalGuideLine x={x} color={color} strokeWidth={strokeWidth} dash={dash} hitEnabled={hitEnabled} />
) :
(
<HorizontalGuideLine y={y} color={color} strokeWidth={strokeWidth} dash={dash} />
<HorizontalGuideLine y={y} color={color} strokeWidth={strokeWidth} dash={dash} hitEnabled={hitEnabled} />
)
);

Expand All @@ -94,6 +98,7 @@ export const Above: React.SFC<DrawingComponentProps<BasicDrawing<DrawingType.Abo
vertical={drawing.guideLine.vertical}
strokeWidth={drawing.guideLine.strokeWidth}
dash={drawing.guideLine.dash}
hitEnabled={false}
/>
)}
<Path
Expand All @@ -116,6 +121,7 @@ export const At: React.SFC<DrawingComponentProps<BasicDrawing<DrawingType.At>>>
vertical={drawing.guideLine.vertical}
strokeWidth={drawing.guideLine.strokeWidth}
dash={drawing.guideLine.dash}
hitEnabled={false}
/>
)}
<Path
Expand Down Expand Up @@ -145,6 +151,7 @@ export const Below: React.SFC<DrawingComponentProps<BasicDrawing<DrawingType.Bel
vertical={drawing.guideLine.vertical}
strokeWidth={drawing.guideLine.strokeWidth}
dash={drawing.guideLine.dash}
hitEnabled={false}
/>
)}
<Path
Expand All @@ -167,6 +174,7 @@ export const Between: React.SFC<DrawingComponentProps<BetweenDrawing>> = ( { dra
vertical={drawing.guideLine.vertical}
strokeWidth={drawing.guideLine.strokeWidth}
dash={drawing.guideLine.dash}
hitEnabled={false}
/>
)}
<Path
Expand All @@ -193,6 +201,7 @@ export const VerticalGridLine: React.SFC<DrawingComponentProps<VerticalGridLineD
color={drawing.color}
strokeWidth={drawing.strokeWidth}
dash={drawing.dash}
hitEnabled={true}
/>
</Group>
);
Expand All @@ -204,6 +213,7 @@ export const HorizontalGridLine: React.SFC<DrawingComponentProps<HorizontalGridL
color={drawing.color}
strokeWidth={drawing.strokeWidth}
dash={drawing.dash}
hitEnabled={true}
/>
</Group>
);
Expand Down

0 comments on commit 8053fce

Please sign in to comment.