[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19496] branches/blender2.5/blender/source /blender: UI: various panels fixes.

Brecht Van Lommel brecht at blender.org
Thu Apr 2 03:39:35 CEST 2009


Revision: 19496
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19496
Author:   blendix
Date:     2009-04-02 03:39:33 +0200 (Thu, 02 Apr 2009)

Log Message:
-----------
UI: various panels fixes.

* Fix sometimes non-working close/open button.
* Fix panels being a bit out of the view on startup.
* Fix too large totrct region for view2d.
* Fix wrong panel order when changing vertical <-> horizontal.
* Fix wrong panel positions after switching contexts.
* Fix an access of freed memory when collapsing panels.

* Free align mode works again.
* Animations work again.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
    branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_panel.c
    branches/blender2.5/blender/source/blender/editors/interface/view2d.c
    branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_header.c
    branches/blender2.5/blender/source/blender/editors/space_buttons/space_buttons.c
    branches/blender2.5/blender/source/blender/editors/space_graph/graph_buttons.c
    branches/blender2.5/blender/source/blender/editors/space_image/image_panels.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_buttons.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_ui.c

Modified: branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h	2009-04-01 22:02:22 UTC (rev 19495)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_interface.h	2009-04-02 01:39:33 UTC (rev 19496)
@@ -496,19 +496,15 @@
 
 extern void uiNewPanelTabbed(char *, char *);
 extern int uiNewPanel(const struct bContext *C, struct ARegion *ar, uiBlock *block, char *panelname, char *tabname, int ofsx, int ofsy, int sizex, int sizey);
+
+extern void uiBeginPanels(const struct bContext *C, struct ARegion *ar);
+extern void uiEndPanels(const struct bContext *C, struct ARegion *ar);
 extern void uiFreePanels(struct ListBase *lb);
-extern void uiDrawPanels(const struct bContext *C, int re_align);
 	
-extern void uiSetPanelsView2d(struct ARegion *ar);
-extern void uiMatchPanelsView2d(struct ARegion *ar);
+extern void uiPanelsHome(struct ARegion *ar);
 
 extern void uiNewPanelHeight(struct uiBlock *block, int sizey);
 extern void uiNewPanelTitle(struct uiBlock *block, char *str);
-extern uiBlock *uiFindOpenPanelBlockName(struct ListBase *lb, char *name);
-extern int uiAlignPanelStep(struct ScrArea *sa, struct ARegion *ar, float fac);
-extern void uiPanelControl(int);
-extern void uiSetPanelHandler(int);
-
 struct Panel *uiPanelFromBlock(struct uiBlock *block);
 
 /* Handlers

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c	2009-04-01 22:02:22 UTC (rev 19495)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c	2009-04-02 01:39:33 UTC (rev 19496)
@@ -34,6 +34,8 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "interface_intern.h"
+
 /************************ Structs and Defines *************************/
 
 #define COLUMN_SPACE	5
@@ -918,7 +920,7 @@
 	PanelType *pt;
 	Panel *panel;
 	float col[3];
-	int xco, yco, x=0, y=0, w;
+	int xco, yco, x=PNL_DIST, y=-PNL_HEADER-PNL_DIST, w;
 
 	// XXX this only hides cruft
 
@@ -930,38 +932,43 @@
 	/* set view2d view matrix for scrolling (without scrollers) */
 	UI_view2d_view_ortho(C, &ar->v2d);
 	
+	uiBeginPanels(C, ar);
+
 	for(pt= ar->type->paneltypes.first; pt; pt= pt->next) {
 		if(context)
 			if(!pt->context || strcmp(context, pt->context) != 0)
 				continue;
 
 		if(pt->draw && (!pt->poll || pt->poll(C))) {
+			block= uiBeginBlock(C, ar, pt->idname, UI_EMBOSS, UI_HELV);
 			w= (ar->type->minsizex)? ar->type->minsizex-22: UI_PANEL_WIDTH-22;
 
-			block= uiBeginBlock(C, ar, pt->idname, UI_EMBOSS, UI_HELV);
-			if(uiNewPanel(C, ar, block, pt->name, pt->name, x, y, w, 0)==0) return;
-			
-			panel= uiPanelFromBlock(block);
-			panel->type= pt;
-			panel->layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, x, y, w, 0);
+			if(uiNewPanel(C, ar, block, pt->name, pt->name, x, y, w, 0)) {
+				panel= uiPanelFromBlock(block);
+				panel->type= pt;
+				panel->layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, x, y, w, 0);
 
-			pt->draw(C, panel);
+				pt->draw(C, panel);
 
-			uiLayoutEnd(C, block, panel->layout, &xco, &yco);
+				uiLayoutEnd(C, block, panel->layout, &xco, &yco);
+				panel->layout= NULL;
+				uiNewPanelHeight(block, y - yco + 6);
+			}
+			else {
+				w= PNL_HEADER;
+				yco= PNL_HEADER;
+			}
+
 			uiEndBlock(C, block);
 
-			panel->layout= NULL;
-			uiNewPanelHeight(block, y - yco + 6);
-
 			if(vertical)
-				y += yco;
+				y += yco+PNL_DIST;
 			else
-				x += xco;
+				x += w+PNL_DIST;
 		}
 	}
 
-	uiDrawPanels(C, 1);
-	uiMatchPanelsView2d(ar);
+	uiEndPanels(C, ar);
 	
 	/* restore view matrix? */
 	UI_view2d_view_restore(C);

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_panel.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_panel.c	2009-04-01 22:02:22 UTC (rev 19495)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_panel.c	2009-04-02 01:39:33 UTC (rev 19496)
@@ -100,7 +100,7 @@
 
 static int panel_aligned(ScrArea *sa, ARegion *ar)
 {
-	if(sa->spacetype==SPACE_BUTS) {
+	if(sa->spacetype==SPACE_BUTS && ar->regiontype == RGN_TYPE_WINDOW) {
 		SpaceButs *sbuts= sa->spacedata.first;
 		return sbuts->align;
 	}
@@ -110,6 +110,26 @@
 	return 0;
 }
 
+static int panels_re_align(ScrArea *sa, ARegion *ar)
+{
+	if(sa->spacetype==SPACE_BUTS && ar->regiontype == RGN_TYPE_WINDOW) {
+		SpaceButs *sbuts= sa->spacedata.first;
+
+		if(sbuts->align) {
+			if(sbuts->re_align || sbuts->mainbo!=sbuts->mainb || sbuts->tabo!=sbuts->tab[sbuts->mainb]) {
+				sbuts->re_align= 0;
+				return 1;
+			}
+		}
+
+		return 0;
+	}
+	else if(ar->regiontype==RGN_TYPE_UI)
+		return 1;
+	
+	return 0;
+}
+
 /* ************** panels ************* */
 
 static void copy_panel_offset(Panel *pa, Panel *papar)
@@ -317,7 +337,7 @@
 }
 
 // for 'home' key
-void uiSetPanelsView2d(ARegion *ar)
+void uiPanelsHome(ARegion *ar)
 {
 	Panel *pa;
 	uiBlock *block;
@@ -362,7 +382,7 @@
 }
 
 // make sure the panels are not outside 'tot' area
-void uiMatchPanelsView2d(ARegion *ar)
+static void ui_panels_update_totrct(ARegion *ar)
 {
 	Panel *pa;
 	uiBlock *block;
@@ -370,14 +390,22 @@
 	int done=0;
 	
 	v2d= &ar->v2d;
+
+	v2d->tot.xmin= 0.0f;
+	v2d->tot.xmax= ar->winx;
+	v2d->tot.ymax= 0.0f;
+	v2d->tot.ymin= -ar->winy;
 	
 	for(pa= ar->panels.first; pa; pa=pa->next) {
 		if(pa->active && pa->paneltab==NULL) {
 			done= 1;
-			if(pa->ofsx < v2d->tot.xmin) v2d->tot.xmin= pa->ofsx;
-			if(pa->ofsx+pa->sizex > v2d->tot.xmax) 
+
+			if(pa->ofsx < v2d->tot.xmin)
+				v2d->tot.xmin= pa->ofsx;
+			if(pa->ofsx+pa->sizex > v2d->tot.xmax)
 				v2d->tot.xmax= pa->ofsx+pa->sizex;
-			if(pa->ofsy < v2d->tot.ymin) v2d->tot.ymin= pa->ofsy;
+			if(pa->ofsy < v2d->tot.ymin)
+				v2d->tot.ymin= pa->ofsy;
 			if(pa->ofsy+pa->sizey+PNL_HEADER > v2d->tot.ymax) 
 				v2d->tot.ymax= pa->ofsy+pa->sizey+PNL_HEADER;
 		}
@@ -394,6 +422,8 @@
 			//XXX }
 		}
 	}	
+
+	UI_view2d_totRect_set(v2d, v2d->tot.xmax, v2d->tot.ymin);
 }
 
 /* extern used by previewrender */
@@ -877,8 +907,8 @@
 {
 	const PanelSort *ps1=a1, *ps2=a2;
 	
-	if( ps1->pa->ofsy < ps2->pa->ofsy) return 1;
-	else if( ps1->pa->ofsy > ps2->pa->ofsy) return -1;
+	if( ps1->pa->ofsy+ps1->pa->sizey < ps2->pa->ofsy+ps2->pa->sizey) return 1;
+	else if( ps1->pa->ofsy+ps1->pa->sizey > ps2->pa->ofsy+ps2->pa->sizey) return -1;
 	else if( ps1->pa->sortcounter > ps2->pa->sortcounter) return 1;
 	else if( ps1->pa->sortcounter < ps2->pa->sortcounter) return -1;
 	
@@ -938,7 +968,7 @@
 		ps->pa->ofsy= -ps->pa->sizey-PNL_HEADER-PNL_DIST;
 	else
 		ps->pa->ofsy= -ps->pa->sizey-PNL_HEADER-PNL_DIST; // XXX was 0;
-	
+
 	for(a=0 ; a<tot-1; a++, ps++) {
 		psnext= ps+1;
 	
@@ -1010,11 +1040,20 @@
 	}
 }
 
+void uiBeginPanels(const bContext *C, ARegion *ar)
+{
+	Panel *pa;
+  
+  	/* set all panels as inactive, so that at the end we know
+	 * which ones were used */
+	for(pa=ar->panels.first; pa; pa=pa->next)
+		pa->active= 0;
+}
+
 /* only draws blocks with panels */
-void uiDrawPanels(const bContext *C, int re_align)
+void uiEndPanels(const bContext *C, ARegion *ar)
 {
 	ScrArea *sa= CTX_wm_area(C);
-	ARegion *ar= CTX_wm_region(C);
 	uiBlock *block;
 	Panel *panot, *panew, *patest;
 	
@@ -1049,7 +1088,8 @@
 	}
 
 	/* re-align */
-	if(re_align) uiAlignPanelStep(sa, ar, 1.0);
+	if(panels_re_align(sa, ar))
+		uiAlignPanelStep(sa, ar, 1.0);
 	
 	if(sa->spacetype!=SPACE_BUTS) {
 #if 0 // XXX make float panel exception
@@ -1133,6 +1173,11 @@
 #endif
 	}
 
+	/* update v2d->totrct and update view */
+	ui_panels_update_totrct(ar);
+	UI_view2d_view_restore(C);
+	UI_view2d_view_ortho(C, &ar->v2d);
+
 	/* draw panels, selected on top */
 	for(block= ar->uiblocks.first; block; block=block->next) {
 		if(block->active && block->panel && !(block->panel->flag & PNL_SELECT)) {
@@ -1435,7 +1480,7 @@
 {
 	ARegion *ar= CTX_wm_region(C);
 	uiBlock *block;
-	int retval, mx, my, inside_header= 0, inside_scale= 0;
+	int retval, mx, my, inside_header= 0, inside_scale= 0, inside;
 
 	retval= WM_UI_HANDLER_CONTINUE;
 
@@ -1445,72 +1490,73 @@
 		ui_window_to_block(ar, block, &mx, &my);
 
 		/* check if inside boundbox */
+		inside= 0;
+
 		if(block->panel && block->panel->paneltab==NULL)
 			if(block->minx <= mx && block->maxx >= mx)
 				if(block->miny <= my && block->maxy+PNL_HEADER >= my)
-					break;
-	}
+					inside= 1;
 
-	if(!block)
-		return retval;
+		if(inside) {
+			/* clicked at panel header? */
+			if(block->panel->flag & PNL_CLOSEDX) {
+				if(block->minx <= mx && block->minx+PNL_HEADER >= mx) 
+					inside_header= 1;
+			}
+			else if((block->maxy <= my) && (block->maxy+PNL_HEADER >= my)) {
+				inside_header= 1;
+			}
+			else if(block->panel->control & UI_PNL_SCALE) {
+				if(block->maxx-PNL_HEADER <= mx)
+					if(block->miny+PNL_HEADER >= my)
+						inside_scale= 1;
+			}
 
-	/* clicked at panel header? */
-	if(block->panel->flag & PNL_CLOSEDX) {
-		if(block->minx <= mx && block->minx+PNL_HEADER >= mx) 
-			inside_header= 1;
-	}
-	else if((block->maxy <= my) && (block->maxy+PNL_HEADER >= my)) {
-		inside_header= 1;
-	}
-	else if(block->panel->control & UI_PNL_SCALE) {
-		if(block->maxx-PNL_HEADER <= mx)
-			if(block->miny+PNL_HEADER >= my)
-				inside_scale= 1;
-	}
+			if(event->val==KM_PRESS) {
+				if(event->type == LEFTMOUSE) {
+					if(inside_header)
+						ui_handle_panel_header(C, block, mx, my);
+					else if(inside_scale && !(block->panel->flag & PNL_CLOSED))
+						panel_activate_state(C, block->panel, PANEL_STATE_DRAG_SCALE);
+				}
+				else if(event->type == ESCKEY) {
+					/*XXX 2.50 if(block->handler) {
+						rem_blockhandler(sa, block->handler);
+						ED_region_tag_redraw(ar);
+						retval= WM_UI_HANDLER_BREAK;
+					}*/
+				}
+				else if(event->type==PADPLUSKEY || event->type==PADMINUS) {
+					int zoom=0;
+				
+					/* if panel is closed, only zoom if mouse is over the header */
+					if (block->panel->flag & (PNL_CLOSEDX|PNL_CLOSEDY)) {
+						if (inside_header)
+							zoom=1;
+					}
+					else
+						zoom=1;
 
-	if(event->val!=KM_PRESS)
-		return retval;
-
-	if(event->type == LEFTMOUSE) {
-		if(inside_header)
-			ui_handle_panel_header(C, block, mx, my);
-		else if(inside_scale && !(block->panel->flag & PNL_CLOSED))
-			panel_activate_state(C, block->panel, PANEL_STATE_DRAG_SCALE);
-	}
-	else if(event->type == ESCKEY) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list