Cleanup: use enum types for screen direction variables
The term direction was used in 3 different ways in screen editing code,
making it hard to follow:
- 0-3 for as magic numbers mapped to [west,north,east,south].
- `h`, `v` characters for [horizontal,vertical] axes.
- Cycle direction SPACE_CONTEXT_CYCLE_PREV, SPACE_CONTEXT_CYCLE_NEXT
The following changes have been made:
- Add `eScreenDir` for [west,north,east,south], use variable name `dir`.
- Add `eScreenAxis` for [horizontal,vertical] values, use variable name
`dir_axis`.
- Add `eScreenCycle` for existing enum `SPACE_CONTEXT_CYCLE_{PREV/NEXT}`.
- Add macros `SCREEN_DIR_IS_VERTICAL(dir)`,
`SCREEN_DIR_IS_HORIZONTAL(dir)`.
Replacing `ELEM(dir, 1, 3)`, `ELEM(dir, 0, 2)`.
- Move `ED_screen_draw_join_highlight`, `ED_screen_draw_split_preview`
to `screen_intern.h`.
Reviewed By: Severin
Ref D11245
This commit is contained in:
@@ -200,8 +200,6 @@ ScrArea *ED_screen_areas_iter_next(const bScreen *screen, const ScrArea *area);
|
||||
/* screens */
|
||||
void ED_screens_init(struct Main *bmain, struct wmWindowManager *wm);
|
||||
void ED_screen_draw_edges(struct wmWindow *win);
|
||||
void ED_screen_draw_join_highlight(struct ScrArea *sa1, struct ScrArea *sa2);
|
||||
void ED_screen_draw_split_preview(struct ScrArea *area, const int dir, const float fac);
|
||||
void ED_screen_refresh(struct wmWindowManager *wm, struct wmWindow *win);
|
||||
void ED_screen_ensure_updated(struct wmWindowManager *wm,
|
||||
struct wmWindow *win,
|
||||
@@ -450,10 +448,10 @@ enum {
|
||||
};
|
||||
|
||||
/* SCREEN_OT_space_context_cycle direction */
|
||||
enum {
|
||||
typedef enum eScreenCycle {
|
||||
SPACE_CONTEXT_CYCLE_PREV,
|
||||
SPACE_CONTEXT_CYCLE_NEXT,
|
||||
};
|
||||
} eScreenCycle;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1172,12 +1172,12 @@ static void region_azones_add(const bScreen *screen, ScrArea *area, ARegion *reg
|
||||
}
|
||||
|
||||
/* dir is direction to check, not the splitting edge direction! */
|
||||
static int rct_fits(const rcti *rect, char dir, int size)
|
||||
static int rct_fits(const rcti *rect, const eScreenAxis dir_axis, int size)
|
||||
{
|
||||
if (dir == 'h') {
|
||||
if (dir_axis == SCREEN_AXIS_H) {
|
||||
return BLI_rcti_size_x(rect) + 1 - size;
|
||||
}
|
||||
/* 'v' */
|
||||
/* Vertical. */
|
||||
return BLI_rcti_size_y(rect) + 1 - size;
|
||||
}
|
||||
|
||||
@@ -1398,7 +1398,8 @@ static void region_rect_recursive(
|
||||
region->flag |= RGN_FLAG_TOO_SMALL;
|
||||
}
|
||||
}
|
||||
else if (rct_fits(remainder, 'v', 1) < 0 || rct_fits(remainder, 'h', 1) < 0) {
|
||||
else if (rct_fits(remainder, SCREEN_AXIS_V, 1) < 0 ||
|
||||
rct_fits(remainder, SCREEN_AXIS_H, 1) < 0) {
|
||||
/* remainder is too small for any usage */
|
||||
region->flag |= RGN_FLAG_TOO_SMALL;
|
||||
}
|
||||
@@ -1410,11 +1411,11 @@ static void region_rect_recursive(
|
||||
else if (ELEM(alignment, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) {
|
||||
rcti *winrct = (region->overlap) ? overlap_remainder : remainder;
|
||||
|
||||
if ((prefsizey == 0) || (rct_fits(winrct, 'v', prefsizey) < 0)) {
|
||||
if ((prefsizey == 0) || (rct_fits(winrct, SCREEN_AXIS_V, prefsizey) < 0)) {
|
||||
region->flag |= RGN_FLAG_TOO_SMALL;
|
||||
}
|
||||
else {
|
||||
int fac = rct_fits(winrct, 'v', prefsizey);
|
||||
int fac = rct_fits(winrct, SCREEN_AXIS_V, prefsizey);
|
||||
|
||||
if (fac < 0) {
|
||||
prefsizey += fac;
|
||||
@@ -1436,11 +1437,11 @@ static void region_rect_recursive(
|
||||
else if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
|
||||
rcti *winrct = (region->overlap) ? overlap_remainder : remainder;
|
||||
|
||||
if ((prefsizex == 0) || (rct_fits(winrct, 'h', prefsizex) < 0)) {
|
||||
if ((prefsizex == 0) || (rct_fits(winrct, SCREEN_AXIS_H, prefsizex) < 0)) {
|
||||
region->flag |= RGN_FLAG_TOO_SMALL;
|
||||
}
|
||||
else {
|
||||
int fac = rct_fits(winrct, 'h', prefsizex);
|
||||
int fac = rct_fits(winrct, SCREEN_AXIS_H, prefsizex);
|
||||
|
||||
if (fac < 0) {
|
||||
prefsizex += fac;
|
||||
@@ -1464,7 +1465,7 @@ static void region_rect_recursive(
|
||||
region->winrct = *remainder;
|
||||
|
||||
if (alignment == RGN_ALIGN_HSPLIT) {
|
||||
if (rct_fits(remainder, 'h', prefsizex) > 4) {
|
||||
if (rct_fits(remainder, SCREEN_AXIS_H, prefsizex) > 4) {
|
||||
region->winrct.xmax = BLI_rcti_cent_x(remainder);
|
||||
remainder->xmin = region->winrct.xmax + 1;
|
||||
}
|
||||
@@ -1473,7 +1474,7 @@ static void region_rect_recursive(
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (rct_fits(remainder, 'v', prefsizey) > 4) {
|
||||
if (rct_fits(remainder, SCREEN_AXIS_V, prefsizey) > 4) {
|
||||
region->winrct.ymax = BLI_rcti_cent_y(remainder);
|
||||
remainder->ymin = region->winrct.ymax + 1;
|
||||
}
|
||||
|
||||
@@ -237,23 +237,25 @@ void ED_screen_draw_edges(wmWindow *win)
|
||||
* \param sa1: Area from which the resultant originates.
|
||||
* \param sa2: Target area that will be replaced.
|
||||
*/
|
||||
void ED_screen_draw_join_highlight(ScrArea *sa1, ScrArea *sa2)
|
||||
void screen_draw_join_highlight(ScrArea *sa1, ScrArea *sa2)
|
||||
{
|
||||
int dir = area_getorientation(sa1, sa2);
|
||||
if (dir == -1) {
|
||||
const eScreenDir dir = area_getorientation(sa1, sa2);
|
||||
if (dir == SCREEN_DIR_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Rect of the combined areas.*/
|
||||
bool vertical = ELEM(dir, 1, 3);
|
||||
rctf combined = {.xmin = vertical ? MAX2(sa1->totrct.xmin, sa2->totrct.xmin) :
|
||||
MIN2(sa1->totrct.xmin, sa2->totrct.xmin),
|
||||
.xmax = vertical ? MIN2(sa1->totrct.xmax, sa2->totrct.xmax) :
|
||||
MAX2(sa1->totrct.xmax, sa2->totrct.xmax),
|
||||
.ymin = vertical ? MIN2(sa1->totrct.ymin, sa2->totrct.ymin) :
|
||||
MAX2(sa1->totrct.ymin, sa2->totrct.ymin),
|
||||
.ymax = vertical ? MAX2(sa1->totrct.ymax, sa2->totrct.ymax) :
|
||||
MIN2(sa1->totrct.ymax, sa2->totrct.ymax)};
|
||||
const bool vertical = SCREEN_DIR_IS_VERTICAL(dir);
|
||||
const rctf combined = {
|
||||
.xmin = vertical ? MAX2(sa1->totrct.xmin, sa2->totrct.xmin) :
|
||||
MIN2(sa1->totrct.xmin, sa2->totrct.xmin),
|
||||
.xmax = vertical ? MIN2(sa1->totrct.xmax, sa2->totrct.xmax) :
|
||||
MAX2(sa1->totrct.xmax, sa2->totrct.xmax),
|
||||
.ymin = vertical ? MIN2(sa1->totrct.ymin, sa2->totrct.ymin) :
|
||||
MAX2(sa1->totrct.ymin, sa2->totrct.ymin),
|
||||
.ymax = vertical ? MAX2(sa1->totrct.ymax, sa2->totrct.ymax) :
|
||||
MIN2(sa1->totrct.ymax, sa2->totrct.ymax),
|
||||
};
|
||||
|
||||
uint pos_id = GPU_vertformat_attr_add(
|
||||
immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
@@ -320,7 +322,7 @@ void ED_screen_draw_join_highlight(ScrArea *sa1, ScrArea *sa2)
|
||||
UI_draw_roundbox_4fv(&combined, false, 7 * U.pixelsize, (float[4]){1.0f, 1.0f, 1.0f, 0.8f});
|
||||
}
|
||||
|
||||
void ED_screen_draw_split_preview(ScrArea *area, const int dir, const float fac)
|
||||
void screen_draw_split_preview(ScrArea *area, const eScreenAxis dir_axis, const float fac)
|
||||
{
|
||||
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
@@ -332,7 +334,7 @@ void ED_screen_draw_split_preview(ScrArea *area, const int dir, const float fac)
|
||||
|
||||
immBegin(GPU_PRIM_LINES, 2);
|
||||
|
||||
if (dir == 'h') {
|
||||
if (dir_axis == SCREEN_AXIS_H) {
|
||||
const float y = (1 - fac) * area->totrct.ymin + fac * area->totrct.ymax;
|
||||
|
||||
immVertex2f(pos, area->totrct.xmin, y);
|
||||
@@ -350,7 +352,7 @@ void ED_screen_draw_split_preview(ScrArea *area, const int dir, const float fac)
|
||||
immEnd();
|
||||
}
|
||||
else {
|
||||
BLI_assert(dir == 'v');
|
||||
BLI_assert(dir_axis == SCREEN_AXIS_V);
|
||||
const float x = (1 - fac) * area->totrct.xmin + fac * area->totrct.xmax;
|
||||
|
||||
immVertex2f(pos, x, area->totrct.ymin);
|
||||
|
||||
@@ -107,7 +107,7 @@ static void screen_delarea(bContext *C, bScreen *screen, ScrArea *area)
|
||||
ScrArea *area_split(const wmWindow *win,
|
||||
bScreen *screen,
|
||||
ScrArea *area,
|
||||
char dir,
|
||||
const eScreenAxis dir_axis,
|
||||
const float fac,
|
||||
const bool merge)
|
||||
{
|
||||
@@ -120,7 +120,7 @@ ScrArea *area_split(const wmWindow *win,
|
||||
rcti window_rect;
|
||||
WM_window_rect_calc(win, &window_rect);
|
||||
|
||||
short split = screen_geom_find_area_split_point(area, &window_rect, dir, fac);
|
||||
short split = screen_geom_find_area_split_point(area, &window_rect, dir_axis, fac);
|
||||
if (split == 0) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ ScrArea *area_split(const wmWindow *win,
|
||||
* normally it shouldn't matter which is used since the copy should match the original
|
||||
* however with viewport rendering and python console this isn't the case. - campbell */
|
||||
|
||||
if (dir == 'h') {
|
||||
if (dir_axis == SCREEN_AXIS_H) {
|
||||
/* new vertices */
|
||||
ScrVert *sv1 = screen_geom_vertex_add(screen, area->v1->vec.x, split);
|
||||
ScrVert *sv2 = screen_geom_vertex_add(screen, area->v4->vec.x, split);
|
||||
@@ -288,10 +288,10 @@ void screen_new_activate_prepare(const wmWindow *win, bScreen *screen_new)
|
||||
* -1 = not valid check.
|
||||
* used with join operator.
|
||||
*/
|
||||
int area_getorientation(ScrArea *sa_a, ScrArea *sa_b)
|
||||
eScreenDir area_getorientation(ScrArea *sa_a, ScrArea *sa_b)
|
||||
{
|
||||
if (sa_a == NULL || sa_b == NULL || sa_a == sa_b) {
|
||||
return -1;
|
||||
return SCREEN_DIR_NONE;
|
||||
}
|
||||
|
||||
const vec2s *sa_bl = &sa_a->v1->vec;
|
||||
@@ -331,29 +331,31 @@ int area_getorientation(ScrArea *sa_a, ScrArea *sa_b)
|
||||
/**
|
||||
* 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)
|
||||
void area_getoffsets(
|
||||
ScrArea *sa_a, ScrArea *sa_b, const eScreenDir dir, int *r_offset1, int *r_offset2)
|
||||
{
|
||||
if (sa_a == NULL || sa_b == NULL) {
|
||||
*r_offset1 = INT_MAX;
|
||||
*r_offset2 = INT_MAX;
|
||||
}
|
||||
else if (dir == 0) { /* West: sa on right and sa_b to the left. */
|
||||
else if (dir == SCREEN_DIR_W) { /* 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 sa_b above. */
|
||||
else if (dir == SCREEN_DIR_N) { /* 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 sa_b to the right. */
|
||||
else if (dir == SCREEN_DIR_E) { /* 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 sa_b below. */
|
||||
else if (dir == SCREEN_DIR_S) { /* 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 {
|
||||
BLI_assert(dir == SCREEN_DIR_NONE);
|
||||
*r_offset1 = INT_MAX;
|
||||
*r_offset2 = INT_MAX;
|
||||
}
|
||||
@@ -390,11 +392,11 @@ static void screen_verts_valign(const wmWindow *win,
|
||||
/* Adjust all screen edges to allow joining two areas. 'dir' value is like area_getorientation().
|
||||
*/
|
||||
static void screen_areas_align(
|
||||
bContext *C, bScreen *screen, ScrArea *sa1, ScrArea *sa2, const int dir)
|
||||
bContext *C, bScreen *screen, ScrArea *sa1, ScrArea *sa2, const eScreenDir dir)
|
||||
{
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
|
||||
if (ELEM(dir, 0, 2)) {
|
||||
if (SCREEN_DIR_IS_HORIZONTAL(dir)) {
|
||||
/* horizontal join, use average for new top and bottom. */
|
||||
int top = (sa1->v2->vec.y + sa2->v2->vec.y) / 2;
|
||||
int bottom = (sa1->v4->vec.y + sa2->v4->vec.y) / 2;
|
||||
@@ -425,8 +427,8 @@ static void screen_areas_align(
|
||||
/* 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)
|
||||
{
|
||||
int dir = area_getorientation(sa1, sa2);
|
||||
if (dir == -1) {
|
||||
const eScreenDir dir = area_getorientation(sa1, sa2);
|
||||
if (dir == SCREEN_DIR_NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -434,7 +436,7 @@ static bool screen_area_join_aligned(bContext *C, bScreen *screen, ScrArea *sa1,
|
||||
int offset2;
|
||||
area_getoffsets(sa1, sa2, dir, &offset1, &offset2);
|
||||
|
||||
int tolerance = ELEM(dir, 0, 2) ? AREAJOINTOLERANCEY : AREAJOINTOLERANCEX;
|
||||
int tolerance = SCREEN_DIR_IS_HORIZONTAL(dir) ? AREAJOINTOLERANCEY : AREAJOINTOLERANCEX;
|
||||
if ((abs(offset1) >= tolerance) || (abs(offset2) >= tolerance)) {
|
||||
return false;
|
||||
}
|
||||
@@ -442,27 +444,27 @@ static bool screen_area_join_aligned(bContext *C, bScreen *screen, ScrArea *sa1,
|
||||
/* Align areas if they are not. */
|
||||
screen_areas_align(C, screen, sa1, sa2, dir);
|
||||
|
||||
if (dir == 0) { /* sa1 to right of sa2 = W */
|
||||
sa1->v1 = sa2->v1; /* BL */
|
||||
sa1->v2 = sa2->v2; /* TL */
|
||||
if (dir == SCREEN_DIR_W) { /* sa1 to right of sa2 = West. */
|
||||
sa1->v1 = sa2->v1; /* BL */
|
||||
sa1->v2 = sa2->v2; /* TL */
|
||||
screen_geom_edge_add(screen, sa1->v2, sa1->v3);
|
||||
screen_geom_edge_add(screen, sa1->v1, sa1->v4);
|
||||
}
|
||||
else if (dir == 1) { /* sa1 to bottom of sa2 = N */
|
||||
sa1->v2 = sa2->v2; /* TL */
|
||||
sa1->v3 = sa2->v3; /* TR */
|
||||
else if (dir == SCREEN_DIR_N) { /* sa1 to bottom of sa2 = North. */
|
||||
sa1->v2 = sa2->v2; /* TL */
|
||||
sa1->v3 = sa2->v3; /* TR */
|
||||
screen_geom_edge_add(screen, sa1->v1, sa1->v2);
|
||||
screen_geom_edge_add(screen, sa1->v3, sa1->v4);
|
||||
}
|
||||
else if (dir == 2) { /* sa1 to left of sa2 = E */
|
||||
sa1->v3 = sa2->v3; /* TR */
|
||||
sa1->v4 = sa2->v4; /* BR */
|
||||
else if (dir == SCREEN_DIR_E) { /* sa1 to left of sa2 = East. */
|
||||
sa1->v3 = sa2->v3; /* TR */
|
||||
sa1->v4 = sa2->v4; /* BR */
|
||||
screen_geom_edge_add(screen, sa1->v2, sa1->v3);
|
||||
screen_geom_edge_add(screen, sa1->v1, sa1->v4);
|
||||
}
|
||||
else if (dir == 3) { /* sa1 on top of sa2 = S */
|
||||
sa1->v1 = sa2->v1; /* BL */
|
||||
sa1->v4 = sa2->v4; /* BR */
|
||||
else if (dir == SCREEN_DIR_S) { /* sa1 on top of sa2 = South. */
|
||||
sa1->v1 = sa2->v1; /* BL */
|
||||
sa1->v4 = sa2->v4; /* BR */
|
||||
screen_geom_edge_add(screen, sa1->v1, sa1->v2);
|
||||
screen_geom_edge_add(screen, sa1->v3, sa1->v4);
|
||||
}
|
||||
@@ -477,9 +479,9 @@ static bool screen_area_join_aligned(bContext *C, bScreen *screen, ScrArea *sa1,
|
||||
|
||||
/* Slice off and return new area. "Reverse" gives right/bottom, rather than left/top. */
|
||||
static ScrArea *screen_area_trim(
|
||||
bContext *C, bScreen *screen, ScrArea **area, int size, int dir, bool reverse)
|
||||
bContext *C, bScreen *screen, ScrArea **area, int size, eScreenDir dir, bool reverse)
|
||||
{
|
||||
bool vertical = ELEM(dir, 1, 3);
|
||||
const bool vertical = SCREEN_DIR_IS_VERTICAL(dir);
|
||||
if (abs(size) < (vertical ? AREAJOINTOLERANCEX : AREAJOINTOLERANCEY)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -488,7 +490,8 @@ static ScrArea *screen_area_trim(
|
||||
float fac = abs(size) / (float)(vertical ? ((*area)->v3->vec.x - (*area)->v1->vec.x) :
|
||||
((*area)->v3->vec.y - (*area)->v1->vec.y));
|
||||
fac = (reverse == vertical) ? 1.0f - fac : fac;
|
||||
ScrArea *newsa = area_split(CTX_wm_window(C), screen, *area, vertical ? 'v' : 'h', fac, true);
|
||||
ScrArea *newsa = area_split(
|
||||
CTX_wm_window(C), screen, *area, vertical ? SCREEN_AXIS_V : SCREEN_AXIS_H, fac, true);
|
||||
|
||||
/* area_split always returns smallest of the two areas, so might have to swap. */
|
||||
if (((fac > 0.5f) == vertical) != reverse) {
|
||||
@@ -504,8 +507,8 @@ static ScrArea *screen_area_trim(
|
||||
static bool screen_area_join_ex(
|
||||
bContext *C, bScreen *screen, ScrArea *sa1, ScrArea *sa2, bool close_all_remainders)
|
||||
{
|
||||
int dir = area_getorientation(sa1, sa2);
|
||||
if (dir == -1) {
|
||||
const eScreenDir dir = area_getorientation(sa1, sa2);
|
||||
if (dir == SCREEN_DIR_NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -549,14 +552,15 @@ bool screen_area_close(struct bContext *C, bScreen *screen, ScrArea *area)
|
||||
float best_alignment = 0.0f;
|
||||
|
||||
LISTBASE_FOREACH (ScrArea *, neighbor, &screen->areabase) {
|
||||
int dir = area_getorientation(area, neighbor);
|
||||
const eScreenDir dir = area_getorientation(area, neighbor);
|
||||
/* Must at least partially share an edge and not be a global area. */
|
||||
if (dir != -1 && !neighbor->global) {
|
||||
if ((dir != SCREEN_DIR_NONE) && (neighbor->global == NULL)) {
|
||||
/* Winx/Winy might not be updated yet, so get lengths from verts. */
|
||||
int area_length = ELEM(dir, 1, 3) ? area->v3->vec.x - area->v1->vec.x :
|
||||
area->v3->vec.y - area->v1->vec.y;
|
||||
int ar_length = ELEM(dir, 1, 3) ? neighbor->v3->vec.x - neighbor->v1->vec.x :
|
||||
neighbor->v3->vec.y - neighbor->v1->vec.y;
|
||||
const bool vertical = SCREEN_DIR_IS_VERTICAL(dir);
|
||||
const int area_length = vertical ? (area->v3->vec.x - area->v1->vec.x) :
|
||||
(area->v3->vec.y - area->v1->vec.y);
|
||||
const int ar_length = vertical ? (neighbor->v3->vec.x - neighbor->v1->vec.x) :
|
||||
(neighbor->v3->vec.y - neighbor->v1->vec.y);
|
||||
/* Calculate the ratio of the lengths of the shared edges. */
|
||||
float alignment = MIN2(area_length, ar_length) / (float)MAX2(area_length, ar_length);
|
||||
if (alignment > best_alignment) {
|
||||
|
||||
@@ -304,7 +304,7 @@ void screen_geom_vertices_scale(const wmWindow *win, bScreen *screen)
|
||||
*/
|
||||
short screen_geom_find_area_split_point(const ScrArea *area,
|
||||
const rcti *window_rect,
|
||||
char dir,
|
||||
const eScreenAxis dir_axis,
|
||||
float fac)
|
||||
{
|
||||
const int cur_area_width = screen_geom_area_width(area);
|
||||
@@ -313,17 +313,21 @@ short screen_geom_find_area_split_point(const ScrArea *area,
|
||||
const short area_min_y = ED_area_headersize();
|
||||
|
||||
/* area big enough? */
|
||||
if ((dir == 'v') && (cur_area_width <= 2 * area_min_x)) {
|
||||
return 0;
|
||||
if (dir_axis == SCREEN_AXIS_V) {
|
||||
if (cur_area_width <= 2 * area_min_x) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((dir == 'h') && (cur_area_height <= 2 * area_min_y)) {
|
||||
return 0;
|
||||
else if (dir_axis == SCREEN_AXIS_H) {
|
||||
if (cur_area_height <= 2 * area_min_y) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* to be sure */
|
||||
CLAMP(fac, 0.0f, 1.0f);
|
||||
|
||||
if (dir == 'h') {
|
||||
if (dir_axis == SCREEN_AXIS_H) {
|
||||
short y = area->v1->vec.y + round_fl_to_short(fac * cur_area_height);
|
||||
|
||||
int area_min = area_min_y;
|
||||
@@ -373,13 +377,13 @@ void screen_geom_select_connected_edge(const wmWindow *win, ScrEdge *edge)
|
||||
{
|
||||
bScreen *screen = WM_window_get_active_screen(win);
|
||||
|
||||
/* 'dir' is the direction of EDGE */
|
||||
char dir;
|
||||
/* 'dir_axis' is the direction of EDGE */
|
||||
eScreenAxis dir_axis;
|
||||
if (edge->v1->vec.x == edge->v2->vec.x) {
|
||||
dir = 'v';
|
||||
dir_axis = SCREEN_AXIS_V;
|
||||
}
|
||||
else {
|
||||
dir = 'h';
|
||||
dir_axis = SCREEN_AXIS_H;
|
||||
}
|
||||
|
||||
ED_screen_verts_iter(win, screen, sv)
|
||||
@@ -396,13 +400,13 @@ void screen_geom_select_connected_edge(const wmWindow *win, ScrEdge *edge)
|
||||
oneselected = false;
|
||||
LISTBASE_FOREACH (ScrEdge *, se, &screen->edgebase) {
|
||||
if (se->v1->flag + se->v2->flag == 1) {
|
||||
if (dir == 'h') {
|
||||
if (dir_axis == SCREEN_AXIS_H) {
|
||||
if (se->v1->vec.y == se->v2->vec.y) {
|
||||
se->v1->flag = se->v2->flag = 1;
|
||||
oneselected = true;
|
||||
}
|
||||
}
|
||||
if (dir == 'v') {
|
||||
else if (dir_axis == SCREEN_AXIS_V) {
|
||||
if (se->v1->vec.x == se->v2->vec.x) {
|
||||
se->v1->flag = se->v2->flag = 1;
|
||||
oneselected = true;
|
||||
|
||||
@@ -29,6 +29,29 @@ struct bContextDataResult;
|
||||
|
||||
/* internal exports only */
|
||||
|
||||
typedef enum eScreenDir {
|
||||
/** This can mean unset, unknown or invalid. */
|
||||
SCREEN_DIR_NONE = -1,
|
||||
/** West/Left. */
|
||||
SCREEN_DIR_W = 0,
|
||||
/** North/Up. */
|
||||
SCREEN_DIR_N = 1,
|
||||
/** East/Right. */
|
||||
SCREEN_DIR_E = 2,
|
||||
/** South/Down. */
|
||||
SCREEN_DIR_S = 3,
|
||||
} eScreenDir;
|
||||
|
||||
#define SCREEN_DIR_IS_VERTICAL(dir) (ELEM(dir, SCREEN_DIR_N, SCREEN_DIR_S))
|
||||
#define SCREEN_DIR_IS_HORIZONTAL(dir) (ELEM(dir, SCREEN_DIR_W, SCREEN_DIR_E))
|
||||
|
||||
typedef enum eScreenAxis {
|
||||
/** Horizontal. */
|
||||
SCREEN_AXIS_H = 'h',
|
||||
/** Vertical. */
|
||||
SCREEN_AXIS_V = 'v',
|
||||
} eScreenAxis;
|
||||
|
||||
#define AZONESPOTW UI_HEADER_OFFSET /* width of corner #AZone - max */
|
||||
#define AZONESPOTH (0.6f * U.widget_unit) /* height of corner #AZone */
|
||||
#define AZONEFADEIN (5.0f * U.widget_unit) /* when #AZone is totally visible */
|
||||
@@ -46,6 +69,10 @@ void ED_area_data_copy(ScrArea *area_dst, ScrArea *area_src, const bool do_free)
|
||||
void ED_area_data_swap(ScrArea *area_dst, ScrArea *area_src);
|
||||
void region_toggle_hidden(struct bContext *C, ARegion *region, const bool do_fade);
|
||||
|
||||
/* screen_draw.c */
|
||||
void screen_draw_join_highlight(struct ScrArea *sa1, struct ScrArea *sa2);
|
||||
void screen_draw_split_preview(struct ScrArea *area, const eScreenAxis dir_axis, const float fac);
|
||||
|
||||
/* screen_edit.c */
|
||||
bScreen *screen_add(struct Main *bmain, const char *name, const rcti *rect);
|
||||
void screen_data_copy(bScreen *to, bScreen *from);
|
||||
@@ -59,12 +86,13 @@ void screen_change_prepare(bScreen *screen_old,
|
||||
ScrArea *area_split(const wmWindow *win,
|
||||
bScreen *screen,
|
||||
ScrArea *area,
|
||||
char dir,
|
||||
const eScreenAxis dir_axis,
|
||||
const float fac,
|
||||
const bool merge);
|
||||
int screen_area_join(struct bContext *C, bScreen *screen, ScrArea *sa1, ScrArea *sa2);
|
||||
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);
|
||||
eScreenDir area_getorientation(ScrArea *sa_a, ScrArea *sa_b);
|
||||
void area_getoffsets(
|
||||
ScrArea *sa_a, ScrArea *sa_b, const eScreenDir 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]);
|
||||
|
||||
@@ -87,7 +115,7 @@ ScrEdge *screen_geom_find_active_scredge(const wmWindow *win,
|
||||
void screen_geom_vertices_scale(const wmWindow *win, bScreen *screen);
|
||||
short screen_geom_find_area_split_point(const ScrArea *area,
|
||||
const rcti *window_rect,
|
||||
char dir,
|
||||
const eScreenAxis dir_axis,
|
||||
float fac);
|
||||
void screen_geom_select_connected_edge(const wmWindow *win, ScrEdge *edge);
|
||||
|
||||
|
||||
@@ -694,7 +694,9 @@ static bool screen_active_editable(bContext *C)
|
||||
typedef struct sActionzoneData {
|
||||
ScrArea *sa1, *sa2;
|
||||
AZone *az;
|
||||
int x, y, gesture_dir, modifier;
|
||||
int x, y;
|
||||
eScreenDir gesture_dir;
|
||||
int modifier;
|
||||
} sActionzoneData;
|
||||
|
||||
/* quick poll to save operators to be created and handled */
|
||||
@@ -1045,16 +1047,16 @@ static int actionzone_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
|
||||
/* Calculate gesture cardinal direction. */
|
||||
if (delta_y > abs(delta_x)) {
|
||||
sad->gesture_dir = 'n';
|
||||
sad->gesture_dir = SCREEN_DIR_N;
|
||||
}
|
||||
else if (delta_x >= abs(delta_y)) {
|
||||
sad->gesture_dir = 'e';
|
||||
sad->gesture_dir = SCREEN_DIR_E;
|
||||
}
|
||||
else if (delta_y < -abs(delta_x)) {
|
||||
sad->gesture_dir = 's';
|
||||
sad->gesture_dir = SCREEN_DIR_S;
|
||||
}
|
||||
else {
|
||||
sad->gesture_dir = 'w';
|
||||
sad->gesture_dir = SCREEN_DIR_W;
|
||||
}
|
||||
|
||||
bool is_gesture;
|
||||
@@ -1071,22 +1073,24 @@ static int actionzone_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
/* Are we still in same area? */
|
||||
if (BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->x, event->y) == sad->sa1) {
|
||||
/* Same area, so possible split. */
|
||||
WM_cursor_set(
|
||||
win, (ELEM(sad->gesture_dir, 'n', 's')) ? WM_CURSOR_H_SPLIT : WM_CURSOR_V_SPLIT);
|
||||
WM_cursor_set(win,
|
||||
SCREEN_DIR_IS_VERTICAL(sad->gesture_dir) ? WM_CURSOR_H_SPLIT :
|
||||
WM_CURSOR_V_SPLIT);
|
||||
is_gesture = (delta_max > split_threshold);
|
||||
}
|
||||
else {
|
||||
/* Different area, so possible join. */
|
||||
if (sad->gesture_dir == 'n') {
|
||||
if (sad->gesture_dir == SCREEN_DIR_N) {
|
||||
WM_cursor_set(win, WM_CURSOR_N_ARROW);
|
||||
}
|
||||
else if (sad->gesture_dir == 's') {
|
||||
else if (sad->gesture_dir == SCREEN_DIR_S) {
|
||||
WM_cursor_set(win, WM_CURSOR_S_ARROW);
|
||||
}
|
||||
else if (sad->gesture_dir == 'e') {
|
||||
else if (sad->gesture_dir == SCREEN_DIR_E) {
|
||||
WM_cursor_set(win, WM_CURSOR_E_ARROW);
|
||||
}
|
||||
else {
|
||||
BLI_assert(sad->gesture_dir == SCREEN_DIR_W);
|
||||
WM_cursor_set(win, WM_CURSOR_W_ARROW);
|
||||
}
|
||||
is_gesture = (delta_max > join_threshold);
|
||||
@@ -1480,7 +1484,7 @@ static void SCREEN_OT_area_close(wmOperatorType *ot)
|
||||
|
||||
typedef struct sAreaMoveData {
|
||||
int bigger, smaller, origval, step;
|
||||
char dir;
|
||||
eScreenAxis dir_axis;
|
||||
enum AreaMoveSnapType {
|
||||
/* Snapping disabled */
|
||||
SNAP_NONE = 0,
|
||||
@@ -1499,7 +1503,7 @@ typedef struct sAreaMoveData {
|
||||
* need window bounds in order to get correct limits */
|
||||
static void area_move_set_limits(wmWindow *win,
|
||||
bScreen *screen,
|
||||
int dir,
|
||||
const eScreenAxis dir_axis,
|
||||
int *bigger,
|
||||
int *smaller,
|
||||
bool *use_bigger_smaller_snap)
|
||||
@@ -1552,7 +1556,7 @@ static void area_move_set_limits(wmWindow *win,
|
||||
WM_window_rect_calc(win, &window_rect);
|
||||
|
||||
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
||||
if (dir == 'h') {
|
||||
if (dir_axis == SCREEN_AXIS_H) {
|
||||
int areamin = ED_area_headersize();
|
||||
|
||||
if (area->v1->vec.y > window_rect.ymin) {
|
||||
@@ -1615,8 +1619,8 @@ static bool area_move_init(bContext *C, wmOperator *op)
|
||||
sAreaMoveData *md = MEM_callocN(sizeof(sAreaMoveData), "sAreaMoveData");
|
||||
op->customdata = md;
|
||||
|
||||
md->dir = screen_geom_edge_is_horizontal(actedge) ? 'h' : 'v';
|
||||
if (md->dir == 'h') {
|
||||
md->dir_axis = screen_geom_edge_is_horizontal(actedge) ? SCREEN_AXIS_H : SCREEN_AXIS_V;
|
||||
if (md->dir_axis == SCREEN_AXIS_H) {
|
||||
md->origval = actedge->v1->vec.y;
|
||||
}
|
||||
else {
|
||||
@@ -1631,7 +1635,8 @@ static bool area_move_init(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
bool use_bigger_smaller_snap = false;
|
||||
area_move_set_limits(win, screen, md->dir, &md->bigger, &md->smaller, &use_bigger_smaller_snap);
|
||||
area_move_set_limits(
|
||||
win, screen, md->dir_axis, &md->bigger, &md->smaller, &use_bigger_smaller_snap);
|
||||
|
||||
md->snap_type = use_bigger_smaller_snap ? SNAP_BIGGER_SMALLER_ONLY : SNAP_AREAGRID;
|
||||
|
||||
@@ -1642,7 +1647,7 @@ static int area_snap_calc_location(const bScreen *screen,
|
||||
const enum AreaMoveSnapType snap_type,
|
||||
const int delta,
|
||||
const int origval,
|
||||
const int dir,
|
||||
const eScreenAxis dir_axis,
|
||||
const int bigger,
|
||||
const int smaller)
|
||||
{
|
||||
@@ -1667,7 +1672,7 @@ static int area_snap_calc_location(const bScreen *screen,
|
||||
break;
|
||||
|
||||
case SNAP_FRACTION_AND_ADJACENT: {
|
||||
const int axis = (dir == 'v') ? 0 : 1;
|
||||
const int axis = (dir_axis == SCREEN_AXIS_V) ? 0 : 1;
|
||||
int snap_dist_best = INT_MAX;
|
||||
{
|
||||
const float div_array[] = {
|
||||
@@ -1735,7 +1740,7 @@ static int area_snap_calc_location(const bScreen *screen,
|
||||
static void area_move_apply_do(const bContext *C,
|
||||
int delta,
|
||||
const int origval,
|
||||
const int dir,
|
||||
const eScreenAxis dir_axis,
|
||||
const int bigger,
|
||||
const int smaller,
|
||||
const enum AreaMoveSnapType snap_type)
|
||||
@@ -1753,11 +1758,12 @@ static void area_move_apply_do(const bContext *C,
|
||||
final_loc = origval + delta;
|
||||
}
|
||||
else {
|
||||
final_loc = area_snap_calc_location(screen, snap_type, delta, origval, dir, bigger, smaller);
|
||||
final_loc = area_snap_calc_location(
|
||||
screen, snap_type, delta, origval, dir_axis, bigger, smaller);
|
||||
}
|
||||
|
||||
BLI_assert(final_loc != -1);
|
||||
short axis = (dir == 'v') ? 0 : 1;
|
||||
short axis = (dir_axis == SCREEN_AXIS_V) ? 0 : 1;
|
||||
|
||||
ED_screen_verts_iter(win, screen, v1)
|
||||
{
|
||||
@@ -1813,7 +1819,7 @@ static void area_move_apply(bContext *C, wmOperator *op)
|
||||
sAreaMoveData *md = op->customdata;
|
||||
int delta = RNA_int_get(op->ptr, "delta");
|
||||
|
||||
area_move_apply_do(C, delta, md->origval, md->dir, md->bigger, md->smaller, md->snap_type);
|
||||
area_move_apply_do(C, delta, md->origval, md->dir_axis, md->bigger, md->smaller, md->snap_type);
|
||||
}
|
||||
|
||||
static void area_move_exit(bContext *C, wmOperator *op)
|
||||
@@ -1878,7 +1884,7 @@ static int area_move_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
int x = RNA_int_get(op->ptr, "x");
|
||||
int y = RNA_int_get(op->ptr, "y");
|
||||
|
||||
int delta = (md->dir == 'v') ? event->x - x : event->y - y;
|
||||
const int delta = (md->dir_axis == SCREEN_AXIS_V) ? event->x - x : event->y - y;
|
||||
RNA_int_set(op->ptr, "delta", delta);
|
||||
|
||||
area_move_apply(C, op);
|
||||
@@ -1944,7 +1950,7 @@ static void SCREEN_OT_area_move(wmOperatorType *ot)
|
||||
/*
|
||||
* operator state vars:
|
||||
* fac spit point
|
||||
* dir direction 'v' or 'h'
|
||||
* dir direction #SCREEN_AXIS_V or #SCREEN_AXIS_H
|
||||
*
|
||||
* operator customdata:
|
||||
* area pointer to (active) area
|
||||
@@ -1981,7 +1987,7 @@ typedef struct sAreaSplitData {
|
||||
int delta; /* delta move edge */
|
||||
int origmin, origsize; /* to calculate fac, for property storage */
|
||||
int previewmode; /* draw previewline, then split */
|
||||
void *draw_callback; /* call `ED_screen_draw_split_preview` */
|
||||
void *draw_callback; /* call `screen_draw_split_preview` */
|
||||
bool do_snap;
|
||||
|
||||
ScrEdge *nedge; /* new edge */
|
||||
@@ -1996,10 +2002,10 @@ static void area_split_draw_cb(const struct wmWindow *UNUSED(win), void *userdat
|
||||
|
||||
sAreaSplitData *sd = op->customdata;
|
||||
if (sd->sarea) {
|
||||
int dir = RNA_enum_get(op->ptr, "direction");
|
||||
const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction");
|
||||
float fac = RNA_float_get(op->ptr, "factor");
|
||||
|
||||
ED_screen_draw_split_preview(sd->sarea, dir, fac);
|
||||
screen_draw_split_preview(sd->sarea, dir_axis, fac);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2026,14 +2032,18 @@ static bool area_split_init(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
/* required properties */
|
||||
int dir = RNA_enum_get(op->ptr, "direction");
|
||||
const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction");
|
||||
|
||||
/* minimal size */
|
||||
if (dir == 'v' && area->winx < 2 * AREAMINX) {
|
||||
return false;
|
||||
if (dir_axis == SCREEN_AXIS_V) {
|
||||
if (area->winx < 2 * AREAMINX) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (dir == 'h' && area->winy < 2 * ED_area_headersize()) {
|
||||
return false;
|
||||
else {
|
||||
if (area->winy < 2 * ED_area_headersize()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* custom data */
|
||||
@@ -2041,7 +2051,7 @@ static bool area_split_init(bContext *C, wmOperator *op)
|
||||
op->customdata = sd;
|
||||
|
||||
sd->sarea = area;
|
||||
if (dir == 'v') {
|
||||
if (dir_axis == SCREEN_AXIS_V) {
|
||||
sd->origmin = area->v1->vec.x;
|
||||
sd->origsize = area->v4->vec.x - sd->origmin;
|
||||
}
|
||||
@@ -2090,9 +2100,9 @@ static bool area_split_apply(bContext *C, wmOperator *op)
|
||||
sAreaSplitData *sd = (sAreaSplitData *)op->customdata;
|
||||
|
||||
float fac = RNA_float_get(op->ptr, "factor");
|
||||
int dir = RNA_enum_get(op->ptr, "direction");
|
||||
const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction");
|
||||
|
||||
sd->narea = area_split(win, screen, sd->sarea, dir, fac, false); /* false = no merge */
|
||||
sd->narea = area_split(win, screen, sd->sarea, dir_axis, fac, false); /* false = no merge */
|
||||
|
||||
if (sd->narea == NULL) {
|
||||
return false;
|
||||
@@ -2109,7 +2119,7 @@ static bool area_split_apply(bContext *C, wmOperator *op)
|
||||
sd->nedge->v1->editflag = 1;
|
||||
sd->nedge->v2->editflag = 1;
|
||||
|
||||
if (dir == 'h') {
|
||||
if (dir_axis == SCREEN_AXIS_H) {
|
||||
sd->origval = sd->nedge->v1->vec.y;
|
||||
}
|
||||
else {
|
||||
@@ -2158,8 +2168,8 @@ static void area_split_exit(bContext *C, wmOperator *op)
|
||||
static void area_split_preview_update_cursor(bContext *C, wmOperator *op)
|
||||
{
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
int dir = RNA_enum_get(op->ptr, "direction");
|
||||
WM_cursor_set(win, dir == 'h' ? WM_CURSOR_H_SPLIT : WM_CURSOR_V_SPLIT);
|
||||
const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction");
|
||||
WM_cursor_set(win, (dir_axis == SCREEN_AXIS_H) ? WM_CURSOR_H_SPLIT : WM_CURSOR_V_SPLIT);
|
||||
}
|
||||
|
||||
/* UI callback, adds new handler */
|
||||
@@ -2175,7 +2185,7 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
PropertyRNA *prop_factor = RNA_struct_find_property(op->ptr, "factor");
|
||||
PropertyRNA *prop_cursor = RNA_struct_find_property(op->ptr, "cursor");
|
||||
|
||||
int dir;
|
||||
eScreenAxis dir_axis;
|
||||
if (event->type == EVT_ACTIONZONE_AREA) {
|
||||
sActionzoneData *sad = event->customdata;
|
||||
|
||||
@@ -2203,12 +2213,12 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
float factor;
|
||||
|
||||
/* Prepare operator state vars. */
|
||||
if (ELEM(sad->gesture_dir, 'n', 's')) {
|
||||
dir = 'h';
|
||||
if (SCREEN_DIR_IS_VERTICAL(sad->gesture_dir)) {
|
||||
dir_axis = SCREEN_AXIS_H;
|
||||
factor = factor_h;
|
||||
}
|
||||
else {
|
||||
dir = 'v';
|
||||
dir_axis = SCREEN_AXIS_V;
|
||||
factor = factor_v;
|
||||
}
|
||||
|
||||
@@ -2218,7 +2228,7 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
|
||||
RNA_property_float_set(op->ptr, prop_factor, factor);
|
||||
|
||||
RNA_property_enum_set(op->ptr, prop_dir, dir);
|
||||
RNA_property_enum_set(op->ptr, prop_dir, dir_axis);
|
||||
|
||||
/* general init, also non-UI case, adds customdata, sets area and defaults */
|
||||
if (!area_split_init(C, op)) {
|
||||
@@ -2230,8 +2240,8 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
if (area == NULL) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
dir = RNA_property_enum_get(op->ptr, prop_dir);
|
||||
if (dir == 'h') {
|
||||
dir_axis = RNA_property_enum_get(op->ptr, prop_dir);
|
||||
if (dir_axis == SCREEN_AXIS_H) {
|
||||
RNA_property_float_set(
|
||||
op->ptr, prop_factor, ((float)(event->x - area->v1->vec.x)) / (float)area->winx);
|
||||
}
|
||||
@@ -2264,9 +2274,9 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
dir = screen_geom_edge_is_horizontal(actedge) ? 'v' : 'h';
|
||||
dir_axis = screen_geom_edge_is_horizontal(actedge) ? SCREEN_AXIS_V : SCREEN_AXIS_H;
|
||||
|
||||
RNA_property_enum_set(op->ptr, prop_dir, dir);
|
||||
RNA_property_enum_set(op->ptr, prop_dir, dir_axis);
|
||||
|
||||
/* special case, adds customdata, sets defaults */
|
||||
if (!area_split_menu_init(C, op)) {
|
||||
@@ -2279,7 +2289,7 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
if (event->type == EVT_ACTIONZONE_AREA) {
|
||||
/* do the split */
|
||||
if (area_split_apply(C, op)) {
|
||||
area_move_set_limits(win, screen, dir, &sd->bigger, &sd->smaller, NULL);
|
||||
area_move_set_limits(win, screen, dir_axis, &sd->bigger, &sd->smaller, NULL);
|
||||
|
||||
/* add temp handler for edge move or cancel */
|
||||
G.moving |= G_TRANSFORM_WM;
|
||||
@@ -2367,8 +2377,9 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
else {
|
||||
if (event->val == KM_PRESS) {
|
||||
if (sd->sarea) {
|
||||
int dir = RNA_property_enum_get(op->ptr, prop_dir);
|
||||
RNA_property_enum_set(op->ptr, prop_dir, (dir == 'v') ? 'h' : 'v');
|
||||
const eScreenAxis dir_axis = RNA_property_enum_get(op->ptr, prop_dir);
|
||||
RNA_property_enum_set(
|
||||
op->ptr, prop_dir, (dir_axis == SCREEN_AXIS_V) ? SCREEN_AXIS_H : SCREEN_AXIS_V);
|
||||
area_split_preview_update_cursor(C, op);
|
||||
update_factor = true;
|
||||
}
|
||||
@@ -2389,9 +2400,9 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
}
|
||||
|
||||
if (update_factor) {
|
||||
const int dir = RNA_property_enum_get(op->ptr, prop_dir);
|
||||
const eScreenAxis dir_axis = RNA_property_enum_get(op->ptr, prop_dir);
|
||||
|
||||
sd->delta = (dir == 'v') ? event->x - sd->origval : event->y - sd->origval;
|
||||
sd->delta = (dir_axis == SCREEN_AXIS_V) ? event->x - sd->origval : event->y - sd->origval;
|
||||
|
||||
if (sd->previewmode == 0) {
|
||||
if (sd->do_snap) {
|
||||
@@ -2399,12 +2410,12 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
SNAP_FRACTION_AND_ADJACENT,
|
||||
sd->delta,
|
||||
sd->origval,
|
||||
dir,
|
||||
dir_axis,
|
||||
sd->bigger,
|
||||
sd->smaller);
|
||||
sd->delta = snap_loc - sd->origval;
|
||||
}
|
||||
area_move_apply_do(C, sd->delta, sd->origval, dir, sd->bigger, sd->smaller, SNAP_NONE);
|
||||
area_move_apply_do(C, sd->delta, sd->origval, dir_axis, sd->bigger, sd->smaller, SNAP_NONE);
|
||||
}
|
||||
else {
|
||||
if (sd->sarea) {
|
||||
@@ -2415,7 +2426,7 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
|
||||
if (sd->sarea) {
|
||||
ScrArea *area = sd->sarea;
|
||||
if (dir == 'v') {
|
||||
if (dir_axis == SCREEN_AXIS_V) {
|
||||
sd->origmin = area->v1->vec.x;
|
||||
sd->origsize = area->v4->vec.x - sd->origmin;
|
||||
}
|
||||
@@ -2431,7 +2442,7 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
SNAP_FRACTION_AND_ADJACENT,
|
||||
sd->delta,
|
||||
sd->origval,
|
||||
dir,
|
||||
dir_axis,
|
||||
sd->origmin + sd->origsize,
|
||||
-sd->origmin);
|
||||
|
||||
@@ -2453,8 +2464,8 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
}
|
||||
|
||||
static const EnumPropertyItem prop_direction_items[] = {
|
||||
{'h', "HORIZONTAL", 0, "Horizontal", ""},
|
||||
{'v', "VERTICAL", 0, "Vertical", ""},
|
||||
{SCREEN_AXIS_H, "HORIZONTAL", 0, "Horizontal", ""},
|
||||
{SCREEN_AXIS_V, "VERTICAL", 0, "Vertical", ""},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -2475,7 +2486,7 @@ static void SCREEN_OT_area_split(wmOperatorType *ot)
|
||||
ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
||||
|
||||
/* rna */
|
||||
RNA_def_enum(ot->srna, "direction", prop_direction_items, 'h', "Direction", "");
|
||||
RNA_def_enum(ot->srna, "direction", prop_direction_items, SCREEN_AXIS_H, "Direction", "");
|
||||
RNA_def_float(ot->srna, "factor", 0.5f, 0.0, 1.0, "Factor", "", 0.0, 1.0);
|
||||
RNA_def_int_vector(
|
||||
ot->srna, "cursor", 2, NULL, INT_MIN, INT_MAX, "Cursor", "", INT_MIN, INT_MAX);
|
||||
@@ -3272,8 +3283,8 @@ static void SCREEN_OT_screen_full_area(wmOperatorType *ot)
|
||||
typedef struct sAreaJoinData {
|
||||
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' */
|
||||
eScreenDir dir; /* Direction of potential join. */
|
||||
void *draw_callback; /* call #screen_draw_join_highlight */
|
||||
|
||||
} sAreaJoinData;
|
||||
|
||||
@@ -3282,8 +3293,8 @@ 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 && (sd->dir != -1)) {
|
||||
ED_screen_draw_join_highlight(sd->sa1, sd->sa2);
|
||||
if (sd->sa1 && sd->sa2 && (sd->dir != SCREEN_DIR_NONE)) {
|
||||
screen_draw_join_highlight(sd->sa1, sd->sa2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3305,7 +3316,7 @@ static bool area_join_init(bContext *C, wmOperator *op, ScrArea *sa1, ScrArea *s
|
||||
|
||||
jd->sa1 = sa1;
|
||||
jd->sa2 = sa2;
|
||||
jd->dir = -1;
|
||||
jd->dir = SCREEN_DIR_NONE;
|
||||
|
||||
op->customdata = jd;
|
||||
|
||||
@@ -3318,7 +3329,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 || (jd->dir == -1)) {
|
||||
if (!jd || (jd->dir == SCREEN_DIR_NONE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3429,21 +3440,21 @@ static int area_join_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
jd->dir = area_getorientation(jd->sa1, jd->sa2);
|
||||
}
|
||||
else if (area != jd->sa2) {
|
||||
jd->dir = -1;
|
||||
jd->dir = SCREEN_DIR_NONE;
|
||||
}
|
||||
|
||||
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
||||
|
||||
if (jd->dir == 1) {
|
||||
if (jd->dir == SCREEN_DIR_N) {
|
||||
WM_cursor_set(win, WM_CURSOR_N_ARROW);
|
||||
}
|
||||
else if (jd->dir == 3) {
|
||||
else if (jd->dir == SCREEN_DIR_S) {
|
||||
WM_cursor_set(win, WM_CURSOR_S_ARROW);
|
||||
}
|
||||
else if (jd->dir == 2) {
|
||||
else if (jd->dir == SCREEN_DIR_E) {
|
||||
WM_cursor_set(win, WM_CURSOR_E_ARROW);
|
||||
}
|
||||
else if (jd->dir == 0) {
|
||||
else if (jd->dir == SCREEN_DIR_W) {
|
||||
WM_cursor_set(win, WM_CURSOR_W_ARROW);
|
||||
}
|
||||
else {
|
||||
@@ -3454,7 +3465,7 @@ static int area_join_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
}
|
||||
case LEFTMOUSE:
|
||||
if (event->val == KM_RELEASE) {
|
||||
if (jd->dir == -1) {
|
||||
if (jd->dir == SCREEN_DIR_NONE) {
|
||||
area_join_cancel(C, op);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
@@ -3528,7 +3539,7 @@ static int screen_area_options_invoke(bContext *C, wmOperator *op, const wmEvent
|
||||
&ptr);
|
||||
/* store initial mouse cursor position. */
|
||||
RNA_int_set_array(&ptr, "cursor", &event->x);
|
||||
RNA_enum_set(&ptr, "direction", 'v');
|
||||
RNA_enum_set(&ptr, "direction", SCREEN_AXIS_V);
|
||||
|
||||
/* Horizontal Split */
|
||||
uiItemFullO(layout,
|
||||
@@ -3541,7 +3552,7 @@ static int screen_area_options_invoke(bContext *C, wmOperator *op, const wmEvent
|
||||
&ptr);
|
||||
/* store initial mouse cursor position. */
|
||||
RNA_int_set_array(&ptr, "cursor", &event->x);
|
||||
RNA_enum_set(&ptr, "direction", 'h');
|
||||
RNA_enum_set(&ptr, "direction", SCREEN_AXIS_H);
|
||||
|
||||
if (sa1 && sa2) {
|
||||
uiItemS(layout);
|
||||
@@ -4126,7 +4137,7 @@ static void screen_area_menu_items(ScrArea *area, uiLayout *layout)
|
||||
&ptr);
|
||||
|
||||
RNA_int_set_array(&ptr, "cursor", loc);
|
||||
RNA_enum_set(&ptr, "direction", 'v');
|
||||
RNA_enum_set(&ptr, "direction", SCREEN_AXIS_V);
|
||||
|
||||
/* Horizontal Split */
|
||||
uiItemFullO(layout,
|
||||
@@ -4139,7 +4150,7 @@ static void screen_area_menu_items(ScrArea *area, uiLayout *layout)
|
||||
&ptr);
|
||||
|
||||
RNA_int_set_array(&ptr, "cursor", &loc[0]);
|
||||
RNA_enum_set(&ptr, "direction", 'h');
|
||||
RNA_enum_set(&ptr, "direction", SCREEN_AXIS_H);
|
||||
|
||||
uiItemS(layout);
|
||||
|
||||
@@ -5420,7 +5431,7 @@ static void context_cycle_prop_get(bScreen *screen,
|
||||
|
||||
static int space_context_cycle_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
||||
{
|
||||
const int direction = RNA_enum_get(op->ptr, "direction");
|
||||
const eScreenCycle direction = RNA_enum_get(op->ptr, "direction");
|
||||
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
@@ -5469,7 +5480,7 @@ static int space_workspace_cycle_invoke(bContext *C, wmOperator *op, const wmEve
|
||||
}
|
||||
|
||||
Main *bmain = CTX_data_main(C);
|
||||
const int direction = RNA_enum_get(op->ptr, "direction");
|
||||
const eScreenCycle direction = RNA_enum_get(op->ptr, "direction");
|
||||
WorkSpace *workspace_src = WM_window_get_active_workspace(win);
|
||||
WorkSpace *workspace_dst = NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user