Text selection with C-space.

This commit is contained in:
Nicholas Marriott
2007-11-22 19:17:01 +00:00
parent 18d72e6928
commit 7ab0b466fe
3 changed files with 123 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $Id: screen.c,v 1.37 2007-11-22 18:09:43 nicm Exp $ */
/* $Id: screen.c,v 1.38 2007-11-22 19:17:01 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -278,6 +278,8 @@ screen_draw_start(struct screen_draw_ctx *ctx,
ctx->cx = s->cx;
ctx->cy = s->cy;
memset(&ctx->sel, 0, sizeof ctx->sel);
ctx->attr = s->attr;
ctx->colr = s->colr;
@ -285,6 +287,32 @@ screen_draw_start(struct screen_draw_ctx *ctx,
input_store_zero(b, CODE_CURSOROFF);
}
/* Check if cell in selection. */
int
screen_check_selection(struct screen_draw_ctx *ctx, u_int px, u_int py)
{
struct screen_draw_sel *sel = &ctx->sel;
u_int xx, yy;
if (!sel->flag)
return (0);
if (sel->ey < sel->sy) {
xx = sel->sx;
yy = sel->sy;
sel->sx = sel->ex;
sel->sy = sel->ey;
sel->ex = xx;
sel->ey = yy;
}
if (py < sel->sy || py > sel->ey)
return (0);
if ((py == sel->sy && px < sel->sx) || (py == sel->ey && px > sel->ex))
return (0);
return (1);
}
/* Get cell data during drawing. */
void
screen_draw_get_cell(struct screen_draw_ctx *ctx,
@ -297,6 +325,9 @@ screen_draw_get_cell(struct screen_draw_ctx *ctx,
cy = screen_y(s, py) - ctx->oy;
screen_get_cell(s, cx, cy, data, attr, colr);
if (screen_check_selection(ctx, cx, cy))
*attr |= ATTR_REVERSE;
}
/* Finalise drawing. */