Screen: support splitting from floating menu
authorCampbell Barton <ideasman42@gmail.com>
Mon, 2 Jul 2018 10:24:21 +0000 (12:24 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 2 Jul 2018 10:40:17 +0000 (12:40 +0200)
source/blender/editors/screen/screen_ops.c

index 411469b539bfa53b1148bd127fe720c4ef051a18..44467b6a99401bbc938e8af68d45fde4ace2e0a9 100644 (file)
@@ -1655,8 +1655,11 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
        int dir;
 
        /* no full window splitting allowed */
-       if (sc->state != SCREENNORMAL)
-               return OPERATOR_CANCELLED;
+       BLI_assert(sc->state == SCREENNORMAL);
+
+       PropertyRNA *prop_dir = RNA_struct_find_property(op->ptr, "direction");
+       PropertyRNA *prop_factor = RNA_struct_find_property(op->ptr, "factor");
+       PropertyRNA *prop_cursor = RNA_struct_find_property(op->ptr, "cursor");
 
        if (event->type == EVT_ACTIONZONE_AREA) {
                sActionzoneData *sad = event->customdata;
@@ -1676,46 +1679,69 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                /* prepare operator state vars */
                if (sad->gesture_dir == 'n' || sad->gesture_dir == 's') {
                        dir = 'h';
-                       RNA_float_set(op->ptr, "factor", ((float)(event->x - sad->sa1->v1->vec.x)) / (float)sad->sa1->winx);
+                       RNA_property_float_set(
+                               op->ptr, prop_factor,
+                               ((float)(event->x - sad->sa1->v1->vec.x)) / (float)sad->sa1->winx);
                }
                else {
                        dir = 'v';
-                       RNA_float_set(op->ptr, "factor", ((float)(event->y - sad->sa1->v1->vec.y)) / (float)sad->sa1->winy);
+                       RNA_property_float_set(
+                               op->ptr, prop_factor,
+                               ((float)(event->y - sad->sa1->v1->vec.y)) / (float)sad->sa1->winy);
                }
-               RNA_enum_set(op->ptr, "direction", dir);
+               RNA_property_enum_set(op->ptr, prop_dir, dir);
 
                /* general init, also non-UI case, adds customdata, sets area and defaults */
-               if (!area_split_init(C, op))
+               if (!area_split_init(C, op)) {
                        return OPERATOR_PASS_THROUGH;
+               }
+       }
+       else if (RNA_property_is_set(op->ptr, prop_dir)) {
+               ScrArea *sa = CTX_wm_area(C);
+               if (sa == NULL) {
+                       return OPERATOR_CANCELLED;
+               }
+               dir = RNA_property_enum_get(op->ptr, prop_dir);
+               if (dir == 'h') {
+                       RNA_property_float_set(
+                               op->ptr, prop_factor,
+                               ((float)(event->x - sa->v1->vec.x)) / (float)sa->winx);
+               }
+               else {
+                       RNA_property_float_set(
+                               op->ptr, prop_factor,
+                               ((float)(event->y - sa->v1->vec.y)) / (float)sa->winy);
+               }
 
+               if (!area_split_init(C, op)) {
+                       return OPERATOR_CANCELLED;
+               }
        }
        else {
                ScrEdge *actedge;
-               int x, y;
+               int event_co[2];
 
                /* retrieve initial mouse coord, so we can find the active edge */
-               if (RNA_struct_property_is_set(op->ptr, "mouse_x"))
-                       x = RNA_int_get(op->ptr, "mouse_x");
-               else
-                       x = event->x;
-
-               if (RNA_struct_property_is_set(op->ptr, "mouse_y"))
-                       y = RNA_int_get(op->ptr, "mouse_y");
-               else
-                       y = event->x;
+               if (RNA_property_is_set(op->ptr, prop_cursor)) {
+                       RNA_property_int_get_array(op->ptr, prop_cursor, event_co);
+               }
+               else {
+                       copy_v2_v2_int(event_co, &event->x);
+               }
 
-               actedge = screen_find_active_scredge(sc, winsize_x, winsize_y, x, y);
-               if (actedge == NULL)
+               actedge = screen_find_active_scredge(sc, winsize_x, winsize_y, event_co[0], event_co[1]);
+               if (actedge == NULL) {
                        return OPERATOR_CANCELLED;
+               }
 
                dir = scredge_is_horizontal(actedge) ? 'v' : 'h';
 
-               RNA_enum_set(op->ptr, "direction", dir);
+               RNA_property_enum_set(op->ptr, prop_dir, dir);
 
                /* special case, adds customdata, sets defaults */
-               if (!area_split_menu_init(C, op))
+               if (!area_split_menu_init(C, op)) {
                        return OPERATOR_CANCELLED;
-
+               }
        }
 
        sd = (sAreaSplitData *)op->customdata;
@@ -1913,8 +1939,7 @@ static void SCREEN_OT_area_split(wmOperatorType *ot)
        /* rna */
        RNA_def_enum(ot->srna, "direction", prop_direction_items, 'h', "Direction", "");
        RNA_def_float(ot->srna, "factor", 0.5f, 0.0, 1.0, "Factor", "", 0.0, 1.0);
-       RNA_def_int(ot->srna, "mouse_x", -100, INT_MIN, INT_MAX, "Mouse X", "", INT_MIN, INT_MAX);
-       RNA_def_int(ot->srna, "mouse_y", -100, INT_MIN, INT_MAX, "Mouse Y", "", INT_MIN, INT_MAX);
+       RNA_def_int_vector(ot->srna, "cursor", 2, NULL, INT_MIN, INT_MAX, "Cursor", "", INT_MIN, INT_MAX);
 }
 
 /** \} */
@@ -2965,8 +2990,7 @@ static int screen_area_options_invoke(bContext *C, wmOperator *op, const wmEvent
 
        uiItemFullO(layout, "SCREEN_OT_area_split", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0, &ptr);
        /* store initial mouse cursor position */
-       RNA_int_set(&ptr, "mouse_x", event->x);
-       RNA_int_set(&ptr, "mouse_y", event->y);
+       RNA_int_set_array(&ptr, "cursor", &event->x);
 
        uiItemFullO(layout, "SCREEN_OT_area_join", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0, &ptr);
        /* mouse cursor on edge, '4' can fail on wide edges... */