X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fivac.git;a=blobdiff_plain;f=src%2Fdisplay.c;fp=src%2Fdisplay.c;h=0000000000000000000000000000000000000000;hp=e42c30b38dd0a6e983f1a2d213fe3db334b2d6ef;hb=21a073b6e9d464f3f11dfb290d27341bb4a203b6;hpb=40031b2d692a7b83e437535045ece6c58f8bf31e diff --git a/src/display.c b/src/display.c deleted file mode 100644 index e42c30b..0000000 --- a/src/display.c +++ /dev/null @@ -1,150 +0,0 @@ -/* display.c -- display management stuff - * - * hackbard@hackdaworld.dyndns.org - * - */ - -#include "display.h" - -#define USE_NCURSES - -int display_init(t_display *display) { - - struct winsize ws; - - /* dimensions */ - if(ioctl(1,TIOCGWINSZ,&ws)==-1) { - perror("[display] ioctl call"); - return D_ERROR; - } - display->max_x=ws.ws_col; - display->max_y=ws.ws_row; - - printf("[display] initializing display, width: %02d / height: %02d ...\n", - ws.ws_col,ws.ws_row); - - /* allocating 'screen' buffer */ - if((display->screen=(unsigned char *)malloc(display->max_x*display->max_y)) - ==NULL) { - perror("[display] malloc call"); - return D_ERROR; - } - /* space as display pixel default */ - memset(display->screen,0x20,display->max_x*display->max_y); - -#ifdef USE_NCURSES - initscr(); - nonl(); - noecho(); - cbreak(); - curs_set(0); -#endif - - return D_SUCCESS; -} - -int display_draw(t_display *display) { - - int x,y; - -#ifdef USE_NCURSES - mvprintw(0,0,"%s",display->screen); - for(y=0;ymax_y;y++) - for(x=0;xmax_x;x++) - mvaddch(y,x,*(display->screen+y*display->max_x+x)); - refresh(); -#else - for(y=0;ymax_y;y++) { - for(x=0;xmax_x;x++) - printf("%c",*(display->screen+y*display->max_x+x)); - printf("\n"); - } -#endif - - return D_SUCCESS; -} - -int display_draw_until_line(t_display *display,int line) { - - int x,y; - -#ifdef USE_NCURSES - for(y=0;ymax_x;x++) - mvaddch(y,x,*(display->screen+y*display->max_x+x)); - refresh(); - } -#else - for(y=0;ymax_x;x++) - printf("%c",*(display->screen+y*display->max_x+x)); - printf("\n"); - } -#endif - - return D_SUCCESS; -} - -int display_set_cursor(t_display *display,int x,int y) { - -#ifdef USE_NCURSES - move(y,x); - refresh(); -#endif - - return D_SUCCESS; -} - -int display_clear_screen(t_display *display) { - - memset(display->screen,0x20,display->max_x*display->max_y); - - return D_SUCCESS; -} - -int display_shutdown(t_display *display) { - -#ifdef USE_NCURSES - endwin(); -#endif - - free(display->screen); - - puts("[display] shutdown"); - - return D_SUCCESS; -} - -int display_line(t_display *display,int X,int Y,int X_,int Y_,char sym) { - - double m; - int x,y; - - m=(Y_-Y)/(X_-X); - - for(y=0;ymax_y;y++) - for(x=0;xmax_x;x++) - if((int)((x-X)*m+Y)==y) *(display->screen+y*display->max_x+x)=sym; - - return D_SUCCESS; -} - -int display_string(t_display *display,int x,int y,char *string,int len) { - - if(len>display->max_x-x) return D_INV_STRING_LEN; - - memcpy(display->screen+y*display->max_x+x,string,len); - - return D_SUCCESS; -} - -int display_string_vert(t_display *display,int x,int y,char *string,int len) { - - int i; - - if(len>display->max_y-y) return D_INV_STRING_LEN; - for(i=y*display->max_x+x;i<(y+len)*display->max_x+x;i+=display->max_x) - *(display->screen+i)=*(string++); - - return D_SUCCESS; -}