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))
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");
}
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;
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;
}
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;
}
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++);
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);
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 */
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);
}
}
}
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);
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;
}
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;
}
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;
}
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;
}