[Bf-blender-cvs] [37273b1] temp-text_editor_cursor_api: add BKE_screen_find_area_from_space and call from rna_space code.

Campbell Barton noreply at git.blender.org
Tue Dec 30 10:25:26 CET 2014


Commit: 37273b1b7802aaa0c695e5bd50e72b4b7d9f5e49
Author: Campbell Barton
Date:   Tue Dec 30 20:24:33 2014 +1100
Branches: temp-text_editor_cursor_api
https://developer.blender.org/rB37273b1b7802aaa0c695e5bd50e72b4b7d9f5e49

add BKE_screen_find_area_from_space and call from rna_space code.

also rna correct function flag use.

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

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/blenkernel/intern/screen.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blenderplayer/bad_level_call_stubs/stubs.c

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

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 188b8e2..4c11ec9 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -280,6 +280,7 @@ void            BKE_screen_area_free(struct ScrArea *sa);
 
 struct ARegion *BKE_area_find_region_type(struct ScrArea *sa, int type);
 struct ARegion *BKE_area_find_region_active_win(struct ScrArea *sa);
+struct ScrArea *BKE_screen_find_area_from_space(struct bScreen *sc, struct SpaceLink *sl) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
 struct ScrArea *BKE_screen_find_big_area(struct bScreen *sc, const int spacetype, const short min);
 
 unsigned int BKE_screen_view3d_layer_active_ex(
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index b229615..ad4ed5a 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -402,6 +402,23 @@ ARegion *BKE_area_find_region_active_win(ScrArea *sa)
 	return NULL;
 }
 
+/**
+ * \note, ideally we can get the area from the context,
+ * there are a few places however where this isn't practical.
+ */
+ScrArea *BKE_screen_find_area_from_space(struct bScreen *sc, SpaceLink *sl)
+{
+	ScrArea *sa;
+
+	for (sa = sc->areabase.first; sa; sa = sa->next) {
+		if (BLI_findindex(&sa->spacedata, sl) != -1) {
+			break;
+		}
+	}
+
+	return sa;
+}
+
 /* note, using this function is generally a last resort, you really want to be
  * using the context when you can - campbell
  * -1 for any type */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 9bdc467..7b87cf1 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -267,13 +267,7 @@ static ScrArea *rna_area_from_space(PointerRNA *ptr)
 {
 	bScreen *sc = (bScreen *)ptr->id.data;
 	SpaceLink *link = (SpaceLink *)ptr->data;
-	ScrArea *sa;
-
-	for (sa = sc->areabase.first; sa; sa = sa->next)
-		if (BLI_findindex(&sa->spacedata, link) != -1)
-			return sa;
-
-	return NULL;
+	return BKE_screen_find_area_from_space(sc, link);
 }
 
 static void area_region_from_regiondata(bScreen *sc, void *regiondata, ScrArea **r_sa, ARegion **r_ar)
@@ -857,21 +851,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_cursor_to_pixel_space(ID *ptr, SpaceText *st, int cursor_co[2], int r_pixel_pos[2])
+static void rna_SpaceTextEditor_cursor_to_pixel_space(ID *id, SpaceText *st, int cursor_co[2], int r_pixel_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_cursor_to_pixel_space(st, ar, cursor_co, r_pixel_pos);
-			break;
-		}
+	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);
+		ED_text_cursor_to_pixel_space(st, ar, cursor_co, r_pixel_pos);
 	}
 }
 
-
 /* Space Properties */
 
 /* note: this function exists only to avoid id refcounting */
@@ -2767,7 +2756,7 @@ static void rna_def_space_text(BlenderRNA *brna)
 
 	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);
+	RNA_def_function_flag(func, FUNC_USE_SELF_ID);
 	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, "result", 2, 0, -1, INT_MAX, "", "Screen Position in Pixels", -1, INT_MAX);
diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c
index 81a308d..e277e21 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_cursor_to_pixel_space(SpaceText *st, ARegion *ar, const int cursor_co[2], int pixel_co[2]) RET_ZERO
+bool ED_text_cursor_to_pixel_space(SpaceText *st, ARegion *ar, const int cursor_co[2], int r_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],




More information about the Bf-blender-cvs mailing list