From: chaoskagami Date: Tue, 28 Jun 2016 18:20:29 +0000 (-0400) Subject: Oh, boy. X-Git-Tag: v0.2.0~55 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=3f8fa694d8f49c5f68e3d49a43fdc78727250d89;p=corbenik%2Fcorbenik.git Oh, boy. * Rectangle draw function, used for * Horizontal fill function, used for * Fixing the pixel gap up top. Needs optimization. Now everybody will complain about the slight flicker caused by repainting, I imagine. Oh well. Can't win them all. --- diff --git a/source/menu.c b/source/menu.c index 7d7bf29..812df2f 100644 --- a/source/menu.c +++ b/source/menu.c @@ -102,10 +102,8 @@ extern unsigned int font_w; void header(char *append) { - for (unsigned int i = 0; i < TOP_WIDTH / font_w; i++) { - fprintf(stdout, "\x1b[30;42m "); - } set_cursor(TOP_SCREEN, 0, 0); + fill_line(stdout, 0, 0x2); fprintf(stdout, "\x1b[30;42m .Corbenik // %s\x1b[0m\n\n", append); } diff --git a/source/std/draw.c b/source/std/draw.c index 6252551..04470b3 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -30,6 +30,61 @@ static unsigned int text_bottom_height = 10; uint8_t top_bg[TOP_SIZE]; uint8_t bottom_bg[BOTTOM_SIZE]; +static uint32_t colors[16] = { + 0x000000, // Black + 0xaa0000, // Blue + 0x00aa00, // Green + 0xaaaa00, // Cyan + 0x0000aa, // Red + 0xaa00aa, // Magenta + 0x0055aa, // Brown + 0xaaaaaa, // Gray + 0x555555, // Dark gray + 0xff5555, // Bright blue + 0x55ff55, // Bright green + 0xffff55, // Bright cyan + 0x5555ff, // Bright red + 0xff55ff, // Bright megenta + 0x55ffff, // Yellow + 0xffffff // White +}; // VGA color table. + +void rect(void* channel, int x, int y, int x2, int y2, uint8_t color) { + uint8_t* screen = NULL; + int height = 0; + if (channel == stdout) { + screen = framebuffers->top_left; + height = TOP_HEIGHT; + } else if (channel == stderr) { + screen = framebuffers->bottom; + height = BOTTOM_HEIGHT; + } else { + return; // Invalid on non-screen displays. + } + + for(int y_a = y; y_a < y2; y_a++) { + for(int x_a = x; x_a < x2; x_a++) { + int xDisplacement = (x_a * SCREEN_DEPTH * height); + int yDisplacement = ((height - y_a - 1) * SCREEN_DEPTH); + int pos = xDisplacement + yDisplacement; + + screen[pos] = colors[color & 0xF]; + screen[pos + 1] = colors[color & 0xF] >> 8; + screen[pos + 2] = colors[color & 0xF] >> 16; + } + } +} + +void fill_line(void* channel, int y, uint8_t color) { + int x2 = 0; + if (channel == stdout) + x2 = TOP_WIDTH; + else if (channel == stderr) + x2 = BOTTOM_WIDTH; + + rect(channel, 0, (y * font_h), x2, ((y+1) * font_h), color); +} + // This is (roughly) the screenshot specs as used by smeas scrtool. void screenshot() { f_unlink(PATH_TEMP "/screenshot.ppm"); @@ -134,25 +189,6 @@ void set_font(const char* filename) { text_bottom_height = BOTTOM_HEIGHT / font_h; } -static uint32_t colors[16] = { - 0x000000, // Black - 0xaa0000, // Blue - 0x00aa00, // Green - 0xaaaa00, // Cyan - 0x0000aa, // Red - 0xaa00aa, // Magenta - 0x0055aa, // Brown - 0xaaaaaa, // Gray - 0x555555, // Dark gray - 0xff5555, // Bright blue - 0x55ff55, // Bright green - 0xffff55, // Bright cyan - 0x5555ff, // Bright red - 0xff55ff, // Bright megenta - 0x55ffff, // Yellow - 0xffffff // White -}; // VGA color table. - void dump_log(unsigned int force) { if(!config.options[OPTION_SAVE_LOGS]) return; diff --git a/source/std/draw.h b/source/std/draw.h index f9443ad..de24ff7 100644 --- a/source/std/draw.h +++ b/source/std/draw.h @@ -38,6 +38,8 @@ _UNUSED static struct framebuffers #define BOTTOM_FB framebuffers->bottom void screenshot(); +void rect(void* channel, int x, int y, int x2, int y2, uint8_t color); +void fill_line(void* channel, int y, uint8_t color); void clear_bg(); void load_bg_top(char* fname_top);