2007-11-23 13:02:45 +00:00
|
|
|
/* $Id: screen.c,v 1.42 2007-11-23 13:02:45 nicm Exp $ */
|
2007-07-09 19:04:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
2007-11-21 13:11:41 +00:00
|
|
|
* Virtual screen.
|
2007-07-09 19:04:12 +00:00
|
|
|
*/
|
|
|
|
|
2007-10-12 13:51:44 +00:00
|
|
|
/* Colour to string. */
|
|
|
|
const char *
|
|
|
|
screen_colourstring(u_char c)
|
|
|
|
{
|
|
|
|
switch (c) {
|
|
|
|
case 0:
|
|
|
|
return ("black");
|
|
|
|
case 1:
|
|
|
|
return ("red");
|
|
|
|
case 2:
|
|
|
|
return ("green");
|
|
|
|
case 3:
|
|
|
|
return ("yellow");
|
|
|
|
case 4:
|
|
|
|
return ("blue");
|
|
|
|
case 5:
|
|
|
|
return ("magenta");
|
|
|
|
case 6:
|
|
|
|
return ("cyan");
|
|
|
|
case 7:
|
|
|
|
return ("white");
|
|
|
|
case 8:
|
|
|
|
return ("default");
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* String to colour. */
|
|
|
|
u_char
|
|
|
|
screen_stringcolour(const char *s)
|
|
|
|
{
|
|
|
|
if (strcasecmp(s, "black") == 0 || (s[0] == '0' && s[1] == '\0'))
|
|
|
|
return (0);
|
|
|
|
if (strcasecmp(s, "red") == 0 || (s[0] == '1' && s[1] == '\0'))
|
|
|
|
return (1);
|
|
|
|
if (strcasecmp(s, "green") == 0 || (s[0] == '2' && s[1] == '\0'))
|
|
|
|
return (2);
|
|
|
|
if (strcasecmp(s, "yellow") == 0 || (s[0] == '3' && s[1] == '\0'))
|
|
|
|
return (3);
|
|
|
|
if (strcasecmp(s, "blue") == 0 || (s[0] == '4' && s[1] == '\0'))
|
|
|
|
return (4);
|
|
|
|
if (strcasecmp(s, "magenta") == 0 || (s[0] == '5' && s[1] == '\0'))
|
|
|
|
return (5);
|
|
|
|
if (strcasecmp(s, "cyan") == 0 || (s[0] == '6' && s[1] == '\0'))
|
|
|
|
return (6);
|
|
|
|
if (strcasecmp(s, "white") == 0 || (s[0] == '7' && s[1] == '\0'))
|
|
|
|
return (7);
|
|
|
|
if (strcasecmp(s, "default") == 0 || (s[0] == '8' && s[1] == '\0'))
|
|
|
|
return (8);
|
|
|
|
return (255);
|
|
|
|
}
|
|
|
|
|
2007-07-09 19:04:12 +00:00
|
|
|
/* Create a new screen. */
|
|
|
|
void
|
2007-11-20 21:42:29 +00:00
|
|
|
screen_create(struct screen *s, u_int dx, u_int dy)
|
2007-07-09 19:04:12 +00:00
|
|
|
{
|
2007-11-20 21:42:29 +00:00
|
|
|
s->dx = dx;
|
|
|
|
s->dy = dy;
|
2007-07-09 19:04:12 +00:00
|
|
|
s->cx = 0;
|
|
|
|
s->cy = 0;
|
|
|
|
|
2007-11-20 18:46:32 +00:00
|
|
|
s->rupper = 0;
|
2007-11-20 21:42:29 +00:00
|
|
|
s->rlower = s->dy - 1;
|
|
|
|
|
2007-11-21 13:11:41 +00:00
|
|
|
s->hsize = 0;
|
2007-11-23 12:48:20 +00:00
|
|
|
s->hlimit = history_limit;
|
2007-07-09 19:04:12 +00:00
|
|
|
|
|
|
|
s->attr = SCREEN_DEFATTR;
|
|
|
|
s->colr = SCREEN_DEFCOLR;
|
|
|
|
|
|
|
|
s->mode = MODE_CURSOR;
|
|
|
|
*s->title = '\0';
|
|
|
|
|
2007-11-20 21:42:29 +00:00
|
|
|
s->grid_data = xmalloc(dy * (sizeof *s->grid_data));
|
|
|
|
s->grid_attr = xmalloc(dy * (sizeof *s->grid_attr));
|
|
|
|
s->grid_colr = xmalloc(dy * (sizeof *s->grid_colr));
|
2007-11-21 15:35:53 +00:00
|
|
|
s->grid_size = xmalloc(dy * (sizeof *s->grid_size));
|
2007-11-20 21:42:29 +00:00
|
|
|
screen_make_lines(s, 0, dy);
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize screen. */
|
|
|
|
void
|
|
|
|
screen_resize(struct screen *s, u_int sx, u_int sy)
|
|
|
|
{
|
2007-11-22 18:09:43 +00:00
|
|
|
u_int i, ox, oy, ny, my;
|
2007-09-21 18:00:58 +00:00
|
|
|
|
2007-07-09 19:04:12 +00:00
|
|
|
if (sx < 1)
|
|
|
|
sx = 1;
|
|
|
|
if (sy < 1)
|
|
|
|
sy = 1;
|
|
|
|
|
2007-11-20 21:42:29 +00:00
|
|
|
ox = s->dx;
|
|
|
|
oy = s->dy;
|
2007-11-21 13:11:41 +00:00
|
|
|
if (sx == ox && sy == oy)
|
|
|
|
return;
|
2007-10-04 19:22:26 +00:00
|
|
|
|
2007-11-21 13:11:41 +00:00
|
|
|
/*
|
|
|
|
* X dimension.
|
|
|
|
*/
|
2007-07-09 19:04:12 +00:00
|
|
|
if (sx != ox) {
|
2007-11-22 19:26:20 +00:00
|
|
|
/*
|
|
|
|
* If getting smaller, nuke any data in lines over the new
|
|
|
|
* size.
|
|
|
|
*/
|
2007-11-22 18:09:43 +00:00
|
|
|
if (sx < ox) {
|
|
|
|
for (i = s->hsize; i < s->hsize + oy; i++) {
|
|
|
|
if (s->grid_size[i] > sx)
|
|
|
|
screen_reduce_line(s, i, sx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-09 19:04:12 +00:00
|
|
|
if (s->cx >= sx)
|
|
|
|
s->cx = sx - 1;
|
2007-11-21 13:11:41 +00:00
|
|
|
s->dx = sx;
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
2007-11-21 13:11:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Y dimension.
|
|
|
|
*/
|
|
|
|
if (sy == oy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Size decreasing. */
|
|
|
|
if (sy < oy) {
|
|
|
|
ny = oy - sy;
|
|
|
|
if (s->cy != 0) {
|
|
|
|
/*
|
|
|
|
* The cursor is not at the start. Try to remove as
|
2007-11-21 14:55:31 +00:00
|
|
|
* many lines as possible from the top. (Up to the
|
|
|
|
* cursor line.)
|
2007-11-21 13:11:41 +00:00
|
|
|
*/
|
|
|
|
my = s->cy;
|
|
|
|
if (my > ny)
|
|
|
|
my = ny;
|
|
|
|
|
2007-11-21 14:30:15 +00:00
|
|
|
screen_free_lines(s, s->hsize, my);
|
2007-11-21 14:55:31 +00:00
|
|
|
screen_move_lines(s, s->hsize, s->hsize + my, oy - my);
|
|
|
|
|
2007-11-21 13:11:41 +00:00
|
|
|
s->cy -= my;
|
|
|
|
oy -= my;
|
|
|
|
}
|
|
|
|
|
|
|
|
ny = oy - sy;
|
|
|
|
if (ny > 0) {
|
|
|
|
/*
|
|
|
|
* Remove any remaining lines from the bottom.
|
|
|
|
*/
|
2007-11-21 14:30:15 +00:00
|
|
|
screen_free_lines(s, s->hsize + oy - ny, ny);
|
2007-11-21 13:11:41 +00:00
|
|
|
if (s->cy >= sy)
|
|
|
|
s->cy = sy - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize line arrays. */
|
|
|
|
ny = s->hsize + sy;
|
|
|
|
s->grid_data = xrealloc(s->grid_data, ny, sizeof *s->grid_data);
|
|
|
|
s->grid_attr = xrealloc(s->grid_attr, ny, sizeof *s->grid_attr);
|
|
|
|
s->grid_colr = xrealloc(s->grid_colr, ny, sizeof *s->grid_colr);
|
2007-11-21 15:35:53 +00:00
|
|
|
s->grid_size = xrealloc(s->grid_size, ny, sizeof *s->grid_size);
|
2007-11-21 13:11:41 +00:00
|
|
|
s->dy = sy;
|
|
|
|
|
|
|
|
/* Size increasing. */
|
|
|
|
if (sy > oy)
|
2007-11-21 14:30:15 +00:00
|
|
|
screen_make_lines(s, s->hsize + oy, sy - oy);
|
2007-11-21 13:11:41 +00:00
|
|
|
|
|
|
|
s->rupper = 0;
|
|
|
|
s->rlower = s->dy - 1;
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
|
2007-11-21 22:20:44 +00:00
|
|
|
/* Expand line. */
|
|
|
|
void
|
|
|
|
screen_expand_line(struct screen *s, u_int py, u_int nx)
|
|
|
|
{
|
|
|
|
u_int ox;
|
|
|
|
|
|
|
|
ox = s->grid_size[py];
|
|
|
|
s->grid_size[py] = nx;
|
|
|
|
|
|
|
|
s->grid_data[py] = xrealloc(s->grid_data[py], 1, nx);
|
|
|
|
memset(&s->grid_data[py][ox], SCREEN_DEFDATA, nx - ox);
|
|
|
|
s->grid_attr[py] = xrealloc(s->grid_attr[py], 1, nx);
|
|
|
|
memset(&s->grid_attr[py][ox], SCREEN_DEFATTR, nx - ox);
|
|
|
|
s->grid_colr[py] = xrealloc(s->grid_colr[py], 1, nx);
|
|
|
|
memset(&s->grid_colr[py][ox], SCREEN_DEFCOLR, nx - ox);
|
|
|
|
}
|
|
|
|
|
2007-11-22 18:09:43 +00:00
|
|
|
/* Reduce line. */
|
|
|
|
void
|
|
|
|
screen_reduce_line(struct screen *s, u_int py, u_int nx)
|
|
|
|
{
|
|
|
|
s->grid_size[py] = nx;
|
|
|
|
|
|
|
|
s->grid_data[py] = xrealloc(s->grid_data[py], 1, nx);
|
|
|
|
s->grid_attr[py] = xrealloc(s->grid_attr[py], 1, nx);
|
|
|
|
s->grid_colr[py] = xrealloc(s->grid_colr[py], 1, nx);
|
|
|
|
}
|
|
|
|
|
2007-11-21 22:20:44 +00:00
|
|
|
/* Get cell. */
|
|
|
|
void
|
|
|
|
screen_get_cell(struct screen *s,
|
|
|
|
u_int cx, u_int cy, u_char *data, u_char *attr, u_char *colr)
|
|
|
|
{
|
|
|
|
if (cx >= s->grid_size[cy]) {
|
|
|
|
*data = SCREEN_DEFDATA;
|
|
|
|
*attr = SCREEN_DEFATTR;
|
|
|
|
*colr = SCREEN_DEFCOLR;
|
|
|
|
} else {
|
|
|
|
*data = s->grid_data[cy][cx];
|
|
|
|
*attr = s->grid_attr[cy][cx];
|
|
|
|
*colr = s->grid_colr[cy][cx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a cell. */
|
|
|
|
void
|
|
|
|
screen_set_cell(struct screen *s,
|
|
|
|
u_int cx, u_int cy, u_char data, u_char attr, u_char colr)
|
|
|
|
{
|
|
|
|
if (cx >= s->grid_size[cy]) {
|
|
|
|
if (data == SCREEN_DEFDATA &&
|
|
|
|
attr == SCREEN_DEFATTR && colr == SCREEN_DEFCOLR)
|
|
|
|
return;
|
|
|
|
screen_expand_line(s, cy, cx + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->grid_data[cy][cx] = data;
|
|
|
|
s->grid_attr[cy][cx] = attr;
|
|
|
|
s->grid_colr[cy][cx] = colr;
|
|
|
|
}
|
|
|
|
|
2007-10-01 14:15:48 +00:00
|
|
|
/* Destroy a screen. */
|
|
|
|
void
|
|
|
|
screen_destroy(struct screen *s)
|
|
|
|
{
|
2007-11-21 21:28:58 +00:00
|
|
|
screen_free_lines(s, 0, s->dy + s->hsize);
|
2007-10-01 14:15:48 +00:00
|
|
|
xfree(s->grid_data);
|
|
|
|
xfree(s->grid_attr);
|
|
|
|
xfree(s->grid_colr);
|
2007-11-21 15:35:53 +00:00
|
|
|
xfree(s->grid_size);
|
2007-10-01 14:15:48 +00:00
|
|
|
}
|
|
|
|
|
2007-11-21 18:24:49 +00:00
|
|
|
/* Initialise drawing. */
|
2007-07-09 19:04:12 +00:00
|
|
|
void
|
2007-11-21 18:24:49 +00:00
|
|
|
screen_draw_start(struct screen_draw_ctx *ctx,
|
|
|
|
struct screen *s, struct buffer *b, u_int ox, u_int oy)
|
2007-07-09 19:04:12 +00:00
|
|
|
{
|
2007-11-21 18:24:49 +00:00
|
|
|
ctx->s = s;
|
|
|
|
ctx->b = b;
|
2007-07-09 19:04:12 +00:00
|
|
|
|
2007-11-21 18:24:49 +00:00
|
|
|
ctx->ox = ox;
|
|
|
|
ctx->oy = oy;
|
|
|
|
|
|
|
|
ctx->cx = s->cx;
|
|
|
|
ctx->cy = s->cy;
|
|
|
|
|
2007-11-23 13:02:45 +00:00
|
|
|
ctx->sel.flag = 0;
|
2007-11-22 19:17:01 +00:00
|
|
|
|
2007-11-21 18:24:49 +00:00
|
|
|
ctx->attr = s->attr;
|
|
|
|
ctx->colr = s->colr;
|
|
|
|
|
|
|
|
input_store_two(b, CODE_SCROLLREGION, 1, screen_size_y(s));
|
2007-11-22 18:09:43 +00:00
|
|
|
input_store_zero(b, CODE_CURSOROFF);
|
2007-11-21 18:24:49 +00:00
|
|
|
}
|
|
|
|
|
2007-11-22 19:40:17 +00:00
|
|
|
/* Set selection. */
|
|
|
|
void
|
|
|
|
screen_draw_set_selection(struct screen_draw_ctx *ctx,
|
|
|
|
int flag, u_int sx, u_int sy, u_int ex, u_int ey)
|
2007-11-22 19:17:01 +00:00
|
|
|
{
|
|
|
|
struct screen_draw_sel *sel = &ctx->sel;
|
|
|
|
|
2007-11-22 19:40:17 +00:00
|
|
|
sel->flag = flag;
|
2007-11-23 13:02:45 +00:00
|
|
|
if (!sel->flag)
|
2007-11-22 19:40:17 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (ey < sy || (sy == ey && ex < sx)) {
|
|
|
|
sel->sx = ex; sel->sy = ey;
|
|
|
|
sel->ex = sx; sel->ey = sy;
|
|
|
|
} else {
|
|
|
|
sel->sx = sx; sel->sy = sy;
|
|
|
|
sel->ex = ex; sel->ey = ey;
|
2007-11-22 19:26:20 +00:00
|
|
|
}
|
2007-11-22 19:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if cell in selection. */
|
|
|
|
int
|
|
|
|
screen_draw_check_selection(struct screen_draw_ctx *ctx, u_int px, u_int py)
|
|
|
|
{
|
|
|
|
struct screen_draw_sel *sel = &ctx->sel;
|
2007-11-22 19:17:01 +00:00
|
|
|
|
2007-11-23 13:02:45 +00:00
|
|
|
if (!sel->flag)
|
|
|
|
return (0);
|
|
|
|
|
2007-11-22 19:17:01 +00:00
|
|
|
if (py < sel->sy || py > sel->ey)
|
|
|
|
return (0);
|
2007-11-22 19:40:17 +00:00
|
|
|
|
2007-11-22 19:26:20 +00:00
|
|
|
if (py == sel->sy && py == sel->ey) {
|
|
|
|
if (px < sel->sx || px > sel->ex)
|
|
|
|
return (0);
|
2007-11-22 19:40:17 +00:00
|
|
|
return (1);
|
2007-11-22 19:26:20 +00:00
|
|
|
}
|
2007-11-22 19:40:17 +00:00
|
|
|
|
|
|
|
if ((py == sel->sy && px < sel->sx) || (py == sel->ey && px > sel->ex))
|
|
|
|
return (0);
|
2007-11-22 19:17:01 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2007-11-21 22:20:44 +00:00
|
|
|
/* Get cell data during drawing. */
|
|
|
|
void
|
|
|
|
screen_draw_get_cell(struct screen_draw_ctx *ctx,
|
|
|
|
u_int px, u_int py, u_char *data, u_char *attr, u_char *colr)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
u_int cx, cy;
|
|
|
|
|
|
|
|
cx = ctx->ox + px;
|
|
|
|
cy = screen_y(s, py) - ctx->oy;
|
|
|
|
|
|
|
|
screen_get_cell(s, cx, cy, data, attr, colr);
|
2007-11-22 19:17:01 +00:00
|
|
|
|
2007-11-22 19:40:17 +00:00
|
|
|
if (screen_draw_check_selection(ctx, cx, cy))
|
2007-11-22 19:17:01 +00:00
|
|
|
*attr |= ATTR_REVERSE;
|
2007-11-21 22:20:44 +00:00
|
|
|
}
|
|
|
|
|
2007-11-21 18:24:49 +00:00
|
|
|
/* Finalise drawing. */
|
|
|
|
void
|
|
|
|
screen_draw_stop(struct screen_draw_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct buffer *b = ctx->b;
|
2007-07-09 19:04:12 +00:00
|
|
|
|
2007-11-20 18:46:32 +00:00
|
|
|
input_store_two(b, CODE_SCROLLREGION, s->rupper + 1, s->rlower + 1);
|
2007-09-29 10:57:39 +00:00
|
|
|
|
2007-11-21 18:24:49 +00:00
|
|
|
if (ctx->cx != s->cx || ctx->cy != s->cy)
|
|
|
|
input_store_two(b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
|
2007-07-09 19:04:12 +00:00
|
|
|
|
2007-11-21 18:24:49 +00:00
|
|
|
if (ctx->attr != s->attr || ctx->colr != s->colr)
|
|
|
|
input_store_two(b, CODE_ATTRIBUTES, s->attr, s->colr);
|
2007-11-22 18:09:43 +00:00
|
|
|
|
|
|
|
if (s->mode & MODE_BACKGROUND) {
|
|
|
|
if (s->mode & MODE_BGCURSOR)
|
|
|
|
input_store_zero(b, CODE_CURSORON);
|
|
|
|
} else {
|
|
|
|
if (s->mode & MODE_CURSOR)
|
|
|
|
input_store_zero(b, CODE_CURSORON);
|
|
|
|
}
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
|
2007-11-21 18:24:49 +00:00
|
|
|
/* Move cursor. */
|
|
|
|
void
|
|
|
|
screen_draw_move(struct screen_draw_ctx *ctx, u_int px, u_int py)
|
|
|
|
{
|
|
|
|
if (px == ctx->cx && py == ctx->cy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
input_store_two(ctx->b, CODE_CURSORMOVE, py + 1, px + 1);
|
|
|
|
|
|
|
|
ctx->cx = px;
|
|
|
|
ctx->cy = py;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set attributes. */
|
|
|
|
void
|
|
|
|
screen_draw_set_attributes(
|
|
|
|
struct screen_draw_ctx *ctx, u_char attr, u_char colr)
|
|
|
|
{
|
|
|
|
if (attr != ctx->attr || colr != ctx->colr) {
|
|
|
|
input_store_two(ctx->b, CODE_ATTRIBUTES, attr, colr);
|
|
|
|
ctx->attr = attr;
|
|
|
|
ctx->colr = colr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw single cell. */
|
|
|
|
void
|
|
|
|
screen_draw_cell(struct screen_draw_ctx *ctx, u_int px, u_int py)
|
|
|
|
{
|
|
|
|
struct buffer *b = ctx->b;
|
|
|
|
u_char data, attr, colr;
|
|
|
|
|
|
|
|
screen_draw_move(ctx, px, py);
|
|
|
|
|
|
|
|
screen_draw_get_cell(ctx, px, py, &data, &attr, &colr);
|
|
|
|
screen_draw_set_attributes(ctx, attr, colr);
|
|
|
|
input_store8(b, data);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't try to wrap as it will cause problems when screen is smaller
|
|
|
|
* than client.
|
|
|
|
*/
|
|
|
|
ctx->cx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw range of cells. */
|
|
|
|
void
|
|
|
|
screen_draw_cells(struct screen_draw_ctx *ctx, u_int px, u_int py, u_int nx)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = px; i < px + nx; i++)
|
|
|
|
screen_draw_cell(ctx, i, py);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw single column. */
|
|
|
|
void
|
|
|
|
screen_draw_column(struct screen_draw_ctx *ctx, u_int px)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = 0; i < screen_size_y(ctx->s); i++)
|
|
|
|
screen_draw_cell(ctx, px, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw single line. */
|
|
|
|
void
|
|
|
|
screen_draw_line(struct screen_draw_ctx *ctx, u_int py)
|
|
|
|
{
|
|
|
|
screen_draw_cells(ctx, 0, py, screen_size_x(ctx->s));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw set of lines. */
|
|
|
|
void
|
|
|
|
screen_draw_lines(struct screen_draw_ctx *ctx, u_int py, u_int ny)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = py; i < py + ny; i++)
|
|
|
|
screen_draw_line(ctx, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw entire screen. */
|
|
|
|
void
|
|
|
|
screen_draw_screen(struct screen_draw_ctx *ctx)
|
|
|
|
{
|
|
|
|
screen_draw_lines(ctx, 0, screen_size_y(ctx->s));
|
|
|
|
}
|
|
|
|
|
2007-11-20 21:42:29 +00:00
|
|
|
/* Create a range of lines. */
|
2007-07-09 19:04:12 +00:00
|
|
|
void
|
2007-08-27 09:53:38 +00:00
|
|
|
screen_make_lines(struct screen *s, u_int py, u_int ny)
|
2007-07-09 19:04:12 +00:00
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
2007-08-27 09:53:38 +00:00
|
|
|
for (i = py; i < py + ny; i++) {
|
2007-11-21 22:20:44 +00:00
|
|
|
s->grid_data[i] = NULL;
|
|
|
|
s->grid_attr[i] = NULL;
|
|
|
|
s->grid_colr[i] = NULL;
|
|
|
|
s->grid_size[i] = 0;
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-20 21:42:29 +00:00
|
|
|
/* Free a range of ny lines at py. */
|
2007-07-09 19:04:12 +00:00
|
|
|
void
|
2007-08-27 09:53:38 +00:00
|
|
|
screen_free_lines(struct screen *s, u_int py, u_int ny)
|
2007-07-09 19:04:12 +00:00
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
2007-08-27 09:53:38 +00:00
|
|
|
for (i = py; i < py + ny; i++) {
|
2007-11-21 22:20:44 +00:00
|
|
|
if (s->grid_data[i] != NULL)
|
|
|
|
xfree(s->grid_data[i]);
|
|
|
|
s->grid_data[i] = NULL;
|
|
|
|
if (s->grid_attr[i] != NULL)
|
|
|
|
xfree(s->grid_attr[i]);
|
|
|
|
s->grid_attr[i] = NULL;
|
|
|
|
if (s->grid_colr[i] != NULL)
|
|
|
|
xfree(s->grid_colr[i]);
|
|
|
|
s->grid_colr[i] = NULL;
|
2007-11-21 15:35:53 +00:00
|
|
|
s->grid_size[i] = 0;
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move a range of lines. */
|
|
|
|
void
|
2007-08-27 09:53:38 +00:00
|
|
|
screen_move_lines(struct screen *s, u_int dy, u_int py, u_int ny)
|
2007-07-09 19:04:12 +00:00
|
|
|
{
|
|
|
|
memmove(
|
2007-08-27 09:53:38 +00:00
|
|
|
&s->grid_data[dy], &s->grid_data[py], ny * (sizeof *s->grid_data));
|
2007-07-09 19:04:12 +00:00
|
|
|
memmove(
|
2007-08-27 09:53:38 +00:00
|
|
|
&s->grid_attr[dy], &s->grid_attr[py], ny * (sizeof *s->grid_attr));
|
2007-07-09 19:04:12 +00:00
|
|
|
memmove(
|
2007-08-27 09:53:38 +00:00
|
|
|
&s->grid_colr[dy], &s->grid_colr[py], ny * (sizeof *s->grid_colr));
|
2007-11-21 15:35:53 +00:00
|
|
|
memmove(
|
|
|
|
&s->grid_size[dy], &s->grid_size[py], ny * (sizeof *s->grid_size));
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill a range of lines. */
|
|
|
|
void
|
|
|
|
screen_fill_lines(
|
2007-08-27 09:53:38 +00:00
|
|
|
struct screen *s, u_int py, u_int ny, u_char data, u_char attr, u_char colr)
|
2007-07-09 19:04:12 +00:00
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
2007-08-27 09:53:38 +00:00
|
|
|
for (i = py; i < py + ny; i++)
|
2007-11-20 21:42:29 +00:00
|
|
|
screen_fill_cells(s, 0, i, s->dx, data, attr, colr);
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
|
2007-11-20 21:42:29 +00:00
|
|
|
/* Fill a range of cells. */
|
2007-09-29 18:48:04 +00:00
|
|
|
void
|
2007-11-20 21:42:29 +00:00
|
|
|
screen_fill_cells(struct screen *s,
|
|
|
|
u_int px, u_int py, u_int nx, u_char data, u_char attr, u_char colr)
|
2007-09-29 18:48:04 +00:00
|
|
|
{
|
2007-11-21 22:20:44 +00:00
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = px; i < px + nx; i++)
|
|
|
|
screen_set_cell(s, i, py, data, attr, colr);
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|