Implement PrintFormat which scrolls the screen when overflowing

This commit is contained in:
Sijmen 2020-12-11 20:52:57 +01:00
parent 9cfcb0ddf7
commit dfb8fb16fc
Signed by: vijfhoek
GPG Key ID: DAF7821E067D9C48
3 changed files with 26 additions and 0 deletions

View File

@ -188,6 +188,16 @@ void Screen::ScrollArea(u32 x1, u32 y1, u32 x2, u32 y2)
} }
} }
void Screen::ScrollUp(u32 pixels)
{
memcpy(
framebuffer,
framebuffer + pixels * 2 * pitch,
(height - pixels * 2) * pitch
);
DrawRectangle(0, height - pixels, width, height, RGBA(0, 0, 0, 0xFF));
}
void Screen::Clear(RGBA colour) void Screen::Clear(RGBA colour)
{ {
DrawRectangle(0, 0, width, height, colour); DrawRectangle(0, 0, width, height, colour);

View File

@ -36,6 +36,7 @@ public:
void Clear(RGBA colour); void Clear(RGBA colour);
void ScrollArea(u32 x1, u32 y1, u32 x2, u32 y2); void ScrollArea(u32 x1, u32 y1, u32 x2, u32 y2);
void ScrollUp(u32 pixels);
void WriteChar(bool petscii, u32 x, u32 y, unsigned char c, RGBA colour); void WriteChar(bool petscii, u32 x, u32 y, unsigned char c, RGBA colour);
u32 PrintText(bool petscii, u32 xPos, u32 yPos, char *ptr, RGBA TxtColour = RGBA(0xff, 0xff, 0xff, 0xff), RGBA BkColour = RGBA(0, 0, 0, 0xFF), bool measureOnly = false, u32* width = 0, u32* height = 0); u32 PrintText(bool petscii, u32 xPos, u32 yPos, char *ptr, RGBA TxtColour = RGBA(0xff, 0xff, 0xff, 0xff), RGBA BkColour = RGBA(0, 0, 0, 0xFF), bool measureOnly = false, u32* width = 0, u32* height = 0);

View File

@ -1867,6 +1867,21 @@ void DisplayMessage(int x, int y, bool LCD, const char* message, u32 textColour,
#endif #endif
} }
int y_pos = 184;
void PrintFormat(const char* format, ...)
{
va_list args;
va_start(args, format);
vsnprintf(tempBuffer, tempBufferSize, format, args);
va_end(args);
if (y_pos + 96 >= screenHeight) {
screen.ScrollUp(8);
y_pos -= 16;
}
screen.PrintText(false, 0, y_pos+=16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK);
}
extern "C" extern "C"
{ {
void kernel_main(unsigned int r0, unsigned int r1, unsigned int atags) void kernel_main(unsigned int r0, unsigned int r1, unsigned int atags)