comparison mcabber/src/screen.c @ 168:6ad156673b19

[/trunk] Changeset 180 by mikael * Try to improve screen (re)drawing
author mikael
date Wed, 04 May 2005 18:50:35 +0000
parents a6ac5498d254
children 09e24917059d
comparison
equal deleted inserted replaced
167:a6ac5498d254 168:6ad156673b19
199 tmp->win = newwin(lines, cols, y, x); 199 tmp->win = newwin(lines, cols, y, x);
200 while (!tmp->win) { 200 while (!tmp->win) {
201 usleep(250); 201 usleep(250);
202 tmp->win = newwin(lines, cols, y, x); 202 tmp->win = newwin(lines, cols, y, x);
203 } 203 }
204 wbkgd(tmp->win, COLOR_PAIR(COLOR_GENERAL));
204 tmp->panel = new_panel(tmp->win); 205 tmp->panel = new_panel(tmp->win);
205 tmp->name = (char *) calloc(1, 96); 206 tmp->name = (char *) calloc(1, 96);
206 strncpy(tmp->name, title, 96); 207 strncpy(tmp->name, title, 96);
207 scr_clear_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL);
208 208
209 if (!dont_show) { 209 if (!dont_show) {
210 currentWindow = tmp; 210 currentWindow = tmp;
211 } else { 211 } else {
212 if (currentWindow) 212 if (currentWindow)
248 248
249 width = scr_WindowWidth(win_entry->win); 249 width = scr_WindowWidth(win_entry->win);
250 250
251 // Should the window be empty? 251 // Should the window be empty?
252 if (win_entry->cleared) { 252 if (win_entry->cleared) {
253 scr_clear_box(win_entry->win, 0, 0, CHAT_WIN_HEIGHT, width, COLOR_GENERAL); 253 werase(win_entry->win);
254 return; 254 return;
255 } 255 }
256 256
257 // win_entry->top is the top message of the screen. If it set to NULL, we 257 // win_entry->top is the top message of the screen. If it set to NULL, we
258 // are displaying the last messages. 258 // are displaying the last messages.
275 275
276 // Get the last CHAT_WIN_HEIGHT lines. 276 // Get the last CHAT_WIN_HEIGHT lines.
277 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT); 277 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT);
278 278
279 // Display these lines 279 // Display these lines
280 wmove(win_entry->win, 0, 0);
281 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { 280 for (n = 0; n < CHAT_WIN_HEIGHT; n++) {
282 int r = width; 281 wmove(win_entry->win, n, 0);
283 if (*(lines+2*n)) { 282 if (*(lines+2*n)) {
284 if (**(lines+2*n)) 283 if (**(lines+2*n))
285 wprintw(win_entry->win, "%s", *(lines+2*n)); // prefix 284 wprintw(win_entry->win, "%s", *(lines+2*n)); // prefix
286 else { 285 else {
287 wprintw(win_entry->win, " "); 286 wprintw(win_entry->win, " ");
288 r -= 12;
289 } 287 }
290 wprintw(win_entry->win, "%s", *(lines+2*n+1)); // line 288 wprintw(win_entry->win, "%s", *(lines+2*n+1)); // line
291 // Calculate the number of blank characters to empty the line 289 wclrtoeol(win_entry->win);
292 r -= strlen(*(lines+2*n)) + strlen(*(lines+2*n+1)); 290 } else {
293 } 291 wclrtobot(win_entry->win);
294 for ( ; r>0 ; r--) { 292 break;
295 wprintw(win_entry->win, " "); 293 }
296 }
297 //// wclrtoeol(win_entry->win); does not work :(
298 } 294 }
299 g_free(lines); 295 g_free(lines);
300 } 296 }
301 297
302 // scr_ShowWindow() 298 // scr_ShowWindow()
445 // I think it could be improved a _lot_ but I'm really not an ncurses 441 // I think it could be improved a _lot_ but I'm really not an ncurses
446 // expert... :-\ Mikael. 442 // expert... :-\ Mikael.
447 // 443 //
448 void scr_DrawMainWindow(unsigned int fullinit) 444 void scr_DrawMainWindow(unsigned int fullinit)
449 { 445 {
450 int l;
451
452 if (fullinit) { 446 if (fullinit) {
453 /* Create windows */ 447 /* Create windows */
454 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0); 448 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0);
455 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH); 449 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH);
456 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0); 450 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0);
457 logWnd = newwin(LOG_WIN_HEIGHT-2, maxX-2, CHAT_WIN_HEIGHT+1, 1); 451 logWnd = newwin(LOG_WIN_HEIGHT-2, maxX-2, CHAT_WIN_HEIGHT+1, 1);
458 inputWnd = newwin(1, maxX, maxY-1, 0); 452 inputWnd = newwin(1, maxX, maxY-1, 0);
453 wbkgd(rosterWnd, COLOR_PAIR(COLOR_GENERAL));
454 wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL));
455 wbkgd(logWnd_border, COLOR_PAIR(COLOR_GENERAL));
456 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL));
459 } else { 457 } else {
460 /* Resize windows */ 458 /* Resize windows */
461 wresize(rosterWnd, CHAT_WIN_HEIGHT, ROSTER_WIDTH); 459 wresize(rosterWnd, CHAT_WIN_HEIGHT, ROSTER_WIDTH);
462 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH); 460 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH);
463 461
466 mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0); 464 mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0);
467 mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1); 465 mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1);
468 466
469 wresize(inputWnd, 1, maxX); 467 wresize(inputWnd, 1, maxX);
470 mvwin(inputWnd, maxY-1, 0); 468 mvwin(inputWnd, maxY-1, 0);
469
470 werase(chatWnd);
471 } 471 }
472 472
473 /* Draw/init windows */ 473 /* Draw/init windows */
474 474
475 // - Clear roster and draw vertical line
476 scr_clear_box(rosterWnd, 0, 0, CHAT_WIN_HEIGHT, ROSTER_WIDTH,
477 COLOR_GENERAL);
478 for (l=0 ; l < CHAT_WIN_HEIGHT ; l++)
479 mvwaddch(rosterWnd, l, ROSTER_WIDTH-1, ACS_VLINE);
480
481 // - Clear chat window
482 scr_clear_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH,
483 COLOR_GENERAL);
484 mvwprintw(chatWnd, 0, 0, "This is the status window"); 475 mvwprintw(chatWnd, 0, 0, "This is the status window");
485 476
486 // - Draw/clear the log window 477 // - Draw/clear the log window
487 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0); 478 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0);
488 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL));
489 // Auto-scrolling in log window 479 // Auto-scrolling in log window
490 scrollok(logWnd, TRUE); 480 scrollok(logWnd, TRUE);
491 481
492 482
493 if (fullinit) { 483 if (fullinit) {
543 list_for_each_safe(pos, n, &window_list) { 533 list_for_each_safe(pos, n, &window_list) {
544 search_entry = window_entry(pos); 534 search_entry = window_entry(pos);
545 if (search_entry->win) { 535 if (search_entry->win) {
546 // Resize buddy window (no need to move it) 536 // Resize buddy window (no need to move it)
547 wresize(search_entry->win, lines, cols); 537 wresize(search_entry->win, lines, cols);
548 scr_clear_box(search_entry->win, 0, 0, lines, cols, COLOR_GENERAL); 538 werase(search_entry->win);
549 // If a panel exists, replace the old window with the new 539 // If a panel exists, replace the old window with the new
550 if (search_entry->panel) { 540 if (search_entry->panel) {
551 replace_panel(search_entry->panel, search_entry->win); 541 replace_panel(search_entry->panel, search_entry->win);
552 } 542 }
553 // Redo line wrapping 543 // Redo line wrapping
579 getmaxyx(rosterWnd, maxy, maxx); 569 getmaxyx(rosterWnd, maxy, maxx);
580 maxx --; // last char is for vertical border 570 maxx --; // last char is for vertical border
581 name[ROSTER_WIDTH-7] = 0; 571 name[ROSTER_WIDTH-7] = 0;
582 572
583 // cleanup of roster window 573 // cleanup of roster window
574 werase(rosterWnd);
575 // Redraw the vertical line (not very good...)
584 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); 576 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL));
585 for (i = 0; i < maxy; i++) { 577 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++)
586 mvwprintw(rosterWnd, i, 0, ""); 578 mvwaddch(rosterWnd, i, ROSTER_WIDTH-1, ACS_VLINE);
587 for (n = 0; n < maxx; n++)
588 waddch(rosterWnd, ' ');
589 }
590 579
591 // Leave now if buddylist is empty 580 // Leave now if buddylist is empty
592 if (!buddylist) { 581 if (!buddylist) {
593 offset = 0; 582 offset = 0;
594 update_panels(); 583 update_panels();