changes in display method -> ncurses (strange *printf probs :/)
[my-code/ivac.git] / src / display.c
index c46c11c..e42c30b 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "display.h"
 
+#define USE_NCURSES
+
 int display_init(t_display *display) {
 
   struct winsize ws;
@@ -30,6 +32,14 @@ int display_init(t_display *display) {
   /* 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;
 }
 
@@ -37,11 +47,19 @@ int display_draw(t_display *display) {
 
   int x,y;
 
+#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));
+  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");
   }
+#endif
 
   return D_SUCCESS;
 }
@@ -50,11 +68,29 @@ int display_draw_until_line(t_display *display,int line) {
   
   int x,y;
 
+#ifdef USE_NCURSES
+  for(y=0;y<line;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<line;y++) {
     for(x=0;x<display->max_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;
 }
@@ -68,6 +104,10 @@ int display_clear_screen(t_display *display) {
 
 int display_shutdown(t_display *display) {
 
+#ifdef USE_NCURSES
+  endwin();
+#endif
+
   free(display->screen);
 
   puts("[display] shutdown");