modifications i forgot to commit
[my-code/api.git] / display / display.c
index cf09a93..fd53247 100644 (file)
@@ -8,7 +8,7 @@
 
 #define USE_NCURSES
 
-int display_init(t_display *display) {
+int display_init(t_display *display,int outfd) {
 
   struct winsize ws;
 
@@ -20,11 +20,13 @@ int display_init(t_display *display) {
   display->max_x=ws.ws_col;
   display->max_y=ws.ws_row;
 
-  fprintf(stderr,"[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;
@@ -45,13 +47,15 @@ int display_init(t_display *display) {
 
 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++) {
@@ -110,7 +114,7 @@ int display_shutdown(t_display *display) {
 
   free(display->screen);
 
-  fprintf(stderr,"[display] shutdown");
+  dprintf(display->outfd,"[display] shutdown\n");
 
   return D_SUCCESS;
 }
@@ -122,9 +126,17 @@ int display_line(t_display *display,int X,int Y,int X_,int Y_,char sym) {
 
   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;
+}
+
+int display_hor_line(t_display *display,int Y,char sym) {
+
+  display_line(display,0,Y,display->max_x,Y,sym);
 
   return D_SUCCESS;
 }