]> hackdaworld.org Git - my-code/ivac.git/commitdiff
new display stuff, DOESNT WORK!!11
authorhackbard <hackbard>
Fri, 21 May 2004 18:34:37 +0000 (18:34 +0000)
committerhackbard <hackbard>
Fri, 21 May 2004 18:34:37 +0000 (18:34 +0000)
src/display.c
src/display.h
src/ivac.c
src/ivac.h

index afb2a574a0db594eff724f8e604d9d031b5e3a6b..c46c11c9aeff52ad5530d68e3d5e732bea9e08cc 100644 (file)
@@ -8,11 +8,18 @@
 
 int display_init(t_display *display) {
 
-  puts("[display] initializing display ...");
+  struct winsize ws;
 
   /* dimensions */
-  display->max_x=atoi(getenv("COLUMNS"));
-  display->max_y=atoi(getenv("LINES"));
+  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))
@@ -32,7 +39,7 @@ int display_draw(t_display *display) {
 
   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("%c",*(display->screen+y*display->max_x+x));
     printf("\n");
   }
 
@@ -43,9 +50,10 @@ int display_draw_until_line(t_display *display,int line) {
   
   int x,y;
 
-  for(x=0;x<display->max_x;x++) {
-    for(y=0;y<line;y++) printf("%c",display->screen+y*display->max_x+x);
-  printf("\n");
+  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");
   }
 
   return D_SUCCESS;
@@ -53,7 +61,7 @@ int display_draw_until_line(t_display *display,int line) {
 
 int display_clear_screen(t_display *display) {
  
-  memcpy(display->screen,0x20,display->max_x*display->max_y);
+  memset(display->screen,0x20,display->max_x*display->max_y);
 
   return D_SUCCESS;
 }
@@ -76,7 +84,7 @@ int display_line(t_display *display,int X,int Y,int X_,int Y_,char sym) {
 
   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;
+      if((int)((x-X)*m+Y)==y) *(display->screen+y*display->max_x+x)=sym;
 
   return D_SUCCESS;
 }
@@ -92,8 +100,9 @@ int display_string(t_display *display,int x,int y,char *string,int len) {
 
 int display_string_vert(t_display *display,int x,int y,char *string,int len) {
 
-  if(len>display->max_y-y) return D_INV_STRING_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++);
 
index ed89a17a167fdaccbaad9498a0393b199a8d4a75..4d89b6333f39e26bd191402f3ef603f4d47488dd 100644 (file)
@@ -3,6 +3,8 @@
 /* includes */
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
 
 /* defines */
 #define D_SUCCESS 1
@@ -25,7 +27,7 @@ typedef struct s_display {
 /* function prototypes */
 int display_init(t_display *display);
 int display_draw(t_display *display);
-int int display_draw_until_line(t_display *display,int line);
+int display_draw_until_line(t_display *display,int line);
 int display_clear_screen(t_display *display);
 int display_shutdown(t_display *display);
 int display_line(t_display *display,int X,int Y,int X_,int Y_,char sym);
index 91676600dfdc02844d7cd66afb42b7dabb8c8a89..55188ec45feba4c12d51d0d39691c696acaa85cd 100644 (file)
@@ -130,13 +130,8 @@ int main(int argc,char **argv) {
   audio_setup(&(ivac.audio));
 
   /* display */
-#ifdef XXX_GUI
-  /* "constant" graphics */
-  ivac_display_head(&ivac);
-  ivac_display_box(&ivac);
-  ivac_display_console(&ivac);
-#endif
   ivac_display(&ivac);
+  ivac_display_draw(&ivac);
 
   /* start event system - callbacks used: ivac_event_cb + ivac_regular_cb */
   event_start(&(ivac.event),(void *)&ivac,ivac_event_cb,ivac_regular_cb);
@@ -279,7 +274,8 @@ int ivac_event_cb(t_event *event,void *ptr) {
       event_math(ivac->net.connection[channel].fd,event,READ,ADD);
       ivac_send_info(channel,ivac);
     }
-    ivac_display(ivac);
+    ivac_display_content(ivac);
+    ivac_display_draw(ivac);
   }
 
   /* wait for user info */
@@ -293,7 +289,8 @@ int ivac_event_cb(t_event *event,void *ptr) {
           sprintf(c_str,"channel %02d: broken pipe - disconnected",channel);
           ivac_add_to_monitor(ivac,c_str);
         }
-        ivac_display(ivac);
+        ivac_display_content(ivac);
+        ivac_display_draw(ivac);
       }
     }
   } 
@@ -459,7 +456,8 @@ int ivac_parse_command(t_input *input,void *ptr) {
     ivac_add_to_monitor(ivac,c_str);
 
     /* refresh whole display content */
-    ivac_display(ivac);
+    ivac_display_content(ivac);
+    ivac_display_draw(ivac);
 
     /* delete content buffer + reset counter */
     memset(input->content,0,input->c_count-1);
@@ -472,25 +470,25 @@ int ivac_parse_command(t_input *input,void *ptr) {
 
 int ivac_display_head(t_ivac *ivac) {
 
-  display_line(&(ivac->display),0,ivac->display.max_x,0,0,'#');
-  display_string(&(ivac->display),(display->max_x-strlen(PROG_NAME))/2,2,
+  display_line(&(ivac->display),0,0,ivac->display.max_x,0,'#');
+  display_string(&(ivac->display),(ivac->display.max_x-strlen(PROG_NAME))/2,1,
                  PROG_NAME,strlen(PROG_NAME));
-  display_line(&(ivac->display),0,ivac->display.max_x,2,2,'#');
+  display_line(&(ivac->display),0,2,ivac->display.max_x,2,'#');
 
   return SUCCESS;
 }
 
-GO ON HERE !!! display stuff
-
 int ivac_display_box(t_ivac *ivac) {
 
-#ifndef XXX_GUI
-  puts("---------------------------------------------------------------------");
+  display_line(&(ivac->display),0,3,ivac->display.max_x,3,'-');
   printf("username: %s, capabilities: %02x|%04x\n",ivac->username,ivac->g_cap,
                                                    ivac->av_cap);
-  puts("---------------------------------------------------------------------");
-  puts("connections:");
-#endif
+  display_line(&(ivac->display),0,5,ivac->display.max_x,5,'-');
+  display_string(&(ivac->display),0,6,"connections:",12);
+  display_line(&(ivac->display),
+               0,ivac->display.max_y-IVAC_PROMPT_LEN-IVAC_CONSOLE_LEN-1,
+               ivac->display.max_x,
+               ivac->display.max_y-IVAC_PROMPT_LEN-IVAC_CONSOLE_LEN-1,'-');
  
   return SUCCESS;
 }
@@ -498,32 +496,34 @@ int ivac_display_box(t_ivac *ivac) {
 int ivac_display_box_content(t_ivac *ivac) {
 
   int channel;
+  char string[MAX_BOX_CHARS];
 
   /* prepare challenger names */
   for(channel=0;channel<MAX_CONNECTIONS;channel++)
     if(ivac->challenger[channel].name[0]==0)
       strcpy(ivac->challenger[channel].name,"<empty>");
 
-#ifndef XXX_GUI
   for(channel=0;channel<MAX_CONNECTIONS;channel++) {
-    if(ivac->net.connection[channel].status&C_INFO_A)
-      printf("channel %02d: %s:%d, status: %02x, name: %s\n",channel,
-             ivac->net.connection[channel].ip,
-             ivac->net.connection[channel].port,
-             ivac->net.connection[channel].status,
-             ivac->challenger[channel].name);
+    if(ivac->net.connection[channel].status&C_INFO_A) {
+      snprintf(string,MAX_BOX_CHARS,
+               "channel %02d: %s:%d, status: %02x, name: %s\n",channel,
+               ivac->net.connection[channel].ip,
+               ivac->net.connection[channel].port,
+               ivac->net.connection[channel].status,
+               ivac->challenger[channel].name);
+      display_string(&(ivac->display),0,IVAC_HEAD_LEN+4+channel,
+                     string,strlen(string));
+    }
   }
-#endif
 
   return SUCCESS;
 }
 
 int ivac_display_console(t_ivac *ivac) {
 
-#ifndef XXX_GUI
-  puts("---------------------------------------------------------------------");
-  puts("console messages:");
-#endif
+  display_string(&(ivac->display),
+                 0,ivac->display.max_y-IVAC_PROMPT_LEN-IVAC_CONSOLE_LEN,
+                 "console messages:",17);
 
   return SUCCESS;
 }
@@ -531,31 +531,43 @@ int ivac_display_console(t_ivac *ivac) {
 int ivac_display_console_content(t_ivac *ivac) {
 
   int i;
+  char string[IVAC_CONSOLE_STRING_LEN];
 
-#ifndef XXX_GUI
-  for(i=0;i<IVAC_CONSOLE_LEN;i++)
-    printf("| %s\n",ivac->console[i]);
-#endif
+  for(i=0;i<IVAC_CONSOLE_LEN;i++) {
+    snprintf(string,IVAC_CONSOLE_STRING_LEN,"%s\n",ivac->console[i]);
+    display_string(&(ivac->display),
+                   0,ivac->display.max_y-IVAC_PROMPT_LEN-IVAC_CONSOLE_LEN+1+i,
+                   string,strlen(string));
+  }
 
   return SUCCESS;
 }
 
 int ivac_display_prompt(t_ivac *ivac) {
 
-#ifndef XXX_GUI
-  puts("---------------------------------------------------------------------");
+  /* simply a printf - dirty! */
   printf("prompt: ");
-#endif
+  fflush(NULL);
 
   return SUCCESS;
 }
 
 int ivac_display_prompt_content(t_ivac *ivac) {
 
-#ifndef XXX_GUI
+  /* simply a printf - dirty! */
   printf("%c",ivac->input.content[ivac->input.c_count-1]);
   fflush(NULL);
-#endif
+
+  return SUCCESS;
+}
+
+int ivac_display_content(t_ivac *ivac) {
+
+  /* display box content */
+  ivac_display_box_content(ivac);
+
+  /* display console content */
+  ivac_display_console_content(ivac);
 
   return SUCCESS;
 }
@@ -564,26 +576,25 @@ int ivac_display(t_ivac *ivac) {
 
   int x,y;
 
-#ifndef XXX_GUI
-  /* display head */
+  /* display static head */
   ivac_display_head(ivac);
 
-  /* display box */
+  /* display static box */
   ivac_display_box(ivac);
-#endif
-  ivac_display_box_content(ivac);
 
-#ifndef XXX_GUI
-  /* display console */
+  /* display static console */
   ivac_display_console(ivac);
-#endif
-  ivac_display_console_content(ivac);
 
-#ifndef XXX_GUI
   /* display command prompt */
   ivac_display_prompt(ivac);
-#endif
-  fflush(NULL);
+
+  return SUCCESS;
+}
+
+int ivac_display_draw(t_ivac *ivac) {
+  
+  display_draw_until_line(&(ivac->display),ivac->display.max_y-1);
+  ivac_display_prompt(ivac);
 
   return SUCCESS;
 }
index d073592633528a207a5bc066ff2a821c6d3d8e62..a25732d1a6650fce0fba14a68f2b41661f6a9d91 100644 (file)
 
 /* defines */
 #define PROG_NAME "ivac -- Copyright (C) 2004 Frank Zirkelbach"
+
 #define CHAR_USERNAME 32
+#define IVAC_CONSOLE_STRING_LEN 64
+#define MAX_BOX_CHARS 64
+
 #define ERROR -1
 #define SUCCESS 1
 
 #define VIDEO (1<<1)
 #define DUPLEX (1<<2)
 
-#define IVAC_CONSOLE_STRING_LEN 64
-
 #define IVAC_HEAD_LEN 3
-#define IVAC_PROMPT_LEN 3
+#define IVAC_PROMPT_LEN 2
 #define IVAC_CONSOLE_LEN 8
 
 #define IVAC_ARG_LEN CHAR_USERNAME
@@ -81,7 +83,9 @@ int ivac_display_console(t_ivac *ivac);
 int ivac_display_console_content(t_ivac *ivac);
 int ivac_display_prompt(t_ivac *ivac);
 int ivac_display_prompt_content(t_ivac *ivac);
+int ivac_display_content(t_ivac *ivac);
 int ivac_display(t_ivac *ivac);
+int ivac_display_draw(t_ivac *ivac);
 int ivac_add_to_monitor(t_ivac *ivac,char *msg);
 
 #endif