diff options
author | Severin <eiseljulian@gmail.com> | 2018-06-29 22:22:27 +0300 |
---|---|---|
committer | Severin <eiseljulian@gmail.com> | 2018-06-29 22:29:06 +0300 |
commit | 48ad67ef8201f8fcd5efdf748c5fea86e2c61d7d (patch) | |
tree | 7ea1d3f862bc5ea54b4b7134be07ab416ea9df04 /source/blender/editors/screen | |
parent | ac2e10d47b38e944efab66781ed0a4f4d4c41588 (diff) |
Cleanup: Add/use function to get area width/height from area vertices
This used to be rather cryptic and it was easy to forget the `+ 1` which in fact
is needed to get the correct width/height, see e626998a262ebe4f. This should
also fix some minor off-by-one errors.
Diffstat (limited to 'source/blender/editors/screen')
-rw-r--r-- | source/blender/editors/screen/screen_draw.c | 8 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_edit.c | 29 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 6 |
4 files changed, 28 insertions, 17 deletions
diff --git a/source/blender/editors/screen/screen_draw.c b/source/blender/editors/screen/screen_draw.c index b81c1e489ea..0a693893310 100644 --- a/source/blender/editors/screen/screen_draw.c +++ b/source/blender/editors/screen/screen_draw.c @@ -44,11 +44,11 @@ */ static void draw_horizontal_join_shape(ScrArea *sa, char dir, unsigned int pos) { + const float width = area_geometry_width(sa) - 1; + const float height = area_geometry_height(sa) - 1; vec2f points[10]; short i; float w, h; - float width = sa->v3->vec.x - sa->v1->vec.x; - float height = sa->v3->vec.y - sa->v1->vec.y; if (height < width) { h = height / 8; @@ -125,11 +125,11 @@ static void draw_horizontal_join_shape(ScrArea *sa, char dir, unsigned int pos) */ static void draw_vertical_join_shape(ScrArea *sa, char dir, unsigned int pos) { + const float width = area_geometry_width(sa) - 1; + const float height = area_geometry_height(sa) - 1; vec2f points[10]; short i; float w, h; - float width = sa->v3->vec.x - sa->v1->vec.x; - float height = sa->v3->vec.y - sa->v1->vec.y; if (height < width) { h = height / 4; diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 3e67ced783d..c3d18abc2cf 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -215,20 +215,21 @@ static void screen_delarea(bContext *C, bScreen *sc, ScrArea *sa) static short testsplitpoint(ScrArea *sa, const rcti *window_rect, char dir, float fac) { short x, y; + const int cur_area_width = area_geometry_width(sa); + const int cur_area_height = area_geometry_height(sa); const short area_min_x = AREAMINX; const short area_min_y = ED_area_headersize(); int area_min; // area big enough? - if (dir == 'v' && (sa->v4->vec.x - sa->v1->vec.x <= 2 * area_min_x)) return 0; - if (dir == 'h' && (sa->v2->vec.y - sa->v1->vec.y <= 2 * area_min_y)) return 0; + if (dir == 'v' && (cur_area_width <= 2 * area_min_x)) return 0; + if (dir == 'h' && (cur_area_height <= 2 * area_min_y)) return 0; // to be sure CLAMP(fac, 0.0f, 1.0f); if (dir == 'h') { - y = sa->v1->vec.y + - round_fl_to_short(fac * (float)(sa->v2->vec.y - sa->v1->vec.y)); + y = sa->v1->vec.y + round_fl_to_short(fac * cur_area_height); area_min = area_min_y; @@ -249,8 +250,7 @@ static short testsplitpoint(ScrArea *sa, const rcti *window_rect, char dir, floa return y; } else { - x = sa->v1->vec.x + - round_fl_to_short(fac * (float)(sa->v4->vec.x - sa->v1->vec.x)); + x = sa->v1->vec.x + round_fl_to_short(fac * cur_area_width); area_min = area_min_x; @@ -447,6 +447,15 @@ void screen_new_activate_prepare(const wmWindow *win, bScreen *screen_new) } +int area_geometry_height(const ScrArea *area) +{ + return area->v2->vec.y - area->v1->vec.y + 1; +} +int area_geometry_width(const ScrArea *area) +{ + return area->v4->vec.x - area->v1->vec.x + 1; +} + /* with sa as center, sb is located at: 0=W, 1=N, 2=E, 3=S */ /* -1 = not valid check */ /* used with join operator */ @@ -611,19 +620,19 @@ static void screen_vertices_scale( /* if the window's Y axis grows, clamp header sized areas */ if (screen_size_y_prev < screen_size_y) { /* growing? */ - const int headery_margin_max = headery_init + 4; + const int headery_margin_max = headery_init + 5; for (sa = sc->areabase.first; sa; sa = sa->next) { ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); sa->temp = 0; if (ar && !(ar->flag & RGN_FLAG_HIDDEN)) { if (sa->v2->vec.y == max[1]) { - if ((sa->v2->vec.y - sa->v1->vec.y) < headery_margin_max) { + if (area_geometry_height(sa) < headery_margin_max) { sa->temp = TEMP_TOP; } } else if (sa->v1->vec.y == min[1]) { - if ((sa->v2->vec.y - sa->v1->vec.y) < headery_margin_max) { + if (area_geometry_height(sa) < headery_margin_max) { sa->temp = TEMP_BOTTOM; } } @@ -712,7 +721,7 @@ static void screen_vertices_scale( if (sa->v2->vec.y < window_rect->ymax) headery += U.pixelsize; - if (sa->v2->vec.y - sa->v1->vec.y + 1 < headery) { + if (area_geometry_height(sa) < headery) { /* lower edge */ ScrEdge *se = BKE_screen_find_edge(sc, sa->v4, sa->v1); if (se && sa->v1 != sa->v2) { diff --git a/source/blender/editors/screen/screen_intern.h b/source/blender/editors/screen/screen_intern.h index 4e78e31256f..0cfe76cdeb8 100644 --- a/source/blender/editors/screen/screen_intern.h +++ b/source/blender/editors/screen/screen_intern.h @@ -55,6 +55,8 @@ void screen_change_update(struct bContext *C, wmWindow *win, bScreen *sc) bScreen *screen_change_prepare(bScreen *screen_old, bScreen *screen_new, struct Main *bmain, struct bContext *C, wmWindow *win); ScrArea *area_split(const wmWindow *win, bScreen *sc, ScrArea *sa, char dir, float fac, int merge); int screen_area_join(struct bContext *C, bScreen *scr, ScrArea *sa1, ScrArea *sa2); +int area_geometry_height(const ScrArea *area); +int area_geometry_width(const ScrArea *area); int area_getorientation(ScrArea *sa, ScrArea *sb); void select_connected_scredge(const wmWindow *win, ScrEdge *edge); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 35608a1f303..e4de87e0b46 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -1282,7 +1282,7 @@ static void area_move_set_limits( if (sa->v2->vec.y < (window_rect.ymax - 1)) areamin += U.pixelsize; - y1 = sa->v2->vec.y - sa->v1->vec.y + 1 - areamin; + y1 = area_geometry_height(sa) - areamin; /* if top or down edge selected, test height */ if (sa->v1->editflag && sa->v4->editflag) @@ -1299,7 +1299,7 @@ static void area_move_set_limits( if (sa->v4->vec.x < (window_rect.xmax - 1)) areamin += U.pixelsize; - x1 = sa->v4->vec.x - sa->v1->vec.x + 1 - areamin; + x1 = area_geometry_width(sa) - areamin; /* if left or right edge selected, test width */ if (sa->v1->editflag && sa->v2->editflag) @@ -1460,7 +1460,7 @@ static void area_move_apply_do( ED_screen_areas_iter(win, sc, sa) { if (sa->v1->editflag || sa->v2->editflag || sa->v3->editflag || sa->v4->editflag) { if (ED_area_is_global(sa)) { - sa->global->cur_fixed_height = round_fl_to_int((sa->v2->vec.y - sa->v1->vec.y) / UI_DPI_FAC); + sa->global->cur_fixed_height = round_fl_to_int(area_geometry_height(sa) / UI_DPI_FAC); sc->do_refresh = true; redraw_all = true; } |