From 26c8303733c243b2181bb644ce6fa2b838de8e15 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 22 Nov 2007 19:40:17 +0000 Subject: Tidier code by moving mess into functions. --- screen.c | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'screen.c') diff --git a/screen.c b/screen.c index b9ddf319..f943c442 100644 --- a/screen.c +++ b/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.39 2007-11-22 19:26:20 nicm Exp $ */ +/* $Id: screen.c,v 1.40 2007-11-22 19:40:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -290,41 +290,43 @@ 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) +/* 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) { 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 (sel->sy == sel->ey && sel->ex < sel->sx) { - xx = sel->sx; - sel->sx = sel->ex; - sel->ex = xx; + sel->flag = flag; + if (!flag) + 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; } +} + +/* 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; if (py < sel->sy || py > sel->ey) return (0); + if (py == sel->sy && py == sel->ey) { if (px < sel->sx || px > sel->ex) return (0); - } else { - if (py == sel->sy && px < sel->sx) - return (0); - if (py == sel->ey && px > sel->ex) - return (0); + return (1); } + + if ((py == sel->sy && px < sel->sx) || (py == sel->ey && px > sel->ex)) + return (0); return (1); } @@ -341,7 +343,7 @@ screen_draw_get_cell(struct screen_draw_ctx *ctx, screen_get_cell(s, cx, cy, data, attr, colr); - if (screen_check_selection(ctx, cx, cy)) + if (screen_draw_check_selection(ctx, cx, cy)) *attr |= ATTR_REVERSE; } -- cgit