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

Annotation of src/usr.bin/tmux/grid-view.c, Revision 1.3

1.3     ! nicm        1: /* $OpenBSD: grid-view.c,v 1.2 2009/06/24 22:04:18 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2008 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: /*
                     26:  * Grid view functions. These work using coordinates relative to the visible
                     27:  * screen area.
                     28:  */
                     29:
                     30: #define grid_view_x(gd, x) (x)
                     31: #define grid_view_y(gd, y) ((gd)->hsize + (y))
                     32:
                     33: /* Get cell for reading. */
                     34: const struct grid_cell *
                     35: grid_view_peek_cell(struct grid *gd, u_int px, u_int py)
                     36: {
                     37:        return (grid_peek_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
                     38: }
                     39:
                     40: /* Get cell for writing. */
                     41: struct grid_cell *
                     42: grid_view_get_cell(struct grid *gd, u_int px, u_int py)
                     43: {
                     44:        return (grid_get_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
                     45: }
                     46:
                     47: /* Set cell. */
                     48: void
                     49: grid_view_set_cell(
                     50:     struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
                     51: {
                     52:        grid_set_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc);
                     53: }
                     54:
                     55: /* Get UTF-8 for reading. */
                     56: const struct grid_utf8 *
                     57: grid_view_peek_utf8(struct grid *gd, u_int px, u_int py)
                     58: {
                     59:        return (grid_peek_utf8(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
                     60: }
                     61:
                     62: /* Get UTF-8 for writing. */
                     63: struct grid_utf8 *
                     64: grid_view_get_utf8(struct grid *gd, u_int px, u_int py)
                     65: {
                     66:        return (grid_get_utf8(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
                     67: }
                     68:
                     69: /* Set UTF-8. */
                     70: void
                     71: grid_view_set_utf8(
                     72:     struct grid *gd, u_int px, u_int py, const struct grid_utf8 *gu)
                     73: {
                     74:        grid_set_utf8(gd, grid_view_x(gd, px), grid_view_y(gd, py), gu);
                     75: }
                     76:
                     77: /* Clear area. */
                     78: void
                     79: grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny)
                     80: {
                     81:        GRID_DEBUG(gd, "px=%u, py=%u, nx=%u, ny=%u", px, py, nx, ny);
                     82:
                     83:        px = grid_view_x(gd, px);
                     84:        py = grid_view_y(gd, py);
                     85:
                     86:        grid_clear(gd, px, py, nx, ny);
                     87: }
                     88:
                     89: /* Scroll region up. */
                     90: void
                     91: grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
                     92: {
                     93:        GRID_DEBUG(gd, "rupper=%u, rlower=%u", rupper, rlower);
                     94:
                     95:        if (rupper == 0 && rlower == gd->sy - 1) {
                     96:                grid_scroll_line(gd);
                     97:                return;
                     98:        }
                     99:
                    100:        rupper = grid_view_y(gd, rupper);
                    101:        rlower = grid_view_y(gd, rlower);
                    102:
                    103:        grid_move_lines(gd, rupper, rupper + 1, rlower - rupper);
                    104: }
                    105:
                    106: /* Scroll region down. */
                    107: void
                    108: grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower)
                    109: {
                    110:        GRID_DEBUG(gd, "rupper=%u, rlower=%u", rupper, rlower);
                    111:
                    112:        rupper = grid_view_y(gd, rupper);
                    113:        rlower = grid_view_y(gd, rlower);
                    114:
                    115:        grid_move_lines(gd, rupper + 1, rupper, rlower - rupper);
                    116: }
                    117:
                    118: /* Insert lines. */
                    119: void
                    120: grid_view_insert_lines(struct grid *gd, u_int py, u_int ny)
                    121: {
                    122:        u_int   sy;
                    123:
                    124:        GRID_DEBUG(gd, "py=%u, ny=%u", py, ny);
                    125:
                    126:        py = grid_view_y(gd, py);
                    127:
                    128:        sy = grid_view_y(gd, gd->sy);
                    129:
                    130:        grid_move_lines(gd, py + ny, py, sy - py - ny);
                    131: }
                    132:
                    133: /* Insert lines in region. */
                    134: void
                    135: grid_view_insert_lines_region(
                    136:     struct grid *gd, unused u_int rupper, u_int rlower, u_int py, u_int ny)
                    137: {
                    138:        GRID_DEBUG(
                    139:            gd, "rupper=%u, rlower=%u, py=%u, ny=%u", rupper, rlower, py, ny);
                    140:
                    141:        rlower = grid_view_y(gd, rlower);
                    142:
                    143:        py = grid_view_y(gd, py);
                    144:
                    145:        grid_move_lines(gd, py + ny, py, (rlower + 1) - py - ny);
                    146: }
                    147:
                    148: /* Delete lines. */
                    149: void
                    150: grid_view_delete_lines(struct grid *gd, u_int py, u_int ny)
                    151: {
                    152:        u_int   sy;
                    153:
                    154:        GRID_DEBUG(gd, "py=%u, ny=%u", py, ny);
                    155:
                    156:        py = grid_view_y(gd, py);
                    157:
                    158:        sy = grid_view_y(gd, gd->sy);
                    159:
                    160:        grid_move_lines(gd, py, py + ny, sy - py - ny);
1.3     ! nicm      161:        grid_clear(gd, 0, sy - ny, gd->sx, py + ny - (sy - ny));
1.1       nicm      162: }
                    163:
                    164: /* Delete lines inside scroll region. */
                    165: void
                    166: grid_view_delete_lines_region(
                    167:     struct grid *gd, unused u_int rupper, u_int rlower, u_int py, u_int ny)
                    168: {
                    169:        GRID_DEBUG(
                    170:            gd, "rupper=%u, rlower=%u, py=%u, ny=%u", rupper, rlower, py, ny);
                    171:
                    172:        rlower = grid_view_y(gd, rlower);
                    173:
                    174:        py = grid_view_y(gd, py);
                    175:
                    176:        grid_move_lines(gd, py, py + ny, (rlower + 1) - py - ny);
                    177: }
                    178:
                    179: /* Insert characters. */
                    180: void
                    181: grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx)
                    182: {
                    183:        u_int   sx;
                    184:
                    185:        GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
                    186:
                    187:        px = grid_view_x(gd, px);
                    188:        py = grid_view_y(gd, py);
                    189:
                    190:        sx = grid_view_x(gd, gd->sx);
                    191:
                    192:        if (px == sx - 1)
                    193:                grid_clear(gd, px, py, 1, 1);
                    194:        else
1.3     ! nicm      195:                grid_move_cells(gd, px + nx, px, py, sx - px - nx);
1.1       nicm      196: }
                    197:
                    198: /* Delete characters. */
                    199: void
                    200: grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx)
                    201: {
                    202:        u_int   sx;
                    203:
                    204:        GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
                    205:
                    206:        px = grid_view_x(gd, px);
                    207:        py = grid_view_y(gd, py);
                    208:
                    209:        sx = grid_view_x(gd, gd->sx);
                    210:
1.3     ! nicm      211:        grid_move_cells(gd, px, px + nx, py, sx - px - nx);
        !           212:        grid_clear(gd, sx - nx, py, px + nx - (sx - nx), 1);
1.2       nicm      213: }
                    214:
                    215: /* Convert cells into a string. */
                    216: char *
                    217: grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
                    218: {
                    219:        GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
                    220:
                    221:        px = grid_view_x(gd, px);
                    222:        py = grid_view_y(gd, py);
                    223:
                    224:        return (grid_string_cells(gd, px, py, nx));
1.1       nicm      225: }