text: #include <kernel/types.h>
  #include <kernel/utils.h>
  #include "console.h"
  #include "gui.h"
  
  uint16 get_box_draw_char(uint8 chn, uint8 fore_color, uint8 back_color)
  {
    uint16 ax = 0;
    uint8 ah = 0;
  
    ah = back_color;
    ah <<= 4;
    ah |= fore_color;
    ax = ah;
    ax <<= 8;
    ax |= chn;
  
    return ax;
  }
  
  void draw_generic_box(uint16 x, uint16 y, 
                        uint16 width, uint16 height,
                        uint8 fore_color, uint8 back_color,
                        uint8 topleft_ch,
                        uint8 topbottom_ch,
                        uint8 topright_ch,
                        uint8 leftrightside_ch,
                        uint8 bottomleft_ch,
                        uint8 bottomright_ch)
  {
    uint32 i;
  
    vga_index = 80*y;
    vga_index += x;
  
    vga_buffer[vga_index] = get_box_draw_char(topleft_ch, fore_color, back_color);
  
    vga_index++;
  
    for(i = 0; i < width; i++){
      vga_buffer[vga_index] = get_box_draw_char(topbottom_ch, fore_color, back_color);
      vga_index++;
    }
    vga_buffer[vga_index] = get_box_draw_char(topright_ch, fore_color, back_color);
  
    y++;
    vga_index = 80*y;
    vga_index += x;
  
    for(i = 0; i < height; i++){
      vga_buffer[vga_index] = get_box_draw_char(leftrightside_ch, fore_color, back_color);
      vga_index++;
      vga_index += width;
      vga_buffer[vga_index] = get_box_draw_char(leftrightside_ch, fore_color, back_color);
      y++;
      vga_index = 80*y;
      vga_index += x;
    }
    vga_buffer[vga_index] = get_box_draw_char(bottomleft_ch, fore_color, back_color);
    vga_index++;
    for(i = 0; i < width; i++){
      vga_buffer[vga_index] = get_box_draw_char(topbottom_ch, fore_color, back_color);
      vga_index++;
    }
    vga_buffer[vga_index] = get_box_draw_char(bottomright_ch, fore_color, back_color);
  
    vga_index = 0;
  }
  
  void draw_box(uint8 boxtype, 
                uint16 x, uint16 y, 
                uint16 width, uint16 height,
                uint8 fore_color, uint8 back_color)
  {
    switch(boxtype){
      case BOX_SINGLELINE : 
        draw_generic_box(x, y, width, height, 
                        fore_color, back_color, 
                        218, 196, 191, 179, 192, 217);
        break;
  
      case BOX_DOUBLELINE : 
        draw_generic_box(x, y, width, height, 
                        fore_color, back_color, 
                        201, 205, 187, 186, 200, 188);
        break;
    }
  }
  
  void fill_box(uint8 ch, uint16 x, uint16 y, uint16 width, uint16 height, uint8 color)
  {
    uint32 i,j;
  
    for(i = 0; i < height; i++){
      vga_index = 80*y;
      vga_index += x;
  
      for(j = 0; j < width; j++){
        vga_buffer[vga_index] = get_box_draw_char(ch, 0, color);
        vga_index++;
      }
      y++;
    }
  }