WM: backport event/keymap type util from 2.8
authorCampbell Barton <ideasman42@gmail.com>
Fri, 8 Jun 2018 06:46:31 +0000 (08:46 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 8 Jun 2018 06:46:31 +0000 (08:46 +0200)
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_event_system.c

index 75b2cfffd03a3d1d7e7b738b48029ab8b366c016..3324fec4cac86e4d96db630deeb50d28012fd1b1 100644 (file)
@@ -143,6 +143,7 @@ float               WM_cursor_pressure      (const struct wmWindow *win);
 
                        /* event map */
 int                    WM_userdef_event_map(int kmitype);
+int                    WM_userdef_event_type_from_keymap_type(int kmitype);
 
                        /* handlers */
 
index 5974d4fddeead432a236582189ed00e0ea6532d1..b9feb4cba09a9f17a4e35bf3e1c5ddb1fb719b49 100644 (file)
@@ -1610,6 +1610,36 @@ int WM_userdef_event_map(int kmitype)
        return kmitype;
 }
 
+/**
+ * Use so we can check if 'wmEvent.type' is released in modal operators.
+ *
+ * An alternative would be to add a 'wmEvent.type_nokeymap'... or similar.
+ */
+int WM_userdef_event_type_from_keymap_type(int kmitype)
+{
+       switch (kmitype) {
+               case SELECTMOUSE:
+                       return (U.flag & USER_LMOUSESELECT) ? LEFTMOUSE : RIGHTMOUSE;
+               case ACTIONMOUSE:
+                       return (U.flag & USER_LMOUSESELECT) ? RIGHTMOUSE : LEFTMOUSE;
+               case EVT_TWEAK_S:
+                       return (U.flag & USER_LMOUSESELECT) ? LEFTMOUSE : RIGHTMOUSE;
+               case EVT_TWEAK_A:
+                       return (U.flag & USER_LMOUSESELECT) ? RIGHTMOUSE : LEFTMOUSE;
+               case EVT_TWEAK_L:
+                       return LEFTMOUSE;
+               case EVT_TWEAK_M:
+                       return MIDDLEMOUSE;
+               case EVT_TWEAK_R:
+                       return RIGHTMOUSE;
+               case WHEELOUTMOUSE:
+                       return (U.uiflag & USER_WHEELZOOMDIR) ? WHEELUPMOUSE : WHEELDOWNMOUSE;
+               case WHEELINMOUSE:
+                       return (U.uiflag & USER_WHEELZOOMDIR) ? WHEELDOWNMOUSE : WHEELUPMOUSE;
+       }
+
+       return kmitype;
+}
 
 static int wm_eventmatch(const wmEvent *winevent, wmKeyMapItem *kmi)
 {