[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17769] branches/blender2.5/blender/source /blender:

Brecht Van Lommel brecht at blender.org
Wed Dec 10 05:37:02 CET 2008


Revision: 17769
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17769
Author:   blendix
Date:     2008-12-10 05:36:33 +0100 (Wed, 10 Dec 2008)

Log Message:
-----------

UI: don't use operators anymore for handling user interface events, but rather
a special UI handler which makes the code clearer. This UI handler is attached
to the region along with other handlers, and also gets a callback when all
handlers for the region are removed to ensure things are properly cleaned up.
This should fix XXX's in the UI code related to events and context switching.

Most of the changes are in interface_handlers.c, which was renamed from
interface_ops.c, to convert operators to the UI handler. UI code notes:
* uiBeginBlock/uiEndBlock/uiFreeBlocks now takes a context argument, this is
  required to properly cancel things like timers or tooltips when the region
  gets removed.
* UI_add_region_handlers will add the region level UI handlers, to be used
  when adding keymap handlers etc. This replaces the UI keymap.
* When the UI code starts a modal interaction (number sliding, text editing,
  opening a menu, ..), it will add an UI handler at the window level which
  will block events.

Windowmanager changes:
* Added an UI handler next to the existing keymap and operator modal handlers.
  It has an event handling and remove callback, and like operator modal handlers
  will remember the area and region if it is registered at the window level.
* Removed the MESSAGE event.
* Operator cancel and UI handler remove callbacks now get the
  window/area/region restored in the context, like the operator modal and UI
  handler event callbacks.
* Regions now receive MOUSEMOVE events for the mouse going outside of the
  region. This was already happening for areas, but UI buttons are at the region
  level so we need it there.

Issues:
* Tooltips and menus stay open when switching to another window, and button
  highlight doesn't work without moving the mouse first when Blender starts up.
  I tried using some events like Q_FIRSTTIME, WINTHAW, but those don't seem to
  arrive..
* Timeline header buttons seem to be moving one pixel or so sometimes when
  interacting with them.
* Seems not due to this commit, but UI and keymap handlers are leaking. It
  seems that handlers are being added to regions in all screens, also in regions
  of areas that are not visible, but these handlers are not removed. Probably
  there should only be handlers in visible regions?

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
    branches/blender2.5/blender/source/blender/editors/interface/interface.c
    branches/blender2.5/blender/source/blender/editors/interface/interface.h
    branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c
    branches/blender2.5/blender/source/blender/editors/screen/area.c
    branches/blender2.5/blender/source/blender/editors/screen/screen_edit.c
    branches/blender2.5/blender/source/blender/editors/screen/spacetypes.c
    branches/blender2.5/blender/source/blender/editors/space_outliner/space_outliner.c
    branches/blender2.5/blender/source/blender/editors/space_time/space_time.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_screen_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_image.c
    branches/blender2.5/blender/source/blender/windowmanager/WM_api.h
    branches/blender2.5/blender/source/blender/windowmanager/WM_types.h
    branches/blender2.5/blender/source/blender/windowmanager/intern/wm_event_system.c
    branches/blender2.5/blender/source/blender/windowmanager/wm_event_system.h
    branches/blender2.5/blender/source/blender/windowmanager/wm_event_types.h

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c

Removed Paths:
-------------
    branches/blender2.5/blender/source/blender/editors/interface/interface_ops.c

Modified: branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h	2008-12-10 03:13:48 UTC (rev 17768)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_interface.h	2008-12-10 04:36:33 UTC (rev 17769)
@@ -37,6 +37,8 @@
 struct wmWindowManager;
 struct AutoComplete;
 struct bContext;
+struct PointerRNA;
+struct PropertyRNA;
 
 /* uiBlock->dt */
 #define UI_EMBOSS		0	/* use one of the themes for drawing */
@@ -72,7 +74,7 @@
 #define UI_BLOCK_MOVEMOUSE_QUIT	128
 #define UI_BLOCK_KEEP_OPEN		256
 
-/* uiMenuBlockHandle->blockretval */
+/* uiMenuBlockHandle->menuretval */
 #define UI_RETURN_CANCEL	1       /* cancel all menus cascading */
 #define UI_RETURN_OK        2       /* choice made */
 #define UI_RETURN_OUT       4       /* left the menu */
@@ -167,50 +169,69 @@
 #define NUMABS	(36<<9)
 #define BUTTYPE	(63<<9)
 
-/* Menu Block Handle */
+typedef struct uiBut uiBut;
+typedef struct uiBlock uiBlock;
+
+/* Common Drawing Functions */
+
+void uiEmboss(float x1, float y1, float x2, float y2, int sel);
+void uiRoundBoxEmboss(float minx, float miny, float maxx, float maxy, float rad, int active);
+void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad);
+void uiSetRoundBox(int type);
+void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad);
+void uiDrawMenuBox(float minx, float miny, float maxx, float maxy, short flag);
+void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy);
+
+/* Popup Menu's */
+
 typedef struct uiMenuBlockHandle {
 	struct ARegion *region;
 	int butretval;
-	int blockretval;
+	int menuretval;
 
 	float retvalue;
 	float retvec[3];
 } uiMenuBlockHandle;
 
-typedef struct uiBut uiBut;
-typedef struct uiBlock uiBlock;
+typedef uiBlock* (*uiBlockFuncFP)(struct bContext *C, struct uiMenuBlockHandle *handle, void *arg1);
 
-void uiEmboss(float x1, float y1, float x2, float y2, int sel);
-void uiRoundBoxEmboss(float minx, float miny, float maxx, float maxy, float rad, int active);
-void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad);
-void uiSetRoundBox(int type);
-void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad);
+extern void pupmenu_set_active(int val);
+extern uiMenuBlockHandle *pupmenu_col(struct bContext *C, char *instr, int mx, int my, int maxrow);
+extern uiMenuBlockHandle *pupmenu(struct bContext *C, char *instr, int mx, int my);
+extern void pupmenu_free(struct bContext *C, uiMenuBlockHandle *handle);
 
-void uiDrawMenuBox(float minx, float miny, float maxx, float maxy, short flag);
-void uiTextBoundsBlock(uiBlock *block, int addval);
+/* Block */
+
+uiBlock *uiBeginBlock(const struct bContext *C, struct ARegion *region, char *name, short dt, short font);
+void uiEndBlock(const struct bContext *C, uiBlock *block);
+uiBlock *uiGetBlock(char *name, struct ARegion *ar);
+void uiFreeBlock(const struct bContext *C, uiBlock *block);
+void uiFreeBlocks(const struct bContext *C, struct ListBase *lb);
+
 void uiBoundsBlock(struct uiBlock *block, int addval);
 void uiDrawBlock(struct uiBlock *block);
-void uiGetMouse(int win, short *adr);
-void uiComposeLinks(uiBlock *block);
-void uiSetButLock(int val, char *lockstr);
-uiBut *uiFindInlink(uiBlock *block, void *poin);
-void uiClearButLock(void);
-int uiDoBlocks(struct ListBase *lb, int event, int movemouse_quit);
+void uiTextBoundsBlock(uiBlock *block, int addval);
+
+void uiBlockSetButLock(uiBlock *block, int val, char *lockstr);
+void uiBlockClearButLock(uiBlock *block);
+
+/* automatic aligning, horiz or verical */
+void uiBlockBeginAlign(uiBlock *block);
+void uiBlockEndAlign(uiBlock *block);
+
+/* Misc */
+
 void uiSetCurFont(uiBlock *block, int index);
+void *uiSetCurFont_ext(float aspect);
 void uiDefFont(unsigned int index, void *xl, void *large, void *medium, void *small);
-void uiFreeBlock(uiBlock *block);
-void uiFreeBlocks(struct ListBase *lb);
-uiBlock *uiBeginBlock(struct wmWindow *window, struct ARegion *region, char *name, short dt, short font);
-void uiEndBlock(uiBlock *block);
-uiBlock *uiGetBlock(char *name, struct ARegion *ar);
 
+void uiComposeLinks(uiBlock *block);
+uiBut *uiFindInlink(uiBlock *block, void *poin);
+
 void uiBlockPickerButtons(struct uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval);
 
+/* Defining Buttons */
 
-/* automatic aligning, horiz or verical */
-void uiBlockBeginAlign(uiBlock *block);
-void uiBlockEndAlign(uiBlock *block);
-
 uiBut *uiDefBut(uiBlock *block, 
 					   int type, int retval, char *str, 
 					   short x1, short y1, 
@@ -258,7 +279,6 @@
 uiBut *uiDefIDPoinBut(struct uiBlock *block, uiIDPoinFuncFP func, short blocktype, int retval, char *str,
 						short x1, short y1, short x2, short y2, void *idpp, char *tip);
 
-typedef uiBlock* (*uiBlockFuncFP)	(struct wmWindow *window, struct uiMenuBlockHandle *handle, void *arg1);
 uiBut *uiDefBlockBut(uiBlock *block, uiBlockFuncFP func, void *func_arg1, char *str, short x1, short y1, short x2, short y2, char *tip);
 uiBut *uiDefPulldownBut(uiBlock *block, uiBlockFuncFP func, void *func_arg1, char *str, short x1, short y1, short x2, short y2, char *tip);
 
@@ -267,8 +287,6 @@
 
 void uiDefKeyevtButS(uiBlock *block, int retval, char *str, short x1, short y1, short x2, short y2, short *spoin, char *tip);
 
-struct PointerRNA;
-struct PropertyRNA;
 uiBut *uiDefRNABut(uiBlock *block, int retval, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, short x1, short y1, short x2, short y2);
 void uiButSetFunc3(uiBut *but, void (*func)(void *arg1, void *arg2, void *arg3), void *arg1, void *arg2, void *arg3);
 
@@ -306,12 +324,8 @@
 
 void 	uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(struct ScrArea *sa, uiBlock *block));
 
+/* Panels */
 
-extern void pupmenu_set_active(int val);
-extern uiMenuBlockHandle *pupmenu_col(struct bContext *C, char *instr, int mx, int my, int maxrow);
-extern uiMenuBlockHandle *pupmenu(struct bContext *C, char *instr, int mx, int my);
-extern void pupmenu_free(struct bContext *C, uiMenuBlockHandle *handle);
-
 extern void uiFreePanels(struct ListBase *lb);
 extern void uiNewPanelTabbed(char *, char *);
 extern int uiNewPanel(struct ScrArea *sa, struct uiBlock *block, char *panelname, char *tabname, int ofsx, int ofsy, int sizex, int sizey);
@@ -329,8 +343,7 @@
 extern void uiPanelControl(int);
 extern void uiSetPanelHandler(int);
 
-extern void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy);
-extern void *uiSetCurFont_ext(float aspect);
+/* Autocomplete */
 
 typedef struct AutoComplete AutoComplete;
 
@@ -338,13 +351,17 @@
 void autocomplete_do_name(AutoComplete *autocpl, const char *name);
 void autocomplete_end(AutoComplete *autocpl, char *autoname);
 
-void uiTestRegion(const struct bContext *C); /* XXX 2.50 temporary test */
+/* Handlers for regions with UI blocks */
 
-void UI_keymap(struct wmWindowManager *wm);
-void UI_operatortypes(void);
+void UI_add_region_handlers(struct ListBase *handlers);
+
+/* Module initialization and exit */
+
 void UI_init(void);
 void UI_init_userdef(void);
 void UI_exit(void);
 
+void uiTestRegion(const struct bContext *C); /* XXX 2.50 temporary test */
+
 #endif /*  UI_INTERFACE_H */
 

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface.c	2008-12-10 03:13:48 UTC (rev 17768)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface.c	2008-12-10 04:36:33 UTC (rev 17769)
@@ -78,7 +78,7 @@
  * ui_blah_blah()	internal function
  */
 
-static void ui_free_but(uiBut *but);
+static void ui_free_but(const bContext *C, uiBut *but);
 
 /* ************ GLOBALS ************* */
 
@@ -109,8 +109,8 @@
 	float gx, gy;
 	int sx, sy, getsizex, getsizey;
 
-	getsizex= ar->winrct.xmax-ar->winrct.xmin;
-	getsizey= ar->winrct.ymax-ar->winrct.ymin;
+	getsizex= ar->winrct.xmax-ar->winrct.xmin+1;
+	getsizey= ar->winrct.ymax-ar->winrct.ymin+1;
 	sx= ar->winrct.xmin;
 	sy= ar->winrct.ymin;
 
@@ -152,8 +152,8 @@
 	float a, b, c, d, e, f, px, py;
 	int sx, sy, getsizex, getsizey;
 
-	getsizex= ar->winrct.xmax-ar->winrct.xmin;
-	getsizey= ar->winrct.ymax-ar->winrct.ymin;
+	getsizex= ar->winrct.xmax-ar->winrct.xmin+1;
+	getsizey= ar->winrct.ymax-ar->winrct.ymin+1;
 	sx= ar->winrct.xmin;
 	sy= ar->winrct.ymin;
 
@@ -426,7 +426,7 @@
 	return 1;
 }
 
-static int ui_but_update_from_old_block(uiBlock *block, uiBut *but)
+static int ui_but_update_from_old_block(const bContext *C, uiBlock *block, uiBut *but)
 {
 	uiBlock *oldblock;
 	uiBut *oldbut;
@@ -438,9 +438,9 @@
 
 	for(oldbut=oldblock->buttons.first; oldbut; oldbut=oldbut->next) {
 		if(ui_but_equals_old(oldbut, but)) {
-			if(oldbut->activate) {
+			if(oldbut->active) {
 				but->flag= oldbut->flag;
-				but->activate= oldbut->activate;
+				but->active= oldbut->active;
 				but->pos= oldbut->pos;
 				but->editstr= oldbut->editstr;
 				but->editval= oldbut->editval;
@@ -450,12 +450,14 @@
 				but->selsta= oldbut->selsta;
 				but->selend= oldbut->selend;
 				found= 1;
+
+				oldbut->active= NULL;
 			}
 
 			/* ensures one button can get activated, and in case the buttons
 			 * draw are the same this gives O(1) lookup for each button */
 			BLI_remlink(&oldblock->buttons, oldbut);
-			ui_free_but(oldbut);
+			ui_free_but(C, oldbut);
 			
 			break;
 		}
@@ -464,7 +466,7 @@
 	return found;
 }
 
-void uiEndBlock(uiBlock *block)
+void uiEndBlock(const bContext *C, uiBlock *block)
 {
 	uiBut *but;
 
@@ -473,14 +475,15 @@
 	 * blocking, while still alowing buttons to be remade each redraw as it
 	 * is expected by blender code */
 	for(but=block->buttons.first; but; but=but->next)
-		if(ui_but_update_from_old_block(block, but))
+		if(ui_but_update_from_old_block(C, block, but))
 			ui_check_but(but);
 
 	if(block->oldblock) {
 		block->auto_open= block->oldblock->auto_open;
 		block->auto_open_last= block->oldblock->auto_open_last;
+		block->tooltipdisabled= block->oldblock->tooltipdisabled;
 
-		uiFreeBlock(block->oldblock);
+		uiFreeBlock(C, block->oldblock);
 		block->oldblock= NULL;
 	}
 	
@@ -1340,21 +1343,22 @@
 	}
 }
 
-static void ui_free_but(uiBut *but)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list