[Bf-blender-cvs] [8ff385dd49a] topbar: Move data of global areas into a separate struct

Julian Eisel noreply at git.blender.org
Fri Apr 20 16:00:16 CEST 2018


Commit: 8ff385dd49a1e7318f119f6d4c92ef26b070ec04
Author: Julian Eisel
Date:   Fri Apr 20 15:56:23 2018 +0200
Branches: topbar
https://developer.blender.org/rB8ff385dd49a1e7318f119f6d4c92ef26b070ec04

Move data of global areas into a separate struct

Made the struct accessible via a pointer in the ScrArea so that we can
use a simple NULL-check for this pointer to see if the area is global.

The struct is not written to files, meaning we have the freedom to do
changes to it without having to worry about compatibility.

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

M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/screen/area.c
M	source/blender/editors/screen/screen_edit.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 1ca2dc0a991..77f7b5f847e 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -397,6 +397,7 @@ void BKE_screen_area_free(ScrArea *sa)
 	for (ar = sa->regionbase.first; ar; ar = ar->next)
 		BKE_area_region_free(st, ar);
 
+	MEM_SAFE_FREE(sa->global);
 	BLI_freelistN(&sa->regionbase);
 	
 	BKE_spacedata_freelist(&sa->spacedata);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 3f78079e7e6..0a246e119f5 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6395,6 +6395,8 @@ static void direct_link_area(FileData *fd, ScrArea *area)
 	area->type = NULL;	/* spacetype callbacks */
 	area->region_active_win = -1;
 
+	area->global = newdataadr(fd, area->global);
+
 	/* if we do not have the spacetype registered we cannot
 	 * free it, so don't allocate any new memory for such spacetypes. */
 	if (!BKE_spacetype_exists(area->spacetype)) {
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index c6f1bae881b..841f880caa1 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2901,6 +2901,11 @@ static void write_area_map(WriteData *wd, ScrAreaMap *area_map)
 	writelist(wd, DATA, ScrEdge, &area_map->edgebase);
 	for (ScrArea *area = area_map->areabase.first; area; area = area->next) {
 		writestruct(wd, DATA, ScrArea, 1, area);
+
+#ifdef WITH_TOPBAR_WRITING
+		writestruct(wd, DATA, ScrGlobalAreaData, 1, area->global);
+#endif
+
 		write_area_regions(wd, area);
 	}
 }
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 321cb1d63e8..8d7b6c86aa1 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -128,8 +128,8 @@ void    ED_area_newspace(struct bContext *C, ScrArea *sa, int type, const bool s
 void    ED_area_prevspace(struct bContext *C, ScrArea *sa);
 void    ED_area_swapspace(struct bContext *C, ScrArea *sa1, ScrArea *sa2);
 int     ED_area_headersize(void);
-int     ED_area_global_size_y(const struct wmWindow *win, const ScrArea *area);
-bool    ED_area_is_global(const struct wmWindow *win, const ScrArea *area);
+int     ED_area_global_size_y(const ScrArea *area);
+bool    ED_area_is_global(const ScrArea *area);
 int     ED_region_global_size_y(void);
 
 /** Iterate over all areas visible in the screen (screen as in everything visible in the window, not just bScreen) */
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 378ff284cde..b6e2d2c57d4 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1203,7 +1203,7 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti
 	if (ar->regiontype == RGN_TYPE_HEADER) {
 		prefsizey = ED_area_headersize();
 	}
-	else if (ED_area_is_global(win, sa)) {
+	else if (ED_area_is_global(sa)) {
 		prefsizey = ED_region_global_size_y();
 	}
 	else if (ar->regiontype == RGN_TYPE_UI && sa->spacetype == SPACE_FILE) {
@@ -2248,17 +2248,15 @@ int ED_area_headersize(void)
 /**
  * \return the final height of a global \a area, accounting for DPI.
  */
-int ED_area_global_size_y(const wmWindow *win, const ScrArea *area)
+int ED_area_global_size_y(const ScrArea *area)
 {
-	BLI_assert(ED_area_is_global(win, area));
-	UNUSED_VARS_NDEBUG(win);
-
-	return round_fl_to_int(area->cur_fixed_height * UI_DPI_FAC);
+	BLI_assert(ED_area_is_global(area));
+	return round_fl_to_int(area->global->cur_fixed_height * UI_DPI_FAC);
 }
 
-bool ED_area_is_global(const wmWindow *win, const ScrArea *area)
+bool ED_area_is_global(const ScrArea *area)
 {
-	return BLI_findindex(&win->global_areas.areabase, area) != -1;
+	return area->global != NULL;
 }
 
 /**
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index 1a7b3d898be..82093b4326a 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -726,7 +726,7 @@ static void screen_vertices_scale(
 		area->v3->vec.x = area->v4->vec.x = window_size_x - 1;
 		/* height */
 		area->v2->vec.y = area->v3->vec.y = window_size_y - 1;
-		area->v1->vec.y = area->v4->vec.y = area->v2->vec.y - ED_area_global_size_y(win, area);
+		area->v1->vec.y = area->v4->vec.y = area->v2->vec.y - ED_area_global_size_y(area);
 	}
 }
 
@@ -1138,11 +1138,14 @@ void ED_screen_global_topbar_area_create(wmWindow *win, const bScreen *screen)
 
 		sa = screen_addarea_ex(&win->global_areas, bottom_left, top_left, top_right, bottom_right,
 		                       HEADERTOP, SPACE_TOPBAR);
-		sa->cur_fixed_height = size_y;
-		sa->size_max = size_y;
-		sa->size_min = HEADERY;
 		sa->regionbase = sl->regionbase;
 
+		/* Data specific to global areas. */
+		sa->global = MEM_callocN(sizeof(*sa->global), __func__);
+		sa->global->cur_fixed_height = size_y;
+		sa->global->size_max = size_y;
+		sa->global->size_min = HEADERY;
+
 		BLI_addhead(&sa->spacedata, sl);
 		BLI_listbase_clear(&sl->regionbase);
 	}
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 83501c17516..2cdbd888f01 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -1136,8 +1136,8 @@ static void area_move_set_limits(
 	if (use_bigger_smaller_snap != NULL) {
 		*use_bigger_smaller_snap = false;
 		for (ScrArea *area = win->global_areas.areabase.first; area; area = area->next) {
-			const int size_min = round_fl_to_int(area->size_min * UI_DPI_FAC);
-			const int size_max = round_fl_to_int(area->size_max * UI_DPI_FAC);
+			const int size_min = round_fl_to_int(area->global->size_min * UI_DPI_FAC);
+			const int size_max = round_fl_to_int(area->global->size_max * UI_DPI_FAC);
 
 			/* logic here is only tested for lower edge :) */
 			/* left edge */
@@ -1346,8 +1346,8 @@ static void area_move_apply_do(
 		bool redraw_all = false;
 		ED_screen_areas_iter(win, sc, sa) {
 			if (sa->v1->editflag || sa->v2->editflag || sa->v3->editflag || sa->v4->editflag) {
-				if (ED_area_is_global(win, sa)) {
-					sa->cur_fixed_height = round_fl_to_int((sa->v2->vec.y - sa->v1->vec.y) / UI_DPI_FAC);
+				if (ED_area_is_global(sa)) {
+					sa->global->cur_fixed_height = round_fl_to_int((sa->v2->vec.y - sa->v1->vec.y) / UI_DPI_FAC);
 					sc->do_refresh = true;
 					redraw_all = true;
 				}
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index 77d05a312cf..6d4494ca2d2 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -226,6 +226,23 @@ typedef struct uiPreview {           /* some preview UI data need to be saved in
 	short pad1[3];
 } uiPreview;
 
+/* These two lines with # tell makesdna this struct can be excluded.
+ * Should be: #ifndef WITH_TOPBAR_WRITING */
+#
+#
+typedef struct ScrGlobalAreaData {
+	/* Global areas have a non-dynamic size. That means, changing the window
+	 * size doesn't affect their size at all. However, they can still be
+	 * 'collapsed', by changing this value. Ignores DPI (ED_area_global_size_y
+	 * and winx/winy don't) */
+	short cur_fixed_height;
+	/* For global areas, this is the min and max size they can use depending on
+	 * if they are 'collapsed' or not. Value is set on area creation and not
+	 * touched afterwards. */
+	short size_min, size_max;
+	short pad;
+} ScrGlobalAreaData;
+
 typedef struct ScrArea {
 	struct ScrArea *next, *prev;
 	
@@ -236,16 +253,6 @@ typedef struct ScrArea {
 
 	char spacetype, butspacetype;	/* SPACE_..., butspacetype is button arg  */
 	short winx, winy;				/* size */
-	/* Global areas have a non-dynamic size. That means, changing the window
-	 * size doesn't affect their size at all. However, they can still be
-	 * 'collapsed', by changing this value. Ignores DPI (ED_area_global_size_y
-	 * and winx/winy don't) */
-	short cur_fixed_height;
-	/* For global areas, this is the min and max size they can use depending on
-	 * if they are 'collapsed' or not. Value is set on area creation and not
-	 * touched afterwards. */
-	short size_min, size_max;
-	short pad2;
 
 	short headertype;				/* OLD! 0=no header, 1= down, 2= up */
 	short do_refresh;				/* private, for spacetype refresh callback */
@@ -256,6 +263,9 @@ typedef struct ScrArea {
 	
 	struct SpaceType *type;		/* callbacks for this space type */
 
+	/* Non-NULL if this area is global. */
+	ScrGlobalAreaData *global;
+
 	/* A list of space links (editors) that were open in this area before. When
 	 * changing the editor type, we try to reuse old editor data from this list.
 	 * The first item is the active/visible one.
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index d3edcaa5ffc..166d97d6b5e 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -2109,7 +2109,7 @@ int WM_window_screen_pixels_y(const wmWindow *win)
 	short screen_size_y = WM_window_pixels_y(win);
 
 	for (ScrArea *sa = win->global_areas.areabase.first; sa; sa = sa->next) {
-		screen_size_y -= ED_area_global_size_y(win, sa);
+		screen_size_y -= ED_area_global_size_y(sa);
 	}
 
 	return screen_size_y;



More information about the Bf-blender-cvs mailing list