]> Chaos Git - corbenik/corbenik.git/commitdiff
Oh, boy.
authorchaoskagami <chaos.kagami@gmail.com>
Tue, 28 Jun 2016 18:20:29 +0000 (14:20 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Tue, 28 Jun 2016 18:20:29 +0000 (14:20 -0400)
 * 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.

source/menu.c
source/std/draw.c
source/std/draw.h

index 7d7bf29b29c0268337ac88f947e82822334d8377..812df2f9177e584ad21b4dd1f00ba2def8fcbcab 100644 (file)
@@ -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);
 }
 
index 6252551fe8e7b43319fc93b0fd390f6a3c7d6912..04470b3ed4397369f0fa8cd8e9a668166a2a2d30 100644 (file)
@@ -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;
index f9443ad3545554a5c3fef1120e90a32bfcea1cba..de24ff7c10752dc5e0b1d37791ebe6b726671409 100644 (file)
@@ -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);