# unight0/8-bit-font-designer architecture

> Architecture diagram of the GitHub repository unight0/8-bit-font-designer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/unight0/8-bit-font-designer
- Repository: https://github.com/unight0/8-bit-font-designer

## Overview

#### Purpose and Entry Point
This is a native SDL2-based 8×8 bitmap font editor. It lets a user select one of up to 256 glyphs, toggle pixels, resize the active font range, and save/open font files compatible with the bundled C header format.

Application startup and main event loop are in:
- `src/main.cpp`
- `src/config.h`

#### Application Orchestration
`main.cpp` initializes the editor runtime, SDL window/rendering context, font state, and command handling. It owns the top-level control flow: process keyboard input, route command characters versus editor navigation, update state, and redraw.

Key integration boundaries:
- SDL2 input/window APIs enter through `src/main.cpp`.
- Editing commands are delegated to command handling.
- Screen rendering is delegated to the renderer.
- Glyph state is held by the font editor model.

#### Font Editor State Model
The editable domain is an 8×8 pixel glyph set with a configurable usable symbol count (maximum 256). The model tracks the current glyph index, cursor position within that glyph, and per-pixel on/off values.

Primary model component:
- `src/fontedit.h`
- `src/fontedit.cpp`

This is the boundary between interactive controls and persistent font data: keyboard actions mutate the in-memory font model, while load/save operations serialize or replace it.

#### Command Parsing and File Operations
Commands are typed directly into the application as a command letter followed immediately by an argument. Command handling interprets edit-symbol, save, open, resize, and quit operations.

Command subsystem:
- `src/cmdhandl.h`
- `src/cmdhandl.cpp`

Important flow:
1. Raw typed command text is collected by the application.
2. `cmdhandl` parses command symbol and argument.
3. It changes selected glyph/font size, requests shutdown, or invokes font persistence.
4. Model and renderer reflect the resulting state.

File paths supplied by `s<file>` and `o<file>` form the external filesystem boundary.

#### Rendering and Interactive Input
The renderer projects font-editor state into SDL drawing operations: the 8×8 glyph grid, enabled pixels, and cursor/selection feedback. Keyboard arrows move the grid cursor; space toggles the addressed pixel.

Rendering component:
- `src/renderer.h`
- `src/renderer.cpp`

The renderer should consume editor state rather than own it; this keeps visual display separate from glyph mutation and persistence.

#### Font Format and Export Contract
The repository includes a C header representation intended for importing saved fonts into other code. The editor’s serialization must remain compatible with that format, making `font8.h` the key output/data contract rather than merely a UI artifact.

Format-related paths:
- `src/font8.h`
- `sample/font0`

#### Runtime and Infrastructure
The project is a compiled C++ desktop program using SDL2 for graphics and keyboard events. Build orchestration is Make-based, with SDL2 and a C++ toolchain as material dependencies.

Build/runtime artifacts:
- `Makefile`
- `src/main.cpp`
- `src/renderer.cpp`

Main entry points: [`src/main.cpp`](https://github.com/unight0/8-bit-font-designer/blob/main/src/main.cpp) (Application loop), [`src/renderer.cpp`](https://github.com/unight0/8-bit-font-designer/blob/main/src/renderer.cpp) (Renderer), [`src/fontedit.cpp`](https://github.com/unight0/8-bit-font-designer/blob/main/src/fontedit.cpp) (Font editor model), [`src/cmdhandl.cpp`](https://github.com/unight0/8-bit-font-designer/blob/main/src/cmdhandl.cpp) (Command handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Editor application"]
  node_main["Application loop<br/>C++ entry point<br/>[main.cpp]"]
  node_config["Runtime config<br/>C++ header<br/>[config.h]"]
  node_command_input["Typed commands<br/>input buffer<br/>[main.cpp]"]
  node_commands["Command handler<br/>C++ subsystem<br/>[cmdhandl.cpp]"]
  node_command_api["Command API<br/>C++ header<br/>[cmdhandl.h]"]
  node_renderer["Renderer<br/>C++ subsystem<br/>[renderer.cpp]"]
  node_renderer_api["Renderer API<br/>C++ header<br/>[renderer.h]"]
end

subgraph group_domain["Font domain"]
  node_font_model["Font editor model<br/>C++ domain model<br/>[fontedit.cpp]"]
  node_font_model_api["Font model API<br/>C++ header<br/>[fontedit.h]"]
end

subgraph group_external["Runtime and data contract"]
  node_build{{"Make build"}}
  node_sdl{{"SDL2<br/>native runtime"}}
  node_font_contract["C font header format<br/>serialization contract<br/>[font8.h]"]
  node_font_files[("Font files<br/>filesystem data")]
end

node_build -->|"builds"| node_main
node_build -->|"builds"| node_renderer
node_build -->|"links"| node_sdl
node_config -->|"configures"| node_main
node_sdl -->|"keyboard and window events"| node_main
node_main -->|"collects"| node_command_input
node_command_input -->|"dispatches"| node_commands
node_command_api -.->|"declares"| node_commands
node_commands -->|"edits, resizes, loads, saves"| node_font_model
node_font_model_api -.->|"declares"| node_font_model
node_main -->|"navigation and pixel toggles"| node_font_model
node_main -->|"requests redraw"| node_renderer
node_renderer_api -.->|"declares"| node_renderer
node_font_model -->|"glyph and cursor state"| node_renderer
node_renderer -->|"drawing operations"| node_sdl
node_commands -->|"opens and saves"| node_font_files
node_font_files -->|"serialized as"| node_font_contract
node_font_contract -.->|"import/export format"| node_font_model

click node_build "https://github.com/unight0/8-bit-font-designer/blob/main/Makefile"
click node_main "https://github.com/unight0/8-bit-font-designer/blob/main/src/main.cpp"
click node_config "https://github.com/unight0/8-bit-font-designer/blob/main/src/config.h"
click node_command_input "https://github.com/unight0/8-bit-font-designer/blob/main/src/main.cpp"
click node_commands "https://github.com/unight0/8-bit-font-designer/blob/main/src/cmdhandl.cpp"
click node_command_api "https://github.com/unight0/8-bit-font-designer/blob/main/src/cmdhandl.h"
click node_font_model "https://github.com/unight0/8-bit-font-designer/blob/main/src/fontedit.cpp"
click node_font_model_api "https://github.com/unight0/8-bit-font-designer/blob/main/src/fontedit.h"
click node_renderer "https://github.com/unight0/8-bit-font-designer/blob/main/src/renderer.cpp"
click node_renderer_api "https://github.com/unight0/8-bit-font-designer/blob/main/src/renderer.h"
click node_font_contract "https://github.com/unight0/8-bit-font-designer/blob/main/src/font8.h"
click node_font_files "https://github.com/unight0/8-bit-font-designer/blob/main/sample/font0"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_config,node_command_input,node_commands,node_command_api,node_renderer,node_renderer_api toneBlue
class node_font_model,node_font_model_api toneAmber
class node_build,node_sdl,node_font_contract,node_font_files toneMint
```

## Components

### Editor application

- [Application loop](https://github.com/unight0/8-bit-font-designer/blob/main/src/main.cpp): C++ entry point · Owns startup, event routing, state updates, and redraws. · `src/main.cpp`
- [Runtime config](https://github.com/unight0/8-bit-font-designer/blob/main/src/config.h): C++ header · `src/config.h`
- [Typed commands](https://github.com/unight0/8-bit-font-designer/blob/main/src/main.cpp): input buffer · Command letter and immediate argument collected by the application. · `src/main.cpp`
- [Command handler](https://github.com/unight0/8-bit-font-designer/blob/main/src/cmdhandl.cpp): C++ subsystem · Parses edit, resize, open, save, and quit commands. · `src/cmdhandl.cpp`
- [Command API](https://github.com/unight0/8-bit-font-designer/blob/main/src/cmdhandl.h): C++ header · `src/cmdhandl.h`
- [Renderer](https://github.com/unight0/8-bit-font-designer/blob/main/src/renderer.cpp): C++ subsystem · Draws the glyph grid, enabled pixels, and cursor feedback from model state. · `src/renderer.cpp`
- [Renderer API](https://github.com/unight0/8-bit-font-designer/blob/main/src/renderer.h): C++ header · `src/renderer.h`

### Font domain

- [Font editor model](https://github.com/unight0/8-bit-font-designer/blob/main/src/fontedit.cpp): C++ domain model · Stores glyph pixels, active glyph, cursor, and usable font range. · `src/fontedit.cpp`
- [Font model API](https://github.com/unight0/8-bit-font-designer/blob/main/src/fontedit.h): C++ header · `src/fontedit.h`

### Runtime and data contract

- [Make build](https://github.com/unight0/8-bit-font-designer/blob/main/Makefile): build · Builds the native SDL2 editor. · `Makefile`
- **SDL2**: native runtime · Provides the window, rendering context, and keyboard events.
- [C font header format](https://github.com/unight0/8-bit-font-designer/blob/main/src/font8.h): serialization contract · Compatibility contract for exported font data. · `src/font8.h`
- [Font files](https://github.com/unight0/8-bit-font-designer/blob/main/sample/font0): filesystem data · Open and save targets, including the bundled sample font. · `sample/font0`

## Connections

- Make build → Application loop: builds
- Make build → Renderer: builds
- Make build → SDL2: links
- Runtime config → Application loop: configures
- SDL2 → Application loop: keyboard and window events
- Application loop → Typed commands: collects
- Typed commands → Command handler: dispatches
- Command API → Command handler: declares
- Command handler → Font editor model: edits, resizes, loads, saves
- Font model API → Font editor model: declares
- Application loop → Font editor model: navigation and pixel toggles
- Application loop → Renderer: requests redraw
- Renderer API → Renderer: declares
- Font editor model → Renderer: glyph and cursor state
- Renderer → SDL2: drawing operations
- Command handler → Font files: opens and saves
- Font files → C font header format: serialized as
- C font header format → Font editor model: import/export format
