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.
TRect = tuple[x, y, width, height: int]
-
TPoint = tuple[x, y: int]
-
PSurface = ref TSurface
-
a surface to draw onto
TSurface = object
w*, h*: Natural
s*: PSurface
-
EGraphics = object of EIO
-
PFont = ref TFont
-
represents a font
defaultFont: PFont
-
default font that is used; this needs to initialized by the client!
proc toSdlColor(c: TColor): TColor {.raises: [], tags: [].}
-
Convert colors.TColor to SDL.TColor
proc createSdlColor(sur: PSurface; c: TColor; alpha: int = 0): int32 {.
raises: [], tags: [].}
-
Creates a color using sdl.MapRGBA.
proc toSdlRect(r: TRect): TRect {.raises: [], tags: [].}
-
Convert graphics.TRect to sdl.TRect.
proc newSurface(width, height: int): PSurface {.raises: [EGraphics], tags: [].}
-
creates a new surface.
proc newFont(name = "VeraMono.ttf"; size = 9; color = colBlack): PFont {.
raises: [EIO], tags: [].}
-
Creates a new font object. Raises EIO if the font cannot be loaded.
proc initDefaultFont(name = "VeraMono.ttf"; size = 9; color = colBlack) {.
raises: [EIO], tags: [].}
-
initializes the defaultFont var.
proc newScreenSurface(width, height: int): PSurface {.raises: [EGraphics],
tags: [].}
-
Creates a new screen surface
proc writeToBMP(sur: PSurface; filename: string) {.raises: [EIO], tags: [].}
-
Saves the contents of the surface sur to the file filename as a BMP file.
proc `[]`(sur: PSurface; p: TPoint): TColor {.raises: [], tags: [].}
-
get pixel at position p. No range checking is done!
proc `[]`(sur: PSurface; x, y: int): TColor {.raises: [], tags: [].}
-
get pixel at position (x, y). No range checking is done!
proc `[]=`(sur: PSurface; p: TPoint; col: TColor) {.raises: [], tags: [].}
-
set the pixel at position p. No range checking is done!
proc `[]=`(sur: PSurface; x, y: int; col: TColor) {.raises: [], tags: [].}
-
set the pixel at position (x, y). No range checking is done!
proc blit(destSurf: PSurface; destRect: TRect; srcSurf: PSurface; srcRect: TRect) {.
raises: [EGraphics], tags: [].}
-
Copies srcSurf into destSurf
proc textBounds(text: string; font = defaultFont): tuple[width, height: int] {.
raises: [EGraphics], tags: [].}
-
proc drawText(sur: PSurface; p: TPoint; text: string; font = defaultFont) {.
raises: [EGraphics], tags: [].}
-
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) {.raises: [EGraphics], tags: [].}
-
Draws text, at location p with font font. bg is the background color.
proc drawCircle(sur: PSurface; p: TPoint; r: Natural; color: TColor) {.
raises: [], tags: [].}
-
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) {.raises: [],
tags: [].}
-
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) {.raises: [],
tags: [].}
-
draws a horizontal line from (x,y) to (x+w-1, y).
proc drawVerLine(sur: PSurface; x, y, h: Natural; Color: TColor) {.raises: [],
tags: [].}
-
draws a vertical line from (x,y) to (x, y+h-1).
proc fillCircle(s: PSurface; p: TPoint; r: Natural; color: TColor) {.raises: [],
tags: [].}
-
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) {.raises: [], tags: [].}
-
draws a rectangle.
proc fillRect(sur: PSurface; r: TRect; col: TColor) {.raises: [EGraphics],
tags: [].}
-
Fills a rectangle using sdl's FillRect function.
proc drawEllipse(sur: PSurface; CX, CY, XRadius, YRadius: Natural; col: TColor) {.
raises: [], tags: [].}
-
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) {.raises: [],
tags: [].}
-
Draws a anti-aliased line from p1 to p2, using Xiaolin Wu's line algorithm
proc fillSurface(sur: PSurface; color: TColor) {.raises: [EGraphics], tags: [].}
-
Fills the entire surface with color.
template withEvents(surf: PSurface; event: expr; actions: stmt): stmt {.
immediate.}
-
Simple template which creates an event loop. Event is the name of the variable containing the TEvent object.