1 /* display.c -- display management stuff
3 * hackbard@hackdaworld.dyndns.org
11 int display_init(t_display *display) {
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;
23 printf("[display] initializing display, width: %02d / height: %02d ...\n",
26 /* allocating 'screen' buffer */
27 if((display->screen=(unsigned char *)malloc(display->max_x*display->max_y))
29 perror("[display] malloc call");
32 /* space as display pixel default */
33 memset(display->screen,0x20,display->max_x*display->max_y);
46 int display_draw(t_display *display) {
51 mvprintw(0,0,"%s",display->screen);
52 for(y=0;y<display->max_y;y++)
53 for(x=0;x<display->max_x;x++)
54 mvaddch(y,x,*(display->screen+y*display->max_x+x));
57 for(y=0;y<display->max_y;y++) {
58 for(x=0;x<display->max_x;x++)
59 printf("%c",*(display->screen+y*display->max_x+x));
67 int display_draw_until_line(t_display *display,int line) {
73 for(x=0;x<display->max_x;x++)
74 mvaddch(y,x,*(display->screen+y*display->max_x+x));
79 for(x=0;x<display->max_x;x++)
80 printf("%c",*(display->screen+y*display->max_x+x));
88 int display_set_cursor(t_display *display,int x,int y) {
98 int display_clear_screen(t_display *display) {
100 memset(display->screen,0x20,display->max_x*display->max_y);
105 int display_shutdown(t_display *display) {
111 free(display->screen);
113 puts("[display] shutdown");
118 int display_line(t_display *display,int X,int Y,int X_,int Y_,char sym) {
125 for(y=0;y<display->max_y;y++)
126 for(x=0;x<display->max_x;x++)
127 if((int)((x-X)*m+Y)==y) *(display->screen+y*display->max_x+x)=sym;
132 int display_string(t_display *display,int x,int y,char *string,int len) {
134 if(len>display->max_x-x) return D_INV_STRING_LEN;
136 memcpy(display->screen+y*display->max_x+x,string,len);
141 int display_string_vert(t_display *display,int x,int y,char *string,int len) {
145 if(len>display->max_y-y) return D_INV_STRING_LEN;
146 for(i=y*display->max_x+x;i<(y+len)*display->max_x+x;i+=display->max_x)
147 *(display->screen+i)=*(string++);