text-mode 0.0.7
Fast virtual text mode with 8x8 Unicode font.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
text-mode
The goal of the text-mode
DUB package is to be a virtual text-mode, like in older DOS machines, except with Unicode support instead of a single 8-bit code page. There is however a 16 color palette like in ancient text modes.
A secundary goal is to be efficient (everything is cached) and provide vintage looks.
0. Basic example
See examples/
to run a basic example (you will need SDL installed).
1. Setup a TM_Console
The following TM_Console
methods are necessary in order to use text-mode
:
size(int columns, int rows)
outbuf(void* p, int width, int height, int pitchBytes)
render()
Example:
TM_Console console;
void setup(MyImage image)
{
// Set number of columns and rows.
int columns = 40;
int rows = 20;
// .size clear the text buffer content and eventually resize it
console.size(columns, rows);
// set where to draw output, can be called every frame
console.outbuf(image.ptr, image.width, image.height, image.pitchBytes);
/* ...printing functions goes here... */
// display changes since the last .render, in output buffer
console.render();
}
**Key concept**: No font resampling is done. Pixels are scaled NxN depending to the room in output buffer, and letterboxed with "border" pixels.
### 2. Print some text
Example:
console.size(40, 22);
with (console)
{
cls();
print("Hello world! ");
println("Same, with line feed");
// Save state (colors, style, cursor position)
save();
// Change foreground color (0 to 15)
fg(TM_red);
print("This is red text ");
bg(TM_blue);
println("on blue background");
// Restore state. Warning: this restore cursor position!
restore();
// Set text cursor position (where text is drawn next)
locate(7, 5);
// There are 3 implemented styles:
// - bold
// - shiny (sort of bloom)
// - underline
style(TM_bold);
println("This is bold");
style(TM_shiny);
print("This is ");
fg(14);
println("shiny");
style(TM_underline);
fg(TM_lgreen);
println("This is underline");
render();
}
Result
**Key-concept**: if text must be printed in a line below the screen, the whole screen scrolls.
TO DOCUMENT
- raw char data access
- print some CCL text
- tweak options
- Registered by ponce
- 0.0.7 released 2 months ago
- p0nce/text-mode
- BSL-1.0
- Dependencies:
- none
- Versions:
-
0.0.7 2024-Jul-22 0.0.6 2024-Jul-19 0.0.5 2024-Jun-29 0.0.4 2024-Jun-27 0.0.3 2024-Jun-27 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
1 downloads this month
-
12 downloads total
-
- Score:
- 0.0
- Short URL:
- text-mode.dub.pm