[Bf-blender-cvs] [9a35ad752e8] blender2.8: Cleanup: Get rid of context in editor 'new' callback

Julian Eisel noreply at git.blender.org
Sat Apr 21 19:47:36 CEST 2018


Commit: 9a35ad752e845129aa756778e7f502a5057b92bf
Author: Julian Eisel
Date:   Sat Apr 21 19:30:56 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB9a35ad752e845129aa756778e7f502a5057b92bf

Cleanup: Get rid of context in editor 'new' callback

Requiring context means we can't easily create new editors to replace deprecated
ones in versioning code.
Think it's reasonable to give editors access to scene and area data for their
initial setup though. They mostly need it for setting "the view", as in,
scrolling values.

Also did minor cleanup in top-bar creation function.

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

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/editors/screen/area.c
M	source/blender/editors/screen/screen_edit.c
M	source/blender/editors/space_action/space_action.c
M	source/blender/editors/space_api/spacetypes.c
M	source/blender/editors/space_buttons/space_buttons.c
M	source/blender/editors/space_clip/space_clip.c
M	source/blender/editors/space_console/space_console.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/editors/space_graph/space_graph.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/editors/space_info/space_info.c
M	source/blender/editors/space_nla/space_nla.c
M	source/blender/editors/space_node/space_node.c
M	source/blender/editors/space_outliner/space_outliner.c
M	source/blender/editors/space_script/space_script.c
M	source/blender/editors/space_sequencer/space_sequencer.c
M	source/blender/editors/space_text/space_text.c
M	source/blender/editors/space_topbar/space_topbar.c
M	source/blender/editors/space_userpref/space_userpref.c
M	source/blender/editors/space_view3d/space_view3d.c

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

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 2a25120ba8d..2736833a5ca 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -77,8 +77,9 @@ typedef struct SpaceType {
 	int spaceid;                                /* unique space identifier */
 	int iconid;                                 /* icon lookup for menus */
 	
-	/* initial allocation, after this WM will call init() too */
-	struct SpaceLink    *(*new)(const struct bContext *C);
+	/* Initial allocation, after this WM will call init() too. Some editors need
+	 * area and scene data (e.g. frame range) to set their initial scrolling. */
+	struct SpaceLink    *(*new)(const struct ScrArea *, const struct Scene *);
 	/* not free spacelink itself */
 	void (*free)(struct SpaceLink *);
 	
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index e4c48a83565..2d058c7c0bf 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1838,7 +1838,7 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
 		else {
 			/* new space */
 			if (st) {
-				sl = st->new(C);
+				sl = st->new(sa, CTX_data_scene(C));
 				BLI_addhead(&sa->spacedata, sl);
 				
 				/* swap regions */
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index 6a27964165d..00bff69cd02 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -1117,27 +1117,42 @@ int ED_screen_area_active(const bContext *C)
 	return 0;
 }
 
+/**
+ * Add an area and geometry (screen-edges and -vertices) for it to \a area_map,
+ * with coordinates/dimensions matching \a rect.
+ */
+static ScrArea *screen_area_create_with_geometry(
+        ScrAreaMap *area_map, const rcti *rect,
+        short headertype, short spacetype)
+{
+	ScrVert *bottom_left  = screen_addvert_ex(area_map, rect->xmin, rect->ymin);
+	ScrVert *top_left     = screen_addvert_ex(area_map, rect->xmin, rect->ymax);
+	ScrVert *top_right    = screen_addvert_ex(area_map, rect->xmax, rect->ymax);
+	ScrVert *bottom_right = screen_addvert_ex(area_map, rect->xmax, rect->ymin);
+
+	screen_addedge_ex(area_map, bottom_left, top_left);
+	screen_addedge_ex(area_map, top_left, top_right);
+	screen_addedge_ex(area_map, top_right, bottom_right);
+	screen_addedge_ex(area_map, bottom_right, bottom_left);
+
+	return screen_addarea_ex(area_map, bottom_left, top_left, top_right, bottom_right, headertype, spacetype);
+}
+
 void ED_screen_global_topbar_area_create(wmWindow *win, const bScreen *screen)
 {
 	if (screen->temp == 0) {
-		SpaceType *st = BKE_spacetype_from_id(SPACE_TOPBAR);
-		SpaceLink *sl = st->new(NULL);
-		ScrArea *sa;
 		const short size_y = 2.25 * HEADERY;
-		const int minx = 0, maxx = WM_window_pixels_x(win) - 1;
-		const int maxy = WM_window_pixels_y(win) - 1, miny = maxy - size_y;
-
-		ScrVert *bottom_left  = screen_addvert_ex(&win->global_areas, minx, miny);
-		ScrVert *top_left     = screen_addvert_ex(&win->global_areas, minx, maxy);
-		ScrVert *top_right    = screen_addvert_ex(&win->global_areas, maxx, maxy);
-		ScrVert *bottom_right = screen_addvert_ex(&win->global_areas, maxx, miny);
-		screen_addedge_ex(&win->global_areas, bottom_left, top_left);
-		screen_addedge_ex(&win->global_areas, top_left, top_right);
-		screen_addedge_ex(&win->global_areas, top_right, bottom_right);
-		screen_addedge_ex(&win->global_areas, bottom_right, bottom_left);
-
-		sa = screen_addarea_ex(&win->global_areas, bottom_left, top_left, top_right, bottom_right,
-		                       HEADERTOP, SPACE_TOPBAR);
+		SpaceType *st;
+		SpaceLink *sl;
+		ScrArea *sa;
+		rcti rect;
+
+		BLI_rcti_init(&rect, 0, WM_window_pixels_x(win) - 1, 0, WM_window_pixels_y(win) - 1);
+		rect.ymin = rect.ymax - size_y;
+
+		sa = screen_area_create_with_geometry(&win->global_areas, &rect, HEADERTOP, SPACE_TOPBAR);
+		st = BKE_spacetype_from_id(SPACE_TOPBAR);
+		sl = st->new(sa, WM_window_get_active_scene(win));
 		sa->regionbase = sl->regionbase;
 
 		/* Data specific to global areas. */
diff --git a/source/blender/editors/space_action/space_action.c b/source/blender/editors/space_action/space_action.c
index b68300e0d52..f749cce69e3 100644
--- a/source/blender/editors/space_action/space_action.c
+++ b/source/blender/editors/space_action/space_action.c
@@ -92,10 +92,8 @@ ARegion *action_has_buttons_region(ScrArea *sa)
 
 /* ******************** default callbacks for action space ***************** */
 
-static SpaceLink *action_new(const bContext *C)
+static SpaceLink *action_new(const ScrArea *sa, const Scene *scene)
 {
-	Scene *scene = CTX_data_scene(C);
-	ScrArea *sa = CTX_wm_area(C);
 	SpaceAction *saction;
 	ARegion *ar;
 	
diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c
index 6c53aa62378..12f16f1fe42 100644
--- a/source/blender/editors/space_api/spacetypes.c
+++ b/source/blender/editors/space_api/spacetypes.c
@@ -280,7 +280,7 @@ void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
 void ED_spacetype_xxx(void);
 
 /* allocate and init some vars */
-static SpaceLink *xxx_new(const bContext *UNUSED(C))
+static SpaceLink *xxx_new(const ScrArea *UNUSED(sa), const Scene *UNUSED(scene))
 {
 	return NULL;
 }
diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c
index 179780bf517..d3fab82f7ff 100644
--- a/source/blender/editors/space_buttons/space_buttons.c
+++ b/source/blender/editors/space_buttons/space_buttons.c
@@ -52,7 +52,7 @@
 
 /* ******************** default callbacks for buttons space ***************** */
 
-static SpaceLink *buttons_new(const bContext *UNUSED(C))
+static SpaceLink *buttons_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
 {
 	ARegion *ar;
 	SpaceButs *sbuts;
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index ba9684411b3..f043280e43c 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -75,12 +75,8 @@
 
 #include "clip_intern.h"  /* own include */
 
-static void init_preview_region(const bContext *C, ARegion *ar)
+static void init_preview_region(const Scene *scene, const ScrArea *sa, const SpaceClip *sc, ARegion *ar)
 {
-	Scene *scene = CTX_data_scene(C);
-	ScrArea *sa = CTX_wm_area(C);
-	SpaceClip *sc = CTX_wm_space_clip(C);
-
 	ar->regiontype = RGN_TYPE_PREVIEW;
 	ar->alignment = RGN_ALIGN_TOP;
 	ar->flag |= RGN_FLAG_HIDDEN;
@@ -138,15 +134,17 @@ static void init_preview_region(const bContext *C, ARegion *ar)
 
 static void reinit_preview_region(const bContext *C, ARegion *ar)
 {
+	Scene *scene = CTX_data_scene(C);
+	ScrArea *sa = CTX_wm_area(C);
 	SpaceClip *sc = CTX_wm_space_clip(C);
 
 	if (sc->view == SC_VIEW_DOPESHEET) {
 		if ((ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) == 0)
-			init_preview_region(C, ar);
+			init_preview_region(scene, sa, sc, ar);
 	}
 	else {
 		if (ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL)
-			init_preview_region(C, ar);
+			init_preview_region(scene, sa, sc, ar);
 	}
 }
 
@@ -168,7 +166,7 @@ static ARegion *ED_clip_has_preview_region(const bContext *C, ScrArea *sa)
 	arnew = MEM_callocN(sizeof(ARegion), "clip preview region");
 
 	BLI_insertlinkbefore(&sa->regionbase, ar, arnew);
-	init_preview_region(C, arnew);
+	init_preview_region(CTX_data_scene(C), sa, CTX_wm_space_clip(C), arnew);
 
 	return arnew;
 }
@@ -228,7 +226,7 @@ static void clip_scopes_check_gpencil_change(ScrArea *sa)
 
 /* ******************** default callbacks for clip space ***************** */
 
-static SpaceLink *clip_new(const bContext *C)
+static SpaceLink *clip_new(const ScrArea *sa, const Scene *scene)
 {
 	ARegion *ar;
 	SpaceClip *sc;
@@ -286,7 +284,7 @@ static SpaceLink *clip_new(const bContext *C)
 	ar = MEM_callocN(sizeof(ARegion), "preview for clip");
 
 	BLI_addtail(&sc->regionbase, ar);
-	init_preview_region(C, ar);
+	init_preview_region(scene, sa, sc, ar);
 
 	/* main region */
 	ar = MEM_callocN(sizeof(ARegion), "main region for clip");
diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c
index 9a2f4b5d431..c49df387707 100644
--- a/source/blender/editors/space_console/space_console.c
+++ b/source/blender/editors/space_console/space_console.c
@@ -52,7 +52,7 @@
 
 /* ******************** default callbacks for console space ***************** */
 
-static SpaceLink *console_new(const bContext *UNUSED(C))
+static SpaceLink *console_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
 {
 	ARegion *ar;
 	SpaceConsole *sconsole;
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 61ea4961f3e..40707d5add7 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -68,7 +68,7 @@
 
 /* ******************** default callbacks for file space ***************** */
 
-static SpaceLink *file_new(const bContext *UNUSED(C))
+static SpaceLink *file_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
 {
 	ARegion *ar;
 	SpaceFile *sfile;
diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c
index b09de2470a2..381cb1d9e6e 100644
--- a/source/blender/editors/space_graph/space_graph.c
+++ b/source/blender/editors/space_graph/space_graph.c
@@ -95,9 +95,8 @@ ARegion *graph_has_buttons_region(ScrArea *sa)
 
 /* ******************** default callbacks for ipo space ***************** */
 
-static SpaceLink *graph_new(const bContext *C)
+static SpaceLink *graph_new(const ScrArea *UNUSED(sa), const Scene *scene)
 {
-	Scene *scene = CTX_data_scene(C);
 	ARegion *ar;
 	SpaceIpo *sipo;
 	
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 38a850568fd..bfbf51487ad 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -162,7 +162,7 @@ ARegion *image_has_tool

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list