mirror of
https://gitlab.com/sheaf/metabrush.git
synced 2024-11-23 23:44:07 +00:00
draw Bézier curves and connecting lines
This commit is contained in:
parent
2bd6847e78
commit
ae0ac23910
|
@ -66,8 +66,10 @@ renderStroke cols zoom ( Stroke strokePts ) = go True strokePts
|
|||
drawPoints, drawNextPoints, drawPath, drawNextPath :: Cairo.Render ()
|
||||
( drawNextPoints, drawNextPath ) = go False ( p2 : ps )
|
||||
drawPoints = do
|
||||
when drawFirstPoint ( drawPoint cols zoom p0 )
|
||||
drawControl cols zoom p1
|
||||
drawLine cols zoom p0 p1
|
||||
drawLine cols zoom p1 p2
|
||||
when drawFirstPoint ( drawPoint cols zoom p0 )
|
||||
drawPoint cols zoom p2
|
||||
drawNextPoints
|
||||
drawPath = do
|
||||
|
@ -85,7 +87,7 @@ drawPoint ( Colours { pathPoint, pathPointOutline } ) zoom ( Point2D x y ) = do
|
|||
|
||||
Cairo.save
|
||||
Cairo.translate x y
|
||||
Cairo.scale ( 4 / zoom ) ( 4 / zoom )
|
||||
Cairo.scale ( 3 / zoom ) ( 3 / zoom )
|
||||
|
||||
Cairo.moveTo 1 0
|
||||
Cairo.lineTo 0.5 hsqrt3
|
||||
|
@ -95,7 +97,7 @@ drawPoint ( Colours { pathPoint, pathPointOutline } ) zoom ( Point2D x y ) = do
|
|||
Cairo.lineTo 0.5 (-hsqrt3)
|
||||
Cairo.closePath
|
||||
|
||||
Cairo.setLineWidth 1
|
||||
Cairo.setLineWidth 0.8
|
||||
withRGBA pathPointOutline Cairo.setSourceRGBA
|
||||
Cairo.strokePreserve
|
||||
|
||||
|
@ -108,11 +110,11 @@ drawControl ( Colours { controlPoint, controlPointOutline } ) zoom ( Point2D x y
|
|||
|
||||
Cairo.save
|
||||
Cairo.translate x y
|
||||
Cairo.scale ( 4 / zoom ) ( 4 / zoom )
|
||||
Cairo.scale ( 3 / zoom ) ( 3 / zoom )
|
||||
|
||||
Cairo.arc 0 0 1 0 ( 2 * pi )
|
||||
|
||||
Cairo.setLineWidth 1
|
||||
Cairo.setLineWidth 0.8
|
||||
withRGBA controlPointOutline Cairo.setSourceRGBA
|
||||
Cairo.strokePreserve
|
||||
|
||||
|
@ -121,5 +123,39 @@ drawControl ( Colours { controlPoint, controlPointOutline } ) zoom ( Point2D x y
|
|||
|
||||
Cairo.restore
|
||||
|
||||
drawLine :: Colours -> Double -> Point2D Double -> Point2D Double -> Cairo.Render ()
|
||||
drawLine ( Colours { controlPoint } ) zoom ( Point2D x1 y1 ) ( Point2D x2 y2 ) = do
|
||||
|
||||
Cairo.save
|
||||
Cairo.moveTo x1 y1
|
||||
Cairo.lineTo x2 y2
|
||||
|
||||
Cairo.setLineWidth ( 3 / zoom )
|
||||
withRGBA controlPoint Cairo.setSourceRGBA
|
||||
Cairo.stroke
|
||||
|
||||
Cairo.restore
|
||||
|
||||
drawQuadraticBezier :: Colours -> Double -> Quadratic.Bezier ( Point2D Double ) -> Cairo.Render ()
|
||||
drawQuadraticBezier _ _ _ = pure ()
|
||||
drawQuadraticBezier ( Colours { path } ) zoom
|
||||
( Quadratic.Bezier
|
||||
{ p0 = Point2D x0 y0
|
||||
, p1 = Point2D x1 y1
|
||||
, p2 = Point2D x2 y2
|
||||
}
|
||||
)
|
||||
= do
|
||||
|
||||
Cairo.save
|
||||
|
||||
Cairo.moveTo x0 y0
|
||||
Cairo.curveTo
|
||||
( ( 2 * x1 + x0 ) / 3 ) ( ( 2 * y1 + y0 ) / 3 )
|
||||
( ( 2 * x1 + x2 ) / 3 ) ( ( 2 * y1 + y2 ) / 3 )
|
||||
x2 y2
|
||||
|
||||
Cairo.setLineWidth ( 6 / zoom )
|
||||
withRGBA path Cairo.setSourceRGBA
|
||||
Cairo.stroke
|
||||
|
||||
Cairo.restore
|
||||
|
|
|
@ -114,6 +114,7 @@ createViewport colours activeDocumentTVar openDocumentsTVar viewportGrid = do
|
|||
GTK.setContainerChild viewportOverlay viewportDrawingArea
|
||||
GTK.widgetAddEvents viewportDrawingArea
|
||||
[ GDK.EventMaskPointerMotionMask
|
||||
, GDK.EventMaskButtonPressMask, GDK.EventMaskButtonReleaseMask
|
||||
, GDK.EventMaskScrollMask, GDK.EventMaskSmoothScrollMask
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in a new issue