package bogue

  1. Overview
  2. Docs

Module Bogue.DrawSource

Low-level graphics and colors.

This module is internally used for low-level graphics and a thin layer over Tsdl.

The public API is mainly useful for Color management. There are also some helper functions for drawing into an Sdl_area.

Dependency graph
Sourcetype canvas

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

Sourcetype texture = Tsdl.Sdl.texture

Initialization and shutdown

Sourceval video_init : unit -> unit

Manually init the SDL video system, and detect the scaling factor used by Bogue. This is useful only if you don't use Bogue's mainloop (for instance if you manually manage your windows and event loop).

Sourceval quit : unit -> unit

Cleanup and quit SDL.

Colors

Sourcetype rgb = int * int * int

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

Sourcetype color = int * int * int * int

r,g,b,a

Sourcetype fill =
  1. | Pattern of texture
  2. | Solid of color

Predefined colors

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

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

Creating colors

Sourceval opaque : rgb -> color
Sourceval transp : rgb -> color
Sourceval lighter : color -> color
Sourceval darker : color -> color
Sourceval set_alpha : int -> rgb -> color
Sourceval random_color : unit -> color
Sourceval 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.

Sourceval pale : rgb -> rgb

Using colors

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

Equivalent to Sdl.set_render_draw_color.

Sourceval set_text_color : rgb -> unit

Overrides the Theme TEXT_COLOR variable.

Drawing functions

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

Sourceval 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).

Sourceval line : ?thick:int -> Tsdl.Sdl.renderer -> color:color -> x0:int -> y0:int -> x1:int -> y1:int -> unit
Sourceval 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).

Sourceval 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.

Misc

Sourcetype align =
  1. | Min
  2. | Center
  3. | Max
Sourceval 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.

Sourceval 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).

OCaml

Innovation. Community. Security.