Commit: 4422ecbb960e88c1b63ebaa325d5d44d052d095f
Author: Campbell Barton
Date:   Wed Jan 21 16:27:21 2015 +1100
Branches: master
https://developer.blender.org/rB4422ecbb960e88c1b63ebaa325d5d44d052d095f

UI: support alt+wheel for expanded enums

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

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

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

diff --git a/source/blender/editors/interface/interface_handlers.c 
b/source/blender/editors/interface/interface_handlers.c
index 5527d37..d9023b9 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -114,6 +114,7 @@
 static void ui_but_smart_controller_add(bContext *C, uiBut *from, uiBut *to);
 static void ui_but_link_add(bContext *C, uiBut *from, uiBut *to);
 static int ui_do_but_EXIT(bContext *C, uiBut *but, struct uiHandleButtonData 
*data, const wmEvent *event);
+static bool ui_but_find_select_in_enum__cmp(const uiBut *but_a, const uiBut 
*but_b);
 
 #ifdef USE_KEYNAV_LIMIT
 static void ui_mouse_motion_keynav_init(struct uiKeyNavLock *keynav, const 
wmEvent *event);
@@ -3348,6 +3349,38 @@ static int ui_do_but_TOG(bContext *C, uiBut *but, 
uiHandleButtonData *data, cons
                        button_activate_state(C, but, BUTTON_STATE_EXIT);
                        return WM_UI_HANDLER_BREAK;
                }
+               else if (ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && 
event->alt) {
+                       /* Support alt+wheel on expanded enum rows */
+                       if (but->type == UI_BTYPE_ROW) {
+                               const int direction = (event->type == 
WHEELDOWNMOUSE) ? -1 : 1;
+                               uiBut *but_select = 
ui_but_find_select_in_enum(but, direction);
+                               if (but_select) {
+                                       uiBut *but_other = (direction == -1) ? 
but_select->next : but_select->prev;
+                                       if (but_other && 
ui_but_find_select_in_enum__cmp(but, but_other)) {
+                                               ARegion *ar = data->region;
+
+                                               data->cancel = true;
+                                               button_activate_exit(C, but, 
data, false, false);
+
+                                               /* Activate the text button. */
+                                               button_activate_init(C, ar, 
but_other, BUTTON_ACTIVATE_OVER);
+                                               data = but_other->active;
+                                               if (data) {
+                                                       ui_apply_but(C, 
but->block, but_other, but_other->active, true);
+                                                       button_activate_exit(C, 
but_other, data, false, false);
+
+                                                       /* restore active 
button */
+                                                       button_activate_init(C, 
ar, but, BUTTON_ACTIVATE_OVER);
+                                               }
+                                               else {
+                                                       /* shouldn't happen */
+                                                       BLI_assert(0);
+                                               }
+                                       }
+                               }
+                               return WM_UI_HANDLER_BREAK;
+                       }
+               }
        }
        return WM_UI_HANDLER_CONTINUE;
 }
@@ -6597,6 +6630,45 @@ static bool ui_but_isect_pie_seg(uiBlock *block, uiBut 
*but)
        return false;
 }
 
+static bool ui_but_find_select_in_enum__cmp(const uiBut *but_a, const uiBut 
*but_b)
+{
+       return ((but_a->type == but_b->type) &&
+               (but_a->alignnr == but_b->alignnr) &&
+               (but_a->poin == but_b->poin) &&
+               (but_a->rnapoin.type == but_b->rnapoin.type) &&
+               (but_a->rnaprop == but_b->rnaprop));
+}
+
+/**
+ * Finds the pressed button in an aligned row (typically an expanded enum).
+ *
+ * \param direction  Use when there may be multiple buttons pressed.
+ */
+uiBut *ui_but_find_select_in_enum(uiBut *but, int direction)
+{
+       uiBut *but_iter = but;
+       uiBut *but_found = NULL;
+       BLI_assert(ELEM(direction, -1, 1));
+
+       while ((but_iter->prev) &&
+              ui_but_find_select_in_enum__cmp(but_iter->prev, but))
+       {
+               but_iter = but_iter->prev;
+       }
+
+       while (but_iter && ui_but_find_select_in_enum__cmp(but_iter, but)) {
+               if (but_iter->flag & UI_SELECT) {
+                       but_found = but_iter;
+                       if (direction == 1) {
+                               break;
+                       }
+               }
+               but_iter = but_iter->next;
+       }
+
+       return but_found;
+}
+
 uiBut *ui_but_find_active_in_region(ARegion *ar)
 {
        uiBlock *block;
diff --git a/source/blender/editors/interface/interface_intern.h 
b/source/blender/editors/interface/interface_intern.h
index 54ba3d7..458e268 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -616,6 +616,7 @@ extern void ui_but_active_free(const struct bContext *C, 
uiBut *but);
 extern bool ui_but_is_active(struct ARegion *ar) ATTR_WARN_UNUSED_RESULT;
 extern int ui_but_menu_direction(uiBut *but);
 extern void ui_but_text_password_hide(char password_str[UI_MAX_DRAW_STR], 
uiBut *but, const bool restore);
+extern uiBut *ui_but_find_select_in_enum(uiBut *but, int direction);
 extern uiBut *ui_but_find_active_in_region(struct ARegion *ar);
 bool ui_but_is_editable(const uiBut *but);
 bool ui_but_is_editable_as_text(const uiBut *but);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to