[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.3

1.3     ! nicm        1: /* $OpenBSD: screen-redraw.c,v 1.2 2009/06/25 05:56:44 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:
                     27: /* Check if cell inside a pane. */
                     28: int
                     29: screen_redraw_check_cell(struct client *c, u_int px, u_int py)
                     30: {
                     31:        struct window           *w = c->session->curw->window;
                     32:        struct window_pane      *wp;
                     33:
                     34:        if (px > w->sx || py > w->sy)
                     35:                return (0);
                     36:
                     37:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.3     ! nicm       38:                if (!window_pane_visible(wp))
        !            39:                        continue;
        !            40:
1.1       nicm       41:                /* Inside pane. */
                     42:                if (px >= wp->xoff && px < wp->xoff + wp->sx &&
                     43:                    py >= wp->yoff && py < wp->yoff + wp->sy)
                     44:                        return (1);
                     45:
                     46:                /* Left/right borders. */
                     47:                if (py >= wp->yoff && py < wp->yoff + wp->sy) {
                     48:                        if (wp->xoff != 0 && px == wp->xoff - 1)
                     49:                                return (1);
                     50:                        if (px == wp->xoff + wp->sx)
                     51:                                return (1);
                     52:                }
                     53:
                     54:                /* Top/bottom borders. */
                     55:                if (px >= wp->xoff && px < wp->xoff + wp->sx) {
                     56:                        if (wp->yoff != 0 && py == wp->yoff - 1)
                     57:                                return (1);
                     58:                        if (py == wp->yoff + wp->sy)
                     59:                                return (1);
                     60:                }
                     61:        }
                     62:
                     63:        return (0);
                     64: }
                     65:
                     66: /* Redraw entire screen.. */
                     67: void
                     68: screen_redraw_screen(struct client *c)
                     69: {
                     70:        struct window           *w = c->session->curw->window;
                     71:        struct tty              *tty = &c->tty;
                     72:        struct window_pane      *wp;
                     73:        u_int                    i, j, sx, sy;
                     74:        int                      status, has_acs;
                     75:        u_char                   choriz, cvert, cbackg;
                     76:
                     77:        /* Get status line, er, status. */
                     78:        status = options_get_number(&c->session->options, "status");
                     79:
                     80:        /* Work out ACS characters. */
                     81:        if (tty_term_has(tty->term, TTYC_ACSC)) {
                     82:                has_acs = 1;
                     83:                choriz = tty_get_acs(tty, 'q');
                     84:                cvert = tty_get_acs(tty, 'x');
                     85:                cbackg = tty_get_acs(tty, '~');
                     86:        } else {
                     87:                has_acs = 0;
                     88:                choriz = '-';
                     89:                cvert = '|';
                     90:                cbackg = '.';
                     91:        }
                     92:
                     93:        /* Clear the screen. */
                     94:        tty_reset(tty);
                     95:        if (has_acs)
                     96:                tty_putcode(tty, TTYC_SMACS);
                     97:        for (j = 0; j < tty->sy - status; j++) {
                     98:                for (i = 0; i < tty->sx; i++) {
                     99:                        if (!screen_redraw_check_cell(c, i, j)) {
                    100:                                tty_cursor(tty, i, j, 0, 0);
                    101:                                tty_putc(tty, cbackg);
                    102:                        }
                    103:                }
                    104:        }
                    105:        if (has_acs)
                    106:                tty_putcode(tty, TTYC_RMACS);
                    107:
                    108:        /* Draw the panes. */
                    109:        TAILQ_FOREACH(wp, &w->panes, entry) {
1.3     ! nicm      110:                if (!window_pane_visible(wp))
1.1       nicm      111:                        continue;
                    112:
                    113:                tty_reset(tty);
                    114:
                    115:                sx = wp->sx;
                    116:                sy = wp->sy;
                    117:
                    118:                /* Draw left and right borders. */
                    119:                if (has_acs)
                    120:                        tty_putcode(tty, TTYC_SMACS);
                    121:                if (wp->xoff > 0) {
                    122:                        for (i = wp->yoff; i < wp->yoff + sy; i++) {
                    123:                                tty_cursor(tty, wp->xoff - 1, i, 0, 0);
                    124:                                tty_putc(tty, cvert);
                    125:                        }
                    126:                }
                    127:                if (wp->xoff + sx < tty->sx) {
                    128:                        for (i = wp->yoff; i < wp->yoff + sy; i++) {
                    129:                                tty_cursor(tty, wp->xoff + sx, i, 0, 0);
                    130:                                tty_putc(&c->tty, cvert);
                    131:                        }
                    132:                }
                    133:
                    134:                /* Draw top and bottom borders. */
                    135:                if (wp->yoff > 0) {
                    136:                        tty_cursor(tty, wp->xoff, wp->yoff - 1, 0, 0);
                    137:                        for (i = 0; i < sx; i++)
                    138:                                tty_putc(tty, choriz);
                    139:                }
                    140:                if (wp->yoff + sy < tty->sy - status) {
                    141:                        tty_cursor(tty, wp->xoff, wp->yoff + sy, 0, 0);
                    142:                        for (i = 0; i < sx; i++)
                    143:                                tty_putc(tty, choriz);
                    144:                }
                    145:                if (has_acs)
                    146:                        tty_putcode(tty, TTYC_RMACS);
                    147:
                    148:                /* Draw the pane. */
                    149:                screen_redraw_pane(c, wp);
                    150:        }
                    151:
                    152:        /* Draw the status line. */
                    153:        screen_redraw_status(c);
                    154: }
                    155:
                    156: /* Draw a single pane. */
                    157: void
                    158: screen_redraw_pane(struct client *c, struct window_pane *wp)
                    159: {
                    160:        u_int   i;
                    161:
                    162:        for (i = 0; i < wp->sy; i++)
                    163:                tty_draw_line(&c->tty, wp->screen, i, wp->xoff, wp->yoff);
                    164: }
                    165:
                    166:
                    167: /* Draw the status line. */
                    168: void
                    169: screen_redraw_status(struct client *c)
                    170: {
                    171:        tty_draw_line(&c->tty, &c->status, 0, 0, c->tty.sy - 1);
                    172: }