bogue

GUI library for ocaml, with animations, based on SDL2
Library bogue
Module Bogue . Draw
Dependency graph
type canvas

Contains the hardware information for drawing (SDL renderer and window).

type texture = Tsdl.Sdl.texture

Initialization and shutdown

val quit : unit -> unit

Cleanup and quit SDL.

Colors

type rgb = int * int * int

red, green and blue values are integers in the range 0..255

type color = int * int * int * int

r,g,b,a

type fill =
| Pattern of texture
| Solid of color

Predefined colors

val black : rgb
val grey : rgb
val pale_grey : rgb
val dark_grey : rgb
val white : rgb
val red : rgb
val blue : rgb
val green : rgb
val magenta : rgb
val cyan : rgb
val yellow : rgb
val sienna : rgb
val label_color : rgb
val none : color

none = (0,0,0,0) is completely transparent black.

Creating colors

val opaque : rgb -> color
val transp : rgb -> color
val lighter : color -> color
val darker : color -> color
val set_alpha : int -> rgb -> color
val random_color : unit -> color
val find_color : string -> rgb

Convert a string of the form "grey" or "#FE01BC" to a rgb code (r,g,b). Color names are taken from here.

val pale : rgb -> rgb

Using colors

val set_color : Tsdl.Sdl.renderer -> color -> unit

Equivalent to Sdl.set_render_draw_color.

Drawing functions

These functions can be used to draw onto an Sdl_area.t.

val to_pixels : (int * int) -> int * int

Convert BOGUE logical coordinates into hardware pixel coordinates. This takes into account both the Theme SCALE and the high-dpi scaling of some systems (mac OS retina, iOS).

val line : ?thick:int -> Tsdl.Sdl.renderer -> color:color -> x0:int -> y0:int -> x1:int -> y1:int -> unit
val rectangle : ?thick:int -> Tsdl.Sdl.renderer -> color:color -> w:int -> h:int -> x:int -> y:int -> unit

rectangle renderer ~color ~thick ~w ~h ~x ~y draws a rectangle with given line thickness. The coordinate of the top left corner is (x,y). The size (including the thick line) is (w,h).

val circle : ?thick:int -> Tsdl.Sdl.renderer -> color:color -> radius:int -> x:int -> y:int -> unit

circle renderer ~width ~color ~radius ~x ~y draws a circle with given line thickness, centered at (x,y), with given radius.

Layers

type layer

Layers are used to decide the order of drawing: which graphical elements (layouts) should be below, which should be above. For the most part, you don't have to access them directly.

val use_new_layer : unit -> unit

Use this when you want to switch to a completely different set of layers, typically when you want to draw on another window.

Misc

type align =
| Min
| Center
| Max
val unscale_size : (int * int) -> int * int

Transform a size (W,H) in physical pixels into 'logical' pixels (w,h), which are used for layouts. This is done by dividing by the Theme SCALE variable.

val set_system_cursor : Tsdl.Sdl.System_cursor.t -> unit

Set the mouse cursor to be the standard system cursor. Internally, this first creates an SDL system cursor (or use a previously created one).