Module Brr_canvas.C2d
The 2D canvas context.
Enumerations
module Fill_rule : sig ... endFill rule enum.
module Image_smoothing_quality : sig ... endImage smoothing quality enum.
module Line_cap : sig ... endLine cap.
module Line_join : sig ... endLine join.
module Text_align : sig ... endText alignement.
module Text_baseline : sig ... endText baseline.
module Text_direction : sig ... endText direction.
module Composite_op : sig ... endCompositing operators.
module Repeat : sig ... endPattern repetition.
Paths
module Path : sig ... endPath2D objects.
Image sources
The type for canvas image sources. This can be many things.
val image_src_of_el : Brr.El.t -> Brr_canvas.C2d.image_srcimage_src_of_el e use this with an Brr.El.img, Brr.El.video, Brr.El.canvas element. No checks are performed.
val image_src_of_jv : Jv.t -> Brr_canvas.C2d.image_srcimage_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
The type for CanvasRenderingContext2DSettings.
val attrs_alpha : Brr_canvas.C2d.attrs -> boolattrs_alpha a is the alpha attribute of a.
val attrs_color_space : Brr_canvas.C2d.attrs -> Jstr.tattrs_color_space a is the colorSpace attribute of a.
val attrs_desynchronized : Brr_canvas.C2d.attrs -> boolattrs_desynchronized a is the desynchronized attribute of a.
val attrs_will_read_frequently : Brr_canvas.C2d.attrs -> boolattrs_will_read_frequenty a is the willReadFrequently attribute of a.
Context
The type for CanvasRenderingContext2D objects.
val get_context :
?attrs:Brr_canvas.C2d.attrs ->
Brr_canvas.Canvas.t ->
Brr_canvas.C2d.tget_context ~attrs cnv is a 2D context for canvas cnv with attributes attrs.
val create :
?attrs:Brr_canvas.C2d.attrs ->
Brr_canvas.Canvas.t ->
Brr_canvas.C2d.tval canvas : Brr_canvas.C2d.t -> Brr_canvas.Canvas.t optioncanvas c is the canvas element associated to the context c (if any).
val attrs : Brr_canvas.C2d.t -> Brr_canvas.C2d.attrsattrs c are the context's attributes.
val save : Brr_canvas.C2d.t -> unitsave c saves the state of c.
val restore : Brr_canvas.C2d.t -> unitrestore c restores last save of c.
Antialiasing
val image_smoothing_enabled : Brr_canvas.C2d.t -> boolimage_smoothing_enabled c determines the image smoothing (antialiasing) performed on c.
val set_image_smoothing_enabled : Brr_canvas.C2d.t -> bool -> unitimage_smoothing_enabled c b sets the image smoothing (antialiasing) performed on c.
val image_smoothing_quality :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Image_smoothing_quality.timage_smoothing_enabled c determines image smoothing quality (antialiasing) performed on c.
val set_image_smoothing_quality :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Image_smoothing_quality.t ->
unitimage_smoothing_enabled c sets the image smoothing quality (antialiasing) performed on c.
Compositing
val global_alpha : Brr_canvas.C2d.t -> floatglobal_alpha c is the global alpha of c.
val set_global_alpha : Brr_canvas.C2d.t -> float -> unitset_global_alpha c a setes the global alpha of c to a.
val global_composite_op : Brr_canvas.C2d.t -> Brr_canvas.C2d.Composite_op.tglobal_composite_op c is the global composite operator of c.
val set_global_composite_op :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Composite_op.t ->
unitset_global_composite_op c op sets the global composite operator of c to op.
val filter : Brr_canvas.C2d.t -> Jstr.tfilter c is the filter of c.
val set_filter : Brr_canvas.C2d.t -> Jstr.t -> unitset_filter c f sets the filter of c to f.
Transformations
val get_transform : Brr_canvas.C2d.t -> Brr_canvas.Matrix4.tget_transform c gets the current transformation matrix.
val set_transform : Brr_canvas.C2d.t -> Brr_canvas.Matrix4.t -> unitset_transform c m sets the current transformation matrix.
val set_transform' :
Brr_canvas.C2d.t ->
a:float ->
b:float ->
c:float ->
d:float ->
e:float ->
f:float ->
unitset_transform' c ~a ~b ~c ~d ~e ~f sets the current transformation matrix.
val reset_transform : Brr_canvas.C2d.t -> unitreset_transform c resets the current transformation matrix to the identity.
val transform : Brr_canvas.C2d.t -> Brr_canvas.Matrix4.t -> unittransform c m transforms space by matrix m.
val transform' :
Brr_canvas.C2d.t ->
a:float ->
b:float ->
c:float ->
d:float ->
e:float ->
f:float ->
unittransform' c ~a ~b ~c ~d ~e ~f transforms space by matrix m.
val translate : Brr_canvas.C2d.t -> x:float -> y:float -> unittranslate c ~x ~y translates space by (x,y).
val rotate : Brr_canvas.C2d.t -> float -> unitrotate c r rotates space by r radians.
val scale : Brr_canvas.C2d.t -> sx:float -> sy:float -> unitscale c ~sx ~sy scales space by (sx, sy).
Style fills and strokes
val set_stroke_style : Brr_canvas.C2d.t -> Brr_canvas.C2d.style -> unitset_stroke_style c s sets the stroke style of c to s.
val set_fill_style : Brr_canvas.C2d.t -> Brr_canvas.C2d.style -> unitset_fill_style c s sets the fill style of c to s.
val color : Jstr.t -> Brr_canvas.C2d.stylecolor s is the color s parsed as a CSS color value as a style.
val gradient_style : Brr_canvas.C2d.gradient -> Brr_canvas.C2d.stylegradient_style g is a style from the given gradient.
val linear_gradient :
Brr_canvas.C2d.t ->
x0:float ->
y0:float ->
x1:float ->
y1:float ->
stops:(float * Jstr.t) list ->
Brr_canvas.C2d.gradientlinear_gradient c ~x0 ~y0 ~x1 ~y1 ~stops create a linear gradient from (x0,y0) to (x1,y1) with color stops stops.
val radial_gradient :
Brr_canvas.C2d.t ->
x0:float ->
y0:float ->
r0:float ->
x1:float ->
y1:float ->
r1:float ->
stops:(float * Jstr.t) list ->
Brr_canvas.C2d.gradientradial_gradient c ~x0 ~y0 ~r0 ~x1 ~y1 ~r1 ~stops create a radial gradient from circle centered at (x0,y0) with radius r0 to circle centered at (x1,y1) with radius r1 and color stops stops.
val pattern_style : Brr_canvas.C2d.pattern -> Brr_canvas.C2d.stylepattern_style p is a style from the given pattern.
val pattern :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.image_src ->
Brr_canvas.C2d.Repeat.t ->
tr:Brr_canvas.Matrix4.t option ->
Brr_canvas.C2d.patternpattern c img repeat ~tr creates a pattern from img repeatint it according to repeat and transform tr.
Style lines
val line_width : Brr_canvas.C2d.t -> floatline_width c is the line width in c.
val set_line_width : Brr_canvas.C2d.t -> float -> unitset_line_width c w set the line width to w in c.
val line_cap : Brr_canvas.C2d.t -> Brr_canvas.C2d.Line_cap.tline_cap c is the line cap in c.
val set_line_cap : Brr_canvas.C2d.t -> Brr_canvas.C2d.Line_cap.t -> unitset_line_cap c cap set the line cap to cap in c.
val line_join : Brr_canvas.C2d.t -> Brr_canvas.C2d.Line_join.tline_join c is the line join in c.
val set_line_join : Brr_canvas.C2d.t -> Brr_canvas.C2d.Line_join.t -> unitset_line_join c join set the line join to join in c.
val miter_limit : Brr_canvas.C2d.t -> floatmiter_limit c is the miter limit in c.
val set_miter_limit : Brr_canvas.C2d.t -> float -> unitset_miter_limit c l set the miter limit to l in c.
val line_dash : Brr_canvas.C2d.t -> float listline_dash c are the line dashes in c.
val set_line_dash : Brr_canvas.C2d.t -> float list -> unitset_line_dash c ds sets the line dashes to ds in c.
val line_dash_offset : Brr_canvas.C2d.t -> floatline_dash_offset c is the line dash offset in c.
val set_line_dash_offset : Brr_canvas.C2d.t -> float -> unitset_line_dash_offset c o set the line dash offset to o in c.
Style shadows
val shadow_blur : Brr_canvas.C2d.t -> floatshadow_blur c is the shadow blur of c.
val set_shadow_blur : Brr_canvas.C2d.t -> float -> unitset_shadow_blur c b sets the shadow blur of c to b.
val shadow_offset_x : Brr_canvas.C2d.t -> floatshadow_offset_x c is the x shadow offset of c.
val set_shadow_offset_x : Brr_canvas.C2d.t -> float -> unitset_shadow_offset_x c o sets the x shadow offset of c to o
val shadow_offset_y : Brr_canvas.C2d.t -> floatshadow_offset_y c is the y shadow offset of c.
val set_shadow_offset_y : Brr_canvas.C2d.t -> float -> unitset_shadow_offset_x c o sets the y shadow offset of c to o.
val shadow_color : Brr_canvas.C2d.t -> Jstr.tshadow_color c is the shadow color of c.
val set_shadow_color : Brr_canvas.C2d.t -> Jstr.t -> unitset_shadow_color c col sets the shadow color of c to col.
Style text
val font : Brr_canvas.C2d.t -> Jstr.tfont c is the font in c.
val set_font : Brr_canvas.C2d.t -> Jstr.t -> unitset_font c fnt set the font to fnt in c.
val text_align : Brr_canvas.C2d.t -> Brr_canvas.C2d.Text_align.ttext_align c is the text align in c.
val set_text_align : Brr_canvas.C2d.t -> Brr_canvas.C2d.Text_align.t -> unitset_text_align c a set the text align to a in c.
val text_baseline : Brr_canvas.C2d.t -> Brr_canvas.C2d.Text_baseline.ttext_baseline c is the text baseline in c.
val set_text_baseline :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Text_baseline.t ->
unitset_text_baseline c b set the text baseline to b in c.
val text_direction : Brr_canvas.C2d.t -> Brr_canvas.C2d.Text_direction.ttext_direction c is the text direction in c.
val set_text_direction :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Text_direction.t ->
unitset_direction c d set the text direction to d in c.
Draw rectangles
val clear_rect :
Brr_canvas.C2d.t ->
x:float ->
y:float ->
w:float ->
h:float ->
unitclear_rect c x y ~w ~h clears the given rectangular area by setting it to transparent black.
val fill_rect :
Brr_canvas.C2d.t ->
x:float ->
y:float ->
w:float ->
h:float ->
unitfill_rect c x y ~w ~h fill the given rectangular area with current fill style.
val stroke_rect :
Brr_canvas.C2d.t ->
x:float ->
y:float ->
w:float ->
h:float ->
unitstroke_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:Brr_canvas.C2d.Fill_rule.t ->
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Path.t ->
unitfill ~fill_rule c p fills p in c according to fill_rule.
val stroke : Brr_canvas.C2d.t -> Brr_canvas.C2d.Path.t -> unitstroke c p strokes path p in c.
val clip :
?fill_rule:Brr_canvas.C2d.Fill_rule.t ->
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Path.t ->
unitclip ~fill_rule c p clip drawing to the region of p in c according to fill_rule.
val draw_focus_if_needed :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Path.t ->
Brr.El.t ->
unitval scroll_path_into_view : Brr_canvas.C2d.t -> Brr_canvas.C2d.Path.t -> unitscroll_path_into_view c p scrolls path p into view in c.
val is_point_in_fill :
?fill_rule:Brr_canvas.C2d.Fill_rule.t ->
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Path.t ->
x:float ->
y:float ->
boolis_point_in_fill ~fill_rule c p x y determines whether (x,y) is in the fill determiend by path p in c according to fill_rule.
val is_point_in_stroke :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Path.t ->
x:float ->
y:float ->
boolpoint_in_path c p x y determines whether (x,y) is in the stroke determiend by path p.
Draw text
val fill_text :
?max_width:float ->
Brr_canvas.C2d.t ->
Jstr.t ->
x:float ->
y:float ->
unitfill_text c txt x y fills text txt at position (x,y).
val stroke_text :
?max_width:float ->
Brr_canvas.C2d.t ->
Jstr.t ->
x:float ->
y:float ->
unitfill_text c txt x y fills text txt at position (x,y).
module Text_metrics : sig ... endText metrics.
val measure_text : Brr_canvas.C2d.t -> Jstr.t -> Brr_canvas.C2d.Text_metrics.tmeasure_text txt measures text txt.
Draw images
val draw_image :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.image_src ->
x:float ->
y:float ->
unitdraw_image c i x y draws image i in the rectangle of c with top-left corner (x,y) and bottom-right corner (x+iw, y+ih), with iw and ih the width and height of i (unclear which unit that is though).
val draw_image_in_rect :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.image_src ->
x:float ->
y:float ->
w:float ->
h:float ->
unitdraw_image_in_rect c i x y ~w ~h draws image i in the rectangle of c with top-left corner (x,y) and bottom-right corner (x+w, y+h).
val draw_sub_image_in_rect :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.image_src ->
sx:float ->
sy:float ->
sw:float ->
sh:float ->
x:float ->
y:float ->
w:float ->
h:float ->
unitdraw_sub_image_in_rect c i ~sx ~sy ~xw ~sh x y ~w ~h draws the pixels of i in the image space rectangle with top-left corner (sx,sy) and bottom-right corner (sx+sw,sy+sh) in the rectangle of c with top-left corner (x,y) and bottom-right corner (x+w, y+h).
Pixel manipulation
module Image_data : sig ... endImage data objects
val create_image_data :
?color_space:Jstr.t ->
Brr_canvas.C2d.t ->
w:int ->
h:int ->
Brr_canvas.C2d.Image_data.tcreate_image_data c ~w ~h is a new image data of wxh transparent black pixels.
val get_image_data :
?color_space:Jstr.t ->
Brr_canvas.C2d.t ->
x:int ->
y:int ->
w:int ->
h:int ->
Brr_canvas.C2d.Image_data.tget_image_data c x y ~w ~h are the pixels of canvas c in the image space rectangle with top-left corner (x,y) and bottom-right corner (x+w, y+h).
val put_image_data :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Image_data.t ->
x:int ->
y:int ->
unitput_image_data c d x y writes the pixels of d in the image space rectangle of c with top-left corner (x,y) and bottom-right corner (x+iw, y+ih), with iw and ih the width and height of i.
val put_sub_image_data :
Brr_canvas.C2d.t ->
Brr_canvas.C2d.Image_data.t ->
sx:int ->
sy:int ->
sw:int ->
sh:int ->
x:int ->
y:int ->
unitput_sub_image_data c d ~sx ~sy ~xw ~sh x y writes the pixels of d in the image space rectangle with top-left corner (sx,sy) and bottom-right corner (sx+sw,sy+sh) to the image space rectangle of c with top-left corner (x,y) and bottom-right corner (x+sx, y+sy).
val to_jv : Brr_canvas.C2d.t -> Jv.jvval of_jv : Jv.jv -> Brr_canvas.C2d.t