about summary refs log tree commit diff stats
path: root/src/img
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-29 21:31:19 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-29 23:24:34 +0200
commit90fa62f49f7f3b80bb89033a740be7a7e9e5cbb3 (patch)
tree3066458b5de642193a4c836f613695f5fb24c864 /src/img
parente01fa3b643966bd64d0f244f1e604f81107604fe (diff)
downloadchawan-90fa62f49f7f3b80bb89033a740be7a7e9e5cbb3.tar.gz
Fixes for Nim 2.2
* xmlhttprequest: fix missing import
* painter: generic tuple workaround
* dynstream: merge module with implementations (so it will work with
  vtables)

Not enabling vtables yet since it doesn't work with refc.
Diffstat (limited to 'src/img')
-rw-r--r--src/img/painter.nim16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/img/painter.nim b/src/img/painter.nim
index 4e8d1f72..7b844447 100644
--- a/src/img/painter.nim
+++ b/src/img/painter.nim
@@ -138,15 +138,19 @@ proc clearRect*(bmp: Bitmap; x0, x1, y0, y1: uint64) =
 proc clear*(bmp: Bitmap) =
   bmp.clearRect(0, bmp.width, 0, bmp.height)
 
+type GlyphCacheItem = object
+  u: uint32
+  bmp: Bitmap
+
 var unifontBitmap*: Bitmap = nil
-var glyphCache: seq[tuple[u: uint32, bmp: Bitmap]]
+var glyphCache: seq[GlyphCacheItem] = @[]
 var glyphCacheI = 0
 proc getCharBmp(u: uint32): Bitmap =
   # We only have the BMP.
   let u = if u <= 0xFFFF: u else: 0xFFFD
-  for (cu, bmp) in glyphCache:
-    if cu == u:
-      return bmp
+  for it in glyphCache:
+    if it.u == u:
+      return it.bmp
   # Unifont glyphs start at x: 32, y: 64, and are of 8x16/16x16 size
   let gx = uint64(32 + 16 * (u mod 0x100))
   let gy = uint64(64 + 16 * (u div 0x100))
@@ -166,9 +170,9 @@ proc getCharBmp(u: uint32): Bitmap =
       if c != white:
         bmp.setpx(x, y, c)
   if glyphCache.len < 256:
-    glyphCache.add((u, bmp))
+    glyphCache.add(GlyphCacheItem(u: u, bmp: bmp))
   else:
-    glyphCache[glyphCacheI] = (u, bmp)
+    glyphCache[glyphCacheI] = GlyphCacheItem(u: u, bmp: bmp)
     inc glyphCacheI
     if glyphCacheI >= glyphCache.len:
       glyphCacheI = 0