[Bf-blender-cvs] [0b01c01] temp-text_editor_cursor_api: sync with cursor drawing code, reduce confusion.

Campbell Barton noreply at git.blender.org
Wed Jan 7 14:47:00 CET 2015


Commit: 0b01c010fc1bccf6d43a26e582dff90245a2c5c3
Author: Campbell Barton
Date:   Thu Jan 8 00:46:15 2015 +1100
Branches: temp-text_editor_cursor_api
https://developer.blender.org/rB0b01c010fc1bccf6d43a26e582dff90245a2c5c3

sync with cursor drawing code, reduce confusion.

===================================================================

M	source/blender/editors/space_text/text_draw.c

===================================================================

diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index e578e8a..ddee755 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -1167,6 +1167,7 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
 	
 	if (!hidden) {
 		/* Draw the cursor itself (we draw the sel. cursor as this is the leading edge) */
+		/* note! ensure ED_text_region_location_from_cursor stays in sync */
 		x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
 		x += vselc * st->cwidth;
 		y = ar->winy - vsell * lheight;
@@ -1566,18 +1567,24 @@ bool ED_text_region_location_from_cursor(SpaceText *st, ARegion* ar, const int c
 		goto error;
 	}
 	else {
-		int offl = 0, offc = 0;
-		int linenr_offset = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
-		/* dont forget to handle tabs as well !*/
-		int char_pos = text_get_char_pos(st, line->line, cursor_co[1]);
+		/* stripped down from 'draw_cursor' */
+		Text *text = st->text;
+		const int lheight = st->lheight_dpi + TXT_LINE_SPACING;
+		int vsell, vselc;
+		int offl, offc;
+		int x, y;
 
-		if (st->wordwrap) {
-			wrap_offset(st, ar, line, cursor_co[1], &offl, &offc);
-		}
+		wrap_offset(st, ar, text->sell, text->selc, &offl, &offc);
+		vsell = txt_get_span(text->lines.first, text->sell) - st->top + offl;
+		vselc = text_get_char_pos(st, text->sell->line, text->selc) - st->left + offc;
+
+		x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
+		x += vselc * st->cwidth;
+		y = ar->winy - vsell * lheight;
 
-		r_pixel_co[0] = (char_pos + offc - st->left) * st->cwidth + linenr_offset;
-		r_pixel_co[1] = (cursor_co[0] + offl - st->top) * (st->lheight_dpi + TXT_LINE_SPACING);
-		r_pixel_co[1] = ar->winy - (r_pixel_co[1] + TXT_OFFSET);
+		/* - lheight so we get the baseline */
+		r_pixel_co[0] = x;
+		r_pixel_co[1] = y - lheight;
 	}
 	return true;




More information about the Bf-blender-cvs mailing list