[Bf-blender-cvs] [9525a41c32a] topbar: Split topbar into multiple aligned & independently scrollable sections

Julian Eisel noreply at git.blender.org
Tue Jul 11 14:51:46 CEST 2017


Commit: 9525a41c32a7041773c806b3597280c5766a8000
Author: Julian Eisel
Date:   Tue Jul 11 05:55:43 2017 +0200
Branches: topbar
https://developer.blender.org/rB9525a41c32a7041773c806b3597280c5766a8000

Split topbar into multiple aligned & independently scrollable sections

Done by adding multiple window/header region types.

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

M	release/scripts/startup/bl_ui/space_topbar.py
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_intern.h
M	source/blender/editors/space_topbar/space_topbar.c
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/makesrna/intern/rna_screen.c
M	source/blender/windowmanager/intern/wm_draw.c

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

diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index 43e366a9e24..028fd848c6e 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -25,12 +25,18 @@ class TOPBAR_HT_upper_bar(Header):
     bl_space_type = 'TOPBAR'
 
     def draw(self, context):
+        region = context.region
+
+        if region.alignment == 'RIGHT':
+            self.draw_right(context)
+        else:
+            self.draw_left(context)
+
+    def draw_left(self, context):
         layout = self.layout
 
         window = context.window
         screen = context.screen
-        scene = context.scene
-        rd = scene.render
 
         layout.operator("wm.splash", text="", icon='BLENDER', emboss=False)
 
@@ -43,13 +49,6 @@ class TOPBAR_HT_upper_bar(Header):
 
         layout.separator()
 
-        layout.template_ID(window, "scene", new="scene.new", unlink="scene.delete")
-
-        if rd.has_multiple_engines:
-            layout.prop(rd, "engine", text="")
-
-        layout.separator()
-
         layout.template_running_jobs()
 
         layout.template_reports_banner()
@@ -68,6 +67,18 @@ class TOPBAR_HT_upper_bar(Header):
             row.label(bpy.app.autoexec_fail_message)
             return
 
+    def draw_right(self, context):
+        layout = self.layout
+
+        window = context.window
+        scene = context.scene
+        rd = scene.render
+
+        if rd.has_multiple_engines:
+            layout.prop(rd, "engine", text="")
+
+        layout.template_ID(window, "scene", new="scene.new", unlink="scene.delete")
+
 
 class TOPBAR_HT_lower_bar(Header):
     bl_space_type = 'TOPBAR'
@@ -75,21 +86,30 @@ class TOPBAR_HT_lower_bar(Header):
 
     def draw(self, context):
         layout = self.layout
+        region = context.region
 
-        window = context.window
+        if region.alignment == 'LEFT':
+            self.draw_left(context)
+        elif region.alignment == 'RIGHT':
+            self.draw_right(context)
+        else:
+            layout.template_operator_redo()
+
+    def draw_left(self, context):
+        layout = self.layout
         workspace = context.workspace
-        screen = context.screen
-        scene = context.scene
 
         if hasattr(workspace, 'object_mode'):
             act_mode_item = bpy.types.Object.bl_rna.properties['mode'].enum_items[workspace.object_mode]
             layout.operator_menu_enum("object.mode_set", "mode", text=act_mode_item.name, icon=act_mode_item.icon)
 
-        layout.separator()
-
-        layout.template_operator_redo()
+    def draw_right(self, context):
+        layout = self.layout
 
-        layout.separator()
+        window = context.window
+        workspace = context.workspace
+        scene = context.scene
+        screen = context.screen
 
         if screen.show_fullscreen:
             layout.operator("screen.back_to_previous", icon='SCREEN_BACK', text="Back to Previous")
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 35eca8d9b02..b841d1d6b9e 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -116,6 +116,7 @@ int     ED_area_headersize(void);
 void    ED_screens_initialize(struct wmWindowManager *wm);
 void    ED_screen_draw(struct wmWindow *win);
 void    ED_screen_refresh(struct wmWindowManager *wm, struct wmWindow *win);
+void    ED_screen_ensure_updated(struct wmWindowManager *wm, struct wmWindow *win, struct bScreen *screen);
 void    ED_screen_do_listen(struct bContext *C, struct wmNotifier *note);
 bool    ED_screen_change(struct bContext *C, struct bScreen *sc);
 void    ED_screen_update_after_scene_change(const struct bScreen *screen, struct Scene *scene_new);
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 87ce6b6ac90..b7cc392ce41 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1477,6 +1477,20 @@ static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *hand
 	}
 }
 
+void screen_area_update_region_sizes(wmWindow *win, ScrArea *area)
+{
+	rcti rect = area->totrct;
+
+	/* region rect sizes */
+	region_rect_recursive(win, area, area->regionbase.first, &rect, 0, false);
+	for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
+		region_subwindow(win, ar, false);
+	}
+
+	/* XXX hack to force drawing */
+	ED_area_tag_redraw(area);
+	area->flag &= ~AREA_FLAG_REGION_SIZE_UPDATE;
+}
 
 /* called in screen_refresh, or screens_init, also area size changes */
 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
@@ -1507,6 +1521,7 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
 	/* region rect sizes */
 	rect = sa->totrct;
 	region_rect_recursive(win, sa, sa->regionbase.first, &rect, 0, true);
+	sa->flag &= ~AREA_FLAG_REGION_SIZE_UPDATE;
 	
 	/* default area handlers */
 	ed_default_handlers(wm, sa, &sa->handlers, sa->type->keymapflag);
@@ -2137,6 +2152,7 @@ void ED_region_header(const bContext *C, ARegion *ar)
 	Header header = {NULL};
 	int maxco, xco, yco;
 	int headery = ED_area_headersize();
+	const int start_ofs = 0.4f * UI_UNIT_X;
 
 	/* clear */
 	UI_ThemeClearColor((ED_screen_area_active(C) || (ar->regiontype != RGN_TYPE_HEADER)) ? TH_BACK : TH_HEADERDESEL);
@@ -2145,7 +2161,7 @@ void ED_region_header(const bContext *C, ARegion *ar)
 	/* set view2d view matrix for scrolling (without scrollers) */
 	UI_view2d_view_ortho(&ar->v2d);
 
-	xco = maxco = 0.4f * UI_UNIT_X;
+	xco = maxco = start_ofs;
 	yco = headery - floor(0.2f * UI_UNIT_Y);
 
 	/* draw all headers types */
@@ -2169,7 +2185,16 @@ void ED_region_header(const bContext *C, ARegion *ar)
 		/* for view2d */
 		if (xco > maxco)
 			maxco = xco;
-		
+
+		if (ar->flag & RGN_RESIZE_LAYOUT_BASED) {
+			ScrArea *sa = CTX_wm_area(C);
+
+			ar->sizex = maxco + start_ofs;
+			UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->sizex, ar->winy);
+
+			sa->flag |= AREA_FLAG_REGION_SIZE_UPDATE;
+			ar->flag &= ~RGN_RESIZE_LAYOUT_BASED;
+		}
 		UI_block_end(C, block);
 		UI_block_draw(C, block);
 	}
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index c66db21a8b5..ac2d7e0c32b 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -812,6 +812,21 @@ void ED_screens_initialize(wmWindowManager *wm)
 	}
 }
 
+void ED_screen_ensure_updated(wmWindowManager *wm, wmWindow *win, bScreen *screen)
+{
+	if (screen->do_refresh) {
+		ED_screen_refresh(wm, win);
+	}
+	else {
+		ED_screen_areas_iter(win, screen, area) {
+			if (area->flag & AREA_FLAG_REGION_SIZE_UPDATE) {
+				screen_area_update_region_sizes(win, area);
+				break;
+			}
+		}
+	}
+}
+
 
 /* *********** exit calls are for closing running stuff ******** */
 
diff --git a/source/blender/editors/screen/screen_intern.h b/source/blender/editors/screen/screen_intern.h
index bfe4e43a576..5a7557a529f 100644
--- a/source/blender/editors/screen/screen_intern.h
+++ b/source/blender/editors/screen/screen_intern.h
@@ -43,6 +43,7 @@ struct Main;
 /* area.c */
 void        ED_area_data_copy(ScrArea *sa_dst, ScrArea *sa_src, const bool do_free);
 void        ED_area_data_swap(ScrArea *sa1, ScrArea *sa2);
+void        screen_area_update_region_sizes(wmWindow *win, ScrArea *area);
 void        region_toggle_hidden(struct bContext *C, ARegion *ar, const bool do_fade);
 
 /* screen_edit.c */
diff --git a/source/blender/editors/space_topbar/space_topbar.c b/source/blender/editors/space_topbar/space_topbar.c
index 49db7473742..198699826c7 100644
--- a/source/blender/editors/space_topbar/space_topbar.c
+++ b/source/blender/editors/space_topbar/space_topbar.c
@@ -65,15 +65,25 @@ static SpaceLink *topbar_new(const bContext *UNUSED(C))
 	stopbar->spacetype = SPACE_TOPBAR;
 
 	/* header */
-	ar = MEM_callocN(sizeof(ARegion), "header for topbar");
-
+	ar = MEM_callocN(sizeof(ARegion), "left aligned header for topbar");
 	BLI_addtail(&stopbar->regionbase, ar);
 	ar->regiontype = RGN_TYPE_HEADER;
 	ar->alignment = RGN_ALIGN_TOP;
+	ar = MEM_callocN(sizeof(ARegion), "right aligned header for topbar");
+	BLI_addtail(&stopbar->regionbase, ar);
+	ar->regiontype = RGN_TYPE_HEADER;
+	ar->alignment = RGN_ALIGN_RIGHT | RGN_SPLIT_PREV;
 
-	/* main region */
-	ar = MEM_callocN(sizeof(ARegion), "main region for topbar");
-
+	/* main regions */
+	ar = MEM_callocN(sizeof(ARegion), "left aligned main region for topbar");
+	BLI_addtail(&stopbar->regionbase, ar);
+	ar->regiontype = RGN_TYPE_WINDOW;
+	ar->alignment = RGN_ALIGN_LEFT;
+	ar = MEM_callocN(sizeof(ARegion), "right aligned main region for topbar");
+	BLI_addtail(&stopbar->regionbase, ar);
+	ar->regiontype = RGN_TYPE_WINDOW;
+	ar->alignment = RGN_ALIGN_RIGHT;
+	ar = MEM_callocN(sizeof(ARegion), "center main region for topbar");
 	BLI_addtail(&stopbar->regionbase, ar);
 	ar->regiontype = RGN_TYPE_WINDOW;
 
@@ -109,6 +119,10 @@ static void topbar_main_region_init(wmWindowManager *wm, ARegion *region)
 {
 	wmKeyMap *keymap;
 
+	/* force delayed UI_view2d_region_reinit call */
+	if (ELEM(region->alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
+		region->flag |= RGN_RESIZE_LAYOUT_BASED;
+	}
 	UI_view2d_region_reinit(&region->v2d, V2D_COMMONVIEW_HEADER, region->winx, region->winy);
 
 	keymap = WM_keymap_find(wm->defaultconf, "View2D Buttons List", 0, 0);
@@ -133,6 +147,9 @@ static void topbar_keymap(struct wmKeyConfig *UNUSED(keyconf))
 /* add handlers, stuff you only do once or on area/region changes */
 static void topbar_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
 {
+	if ((ar->alignment & ~RGN_SPLIT_PREV) == RGN_ALIGN_RIGHT) {
+		ar->flag |= RGN_RESIZE_LAYOUT_BASED;
+	}
 	ED_region_header_init(ar);
 }
 
@@ -225,6 +242,7 @@ void ED_spacetype_topbar(void)
 	art->init = topbar_main_region_init;
 	art->draw = topbar_main_region_draw;
 	art->listener = topbar_main_region_listener;
+	art->prefsizex = UI_UNIT_X * 5; /* Mainly to avoid glitches */
 	art->keymapflag = ED_KEYMAP_UI;
 
 	BLI_addhead(&st->regiontypes, art);
@@ -233,6 +251,7 @@ void ED_spac

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list