[Bf-codereview] Non-modal menus (issue 6279046)
jorge at lunarworkshop.com
jorge at lunarworkshop.com
Sat Jun 2 19:54:15 CEST 2012
Reviewers: bf-codereview_blender.org,
Description:
Non-modal menus
Please review this at http://codereview.appspot.com/6279046/
Affected files:
M .
M source/blender/editors/interface/interface_handlers.c
M source/blender/windowmanager/intern/wm_event_system.c
Index: .
===================================================================
--- . (revision 47347)
+++ . (working copy)
Property changes on: .
___________________________________________________________________
Modified: svn:mergeinfo
Merged /branches/soc-2012-bratwurst:r47251-47253,47301,47346
Index: source/blender/editors/interface/interface_handlers.c
===================================================================
--- source/blender/editors/interface/interface_handlers.c (revision 47347)
+++ source/blender/editors/interface/interface_handlers.c (working copy)
@@ -5541,6 +5541,7 @@
static int ui_handle_button_over(bContext *C, wmEvent *event, ARegion *ar)
{
uiBut *but;
+ int retval = WM_UI_HANDLER_CONTINUE;
if (event->type == MOUSEMOVE) {
but = ui_but_find_mouse_over(ar, event->x, event->y);
@@ -5554,8 +5555,17 @@
ui_do_button(C, but->block, but, event);
}
}
+ else if (event->type == LEFTMOUSE) {
+ but = ui_but_find_mouse_over(ar, event->x, event->y);
+ /* If the user clicked a button, quickly activate it and then run its ui
stuff */
+ if (but)
+ {
+ button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER);
+ retval = ui_do_button(C, but->block, but, event);
+ }
+ }
- return WM_UI_HANDLER_CONTINUE;
+ return retval;
}
/* exported to interface.c: uiButActiveOnly() */
@@ -6054,6 +6064,12 @@
ui_menu_scroll(ar, block, my);
}
else {
+ // For these types to be called the mouse must be inside the block event.
+ int mousewheels = event->type == WHEELUPMOUSE || event->type ==
WHEELDOWNMOUSE;
+ int callblockevent = TRUE;
+ if (!inside && mousewheels)
+ callblockevent = FALSE;
+
/* for ui_mouse_motion_towards_block */
if (event->type == MOUSEMOVE) {
ui_mouse_motion_towards_init(menu, mx, my, 0);
@@ -6065,8 +6081,11 @@
WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER,
MENU_SCROLL_INTERVAL);
}
- /* first block own event func */
- if (block->block_event_func && block->block_event_func(C, block,
event)) ;
+ /* If we shouldn't call the block event function, it's because we're
running mouse wheels outside the block,
+ * so don't run other stuff either. We don't want it to cycle buttons in
this case. */
+ if (!callblockevent);
+ /* run the block event func */
+ else if (block->block_event_func && block->block_event_func(C, block,
event)) ;
/* events not for active search menu button */
else if (but == NULL || but->type != SEARCH_MENU) {
switch (event->type) {
@@ -6368,7 +6387,7 @@
/* if we set a menu return value, ensure we continue passing this on to
* lower menus and buttons, so always set continue then, and if we are
* inside the region otherwise, ensure we swallow the event */
- if (menu->menuretval)
+ if (menu->menuretval && menu->menuretval != UI_RETURN_UPDATE)
return WM_UI_HANDLER_CONTINUE;
else if (inside)
return WM_UI_HANDLER_BREAK;
@@ -6516,7 +6535,7 @@
ARegion *ar;
uiBut *but;
uiHandleButtonData *data;
- int retval;
+ int retval = WM_UI_HANDLER_CONTINUE;
/* here we handle buttons at the window level, modal, for example
* while number sliding, text editing, or when a menu block is open */
@@ -6542,6 +6561,9 @@
else
ui_handle_button_event(C, event, but);
}
+ /* If the menu keeps the input but wants an update anyway... */
+ else if (retval == WM_UI_HANDLER_BREAK && data->menu->menuretval ==
UI_RETURN_UPDATE)
+ ui_handle_button_return_submenu(C, event, but);
}
else {
/* handle events for the activated button */
@@ -6556,8 +6578,7 @@
/* delayed apply callbacks */
ui_apply_but_funcs_after(C);
- /* we block all events, this is modal interaction */
- return WM_UI_HANDLER_BREAK;
+ return retval;
}
/* two types of popups, one with operator + enum, other with regular
callbacks */
Index: source/blender/windowmanager/intern/wm_event_system.c
===================================================================
--- source/blender/windowmanager/intern/wm_event_system.c (revision 47347)
+++ source/blender/windowmanager/intern/wm_event_system.c (working copy)
@@ -331,19 +331,8 @@
ScrArea *area = CTX_wm_area(C);
ARegion *region = CTX_wm_region(C);
ARegion *menu = CTX_wm_menu(C);
- static int do_wheel_ui = TRUE;
- int is_wheel = ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE);
int retval;
- /* UI is quite aggressive with swallowing events, like scrollwheel */
- /* I realize this is not extremely nice code... when UI gets keymaps it
can be maybe smarter */
- if (do_wheel_ui == FALSE) {
- if (is_wheel)
- return WM_HANDLER_CONTINUE;
- else if (wm_event_always_pass(event) == 0)
- do_wheel_ui = TRUE;
- }
-
/* we set context to where ui handler came from */
if (handler->ui_area) CTX_wm_area_set(C, handler->ui_area);
if (handler->ui_region) CTX_wm_region_set(C, handler->ui_region);
@@ -367,10 +356,6 @@
if (retval == WM_UI_HANDLER_BREAK)
return WM_HANDLER_BREAK;
- /* event not handled in UI, if wheel then we temporarily disable it */
- if (is_wheel)
- do_wheel_ui = FALSE;
-
return WM_HANDLER_CONTINUE;
}
More information about the Bf-codereview
mailing list