Clean up console
This commit is contained in:
1 parent
0568a813f2
commit
cb31e36e90
2 files changed
+32
-20
No files matched your search
@@ -8,17 +8,30 @@ import hulk.kfont;
|
||||
|
||||
struct console
|
||||
{
|
||||
/** Console width in text columns. */
|
||||
private static __gshared size_t m_width;
|
||||
|
||||
/** Console height in text rows. */
|
||||
private static __gshared size_t m_height;
|
||||
|
||||
/** Current console cursor X position. */
|
||||
private static __gshared size_t m_x;
|
||||
|
||||
/** Current console cursor Y position. */
|
||||
private static __gshared size_t m_y;
|
||||
|
||||
/**
|
||||
* Initialize the console.
|
||||
*/
|
||||
public static void initialize()
|
||||
{
|
||||
m_width = fb.width / kfont.advance;
|
||||
m_height = fb.height / kfont.line_height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the console.
|
||||
*/
|
||||
public static void clear()
|
||||
{
|
||||
fb.clear();
|
||||
@@ -26,6 +39,11 @@ struct console
|
||||
m_y = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a character to the console.
|
||||
*
|
||||
* @param ch Character to write.
|
||||
*/
|
||||
public static void write(char ch)
|
||||
{
|
||||
if (ch == '\n')
|
||||
@@ -53,17 +71,30 @@ struct console
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a character.
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
const(CharInfo) * ci = &kfont.chars[ch];
|
||||
fb.blit_alpha_bitmap(fb_x(x) + ci.left, fb_y(y) + ci.top - ci.height, ci.bitmap, ci.width, ci.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the framebuffer X coordinate corresponding to the console X position.
|
||||
*/
|
||||
private static size_t fb_x(size_t x)
|
||||
{
|
||||
return x * kfont.advance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the framebuffer Y coordinate corresponding to the console Y position.
|
||||
*/
|
||||
private static size_t fb_y(size_t y)
|
||||
{
|
||||
return fb.height - ((y + 1u) * kfont.line_height);
|
||||
|
||||
Reference in new issue
Block a user