diff options
author | Julian Eisel <julian@blender.org> | 2021-04-26 17:14:27 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-04-26 17:14:27 +0300 |
commit | 2ffabbd5296556d56a6401207d309a7a61ba1d7e (patch) | |
tree | 2225d55e559110ac54f3277f9da375a2fc2749d7 /source/blender/editors/screen | |
parent | dc009dd6c1c1edd5b81ef833f53930c72c789ce1 (diff) | |
parent | bac9562f15639066b076decb9ca3151391eb54a0 (diff) |
Merge remote-tracking branch 'origin/master' into asset-browser-poselib
Diffstat (limited to 'source/blender/editors/screen')
-rw-r--r-- | source/blender/editors/screen/screen_edit.c | 86 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_intern.h | 4 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 75 |
3 files changed, 72 insertions, 93 deletions
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 8e51772d801..75aa709a5d1 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -279,42 +279,44 @@ void screen_new_activate_prepare(const wmWindow *win, bScreen *screen_new) screen_new->do_draw = true; } -/* with area as center, sb is located at: 0=W, 1=N, 2=E, 3=S */ -/* -1 = not valid check */ -/* used with join operator */ -int area_getorientation(ScrArea *area, ScrArea *sb) +/** + * with `sa_a` as center, `sa_b` is located at: 0=W, 1=N, 2=E, 3=S + * -1 = not valid check. + * used with join operator. + */ +int area_getorientation(ScrArea *sa_a, ScrArea *sa_b) { - if (area == NULL || sb == NULL || area == sb) { + if (sa_a == NULL || sa_b == NULL || sa_a == sa_b) { return -1; } - vec2s saBL = area->v1->vec; - vec2s saTL = area->v2->vec; - vec2s saTR = area->v3->vec; - vec2s saBR = area->v4->vec; + const vec2s *sa_bl = &sa_a->v1->vec; + const vec2s *sa_tl = &sa_a->v2->vec; + const vec2s *sa_tr = &sa_a->v3->vec; + const vec2s *sa_br = &sa_a->v4->vec; - vec2s sbBL = sb->v1->vec; - vec2s sbTL = sb->v2->vec; - vec2s sbTR = sb->v3->vec; - vec2s sbBR = sb->v4->vec; + const vec2s *sb_bl = &sa_b->v1->vec; + const vec2s *sb_tl = &sa_b->v2->vec; + const vec2s *sb_tr = &sa_b->v3->vec; + const vec2s *sb_br = &sa_b->v4->vec; - if (saBL.x == sbBR.x && saTL.x == sbTR.x) { /* area to right of sb = W */ - if ((MIN2(saTL.y, sbTR.y) - MAX2(saBL.y, sbBR.y)) > AREAJOINTOLERANCEY) { + if (sa_bl->x == sb_br->x && sa_tl->x == sb_tr->x) { /* sa_a to right of sa_b = W */ + if ((MIN2(sa_tl->y, sb_tr->y) - MAX2(sa_bl->y, sb_br->y)) > AREAJOINTOLERANCEY) { return 0; } } - else if (saTL.y == sbBL.y && saTR.y == sbBR.y) { /* area to bottom of sb = N */ - if ((MIN2(saTR.x, sbBR.x) - MAX2(saTL.x, sbBL.x)) > AREAJOINTOLERANCEX) { + else if (sa_tl->y == sb_bl->y && sa_tr->y == sb_br->y) { /* sa_a to bottom of sa_b = N */ + if ((MIN2(sa_tr->x, sb_br->x) - MAX2(sa_tl->x, sb_bl->x)) > AREAJOINTOLERANCEX) { return 1; } } - else if (saTR.x == sbTL.x && saBR.x == sbBL.x) { /* area to left of sb = E */ - if ((MIN2(saTR.y, sbTL.y) - MAX2(saBR.y, sbBL.y)) > AREAJOINTOLERANCEY) { + else if (sa_tr->x == sb_tl->x && sa_br->x == sb_bl->x) { /* sa_a to left of sa_b = E */ + if ((MIN2(sa_tr->y, sb_tl->y) - MAX2(sa_br->y, sb_bl->y)) > AREAJOINTOLERANCEY) { return 2; } } - else if (saBL.y == sbTL.y && saBR.y == sbTR.y) { /* area on top of sb = S */ - if ((MIN2(saBR.x, sbTR.x) - MAX2(saBL.x, sbTL.x)) > AREAJOINTOLERANCEX) { + else if (sa_bl->y == sb_tl->y && sa_br->y == sb_tr->y) { /* sa_a on top of sa_b = S */ + if ((MIN2(sa_br->x, sb_tr->x) - MAX2(sa_bl->x, sb_tl->x)) > AREAJOINTOLERANCEX) { return 3; } } @@ -322,32 +324,34 @@ int area_getorientation(ScrArea *area, ScrArea *sb) return -1; } -/* Get alignment offset of adjacent areas. 'dir' value is like area_getorientation(). */ -void area_getoffsets(ScrArea *area, ScrArea *sb, const int dir, int *offset1, int *offset2) +/** + * Get alignment offset of adjacent areas. 'dir' value is like #area_getorientation(). + */ +void area_getoffsets(ScrArea *sa_a, ScrArea *sa_b, const int dir, int *r_offset1, int *r_offset2) { - if (area == NULL || sb == NULL) { - *offset1 = INT_MAX; - *offset2 = INT_MAX; + if (sa_a == NULL || sa_b == NULL) { + *r_offset1 = INT_MAX; + *r_offset2 = INT_MAX; } - else if (dir == 0) { /* West: sa on right and sb to the left. */ - *offset1 = sb->v3->vec.y - area->v2->vec.y; - *offset2 = sb->v4->vec.y - area->v1->vec.y; + else if (dir == 0) { /* West: sa on right and sa_b to the left. */ + *r_offset1 = sa_b->v3->vec.y - sa_a->v2->vec.y; + *r_offset2 = sa_b->v4->vec.y - sa_a->v1->vec.y; } - else if (dir == 1) { /* North: sa below and sb above. */ - *offset1 = area->v2->vec.x - sb->v1->vec.x; - *offset2 = area->v3->vec.x - sb->v4->vec.x; + else if (dir == 1) { /* North: sa below and sa_b above. */ + *r_offset1 = sa_a->v2->vec.x - sa_b->v1->vec.x; + *r_offset2 = sa_a->v3->vec.x - sa_b->v4->vec.x; } - else if (dir == 2) { /* East: sa on left and sb to the right. */ - *offset1 = sb->v2->vec.y - area->v3->vec.y; - *offset2 = sb->v1->vec.y - area->v4->vec.y; + else if (dir == 2) { /* East: sa on left and sa_b to the right. */ + *r_offset1 = sa_b->v2->vec.y - sa_a->v3->vec.y; + *r_offset2 = sa_b->v1->vec.y - sa_a->v4->vec.y; } - else if (dir == 3) { /* South: sa above and sb below. */ - *offset1 = area->v1->vec.x - sb->v2->vec.x; - *offset2 = area->v4->vec.x - sb->v3->vec.x; + else if (dir == 3) { /* South: sa above and sa_b below. */ + *r_offset1 = sa_a->v1->vec.x - sa_b->v2->vec.x; + *r_offset2 = sa_a->v4->vec.x - sa_b->v3->vec.x; } else { - *offset1 = INT_MAX; - *offset2 = INT_MAX; + *r_offset1 = INT_MAX; + *r_offset2 = INT_MAX; } } @@ -515,7 +519,7 @@ static bool screen_area_join_ex( screen_area_join_aligned(C, screen, sa1, sa2); if (close_all_remainders || offset1 < 0 || offset2 > 0) { - /* Close both if trimiming sa1. */ + /* Close both if trimming `sa1`. */ screen_area_close(C, screen, side1); screen_area_close(C, screen, side2); } diff --git a/source/blender/editors/screen/screen_intern.h b/source/blender/editors/screen/screen_intern.h index cda7ba6a4a9..dd196f9621b 100644 --- a/source/blender/editors/screen/screen_intern.h +++ b/source/blender/editors/screen/screen_intern.h @@ -59,8 +59,8 @@ void screen_change_prepare(bScreen *screen_old, ScrArea *area_split( const wmWindow *win, bScreen *screen, ScrArea *area, char dir, float fac, int merge); int screen_area_join(struct bContext *C, bScreen *screen, ScrArea *sa1, ScrArea *sa2); -int area_getorientation(ScrArea *area, ScrArea *sb); -void area_getoffsets(ScrArea *area, ScrArea *sb, const int dir, int *offset1, int *offset2); +int area_getorientation(ScrArea *sa_a, ScrArea *sa_b); +void area_getoffsets(ScrArea *sa_a, ScrArea *sa_b, const int dir, int *r_offset1, int *r_offset2); bool screen_area_close(struct bContext *C, bScreen *screen, ScrArea *area); struct AZone *ED_area_actionzone_find_xy(ScrArea *area, const int xy[2]); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index cc920aece0a..5b371ed2caa 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -3262,8 +3262,9 @@ static void SCREEN_OT_screen_full_area(wmOperatorType *ot) */ typedef struct sAreaJoinData { - ScrArea *sa1; /* first area to be considered */ - ScrArea *sa2; /* second area to be considered */ + ScrArea *sa1; /* Potential source area (kept). */ + ScrArea *sa2; /* Potential target area (removed or reduced). */ + int dir; /* Direction of potential join. */ void *draw_callback; /* call 'ED_screen_draw_join_highlight' */ } sAreaJoinData; @@ -3273,7 +3274,7 @@ static void area_join_draw_cb(const struct wmWindow *UNUSED(win), void *userdata const wmOperator *op = userdata; sAreaJoinData *sd = op->customdata; - if (sd->sa1 && sd->sa2) { + if (sd->sa1 && sd->sa2 && (sd->dir != -1)) { ED_screen_draw_join_highlight(sd->sa1, sd->sa2); } } @@ -3296,6 +3297,7 @@ static bool area_join_init(bContext *C, wmOperator *op, ScrArea *sa1, ScrArea *s jd->sa1 = sa1; jd->sa2 = sa2; + jd->dir = -1; op->customdata = jd; @@ -3308,7 +3310,7 @@ static bool area_join_init(bContext *C, wmOperator *op, ScrArea *sa1, ScrArea *s static bool area_join_apply(bContext *C, wmOperator *op) { sAreaJoinData *jd = (sAreaJoinData *)op->customdata; - if (!jd) { + if (!jd || (jd->dir == -1)) { return false; } @@ -3410,61 +3412,30 @@ static int area_join_modal(bContext *C, wmOperator *op, const wmEvent *event) case MOUSEMOVE: { ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->x, event->y); - int dir = -1; + jd->dir = area_getorientation(jd->sa1, jd->sa2); - if (area) { - if (jd->sa1 != area) { - dir = area_getorientation(jd->sa1, area); - if (dir != -1) { - jd->sa2 = area; - } - else { - /* we are not bordering on the previously selected area - * we check if area has common border with the one marked for removal - * in this case we can swap areas. - */ - dir = area_getorientation(area, jd->sa2); - if (dir != -1) { - jd->sa1 = jd->sa2; - jd->sa2 = area; - } - else { - jd->sa2 = NULL; - } - } - WM_event_add_notifier(C, NC_WINDOW, NULL); - } - else { - /* we are back in the area previously selected for keeping - * we swap the areas if possible to allow user to choose */ - if (jd->sa2 != NULL) { - jd->sa1 = jd->sa2; - jd->sa2 = area; - dir = area_getorientation(jd->sa1, jd->sa2); - if (dir == -1) { - printf("oops, didn't expect that!\n"); - } - } - else { - dir = area_getorientation(jd->sa1, area); - if (dir != -1) { - jd->sa2 = area; - } - } - WM_event_add_notifier(C, NC_WINDOW, NULL); - } + if (area == jd->sa1) { + /* Hovering current source, so change direction. */ + jd->sa1 = jd->sa2; + jd->sa2 = area; + jd->dir = area_getorientation(jd->sa1, jd->sa2); } + else if (area != jd->sa2) { + jd->dir = -1; + } + + WM_event_add_notifier(C, NC_WINDOW, NULL); - if (dir == 1) { + if (jd->dir == 1) { WM_cursor_set(win, WM_CURSOR_N_ARROW); } - else if (dir == 3) { + else if (jd->dir == 3) { WM_cursor_set(win, WM_CURSOR_S_ARROW); } - else if (dir == 2) { + else if (jd->dir == 2) { WM_cursor_set(win, WM_CURSOR_E_ARROW); } - else if (dir == 0) { + else if (jd->dir == 0) { WM_cursor_set(win, WM_CURSOR_W_ARROW); } else { @@ -3475,6 +3446,10 @@ static int area_join_modal(bContext *C, wmOperator *op, const wmEvent *event) } case LEFTMOUSE: if (event->val == KM_RELEASE) { + if (jd->dir == -1) { + area_join_cancel(C, op); + return OPERATOR_CANCELLED; + } ED_area_tag_redraw(jd->sa1); ED_area_tag_redraw(jd->sa2); |