| Copyright | Will Thompson and Iñaki García Etxebarria |
|---|---|
| License | LGPL-2.1 |
| Maintainer | Iñaki García Etxebarria |
| Safe Haskell | None |
| Language | Haskell2010 |
GI.Gsk.Structs.Path
Description
Describes lines and curves that are more complex than simple rectangles.
Paths can used for rendering (filling or stroking) and for animations (e.g. as trajectories).
GskPath is an immutable, opaque, reference-counted struct.
After creation, you cannot change the types it represents. Instead,
new GskPath objects have to be created. The PathBuilder
structure is meant to help in this endeavor.
Conceptually, a path consists of zero or more contours (continuous, connected curves), each of which may or may not be closed. Contours are typically constructed from Bézier segments.
<picture> <source srcset="path-dark.png" media="(prefers-color-scheme: dark)"> <img alt="A Path" src="path-light.png"> </picture>
Since: 4.14
Synopsis
- newtype Path = Path (ManagedPtr Path)
- pathEqual :: (HasCallStack, MonadIO m) => Path -> Path -> m Bool
- pathForeach :: (HasCallStack, MonadIO m) => Path -> [PathForeachFlags] -> PathForeachFunc -> m Bool
- pathForeachIntersection :: (HasCallStack, MonadIO m) => Path -> Maybe Path -> PathIntersectionFunc -> m Bool
- pathGetBounds :: (HasCallStack, MonadIO m) => Path -> m (Bool, Rect)
- pathGetStrokeBounds :: (HasCallStack, MonadIO m) => Path -> Stroke -> m (Bool, Rect)
- pathGetTightBounds :: (HasCallStack, MonadIO m) => Path -> m (Bool, Rect)
- pathInFill :: (HasCallStack, MonadIO m) => Path -> Point -> FillRule -> m Bool
- pathIsClosed :: (HasCallStack, MonadIO m) => Path -> m Bool
- pathIsEmpty :: (HasCallStack, MonadIO m) => Path -> m Bool
- pathParse :: (HasCallStack, MonadIO m) => Text -> m (Maybe Path)
- pathPrint :: (HasCallStack, MonadIO m) => Path -> String -> m ()
- pathRef :: (HasCallStack, MonadIO m) => Path -> m Path
- pathToCairo :: (HasCallStack, MonadIO m) => Path -> Context -> m ()
- pathToString :: (HasCallStack, MonadIO m) => Path -> m Text
- pathUnref :: (HasCallStack, MonadIO m) => Path -> m ()
Exported types
Memory-managed wrapper type.
Constructors
| Path (ManagedPtr Path) |
Instances
| Eq Path Source # | |
| GBoxed Path Source # | |
Defined in GI.Gsk.Structs.Path | |
| ManagedPtrNewtype Path Source # | |
Defined in GI.Gsk.Structs.Path Methods toManagedPtr :: Path -> ManagedPtr Path Source # | |
| TypedObject Path Source # | |
| HasParentTypes Path Source # | |
Defined in GI.Gsk.Structs.Path | |
| IsGValue (Maybe Path) Source # | Convert |
| type ParentTypes Path Source # | |
Defined in GI.Gsk.Structs.Path | |
Methods
Click to display all available methods, including inherited ones
Methods
equal, foreach, foreachIntersection, inFill, isClosed, isEmpty, print, ref, toCairo, toString, unref.
Getters
getBounds, getStrokeBounds, getTightBounds.
Setters
None.
equal
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> Path |
|
| -> m Bool | Returns: true if |
Returns whether two paths have identical structure.
Note that it is possible to construct paths that render identical even though they don't have the same structure.
Since: 4.22
foreach
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> [PathForeachFlags] |
|
| -> PathForeachFunc |
|
| -> m Bool | Returns: false if |
Calls func for every operation of the path.
Note that this may only approximate self, because paths can contain
optimizations for various specialized contours, and depending on the
flags, the path may be decomposed into simpler curves than the ones
that it contained originally.
This function serves two purposes:
- When the
flagsallow everything, it provides access to the raw, unmodified data of the path. - When the
flagsdisallow certain operations, it provides an approximation of the path using just the allowed operations.
Since: 4.14
foreachIntersection
pathForeachIntersection Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> Maybe Path |
|
| -> PathIntersectionFunc |
|
| -> m Bool | Returns: |
Finds intersections between two paths.
This function finds intersections between path1 and path2,
and calls func for each of them, in increasing order for path1.
If path2 is not provided or equal to path1, the function finds
non-trivial self-intersections of path1.
When segments of the paths coincide, the callback is called once
for the start of the segment, with gSKPATHINTERSECTIONSTART, and
once for the end of the segment, with gSKPATHINTERSECTIONEND.
Note that other intersections may occur between the start and end
of such a segment.
If func returns FALSE, the iteration is stopped.
Since: 4.20
getBounds
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> m (Bool, Rect) | Returns: true if the path has bounds, false if the path is known to be empty and have no bounds |
Computes the bounds of the given path.
The returned bounds may be larger than necessary, because this
function aims to be fast, not accurate. The bounds are guaranteed
to contain the path. For accurate bounds, use
pathGetTightBounds.
It is possible that the returned rectangle has 0 width and/or height. This can happen when the path only describes a point or an axis-aligned line.
If the path is empty, false is returned and bounds are set to
rectZero. This is different from the case where the path
is a single point at the origin, where the bounds will also be set to
the zero rectangle but true will be returned.
Since: 4.14
getStrokeBounds
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> Stroke |
|
| -> m (Bool, Rect) | Returns: true if the path has bounds, false if the path is known to be empty and have no bounds. |
Computes the bounds for stroking the given path with the given parameters.
The returned bounds may be larger than necessary, because this function aims to be fast, not accurate. The bounds are guaranteed to contain the area affected by the stroke, including protrusions like miters.
Since: 4.14
getTightBounds
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> m (Bool, Rect) | Returns: true if the path has bounds, false if the path is known to be empty and have no bounds |
Computes the tight bounds of the given path.
This function works harder than pathGetBounds to
produce the smallest possible bounds.
Since: 4.22
inFill
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> Point |
|
| -> FillRule |
|
| -> m Bool | Returns: true if |
Returns whether a point is inside the fill area of a path.
Note that this function assumes that filling a contour implicitly closes it.
Since: 4.14
isClosed
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> m Bool | Returns: true if the path is closed |
Returns if the path represents a single closed contour.
Since: 4.14
isEmpty
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> m Bool | Returns: true if the path is empty |
Checks if the path is empty, i.e. contains no lines or curves.
Since: 4.14
parse
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Text |
|
| -> m (Maybe Path) | Returns: a new |
Constructs a path from a serialized form.
The string is expected to be in (a superset of)
SVG path syntax,
as e.g. produced by pathToString.
A high-level summary of the syntax:
M x yMove to(x, y)L x yAdd a line from the current point to(x, y)Q x1 y1 x2 y2Add a quadratic Bézier from the current point to(x2, y2), with control point(x1, y1)C x1 y1 x2 y2 x3 y3Add a cubic Bézier from the current point to(x3, y3), with control points(x1, y1)and(x2, y2)ZClose the contour by drawing a line back to the start pointH xAdd a horizontal line from the current point to the given x valueV yAdd a vertical line from the current point to the given y valueT x2 y2Add a quadratic Bézier, using the reflection of the previous segments' control point as control pointS x2 y2 x3 y3Add a cubic Bézier, using the reflection of the previous segments' second control point as first control pointA rx ry r l s x yAdd an elliptical arc from the current point to(x, y)with radii rx and ry. See the SVG documentation for how the other parameters influence the arc.O x1 y1 x2 y2 wAdd a rational quadratic Bézier from the current point to(x2, y2)with control point(x1, y1)and weightw.
All the commands have lowercase variants that interpret coordinates relative to the current point.
The O command is an extension that is not supported in SVG.
Since: 4.14
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> String |
|
| -> m () |
Converts the path into a human-readable representation.
The string is compatible with (a superset of)
SVG path syntax,
see pathParse for a summary of the syntax.
Since: 4.14
ref
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> m Path | Returns: the passed in |
Increases the reference count of a path by one.
Since: 4.14
toCairo
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> Context |
|
| -> m () |
Appends the path to a cairo context for drawing with Cairo.
This may cause some suboptimal conversions to be performed as
Cairo does not support all features of GskPath.
This function does not clear the existing Cairo path. Call
cairo_new_path() if you want this.
Since: 4.14
toString
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Path |
|
| -> m Text | Returns: a new string for |
Converts the path into a human-readable string.
You can use this function in a debugger to get a quick overview of the path.
This is a wrapper around pathPrint, see that function
for details.
Since: 4.14