diff options
author | Martin Felke <martin.felke@googlemail.com> | 2015-01-07 17:14:07 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-01-07 17:22:11 +0300 |
commit | e0e9cd0163a62e74d9837becad4e9097228ce60e (patch) | |
tree | 9113d0789883de7673d81ee63cdf20b212b13bf3 /source/blender/makesrna/intern/rna_space_api.c | |
parent | 14f2597d7e518be552020875e52c5d6804b48a1e (diff) |
PyAPI: Call to get the pixel x,y in a text block
This allows scripts to request the screen location of any (line, column) pair.
Diffstat (limited to 'source/blender/makesrna/intern/rna_space_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_space_api.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_space_api.c b/source/blender/makesrna/intern/rna_space_api.c index aed77378241..4114ee8a289 100644 --- a/source/blender/makesrna/intern/rna_space_api.c +++ b/source/blender/makesrna/intern/rna_space_api.c @@ -31,6 +31,8 @@ #ifdef RNA_RUNTIME +#include "ED_text.h" + static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d) { bScreen *sc = (bScreen *)id; @@ -49,6 +51,19 @@ static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d) } } +static void rna_SpaceTextEditor_region_location_from_cursor( + ID *id, SpaceText *st, + int line, int column, int r_pixel_pos[2]) +{ + bScreen *sc = (bScreen *)id; + ScrArea *sa = BKE_screen_find_area_from_space(sc, (SpaceLink *)st); + if (sa) { + ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + const int cursor_co[2] = {line, column}; + ED_text_region_location_from_cursor(st, ar, cursor_co, r_pixel_pos); + } +} + #else void RNA_api_region_view3d(StructRNA *srna) @@ -74,4 +89,20 @@ void RNA_api_space_node(StructRNA *srna) RNA_def_property_flag(parm, PROP_REQUIRED); } +void RNA_api_space_text(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *parm; + + func = RNA_def_function(srna, "region_location_from_cursor", "rna_SpaceTextEditor_region_location_from_cursor"); + RNA_def_function_ui_description(func, "Retrieve the region position from the given line and character position"); + RNA_def_function_flag(func, FUNC_USE_SELF_ID); + parm = RNA_def_int(func, "line", 0, INT_MIN, INT_MAX, "Line", "Line index", 0, INT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_int(func, "column", 0, INT_MIN, INT_MAX, "Column", "Column index", 0, INT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_int_array(func, "result", 2, 0, -1, INT_MAX, "", "Region coordinates", -1, INT_MAX); + RNA_def_function_output(func, parm); +} + #endif |