From: hackbard Date: Fri, 21 May 2004 18:34:37 +0000 (+0000) Subject: new display stuff, DOESNT WORK!!11 X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=050a55681aaf01024a475eb4e68880040af758bd;p=my-code%2Fivac.git new display stuff, DOESNT WORK!!11 --- diff --git a/src/display.c b/src/display.c index afb2a57..c46c11c 100644 --- a/src/display.c +++ b/src/display.c @@ -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;ymax_y;y++) { for(x=0;xmax_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;xmax_x;x++) { - for(y=0;yscreen+y*display->max_x+x); - printf("\n"); + for(y=0;ymax_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;ymax_y;y++) for(x=0;xmax_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++); diff --git a/src/display.h b/src/display.h index ed89a17..4d89b63 100644 --- a/src/display.h +++ b/src/display.h @@ -3,6 +3,8 @@ /* includes */ #include #include +#include +#include /* 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); diff --git a/src/ivac.c b/src/ivac.c index 9167660..55188ec 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -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;channelchallenger[channel].name[0]==0) strcpy(ivac->challenger[channel].name,""); -#ifndef XXX_GUI for(channel=0;channelnet.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;iconsole[i]); -#endif + for(i=0;iconsole[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; } diff --git a/src/ivac.h b/src/ivac.h index d073592..a25732d 100644 --- a/src/ivac.h +++ b/src/ivac.h @@ -15,7 +15,11 @@ /* 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 @@ -36,10 +40,8 @@ #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