#include "display.h"
-// #define USE_NCURSES
+#define USE_NCURSES
-int display_init(t_display *display) {
+int display_init(t_display *display,int outfd) {
struct winsize ws;
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);
+ display->outfd=outfd;
+
+ dprintf(display->outfd,"[display] initializing display, w: %02d / h: %02d\n",
+ ws.ws_col,ws.ws_row);
/* allocating 'screen' buffer */
- if((display->screen=(unsigned char *)malloc(display->max_x*display->max_y))
+ if((display->screen=(char *)malloc(display->max_x*display->max_y))
==NULL) {
perror("[display] malloc call");
return D_ERROR;
int display_draw(t_display *display) {
+#ifndef USE_NCURSES
int x,y;
+#endif
#ifdef USE_NCURSES
mvprintw(0,0,"%s",display->screen);
- for(y=0;y<display->max_y;y++)
- for(x=0;x<display->max_x;x++)
- mvaddch(y,x,*(display->screen+y*display->max_x+x));
+ //for(y=0;y<display->max_y;y++)
+ // for(x=0;x<display->max_x;x++)
+ // mvaddch(y,x,*(display->screen+y*display->max_x+x));
refresh();
#else
for(y=0;y<display->max_y;y++) {
for(x=0;x<display->max_x;x++)
- printf("%c",*(display->screen+y*display->max_x+x));
- printf("\n");
+ fprintf(stderr,"%c",*(display->screen+y*display->max_x+x));
+ fprintf(stderr,"\n");
}
#endif
#else
for(y=0;y<line;y++) {
for(x=0;x<display->max_x;x++)
- printf("%c",*(display->screen+y*display->max_x+x));
- printf("\n");
+ fprintf(stderr,"%c",*(display->screen+y*display->max_x+x));
+ fprintf(stderr,"\n");
}
#endif
free(display->screen);
- puts("[display] shutdown");
+ dprintf(display->outfd,"[display] shutdown\n");
return D_SUCCESS;
}
m=(Y_-Y)/(X_-X);
- for(y=0;y<display->max_y;y++)
- for(x=0;x<display->max_x;x++)
- if((int)((x-X)*m+Y)==y) *(display->screen+y*display->max_x+x)=sym;
+ for(x=X;x<=X_;x++) {
+ y=(x-X)*m+Y;
+ *(display->screen+y*display->max_x+x)=sym;
+ }
return D_SUCCESS;
}