[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37273] branches/cycles/source/blender/ editors: Cycles: UI tweak some quick code to auto hide scrollbars.

Brecht Van Lommel brechtvanlommel at pandora.be
Mon Jun 6 22:07:08 CEST 2011


Revision: 37273
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37273
Author:   blendix
Date:     2011-06-06 20:07:08 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
Cycles: UI tweak some quick code to auto hide scrollbars. Not happy with this
yet because it runs python draw functions twice when scrollers are showing.

Modified Paths:
--------------
    branches/cycles/source/blender/editors/include/UI_interface.h
    branches/cycles/source/blender/editors/interface/interface_panel.c
    branches/cycles/source/blender/editors/interface/interface_style.c
    branches/cycles/source/blender/editors/interface/view2d.c
    branches/cycles/source/blender/editors/screen/area.c

Modified: branches/cycles/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/cycles/source/blender/editors/include/UI_interface.h	2011-06-06 20:04:58 UTC (rev 37272)
+++ branches/cycles/source/blender/editors/include/UI_interface.h	2011-06-06 20:07:08 UTC (rev 37273)
@@ -583,6 +583,7 @@
 
 void uiBeginPanels(const struct bContext *C, struct ARegion *ar);
 void uiEndPanels(const struct bContext *C, struct ARegion *ar);
+void uiDrawPanels(const struct bContext *C, struct ARegion *ar);
 
 struct Panel *uiBeginPanel(struct ScrArea *sa, struct ARegion *ar, uiBlock *block, struct PanelType *pt, int *open);
 void uiEndPanel(uiBlock *block, int width, int height);

Modified: branches/cycles/source/blender/editors/interface/interface_panel.c
===================================================================
--- branches/cycles/source/blender/editors/interface/interface_panel.c	2011-06-06 20:04:58 UTC (rev 37272)
+++ branches/cycles/source/blender/editors/interface/interface_panel.c	2011-06-06 20:07:08 UTC (rev 37273)
@@ -846,7 +846,12 @@
 	
 	if(firstpa)
 		firstpa->runtime_flag |= PNL_FIRST;
+}
 
+void uiDrawPanels(const bContext *C, ARegion *ar)
+{
+	uiBlock *block;
+
 	UI_ThemeClearColor(TH_BACK);
 	
 	/* draw panels, selected on top */

Modified: branches/cycles/source/blender/editors/interface/interface_style.c
===================================================================
--- branches/cycles/source/blender/editors/interface/interface_style.c	2011-06-06 20:04:58 UTC (rev 37272)
+++ branches/cycles/source/blender/editors/interface/interface_style.c	2011-06-06 20:07:08 UTC (rev 37273)
@@ -122,7 +122,7 @@
 	style->buttonspacex= 8;
 	style->buttonspacey= 2;
 	style->panelspace= 8;
-	style->panelouter= 4;
+	style->panelouter= 3;
 	
 	return style;
 }

Modified: branches/cycles/source/blender/editors/interface/view2d.c
===================================================================
--- branches/cycles/source/blender/editors/interface/view2d.c	2011-06-06 20:04:58 UTC (rev 37272)
+++ branches/cycles/source/blender/editors/interface/view2d.c	2011-06-06 20:07:08 UTC (rev 37273)
@@ -278,10 +278,9 @@
 				v2d->align= (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
 				v2d->keeptot= V2D_KEEPTOT_BOUNDS;
 				
-				/*v2d->scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
+				v2d->scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
 				v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
-				v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE;*/
-				v2d->scroll= 0;
+				v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
 
 				v2d->tot.xmin= 0.0f;
 				v2d->tot.xmax= winx;
@@ -291,7 +290,7 @@
 				
 				v2d->cur.xmin= 0.0f;
 				/* bad workaround for keeping zoom level with scrollers */
-				v2d->cur.xmax= (winx/* - V2D_SCROLL_WIDTH*/)*panelzoom;
+				v2d->cur.xmax= (winx - V2D_SCROLL_WIDTH)*panelzoom;
 				
 				v2d->cur.ymax= 0.0f;
 				v2d->cur.ymin= (-winy)*panelzoom;

Modified: branches/cycles/source/blender/editors/screen/area.c
===================================================================
--- branches/cycles/source/blender/editors/screen/area.c	2011-06-06 20:04:58 UTC (rev 37272)
+++ branches/cycles/source/blender/editors/screen/area.c	2011-06-06 20:07:08 UTC (rev 37273)
@@ -1145,38 +1145,22 @@
 
 /************************ standard UI regions ************************/
 
-void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *context, int contextnr)
+static void region_panels_layout(const bContext *C, ARegion *ar, int vertical, const char *context, int w, int em, int *r_x, int *r_y)
 {
 	ScrArea *sa= CTX_wm_area(C);
-	uiStyle *style= U.uistyles.first;
-	uiBlock *block;
 	PanelType *pt;
 	Panel *panel;
-	View2D *v2d= &ar->v2d;
-	View2DScrollers *scrollers;
-	int xco, yco, x, y, miny=0, w, em, header, triangle, open, newcontext= 0;
+	uiBlock *block;
+	uiStyle *style= U.uistyles.first;
+	int x, y, miny=0, xco, yco;
+	int open, header, triangle;
 
-	if(contextnr >= 0)
-		newcontext= UI_view2d_tab_set(v2d, contextnr);
-
-	if(vertical) {
-		w= v2d->cur.xmax - v2d->cur.xmin;
-		em= (ar->type->prefsizex)? 10: 20;
-	}
-	else {
-		w= UI_PANEL_WIDTH;
-		em= (ar->type->prefsizex)? 10: 20;
-	}
-
 	x= 0;
 	y= -style->panelouter;
 
 	/* create panels */
 	uiBeginPanels(C, ar);
 
-	/* set view2d view matrix for scrolling (without scrollers) */
-	UI_view2d_view_ortho(v2d);
-
 	for(pt= ar->type->paneltypes.first; pt; pt= pt->next) {
 		/* verify context */
 		if(context)
@@ -1261,6 +1245,40 @@
 		y= UI_PANEL_WIDTH;
 	}
 
+	uiEndPanels(C, ar);
+
+	*r_x = x;
+	*r_y = y;
+}
+
+void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *context, int contextnr)
+{
+	View2D *v2d= &ar->v2d;
+	View2DScrollers *scrollers;
+	int x, y, w, em, newcontext= 0, need_scrollers;
+
+	if(contextnr >= 0)
+		newcontext= UI_view2d_tab_set(v2d, contextnr);
+
+	if(vertical) {
+		w= v2d->cur.xmax - v2d->cur.xmin;
+		em= (ar->type->prefsizex)? 10: 20;
+	}
+	else {
+		w= UI_PANEL_WIDTH;
+		em= (ar->type->prefsizex)? 10: 20;
+	}
+
+	/* try to draw without scrollbars */
+	UI_view2d_view_ortho(v2d);
+
+	region_panels_layout(C, ar, vertical, context, ar->winx, em, &x, &y);
+
+	/* if it doesn't fit, draw again in smaller space with scrollers */
+	need_scrollers = (abs(y) > ar->winy);
+	if(need_scrollers)
+		region_panels_layout(C, ar, vertical, context, ar->winx-V2D_SCROLL_WIDTH, em, &x, &y);
+
 	/* clear */
 	UI_ThemeClearColor((ar->type->regionid == RGN_TYPE_PREVIEW)?TH_PREVIEW_BACK:TH_BACK);
 	glClear(GL_COLOR_BUFFER_BIT);
@@ -1270,8 +1288,9 @@
 		/* only allow scrolling in vertical direction */
 		v2d->keepofs |= V2D_LOCKOFS_X|V2D_KEEPOFS_Y;
 		v2d->keepofs &= ~(V2D_LOCKOFS_Y|V2D_KEEPOFS_X);
-		//v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
-		//v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
+		v2d->scroll &= ~(V2D_SCROLL_HORIZONTAL_HIDE|V2D_SCROLL_VERTICAL_HIDE);
+		if(!need_scrollers)
+			v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
 		
 		// don't jump back when panels close or hide
 		if(!newcontext)
@@ -1286,8 +1305,9 @@
 		v2d->keepofs &= ~(V2D_LOCKOFS_X|V2D_LOCKOFS_Y|V2D_KEEPOFS_X|V2D_KEEPOFS_Y);
 		//v2d->keepofs |= V2D_LOCKOFS_Y|V2D_KEEPOFS_X;
 		//v2d->keepofs &= ~(V2D_LOCKOFS_X|V2D_KEEPOFS_Y);
-		//v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
-		//v2d->scroll &= ~V2D_SCROLL_HORIZONTAL_HIDE;
+		v2d->scroll &= ~(V2D_SCROLL_HORIZONTAL_HIDE|V2D_SCROLL_VERTICAL_HIDE);
+		if(!need_scrollers)
+			v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
 		
 		// don't jump back when panels close or hide
 		if(!newcontext)
@@ -1297,20 +1317,23 @@
 
 	// +V2D_SCROLL_HEIGHT is workaround to set the actual height
 	UI_view2d_totRect_set(v2d, x+V2D_SCROLL_WIDTH, y+V2D_SCROLL_HEIGHT);
+	UI_view2d_totRect_set(v2d, x+V2D_SCROLL_WIDTH, y+V2D_SCROLL_HEIGHT);
 
 	/* set the view */
 	UI_view2d_view_ortho(v2d);
 
 	/* this does the actual drawing! */
-	uiEndPanels(C, ar);
+	uiDrawPanels(C, ar);
 	
 	/* restore view matrix */
 	UI_view2d_view_restore(C);
 	
 	/* scrollers */
-	//scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
-	//UI_view2d_scrollers_draw(C, v2d, scrollers);
-	//UI_view2d_scrollers_free(scrollers);
+	if(need_scrollers) {
+		scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
+		UI_view2d_scrollers_draw(C, v2d, scrollers);
+		UI_view2d_scrollers_free(scrollers);
+	}
 }
 
 void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
@@ -1319,10 +1342,9 @@
 	
 	// XXX quick hacks for files saved with 2.5 already (i.e. the builtin defaults file)
 		// scrollbars for button regions
-	/*ar->v2d.scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM); 
+	ar->v2d.scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM); 
 	ar->v2d.scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
-	ar->v2d.scroll &= ~V2D_SCROLL_VERTICAL_HIDE;*/
-	ar->v2d.scroll= 0;
+	ar->v2d.scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
 	ar->v2d.keepzoom |= V2D_KEEPZOOM;
 
 		// correctly initialised User-Prefs?




More information about the Bf-blender-cvs mailing list