From 64da2f16813bbf03b8a2117d7c4abffd1adf525f Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 19 Feb 2010 08:34:07 +0100 Subject: development of graphics module --- lib/devel/graphics.nim | 412 ------------------------------------------------- 1 file changed, 412 deletions(-) delete mode 100644 lib/devel/graphics.nim (limited to 'lib/devel/graphics.nim') diff --git a/lib/devel/graphics.nim b/lib/devel/graphics.nim deleted file mode 100644 index 347d16a30..000000000 --- a/lib/devel/graphics.nim +++ /dev/null @@ -1,412 +0,0 @@ -# -# -# Nimrod's Runtime Library -# (c) Copyright 2010 Andreas Rumpf -# -# See the file "copying.txt", included in this -# distribution, for details about the copyright. -# - -## This module implements graphical output for Nimrod; the current -## implementation uses Cairo under the surface. - -import cairo - -type - PSurface* = ref TSurface - TSurface {.pure, final.} = object - c: cairo.PSurface - - ... # internal data - - - TRect* = tuple[x, y, width, height: int] - TPoint* = tuple[x, y: int] - - TColor* = distinct int ## a color stored as RGB - -proc `==` *(a, b: TColor): bool {.borrow.} - ## compares two colors. - -template extract(a: TColor, r, g, b: expr) = - var r = a shr 16 and 0xff - var g = a shr 8 and 0xff - var b = a and 0xff - -template rawRGB(r, g, b: expr): expr = - TColor(r shl 16 or g shl 8 or b) - -template colorOp(op: expr) = - extract(a, ar, ag, ab) - extract(b, br, bg, bb) - result = rawRGB(op(ar, br), op(ag, bg), op(ab, bb)) - -template satPlus(a, b: expr): expr = - # saturated plus: - block: - var result = a +% b - if result > 255: result = 255 - result - -template satMinus(a, b: expr): expr = - block: - var result = a -% b - if result < 0: result = 0 - result - -proc `+`*(a, b: TColor): TColor = - ## adds two colors: This uses saturated artithmetic, so that each color - ## component cannot overflow (255 is used as a maximum). - colorOp(satPlus) - -proc `-`*(a, b: TColor): TColor = - ## substracts two colors: This uses saturated artithmetic, so that each color - ## component cannot overflow (255 is used as a maximum). - colorOp(satMinus) - -template mix*(a, b: TColor, fn: expr): expr = - ## uses `fn` to mix the colors `a` and `b`. `fn` is invoked for each component - ## R, G, and B. This is a template because `fn` should be inlined and the - ## compiler cannot inline proc pointers yet. If `fn`'s result is not in the - ## range[0..255], it will be saturated to be so. - template `><` (x: expr): expr = - # keep it in the range 0..255 - block: - var xx = x # eval only once - if xx >% 255: - xx = if xx < 0: 0 else: 255 - xx - - extract(a, ar, ag, ab) - extract(b, br, bg, bb) - rawRGB(>