WM: remove hard-coded circle radius memory
authorCampbell Barton <ideasman42@gmail.com>
Mon, 16 Oct 2017 04:32:09 +0000 (15:32 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 16 Oct 2017 04:32:09 +0000 (15:32 +1100)
Replace with operator type 'last_properties'.

Also use generic function for circle gesture properties.

13 files changed:
source/blender/editors/gpencil/gpencil_select.c
source/blender/editors/mask/mask_select.c
source/blender/editors/space_action/action_select.c
source/blender/editors/space_clip/tracking_select.c
source/blender/editors/space_graph/graph_select.c
source/blender/editors/space_node/node_select.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_gesture.c
source/blender/windowmanager/intern/wm_operator_props.c
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/wm.h

index 2912a1ac4eb628fc8cabffe36cafbcb28e4e5215..700a1dc943976b1659eeb51f5faea42477b16ef5 100644 (file)
@@ -830,10 +830,7 @@ void GPENCIL_OT_select_circle(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* properties */
-       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", 1, 1, INT_MAX, "Radius", "", 1, INT_MAX);
-       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
+       WM_operator_properties_gesture_circle(ot);
 }
 
 /* ********************************************** */
index a4268bddaf545fc2b7283be90f6473e851e0a0b9..990b07066b16cf3f36c359471dc6ca267d70f8c3 100644 (file)
@@ -681,10 +681,7 @@ void MASK_OT_select_circle(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        /* properties */
-       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", 1, 1, INT_MAX, "Radius", "", 1, INT_MAX);
-       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
+       WM_operator_properties_gesture_circle(ot);
 }
 
 static int mask_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
index 17edbc6cc1dbdbf5040c1e2648711d4ab07ea2a8..6d785e1f7dfb6fd5ea2dcb23880cf5ee3344da22 100644 (file)
@@ -629,11 +629,9 @@ void ACTION_OT_select_circle(wmOperatorType *ot)
        
        /* flags */
        ot->flag = OPTYPE_UNDO;
-       
-       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", 1, 1, INT_MAX, "Radius", "", 1, INT_MAX);
-       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
+
+       /* properties */
+       WM_operator_properties_gesture_circle(ot);
 }
 
 /* ******************** Column Select Operator **************************** */
index e970b1b97433123c3cc6b9e18f7285cd66a640d4..3cbf1cf4e0cab6bb8f10bd72936a52063c58c41d 100644 (file)
@@ -782,10 +782,7 @@ void CLIP_OT_select_circle(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        /* properties */
-       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", 1, 1, INT_MAX, "Radius", "", 1, INT_MAX);
-       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
+       WM_operator_properties_gesture_circle(ot);
 }
 
 /********************** select all operator *********************/
index 67b960bfa534f77a92e3d74c120b73dc48793e36..dd4449b77f712c358a34aa55076b629019c80490 100644 (file)
@@ -555,11 +555,9 @@ void GRAPH_OT_select_circle(wmOperatorType *ot)
        
        /* flags */
        ot->flag = OPTYPE_UNDO;
-       
-       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", 1, 1, INT_MAX, "Radius", "", 1, INT_MAX);
-       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
+
+       /* properties */
+       WM_operator_properties_gesture_circle(ot);
 }
 
 /* ******************** Column Select Operator **************************** */
index 7195d2a9838777571d076fa61d0e624223a14e9c..f7b8f53a63f16c3b946516b9a4c292fb4722a29a 100644 (file)
@@ -647,11 +647,8 @@ void NODE_OT_select_circle(wmOperatorType *ot)
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
-       /* rna */
-       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", 1, 1, INT_MAX, "Radius", "", 1, INT_MAX);
-       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
+       /* properties */
+       WM_operator_properties_gesture_circle(ot);
 }
 
 /* ****** Lasso Select ****** */
index 7d927766bbd1c8ee7c9dffaaf81087c2919a79c7..7f99a81ba994c8bd15d76c0f1387e0a1dc7ce545 100644 (file)
@@ -2896,9 +2896,7 @@ void VIEW3D_OT_select_circle(wmOperatorType *ot)
        
        /* flags */
        ot->flag = OPTYPE_UNDO;
-       
-       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", 1, 1, INT_MAX, "Radius", "", 1, INT_MAX);
-       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
+
+       /* properties */
+       WM_operator_properties_gesture_circle(ot);
 }
index 75294af08f9df06fb92e574e14b19ff1624cddce..8dbe22b7ffe824fe98c17738fed073d7179c0076 100644 (file)
@@ -3088,12 +3088,9 @@ static void UV_OT_circle_select(wmOperatorType *ot)
        
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-       
+
        /* properties */
-       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", 1, 1, INT_MAX, "Radius", "", 1, INT_MAX);
-       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
+       WM_operator_properties_gesture_circle(ot);
 }
 
 
index 7c1c388bcba9639e53099f463d3404ef74c328b3..d91c4a4efe0a845edb462b045bcda64e4d7c389f 100644 (file)
@@ -309,8 +309,9 @@ void        WM_operator_properties_border(struct wmOperatorType *ot);
 void        WM_operator_properties_border_to_rcti(struct wmOperator *op, struct rcti *rect);
 void        WM_operator_properties_border_to_rctf(struct wmOperator *op, rctf *rect);
 void        WM_operator_properties_gesture_border(struct wmOperatorType *ot, bool extend);
-void        WM_operator_properties_mouse_select(struct wmOperatorType *ot);
 void        WM_operator_properties_gesture_straightline(struct wmOperatorType *ot, int cursor);
+void        WM_operator_properties_gesture_circle(struct wmOperatorType *ot);
+void        WM_operator_properties_mouse_select(struct wmOperatorType *ot);
 void        WM_operator_properties_select_all(struct wmOperatorType *ot);
 void        WM_operator_properties_select_action(struct wmOperatorType *ot, int default_action);
 void        WM_operator_properties_select_action_simple(struct wmOperatorType *ot, int default_action);
index f66efa72908a4cffc3960a9e0b0635421fda47d4..11f39dc934ca50a6e3d3c7c6389b784f0fa37b23 100644 (file)
@@ -84,11 +84,7 @@ wmGesture *WM_gesture_new(bContext *C, const wmEvent *event, int type)
                rect->xmin = event->x - sx;
                rect->ymin = event->y - sy;
                if (type == WM_GESTURE_CIRCLE) {
-#ifdef GESTURE_MEMORY
-                       rect->xmax = circle_select_size;
-#else
-                       rect->xmax = 25;    // XXX temp
-#endif
+                       /* caller is responsible for initializing 'xmax' to radius. */
                }
                else {
                        rect->xmax = event->x - sx;
index 18836f34c9976341a0c4d7cdc77e7585aeea7820..2a44b4997a297c633fdb417c6899313c19299abb 100644 (file)
@@ -224,6 +224,9 @@ void WM_operator_properties_border_to_rctf(struct wmOperator *op, rctf *rect)
        BLI_rctf_rcti_copy(rect, &rect_i);
 }
 
+/**
+ * Use with #WM_border_select_invoke
+ */
 void WM_operator_properties_gesture_border(wmOperatorType *ot, bool extend)
 {
        RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
@@ -235,19 +238,9 @@ void WM_operator_properties_gesture_border(wmOperatorType *ot, bool extend)
        }
 }
 
-void WM_operator_properties_mouse_select(wmOperatorType *ot)
-{
-       PropertyRNA *prop;
-
-       prop = RNA_def_boolean(ot->srna, "extend", false, "Extend",
-                              "Extend selection instead of deselecting everything first");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "Remove from selection");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "toggle", false, "Toggle Selection", "Toggle the selection");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-}
-
+/**
+ * Use with #WM_gesture_straightline_invoke
+ */
 void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
 {
        PropertyRNA *prop;
@@ -268,6 +261,36 @@ void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
        }
 }
 
+/**
+ * Use with #WM_gesture_circle_invoke
+ */
+void WM_operator_properties_gesture_circle(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+       const int radius_default = 25;
+
+       prop = RNA_def_int(ot->srna, "x", 0, INT_MIN, INT_MAX, "X", "", INT_MIN, INT_MAX);
+       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
+       prop = RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX);
+       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
+       RNA_def_int(ot->srna, "radius", radius_default, 1, INT_MAX, "Radius", "", 1, INT_MAX);
+       prop = RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
+       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
+}
+
+void WM_operator_properties_mouse_select(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+
+       prop = RNA_def_boolean(ot->srna, "extend", false, "Extend",
+                              "Extend selection instead of deselecting everything first");
+       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+       prop = RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "Remove from selection");
+       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+       prop = RNA_def_boolean(ot->srna, "toggle", false, "Toggle Selection", "Toggle the selection");
+       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+}
+
 /**
  * \param nth_can_disable: Enable if we want to be able to select no interval at all.
  */
index 6fdc0a0a8c0c4f1c623aaff84057ed75baada11c..e4776ea7b29dc32963dcf94804b5217c974a9b72 100644 (file)
@@ -2394,14 +2394,15 @@ void WM_border_select_cancel(bContext *C, wmOperator *op)
 /* **************** 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, const wmEvent *event)
 {
        op->customdata = WM_gesture_new(C, event, WM_GESTURE_CIRCLE);
+       wmGesture *gesture = op->customdata;
+       rcti *rect = gesture->customdata;
        
+       /* Default or previously stored value. */
+       rect->xmax = RNA_int_get(op->ptr, "radius");
+
        /* add modal handler */
        WM_event_add_modal_handler(C, op);
        
@@ -2428,9 +2429,6 @@ static void gesture_circle_apply(bContext *C, wmOperator *op)
                retval = op->type->exec(C, op);
                OPERATOR_RETVAL_CHECK(retval);
        }
-#ifdef GESTURE_MEMORY
-       circle_select_size = rect->xmax;
-#endif
 }
 
 int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
@@ -2452,6 +2450,7 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
                }
        }
        else if (event->type == EVT_MODAL_MAP) {
+               bool is_circle_size = false;
                float fac;
                
                switch (event->val) {
@@ -2462,22 +2461,25 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
                                else
                                        rect->xmax += floor(fac);
                                if (rect->xmax < 1) rect->xmax = 1;
-                               wm_gesture_tag_redraw(C);
+                               is_circle_size = true;
                                break;
                        case GESTURE_MODAL_CIRCLE_ADD:
                                rect->xmax += 2 + rect->xmax / 10;
-                               wm_gesture_tag_redraw(C);
+                               is_circle_size = true;
                                break;
                        case GESTURE_MODAL_CIRCLE_SUB:
                                rect->xmax -= 2 + rect->xmax / 10;
                                if (rect->xmax < 1) rect->xmax = 1;
-                               wm_gesture_tag_redraw(C);
+                               is_circle_size = true;
                                break;
                        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);
+                       {
+                               PropertyRNA *prop = RNA_struct_find_property(op->ptr, "gesture_mode");
+                               if (prop != NULL) {
+                                       RNA_property_int_set(op->ptr, prop, event->val);
+                               }
 
                                if (event->val != GESTURE_MODAL_NOP) {
                                        /* apply first click */
@@ -2486,12 +2488,22 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
                                        wm_gesture_tag_redraw(C);
                                }
                                break;
-
+                       }
                        case GESTURE_MODAL_CANCEL:
                        case GESTURE_MODAL_CONFIRM:
+                               /* Normally we wouldn't store last-properties on cancel,
+                                * this is an exception since the circle tool is modal. */
+                               WM_operator_last_properties_store(op);
                                wm_gesture_end(C, op);
                                return OPERATOR_FINISHED; /* use finish or we don't get an undo */
                }
+
+               if (is_circle_size) {
+                       wm_gesture_tag_redraw(C);
+
+                       /* So next use remembers last seen size, even if we didn't apply it. */
+                       RNA_int_set(op->ptr, "radius", rect->xmax);
+               }
        }
 #ifdef WITH_INPUT_NDOF
        else if (event->type == NDOF_MOTION) {
@@ -2522,12 +2534,10 @@ void WM_OT_circle_gesture(wmOperatorType *ot)
        
        ot->invoke = WM_gesture_circle_invoke;
        ot->modal = WM_gesture_circle_modal;
-       
        ot->poll = WM_operator_winactive;
-       
-       RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
-       RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
-       RNA_def_property(ot->srna, "radius", PROP_INT, PROP_NONE);
+
+       /* properties */
+       WM_operator_properties_gesture_circle(ot);
 
 }
 #endif
index cb88ca3a474f250c6f81672f39f9051a21341dbb..c1cab8c8ff86f0006588d0f0382202a31ef8a0e8 100644 (file)
@@ -88,12 +88,4 @@ void wm_stereo3d_set_cancel(bContext *C, wmOperator *op);
 void wm_open_init_load_ui(wmOperator *op, bool use_prefs);
 void wm_open_init_use_scripts(wmOperator *op, bool use_prefs);
 
-/* 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__ */
-