[Bf-blender-cvs] [12bf84c] master: BKE_screen: add BKE_screen_find_area_xy

Campbell Barton noreply at git.blender.org
Wed Jan 21 03:47:17 CET 2015


Commit: 12bf84cbe40a3f54d1b5927554a41a226c471ae0
Author: Campbell Barton
Date:   Wed Jan 21 13:43:46 2015 +1100
Branches: master
https://developer.blender.org/rB12bf84cbe40a3f54d1b5927554a41a226c471ae0

BKE_screen: add BKE_screen_find_area_xy

Use from eyedropper & screen operators
also define SPACE_TYPE_ANY for readability.

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

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/blenkernel/intern/screen.c
M	source/blender/editors/interface/interface_eyedropper.c
M	source/blender/editors/render/render_view.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/makesdna/DNA_space_types.h

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

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 4c11ec9..3eb6ba7 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -265,7 +265,7 @@ struct SpaceType *BKE_spacetype_from_id(int spaceid);
 struct ARegionType *BKE_regiontype_from_id(struct SpaceType *st, int regionid);
 const struct ListBase *BKE_spacetypes_list(void);
 void BKE_spacetype_register(struct SpaceType *st);
-int BKE_spacetype_exists(int spaceid);
+bool BKE_spacetype_exists(int spaceid);
 void BKE_spacetypes_free(void); /* only for quitting blender */
 
 /* spacedata */
@@ -282,6 +282,7 @@ 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);
+struct ScrArea *BKE_screen_find_area_xy(struct bScreen *sc, const int spacetype, int x, int y);
 
 unsigned int BKE_screen_view3d_layer_active_ex(
         const struct View3D *v3d, const struct Scene *scene, bool use_localvd) ATTR_NONNULL(2);
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index ad4ed5a..c9dba38 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -46,6 +46,7 @@
 
 #include "BLI_listbase.h"
 #include "BLI_utildefines.h"
+#include "BLI_rect.h"
 
 #include "BKE_idprop.h"
 #include "BKE_screen.h"
@@ -137,7 +138,7 @@ void BKE_spacetype_register(SpaceType *st)
 	BLI_addtail(&spacetypes, st);
 }
 
-int BKE_spacetype_exists(int spaceid)
+bool BKE_spacetype_exists(int spaceid)
 {
 	return BKE_spacetype_from_id(spaceid) != NULL;
 }
@@ -419,16 +420,17 @@ ScrArea *BKE_screen_find_area_from_space(struct bScreen *sc, SpaceLink *sl)
 	return sa;
 }
 
-/* note, using this function is generally a last resort, you really want to be
+/**
+ * \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 */
+ */
 ScrArea *BKE_screen_find_big_area(bScreen *sc, const int spacetype, const short min)
 {
 	ScrArea *sa, *big = NULL;
 	int size, maxsize = 0;
 
 	for (sa = sc->areabase.first; sa; sa = sa->next) {
-		if ((spacetype == -1) || sa->spacetype == spacetype) {
+		if ((spacetype == SPACE_TYPE_ANY) || (sa->spacetype == spacetype)) {
 			if (min <= sa->winx && min <= sa->winy) {
 				size = sa->winx * sa->winy;
 				if (size > maxsize) {
@@ -442,6 +444,22 @@ ScrArea *BKE_screen_find_big_area(bScreen *sc, const int spacetype, const short
 	return big;
 }
 
+ScrArea *BKE_screen_find_area_xy(bScreen *sc, const int spacetype, int x, int y)
+{
+	ScrArea *sa, *sa_found = NULL;
+
+	for (sa = sc->areabase.first; sa; sa = sa->next) {
+		if (BLI_rcti_isect_pt(&sa->totrct, x, y)) {
+			if ((spacetype == SPACE_TYPE_ANY) || (sa->spacetype == spacetype)) {
+				sa_found = sa;
+			}
+			break;
+		}
+	}
+	return sa_found;
+}
+
+
 /**
  * Utility function to get the active layer to use when adding new objects.
  */
diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c
index ec1234a..f5b24f4 100644
--- a/source/blender/editors/interface/interface_eyedropper.c
+++ b/source/blender/editors/interface/interface_eyedropper.c
@@ -172,43 +172,42 @@ static void eyedropper_color_sample_fl(bContext *C, Eyedropper *UNUSED(eye), int
 
 	/* we could use some clever */
 	wmWindow *win = CTX_wm_window(C);
-	ScrArea *sa;
-	for (sa = win->screen->areabase.first; sa; sa = sa->next) {
-		if (BLI_rcti_isect_pt(&sa->totrct, mx, my)) {
-			if (sa->spacetype == SPACE_IMAGE) {
-				ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
-				if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) {
-					SpaceImage *sima = sa->spacedata.first;
-					int mval[2] = {mx - ar->winrct.xmin,
-					               my - ar->winrct.ymin};
-
-					if (ED_space_image_color_sample(CTX_data_scene(C), sima, ar, mval, r_col)) {
-						return;
-					}
+	ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, mx, my);
+
+	if (sa) {
+		if (sa->spacetype == SPACE_IMAGE) {
+			ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+			if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) {
+				SpaceImage *sima = sa->spacedata.first;
+				int mval[2] = {mx - ar->winrct.xmin,
+				               my - ar->winrct.ymin};
+
+				if (ED_space_image_color_sample(CTX_data_scene(C), sima, ar, mval, r_col)) {
+					return;
 				}
 			}
-			else if (sa->spacetype == SPACE_NODE) {
-				ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
-				if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) {
-					SpaceNode *snode = sa->spacedata.first;
-					int mval[2] = {mx - ar->winrct.xmin,
-					               my - ar->winrct.ymin};
-
-					if (ED_space_node_color_sample(CTX_data_scene(C), snode, ar, mval, r_col)) {
-						return;
-					}
+		}
+		else if (sa->spacetype == SPACE_NODE) {
+			ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+			if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) {
+				SpaceNode *snode = sa->spacedata.first;
+				int mval[2] = {mx - ar->winrct.xmin,
+				               my - ar->winrct.ymin};
+
+				if (ED_space_node_color_sample(CTX_data_scene(C), snode, ar, mval, r_col)) {
+					return;
 				}
 			}
-			else if (sa->spacetype == SPACE_CLIP) {
-				ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
-				if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) {
-					SpaceClip *sc = sa->spacedata.first;
-					int mval[2] = {mx - ar->winrct.xmin,
-					               my - ar->winrct.ymin};
-
-					if (ED_space_clip_color_sample(CTX_data_scene(C), sc, ar, mval, r_col)) {
-						return;
-					}
+		}
+		else if (sa->spacetype == SPACE_CLIP) {
+			ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+			if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) {
+				SpaceClip *sc = sa->spacedata.first;
+				int mval[2] = {mx - ar->winrct.xmin,
+				               my - ar->winrct.ymin};
+
+				if (ED_space_clip_color_sample(CTX_data_scene(C), sc, ar, mval, r_col)) {
+					return;
 				}
 			}
 		}
@@ -473,53 +472,49 @@ static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int
 
 	/* we could use some clever */
 	wmWindow *win = CTX_wm_window(C);
-	ScrArea *sa;
+	ScrArea *sa = BKE_screen_find_area_xy(win->screen, -1, mx, my);
 
 	ScrArea *area_prev = CTX_wm_area(C);
 	ARegion *ar_prev = CTX_wm_region(C);
 
 	ddr->name[0] = '\0';
 
-	for (sa = win->screen->areabase.first; sa; sa = sa->next) {
-		if (BLI_rcti_isect_pt(&sa->totrct, mx, my)) {
-			if (sa->spacetype == SPACE_VIEW3D) {
-				ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
-				if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) {
-					const int mval[2] = {
-					    mx - ar->winrct.xmin,
-					    my - ar->winrct.ymin};
-					Base *base;
-
-					CTX_wm_area_set(C, sa);
-					CTX_wm_region_set(C, ar);
-
-					/* grr, always draw else we leave stale text */
-					ED_region_tag_redraw(ar);
-
-					base = ED_view3d_give_base_under_cursor(C, mval);
-					if (base) {
-						Object *ob = base->object;
-						ID *id = NULL;
-						if (ddr->idcode == ID_OB) {
-							id = (ID *)ob;
+	if (sa) {
+		if (sa->spacetype == SPACE_VIEW3D) {
+			ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+			if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) {
+				const int mval[2] = {
+				    mx - ar->winrct.xmin,
+				    my - ar->winrct.ymin};
+				Base *base;
+
+				CTX_wm_area_set(C, sa);
+				CTX_wm_region_set(C, ar);
+
+				/* grr, always draw else we leave stale text */
+				ED_region_tag_redraw(ar);
+
+				base = ED_view3d_give_base_under_cursor(C, mval);
+				if (base) {
+					Object *ob = base->object;
+					ID *id = NULL;
+					if (ddr->idcode == ID_OB) {
+						id = (ID *)ob;
+					}
+					else if (ob->data) {
+						if (GS(((ID *)ob->data)->name) == ddr->idcode) {
+							id = (ID *)ob->data;
 						}
-						else if (ob->data) {
-							if (GS(((ID *)ob->data)->name) == ddr->idcode) {
-								id = (ID *)ob->data;
-							}
-							else {
-								BLI_snprintf(ddr->name, sizeof(ddr->name), "Incompatible, expected a %s",
-								             ddr->idcode_name);
-							}
-						}
-
-						if (id) {
-							BLI_snprintf(ddr->name, sizeof(ddr->name), "%s: %s",
-							             ddr->idcode_name, id->name + 2);
-							*r_id = id;
+						else {
+							BLI_snprintf(ddr->name, sizeof(ddr->name), "Incompatible, expected a %s",
+							             ddr->idcode_name);
 						}
+					}
 
-						break;
+					if (id) {
+						BLI_snprintf(ddr->name, sizeof(ddr->name), "%s: %s",
+						             ddr->idcode_name, id->name + 2);
+						*r_id = id;
 					}
 				}
 			}
@@ -756,7 +751,7 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx,
 
 	/* we could use some clever */
 	wmWindow *win = CTX_wm_window(C);
-	ScrArea *sa;
+	ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, mx, my);
 	Scene *scene = win->screen->scene;
 	UnitSettings *unit = &scene->unit;
 	const bool do_split = (unit->flag & USER_UNIT_OPT_SPLIT) != 0;
@@ -766,47 +761,44 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx,
 
 	ddr->name[0] = '\0';
 
-	for (sa = win->screen->areabase.first; sa; sa = sa->next) {
-		if (BLI_rcti_isect_pt(&sa->totrct, mx, my)) {
-			if (sa->spacetype == SPACE_VIEW3D) {
-				ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
-				if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) {
-					View3D *v3d = sa->spacedata.first;
-					RegionView3D *rv3d = ar->regiondata;
-					/* weak, we could pass in some reference point */
-					const float *view_co = v3d->camera ? v3d->camera->obmat[3] : rv3d->viewinv[3];
-					const int mval[2] = {
-					    mx - ar->winrct.xmin,
-					    my - ar->winrct.ymin};
-					float co[3];
-
-					CTX_wm_area_set(C, sa);
-					CTX_wm_region_set(C, ar);
-
-					/* grr, always draw else we leave stale text */
-	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list