Add console header line
This commit is contained in:
1 parent
4273c703e9
commit
8638840cd8
3 files changed
+64
-11
No files matched your search
+55
-4
@@ -5,6 +5,9 @@ module hulk.console;
|
||||
|
||||
import hulk.fb;
|
||||
import hulk.kfont;
|
||||
import hulk.ver;
|
||||
import hulk.rtc;
|
||||
import hulk.writef;
|
||||
|
||||
/**
|
||||
* Represent the HULK console.
|
||||
@@ -13,6 +16,8 @@ import hulk.kfont;
|
||||
*/
|
||||
struct Console
|
||||
{
|
||||
private enum BORDER_COLOR = 0xFF8000u;
|
||||
|
||||
/** Console width in text columns. */
|
||||
private static __gshared size_t m_width;
|
||||
|
||||
@@ -30,8 +35,9 @@ struct Console
|
||||
*/
|
||||
public static void initialize()
|
||||
{
|
||||
size_t fb_console_height = Fb.height - Kfont.line_height - 1;
|
||||
m_width = Fb.width / Kfont.advance;
|
||||
m_height = Fb.height / Kfont.line_height;
|
||||
m_height = fb_console_height / Kfont.line_height;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,6 +48,7 @@ struct Console
|
||||
Fb.clear();
|
||||
m_x = 0u;
|
||||
m_y = 0u;
|
||||
draw_header();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,16 +84,28 @@ struct Console
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a character.
|
||||
* Render a character using console characters.
|
||||
*
|
||||
* @param x X position.
|
||||
* @param y Y position.
|
||||
* @param ch Character to render.
|
||||
*/
|
||||
private static void render_char(size_t x, size_t y, char ch)
|
||||
{
|
||||
render_char_fb(fb_x(x), fb_y(y), ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a character using framebuffer coordinates.
|
||||
*
|
||||
* @param x X position.
|
||||
* @param y Y position.
|
||||
* @param ch Character to render.
|
||||
*/
|
||||
private static void render_char_fb(size_t x, size_t y, char ch)
|
||||
{
|
||||
const(CharInfo) * ci = &Kfont.chars[ch];
|
||||
Fb.blit_alpha_bitmap(fb_x(x) + ci.left, fb_y(y) + ci.top, ci.bitmap, ci.width, ci.height);
|
||||
Fb.blit_alpha_bitmap(x + ci.left, y + ci.top, ci.bitmap, ci.width, ci.height);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,6 +121,38 @@ struct Console
|
||||
*/
|
||||
private static size_t fb_y(size_t y)
|
||||
{
|
||||
return y * Kfont.line_height;
|
||||
return (y + 1) * Kfont.line_height + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw console header line.
|
||||
*/
|
||||
private static draw_header()
|
||||
{
|
||||
static __gshared string header_text = "Welcome to HOS v" ~ VERSION ~ "!";
|
||||
Fb.rect(0u, Kfont.line_height, Fb.width, 1, BORDER_COLOR);
|
||||
size_t x = 0;
|
||||
foreach (c; header_text)
|
||||
{
|
||||
render_char_fb(fb_x(x), 0, c);
|
||||
x++;
|
||||
}
|
||||
update_header();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update console header.
|
||||
*/
|
||||
public static update_header()
|
||||
{
|
||||
__gshared uint x;
|
||||
x = Fb.width - 8 * Kfont.advance;
|
||||
Fb.rect(x - 1, 0, 1, Kfont.line_height, BORDER_COLOR);
|
||||
Fb.rect(x, 0, Fb.width - x, Kfont.line_height, 0);
|
||||
Rtc.time rtc_time = Rtc.read_rtc_time();
|
||||
writef(function(ubyte ch) {
|
||||
render_char_fb(x, 0, ch);
|
||||
x += Kfont.advance;
|
||||
}, "%02u:%02u:%02u", rtc_time.hour, rtc_time.minute, rtc_time.second);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user