// draw string with transparent background public static void DrawString(int x, int y, string text, VGAColor fg, VGAFont font) { // determine font size fontHeight = 8; if (font == VGAFont.Font8x8) { fontHeight = 8; } else if (font == VGAFont.Font8x16) { fontHeight = 16; } int xx = x, yy = y; for (int i = 0; i < text.Length; i++) { // new line if (text[i] == '\n') { xx = x; yy += fontHeight; } // character else { DrawChar(xx, yy, text[i], fg, font); xx += 8; } } }
// draw character with background color public static void DrawChar(int x, int y, char c, VGAColor fg, VGAColor bg, VGAFont font) { // determine font size fontHeight = 8; if (font == VGAFont.Font8x8) { fontHeight = 8; } else if (font == VGAFont.Font8x16) { fontHeight = 16; } int p = fontHeight * (byte)c; // vertical for (int cy = 0; cy < fontHeight; cy++) { // horizontal for (byte cx = 0; cx < 8; cx++) { // 8x8 if (font == VGAFont.Font8x8) { // convert to position and draw if (VGAFontData.ConvertByteToBitAddress(VGAFontData.Font8x8_Data[p + cy], cx + 1)) { DrawPixel(x + (8 - cx), y + cy, fg); } else { DrawPixel(x + (8 - cx), y + cy, bg); } } // 8x16 else if (font == VGAFont.Font8x16) { // convert to position and draw if (VGAFontData.ConvertByteToBitAddress(VGAFontData.Font8x16_Data[p + cy], cx + 1)) { DrawPixel(x + (8 - cx), y + cy, fg); } else { DrawPixel(x + (8 - cx), y + cy, bg); } } } } }