Commit: 8176b3a94ceae4d762804d278f9b72d0e4b18981
Author: Campbell Barton
Date:   Tue Dec 30 19:53:35 2014 +1100
Branches: temp-text_editor_cursor_api
https://developer.blender.org/rB8176b3a94ceae4d762804d278f9b72d0e4b18981

minor refactor/rename

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

M       source/blender/editors/include/ED_text.h
M       source/blender/editors/space_text/text_draw.c
M       source/blender/makesrna/intern/rna_space.c
M       source/blenderplayer/bad_level_call_stubs/stubs.c

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

diff --git a/source/blender/editors/include/ED_text.h 
b/source/blender/editors/include/ED_text.h
index 59bb37d..b902641 100644
--- a/source/blender/editors/include/ED_text.h
+++ b/source/blender/editors/include/ED_text.h
@@ -35,7 +35,7 @@ struct SpaceText;
 struct ARegion;
 
 void ED_text_undo_step(struct bContext *C, int step);
-bool ED_text_line_char_to_pixel_space(struct SpaceText *st, struct ARegion 
*ar, const int line_char[2], int screen_pos[2]);
+bool ED_text_cursor_to_pixel_space(struct SpaceText *st, struct ARegion *ar, 
const int cursor_co[2], int r_pixel_co[2]);
 
 #endif /* __ED_TEXT_H__ */
 
diff --git a/source/blender/editors/space_text/text_draw.c 
b/source/blender/editors/space_text/text_draw.c
index bc30213..53c2ddd 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -1550,37 +1550,35 @@ void text_update_cursor_moved(bContext *C)
        text_scroll_to_cursor__area(st, sa, true);
 }
 
-bool ED_text_line_char_to_pixel_space(SpaceText *st, ARegion* ar, const int 
line_char[2], int screen_pos[2])
+/**
+ * Takes a cursor (row, character) and returns x,y pixel coords.
+ */
+bool ED_text_cursor_to_pixel_space(SpaceText *st, ARegion* ar, const int 
cursor_co[2], int r_pixel_co[2])
 {
        TextLine* line = NULL;
 
-       if (st && st->text)     {
-               /*ensure line, char are valid text positions (hmm, why... does 
it matter here?) */
-               if (line_char[0] < 0) {
-                       screen_pos[0] = screen_pos[1] = -1;
-                       return false;
-               }
-               else {
-                       line = BLI_findlink(&st->text->lines, line_char[0]);
-                       if (!line || (line_char[1] < 0) || (line_char[1] > 
line->len)) {
-                               screen_pos[0] = screen_pos[1] = -1;
-                               return false;
-                       }
-                       else {
-                               int offl = 0, offc = 0;
-
-                               if (st->wordwrap) {
-                                       wrap_offset(st, ar, line, line_char[1], 
&offl, &offc);
-                               }
+       if (!st->text) {
+               goto error;
+       }
 
-                               screen_pos[0] = (line_char[1] + offc - 
st->left) * st->cwidth;
-                               screen_pos[1] = (line_char[0] + offl - st->top) 
* (st->lheight_dpi + TXT_LINE_SPACING);
-                               return true;
-                       }
-               }
+       line = BLI_findlink(&st->text->lines, cursor_co[0]);
+       if (!line || (cursor_co[1] < 0) || (cursor_co[1] > line->len)) {
+               goto error;
        }
        else {
-               screen_pos[0] = screen_pos[1] = -1;
-               return false;
+               int offl = 0, offc = 0;
+
+               if (st->wordwrap) {
+                       wrap_offset(st, ar, line, cursor_co[1], &offl, &offc);
+               }
+
+               r_pixel_co[0] = (cursor_co[1] + offc - st->left) * st->cwidth;
+               r_pixel_co[1] = (cursor_co[0] + offl - st->top) * 
(st->lheight_dpi + TXT_LINE_SPACING);
        }
+       return true;
+
+
+error:
+       r_pixel_co[0] = r_pixel_co[1] = -1;
+       return false;
 }
diff --git a/source/blender/makesrna/intern/rna_space.c 
b/source/blender/makesrna/intern/rna_space.c
index f9495d5..9bdc467 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -857,15 +857,16 @@ static void rna_SpaceTextEditor_updateEdited(Main 
*UNUSED(bmain), Scene *UNUSED(
                WM_main_add_notifier(NC_TEXT | NA_EDITED, st->text);
 }
 
-static void rna_SpaceTextEditor_line_char_to_screen_pos(ID *ptr, SpaceText 
*st, int line_char[2], int screen_pos[2])
+static void rna_SpaceTextEditor_cursor_to_pixel_space(ID *ptr, SpaceText *st, 
int cursor_co[2], int r_pixel_pos[2])
 {
-       bScreen *scr = (bScreen*)ptr;
+       bScreen *scr = (bScreen *)ptr;
        ScrArea *sa;
 
        for (sa = scr->areabase.first; sa; sa = sa->next) {
                if (BLI_findindex(&sa->spacedata, st) != -1) {
                        ARegion *ar = BKE_area_find_region_type(sa, 
RGN_TYPE_WINDOW);
-                       ED_text_line_char_to_pixel_space(st, ar, line_char, 
screen_pos);
+                       ED_text_cursor_to_pixel_space(st, ar, cursor_co, 
r_pixel_pos);
+                       break;
                }
        }
 }
@@ -2764,12 +2765,12 @@ static void rna_def_space_text(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Replace Text", "Text to replace 
selected text with using the replace tool");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TEXT, NULL);
 
-       func = RNA_def_function(srna, "line_char_to_screen_pos", 
"rna_SpaceTextEditor_line_char_to_screen_pos");
+       func = RNA_def_function(srna, "cursor_to_pixel_space", 
"rna_SpaceTextEditor_cursor_to_pixel_space");
        RNA_def_function_ui_description(func, "Retrieve the screen position in 
pixels from the given line and character position");
        RNA_def_function_flag(func, PROP_RNAPTR);
-       parm = RNA_def_int_array(func, "line_char", 2, 0, 0, INT_MAX, "", "Text 
Position, line and character in line", 0, INT_MAX);
+       parm = RNA_def_int_array(func, "cursor", 2, 0, 0, INT_MAX, "", "Text 
Position, line and character in line", 0, INT_MAX);
        RNA_def_property_flag(parm, PROP_REQUIRED);
-       parm = RNA_def_int_array(func, "screen_pos", 2, 0, -1, INT_MAX, "", 
"Screen Position in Pixels", -1, INT_MAX);
+       parm = RNA_def_int_array(func, "result", 2, 0, -1, INT_MAX, "", "Screen 
Position in Pixels", -1, INT_MAX);
        RNA_def_function_output(func, parm);
 }
 
diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c 
b/source/blenderplayer/bad_level_call_stubs/stubs.c
index 730225e..81a308d 100644
--- a/source/blenderplayer/bad_level_call_stubs/stubs.c
+++ b/source/blenderplayer/bad_level_call_stubs/stubs.c
@@ -483,7 +483,7 @@ bool ED_texture_context_check_lamp(const struct bContext 
*C) RET_ZERO
 bool ED_texture_context_check_particles(const struct bContext *C) RET_ZERO
 bool ED_texture_context_check_others(const struct bContext *C) RET_ZERO
 
-bool ED_text_line_char_to_pixel_space(SpaceText *st, ARegion *ar, const int 
line_char[], int screen_pos[]) RET_ZERO
+bool ED_text_cursor_to_pixel_space(SpaceText *st, ARegion *ar, const int 
cursor_co[2], int pixel_co[2]) RET_ZERO
 
 bool snapObjectsRayEx(struct Scene *scene, struct Base *base_act, struct 
View3D *v3d, struct ARegion *ar, struct Object *obedit, short snap_mode,
                       struct Object **r_ob, float r_obmat[4][4],

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to