From a089ad0e1dd19ef8f5dda555a8657d47c1f7bbd4 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 14 Feb 2011 19:26:45 +0000 Subject: Pass clip rect to textarea redraw as struct rect. svn path=/trunk/netsurf/; revision=11681 --- desktop/textarea.c | 75 ++++++++++++++++++++++++++---------------------------- desktop/textarea.h | 2 +- desktop/tree.c | 3 +-- 3 files changed, 38 insertions(+), 42 deletions(-) (limited to 'desktop') diff --git a/desktop/textarea.c b/desktop/textarea.c index 6e4950641..cb5ce1285 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -728,25 +728,22 @@ bool textarea_reflow(struct text_area *ta, unsigned int line) * \param y1 bottom Y coordinate of redraw area */ void textarea_redraw(struct text_area *ta, int x, int y, - int clip_x0, int clip_y0, int clip_x1, int clip_y1) + struct rect *clip) { int line0, line1, line; int chars, offset, text_y_offset, text_y_offset_baseline; unsigned int c_pos, c_len, b_start, b_end, line_len; char *line_text; - int x0, x1, y0, y1; + struct rect r; plot_style_t plot_style_fill_bg = { .fill_type = PLOT_OP_TYPE_SOLID, .fill_colour = BACKGROUND_COL, }; - x0 = clip_x0; - x1 = clip_x1; - y0 = clip_y0; - y1 = clip_y1; + r = *clip; - if (x1 < x || x0 > x + ta->vis_width || y1 < y || - y0 > y + ta->vis_height) + if (r.x1 < x || r.x0 > x + ta->vis_width || r.y1 < y || + r.y0 > y + ta->vis_height) /* Textarea outside the clipping rectangle */ return; @@ -757,8 +754,8 @@ void textarea_redraw(struct text_area *ta, int x, int y, if (ta->flags & TEXTAREA_READONLY) plot_style_fill_bg.fill_colour = READONLY_BG; - line0 = (y0 - y + ta->scroll_y) / ta->line_height - 1; - line1 = (y1 - y + ta->scroll_y) / ta->line_height + 1; + line0 = (r.y0 - y + ta->scroll_y) / ta->line_height - 1; + line1 = (r.y1 - y + ta->scroll_y) / ta->line_height + 1; if (line0 < 0) line0 = 0; @@ -771,26 +768,26 @@ void textarea_redraw(struct text_area *ta, int x, int y, if (line1 < line0) line1 = line0; - if (x0 < x) - x0 = x; - if (y0 < y) - y0 = y; - if (x1 > x + ta->vis_width) - x1 = x + ta->vis_width; - if (y1 > y + ta->vis_height) - y1 = y + ta->vis_height; - - plot.clip(x0, y0, x1, y1); - plot.rectangle(x0, y0, x1, y1, &plot_style_fill_bg); + if (r.x0 < x) + r.x0 = x; + if (r.y0 < y) + r.y0 = y; + if (r.x1 > x + ta->vis_width) + r.x1 = x + ta->vis_width; + if (r.y1 > y + ta->vis_height) + r.y1 = y + ta->vis_height; + + plot.clip(r.x0, r.y0, r.x1, r.y1); + plot.rectangle(r.x0, r.y0, r.x1, r.y1, &plot_style_fill_bg); plot.rectangle(x, y, x + ta->vis_width - 1, y + ta->vis_height - 1, &pstyle_stroke_border); - if (x0 < x + MARGIN_LEFT) - x0 = x + MARGIN_LEFT; - if (x1 > x + ta->vis_width - MARGIN_RIGHT) - x1 = x + ta->vis_width - MARGIN_RIGHT; - plot.clip(x0, y0, x1, y1); + if (r.x0 < x + MARGIN_LEFT) + r.x0 = x + MARGIN_LEFT; + if (r.x1 > x + ta->vis_width - MARGIN_RIGHT) + r.x1 = x + ta->vis_width - MARGIN_RIGHT; + plot.clip(r.x0, r.y0, r.x1, r.y1); if (line0 > 0) c_pos = utf8_bounded_length(ta->text, @@ -809,7 +806,7 @@ void textarea_redraw(struct text_area *ta, int x, int y, } for (line = line0; (line <= line1) && - (y + line * ta->line_height <= y1 + ta->scroll_y); + (y + line * ta->line_height <= r.y1 + ta->scroll_y); line++) { if (ta->lines[line].b_length == 0) continue; @@ -846,11 +843,11 @@ void textarea_redraw(struct text_area *ta, int x, int y, line_len, b_start); nsfont.font_width(&ta->fstyle, line_text, - b_start, &x0); - x0 += x + MARGIN_LEFT; + b_start, &r.x0); + r.x0 += x + MARGIN_LEFT; } else { - x0 = x + MARGIN_LEFT; + r.x0 = x + MARGIN_LEFT; b_start = 0; } @@ -872,12 +869,12 @@ void textarea_redraw(struct text_area *ta, int x, int y, nsfont.font_width(&ta->fstyle, &(ta->text[ta->lines[line].b_start + b_start]), - b_end, &x1); - x1 += x0; - plot.rectangle(x0 - ta->scroll_x, y + + b_end, &r.x1); + r.x1 += r.x0; + plot.rectangle(r.x0 - ta->scroll_x, y + line * ta->line_height + 1 - ta->scroll_y + text_y_offset, - x1 - ta->scroll_x, + r.x1 - ta->scroll_x, y + (line + 1) * ta->line_height - 1 - ta->scroll_y + text_y_offset, &pstyle_fill_selection); @@ -886,14 +883,14 @@ void textarea_redraw(struct text_area *ta, int x, int y, c_pos += c_len; - y0 = y + line * ta->line_height + text_y_offset_baseline; + r.y0 = y + line * ta->line_height + text_y_offset_baseline; ta->fstyle.background = (ta->flags & TEXTAREA_READONLY) ? READONLY_BG : BACKGROUND_COL, plot.text(x + MARGIN_LEFT - ta->scroll_x, - y0 - ta->scroll_y, + r.y0 - ta->scroll_y, ta->text + ta->lines[line].b_start, ta->lines[line].b_length, &ta->fstyle); @@ -901,13 +898,13 @@ void textarea_redraw(struct text_area *ta, int x, int y, if ((ta->selection_end == -1 || ta->selection_start == ta->selection_end) && - x + ta->caret_x >= clip_x0 && - x + ta->caret_x <= clip_x1) { + x + ta->caret_x >= clip->x0 && + x + ta->caret_x <= clip->x1) { /* There is no selection and caret is in horizontal * clip range. */ int caret_height = ta->line_height - 1; y += ta->caret_y + text_y_offset; - if (y + caret_height >= clip_y0 && y <= clip_y1) + if (y + caret_height >= clip->y0 && y <= clip->y1) /* Caret in vertical clip range; plot */ plot.line(x + ta->caret_x, y + ta->caret_y, x + ta->caret_x, diff --git a/desktop/textarea.h b/desktop/textarea.h index 04c269d3c..82c9c2a20 100644 --- a/desktop/textarea.h +++ b/desktop/textarea.h @@ -47,7 +47,7 @@ int textarea_get_text(struct text_area *ta, char *buf, unsigned int len); bool textarea_set_caret(struct text_area *ta, int caret); int textarea_get_caret(struct text_area *ta); void textarea_redraw(struct text_area *ta, int x, int y, - int x0, int y0, int x1, int y1); + struct rect *clip); bool textarea_keypress(struct text_area *ta, uint32_t key); bool textarea_mouse_action(struct text_area *ta, browser_mouse_state mouse, int x, int y); diff --git a/desktop/tree.c b/desktop/tree.c index 131106b65..7e303827d 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -1867,8 +1867,7 @@ void tree_draw(struct tree *tree, int x, int y, y = y + tree->editing->box.y; if (tree->editing->type == NODE_ELEMENT_TEXT_PLUS_ICON) x += NODE_INSTEP; - textarea_redraw(tree->textarea, x, y, - clip.x0, clip.y0, clip.x1, clip.y1); + textarea_redraw(tree->textarea, x, y, &clip); } } -- cgit v1.2.3