diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-08-10 22:17:05 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-08-10 22:17:05 -0700 |
commit | c407d842a4195a90e4e2bf5cbe14a6104a21142f (patch) | |
tree | 8e48c867a5dc2629888a15ff7d3efd6687abb431 | |
parent | 0d905ca59e5e5237c95cda1b5b6868a1750e00e8 (diff) | |
download | mu-c407d842a4195a90e4e2bf5cbe14a6104a21142f.tar.gz |
slack: first rendering of test data
-rw-r--r-- | 511image.mu | 2 | ||||
-rw-r--r-- | browse-slack/environment.mu | 72 | ||||
-rw-r--r-- | browse-slack/main.mu | 2 |
3 files changed, 73 insertions, 3 deletions
diff --git a/511image.mu b/511image.mu index 7d4127f4..f2df9424 100644 --- a/511image.mu +++ b/511image.mu @@ -79,7 +79,7 @@ fn render-image screen: (addr screen), _img: (addr image), xmin: int, ymin: int, render-raw-image screen, img2, xmin, ymin, width, height return } - abort "render-image: unrecognized image type" +#? abort "render-image: unrecognized image type" } ## helpers diff --git a/browse-slack/environment.mu b/browse-slack/environment.mu index 8f68a3fa..123e3803 100644 --- a/browse-slack/environment.mu +++ b/browse-slack/environment.mu @@ -19,7 +19,77 @@ type tab { # the current page at } -fn render-environment env: (addr environment), users: (addr array user), channels: (addr array channel), items: (addr array item) { +# static buffer sizes in this file: +# item-padding-hor # in pixels +# item-padding-ver # in characters +# avatar-side # in pixels +# avatar-space-hor # in characters +# author-name-padding-ver # in characters +# post-right-coord # in characters + +fn render-environment screen: (addr screen), env: (addr environment), users: (addr array user), channels: (addr array channel), _items: (addr array item) { + clear-screen screen + var tmp-width/eax: int <- copy 0 + var tmp-height/ecx: int <- copy 0 + tmp-width, tmp-height <- screen-size screen + var screen-height: int + copy-to screen-height, tmp-height + # + var y/ecx: int <- copy 1/item-padding-ver + var items/esi: (addr array item) <- copy _items + var i/ebx: int <- copy 0 + var max/edx: int <- length items + { + compare i, max + break-if->= + compare y, screen-height + break-if->= + var offset/eax: (offset item) <- compute-offset items, i + var curr-item/eax: (addr item) <- index items, offset + y <- render-item screen, curr-item, users, y, screen-height + i <- increment + loop + } +} + +fn render-item screen: (addr screen), _item: (addr item), _users: (addr array user), y: int, screen-height: int -> _/ecx: int { + var item/esi: (addr item) <- copy _item + var users/edi: (addr array user) <- copy _users + var author-index-addr/ecx: (addr int) <- get item, by + var author-index/ecx: int <- copy *author-index-addr + var author-offset/ecx: (offset user) <- compute-offset users, author-index + var author/ecx: (addr user) <- index users, author-offset + # author avatar + var author-avatar/ebx: (addr image) <- get author, avatar + { + compare author-avatar, 0 + break-if-= + var y/edx: int <- copy y + y <- shift-left 4/log2font-height + render-image screen, author-avatar, 0x18/item-padding-hor, y, 0x50/avatar-side, 0x50/avatar-side + } + # author name + var author-real-name-ah/eax: (addr handle array byte) <- get author, real-name + var author-real-name/eax: (addr array byte) <- lookup *author-real-name-ah + set-cursor-position screen, 0x10/avatar-space-hor, y + draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, author-real-name, 0xf/white 0/black + increment y + # text + var text-ah/eax: (addr handle array byte) <- get item, text + var _text/eax: (addr array byte) <- lookup *text-ah + var text/edx: (addr array byte) <- copy _text + var x/eax: int <- copy 0x10/avatar-space-hor + var text-y/ecx: int <- copy y + text-y <- add 1/author-name-padding-ver + x, text-y <- draw-text-wrapping-right-then-down screen, text, x text-y, 0x50/xmax=post-right-coord screen-height, x text-y, 7/fg 0/bg + # flush + add-to y, 6 + compare y, text-y + { + break-if-< + return y + } + return text-y } fn update-environment env: (addr environment), key: byte { diff --git a/browse-slack/main.mu b/browse-slack/main.mu index 40ccbde4..153f3dfb 100644 --- a/browse-slack/main.mu +++ b/browse-slack/main.mu @@ -75,7 +75,7 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) var env-storage: environment var env/ebx: (addr environment) <- address env-storage { - render-environment env, users, channels, items + render-environment screen, env, users, channels, items { var key/eax: byte <- read-key keyboard compare key, 0 |