外观
graphics
原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793455665/FIN+5.3.1+graphics 中文整理基于 FIN 5.3.1
导读: @Serializable
以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。
目录(导读)
- mixins
- classes
- enums
- Slot Details
- a
- asColorPaint
- b
- black
- darker
- desaturate
- equals
- fromStr
- g
- h
- hash
- interpolateHsl
- interpolateRgb
- isColorPaint
- isTransparent
- l
- lighter
- make
- makeHsl
- makeRgb
- opacity
- r
- rgb
- s
- saturate
- toHexStr
- toStr
- transparent
- white
- fromProps
- name
- names
- size
- style
- toProps
- toSize
- toStyle
- toWeight
- weight
- ascent
- descent
- height
- leading
- width
- isNormal
- italic
- normal
- oblique
- vals
- bold
- extraBold
- extraLight
- fromNum
- light
- medium
- num
- semiBold
- thin
- alpha
- clipRect
- clipRoundRect
- color
- dispose
- drawEllipse
- drawImage
- drawImageRegion
- drawLine
- drawRect
- drawRoundRect
- drawText
- fillEllipse
- fillRect
- fillRoundRect
- font
- metrics
- paint
- path
- pop
- push
- stroke
- transform
- translate
- cur
- image
- arc
- clip
- close
- curveTo
- draw
- fill
- lineTo
- moveTo
- quadTo
- isLoaded
- mime
- render
- uri
- w
- write
- bottom
- defVal
- isNone
- left
- right
- top
- makeInt
- x
- y
- contains
- intersection
- intersects
- makePosSize
- pos
- union
- cap
- dash
- …(其余标题见英文正文)
API 正文(英文)
enums
| FontStyle | Font style property values: normal, italic, oblique |
| FontWeight | Font weight property values |
| StrokeCap | Defines how a stroke end cap is rendered |
| StrokeJoin | Defines how two stroke lines are joined together |
Color
@Js @Serializable { simple=true } const class Color : Obj, Paint
Models an CSS4 RGB color with alpha
Constructors
| fromStr | Parse color from CSS 4 string. |
| make | Make a new instance with the RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue. |
Fields
| a | The alpha component from 0.0 to 1.0 |
| black | Black is #000 |
| rgb | The RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue. |
| transparent | Transparent constant with opacity set to zero |
| white | White is #FFF |
Methods
| asColorPaint | Return this |
| b | The blue component from 0 to 255. |
| darker | Get a color which is a dark shade of this color. |
| desaturate | Convenience for saturate(-percentage). |
| equals | Equality |
| g | The green component from 0 to 255. |
| h | Hue as a float between 0.0 and 360.0 of the HSL model (hue, saturation, lightness). |
| hash | Return the hash code. |
| interpolateHsl | Interpolate between a and b where t is 0.0 to 1.0 using HSL color model. |
| interpolateRgb | Interpolate between a and b where t is 0.0 to 1.0 using RGB color model. |
| isColorPaint | Always return true |
| isTransparent | Return if a is zero, fully transparent |
| l | Lightness (brightness) as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). |
| lighter | Get a color which is a lighter shade of this color. |
| makeHsl | Construct a color using HSL model (hue, saturation, lightness) |
| makeRgb | Make a new instance with the RGB individual components as integers between 0 and 255 and alpha as float between 1.0 and 0.0. |
| opacity | Adjust the opacity of this color and return new instance, where opacity is between 0.0 and 1.0. |
| r | The red component from 0 to 255. |
| s | Saturation as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). |
| saturate | Adjust saturation as percentage between -1..1. |
| toHexStr | Format as #RGB, #RRGGBB or #RRGGBBAA syntax |
| toStr | If the alpha component is 1.0, then format as "#RRGGBB" hex string, otherwise format as "rbga()" notation. |
Slot Details
a
const Float a
The alpha component from 0.0 to 1.0
asColorPaint
virtual override Color asColorPaint()
Return this
b
Int b()
The blue component from 0 to 255.
black
const static Color black := Color.make(0, 1.0)
Black is #000
darker
Color darker(Float percentage := 0.2f)
Get a color which is a dark shade of this color. This decreases the brightness by the given percentage which is a float between 0.0 and 1.0.
desaturate
Color desaturate(Float percentage := 0.2f)
Convenience for saturate(-percentage).
equals
virtual override Bool equals(Obj? that)
Equality
fromStr
static new fromStr(Str s, Bool checked := true)
Parse color from CSS 4 string. If invalid and checked is true then throw ParseErr otherwise return null. The following formats are supported:
- CSS keyword color
- #RRGGBB
- #RRGGBBAA
- #RGB
- #RGBA
- rgb(r, g b)
- rgba(r, g, b, a)
- hsl(h, s, l)
- hsla(h, s, l, a)
Functional notation works with comma or space separated arguments.
Examples:
Color.fromStr("red")
Color.fromStr("#8A0")
Color.fromStr("#88AA00")
Color.fromStr("rgba(255, 0, 0, 0.3)")
Color.fromStr("rgb(100% 0% 0% 25%)")g
Int g()
The green component from 0 to 255.
h
Float h()
Hue as a float between 0.0 and 360.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, s, l.
hash
virtual override Int hash()
Return the hash code.
interpolateHsl
static Color interpolateHsl(Color a, Color b, Float t)
Interpolate between a and b where t is 0.0 to 1.0 using HSL color model.
interpolateRgb
static Color interpolateRgb(Color a, Color b, Float t)
Interpolate between a and b where t is 0.0 to 1.0 using RGB color model.
isColorPaint
virtual override Bool isColorPaint()
Always return true
isTransparent
Bool isTransparent()
Return if a is zero, fully transparent
l
Float l()
Lightness (brightness) as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, h, s.
lighter
Color lighter(Float percentage := 0.2f)
Get a color which is a lighter shade of this color. This increases the brightness by the given percentage which is a float between 0.0 and 1.0.
make
new make(Int rgb := 0, Float a := 1.0f)
Make a new instance with the RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue. Alpha should be a float between 1.0 and 0.0.
makeHsl
static Color makeHsl(Float h, Float s, Float l, Float a := 1.0f)
Construct a color using HSL model (hue, saturation, lightness):
- hue as 0.0 to 360.0
- saturation as 0.0 to 1.0
- lightness (or brightness) as 0.0 to 1.0
- alpha as 0.0 to 1.0 Also see
h,s,l.
makeRgb
static Color makeRgb(Int r, Int g, Int b, Float a := 1.0f)
Make a new instance with the RGB individual components as integers between 0 and 255 and alpha as float between 1.0 and 0.0.
opacity
Color opacity(Float opacity := 1.0f)
Adjust the opacity of this color and return new instance, where opacity is between 0.0 and 1.0.
r
Int r()
The red component from 0 to 255.
rgb
const Int rgb
The RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue.
s
Float s()
Saturation as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, h, l.
saturate
Color saturate(Float percentage := 0.2f)
Adjust saturation as percentage between -1..1.
toHexStr
Str toHexStr()
Format as #RGB, #RRGGBB or #RRGGBBAA syntax
toStr
virtual override Str toStr()
If the alpha component is 1.0, then format as "#RRGGBB" hex string, otherwise format as "rbga()" notation.
transparent
const static Color transparent := Color.make(0, 0.0)
Transparent constant with opacity set to zero
white
const static Color white := Color.make(16777215, 1.0)
White is #FFF
Font
@Js @Serializable { simple=true } const class Font : Obj
Font models font-family, font-size, and font-style, and font-weight. Metrics are available for a predefined set of fonts.
Constructors
| fromProps | Construct from a map of CSS props such as font-family, font-size. |
| fromStr | Parse font from string using CSS shorthand format for supported properties |
| make | Construct with it-block |
Fields
| names | List of prioritized family names |
| size | Size of font in points. |
| style | Style as normal, italic, or oblique |
| weight | Weight as number from 100 to 900 |
Methods
| equals | Equality is based on all fields. |
| hash | Return hash of all fields |
| name | First family name in names |
| toProps | Get CSS style properties for this font. |
| toSize | Return this font with different point size. |
| toStr | Format as "[style] [weight] <size>pt <names>" |
| toStyle | Return this font with different style |
| toWeight | Return this font with different weight. |
Slot Details
equals
virtual override Bool equals(Obj? that)
Equality is based on all fields.
fromProps
static new fromProps(Str:Str props)
Construct from a map of CSS props such as font-family, font-size. Also see toProps.
fromStr
static new fromStr(Str s, Bool checked := true)
Parse font from string using CSS shorthand format for supported properties:
[<style>] [<weight>] <size> <names>Examples:
Font.fromStr("12pt Arial")
Font.fromStr("bold 10pt Courier")
Font.fromStr("italic bold 8pt Times")
Font.fromStr("italic 300 10pt sans-serif")hash
virtual override Int hash()
Return hash of all fields
make
new make(|This| f)
Construct with it-block
name
Str name()
First family name in names
names
const Str[] names := Str["sans-serif"]
List of prioritized family names
size
const Float size := 11.0f
Size of font in points.
style
const FontStyle style := FontStyle.normal
Style as normal, italic, or oblique
toProps
Str:Str toProps()
Get CSS style properties for this font. Also see fromProps
toSize
Font toSize(Float size)
Return this font with different point size.
toStr
virtual override Str toStr()
Format as "[style] [weight] <size>pt <names>"
toStyle
Font toStyle(FontStyle style)
Return this font with different style
toWeight
Font toWeight(FontWeight weight)
Return this font with different weight.
weight
const FontWeight weight := FontWeight.normal
Weight as number from 100 to 900
FontMetrics
@Js abstract const class FontMetrics : Obj
FontMetrics represents font size information for a Font within a specific graphics context.
Methods
| ascent | Get ascent of this font which is the distance from baseline to top of chars, not including any leading area. |
| descent | Get descent of this font which is the distance from baseline to bottom of chars, not including any leading area. |
| height | Get height of this font which is the sum of ascent, descent, and leading. |
| leading | Get leading of this font which is the distance above the ascent which may include accents and other marks. |
| width | Get the width of the string when painted with this font. |
Slot Details
ascent
abstract Float ascent()
Get ascent of this font which is the distance from baseline to top of chars, not including any leading area.
descent
abstract Float descent()
Get descent of this font which is the distance from baseline to bottom of chars, not including any leading area.
height
abstract Float height()
Get height of this font which is the sum of ascent, descent, and leading.
leading
abstract Float leading()
Get leading of this font which is the distance above the ascent which may include accents and other marks.
width
abstract Float width(Str s)
Get the width of the string when painted with this font.
FontStyle
@Js @Serializable { simple=true } enum class FontStyle : Enum
Font style property values: normal, italic, oblique
Enum
| normal | |
| italic | |
| oblique |
Constructors
| fromStr | Return the FontStyle instance for the specified name. |
Fields
| vals | List of FontStyle values indexed by ordinal |
Methods
| isNormal | Is this the normal value |
Slot Details
fromStr
static new fromStr(Str name, Bool checked := true)
Return the FontStyle instance for the specified name. If not a valid name and checked is false return null, otherwise throw ParseErr.
isNormal
Bool isNormal()
Is this the normal value
italic
const static FontStyle italic := ...
normal
const static FontStyle normal := ...
oblique
const static FontStyle oblique := ...
vals
const static FontStyle[] vals := ...
List of FontStyle values indexed by ordinal
FontWeight
@Js @Serializable { simple=true } enum class FontWeight : Enum
Font weight property values
Enum
| thin | |
| extraLight | |
| light | |
| normal | |
| medium | |
| semiBold | |
| bold | |
| extraBold | |
| black |
Constructors
| fromStr | Return the FontWeight instance for the specified name. |
Fields
| num | Numeric weight as number from 100 to 900 |
| vals | List of FontWeight values indexed by ordinal |
Methods
| fromNum | From numeric value 100 to 900 |
| isNormal | Is this the normal value |
Slot Details
black
const static FontWeight black := ...
bold
const static FontWeight bold := ...
extraBold
const static FontWeight extraBold := ...
extraLight
const static FontWeight extraLight := ...
fromNum
static FontWeight? fromNum(Int num, Bool checked := true)
From numeric value 100 to 900
fromStr
static new fromStr(Str name, Bool checked := true)
Return the FontWeight instance for the specified name. If not a valid name and checked is false return null, otherwise throw ParseErr.
isNormal
Bool isNormal()
Is this the normal value
light
const static FontWeight light := ...
medium
const static FontWeight medium := ...
normal
const static FontWeight normal := ...
num
const Int num
Numeric weight as number from 100 to 900
semiBold
const static FontWeight semiBold := ...
thin
const static FontWeight thin := ...
vals
const static FontWeight[] vals := ...
List of FontWeight values indexed by ordinal
Graphics
@Js mixin Graphics
Graphics is used to draw 2D graphics.
Fields
| alpha | Global alpha value used to control opacity for rending. |
| color | Convenience for setting paint to a solid color. |
| font | Current font used for drawing text |
| paint | Current paint defines how text and shapes are stroked and filled |
| stroke | Current stroke defines how the shapes are outlined |
Methods
| clipRect | Convenience to clip the given the rectangle. |
| clipRoundRect | Clip a rectangle with rounded corners with the current paint. |
| dispose | Dispose of this graphics context and release underyling OS resources. |
| drawEllipse | Draw an ellipse within the given bounds with the current stroke and paint. |
| drawImage | Draw an image at the given coordinate for the top/left corner. |
| drawImageRegion | Draw a rectangular region of the source image to the drawing surface. |
| drawLine | Draw a line with the current stroke and paint. |
| drawRect | Draw a rectangle with the current stroke and paint. |
| drawRoundRect | Draw a rectangle with rounded corners with the current stroke and paint. |
| drawText | Draw a the text string with the current paint and font. |
| fillEllipse | Fill an ellipse within the given bounds with the current stroke and paint. |
| fillRect | Fill a rectangle with the current paint. |
| fillRoundRect | Fill a rectangle with rounded corners with the current paint. |
| metrics | Get font metrics for the current font |
| path | Begin a new path operation to stroke, fill, or clip a shape. |
| pop | Pop the graphics stack and reset the state to the the last push. |
| push | Push the current graphics state onto an internal stack. |
| transform | Perform an affine transformation on the coordinate system |
| translate | Translate the coordinate system to the new origin. |
Slot Details
alpha
abstract Float alpha
Global alpha value used to control opacity for rending. The value must be between 0.0 (transparent) and 1.0 (opaue).
clipRect
abstract This clipRect(Float x, Float y, Float w, Float h)
Convenience to clip the given the rectangle. This sets the clipping area to the intersection of the current clipping region and the specified rectangle.
clipRoundRect
abstract This clipRoundRect(Float x, Float y, Float w, Float h, Float wArc, Float hArc)
Clip a rectangle with rounded corners with the current paint. The ellipse of the corners is specified by wArc and hArc.
color
abstract Color color
Convenience for setting paint to a solid color. If the paint is currently not a solid color, then get returns Paint.asColorPaint.
dispose
abstract Void dispose()
Dispose of this graphics context and release underyling OS resources.
drawEllipse
abstract This drawEllipse(Float x, Float y, Float w, Float h)
Draw an ellipse within the given bounds with the current stroke and paint.
drawImage
abstract This drawImage(Image img, Float x, Float y, Float w := img.w(), Float h := img.h())
Draw an image at the given coordinate for the top/left corner. If the width or height does not correspond to the image's natural size then the image is scaled to fit.
drawImageRegion
abstract This drawImageRegion(Image img, Rect src, Rect dst)
Draw a rectangular region of the source image to the drawing surface. The src rectangle defines the subregion of the source image to use. The dst rectangle identifies the destination location. If the src size does not correspond to the dst size, then the image is scaled to fit.
drawLine
abstract This drawLine(Float x1, Float y1, Float x2, Float y2)
Draw a line with the current stroke and paint.
drawRect
abstract This drawRect(Float x, Float y, Float w, Float h)
Draw a rectangle with the current stroke and paint.
drawRoundRect
abstract This drawRoundRect(Float x, Float y, Float w, Float h, Float wArc, Float hArc)
Draw a rectangle with rounded corners with the current stroke and paint. The ellipse of the corners is specified by wArc and hArc.
drawText
abstract This drawText(Str s, Float x, Float y)
Draw a the text string with the current paint and font. The x, y coordinate specifies the left baseline corner of where the text is to be drawn. Technically this is a fill operation similiar to the Canvas fillText function (there is currently no support to stroke/outline text).
fillEllipse
abstract This fillEllipse(Float x, Float y, Float w, Float h)
Fill an ellipse within the given bounds with the current stroke and paint.
fillRect
abstract This fillRect(Float x, Float y, Float w, Float h)
Fill a rectangle with the current paint.
fillRoundRect
abstract This fillRoundRect(Float x, Float y, Float w, Float h, Float wArc, Float hArc)
Fill a rectangle with rounded corners with the current paint. The ellipse of the corners is specified by wArc and hArc.
font
abstract Font font
Current font used for drawing text
metrics
abstract FontMetrics metrics()
Get font metrics for the current font
paint
abstract Paint paint
Current paint defines how text and shapes are stroked and filled
path
abstract GraphicsPath path()
Begin a new path operation to stroke, fill, or clip a shape.
pop
abstract This pop()
Pop the graphics stack and reset the state to the the last push.
push
abstract This push(Rect? r := null)
Push the current graphics state onto an internal stack. Reset the state back to its current state via pop. If r is non-null, the graphics state is automatically translated and clipped to the bounds.
stroke
abstract Stroke stroke
Current stroke defines how the shapes are outlined
transform
abstract This transform(Transform transform)
Perform an affine transformation on the coordinate system
translate
abstract This translate(Float x, Float y)
Translate the coordinate system to the new origin. This call is a convenience for:
transform(Transform.translate(x, y))GraphicsEnv
@Js const mixin GraphicsEnv
GraphicsEnv encapsulates a graphics toolkit. It is responsible image loading and caching.
Methods
| cur | Default environment for the VM |
| image | Get an image for the given uri. |
Slot Details
cur
static GraphicsEnv cur()
Default environment for the VM
image
abstract Image image(Uri uri, Buf? data := null)
Get an image for the given uri. The uri is the unique key for the image in this environment. If file data is null, then asynchronously load and cache the image on the first load. Standard supported formats are: PNG, JPEG, and SVG.
GraphicsPath
@Js mixin GraphicsPath
GraphicsPath is used to path complex shapes for stroking, filling, and clipping.
Methods
| arc | Create circular arc centered at x, y with given radius. |
| clip | Intersect the current clipping shape with this path. |
| close | Close the path by add a line from current point back to starting point. |
| curveTo | Add a Bézier curve to the path. |
| draw | Stroke the the current path using current stroke and paint. |
| fill | Fill the current path with current paint. |
| lineTo | Add a line to the path from current point to given point. |
| moveTo | Move the current point without creating a line. |
| quadTo | Add a quadratic Bézier curve to the path. |
Slot Details
arc
abstract This arc(Float x, Float y, Float radius, Float start, Float sweep)
Create circular arc centered at x, y with given radius. The start angle and sweep angle are measured in degrees. East is 0°, north 90°, west is 180°, and south is 270°. Positive sweeps are counterclockwise and negative sweeps are clockwise.
clip
abstract This clip()
Intersect the current clipping shape with this path. This call terminates the current pathing operation.
close
abstract This close()
Close the path by add a line from current point back to starting point.
curveTo
abstract This curveTo(Float cp1x, Float cp1y, Float cp2x, Float cp2y, Float x, Float y)
Add a Bézier curve to the path. The cp1 and cp2 parameters specify the first and second control points; x and y specify the end point.
draw
abstract This draw()
Stroke the the current path using current stroke and paint. This call terminates the current pathing operation.
fill
abstract This fill()
Fill the current path with current paint. This call terminates the current pathing operation.
lineTo
abstract This lineTo(Float x, Float y)
Add a line to the path from current point to given point.
moveTo
abstract This moveTo(Float x, Float y)
Move the current point without creating a line.
quadTo
abstract This quadTo(Float cpx, Float cpy, Float x, Float y)
Add a quadratic Bézier curve to the path. The cpx and cpy specify the control point; the x and y specify the end point.
Image
@Js mixin Image
Graphical image. Images are loaded from a file using GraphicsEnv.image.
Methods
| h | Get the size height |
| isLoaded | Is this image completely loaded into memory for use. |
| mime | Image format based on file type |
| render | Render a new image with the given MIME type and size using the provided Graphics instance. |
| size | Get the natural size of this image. |
| uri | Unique uri key for this image in the GraphicsEnv cache. |
| w | Get the size width |
| write | Write image content to the given output stream, where encoding is based on mime type. |
Slot Details
h
virtual Float h()
Get the size height
isLoaded
abstract Bool isLoaded()
Is this image completely loaded into memory for use. When a given uri is first accessed by GraphicsEnv.image it may be asynchronously loaded in the background and false is returned until load is complete.
mime
abstract MimeType mime()
Image format based on file type:
image/pngimage/gifimage/jpegimage/svg+xml
render
static Image render(MimeType mime, Size size, |Graphics| f)
Render a new image with the given MIME type and size using the provided Graphics instance. Throws UnsupportedErr if rendering is not supported in this env.
size
abstract Size size()
Get the natural size of this image. If the image has not been loaded yet, then return 0,0.
uri
abstract Uri uri()
Unique uri key for this image in the GraphicsEnv cache.
w
virtual Float w()
Get the size width
write
virtual Void write(OutStream out)
Write image content to the given output stream, where encoding is based on mime type. Throws UnsupportedErr if write is not supported in this env.
Insets
@Js @Serializable { simple=true } const class Insets : Obj
Insets represents spacing around the edge of a rectangle.
Constructors
| fromStr | Parse from comma or space separated string using CSS format |
| make | Construct with top, and optional right, bottom, left. |
Fields
| bottom | Bottom side spacing |
| defVal | Default instance 0, 0, 0, 0. |
| left | Left side spacing |
| right | Right side spacing |
| top | Top side spacing |
Methods
| equals | Return if obj is same Insets value. |
| h | Top plus bottom |
| hash | Return hash of top, right, bottom, left. |
| isNone | Return if all sides are set to zero |
| toSize | Return right+left, top+bottom |
| toStr | If all four sides are equal return "len" otherwise return "top right bottom left". |
| w | Left plus right |
Slot Details
bottom
const Float bottom
Bottom side spacing
defVal
const static Insets defVal := ...
Default instance 0, 0, 0, 0.
equals
virtual override Bool equals(Obj? obj)
Return if obj is same Insets value.
fromStr
static new fromStr(Str s, Bool checked := true)
Parse from comma or space separated string using CSS format:
- "top"
- "top, right" (implies bottom = top, left = right)
- "top, right, bottom" (implies left = right)
- "top, right, bottom, left"
h
Float h()
Top plus bottom
hash
virtual override Int hash()
Return hash of top, right, bottom, left.
isNone
Bool isNone()
Return if all sides are set to zero
left
const Float left
Left side spacing
make
new make(Num top, Num? right := null, Num? bottom := null, Num? left := null)
Construct with top, and optional right, bottom, left. If one side is not specified, it is reflected from the opposite side:
Insets(5) => Insets(5,5,5,5)
Insets(5,6) => Insets(5,6,5,6)
Insets(5,6,7) => Insets(5,6,7,6)right
const Float right
Right side spacing
toSize
Size toSize()
Return right+left, top+bottom
toStr
virtual override Str toStr()
If all four sides are equal return "len" otherwise return "top right bottom left".
top
const Float top
Top side spacing
w
Float w()
Left plus right
Paint
@Js const mixin Paint
Paint models the color, image, or pattern used to stroke or fill a shape. Currently there is only one implementation: Color.
Methods
| asColorPaint | Return as solid Color |
| isColorPaint | Is this solid color paint |
Slot Details
asColorPaint
abstract Color asColorPaint()
Return as solid Color
isColorPaint
abstract Bool isColorPaint()
Is this solid color paint
Point
@Js @Serializable { simple=true } const class Point : Obj
Point models a x,y coordinate.
Constructors
| fromStr | Parse from comma or space separated string. |
| make | Construct with x, y. |
| makeInt | Construct with x, y. |
Fields
| defVal | Default instance is 0,0. |
| x | X coordinate |
| y | Y coordinate |
Methods
| equals | Return if obj is same Point value. |
| hash | Return hash of x and y. |
| toStr | Return "x y" |
| translate | Return x+tx, y+ty |
Slot Details
defVal
const static Point defVal := Point.<ctor>(0.0, 0.0)
Default instance is 0,0.
equals
virtual override Bool equals(Obj? obj)
Return if obj is same Point value.
fromStr
static new fromStr(Str s, Bool checked := true)
Parse from comma or space separated string. If invalid then throw ParseErr or return null based on checked flag.
hash
virtual override Int hash()
Return hash of x and y.
make
new make(Float x, Float y)
Construct with x, y.
makeInt
new makeInt(Int x, Int y)
Construct with x, y.
toStr
virtual override Str toStr()
Return "x y"
translate
Point translate(Point t)
Return x+tx, y+ty
x
const Float x
X coordinate
y
const Float y
Y coordinate
Rect
@Js @Serializable { simple=true } const class Rect : Obj
Represents the x,y coordinate and w,h size of a rectangle.
Constructors
| fromStr | Parse from comma or space separated string. |
| make | Construct with x, y, w, h. |
| makeInt | Construct with x, y, w, h as integers. |
| makePosSize | Construct from a Point and Size instance |
Fields
| defVal | Default instance is 0, 0, 0, 0. |
| h | Height |
| w | Width |
| x | X coordinate |
| y | Y coordinate |
Methods
| contains | Return true if x,y is inside the bounds of this rectangle. |
| equals | Return if obj is same Rect value. |
| hash | Return hash of x, y, w, and h. |
| intersection | Compute the intersection between this rectangle and that rectangle. |
| intersects | Return true if this rectangle intersects any portion of that rectangle |
| pos | Get the x, y coordinate of this rectangle. |
| size | Get the w, h size of this rectangle. |
| toStr | Return "x y w h" |
| union | Compute the union between this rectangle and that rectangle, which is the bounding box that exactly contains both rectangles. |
Slot Details
contains
Bool contains(Point pt)
Return true if x,y is inside the bounds of this rectangle.
defVal
const static Rect defVal := Rect.<ctor>(0.0, 0.0, 0.0, 0.0)
Default instance is 0, 0, 0, 0.
equals
virtual override Bool equals(Obj? obj)
Return if obj is same Rect value.
fromStr
static new fromStr(Str s, Bool checked := true)
Parse from comma or space separated string. If invalid then throw ParseErr or return null based on checked flag.
h
const Float h
Height
hash
virtual override Int hash()
Return hash of x, y, w, and h.
intersection
Rect intersection(Rect that)
Compute the intersection between this rectangle and that rectangle. If there is no intersection, then return defVal.
intersects
Bool intersects(Rect that)
Return true if this rectangle intersects any portion of that rectangle
make
new make(Float x, Float y, Float w, Float h)
Construct with x, y, w, h.
makeInt
new makeInt(Int x, Int y, Int w, Int h)
Construct with x, y, w, h as integers.
makePosSize
new makePosSize(Point p, Size s)
Construct from a Point and Size instance
pos
Point pos()
Get the x, y coordinate of this rectangle.
size
Size size()
Get the w, h size of this rectangle.
toStr
virtual override Str toStr()
Return "x y w h"
union
Rect union(Rect that)
Compute the union between this rectangle and that rectangle, which is the bounding box that exactly contains both rectangles.
w
const Float w
Width
x
const Float x
X coordinate
y
const Float y
Y coordinate
Size
@Js @Serializable { simple=true } const class Size : Obj
Size models the width and height of a shape.
Constructors
| fromStr | Parse from comma or space separated string. |
| make | Construct with w, h. |
| makeInt | Construct with w, h as integers. |
Fields
| defVal | Default instance is 0,0. |
| h | Height |
| w | Width |
Methods
| equals | Return if obj is same Size value. |
| hash | Return hash of w and h. |
| toStr | Return "w h" |
Slot Details
defVal
const static Size defVal := Size.<ctor>(0.0, 0.0)
Default instance is 0,0.
equals
virtual override Bool equals(Obj? obj)
Return if obj is same Size value.
fromStr
static new fromStr(Str s, Bool checked := true)
Parse from comma or space separated string. If invalid then throw ParseErr or return null based on checked flag.
h
const Float h
Height
hash
virtual override Int hash()
Return hash of w and h.
make
new make(Float w, Float h)
Construct with w, h.
makeInt
new makeInt(Int w, Int h)
Construct with w, h as integers.
toStr
virtual override Str toStr()
Return "w h"
w
const Float w
Width
Stroke
@Js @Serializable { simple=true } const class Stroke : Obj
Stroke defines the how to render shape outlines.
Constructors
| fromStr | Parse from string format |
| make | Make with an it-block |
| makeFields | Make with fields |
Fields
| cap | How to render line end caps. |
| dash | Dash pattern as space/comma separated numbers of dashes and gaps. |
| defVal | Default value is width 1, no dash, butt cap, miter join. |
| join | How to render line joins. |
| none | Value with width of zero |
| width | Stroke width. |
Methods
| equals | Equality is based on fields |
| hash | Hash is based on fields |
| isNone | Is the width set to zero |
| scale | Scale size and dash pattern by given ratio |
| toSize | Return this stroke with different width. |
| toStr | Return string format - see fromStr |
Slot Details
cap
const StrokeCap cap := StrokeCap.butt
How to render line end caps. Default is butt.
dash
const Str? dash
Dash pattern as space/comma separated numbers of dashes and gaps. If null then render as solid line.
defVal
const static Stroke defVal := makeFields
Default value is width 1, no dash, butt cap, miter join.
equals
virtual override Bool equals(Obj? obj)
Equality is based on fields
fromStr
static new fromStr(Str s, Bool checked := true)
Parse from string format:
width [dash] cap joinExamples:
0.5
2 [1, 2]
round radiushash
virtual override Int hash()
Hash is based on fields
isNone
Bool isNone()
Is the width set to zero
join
const StrokeJoin join := StrokeJoin.miter
How to render line joins. Default is miter.
make
new make(|This| f)
Make with an it-block
makeFields
new makeFields(Float width := 1.0f, Str? dash := null, StrokeCap cap := StrokeCap.butt, StrokeJoin join := StrokeJoin.miter)
Make with fields
none
const static Stroke none := Stroke.makeFields(0.0)
Value with width of zero
scale
Stroke scale(Float ratio)
Scale size and dash pattern by given ratio
toSize
Stroke toSize(Float newWidth)
Return this stroke with different width.
toStr
virtual override Str toStr()
Return string format - see fromStr
width
const Float width := 1.0f
Stroke width. Default is 1.
StrokeCap
@Js @Serializable { simple=true } enum class StrokeCap : Enum
Defines how a stroke end cap is rendered
Enum
| butt | Cap is a flat edge with no extension |
| round | Cap is a a rounded semi-circle |
| square | Cap is a half square extension |
Constructors
| fromStr | Return the StrokeCap instance for the specified name. |
Fields
| vals | List of StrokeCap values indexed by ordinal |
Slot Details
butt
const static StrokeCap butt := ...
Cap is a flat edge with no extension
fromStr
static new fromStr(Str name, Bool checked := true)
Return the StrokeCap instance for the specified name. If not a valid name and checked is false return null, otherwise throw ParseErr.
round
const static StrokeCap round := ...
Cap is a a rounded semi-circle
square
const static StrokeCap square := ...
Cap is a half square extension
vals
const static StrokeCap[] vals := ...
List of StrokeCap values indexed by ordinal
StrokeJoin
@Js @Serializable { simple=true } enum class StrokeJoin : Enum
Defines how two stroke lines are joined together
Enum
| bevel | Join using a bevel with angle to smooth transition |
| miter | Join using sharp corners |
| radius | Join using rounded semi-circle (round in SVG terminology) |
Constructors
| fromStr | Return the StrokeJoin instance for the specified name. |
Fields
| vals | List of StrokeJoin values indexed by ordinal |
Slot Details
bevel
const static StrokeJoin bevel := ...
Join using a bevel with angle to smooth transition
fromStr
static new fromStr(Str name, Bool checked := true)
Return the StrokeJoin instance for the specified name. If not a valid name and checked is false return null, otherwise throw ParseErr.
miter
const static StrokeJoin miter := ...
Join using sharp corners
radius
const static StrokeJoin radius := ...
Join using rounded semi-circle (round in SVG terminology)
vals
const static StrokeJoin[] vals := ...
List of StrokeJoin values indexed by ordinal
Transform
@Js @Serializable { simple=true } const class Transform : Obj
Transform models an affine transformation matrix:
|a c e|
|b d f|
|0 0 1|Constructors
| fromStr | Parse from SVG string format |
| make | Construct from matrix values |
Fields
| a | |
| b | |
| c | |
| d | |
| defVal | Default instance is no transform. |
| e | |
| f |
Methods
| equals | Equality is based on string format |
| hash | Hash code is based on string format |
| mult | Multiply this matrix by given matrix and return result as new instance |
| rotate | Rotate angle in degrees |
| scale | Scale transform |
| skewX | Skew x by angle in degrees |
| skewY | Skew y by angle in degrees |
| toStr | Return in matrix(<a> <b> <c> <d> <e> <f>) format |
| translate | Translate transform |
Slot Details
a
const Float a
b
const Float b
c
const Float c
d
const Float d
defVal
const static Transform defVal := ...
Default instance is no transform.
e
const Float e
equals
virtual override Bool equals(Obj? obj)
Equality is based on string format
f
const Float f
fromStr
static new fromStr(Str s, Bool checked := true)
Parse from SVG string format:
matrix(<a> <b> <c> <d> <e> <f>)
translate(<x> [<y>])
scale(<x> [<y>])
rotate(<a> [<x> <y>])
skewX(<a>)
skewY(<a>)hash
virtual override Int hash()
Hash code is based on string format
make
new make(Float a, Float b, Float c, Float d, Float e, Float f)
Construct from matrix values
mult
@Operator This mult(Transform that)
Multiply this matrix by given matrix and return result as new instance
rotate
static Transform rotate(Float angle, Float? cx := null, Float? cy := null)
Rotate angle in degrees
scale
static Transform scale(Float sx, Float sy)
Scale transform
skewX
static Transform skewX(Float angle)
Skew x by angle in degrees
skewY
static Transform skewY(Float angle)
Skew y by angle in degrees
toStr
virtual override Str toStr()
Return in matrix(<a> <b> <c> <d> <e> <f>) format
translate
static Transform translate(Float tx, Float ty)
Translate transform