big rename
This commit is contained in:
parent
15a7bcc89f
commit
11b6958755
98 changed files with 2491 additions and 2341 deletions
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Nimrod's Runtime Library
|
||||
# Nim's Runtime Library
|
||||
# (c) Copyright 2010 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
|
|
@ -12,18 +12,20 @@
|
|||
import strutils
|
||||
|
||||
type
|
||||
TColor* = distinct int ## a color stored as RGB
|
||||
Color* = distinct int ## a color stored as RGB
|
||||
|
||||
proc `==` *(a, b: TColor): bool {.borrow.}
|
||||
{.deprecated: [TColor: Color].}
|
||||
|
||||
proc `==` *(a, b: Color): bool {.borrow.}
|
||||
## compares two colors.
|
||||
|
||||
template extract(a: TColor, r, g, b: expr) {.immediate.}=
|
||||
template extract(a: Color, r, g, b: expr) {.immediate.}=
|
||||
var r = a.int shr 16 and 0xff
|
||||
var g = a.int shr 8 and 0xff
|
||||
var b = a.int and 0xff
|
||||
|
||||
template rawRGB(r, g, b: int): expr =
|
||||
TColor(r shl 16 or g shl 8 or b)
|
||||
Color(r shl 16 or g shl 8 or b)
|
||||
|
||||
template colorOp(op: expr) {.immediate.} =
|
||||
extract(a, ar, ag, ab)
|
||||
|
|
@ -38,23 +40,23 @@ proc satMinus(a, b: int): int {.inline.} =
|
|||
result = a -% b
|
||||
if result < 0: result = 0
|
||||
|
||||
proc `+`*(a, b: TColor): TColor =
|
||||
proc `+`*(a, b: Color): Color =
|
||||
## 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 =
|
||||
proc `-`*(a, b: Color): Color =
|
||||
## substracts two colors: This uses saturated artithmetic, so that each color
|
||||
## component cannot overflow (255 is used as a maximum).
|
||||
colorOp(satMinus)
|
||||
|
||||
proc extractRGB*(a: TColor): tuple[r, g, b: range[0..255]] =
|
||||
proc extractRGB*(a: Color): 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
|
||||
|
||||
proc intensity*(a: TColor, f: float): TColor =
|
||||
proc intensity*(a: Color, f: float): Color =
|
||||
## returns `a` with intensity `f`. `f` should be a float from 0.0 (completely
|
||||
## dark) to 1.0 (full color intensity).
|
||||
var r = toInt(toFloat(a.int shr 16 and 0xff) * f)
|
||||
|
|
@ -65,7 +67,7 @@ proc intensity*(a: TColor, f: float): TColor =
|
|||
if b >% 255: b = 255
|
||||
result = rawRGB(r, g, b)
|
||||
|
||||
template mix*(a, b: TColor, fn: expr): expr =
|
||||
template mix*(a, b: Color, 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
|
||||
|
|
@ -84,146 +86,146 @@ template mix*(a, b: TColor, fn: expr): expr =
|
|||
|
||||
|
||||
const
|
||||
colAliceBlue* = TColor(0xF0F8FF)
|
||||
colAntiqueWhite* = TColor(0xFAEBD7)
|
||||
colAqua* = TColor(0x00FFFF)
|
||||
colAquamarine* = TColor(0x7FFFD4)
|
||||
colAzure* = TColor(0xF0FFFF)
|
||||
colBeige* = TColor(0xF5F5DC)
|
||||
colBisque* = TColor(0xFFE4C4)
|
||||
colBlack* = TColor(0x000000)
|
||||
colBlanchedAlmond* = TColor(0xFFEBCD)
|
||||
colBlue* = TColor(0x0000FF)
|
||||
colBlueViolet* = TColor(0x8A2BE2)
|
||||
colBrown* = TColor(0xA52A2A)
|
||||
colBurlyWood* = TColor(0xDEB887)
|
||||
colCadetBlue* = TColor(0x5F9EA0)
|
||||
colChartreuse* = TColor(0x7FFF00)
|
||||
colChocolate* = TColor(0xD2691E)
|
||||
colCoral* = TColor(0xFF7F50)
|
||||
colCornflowerBlue* = TColor(0x6495ED)
|
||||
colCornsilk* = TColor(0xFFF8DC)
|
||||
colCrimson* = TColor(0xDC143C)
|
||||
colCyan* = TColor(0x00FFFF)
|
||||
colDarkBlue* = TColor(0x00008B)
|
||||
colDarkCyan* = TColor(0x008B8B)
|
||||
colDarkGoldenRod* = TColor(0xB8860B)
|
||||
colDarkGray* = TColor(0xA9A9A9)
|
||||
colDarkGreen* = TColor(0x006400)
|
||||
colDarkKhaki* = TColor(0xBDB76B)
|
||||
colDarkMagenta* = TColor(0x8B008B)
|
||||
colDarkOliveGreen* = TColor(0x556B2F)
|
||||
colDarkorange* = TColor(0xFF8C00)
|
||||
colDarkOrchid* = TColor(0x9932CC)
|
||||
colDarkRed* = TColor(0x8B0000)
|
||||
colDarkSalmon* = TColor(0xE9967A)
|
||||
colDarkSeaGreen* = TColor(0x8FBC8F)
|
||||
colDarkSlateBlue* = TColor(0x483D8B)
|
||||
colDarkSlateGray* = TColor(0x2F4F4F)
|
||||
colDarkTurquoise* = TColor(0x00CED1)
|
||||
colDarkViolet* = TColor(0x9400D3)
|
||||
colDeepPink* = TColor(0xFF1493)
|
||||
colDeepSkyBlue* = TColor(0x00BFFF)
|
||||
colDimGray* = TColor(0x696969)
|
||||
colDodgerBlue* = TColor(0x1E90FF)
|
||||
colFireBrick* = TColor(0xB22222)
|
||||
colFloralWhite* = TColor(0xFFFAF0)
|
||||
colForestGreen* = TColor(0x228B22)
|
||||
colFuchsia* = TColor(0xFF00FF)
|
||||
colGainsboro* = TColor(0xDCDCDC)
|
||||
colGhostWhite* = TColor(0xF8F8FF)
|
||||
colGold* = TColor(0xFFD700)
|
||||
colGoldenRod* = TColor(0xDAA520)
|
||||
colGray* = TColor(0x808080)
|
||||
colGreen* = TColor(0x008000)
|
||||
colGreenYellow* = TColor(0xADFF2F)
|
||||
colHoneyDew* = TColor(0xF0FFF0)
|
||||
colHotPink* = TColor(0xFF69B4)
|
||||
colIndianRed* = TColor(0xCD5C5C)
|
||||
colIndigo* = TColor(0x4B0082)
|
||||
colIvory* = TColor(0xFFFFF0)
|
||||
colKhaki* = TColor(0xF0E68C)
|
||||
colLavender* = TColor(0xE6E6FA)
|
||||
colLavenderBlush* = TColor(0xFFF0F5)
|
||||
colLawnGreen* = TColor(0x7CFC00)
|
||||
colLemonChiffon* = TColor(0xFFFACD)
|
||||
colLightBlue* = TColor(0xADD8E6)
|
||||
colLightCoral* = TColor(0xF08080)
|
||||
colLightCyan* = TColor(0xE0FFFF)
|
||||
colLightGoldenRodYellow* = TColor(0xFAFAD2)
|
||||
colLightGrey* = TColor(0xD3D3D3)
|
||||
colLightGreen* = TColor(0x90EE90)
|
||||
colLightPink* = TColor(0xFFB6C1)
|
||||
colLightSalmon* = TColor(0xFFA07A)
|
||||
colLightSeaGreen* = TColor(0x20B2AA)
|
||||
colLightSkyBlue* = TColor(0x87CEFA)
|
||||
colLightSlateGray* = TColor(0x778899)
|
||||
colLightSteelBlue* = TColor(0xB0C4DE)
|
||||
colLightYellow* = TColor(0xFFFFE0)
|
||||
colLime* = TColor(0x00FF00)
|
||||
colLimeGreen* = TColor(0x32CD32)
|
||||
colLinen* = TColor(0xFAF0E6)
|
||||
colMagenta* = TColor(0xFF00FF)
|
||||
colMaroon* = TColor(0x800000)
|
||||
colMediumAquaMarine* = TColor(0x66CDAA)
|
||||
colMediumBlue* = TColor(0x0000CD)
|
||||
colMediumOrchid* = TColor(0xBA55D3)
|
||||
colMediumPurple* = TColor(0x9370D8)
|
||||
colMediumSeaGreen* = TColor(0x3CB371)
|
||||
colMediumSlateBlue* = TColor(0x7B68EE)
|
||||
colMediumSpringGreen* = TColor(0x00FA9A)
|
||||
colMediumTurquoise* = TColor(0x48D1CC)
|
||||
colMediumVioletRed* = TColor(0xC71585)
|
||||
colMidnightBlue* = TColor(0x191970)
|
||||
colMintCream* = TColor(0xF5FFFA)
|
||||
colMistyRose* = TColor(0xFFE4E1)
|
||||
colMoccasin* = TColor(0xFFE4B5)
|
||||
colNavajoWhite* = TColor(0xFFDEAD)
|
||||
colNavy* = TColor(0x000080)
|
||||
colOldLace* = TColor(0xFDF5E6)
|
||||
colOlive* = TColor(0x808000)
|
||||
colOliveDrab* = TColor(0x6B8E23)
|
||||
colOrange* = TColor(0xFFA500)
|
||||
colOrangeRed* = TColor(0xFF4500)
|
||||
colOrchid* = TColor(0xDA70D6)
|
||||
colPaleGoldenRod* = TColor(0xEEE8AA)
|
||||
colPaleGreen* = TColor(0x98FB98)
|
||||
colPaleTurquoise* = TColor(0xAFEEEE)
|
||||
colPaleVioletRed* = TColor(0xD87093)
|
||||
colPapayaWhip* = TColor(0xFFEFD5)
|
||||
colPeachPuff* = TColor(0xFFDAB9)
|
||||
colPeru* = TColor(0xCD853F)
|
||||
colPink* = TColor(0xFFC0CB)
|
||||
colPlum* = TColor(0xDDA0DD)
|
||||
colPowderBlue* = TColor(0xB0E0E6)
|
||||
colPurple* = TColor(0x800080)
|
||||
colRed* = TColor(0xFF0000)
|
||||
colRosyBrown* = TColor(0xBC8F8F)
|
||||
colRoyalBlue* = TColor(0x4169E1)
|
||||
colSaddleBrown* = TColor(0x8B4513)
|
||||
colSalmon* = TColor(0xFA8072)
|
||||
colSandyBrown* = TColor(0xF4A460)
|
||||
colSeaGreen* = TColor(0x2E8B57)
|
||||
colSeaShell* = TColor(0xFFF5EE)
|
||||
colSienna* = TColor(0xA0522D)
|
||||
colSilver* = TColor(0xC0C0C0)
|
||||
colSkyBlue* = TColor(0x87CEEB)
|
||||
colSlateBlue* = TColor(0x6A5ACD)
|
||||
colSlateGray* = TColor(0x708090)
|
||||
colSnow* = TColor(0xFFFAFA)
|
||||
colSpringGreen* = TColor(0x00FF7F)
|
||||
colSteelBlue* = TColor(0x4682B4)
|
||||
colTan* = TColor(0xD2B48C)
|
||||
colTeal* = TColor(0x008080)
|
||||
colThistle* = TColor(0xD8BFD8)
|
||||
colTomato* = TColor(0xFF6347)
|
||||
colTurquoise* = TColor(0x40E0D0)
|
||||
colViolet* = TColor(0xEE82EE)
|
||||
colWheat* = TColor(0xF5DEB3)
|
||||
colWhite* = TColor(0xFFFFFF)
|
||||
colWhiteSmoke* = TColor(0xF5F5F5)
|
||||
colYellow* = TColor(0xFFFF00)
|
||||
colYellowGreen* = TColor(0x9ACD32)
|
||||
colAliceBlue* = Color(0xF0F8FF)
|
||||
colAntiqueWhite* = Color(0xFAEBD7)
|
||||
colAqua* = Color(0x00FFFF)
|
||||
colAquamarine* = Color(0x7FFFD4)
|
||||
colAzure* = Color(0xF0FFFF)
|
||||
colBeige* = Color(0xF5F5DC)
|
||||
colBisque* = Color(0xFFE4C4)
|
||||
colBlack* = Color(0x000000)
|
||||
colBlanchedAlmond* = Color(0xFFEBCD)
|
||||
colBlue* = Color(0x0000FF)
|
||||
colBlueViolet* = Color(0x8A2BE2)
|
||||
colBrown* = Color(0xA52A2A)
|
||||
colBurlyWood* = Color(0xDEB887)
|
||||
colCadetBlue* = Color(0x5F9EA0)
|
||||
colChartreuse* = Color(0x7FFF00)
|
||||
colChocolate* = Color(0xD2691E)
|
||||
colCoral* = Color(0xFF7F50)
|
||||
colCornflowerBlue* = Color(0x6495ED)
|
||||
colCornsilk* = Color(0xFFF8DC)
|
||||
colCrimson* = Color(0xDC143C)
|
||||
colCyan* = Color(0x00FFFF)
|
||||
colDarkBlue* = Color(0x00008B)
|
||||
colDarkCyan* = Color(0x008B8B)
|
||||
colDarkGoldenRod* = Color(0xB8860B)
|
||||
colDarkGray* = Color(0xA9A9A9)
|
||||
colDarkGreen* = Color(0x006400)
|
||||
colDarkKhaki* = Color(0xBDB76B)
|
||||
colDarkMagenta* = Color(0x8B008B)
|
||||
colDarkOliveGreen* = Color(0x556B2F)
|
||||
colDarkorange* = Color(0xFF8C00)
|
||||
colDarkOrchid* = Color(0x9932CC)
|
||||
colDarkRed* = Color(0x8B0000)
|
||||
colDarkSalmon* = Color(0xE9967A)
|
||||
colDarkSeaGreen* = Color(0x8FBC8F)
|
||||
colDarkSlateBlue* = Color(0x483D8B)
|
||||
colDarkSlateGray* = Color(0x2F4F4F)
|
||||
colDarkTurquoise* = Color(0x00CED1)
|
||||
colDarkViolet* = Color(0x9400D3)
|
||||
colDeepPink* = Color(0xFF1493)
|
||||
colDeepSkyBlue* = Color(0x00BFFF)
|
||||
colDimGray* = Color(0x696969)
|
||||
colDodgerBlue* = Color(0x1E90FF)
|
||||
colFireBrick* = Color(0xB22222)
|
||||
colFloralWhite* = Color(0xFFFAF0)
|
||||
colForestGreen* = Color(0x228B22)
|
||||
colFuchsia* = Color(0xFF00FF)
|
||||
colGainsboro* = Color(0xDCDCDC)
|
||||
colGhostWhite* = Color(0xF8F8FF)
|
||||
colGold* = Color(0xFFD700)
|
||||
colGoldenRod* = Color(0xDAA520)
|
||||
colGray* = Color(0x808080)
|
||||
colGreen* = Color(0x008000)
|
||||
colGreenYellow* = Color(0xADFF2F)
|
||||
colHoneyDew* = Color(0xF0FFF0)
|
||||
colHotPink* = Color(0xFF69B4)
|
||||
colIndianRed* = Color(0xCD5C5C)
|
||||
colIndigo* = Color(0x4B0082)
|
||||
colIvory* = Color(0xFFFFF0)
|
||||
colKhaki* = Color(0xF0E68C)
|
||||
colLavender* = Color(0xE6E6FA)
|
||||
colLavenderBlush* = Color(0xFFF0F5)
|
||||
colLawnGreen* = Color(0x7CFC00)
|
||||
colLemonChiffon* = Color(0xFFFACD)
|
||||
colLightBlue* = Color(0xADD8E6)
|
||||
colLightCoral* = Color(0xF08080)
|
||||
colLightCyan* = Color(0xE0FFFF)
|
||||
colLightGoldenRodYellow* = Color(0xFAFAD2)
|
||||
colLightGrey* = Color(0xD3D3D3)
|
||||
colLightGreen* = Color(0x90EE90)
|
||||
colLightPink* = Color(0xFFB6C1)
|
||||
colLightSalmon* = Color(0xFFA07A)
|
||||
colLightSeaGreen* = Color(0x20B2AA)
|
||||
colLightSkyBlue* = Color(0x87CEFA)
|
||||
colLightSlateGray* = Color(0x778899)
|
||||
colLightSteelBlue* = Color(0xB0C4DE)
|
||||
colLightYellow* = Color(0xFFFFE0)
|
||||
colLime* = Color(0x00FF00)
|
||||
colLimeGreen* = Color(0x32CD32)
|
||||
colLinen* = Color(0xFAF0E6)
|
||||
colMagenta* = Color(0xFF00FF)
|
||||
colMaroon* = Color(0x800000)
|
||||
colMediumAquaMarine* = Color(0x66CDAA)
|
||||
colMediumBlue* = Color(0x0000CD)
|
||||
colMediumOrchid* = Color(0xBA55D3)
|
||||
colMediumPurple* = Color(0x9370D8)
|
||||
colMediumSeaGreen* = Color(0x3CB371)
|
||||
colMediumSlateBlue* = Color(0x7B68EE)
|
||||
colMediumSpringGreen* = Color(0x00FA9A)
|
||||
colMediumTurquoise* = Color(0x48D1CC)
|
||||
colMediumVioletRed* = Color(0xC71585)
|
||||
colMidnightBlue* = Color(0x191970)
|
||||
colMintCream* = Color(0xF5FFFA)
|
||||
colMistyRose* = Color(0xFFE4E1)
|
||||
colMoccasin* = Color(0xFFE4B5)
|
||||
colNavajoWhite* = Color(0xFFDEAD)
|
||||
colNavy* = Color(0x000080)
|
||||
colOldLace* = Color(0xFDF5E6)
|
||||
colOlive* = Color(0x808000)
|
||||
colOliveDrab* = Color(0x6B8E23)
|
||||
colOrange* = Color(0xFFA500)
|
||||
colOrangeRed* = Color(0xFF4500)
|
||||
colOrchid* = Color(0xDA70D6)
|
||||
colPaleGoldenRod* = Color(0xEEE8AA)
|
||||
colPaleGreen* = Color(0x98FB98)
|
||||
colPaleTurquoise* = Color(0xAFEEEE)
|
||||
colPaleVioletRed* = Color(0xD87093)
|
||||
colPapayaWhip* = Color(0xFFEFD5)
|
||||
colPeachPuff* = Color(0xFFDAB9)
|
||||
colPeru* = Color(0xCD853F)
|
||||
colPink* = Color(0xFFC0CB)
|
||||
colPlum* = Color(0xDDA0DD)
|
||||
colPowderBlue* = Color(0xB0E0E6)
|
||||
colPurple* = Color(0x800080)
|
||||
colRed* = Color(0xFF0000)
|
||||
colRosyBrown* = Color(0xBC8F8F)
|
||||
colRoyalBlue* = Color(0x4169E1)
|
||||
colSaddleBrown* = Color(0x8B4513)
|
||||
colSalmon* = Color(0xFA8072)
|
||||
colSandyBrown* = Color(0xF4A460)
|
||||
colSeaGreen* = Color(0x2E8B57)
|
||||
colSeaShell* = Color(0xFFF5EE)
|
||||
colSienna* = Color(0xA0522D)
|
||||
colSilver* = Color(0xC0C0C0)
|
||||
colSkyBlue* = Color(0x87CEEB)
|
||||
colSlateBlue* = Color(0x6A5ACD)
|
||||
colSlateGray* = Color(0x708090)
|
||||
colSnow* = Color(0xFFFAFA)
|
||||
colSpringGreen* = Color(0x00FF7F)
|
||||
colSteelBlue* = Color(0x4682B4)
|
||||
colTan* = Color(0xD2B48C)
|
||||
colTeal* = Color(0x008080)
|
||||
colThistle* = Color(0xD8BFD8)
|
||||
colTomato* = Color(0xFF6347)
|
||||
colTurquoise* = Color(0x40E0D0)
|
||||
colViolet* = Color(0xEE82EE)
|
||||
colWheat* = Color(0xF5DEB3)
|
||||
colWhite* = Color(0xFFFFFF)
|
||||
colWhiteSmoke* = Color(0xF5F5F5)
|
||||
colYellow* = Color(0xFFFF00)
|
||||
colYellowGreen* = Color(0x9ACD32)
|
||||
|
||||
colorNames = [
|
||||
("aliceblue", colAliceBlue),
|
||||
|
|
@ -367,11 +369,11 @@ const
|
|||
("yellow", colYellow),
|
||||
("yellowgreen", colYellowGreen)]
|
||||
|
||||
proc `$`*(c: TColor): string =
|
||||
proc `$`*(c: Color): string =
|
||||
## converts a color into its textual representation. Example: ``#00FF00``.
|
||||
result = '#' & toHex(int(c), 6)
|
||||
|
||||
proc binaryStrSearch(x: openarray[tuple[name: string, col: TColor]],
|
||||
proc binaryStrSearch(x: openArray[tuple[name: string, col: Color]],
|
||||
y: string): int =
|
||||
var a = 0
|
||||
var b = len(x) - 1
|
||||
|
|
@ -383,14 +385,14 @@ proc binaryStrSearch(x: openarray[tuple[name: string, col: TColor]],
|
|||
else: return mid
|
||||
result = - 1
|
||||
|
||||
proc parseColor*(name: string): TColor =
|
||||
proc parseColor*(name: string): Color =
|
||||
## parses `name` to a color value. If no valid color could be
|
||||
## parsed ``EInvalidValue`` is raised.
|
||||
if name[0] == '#':
|
||||
result = TColor(parseHexInt(name))
|
||||
result = Color(parseHexInt(name))
|
||||
else:
|
||||
var idx = binaryStrSearch(colorNames, name)
|
||||
if idx < 0: raise newException(EInvalidValue, "unkown color: " & name)
|
||||
if idx < 0: raise newException(ValueError, "unkown color: " & name)
|
||||
result = colorNames[idx][1]
|
||||
|
||||
proc isColor*(name: string): bool =
|
||||
|
|
@ -403,7 +405,7 @@ proc isColor*(name: string): bool =
|
|||
else:
|
||||
result = binaryStrSearch(colorNames, name) >= 0
|
||||
|
||||
proc rgb*(r, g, b: range[0..255]): TColor =
|
||||
proc rgb*(r, g, b: range[0..255]): Color =
|
||||
## constructs a color from RGB values.
|
||||
result = rawRGB(r, g, b)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue