Module Brr_canvas.C2d
The 2D canvas context.
Enumerations
module Fill_rule : sig ... end
Fill rule enum.
module Image_smoothing_quality : sig ... end
Image smoothing quality enum.
module Line_cap : sig ... end
Line cap.
module Line_join : sig ... end
Line join.
module Text_align : sig ... end
Text alignement.
module Text_baseline : sig ... end
Text baseline.
module Text_direction : sig ... end
Text direction.
module Composite_op : sig ... end
Compositing operators.
module Repeat : sig ... end
Pattern repetition.
Paths
module Path : sig ... end
Path2D objects.
Image sources
type image_src
The type for canvas image sources. This can be many things.
val image_src_of_el : Brr.El.t -> image_src
image_src_of_el e
use this with anEl
.img,El
.video,El
.canvas element. No checks are performed.
val image_src_of_jv : Jv.t -> image_src
image_src_of_jv jv
is an image source from the given JavaScript value.jv
must be one of these things, no checks are performed.
Context attributes
type attrs
The type for CanvasRenderingContext2DSettings.
val attrs : ?alpha:bool -> ?desynchronized:bool -> unit -> attrs
attrs ()
areattrs
with the given attributes.
val attrs_alpha : attrs -> bool
attrs_alpha a
is thealpha
attribute ofa
.
val attrs_desynchronized : attrs -> bool
attrs_desynchronized a
is thedesynchronized
attribute ofa
.
Context
type t
The type for CanvasRenderingContext2D objects.
val create : ?attrs:attrs -> Canvas.t -> t
create ~attrs cnv
creates 2D context for canvascnv
with attributesattrs
.
Antialiasing
val image_smoothing_enabled : t -> bool
image_smoothing_enabled c
determines the image smoothing (antialiasing) performed onc
.
val set_image_smoothing_enabled : t -> bool -> unit
image_smoothing_enabled c b
sets the image smoothing (antialiasing) performed onc
.
val image_smoothing_quality : t -> Image_smoothing_quality.t
image_smoothing_enabled c
determines image smoothing quality (antialiasing) performed onc
.
val set_image_smoothing_quality : t -> Image_smoothing_quality.t -> unit
image_smoothing_enabled c
sets the image smoothing quality (antialiasing) performed onc
.
Compositing
val global_alpha : t -> float
global_alpha c
is the global alpha ofc
.
val set_global_alpha : t -> float -> unit
set_global_alpha c a
setes the global alpha ofc
toa
.
val global_composite_op : t -> Composite_op.t
global_composite_op c
is the global composite operator ofc
.
val set_global_composite_op : t -> Composite_op.t -> unit
set_global_composite_op c op
sets the global composite operator ofc
toop
.
Transformations
val reset_transform : t -> unit
reset_transform c
resets the current transformation matrix to the identity.
val transform : t -> Matrix4.t -> unit
transform c m
transforms space by matrixm
.
val translate : t -> x:float -> y:float -> unit
translate c x y
translates space by (x
,y
).
Style fills and strokes
val set_stroke_style : t -> style -> unit
set_stroke_style c s
sets the stroke style ofc
tos
.
val set_fill_style : t -> style -> unit
set_fill_style c s
sets the fill style ofc
tos
.
val color : Jstr.t -> style
color s
is the colors
parsed as a CSS color value as a style.
val linear_gradient : t -> x0:float -> y0:float -> x1:float -> y1:float -> stops:(float * Jstr.t) list -> gradient
linear_gradient c ~x0 ~y0 ~x1 ~y1 ~stops
create a linear gradient from (x0
,y0
) to (x1
,y1
) with color stopsstops
.
val radial_gradient : t -> x0:float -> y0:float -> r0:float -> x1:float -> y1:float -> r1:float -> stops:(float * Jstr.t) list -> gradient
radial_gradient c ~x0 ~y0 ~r0 ~x1 ~y1 ~r1 ~stops
create a radial gradient from circle centered at (x0
,y0
) with radiusr0
to circle centered at (x1
,y1
) with radiusr1
and color stopsstops
.
Style lines
val line_width : t -> float
line_width c
is the line width inc
.
val set_line_width : t -> float -> unit
set_line_width c w
set the line width tow
inc
.
val line_cap : t -> Line_cap.t
line_cap c
is the line cap inc
.
val set_line_cap : t -> Line_cap.t -> unit
set_line_cap c cap
set the line cap tocap
inc
.
val line_join : t -> Line_join.t
line_join c
is the line join inc
.
val set_line_join : t -> Line_join.t -> unit
set_line_join c join
set the line join tojoin
inc
.
val miter_limit : t -> float
miter_limit c
is the miter limit inc
.
val set_miter_limit : t -> float -> unit
set_miter_limit c l
set the miter limit tol
inc
.
val line_dash : t -> float list
line_dash c
are the line dashes inc
.
val line_dash_offset : t -> float
line_dash_offset c
is the line dash offset inc
.
val set_line_dash_offset : t -> float -> unit
set_line_dash_offset c o
set the line dash offset too
inc
.
Style shadows
val shadow_blur : t -> float
shadow_blur c
is the shadow blur ofc
.
val set_shadow_blur : t -> float -> unit
set_shadow_blur c b
sets the shadow blur ofc
tob
.
val shadow_offset_x : t -> float
shadow_offset_x c
is the x shadow offset ofc
.
val set_shadow_offset_x : t -> float -> unit
set_shadow_offset_x c o
sets the x shadow offset ofc
too
val shadow_offset_y : t -> float
shadow_offset_y c
is the y shadow offset ofc
.
val set_shadow_offset_y : t -> float -> unit
set_shadow_offset_x c o
sets the y shadow offset ofc
too
.
val shadow_color : t -> Jstr.t
shadow_color c
is the shadow color ofc
.
val set_shadow_color : t -> Jstr.t -> unit
set_shadow_color c col
sets the shadow color ofc
tocol
.
Style text
val text_align : t -> Text_align.t
text_align c
is the text align inc
.
val set_text_align : t -> Text_align.t -> unit
set_text_align c a
set the text align toa
inc
.
val text_baseline : t -> Text_baseline.t
text_baseline c
is the text baseline inc
.
val set_text_baseline : t -> Text_baseline.t -> unit
set_text_baseline c b
set the text baseline tob
inc
.
val text_direction : t -> Text_direction.t
text_direction c
is the text direction inc
.
val set_text_direction : t -> Text_direction.t -> unit
set_direction c d
set the text direction tod
inc
.
Draw rectangles
val clear_rect : t -> x:float -> y:float -> w:float -> h:float -> unit
clear_rect c x y ~w ~h
clears the given rectangular area by setting it to transparent black.
val fill_rect : t -> x:float -> y:float -> w:float -> h:float -> unit
fill_rect c x y ~w ~h
fill the given rectangular area with current fill style.
val stroke_rect : t -> x:float -> y:float -> w:float -> h:float -> unit
stroke_rect c x y ~w ~h
strokes the given rectangular area with current stroke style.
Draw paths
Note. fill_rule
always defaults to Fill_rule.nonzero
.
val fill : ?fill_rule:Fill_rule.t -> t -> Path.t -> unit
fill ~fill_rule c p
fillsp
inc
according tofill_rule
.
val clip : ?fill_rule:Fill_rule.t -> t -> Path.t -> unit
clip ~fill_rule c p
clip drawing to the region ofp
inc
according tofill_rule
.
val draw_focus_if_needed : t -> Path.t -> Brr.El.t -> unit
draw_focus_if_needed c p e
draws a focus ring aroundp
inc
ife
has focus.
val scroll_path_into_view : t -> Path.t -> unit
scroll_path_into_view c p
scrolls pathp
into view inc
.
val is_point_in_fill : ?fill_rule:Fill_rule.t -> t -> Path.t -> x:float -> y:float -> bool
is_point_in_fill ~fill_rule c p x y
determines whether (x
,y
) is in the fill determiend by pathp
inc
according tofill_rule
.
val is_point_in_stroke : t -> Path.t -> x:float -> y:float -> bool
point_in_path c p x y
determines whether (x
,y
) is in the stroke determiend by pathp
.
Draw text
val fill_text : ?max_width:float -> t -> Jstr.t -> x:float -> y:float -> unit
fill_text c txt x y
fills texttxt
at position (x
,y
).
val stroke_text : ?max_width:float -> t -> Jstr.t -> x:float -> y:float -> unit
fill_text c txt x y
fills texttxt
at position (x
,y
).
module Text_metrics : sig ... end
Text metrics.
val measure_text : t -> Jstr.t -> Text_metrics.t
measure_text txt
measures texttxt
.
Draw images
val draw_image : t -> image_src -> x:float -> y:float -> unit
draw_image c i x y
draws imagei
in the rectangle ofc
with top-left corner (x
,y
) and bottom-right corner (x+iw
,y+ih
), withiw
andih
the width and height ofi
(unclear which unit that is though).
val draw_image_in_rect : t -> image_src -> x:float -> y:float -> w:float -> h:float -> unit
draw_image_in_rect c i x y ~w ~h
draws imagei
in the rectangle ofc
with top-left corner (x
,y
) and bottom-right corner (x+w
,y+h
).
val draw_sub_image_in_rect : t -> image_src -> sx:float -> sy:float -> sw:float -> sh:float -> x:float -> y:float -> w:float -> h:float -> unit
draw_sub_image_in_rect c i ~sx ~sy ~xw ~sh x y ~w ~h
draws the pixels ofi
in the image space rectangle with top-left corner (sx
,sy
) and bottom-right corner (sx+sw
,sy+sh
) in the rectangle ofc
with top-left corner (x
,y
) and bottom-right corner (x+w
,y+h
).
Pixel manipulation
module Image_data : sig ... end
Image data objects
val create_image_data : t -> w:int -> h:int -> Image_data.t
create_image_data c ~w ~h
is a new image data ofw
xh
transparent black pixels.
val get_image_data : t -> x:int -> y:int -> w:int -> h:int -> Image_data.t
get_image_data c x y ~w ~h
are the pixels of canvasc
in the image space rectangle with top-left corner (x
,y
) and bottom-right corner (x+w
,y+h
).
val put_image_data : t -> Image_data.t -> x:int -> y:int -> unit
put_image_data c d x y
writes the pixels ofd
in the image space rectangle ofc
with top-left corner (x
,y
) and bottom-right corner (x+iw
,y+ih
), withiw
andih
the width and height ofi
.
val put_sub_image_data : t -> Image_data.t -> sx:int -> sy:int -> sw:int -> sh:int -> x:int -> y:int -> unit
put_sub_image_data c d ~sx ~sy ~xw ~sh x y
writes the pixels ofd
in the image space rectangle with top-left corner (sx
,sy
) and bottom-right corner (sx+sw
,sy+sh
) to the image space rectangle ofc
with top-left corner (x
,y
) and bottom-right corner (x+sx
,y+sy
).