Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/screen/screen_edit.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| ED_screen_verts_iter(win, screen, v1) | ED_screen_verts_iter(win, screen, v1) | ||||
| { | { | ||||
| if (v1->vec.y == from_y) { | if (v1->vec.y == from_y) { | ||||
| v1->vec.y = to_y; | v1->vec.y = to_y; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Test if two adjoining areas can be aligned by having their screen edges adjusted. */ | |||||
| static bool screen_areas_can_align(bScreen *screen, ScrArea *sa1, ScrArea *sa2, eScreenDir dir) | |||||
| { | |||||
campbellbarton: *picky* (`AREAJOINTOLERANCEY`, `AREAJOINTOLERANCEX`) can be assigned to `const` vars & reused… | |||||
| if (dir == SCREEN_DIR_NONE) { | |||||
| return false; | |||||
| } | |||||
| int offset1; | |||||
| int offset2; | |||||
| area_getoffsets(sa1, sa2, dir, &offset1, &offset2); | |||||
| const int tolerance = SCREEN_DIR_IS_HORIZONTAL(dir) ? AREAJOINTOLERANCEY : AREAJOINTOLERANCEX; | |||||
| if ((abs(offset1) >= tolerance) || (abs(offset2) >= tolerance)) { | |||||
| /* Misalignment is too great. */ | |||||
| return false; | |||||
| } | |||||
| /* Areas that are _smaller_ than minimum sizes, sharing an edge to be moved. See T100772. */ | |||||
| if (SCREEN_DIR_IS_VERTICAL(dir)) { | |||||
| const short xmin = MIN2(sa1->v1->vec.x, sa2->v1->vec.x); | |||||
| const short xmax = MAX2(sa1->v3->vec.x, sa2->v3->vec.x); | |||||
Done Inline Actions*picky* - can be const. campbellbarton: *picky* - can be const. | |||||
| LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | |||||
| if (area->v3->vec.x - area->v1->vec.x < tolerance && | |||||
| (area->v1->vec.x == xmin || area->v3->vec.x == xmax)) { | |||||
| /* There is a narrow vertical area sharing an edge of the combined bounds. */ | |||||
| return false; | |||||
| } | |||||
| } | |||||
| } | |||||
| else { | |||||
| const short ymin = MIN2(sa1->v1->vec.y, sa2->v1->vec.y); | |||||
| const short ymax = MAX2(sa1->v3->vec.y, sa2->v3->vec.y); | |||||
Done Inline Actions*picky* - can be const. campbellbarton: *picky* - can be const. | |||||
| LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | |||||
| if (area->v3->vec.y - area->v1->vec.y < tolerance && | |||||
| (area->v1->vec.y == ymin || area->v3->vec.y == ymax)) { | |||||
| /* There is a narrow horizontal area sharing an edge of the combined bounds. */ | |||||
| return false; | |||||
| } | |||||
| } | |||||
| } | |||||
| return true; | |||||
| } | |||||
| /* Adjust all screen edges to allow joining two areas. 'dir' value is like area_getorientation(). | /* Adjust all screen edges to allow joining two areas. 'dir' value is like area_getorientation(). | ||||
| */ | */ | ||||
| static void screen_areas_align( | static bool screen_areas_align( | ||||
| bContext *C, bScreen *screen, ScrArea *sa1, ScrArea *sa2, const eScreenDir dir) | bContext *C, bScreen *screen, ScrArea *sa1, ScrArea *sa2, const eScreenDir dir) | ||||
| { | { | ||||
| if (!screen_areas_can_align(screen, sa1, sa2, dir)) { | |||||
| return false; | |||||
| } | |||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| if (SCREEN_DIR_IS_HORIZONTAL(dir)) { | if (SCREEN_DIR_IS_HORIZONTAL(dir)) { | ||||
| /* horizontal join, use average for new top and bottom. */ | /* horizontal join, use average for new top and bottom. */ | ||||
| int top = (sa1->v2->vec.y + sa2->v2->vec.y) / 2; | int top = (sa1->v2->vec.y + sa2->v2->vec.y) / 2; | ||||
| int bottom = (sa1->v4->vec.y + sa2->v4->vec.y) / 2; | int bottom = (sa1->v4->vec.y + sa2->v4->vec.y) / 2; | ||||
| /* Move edges exactly matching source top and bottom. */ | /* Move edges exactly matching source top and bottom. */ | ||||
| Show All 12 Lines | |||||
| /* Move edges exactly matching source left and right. */ | /* Move edges exactly matching source left and right. */ | ||||
| screen_verts_halign(win, screen, sa1->v1->vec.x, left); | screen_verts_halign(win, screen, sa1->v1->vec.x, left); | ||||
| screen_verts_halign(win, screen, sa1->v3->vec.x, right); | screen_verts_halign(win, screen, sa1->v3->vec.x, right); | ||||
| /* Move edges exactly matching target left and right */ | /* Move edges exactly matching target left and right */ | ||||
| screen_verts_halign(win, screen, sa2->v1->vec.x, left); | screen_verts_halign(win, screen, sa2->v1->vec.x, left); | ||||
| screen_verts_halign(win, screen, sa2->v3->vec.x, right); | screen_verts_halign(win, screen, sa2->v3->vec.x, right); | ||||
| } | } | ||||
| return true; | |||||
| } | } | ||||
| /* Simple join of two areas without any splitting. Will return false if not possible. */ | /* Simple join of two areas without any splitting. Will return false if not possible. */ | ||||
| static bool screen_area_join_aligned(bContext *C, bScreen *screen, ScrArea *sa1, ScrArea *sa2) | static bool screen_area_join_aligned(bContext *C, bScreen *screen, ScrArea *sa1, ScrArea *sa2) | ||||
| { | { | ||||
| const eScreenDir dir = area_getorientation(sa1, sa2); | const eScreenDir dir = area_getorientation(sa1, sa2); | ||||
| if (dir == SCREEN_DIR_NONE) { | |||||
| return false; | |||||
| } | |||||
| int offset1; | |||||
| int offset2; | |||||
| area_getoffsets(sa1, sa2, dir, &offset1, &offset2); | |||||
| int tolerance = SCREEN_DIR_IS_HORIZONTAL(dir) ? AREAJOINTOLERANCEY : AREAJOINTOLERANCEX; | /* Ensure that the area edges are exactly aligned. */ | ||||
| if ((abs(offset1) >= tolerance) || (abs(offset2) >= tolerance)) { | if (!screen_areas_align(C, screen, sa1, sa2, dir)) { | ||||
Done Inline Actions*picky* clang-format. campbellbarton: *picky* clang-format. | |||||
Done Inline ActionsComment needs finishing. campbellbarton: Comment needs finishing. | |||||
| return false; | return false; | ||||
| } | } | ||||
| /* Align areas if they are not. */ | |||||
| screen_areas_align(C, screen, sa1, sa2, dir); | |||||
| if (dir == SCREEN_DIR_W) { /* sa1 to right of sa2 = West. */ | if (dir == SCREEN_DIR_W) { /* sa1 to right of sa2 = West. */ | ||||
| sa1->v1 = sa2->v1; /* BL */ | sa1->v1 = sa2->v1; /* BL */ | ||||
| sa1->v2 = sa2->v2; /* TL */ | sa1->v2 = sa2->v2; /* TL */ | ||||
| screen_geom_edge_add(screen, sa1->v2, sa1->v3); | screen_geom_edge_add(screen, sa1->v2, sa1->v3); | ||||
| screen_geom_edge_add(screen, sa1->v1, sa1->v4); | screen_geom_edge_add(screen, sa1->v1, sa1->v4); | ||||
| } | } | ||||
| else if (dir == SCREEN_DIR_N) { /* sa1 to bottom of sa2 = North. */ | else if (dir == SCREEN_DIR_N) { /* sa1 to bottom of sa2 = North. */ | ||||
| sa1->v2 = sa2->v2; /* TL */ | sa1->v2 = sa2->v2; /* TL */ | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||
*picky* (AREAJOINTOLERANCEY, AREAJOINTOLERANCEX) can be assigned to const vars & reused, as this multiplies by U.dpi_fac.