UI: Adding Constraint to the Area Join Operations
Removing mid-operation area re-targeting for safety and predictability. Differential Revision: https://developer.blender.org/D11066 Reviewed by Campbell Barton
This commit is contained in:
parent
c204e0c385
commit
c76141e425
|
@ -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;
|
||||
}
|
||||
|
||||
if (dir == 1) {
|
||||
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
||||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue