# Module graphics

This module implements graphical output for Nimrod; the current implementation uses SDL but the interface is meant to support multiple backends some day. There is no need to init SDL as this module does that implicitly.

# Imports

colors, math, sdl, sdl_ttf

# Types

    TRect* = tuple[x, y, width, height: int]

    TPoint* = tuple[x, y: int]

    PSurface* = ref TSurface

  a surface to draw onto

    TSurface* {.pure, final.} = object
      w*, h*: int
      s*: sdl.PSurface

    EGraphics* = object of EIO

    PFont* = ref TFont

  represents a font

# Vars

    defaultFont*: PFont

  default font that is used; this needs to initialized by the client!

# Procs

    proc toSdlColor*(c: TColor): Sdl.TColor

  Convert colors.TColor to SDL.TColor

    proc createSdlColor*(sur: PSurface; c: TColor; alpha: int = 0): int32

  Creates a color using `sdl.MapRGBA`.

    proc toSdlRect*(r: TRect): sdl.TRect

  Convert `graphics.TRect` to `sdl.TRect`.

    proc newSurface*(width, height: int): PSurface

  creates a new surface.

    proc newFont*(name = "VeraMono.ttf"; size = 9; color = colBlack): PFont

  Creates a new font object. Raises `EIO` if the font cannot be loaded.

    proc initDefaultFont*(name = "VeraMono.ttf"; size = 9; color = colBlack)

  initializes the defaultFont var.

    proc newScreenSurface*(width, height: int): PSurface

  Creates a new screen surface

    proc writeToBMP*(sur: PSurface; filename: string)

  Saves the contents of the surface sur to the file filename as a BMP file.

    proc `[]`*(sur: PSurface; p: TPoint): TColor

  get pixel at position p. No range checking is done!

    proc `[]`*(sur: PSurface; x, y: int): TColor

  get pixel at position `(x, y)`. No range checking is done!

    proc `[] =`*(sur: PSurface; p: TPoint; col: TColor)

  set the pixel at position p. No range checking is done!

    proc `[] =`*(sur: PSurface; x, y: int; col: TColor)

  set the pixel at position `(x, y)`. No range checking is done!

    proc blit*(destSurf: PSurface; destRect: TRect; srcSurf: PSurface;
               srcRect: TRect)

  Copies `srcSurf` into `destSurf`

    proc textBounds*(text: string; font = defaultFont): tuple[width, height: int]

    proc drawText*(sur: PSurface; p: TPoint; text: string; font = defaultFont)

  Draws text with a transparent background, at location `p` with the given font.

    proc drawText*(sur: PSurface; p: TPoint; text: string; bg: TColor;
                   font = defaultFont)

  Draws text, at location `p` with font `font`. `bg` is the background color.

    proc drawCircle*(sur: PSurface; p: TPoint; r: Natural; color: TColor)

  draws a circle with center p and radius r with the given color onto the surface sur.

    proc drawLine*(sur: PSurface; p1, p2: TPoint; color: TColor)

  draws a line between the two points p1 and p2 with the given color onto the surface sur.

    proc drawHorLine*(sur: PSurface; x, y, w: Natural; Color: TColor)

  draws a horizontal line from (x,y) to (x+w-1, y).

    proc drawVerLine*(sur: PSurface; x, y, h: Natural; Color: TColor)

  draws a vertical line from (x,y) to (x, y+h-1).

    proc fillCircle*(s: PSurface; p: TPoint; r: Natural; color: TColor)

  draws a circle with center p and radius r with the given color onto the surface sur and fills it.

    proc drawRect*(sur: PSurface; r: TRect; color: TColor)

  draws a rectangle.

    proc fillRect*(sur: PSurface; r: TRect; col: TColor)

  Fills a rectangle using sdl's `FillRect` function.

    proc drawEllipse*(sur: PSurface; CX, CY, XRadius, YRadius: Natural; col: TColor)

  Draws an ellipse, `CX` and `CY` specify the center X and Y of the ellipse, `XRadius` and `YRadius` specify half the width and height of the ellipse.

    proc drawLineAA*(sur: PSurface; p1, p2: TPoint; color: TColor)

  Draws a anti-aliased line from `p1` to `p2`, using Xiaolin Wu's line algorithm

    proc fillSurface*(sur: PSurface; color: TColor)

  Fills the entire surface with `color`.

# Templates

    template withEvents*(surf: PSurface; event: expr; actions: stmt): stmt

  Simple template which creates an event loop. `Event` is the name of the variable containing the TEvent object.

Generated: 2012-09-23 21:47:54 UTC