bugfix: macro evaluation; added colors.extractRGB

This commit is contained in:
Andreas Rumpf 2010-03-04 23:42:19 +01:00
commit f45a2f23b0
8 changed files with 190 additions and 154 deletions

View file

@ -6,8 +6,8 @@
# distribution, for details about the copyright.
#
## This module implements graphical output for Nimrod; the current
## implementation uses Cairo under the surface.
## This module implements color handling for Nimrod. It is used by
## the ``graphics`` module.
import strutils
@ -53,6 +53,12 @@ proc `-`*(a, b: TColor): TColor =
## component cannot overflow (255 is used as a maximum).
colorOp(satMinus)
proc extractRGB*(a: TColor): tuple[r, g, b: range[0..255]] =
## extracts the red/green/blue components of the color `a`.
result.r = a.int shr 16 and 0xff
result.g = a.int shr 8 and 0xff
result.b = a.int and 0xff
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