about summary refs log tree commit diff stats
path: root/src/types
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-12-10 17:39:21 +0100
committerbptato <nincsnevem662@gmail.com>2021-12-10 17:39:21 +0100
commite46f0a4cb9b6a843e900dbb3abd5ce9684f47016 (patch)
tree7d4c893343a1b26a9996ad999dbd89e091efa3a3 /src/types
parent91dee7d0d7cfe0f7faa2bf4b364e1db87ec6b70f (diff)
downloadchawan-e46f0a4cb9b6a843e900dbb3abd5ce9684f47016.tar.gz
Support more colors, config.nim refactoring
Diffstat (limited to 'src/types')
-rw-r--r--src/types/color.nim37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/types/color.nim b/src/types/color.nim
index 45a3f31d..ca04a0e7 100644
--- a/src/types/color.nim
+++ b/src/types/color.nim
@@ -1,5 +1,7 @@
 type
-  RGBColor* = tuple[r: uint8, g: uint8, b: uint8]
+  RGBColor* = distinct int
+
+  RGBAColor* = distinct int
 
   CellColor* = object
     case rgb*: bool
@@ -12,7 +14,38 @@ func `==`*(color1: CellColor, color2: CellColor): bool =
   if color1.rgb != color2.rgb:
     return false
   if color1.rgb:
-    return color1.rgbcolor == color2.rgbcolor
+    return int(color1.rgbcolor) == int(color2.rgbcolor)
   return color1.color == color2.color
 
 const defaultColor* = CellColor(rgb: false, color: 0)
+
+func r*(c: RGBAColor): int =
+  return int(c) shr 16 and 0xff
+
+func g*(c: RGBAColor): int =
+  return int(c) shr 8 and 0xff
+
+func b*(c: RGBAColor): int =
+  return int(c) and 0xff
+
+func a*(c: RGBAColor): int =
+  return int(c) shr 24 and 0xff
+
+func rgb*(r, g, b: int): RGBColor =
+  return RGBColor((r shl 16) or (g shl 8) or b)
+
+
+func r*(c: RGBColor): int =
+  return int(c) shr 16 and 0xff
+
+func g*(c: RGBColor): int =
+  return int(c) shr 8 and 0xff
+
+func b*(c: RGBColor): int =
+  return int(c) and 0xff
+
+func rgba*(r, g, b, a: int): RGBAColor =
+  return RGBAColor((a shl 24) or (r shl 16) or (g shl 8) or b)
+
+converter toRGBColor*(i: RGBAColor): RGBColor =
+  return RGBColor(int(i) and 0xFFFFFF)