diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-02-13 02:36:54 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-02-13 02:37:28 +0400 |
commit | 4c21e2b3825ef21e29f179584109a7974a185f3d (patch) | |
tree | 3f3b990acedfd0d69119e51931d2517fea469868 /source | |
parent | d4c87f2f79b674963a73ceee154226a1cd6d2acc (diff) |
UI: split ui_popup_menu_memory into get/set functions and store as uint
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 29 |
3 files changed, 25 insertions, 11 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index ec6065c0cfd..85afc057142 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 d3378af3de7..29f56192eb2 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 67ae883ba7e..fadfe097277 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 |