Add bitmap font, UI primitives and a HUD with message log
Ports the CP437 font renderer from wds to the framebuffer: proportional advance from measured ink bounds, luminance-keyed mask, word wrap. The right 80 px strip becomes a HUD with name, HP bar, population and a log fed from sim events; Attacked/Died now carry the type ids the log needs, since the victim is gone from the world by the time events are read. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+13
-22
@@ -2,29 +2,20 @@
|
||||
|
||||
## Current state
|
||||
|
||||
No text rendering exists yet. No font loading or glyph blitting code exists.
|
||||
`game/src/font.rs` — a CP437 bitmap font ported from the `wds` project.
|
||||
|
||||
## Goal
|
||||
|
||||
Draw ASCII text into the RGB565 framebuffer using a bitmap font.
|
||||
|
||||
## Design notes
|
||||
|
||||
- A bitmap font is the right fit: each glyph is a small masked tile, blitted
|
||||
directly into the framebuffer using the existing blit primitive in `pixelhelper.rs`.
|
||||
- Likely approach: a fixed 8×8 or similar glyph grid packed into a PNG,
|
||||
one glyph per ASCII codepoint starting at 0x20 (space).
|
||||
- The font image only needs its alpha mask: glyph pixels are opaque, background transparent;
|
||||
the caller supplies the color and `draw_text` paints the mask with it.
|
||||
- API sketch:
|
||||
```rust
|
||||
fn draw_text(frame: &mut [u16], font: &Font, x: i32, y: i32, color: u16, text: &str);
|
||||
```
|
||||
- `Font` holds the glyph sheet as an `Image` plus glyph width/height.
|
||||
- Atlas: 32 columns × 8 rows of fixed cells, codepoint = index (`A` at 65 → column 1,
|
||||
row 2). Loaded with `Image::from_png`; the mask is derived from luminance (white on
|
||||
black), so the caller paints glyphs in any RGB565 color.
|
||||
- Proportional advance: on load the ink span of every glyph (leftmost/rightmost lit
|
||||
column) is measured. `draw` crops to that span and advances by ink width + 1 px
|
||||
tracking; blank glyphs (space) advance half a cell.
|
||||
- `cp437(char)` maps ASCII 1:1 and the accented letters the atlas has (ä ö ü ß …);
|
||||
everything else becomes `?`.
|
||||
- `text_width` and `wrap` (word wrap with hard `\n`) for layout.
|
||||
- Font in use: `assets/fonts/cga-8x8.png` (Oldschool PC Font Pack, CGA 8×8).
|
||||
|
||||
## Open questions
|
||||
|
||||
- How do we handle proportional spacing of different characters?
|
||||
- How do we store font data in memory?
|
||||
- How do we handle font color rendering?
|
||||
- How do we handle special characters like Ä, Ö, Ü, ß, etc.?
|
||||
- A second, smaller or larger font (the EGA 8×14 from `wds`) once the UI needs hierarchy.
|
||||
- Text color per span / inline markup for the log — not before it is needed.
|
||||
|
||||
Reference in New Issue
Block a user