[BACK]Return to screen-redraw.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/screen-redraw.c, Revision 1.6

1.6     ! nicm        1: /* $OpenBSD: screen-redraw.c,v 1.5 2009/07/14 19:11:58 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
                     15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                     16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18:
                     19: #include <sys/types.h>
                     20:
                     21: #include <string.h>
                     22:
                     23: #include "tmux.h"
                     24:
                     25: int    screen_redraw_check_cell(struct client *, u_int, u_int);
                     26:
1.6     ! nicm       27: #define CELL_INSIDE 0
        !            28: #define CELL_LEFT 1
        !            29: #define CELL_RIGHT 2
        !            30: #define CELL_TOP 3
        !            31: #define CELL_BOTTOM 4
        !            32: #define CELL_OUTSIDE 5
        !            33:
1.1       nicm       34: /* Check if cell inside a pane. */
                     35: int
                     36: screen_redraw_check_cell(struct client *c, u_int px, u_int py)
                     37: {
                     38:        struct window           *w = c->session->curw->window;
                     39:        struct window_pane      *wp;
                     40:
                     41:        if (px > w->sx || py > w->sy)
1.6     ! nicm       42:                return (CELL_OUTSIDE);
1.1       nicm       43:
                     44:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.3       nicm       45:                if (!window_pane_visible(wp))
                     46:                        continue;
                     47:
1.1       nicm       48:                /* Inside pane. */
                     49:                if (px >= wp->xoff && px < wp->xoff + wp->sx &&
                     50:                    py >= wp->yoff && py < wp->yoff + wp->sy)
1.6     ! nicm       51:                        return (CELL_INSIDE);
1.1       nicm       52:
                     53:                /* Left/right borders. */
                     54:                if (py >= wp->yoff && py < wp->yoff + wp->sy) {
                     55:                        if (wp->xoff != 0 && px == wp->xoff - 1)
1.6     ! nicm       56:                                return (CELL_LEFT);
1.1       nicm       57:                        if (px == wp->xoff + wp->sx)
1.6     ! nicm       58:                                return (CELL_RIGHT);
1.1       nicm       59:                }
                     60:
                     61:                /* Top/bottom borders. */
                     62:                if (px >= wp->xoff && px < wp->xoff + wp->sx) {
                     63:                        if (wp->yoff != 0 && py == wp->yoff - 1)
1.6     ! nicm       64:                                return (CELL_TOP);
1.1       nicm       65:                        if (py == wp->yoff + wp->sy)
1.6     ! nicm       66:                                return (CELL_BOTTOM);
1.1       nicm       67:                }
                     68:        }
                     69:
1.6     ! nicm       70:        return (CELL_OUTSIDE);
1.1       nicm       71: }
                     72:
1.4       nicm       73: /* Redraw entire screen. */
1.1       nicm       74: void
1.4       nicm       75: screen_redraw_screen(struct client *c, int status_only)
1.1       nicm       76: {
                     77:        struct window           *w = c->session->curw->window;
                     78:        struct tty              *tty = &c->tty;
                     79:        struct window_pane      *wp;
1.6     ! nicm       80:        u_int                    i, j, type;
        !            81:        int                      status;
        !            82:        const u_char            *border;
1.1       nicm       83:
                     84:        /* Get status line, er, status. */
1.4       nicm       85:        if (c->message_string != NULL || c->prompt_string != NULL)
                     86:                status = 1;
                     87:        else
                     88:                status = options_get_number(&c->session->options, "status");
                     89:
                     90:        /* If only drawing status and it is present, don't need the rest. */
                     91:        if (status_only && status) {
                     92:                tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1);
                     93:                return;
                     94:        }
1.1       nicm       95:
1.6     ! nicm       96:        /* Draw background and borders. */
        !            97:        tty_reset(tty);
1.1       nicm       98:        if (tty_term_has(tty->term, TTYC_ACSC)) {
1.6     ! nicm       99:                border = " xxqq~";
1.1       nicm      100:                tty_putcode(tty, TTYC_SMACS);
1.6     ! nicm      101:        } else
        !           102:                border = " ||--.";
1.1       nicm      103:        for (j = 0; j < tty->sy - status; j++) {
1.4       nicm      104:                if (status_only && j != tty->sy - 1)
                    105:                        continue;
1.1       nicm      106:                for (i = 0; i < tty->sx; i++) {
1.6     ! nicm      107:                        type = screen_redraw_check_cell(c, i, j);
        !           108:                        if (type != CELL_INSIDE) {
1.1       nicm      109:                                tty_cursor(tty, i, j, 0, 0);
1.6     ! nicm      110:                                tty_putc(tty, border[type]);
1.1       nicm      111:                        }
                    112:                }
                    113:        }
1.6     ! nicm      114:        tty_putcode(tty, TTYC_RMACS);
1.1       nicm      115:
                    116:        /* Draw the panes. */
                    117:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.3       nicm      118:                if (!window_pane_visible(wp))
1.1       nicm      119:                        continue;
1.4       nicm      120:                for (i = 0; i < wp->sy; i++) {
1.5       nicm      121:                        if (status_only && wp->yoff + i != tty->sy - 1)
1.4       nicm      122:                                continue;
                    123:                        tty_draw_line(tty, wp->screen, i, wp->xoff, wp->yoff);
                    124:                }
1.1       nicm      125:        }
                    126:
                    127:        /* Draw the status line. */
1.4       nicm      128:        if (status)
                    129:                tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1);
1.1       nicm      130: }
                    131:
                    132: /* Draw a single pane. */
                    133: void
                    134: screen_redraw_pane(struct client *c, struct window_pane *wp)
                    135: {
                    136:        u_int   i;
                    137:
                    138:        for (i = 0; i < wp->sy; i++)
                    139:                tty_draw_line(&c->tty, wp->screen, i, wp->xoff, wp->yoff);
                    140: }