-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d308fa7
commit b0a8a29
Showing
18 changed files
with
175 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions
52
demo/src/App/WorkArea/Canvas/ControlPointStems/ControlPointStems.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react' | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Utils | ||
// ----------------------------------------------------------------------------- | ||
|
||
const renderStems = (points) => | ||
points.map(([point1, point2], idx) => { | ||
return ( | ||
<line | ||
key={idx} | ||
x1={point1.x} | ||
y1={point1.y} | ||
x2={point2.x} | ||
y2={point2.y} | ||
stroke="#BBB" | ||
/> | ||
) | ||
}) | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Exports | ||
// ----------------------------------------------------------------------------- | ||
|
||
const ControlPointStems = ({ boundingCurves, width, height }) => { | ||
const points = [ | ||
[boundingCurves.top.startPoint, boundingCurves.top.controlPoint1], | ||
[boundingCurves.top.endPoint, boundingCurves.top.controlPoint2], | ||
[boundingCurves.bottom.startPoint, boundingCurves.bottom.controlPoint1], | ||
[boundingCurves.bottom.endPoint, boundingCurves.bottom.controlPoint2], | ||
[boundingCurves.left.startPoint, boundingCurves.left.controlPoint1], | ||
[boundingCurves.left.endPoint, boundingCurves.left.controlPoint2], | ||
[boundingCurves.right.startPoint, boundingCurves.right.controlPoint1], | ||
[boundingCurves.right.endPoint, boundingCurves.right.controlPoint2], | ||
] | ||
|
||
return ( | ||
<div className={`absolute inset-0`}> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
overflow="visible" | ||
viewBox={`0 0 ${width} ${height}`} | ||
width={width} | ||
height={height} | ||
> | ||
{renderStems(points)} | ||
</svg> | ||
</div> | ||
) | ||
} | ||
|
||
export default ControlPointStems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ControlPointStems from './ControlPointStems.jsx' | ||
|
||
export default ControlPointStems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React from 'react' | ||
import useObserveClientSize from '../../hooks/useObserveClientSize' | ||
import { clampGridSquareToGridDimensions } from '../../utils' | ||
import Canvas from './Canvas' | ||
import ControlNodes from './Canvas/ControlNodes' | ||
import ControlPointStems from './Canvas/ControlPointStems' | ||
import Shape from './Canvas/Shape' | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Const | ||
// ----------------------------------------------------------------------------- | ||
|
||
const BORDER_WIDTHS = 2 | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Exports | ||
// ----------------------------------------------------------------------------- | ||
|
||
const WorkArea = ({ | ||
setCanvas, | ||
canvasSize, | ||
coonsPatch, | ||
surface, | ||
config, | ||
boundingCurves, | ||
setBoundingCurves, | ||
handleNodePositionChange, | ||
handleShapeDrag, | ||
setCanvasSize, | ||
grid, | ||
}) => { | ||
const displayRef = React.useRef(null) | ||
|
||
const gridSquareClamped = React.useMemo( | ||
() => | ||
surface.gridSquare | ||
? clampGridSquareToGridDimensions(surface.gridSquare, grid) | ||
: surface.gridSquare, | ||
[surface, grid] | ||
) | ||
|
||
useObserveClientSize(displayRef, setCanvasSize, { | ||
// left + right border widths | ||
width: -BORDER_WIDTHS, | ||
// top + bottom border widths | ||
height: -BORDER_WIDTHS, | ||
}) | ||
|
||
return ( | ||
<div | ||
className="relative h-full flex-grow overflow-hidden" | ||
id="work-area" | ||
ref={displayRef} | ||
> | ||
<Canvas | ||
setCanvas={setCanvas} | ||
width={canvasSize.width} | ||
height={canvasSize.height} | ||
coonsPatch={coonsPatch} | ||
gridSquare={gridSquareClamped} | ||
surface={surface} | ||
config={config} | ||
/> | ||
{boundingCurves && ( | ||
<React.Fragment> | ||
<Shape | ||
boundingCurves={boundingCurves} | ||
onDrag={handleShapeDrag(boundingCurves, setBoundingCurves, config)} | ||
/> | ||
{config.bounds.shouldDrawCornerPoints && ( | ||
<React.Fragment> | ||
<ControlPointStems | ||
boundingCurves={boundingCurves} | ||
width={canvasSize.width} | ||
height={canvasSize.height} | ||
/> | ||
<ControlNodes | ||
boundingCurves={boundingCurves} | ||
onNodePositionChange={handleNodePositionChange( | ||
boundingCurves, | ||
setBoundingCurves, | ||
config | ||
)} | ||
/> | ||
</React.Fragment> | ||
)} | ||
</React.Fragment> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default WorkArea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import WorkArea from './WorkArea.jsx' | ||
|
||
export default WorkArea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters