[Bf-blender-cvs] [a83ca53] temp-text_editor_cursor_api: previous commit wasn't good, instead tweak existing code

Campbell Barton noreply at git.blender.org
Wed Jan 7 15:10:57 CET 2015


Commit: a83ca531b15166b67d9c511cb91d64f19a6f3662
Author: Campbell Barton
Date:   Thu Jan 8 01:10:29 2015 +1100
Branches: temp-text_editor_cursor_api
https://developer.blender.org/rBa83ca531b15166b67d9c511cb91d64f19a6f3662

previous commit wasn't good, instead tweak existing code

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

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 ddee755..ed1cbec 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -1167,7 +1167,6 @@ 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;
@@ -1556,7 +1555,7 @@ void text_update_cursor_moved(bContext *C)
  */
 bool ED_text_region_location_from_cursor(SpaceText *st, ARegion* ar, const int cursor_co[2], int r_pixel_co[2])
 {
-	TextLine* line = NULL;
+	TextLine *line = NULL;
 
 	if (!st->text) {
 		goto error;
@@ -1567,24 +1566,15 @@ bool ED_text_region_location_from_cursor(SpaceText *st, ARegion* ar, const int c
 		goto error;
 	}
 	else {
-		/* 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;
-
-		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;
-
-		/* - lheight so we get the baseline */
-		r_pixel_co[0] = x;
-		r_pixel_co[1] = y - lheight;
+		int linenr_offset = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
+		/* handle tabs as well! */
+		int char_pos = text_get_char_pos(st, line->line, cursor_co[1]);
+
+		wrap_offset(st, ar, line, cursor_co[1], &offl, &offc);
+		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)) - st->lheight_dpi;
 	}
 	return true;




More information about the Bf-blender-cvs mailing list