2008-09-10 18:59:29 +00:00
|
|
|
/* $Id: screen.c,v 1.70 2008-09-10 18:59:29 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-12-06 09:46:23 +00:00
|
|
|
*
|
|
|
|
* A screen is stored as three arrays of lines of 8-bit values, one for the
|
|
|
|
* actual characters (data), one for attributes and one for colours. Three
|
|
|
|
* seperate blocks means memset and friends can be used. Each array is y by x
|
|
|
|
* in size, row then column order. Sizes are 0-based. There is an additional
|
|
|
|
* array of u_ints with the size of each line.
|
|
|
|
*
|
|
|
|
* Each screen has a history starting at the beginning of the arrays and
|
|
|
|
* extending for hsize lines. Beyond that is the screen display of size
|
|
|
|
* dy:
|
|
|
|
*
|
|
|
|
* ----------- array base
|
|
|
|
* | |
|
|
|
|
* | history |
|
|
|
|
* ----------- array base + hsize
|
|
|
|
* | |
|
|
|
|
* | display |
|
|
|
|
* | |
|
|
|
|
* ----------- array base + hsize + dy
|
|
|
|
*
|
|
|
|
* The screen_x/screen_y macros are used to convert a cell on the displayed
|
2008-06-18 22:21:51 +00:00
|
|
|
* area to an absolute position in the arrays.
|
2007-12-06 09:46:23 +00:00
|
|
|
*
|
|
|
|
* Screen handling code is split into four files:
|
|
|
|
*
|
|
|
|
* screen.c: Creation/deletion, utility functions, and basic functions to
|
|
|
|
* manipulate the screen based on offsets from the base.
|
|
|
|
* screen-display.c: Basic functions for manipulating the displayed
|
|
|
|
* part of the screen. x,y coordinates passed to these
|
|
|
|
* are relative to the display. These are largely
|
2008-06-18 22:21:51 +00:00
|
|
|
* utility functions for screen-write.c.
|
2007-12-06 09:46:23 +00:00
|
|
|
* screen-redraw.c: Functions for redrawing all or part of a screen to
|
|
|
|
* one or more ttys. A context is filled via one of the
|
|
|
|
* screen_redraw_start* variants which sets up (removes
|
|
|
|
* cursor etc) and figures out which tty_write_* function
|
|
|
|
* to use to write to the terminals, then the other
|
|
|
|
* screen_redraw_* functions are used to draw the screen,
|
|
|
|
* and screen_redraw_stop used to reset the cursor and
|
|
|
|
* clean up. These are used when changing window and a
|
|
|
|
* few other bits (status line).
|
|
|
|
* screen-write.c: Functions for modifying (writing into) the screen and
|
|
|
|
* optionally simultaneously updating one or more ttys.
|
|
|
|
* These are used in much the same way as the redraw
|
|
|
|
* functions. These are used to update when parsing
|
|
|
|
* input from the window (input.c) and for the various
|
|
|
|
* other modes which maintain private screens.
|
|
|
|
*
|
|
|
|
* If you're thinking this all seems too complicated, that's because it is :-/.
|
2007-07-09 19:04:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Create a new screen. */
|
|
|
|
void
|
2008-06-03 21:42:37 +00:00
|
|
|
screen_create(struct screen *s, u_int dx, u_int dy, u_int hlimit)
|
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;
|
2008-06-03 21:42:37 +00:00
|
|
|
s->hlimit = hlimit;
|
2007-07-09 19:04:12 +00:00
|
|
|
|
2008-07-24 21:42:40 +00:00
|
|
|
s->attr = 0;
|
2008-09-08 17:40:51 +00:00
|
|
|
s->fg = 8;
|
|
|
|
s->bg = 8;
|
2007-07-09 19:04:12 +00:00
|
|
|
|
2008-07-24 07:01:57 +00:00
|
|
|
s->mode = MODE_CURSOR;
|
2007-11-30 11:08:35 +00:00
|
|
|
s->title = xstrdup("");
|
2007-07-09 19:04:12 +00:00
|
|
|
|
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));
|
2008-09-08 17:40:51 +00:00
|
|
|
s->grid_fg = xmalloc(dy * (sizeof *s->grid_fg));
|
|
|
|
s->grid_bg = xmalloc(dy * (sizeof *s->grid_bg));
|
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-12-06 09:46:23 +00:00
|
|
|
|
2008-09-09 22:16:37 +00:00
|
|
|
utf8_init(&s->utf8_table, UTF8_LIMIT);
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_clear_selection(s);
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 07:04:31 +00:00
|
|
|
/* Reinitialise screen. */
|
|
|
|
void
|
|
|
|
screen_reset(struct screen *s)
|
|
|
|
{
|
|
|
|
s->cx = 0;
|
|
|
|
s->cy = 0;
|
|
|
|
|
|
|
|
s->rupper = 0;
|
|
|
|
s->rlower = s->dy - 1;
|
|
|
|
|
2008-07-24 21:42:40 +00:00
|
|
|
s->attr = 0;
|
2008-09-08 17:40:51 +00:00
|
|
|
s->fg = 8;
|
|
|
|
s->bg = 8;
|
2008-06-29 07:04:31 +00:00
|
|
|
|
2008-07-24 07:01:57 +00:00
|
|
|
s->mode = MODE_CURSOR;
|
2008-06-29 07:04:31 +00:00
|
|
|
|
|
|
|
screen_display_fill_area(s, 0, 0,
|
2008-09-08 17:40:51 +00:00
|
|
|
screen_size_x(s), screen_size_y(s), ' ', 0, 8, 8);
|
2008-06-29 07:04:31 +00:00
|
|
|
|
|
|
|
screen_clear_selection(s);
|
|
|
|
}
|
|
|
|
|
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-12-06 09:46:23 +00:00
|
|
|
/*
|
2007-11-21 13:11:41 +00:00
|
|
|
* X dimension.
|
|
|
|
*/
|
2007-07-09 19:04:12 +00:00
|
|
|
if (sx != ox) {
|
2007-12-06 09:46:23 +00:00
|
|
|
/*
|
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-12-06 09:46:23 +00:00
|
|
|
|
2007-11-21 13:11:41 +00:00
|
|
|
s->cy -= my;
|
|
|
|
oy -= my;
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
2007-11-21 13:11:41 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2007-11-21 13:11:41 +00:00
|
|
|
/* 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);
|
2008-09-08 17:40:51 +00:00
|
|
|
s->grid_fg = xrealloc(s->grid_fg, ny, sizeof *s->grid_fg);
|
|
|
|
s->grid_bg = xrealloc(s->grid_bg, ny, sizeof *s->grid_bg);
|
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;
|
|
|
|
|
2008-09-08 22:03:56 +00:00
|
|
|
s->grid_data[py] = xrealloc(
|
|
|
|
s->grid_data[py], sizeof **s->grid_data, nx);
|
|
|
|
memset(&s->grid_data[py][ox], ' ', (nx - ox) * sizeof **s->grid_data);
|
|
|
|
s->grid_attr[py] = xrealloc(
|
|
|
|
s->grid_attr[py], sizeof **s->grid_attr, nx);
|
|
|
|
memset(&s->grid_attr[py][ox], 0, (nx - ox) * sizeof **s->grid_attr);
|
|
|
|
s->grid_fg[py] = xrealloc(
|
|
|
|
s->grid_fg[py], sizeof **s->grid_fg, nx);
|
|
|
|
memset(&s->grid_fg[py][ox], 8, (nx - ox) * sizeof **s->grid_fg);
|
|
|
|
s->grid_bg[py] = xrealloc(
|
|
|
|
s->grid_bg[py], sizeof **s->grid_bg, nx);
|
|
|
|
memset(&s->grid_bg[py][ox], 8, (nx - ox) * sizeof **s->grid_bg);
|
2007-11-21 22:20:44 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2008-09-08 22:03:56 +00:00
|
|
|
s->grid_data[py] = xrealloc(
|
|
|
|
s->grid_data[py], sizeof **s->grid_data, nx);
|
|
|
|
s->grid_attr[py] = xrealloc(
|
|
|
|
s->grid_attr[py], sizeof **s->grid_attr, nx);
|
|
|
|
s->grid_fg[py] = xrealloc(
|
|
|
|
s->grid_fg[py], sizeof **s->grid_fg, nx);
|
|
|
|
s->grid_bg[py] = xrealloc(
|
|
|
|
s->grid_bg[py], sizeof **s->grid_bg, nx);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
2007-11-21 22:20:44 +00:00
|
|
|
/* Get cell. */
|
|
|
|
void
|
|
|
|
screen_get_cell(struct screen *s,
|
2008-09-08 22:03:56 +00:00
|
|
|
u_int cx, u_int cy, u_char *data, u_short *attr, u_char *fg, u_char *bg)
|
2007-11-21 22:20:44 +00:00
|
|
|
{
|
|
|
|
if (cx >= s->grid_size[cy]) {
|
2008-07-24 21:42:40 +00:00
|
|
|
*data = ' ';
|
|
|
|
*attr = 0;
|
2008-09-08 17:40:51 +00:00
|
|
|
*fg = 8;
|
|
|
|
*bg = 8;
|
2007-11-21 22:20:44 +00:00
|
|
|
} else {
|
|
|
|
*data = s->grid_data[cy][cx];
|
|
|
|
*attr = s->grid_attr[cy][cx];
|
2008-09-08 17:40:51 +00:00
|
|
|
*fg = s->grid_fg[cy][cx];
|
|
|
|
*bg = s->grid_bg[cy][cx];
|
2007-11-21 22:20:44 +00:00
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
|
|
|
|
if (screen_check_selection(s, cx, cy))
|
|
|
|
*attr |= ATTR_REVERSE;
|
2007-11-21 22:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a cell. */
|
|
|
|
void
|
|
|
|
screen_set_cell(struct screen *s,
|
2008-09-08 22:03:56 +00:00
|
|
|
u_int cx, u_int cy, u_char data, u_short attr, u_char fg, u_char bg)
|
2007-11-21 22:20:44 +00:00
|
|
|
{
|
2008-06-14 12:05:06 +00:00
|
|
|
if (cx >= s->grid_size[cy])
|
2007-11-21 22:20:44 +00:00
|
|
|
screen_expand_line(s, cy, cx + 1);
|
|
|
|
|
|
|
|
s->grid_data[cy][cx] = data;
|
|
|
|
s->grid_attr[cy][cx] = attr;
|
2008-09-08 17:40:51 +00:00
|
|
|
s->grid_fg[cy][cx] = fg;
|
|
|
|
s->grid_bg[cy][cx] = bg;
|
2007-11-21 22:20:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-01 14:15:48 +00:00
|
|
|
/* Destroy a screen. */
|
|
|
|
void
|
|
|
|
screen_destroy(struct screen *s)
|
|
|
|
{
|
2008-09-09 22:16:37 +00:00
|
|
|
utf8_free(&s->utf8_table);
|
2007-11-30 11:08:35 +00:00
|
|
|
xfree(s->title);
|
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);
|
2008-09-08 17:40:51 +00:00
|
|
|
xfree(s->grid_fg);
|
|
|
|
xfree(s->grid_bg);
|
2007-11-21 15:35:53 +00:00
|
|
|
xfree(s->grid_size);
|
2007-10-01 14:15:48 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2008-09-08 17:40:51 +00:00
|
|
|
s->grid_fg[i] = NULL;
|
|
|
|
s->grid_bg[i] = NULL;
|
2007-11-21 22:20:44 +00:00
|
|
|
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;
|
2008-09-08 17:40:51 +00:00
|
|
|
if (s->grid_fg[i] != NULL)
|
|
|
|
xfree(s->grid_fg[i]);
|
|
|
|
s->grid_fg[i] = NULL;
|
|
|
|
if (s->grid_bg[i] != NULL)
|
|
|
|
xfree(s->grid_bg[i]);
|
|
|
|
s->grid_bg[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(
|
2008-09-08 17:40:51 +00:00
|
|
|
&s->grid_fg[dy], &s->grid_fg[py], ny * (sizeof *s->grid_fg));
|
|
|
|
memmove(
|
|
|
|
&s->grid_bg[dy], &s->grid_bg[py], ny * (sizeof *s->grid_bg));
|
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
|
|
|
}
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
/* Fill an area. */
|
2007-07-09 19:04:12 +00:00
|
|
|
void
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_fill_area(struct screen *s, u_int px, u_int py,
|
2008-09-08 22:03:56 +00:00
|
|
|
u_int nx, u_int ny, u_char data, u_short attr, u_char fg, u_char bg)
|
2007-07-09 19:04:12 +00:00
|
|
|
{
|
2007-12-06 09:46:23 +00:00
|
|
|
u_int i, j;
|
2007-07-09 19:04:12 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
for (i = py; i < py + ny; i++) {
|
|
|
|
for (j = px; j < px + nx; j++)
|
2008-09-08 17:40:51 +00:00
|
|
|
screen_set_cell(s, j, i, data, attr, fg, bg);
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
/* Set selection. */
|
2007-09-29 18:48:04 +00:00
|
|
|
void
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_set_selection(struct screen *s, u_int sx, u_int sy, u_int ex, u_int ey)
|
2007-09-29 18:48:04 +00:00
|
|
|
{
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen_sel *sel = &s->sel;
|
2007-11-21 22:20:44 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
sel->flag = 1;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear selection. */
|
|
|
|
void
|
|
|
|
screen_clear_selection(struct screen *s)
|
|
|
|
{
|
|
|
|
struct screen_sel *sel = &s->sel;
|
|
|
|
|
|
|
|
sel->flag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if cell in selection. */
|
|
|
|
int
|
|
|
|
screen_check_selection(struct screen *s, u_int px, u_int py)
|
|
|
|
{
|
|
|
|
struct screen_sel *sel = &s->sel;
|
|
|
|
|
|
|
|
if (!sel->flag || py < sel->sy || py > sel->ey)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (py == sel->sy && py == sel->ey) {
|
|
|
|
if (px < sel->sx || px > sel->ex)
|
|
|
|
return (0);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((py == sel->sy && px < sel->sx) || (py == sel->ey && px > sel->ex))
|
|
|
|
return (0);
|
|
|
|
return (1);
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|