- converted circle select use a modal map
authorCampbell Barton <ideasman42@gmail.com>
Thu, 5 Nov 2009 17:32:06 +0000 (17:32 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 5 Nov 2009 17:32:06 +0000 (17:32 +0000)
- now works exactly like 2.4x, except that its accessed from the CKey
- hack to remember circle size, need some better way to do this

source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/windowmanager/intern/wm_gesture.c
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/wm.h
source/blender/windowmanager/wm_event_types.h

index 0c90347..04658df 100644 (file)
@@ -1917,17 +1917,20 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
        int x= RNA_int_get(op->ptr, "x");
        int y= RNA_int_get(op->ptr, "y");
        int radius= RNA_int_get(op->ptr, "radius");
+    int gesture_mode= RNA_int_get(op->ptr, "gesture_mode");
+    int selecting;
        
+    selecting= (gesture_mode==GESTURE_MODAL_SELECT);
+    
        if(CTX_data_edit_object(C) || (obact && obact->mode & OB_MODE_PARTICLE_EDIT)) {
                ViewContext vc;
-               short mval[2], selecting;
+               short mval[2];
                
                view3d_operator_needs_opengl(C);
                
                view3d_set_viewcontext(C, &vc);
                mval[0]= x;
                mval[1]= y;
-               selecting= LEFTMOUSE==RNA_int_get(op->ptr, "event_type"); // XXX solve
 
                if(CTX_data_edit_object(C)) {
                        obedit_circle_select(&vc, selecting, mval, (float)radius);
@@ -1938,7 +1941,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
        }
        else {
                Base *base;
-               
+               selecting= selecting?BA_SELECT:BA_DESELECT;
                for(base= FIRSTBASE; base; base= base->next) {
                        if(base->lay & v3d->lay) {
                                project_short(ar, base->object->obmat[3], &base->sx);
@@ -1946,7 +1949,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
                                        int dx= base->sx-x;
                                        int dy= base->sy-y;
                                        if( dx*dx + dy*dy < radius*radius)
-                                               ED_base_object_select(base, BA_SELECT);
+                                               ED_base_object_select(base, selecting);
                                }
                        }
                }
@@ -1974,5 +1977,5 @@ void VIEW3D_OT_select_circle(wmOperatorType *ot)
        RNA_def_int(ot->srna, "x", 0, INT_MIN, INT_MAX, "X", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "radius", 0, INT_MIN, INT_MAX, "Radius", "", INT_MIN, INT_MAX);
-       RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
 }
index 460f997..47f10ce 100644 (file)
@@ -2205,9 +2205,10 @@ int circle_select_exec(bContext *C, wmOperator *op)
        MTFace *tface;
        int x, y, radius, width, height, select;
        float zoomx, zoomy, offset[2], ellipse[2];
-
+    int gesture_mode= RNA_int_get(op->ptr, "gesture_mode");
+    
        /* get operator properties */
-       select= (RNA_int_get(op->ptr, "event_type") == LEFTMOUSE); // XXX hardcoded
+       select= (gesture_mode == GESTURE_MODAL_SELECT);
        x= RNA_int_get(op->ptr, "x");
        y= RNA_int_get(op->ptr, "y");
        radius= RNA_int_get(op->ptr, "radius");
@@ -2261,7 +2262,7 @@ void UV_OT_circle_select(wmOperatorType *ot)
        RNA_def_int(ot->srna, "x", 0, INT_MIN, INT_MAX, "X", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "radius", 0, INT_MIN, INT_MAX, "Radius", "", INT_MIN, INT_MAX);
-       RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
 }
 
 /* ******************** snap cursor operator **************** */
index 0547132..882da17 100644 (file)
@@ -76,9 +76,13 @@ wmGesture *WM_gesture_new(bContext *C, wmEvent *event, int type)
                gesture->customdata= rect;
                rect->xmin= event->x - sx;
                rect->ymin= event->y - sy;
-               if(type==WM_GESTURE_CIRCLE)
+               if(type==WM_GESTURE_CIRCLE) {
+#ifdef GESTURE_MEMORY
+                       rect->xmax= circle_select_size;
+#else
                        rect->xmax= 25; // XXX temp
-               else {
+#endif
+               } else {
                        rect->xmax= event->x - sx;
                        rect->ymax= event->y - sy;
                }
index b75292c..0c6897e 100644 (file)
@@ -81,6 +81,7 @@
 #include "wm.h"
 #include "wm_draw.h"
 #include "wm_event_system.h"
+#include "wm_event_types.h"
 #include "wm_subwindow.h"
 #include "wm_window.h"
 
@@ -1635,6 +1636,10 @@ int WM_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
 /* **************** circle gesture *************** */
 /* works now only for selection or modal paint stuff, calls exec while hold mouse, exit on release */
 
+#ifdef GESTURE_MEMORY
+int circle_select_size= 25; // XXX - need some operator memory thing\!
+#endif
+
 int WM_gesture_circle_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        op->customdata= WM_gesture_new(C, event, WM_GESTURE_CIRCLE);
@@ -1652,6 +1657,9 @@ static void gesture_circle_apply(bContext *C, wmOperator *op)
        wmGesture *gesture= op->customdata;
        rcti *rect= gesture->customdata;
        
+    if(RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_NOP)
+        return;
+
        /* operator arguments and storage. */
        RNA_int_set(op->ptr, "x", rect->xmin);
        RNA_int_set(op->ptr, "y", rect->ymin);
@@ -1659,6 +1667,10 @@ static void gesture_circle_apply(bContext *C, wmOperator *op)
        
        if(op->type->exec)
                op->type->exec(C, op);
+
+#ifdef GESTURE_MEMORY
+       circle_select_size= rect->xmax;
+#endif
 }
 
 int WM_gesture_circle_modal(bContext *C, wmOperator *op, wmEvent *event)
@@ -1667,52 +1679,48 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, wmEvent *event)
        rcti *rect= gesture->customdata;
        int sx, sy;
 
-       switch(event->type) {
-               case MOUSEMOVE:
-                       
-                       wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
-                       
-                       rect->xmin= event->x - sx;
-                       rect->ymin= event->y - sy;
-                       
-                       wm_gesture_tag_redraw(C);
-                       
-                       if(gesture->mode)
-                               gesture_circle_apply(C, op);
+       if(event->type== MOUSEMOVE) {
+               wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
 
-                       break;
-               case WHEELDOWNMOUSE:
-               case PADMINUS:
-               case MINUSKEY:
+               rect->xmin= event->x - sx;
+               rect->ymin= event->y - sy;
+
+               wm_gesture_tag_redraw(C);
+
+               if(gesture->mode)
+                       gesture_circle_apply(C, op);
+       }
+       else if (event->type==EVT_MODAL_MAP) {
+               switch (event->val) {
+               case GESTURE_MODAL_ADD:
                        rect->xmax += 2 + rect->xmax/10;
                        wm_gesture_tag_redraw(C);
                        break;
-               case WHEELUPMOUSE:
-               case PADPLUSKEY:
-               case EQUALKEY:
+               case GESTURE_MODAL_SUB:
                        rect->xmax -= 2 + rect->xmax/10;
                        if(rect->xmax < 1) rect->xmax= 1;
                        wm_gesture_tag_redraw(C);
                        break;
-               case LEFTMOUSE:
-//             case MIDDLEMOUSE: /* ??? - somehow mouse wheel are interpreted as middle mouse release events - campbell */
-               case RIGHTMOUSE:
-                       if(event->val==KM_RELEASE) {    /* key release */
-                               wm_gesture_end(C, op);
-                               return OPERATOR_FINISHED;
-                       } else {
-                               if( RNA_struct_find_property(op->ptr, "event_type") )
-                                       RNA_int_set(op->ptr, "event_type", event->type);
-                               
+               case GESTURE_MODAL_SELECT:
+               case GESTURE_MODAL_DESELECT:
+               case GESTURE_MODAL_NOP:
+                       if(RNA_struct_find_property(op->ptr, "gesture_mode"))
+                               RNA_int_set(op->ptr, "gesture_mode", event->val);
+
+                       if(event->val != GESTURE_MODAL_NOP) {
                                /* apply first click */
                                gesture_circle_apply(C, op);
                                gesture->mode= 1;
                        }
                        break;
-               case ESCKEY:
+
+               case GESTURE_MODAL_CANCEL:
+               case GESTURE_MODAL_CONFIRM:
                        wm_gesture_end(C, op);
                        return OPERATOR_CANCELLED;
+               }
        }
+
        return OPERATOR_RUNNING_MODAL;
 }
 
@@ -2359,6 +2367,53 @@ void wm_operatortype_init(void)
 
 }
 
+/* called in transform_ops.c, on each regeneration of keymaps  */
+static void gesture_circle_modal_keymap(wmKeyConfig *keyconf)
+{
+       static EnumPropertyItem modal_items[] = {
+       {GESTURE_MODAL_CANCEL,  "CANCEL", 0, "Cancel", ""},
+       {GESTURE_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
+       {GESTURE_MODAL_ADD, "ADD", 0, "Add", ""},
+       {GESTURE_MODAL_SUB, "SUBTRACT", 0, "Subtract", ""},
+
+       {GESTURE_MODAL_SELECT,  "SELECT", 0, "Select", ""},
+       {GESTURE_MODAL_DESELECT,"DESELECT", 0, "DeSelect", ""},
+       {GESTURE_MODAL_NOP,"NOP", 0, "No Operation", ""},
+
+
+       {0, NULL, 0, NULL, NULL}};
+
+       wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "View3D Gesture Circle");
+
+       /* this function is called for each spacetype, only needs to add map once */
+       if(keymap) return;
+
+       keymap= WM_modalkeymap_add(keyconf, "View3D Gesture Circle", modal_items);
+
+       /* items for modal map */
+       WM_modalkeymap_add_item(keymap, ESCKEY,    KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CANCEL);
+       WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_ANY, KM_ANY, 0, GESTURE_MODAL_CANCEL);
+
+       WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CONFIRM);
+       WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CONFIRM);
+
+       WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_SELECT);
+       WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_DESELECT);
+
+       WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, GESTURE_MODAL_NOP);
+       WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, GESTURE_MODAL_NOP);
+
+       WM_modalkeymap_add_item(keymap, PADPLUSKEY, KM_PRESS, 0, 0, GESTURE_MODAL_ADD);
+       WM_modalkeymap_add_item(keymap, PADMINUS, KM_PRESS, 0, 0, GESTURE_MODAL_SUB);
+       WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_ADD);
+       WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_SUB);
+
+       /* assign map to operators */
+       WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_circle");
+       WM_modalkeymap_assign(keymap, "UV_OT_circle_select");
+
+}
+
 /* default keymap for windows and screens, only call once per WM */
 void wm_window_keymap(wmKeyConfig *keyconf)
 {
@@ -2447,6 +2502,8 @@ void wm_window_keymap(wmKeyConfig *keyconf)
        km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F12KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
        RNA_string_set(km->ptr, "value", "DOPESHEET_EDITOR");
+
+       gesture_circle_modal_keymap(keyconf);
 }
 
 /* Generic itemf's for operators that take library args */
index 609b614..c476b7e 100644 (file)
@@ -76,5 +76,12 @@ void wm_autosave_delete(void);
 void wm_autosave_read(bContext *C, struct ReportList *reports);
 void wm_autosave_location(char *filename);
 
+/* hack to store circle select size - campbell, must replace with nice operator memory */
+#define GESTURE_MEMORY
+
+#ifdef GESTURE_MEMORY
+extern int circle_select_size;
+#endif
+
 #endif /* WM_H */
 
index c758879..a07f9f2 100644 (file)
 #define EVT_BUT_OPEN   0x5021
 #define EVT_MODAL_MAP  0x5022
 
-
+/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
+#define GESTURE_MODAL_CANCEL           1
+#define GESTURE_MODAL_CONFIRM          2
+#define GESTURE_MODAL_ADD                      3
+#define GESTURE_MODAL_SUB                      4
+
+#define GESTURE_MODAL_SELECT           5
+#define GESTURE_MODAL_DESELECT         6
+#define GESTURE_MODAL_NOP                      7
 
 #endif /* WM_EVENT_TYPES_H */