1 /* display.c -- display management stuff
3 * hackbard@hackdaworld.dyndns.org
11 int display_init(t_display *display,int outfd) {
16 if(ioctl(1,TIOCGWINSZ,&ws)==-1) {
17 perror("[display] ioctl call");
20 display->max_x=ws.ws_col;
21 display->max_y=ws.ws_row;
25 dprintf(display->outfd,"[display] initializing display, w: %02d / h: %02d\n",
28 /* allocating 'screen' buffer */
29 if((display->screen=(char *)malloc(display->max_x*display->max_y))
31 perror("[display] malloc call");
34 /* space as display pixel default */
35 memset(display->screen,0x20,display->max_x*display->max_y);
48 int display_draw(t_display *display) {
53 mvprintw(0,0,"%s",display->screen);
54 for(y=0;y<display->max_y;y++)
55 for(x=0;x<display->max_x;x++)
56 mvaddch(y,x,*(display->screen+y*display->max_x+x));
59 for(y=0;y<display->max_y;y++) {
60 for(x=0;x<display->max_x;x++)
61 fprintf(stderr,"%c",*(display->screen+y*display->max_x+x));
69 int display_draw_until_line(t_display *display,int line) {
75 for(x=0;x<display->max_x;x++)
76 mvaddch(y,x,*(display->screen+y*display->max_x+x));
81 for(x=0;x<display->max_x;x++)
82 fprintf(stderr,"%c",*(display->screen+y*display->max_x+x));
90 int display_set_cursor(t_display *display,int x,int y) {
100 int display_clear_screen(t_display *display) {
102 memset(display->screen,0x20,display->max_x*display->max_y);
107 int display_shutdown(t_display *display) {
113 free(display->screen);
115 dprintf(display->outfd,"[display] shutdown\n");
120 int display_line(t_display *display,int X,int Y,int X_,int Y_,char sym) {
129 *(display->screen+y*display->max_x+x)=sym;
135 int display_string(t_display *display,int x,int y,char *string,int len) {
137 if(len>display->max_x-x) return D_INV_STRING_LEN;
139 memcpy(display->screen+y*display->max_x+x,string,len);
144 int display_string_vert(t_display *display,int x,int y,char *string,int len) {
148 if(len>display->max_y-y) return D_INV_STRING_LEN;
149 for(i=y*display->max_x+x;i<(y+len)*display->max_x+x;i+=display->max_x)
150 *(display->screen+i)=*(string++);