GfxAll errors are reported with this exception. The payload is an informative message.
Type of windows.
val resource_ready : 'a resource -> boolTests if the resource is available.
val get_resource : 'a resource -> 'aReturns the content of the resource.
val get_resource_opt : 'a resource -> 'a optionReturns Some v if the resource is ready and None otherwise.
val create : string -> windowcreate s returns a window and a rendering surface from the string s. The string has the form "name:WxH:flags".
name is element id of the canvas representing the window.name is the window title.val get_window_size : window -> int * intreturns the dimensions in screen pixels of the window.
val set_window_size : window -> int -> int -> unitsets the dimensions in pixels of the window.
val set_context_logical_size : context -> int -> int -> unitset_context_logical_size ctx w h sets the logical size of the context. The initial values are the same dimentions as the window. The logical size reflects the range of pixels that are shown in the context. For instance, If the logical size is 100x100 but the window size is 400x400, each logical pixel will be automatically zoomed and displayed as a 4x4 pixel in the window.
val get_context_logical_size : context -> int * intget_context_logical_size ctx w h returns the logical size of the context.
val set_transform : context -> float -> bool -> bool -> unitset_transform ctx angle hflip vflip stores a transformation in the context. The transformation is a rotation of angle (in radians), on horizontal reflection (if hflip is true) and a vertical reflection (if vflip) is true).
val get_transform : context -> float * bool * boolget_transform ctx returns the transformation currently associated with the context.
val reset_transform : context -> unitreset_transform ctx is an alias for set_transform ctx 0.0 false false.
create_surface ctx w h creates a surface for the given rendering context.
val surface_size : surface -> int * intreturns the dimensions of a surface.
blit dst src x y copies surface src on surface dst at point (x,y).
blit_scale ctx dst src dx dy dw dh copies surface src on surface dst at point (dx,dy) scaling it to dw width and dh height
val blit_full :
context ->
surface ->
surface ->
int ->
int ->
int ->
int ->
int ->
int ->
int ->
int ->
unitblit_full ctx dst src sx sy sw sh dx dy dw dh copies the surface extracted from src at point (sx, sy) with dimensions (sw, sh) on surface dst at point (dx,dy) scaling it to dw width and dh height.
val color : int -> int -> int -> int -> colorcolor r g b a returns a color built from components red green blue and alpha. all values must be integers between 0 and 255 inclusive.
fill_rect ctx dst x y w h draws and fills a rectangle on surface surface dst at coordinates (x, y) and with dimensions w * h. The rectangle is filled with current color.
load_image ctx path loads an image whose content is given by an implementation dependent string (filename, url, … ). Common image types are supported (PNG, JPEG, …). The returned resource may not be extracted used until resource_ready returns true.
val load_file : string -> string resourceload_file path creates a resource that, when ready, resolves to the content of the file denoted by path.
path is a URL to be loaded with.path is the path of a file.val load_font : string -> string -> int -> fontload_font fn extra size loads font fn at size size given in points. The extra parameters allows to pass implementation dependent options.
fn is a font name. If it does not exist, it is silently replaced by a close matching font or default font by the browser.fn must be a path to the .ttf file containing the font.render_text ctx txt f c returns a surface containing the text txt rendered using font f with color c.
val measure_text : string -> font -> int * intmesure_text txt f returns the size (width and height) of the surface that render_text would return, without creating it.
type event = | NoEventno event
*)| KeyUp of stringKey with a given name was released
*)| KeyDown of stringKey with a given name was pressed
*)| MouseMove of int * intbutton pressed bitmask and x/y coordinates, relative to the window.
*)| MouseButton of int * bool * int * intbutton button number, pressed/released, x/y relative to the window.
*)| Quitreturned by the SDL backend whenever the user closes the window or hit CTRL-C in the terminal
*)The type of input events. The string describing keyboard events is implementation defined.
val poll_event : unit -> eventpoll_event () returns the next event in the event queue.
main_loop f k calls a f repeteadly. If the optional parameter limit is true (the default) then f is called no faster than 60 times/second. If limit is false then the function is called as much as possible which means:
f is called as fast as possible, unless the flag "r=presentvsync" is passed as a flag when creating the window, in which case, the function is called at the monitor refresh rate.f is called at the monitor refresh rate (which may be more than 60Hz) as per the specification of requestAnimationFrame. The callback f is given a float representing the elapsed time in milliseconds since the begining of the program. if f returns None, then it will continue being called. If f returns Some v then the continuation k v is called instead (once).One would typically write code such as:
let text_file = Gfx.load_file "foo.txt" in
Gfx.main_loop
(fun _dt -> Gfx.get_resource_opt text_file)
(fun content ->
(* do something with the content *)
)val commit : context -> unitcommit ctx renders the rendering context on to its underlying window. This should be the last graphical operation of the current frame.
open_formatter src opens a formatter for debugging purposes.
src must be the ID of an element whose innerHTML is appended to. It is recommended to style the element with the CSS property white-space:pre to preserve white spaces.src is the file path.set_debug_formatter fmt sets the current formatter. The default value is Format.stderr.
Format.stderr writes to the JavaScript console. in error mode (console.error).Format.stderr writes to the standard error as usual.