int vt_draw_frame(int width, int height, char attr, int r, int c) { if(r+height >= scr_lines || c+width >= scr_width || r < 0 || c < 0 ) return 1; else{ int aux_width = width, aux_height = height; vt_print_char(UL_CORNER, attr, r, c); vt_print_char(LL_CORNER, attr, r+height-1, c); vt_print_char(UR_CORNER, attr, r, c+width-1); vt_print_char(LR_CORNER, attr, r+height-1, c+width-1); int i = aux_width - 2; for(i; i!=0; i--){ vt_print_char(HOR_BAR, attr, r, c+i); vt_print_char(HOR_BAR, attr, r+height-1, c+i); } i = aux_height - 2; for(i; i!=0; i--){ vt_print_char(VERT_BAR, attr, r+i, c); vt_print_char(VERT_BAR, attr, r+i, c + width-1); } return 0; } }
int vt_print_string(char *str, char attr, int r, int c) { int i = 0; while (str[i] != 0) { vt_print_char(str[i], attr, r, c+i); i++; } return 0; }
int vt_print_string(char *str, char attr, int r, int c) { if (r >= scr_lines || r < 0 || c >= scr_width || c < 0 || (c+strlen(str)>=scr_width)) return 1; unsigned int i; int position = c; for(i=0; i<strlen(str);i++){ if(vt_print_char(str[i], attr, r, position) != 0) return 1; position++; } return 0; }
int vt_draw_frame(int width, int height, char attr, int r, int c) { int i, j; for (i=1; i<=height; i++) { for (j=1; j<=width; j++) { if (i == 1 && j == 1) { vt_print_char(UL_CORNER, attr, r+i, c+j); } else if (i == 1 && j == width) { vt_print_char(UR_CORNER, attr, r+i, c+j); } else if (i == height && j == 1) { vt_print_char(LL_CORNER, attr, r+i, c+j); } else if (i == height && j == width) { vt_print_char(LR_CORNER, attr, r+i, c+j); } else if (i == 1 || i == height) { vt_print_char(HOR_BAR, attr, r+i, c+j); } else if (j == 1 || j == width) { vt_print_char(VERT_BAR, attr, r+i, c+j); } } } return 0; }
int vt_draw_frame(int width, int height, char attr, int r, int c) { char border = '#'; //Char to use for the frame char *line = malloc(width*sizeof(char)); //Allocate space equivalent to the width of the frame unsigned int i; for(i=0;i<width;i++){ line[i] = border; //Fill in the line with the border char defined previously } int result; for(i=0;i<height;i++){ if(i==0 || i == height-1) //If it's the first and last line draw the frame horizontally result = vt_print_string(line, attr, r+i, c); else{ //Else only draw the first and last char result = vt_print_char(border, attr, r+i, c); result = vt_print_char(border, attr, r+i, c+width-1); } } free(line); return result; }