[Bf-blender-cvs] [4c21e2b] master: UI: split ui_popup_menu_memory into get/set functions and store as uint

Campbell Barton noreply at git.blender.org
Thu Feb 13 00:01:19 CET 2014


Commit: 4c21e2b3825ef21e29f179584109a7974a185f3d
Author: Campbell Barton
Date:   Thu Feb 13 09:36:54 2014 +1100
https://developer.blender.org/rB4c21e2b3825ef21e29f179584109a7974a185f3d

UI: split ui_popup_menu_memory into get/set functions and store as uint

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

M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_regions.c

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

diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index ec6065c..85afc05 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -6764,7 +6764,7 @@ static void button_activate_exit(bContext *C, uiBut *but, uiHandleButtonData *da
 
 		/* popup menu memory */
 		if (block->flag & UI_BLOCK_POPUP_MEMORY)
-			ui_popup_menu_memory(block, but);
+			ui_popup_menu_memory_set(block, but);
 	}
 
 	/* disable tooltips until mousemove + last active flag */
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index d3378af..29f5619 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -293,7 +293,7 @@ struct uiBlock {
 	rctf rect;
 	float aspect;
 
-	int puphash;  /* popup menu hash for memory */
+	unsigned int puphash;  /* popup menu hash for memory */
 
 	uiButHandleFunc func;
 	void *func_arg1;
@@ -466,7 +466,8 @@ uiBlock *ui_block_func_COLOR(struct bContext *C, uiPopupBlockHandle *handle, voi
 struct ARegion *ui_tooltip_create(struct bContext *C, struct ARegion *butregion, uiBut *but);
 void ui_tooltip_free(struct bContext *C, struct ARegion *ar);
 
-uiBut *ui_popup_menu_memory(struct uiBlock *block, struct uiBut *but);
+uiBut *ui_popup_menu_memory_get(struct uiBlock *block);
+void   ui_popup_menu_memory_set(struct uiBlock *block, struct uiBut *but);
 
 float *ui_block_hsv_get(struct uiBlock *block);
 void ui_popup_block_scrolltest(struct uiBlock *block);
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index 67ae883..fadfe09 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -2037,7 +2037,7 @@ uiBlock *ui_block_func_COLOR(bContext *C, uiPopupBlockHandle *handle, void *arg_
 
 /************************ Popup Menu Memory ****************************/
 
-static int ui_popup_string_hash(const char *str)
+static unsigned int ui_popup_string_hash(const char *str)
 {
 	/* sometimes button contains hotkey, sometimes not, strip for proper compare */
 	int hash;
@@ -2050,16 +2050,19 @@ static int ui_popup_string_hash(const char *str)
 	return hash;
 }
 
-static int ui_popup_menu_hash(const char *str)
+static unsigned int ui_popup_menu_hash(const char *str)
 {
 	return BLI_ghashutil_strhash(str);
 }
 
 /* but == NULL read, otherwise set */
-uiBut *ui_popup_menu_memory(uiBlock *block, uiBut *but)
+static uiBut *ui_popup_menu_memory__internal(uiBlock *block, uiBut *but)
 {
-	static int mem[256], first = 1;
-	int hash = block->puphash;
+	static unsigned int mem[256];
+	static bool first = false;
+
+	const unsigned int hash = block->puphash;
+	const unsigned int hash_mod = hash & 255;
 	
 	if (first) {
 		/* init */
@@ -2069,19 +2072,29 @@ uiBut *ui_popup_menu_memory(uiBlock *block, uiBut *but)
 
 	if (but) {
 		/* set */
-		mem[hash & 255] = ui_popup_string_hash(but->str);
+		mem[hash_mod] = ui_popup_string_hash(but->str);
 		return NULL;
 	}
 	else {
 		/* get */
 		for (but = block->buttons.first; but; but = but->next)
-			if (ui_popup_string_hash(but->str) == mem[hash & 255])
+			if (ui_popup_string_hash(but->str) == mem[hash_mod])
 				return but;
 
 		return NULL;
 	}
 }
 
+uiBut *ui_popup_menu_memory_get(uiBlock *block)
+{
+	return ui_popup_menu_memory__internal(block, NULL);
+}
+
+void ui_popup_menu_memory_set(uiBlock *block, uiBut *but)
+{
+	ui_popup_menu_memory__internal(block, but);
+}
+
 /******************** Popup Menu with callback or string **********************/
 
 struct uiPopupMenu {
@@ -2156,7 +2169,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi
 
 		/* offset the mouse position, possibly based on earlier selection */
 		if ((block->flag & UI_BLOCK_POPUP_MEMORY) &&
-		    (bt = ui_popup_menu_memory(block, NULL)))
+		    (bt = ui_popup_menu_memory_get(block)))
 		{
 			/* position mouse on last clicked item, at 0.8*width of the
 			 * button, so it doesn't overlap the text too much, also note




More information about the Bf-blender-cvs mailing list