Commit: 62e1d8fc276e6be833135873435e4f0366ca8682
Author: Campbell Barton
Date:   Tue Dec 30 19:44:59 2014 +1100
Branches: temp-text_editor_cursor_api
https://developer.blender.org/rB62e1d8fc276e6be833135873435e4f0366ca8682

patch D945 from scorpion81 (Martin Felke)

Committing to a branch for cleanup & api edits

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

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 9a36cb3..59bb37d 100644
--- a/source/blender/editors/include/ED_text.h
+++ b/source/blender/editors/include/ED_text.h
@@ -31,8 +31,11 @@
 #define __ED_TEXT_H__
 
 struct bContext;
+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]);
 
 #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 a43d430..bc30213 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -44,6 +44,8 @@
 #include "BKE_text.h"
 #include "BKE_screen.h"
 
+#include "ED_text.h"
+
 #include "BIF_gl.h"
 
 #include "UI_interface.h"
@@ -1547,3 +1549,38 @@ 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])
+{
+       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);
+                               }
+
+                               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;
+                       }
+               }
+       }
+       else {
+               screen_pos[0] = screen_pos[1] = -1;
+               return false;
+       }
+}
diff --git a/source/blender/makesrna/intern/rna_space.c 
b/source/blender/makesrna/intern/rna_space.c
index 72fd7bf..f9495d5 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -210,6 +210,7 @@ static EnumPropertyItem buttons_texture_context_items[] = {
 #include "ED_view3d.h"
 #include "ED_sequencer.h"
 #include "ED_clip.h"
+#include "ED_text.h"
 
 #include "GPU_material.h"
 
@@ -856,6 +857,19 @@ 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])
+{
+       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);
+               }
+       }
+}
+
 
 /* Space Properties */
 
@@ -2641,7 +2655,8 @@ static void rna_def_space_sequencer(BlenderRNA *brna)
 static void rna_def_space_text(BlenderRNA *brna)
 {
        StructRNA *srna;
-       PropertyRNA *prop;
+       PropertyRNA *prop, *parm;
+       FunctionRNA *func;
 
        srna = RNA_def_struct(brna, "SpaceTextEditor", "Space");
        RNA_def_struct_sdna(srna, "SpaceText");
@@ -2748,6 +2763,14 @@ static void rna_def_space_text(BlenderRNA *brna)
        RNA_def_property_string_sdna(prop, NULL, "replacestr");
        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");
+       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);
+       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);
+       RNA_def_function_output(func, parm);
 }
 
 static void rna_def_space_dopesheet(BlenderRNA *brna)
diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c 
b/source/blenderplayer/bad_level_call_stubs/stubs.c
index 954e431..730225e 100644
--- a/source/blenderplayer/bad_level_call_stubs/stubs.c
+++ b/source/blenderplayer/bad_level_call_stubs/stubs.c
@@ -163,6 +163,7 @@ struct wmWindowManager;
 #include "../blender/editors/include/ED_render.h"
 #include "../blender/editors/include/ED_screen.h"
 #include "../blender/editors/include/ED_space_api.h"
+#include "../blender/editors/include/ED_text.h"
 #include "../blender/editors/include/ED_transform.h"
 #include "../blender/editors/include/ED_uvedit.h"
 #include "../blender/editors/include/ED_view3d.h"
@@ -482,6 +483,8 @@ 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 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],
                       const float ray_start[3], const float ray_normal[3], 
float *r_ray_dist,

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

Reply via email to