Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/screen/screen_ops.c
| Show First 20 Lines • Show All 688 Lines • ▼ Show 20 Lines | |||||
| * modal() accept modal events while doing it | * modal() accept modal events while doing it | ||||
| * call apply() with gesture info, active window, nonactive window | * call apply() with gesture info, active window, nonactive window | ||||
| * call exit() and remove handler when LMB confirm | * call exit() and remove handler when LMB confirm | ||||
| */ | */ | ||||
| typedef struct sActionzoneData { | typedef struct sActionzoneData { | ||||
| ScrArea *sa1, *sa2; | ScrArea *sa1, *sa2; | ||||
| AZone *az; | AZone *az; | ||||
| int x, y, gesture_dir, modifier; | int x, y; | ||||
| eScreenDir gesture_dir; | |||||
| int modifier; | |||||
| } sActionzoneData; | } sActionzoneData; | ||||
| /* quick poll to save operators to be created and handled */ | /* quick poll to save operators to be created and handled */ | ||||
| static bool actionzone_area_poll(bContext *C) | static bool actionzone_area_poll(bContext *C) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| bScreen *screen = WM_window_get_active_screen(win); | bScreen *screen = WM_window_get_active_screen(win); | ||||
| ▲ Show 20 Lines • Show All 334 Lines • ▼ Show 20 Lines | case MOUSEMOVE: { | ||||
| /* Movement in dominant direction before action taken. */ | /* Movement in dominant direction before action taken. */ | ||||
| const int join_threshold = (0.6 * U.widget_unit); | const int join_threshold = (0.6 * U.widget_unit); | ||||
| const int split_threshold = (1.2 * U.widget_unit); | const int split_threshold = (1.2 * U.widget_unit); | ||||
| const int area_threshold = (0.1 * U.widget_unit); | const int area_threshold = (0.1 * U.widget_unit); | ||||
| /* Calculate gesture cardinal direction. */ | /* Calculate gesture cardinal direction. */ | ||||
| if (delta_y > abs(delta_x)) { | if (delta_y > abs(delta_x)) { | ||||
| sad->gesture_dir = 'n'; | sad->gesture_dir = SCREEN_DIR_N; | ||||
| } | } | ||||
| else if (delta_x >= abs(delta_y)) { | else if (delta_x >= abs(delta_y)) { | ||||
| sad->gesture_dir = 'e'; | sad->gesture_dir = SCREEN_DIR_E; | ||||
| } | } | ||||
| else if (delta_y < -abs(delta_x)) { | else if (delta_y < -abs(delta_x)) { | ||||
| sad->gesture_dir = 's'; | sad->gesture_dir = SCREEN_DIR_S; | ||||
| } | } | ||||
| else { | else { | ||||
| sad->gesture_dir = 'w'; | sad->gesture_dir = SCREEN_DIR_W; | ||||
| } | } | ||||
| bool is_gesture; | bool is_gesture; | ||||
| if (sad->az->type == AZONE_AREA) { | if (sad->az->type == AZONE_AREA) { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| rcti screen_rect; | rcti screen_rect; | ||||
| WM_window_screen_rect_calc(win, &screen_rect); | WM_window_screen_rect_calc(win, &screen_rect); | ||||
| /* Have we dragged off the zone and are not on an edge? */ | /* Have we dragged off the zone and are not on an edge? */ | ||||
| if ((ED_area_actionzone_find_xy(sad->sa1, &event->x) != sad->az) && | if ((ED_area_actionzone_find_xy(sad->sa1, &event->x) != sad->az) && | ||||
| (screen_geom_area_map_find_active_scredge( | (screen_geom_area_map_find_active_scredge( | ||||
| AREAMAP_FROM_SCREEN(screen), &screen_rect, event->x, event->y) == NULL)) { | AREAMAP_FROM_SCREEN(screen), &screen_rect, event->x, event->y) == NULL)) { | ||||
| /* Are we still in same area? */ | /* Are we still in same area? */ | ||||
| if (BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->x, event->y) == sad->sa1) { | if (BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->x, event->y) == sad->sa1) { | ||||
| /* Same area, so possible split. */ | /* Same area, so possible split. */ | ||||
| WM_cursor_set( | WM_cursor_set(win, | ||||
| win, (ELEM(sad->gesture_dir, 'n', 's')) ? WM_CURSOR_H_SPLIT : WM_CURSOR_V_SPLIT); | SCREEN_DIR_IS_VERTICAL(sad->gesture_dir) ? WM_CURSOR_H_SPLIT : | ||||
| WM_CURSOR_V_SPLIT); | |||||
| is_gesture = (delta_max > split_threshold); | is_gesture = (delta_max > split_threshold); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Different area, so possible join. */ | /* 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); | 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); | 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); | WM_cursor_set(win, WM_CURSOR_E_ARROW); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(sad->gesture_dir == SCREEN_DIR_W); | |||||
| WM_cursor_set(win, WM_CURSOR_W_ARROW); | WM_cursor_set(win, WM_CURSOR_W_ARROW); | ||||
| } | } | ||||
| is_gesture = (delta_max > join_threshold); | is_gesture = (delta_max > join_threshold); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| WM_cursor_set(CTX_wm_window(C), WM_CURSOR_CROSS); | WM_cursor_set(CTX_wm_window(C), WM_CURSOR_CROSS); | ||||
| is_gesture = false; | is_gesture = false; | ||||
| ▲ Show 20 Lines • Show All 377 Lines • ▼ Show 20 Lines | |||||
| * | * | ||||
| * modal() accept modal events while doing it | * modal() accept modal events while doing it | ||||
| * call apply() with delta motion | * call apply() with delta motion | ||||
| * call exit() and remove handler | * call exit() and remove handler | ||||
| */ | */ | ||||
| typedef struct sAreaMoveData { | typedef struct sAreaMoveData { | ||||
| int bigger, smaller, origval, step; | int bigger, smaller, origval, step; | ||||
| char dir; | eScreenAxis dir_axis; | ||||
| enum AreaMoveSnapType { | enum AreaMoveSnapType { | ||||
| /* Snapping disabled */ | /* Snapping disabled */ | ||||
| SNAP_NONE = 0, | SNAP_NONE = 0, | ||||
| /* Snap to an invisible grid with a unit defined in AREAGRID */ | /* Snap to an invisible grid with a unit defined in AREAGRID */ | ||||
| SNAP_AREAGRID, | SNAP_AREAGRID, | ||||
| /* Snap to fraction (half, third.. etc) and adjacent edges. */ | /* Snap to fraction (half, third.. etc) and adjacent edges. */ | ||||
| SNAP_FRACTION_AND_ADJACENT, | SNAP_FRACTION_AND_ADJACENT, | ||||
| /* Snap to either bigger or smaller, nothing in-between (used for | /* Snap to either bigger or smaller, nothing in-between (used for | ||||
| * global areas). This has priority over other snap types, if it is | * global areas). This has priority over other snap types, if it is | ||||
| * used, toggling SNAP_FRACTION_AND_ADJACENT doesn't work. */ | * used, toggling SNAP_FRACTION_AND_ADJACENT doesn't work. */ | ||||
| SNAP_BIGGER_SMALLER_ONLY, | SNAP_BIGGER_SMALLER_ONLY, | ||||
| } snap_type; | } snap_type; | ||||
| } sAreaMoveData; | } sAreaMoveData; | ||||
| /* helper call to move area-edge, sets limits | /* helper call to move area-edge, sets limits | ||||
| * need window bounds in order to get correct limits */ | * need window bounds in order to get correct limits */ | ||||
| static void area_move_set_limits(wmWindow *win, | static void area_move_set_limits(wmWindow *win, | ||||
| bScreen *screen, | bScreen *screen, | ||||
| int dir, | const eScreenAxis dir_axis, | ||||
| int *bigger, | int *bigger, | ||||
| int *smaller, | int *smaller, | ||||
| bool *use_bigger_smaller_snap) | bool *use_bigger_smaller_snap) | ||||
| { | { | ||||
| /* we check all areas and test for free space with MINSIZE */ | /* we check all areas and test for free space with MINSIZE */ | ||||
| *bigger = *smaller = 100000; | *bigger = *smaller = 100000; | ||||
| if (use_bigger_smaller_snap != NULL) { | if (use_bigger_smaller_snap != NULL) { | ||||
| Show All 36 Lines | LISTBASE_FOREACH (ScrArea *, area, &win->global_areas.areabase) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| rcti window_rect; | rcti window_rect; | ||||
| WM_window_rect_calc(win, &window_rect); | WM_window_rect_calc(win, &window_rect); | ||||
| LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | ||||
| if (dir == 'h') { | if (dir_axis == SCREEN_AXIS_H) { | ||||
| int areamin = ED_area_headersize(); | int areamin = ED_area_headersize(); | ||||
| if (area->v1->vec.y > window_rect.ymin) { | if (area->v1->vec.y > window_rect.ymin) { | ||||
| areamin += U.pixelsize; | areamin += U.pixelsize; | ||||
| } | } | ||||
| if (area->v2->vec.y < (window_rect.ymax - 1)) { | if (area->v2->vec.y < (window_rect.ymax - 1)) { | ||||
| areamin += U.pixelsize; | areamin += U.pixelsize; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | static bool area_move_init(bContext *C, wmOperator *op) | ||||
| ScrEdge *actedge = screen_geom_find_active_scredge(win, screen, x, y); | ScrEdge *actedge = screen_geom_find_active_scredge(win, screen, x, y); | ||||
| if (actedge == NULL) { | if (actedge == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| sAreaMoveData *md = MEM_callocN(sizeof(sAreaMoveData), "sAreaMoveData"); | sAreaMoveData *md = MEM_callocN(sizeof(sAreaMoveData), "sAreaMoveData"); | ||||
| op->customdata = md; | op->customdata = md; | ||||
| md->dir = screen_geom_edge_is_horizontal(actedge) ? 'h' : 'v'; | md->dir_axis = screen_geom_edge_is_horizontal(actedge) ? SCREEN_AXIS_H : SCREEN_AXIS_V; | ||||
| if (md->dir == 'h') { | if (md->dir_axis == SCREEN_AXIS_H) { | ||||
| md->origval = actedge->v1->vec.y; | md->origval = actedge->v1->vec.y; | ||||
| } | } | ||||
| else { | else { | ||||
| md->origval = actedge->v1->vec.x; | md->origval = actedge->v1->vec.x; | ||||
| } | } | ||||
| screen_geom_select_connected_edge(win, actedge); | screen_geom_select_connected_edge(win, actedge); | ||||
| /* now all vertices with 'flag == 1' are the ones that can be moved. Move this to editflag */ | /* now all vertices with 'flag == 1' are the ones that can be moved. Move this to editflag */ | ||||
| ED_screen_verts_iter(win, screen, v1) | ED_screen_verts_iter(win, screen, v1) | ||||
| { | { | ||||
| v1->editflag = v1->flag; | v1->editflag = v1->flag; | ||||
| } | } | ||||
| bool use_bigger_smaller_snap = false; | 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; | md->snap_type = use_bigger_smaller_snap ? SNAP_BIGGER_SMALLER_ONLY : SNAP_AREAGRID; | ||||
| return true; | return true; | ||||
| } | } | ||||
| static int area_snap_calc_location(const bScreen *screen, | static int area_snap_calc_location(const bScreen *screen, | ||||
| const enum AreaMoveSnapType snap_type, | const enum AreaMoveSnapType snap_type, | ||||
| const int delta, | const int delta, | ||||
| const int origval, | const int origval, | ||||
| const int dir, | const eScreenAxis dir_axis, | ||||
| const int bigger, | const int bigger, | ||||
| const int smaller) | const int smaller) | ||||
| { | { | ||||
| BLI_assert(snap_type != SNAP_NONE); | BLI_assert(snap_type != SNAP_NONE); | ||||
| int m_cursor_final = -1; | int m_cursor_final = -1; | ||||
| const int m_cursor = origval + delta; | const int m_cursor = origval + delta; | ||||
| const int m_span = (float)(bigger + smaller); | const int m_span = (float)(bigger + smaller); | ||||
| const int m_min = origval - smaller; | const int m_min = origval - smaller; | ||||
| // const int axis_max = axis_min + m_span; | // const int axis_max = axis_min + m_span; | ||||
| switch (snap_type) { | switch (snap_type) { | ||||
| case SNAP_AREAGRID: | case SNAP_AREAGRID: | ||||
| m_cursor_final = m_cursor; | m_cursor_final = m_cursor; | ||||
| if (!ELEM(delta, bigger, -smaller)) { | if (!ELEM(delta, bigger, -smaller)) { | ||||
| m_cursor_final -= (m_cursor % AREAGRID); | m_cursor_final -= (m_cursor % AREAGRID); | ||||
| CLAMP(m_cursor_final, origval - smaller, origval + bigger); | CLAMP(m_cursor_final, origval - smaller, origval + bigger); | ||||
| } | } | ||||
| break; | break; | ||||
| case SNAP_BIGGER_SMALLER_ONLY: | case SNAP_BIGGER_SMALLER_ONLY: | ||||
| m_cursor_final = (m_cursor >= bigger) ? bigger : smaller; | m_cursor_final = (m_cursor >= bigger) ? bigger : smaller; | ||||
| break; | break; | ||||
| case SNAP_FRACTION_AND_ADJACENT: { | 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; | int snap_dist_best = INT_MAX; | ||||
| { | { | ||||
| const float div_array[] = { | const float div_array[] = { | ||||
| /* Middle. */ | /* Middle. */ | ||||
| 1.0f / 2.0f, | 1.0f / 2.0f, | ||||
| /* Thirds. */ | /* Thirds. */ | ||||
| 1.0f / 3.0f, | 1.0f / 3.0f, | ||||
| 2.0f / 3.0f, | 2.0f / 3.0f, | ||||
| ▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | static int area_snap_calc_location(const bScreen *screen, | ||||
| return m_cursor_final; | return m_cursor_final; | ||||
| } | } | ||||
| /* moves selected screen edge amount of delta, used by split & move */ | /* moves selected screen edge amount of delta, used by split & move */ | ||||
| static void area_move_apply_do(const bContext *C, | static void area_move_apply_do(const bContext *C, | ||||
| int delta, | int delta, | ||||
| const int origval, | const int origval, | ||||
| const int dir, | const eScreenAxis dir_axis, | ||||
| const int bigger, | const int bigger, | ||||
| const int smaller, | const int smaller, | ||||
| const enum AreaMoveSnapType snap_type) | const enum AreaMoveSnapType snap_type) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| bScreen *screen = CTX_wm_screen(C); | bScreen *screen = CTX_wm_screen(C); | ||||
| short final_loc = -1; | short final_loc = -1; | ||||
| bool doredraw = false; | bool doredraw = false; | ||||
| if (snap_type != SNAP_BIGGER_SMALLER_ONLY) { | if (snap_type != SNAP_BIGGER_SMALLER_ONLY) { | ||||
| CLAMP(delta, -smaller, bigger); | CLAMP(delta, -smaller, bigger); | ||||
| } | } | ||||
| if (snap_type == SNAP_NONE) { | if (snap_type == SNAP_NONE) { | ||||
| final_loc = origval + delta; | final_loc = origval + delta; | ||||
| } | } | ||||
| else { | 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); | 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) | ED_screen_verts_iter(win, screen, v1) | ||||
| { | { | ||||
| if (v1->editflag) { | if (v1->editflag) { | ||||
| short oldval = (&v1->vec.x)[axis]; | short oldval = (&v1->vec.x)[axis]; | ||||
| (&v1->vec.x)[axis] = final_loc; | (&v1->vec.x)[axis] = final_loc; | ||||
| if (oldval == final_loc) { | if (oldval == final_loc) { | ||||
| Show All 39 Lines | static void area_move_apply_do(const bContext *C, | ||||
| } | } | ||||
| } | } | ||||
| static void area_move_apply(bContext *C, wmOperator *op) | static void area_move_apply(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| sAreaMoveData *md = op->customdata; | sAreaMoveData *md = op->customdata; | ||||
| int delta = RNA_int_get(op->ptr, "delta"); | 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) | static void area_move_exit(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| if (op->customdata) { | if (op->customdata) { | ||||
| MEM_freeN(op->customdata); | MEM_freeN(op->customdata); | ||||
| } | } | ||||
| op->customdata = NULL; | op->customdata = NULL; | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | static int area_move_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| sAreaMoveData *md = op->customdata; | sAreaMoveData *md = op->customdata; | ||||
| /* execute the events */ | /* execute the events */ | ||||
| switch (event->type) { | switch (event->type) { | ||||
| case MOUSEMOVE: { | case MOUSEMOVE: { | ||||
| int x = RNA_int_get(op->ptr, "x"); | int x = RNA_int_get(op->ptr, "x"); | ||||
| int y = RNA_int_get(op->ptr, "y"); | 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); | RNA_int_set(op->ptr, "delta", delta); | ||||
| area_move_apply(C, op); | area_move_apply(C, op); | ||||
| break; | break; | ||||
| } | } | ||||
| case EVT_MODAL_MAP: { | case EVT_MODAL_MAP: { | ||||
| switch (event->val) { | switch (event->val) { | ||||
| case KM_MODAL_APPLY: | case KM_MODAL_APPLY: | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Split Area Operator | /** \name Split Area Operator | ||||
| * \{ */ | * \{ */ | ||||
| /* | /* | ||||
| * operator state vars: | * operator state vars: | ||||
| * fac spit point | * fac spit point | ||||
| * dir direction 'v' or 'h' | * dir direction #SCREEN_AXIS_V or #SCREEN_AXIS_H | ||||
| * | * | ||||
| * operator customdata: | * operator customdata: | ||||
| * area pointer to (active) area | * area pointer to (active) area | ||||
| * x, y last used mouse pos | * x, y last used mouse pos | ||||
| * (more, see below) | * (more, see below) | ||||
| * | * | ||||
| * functions: | * functions: | ||||
| * | * | ||||
| Show All 20 Lines | |||||
| */ | */ | ||||
| typedef struct sAreaSplitData { | typedef struct sAreaSplitData { | ||||
| int origval; /* for move areas */ | int origval; /* for move areas */ | ||||
| int bigger, smaller; /* constraints for moving new edge */ | int bigger, smaller; /* constraints for moving new edge */ | ||||
| int delta; /* delta move edge */ | int delta; /* delta move edge */ | ||||
| int origmin, origsize; /* to calculate fac, for property storage */ | int origmin, origsize; /* to calculate fac, for property storage */ | ||||
| int previewmode; /* draw previewline, then split */ | 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; | bool do_snap; | ||||
| ScrEdge *nedge; /* new edge */ | ScrEdge *nedge; /* new edge */ | ||||
| ScrArea *sarea; /* start area */ | ScrArea *sarea; /* start area */ | ||||
| ScrArea *narea; /* new area */ | ScrArea *narea; /* new area */ | ||||
| } sAreaSplitData; | } sAreaSplitData; | ||||
| static void area_split_draw_cb(const struct wmWindow *UNUSED(win), void *userdata) | static void area_split_draw_cb(const struct wmWindow *UNUSED(win), void *userdata) | ||||
| { | { | ||||
| const wmOperator *op = userdata; | const wmOperator *op = userdata; | ||||
| sAreaSplitData *sd = op->customdata; | sAreaSplitData *sd = op->customdata; | ||||
| if (sd->sarea) { | 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"); | 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); | ||||
| } | } | ||||
| } | } | ||||
| /* generic init, menu case, doesn't need active area */ | /* generic init, menu case, doesn't need active area */ | ||||
| static bool area_split_menu_init(bContext *C, wmOperator *op) | static bool area_split_menu_init(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| /* custom data */ | /* custom data */ | ||||
| sAreaSplitData *sd = (sAreaSplitData *)MEM_callocN(sizeof(sAreaSplitData), "op_area_split"); | sAreaSplitData *sd = (sAreaSplitData *)MEM_callocN(sizeof(sAreaSplitData), "op_area_split"); | ||||
| Show All 10 Lines | static bool area_split_init(bContext *C, wmOperator *op) | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| /* required context */ | /* required context */ | ||||
| if (area == NULL) { | if (area == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* required properties */ | /* required properties */ | ||||
| int dir = RNA_enum_get(op->ptr, "direction"); | const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction"); | ||||
| /* minimal size */ | /* minimal size */ | ||||
| if (dir == 'v' && area->winx < 2 * AREAMINX) { | if (dir_axis == SCREEN_AXIS_V) { | ||||
| if (area->winx < 2 * AREAMINX) { | |||||
| return false; | return false; | ||||
| } | } | ||||
| if (dir == 'h' && area->winy < 2 * ED_area_headersize()) { | } | ||||
| else { | |||||
| if (area->winy < 2 * ED_area_headersize()) { | |||||
| return false; | return false; | ||||
| } | } | ||||
| } | |||||
| /* custom data */ | /* custom data */ | ||||
| sAreaSplitData *sd = (sAreaSplitData *)MEM_callocN(sizeof(sAreaSplitData), "op_area_split"); | sAreaSplitData *sd = (sAreaSplitData *)MEM_callocN(sizeof(sAreaSplitData), "op_area_split"); | ||||
| op->customdata = sd; | op->customdata = sd; | ||||
| sd->sarea = area; | sd->sarea = area; | ||||
| if (dir == 'v') { | if (dir_axis == SCREEN_AXIS_V) { | ||||
| sd->origmin = area->v1->vec.x; | sd->origmin = area->v1->vec.x; | ||||
| sd->origsize = area->v4->vec.x - sd->origmin; | sd->origsize = area->v4->vec.x - sd->origmin; | ||||
| } | } | ||||
| else { | else { | ||||
| sd->origmin = area->v1->vec.y; | sd->origmin = area->v1->vec.y; | ||||
| sd->origsize = area->v2->vec.y - sd->origmin; | sd->origsize = area->v2->vec.y - sd->origmin; | ||||
| } | } | ||||
| Show All 32 Lines | |||||
| /* do the split, return success */ | /* do the split, return success */ | ||||
| static bool area_split_apply(bContext *C, wmOperator *op) | static bool area_split_apply(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| const wmWindow *win = CTX_wm_window(C); | const wmWindow *win = CTX_wm_window(C); | ||||
| bScreen *screen = CTX_wm_screen(C); | bScreen *screen = CTX_wm_screen(C); | ||||
| sAreaSplitData *sd = (sAreaSplitData *)op->customdata; | sAreaSplitData *sd = (sAreaSplitData *)op->customdata; | ||||
| float fac = RNA_float_get(op->ptr, "factor"); | 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) { | if (sd->narea == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| sd->nedge = area_findsharededge(screen, sd->sarea, sd->narea); | sd->nedge = area_findsharededge(screen, sd->sarea, sd->narea); | ||||
| /* select newly created edge, prepare for moving edge */ | /* select newly created edge, prepare for moving edge */ | ||||
| ED_screen_verts_iter(win, screen, sv) | ED_screen_verts_iter(win, screen, sv) | ||||
| { | { | ||||
| sv->editflag = 0; | sv->editflag = 0; | ||||
| } | } | ||||
| sd->nedge->v1->editflag = 1; | sd->nedge->v1->editflag = 1; | ||||
| sd->nedge->v2->editflag = 1; | sd->nedge->v2->editflag = 1; | ||||
| if (dir == 'h') { | if (dir_axis == SCREEN_AXIS_H) { | ||||
| sd->origval = sd->nedge->v1->vec.y; | sd->origval = sd->nedge->v1->vec.y; | ||||
| } | } | ||||
| else { | else { | ||||
| sd->origval = sd->nedge->v1->vec.x; | sd->origval = sd->nedge->v1->vec.x; | ||||
| } | } | ||||
| ED_area_tag_redraw(sd->sarea); | ED_area_tag_redraw(sd->sarea); | ||||
| ED_area_tag_redraw(sd->narea); | ED_area_tag_redraw(sd->narea); | ||||
| Show All 32 Lines | static void area_split_exit(bContext *C, wmOperator *op) | ||||
| BKE_screen_remove_double_scredges(CTX_wm_screen(C)); | BKE_screen_remove_double_scredges(CTX_wm_screen(C)); | ||||
| G.moving &= ~G_TRANSFORM_WM; | G.moving &= ~G_TRANSFORM_WM; | ||||
| } | } | ||||
| static void area_split_preview_update_cursor(bContext *C, wmOperator *op) | static void area_split_preview_update_cursor(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| int dir = RNA_enum_get(op->ptr, "direction"); | const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction"); | ||||
| WM_cursor_set(win, dir == 'h' ? WM_CURSOR_H_SPLIT : WM_CURSOR_V_SPLIT); | WM_cursor_set(win, (dir_axis == SCREEN_AXIS_H) ? WM_CURSOR_H_SPLIT : WM_CURSOR_V_SPLIT); | ||||
| } | } | ||||
| /* UI callback, adds new handler */ | /* UI callback, adds new handler */ | ||||
| static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| bScreen *screen = CTX_wm_screen(C); | bScreen *screen = CTX_wm_screen(C); | ||||
| /* no full window splitting allowed */ | /* no full window splitting allowed */ | ||||
| BLI_assert(screen->state == SCREENNORMAL); | BLI_assert(screen->state == SCREENNORMAL); | ||||
| PropertyRNA *prop_dir = RNA_struct_find_property(op->ptr, "direction"); | PropertyRNA *prop_dir = RNA_struct_find_property(op->ptr, "direction"); | ||||
| PropertyRNA *prop_factor = RNA_struct_find_property(op->ptr, "factor"); | PropertyRNA *prop_factor = RNA_struct_find_property(op->ptr, "factor"); | ||||
| PropertyRNA *prop_cursor = RNA_struct_find_property(op->ptr, "cursor"); | PropertyRNA *prop_cursor = RNA_struct_find_property(op->ptr, "cursor"); | ||||
| int dir; | eScreenAxis dir_axis; | ||||
| if (event->type == EVT_ACTIONZONE_AREA) { | if (event->type == EVT_ACTIONZONE_AREA) { | ||||
| sActionzoneData *sad = event->customdata; | sActionzoneData *sad = event->customdata; | ||||
| if (sad == NULL || sad->modifier > 0) { | if (sad == NULL || sad->modifier > 0) { | ||||
| return OPERATOR_PASS_THROUGH; | return OPERATOR_PASS_THROUGH; | ||||
| } | } | ||||
| /* verify *sad itself */ | /* verify *sad itself */ | ||||
| Show All 11 Lines | if (event->type == EVT_ACTIONZONE_AREA) { | ||||
| const float factor_h = ((float)(event->x - sad->sa1->v1->vec.x)) / (float)sad->sa1->winx; | const float factor_h = ((float)(event->x - sad->sa1->v1->vec.x)) / (float)sad->sa1->winx; | ||||
| const bool is_left = factor_v < 0.5f; | const bool is_left = factor_v < 0.5f; | ||||
| const bool is_bottom = factor_h < 0.5f; | const bool is_bottom = factor_h < 0.5f; | ||||
| const bool is_right = !is_left; | const bool is_right = !is_left; | ||||
| const bool is_top = !is_bottom; | const bool is_top = !is_bottom; | ||||
| float factor; | float factor; | ||||
| /* Prepare operator state vars. */ | /* Prepare operator state vars. */ | ||||
| if (ELEM(sad->gesture_dir, 'n', 's')) { | if (SCREEN_DIR_IS_VERTICAL(sad->gesture_dir)) { | ||||
| dir = 'h'; | dir_axis = SCREEN_AXIS_H; | ||||
| factor = factor_h; | factor = factor_h; | ||||
| } | } | ||||
| else { | else { | ||||
| dir = 'v'; | dir_axis = SCREEN_AXIS_V; | ||||
| factor = factor_v; | factor = factor_v; | ||||
| } | } | ||||
| if ((is_top && is_left) || (is_bottom && is_right)) { | if ((is_top && is_left) || (is_bottom && is_right)) { | ||||
| factor = 1.0f - factor; | factor = 1.0f - factor; | ||||
| } | } | ||||
| RNA_property_float_set(op->ptr, prop_factor, factor); | 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 */ | /* general init, also non-UI case, adds customdata, sets area and defaults */ | ||||
| if (!area_split_init(C, op)) { | if (!area_split_init(C, op)) { | ||||
| return OPERATOR_PASS_THROUGH; | return OPERATOR_PASS_THROUGH; | ||||
| } | } | ||||
| } | } | ||||
| else if (RNA_property_is_set(op->ptr, prop_dir)) { | else if (RNA_property_is_set(op->ptr, prop_dir)) { | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| if (area == NULL) { | if (area == NULL) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| dir = RNA_property_enum_get(op->ptr, prop_dir); | dir_axis = RNA_property_enum_get(op->ptr, prop_dir); | ||||
| if (dir == 'h') { | if (dir_axis == SCREEN_AXIS_H) { | ||||
| RNA_property_float_set( | RNA_property_float_set( | ||||
| op->ptr, prop_factor, ((float)(event->x - area->v1->vec.x)) / (float)area->winx); | op->ptr, prop_factor, ((float)(event->x - area->v1->vec.x)) / (float)area->winx); | ||||
| } | } | ||||
| else { | else { | ||||
| RNA_property_float_set( | RNA_property_float_set( | ||||
| op->ptr, prop_factor, ((float)(event->y - area->v1->vec.y)) / (float)area->winy); | op->ptr, prop_factor, ((float)(event->y - area->v1->vec.y)) / (float)area->winy); | ||||
| } | } | ||||
| Show All 16 Lines | else { | ||||
| WM_window_rect_calc(win, &window_rect); | WM_window_rect_calc(win, &window_rect); | ||||
| ScrEdge *actedge = screen_geom_area_map_find_active_scredge( | ScrEdge *actedge = screen_geom_area_map_find_active_scredge( | ||||
| AREAMAP_FROM_SCREEN(screen), &window_rect, event_co[0], event_co[1]); | AREAMAP_FROM_SCREEN(screen), &window_rect, event_co[0], event_co[1]); | ||||
| if (actedge == NULL) { | if (actedge == NULL) { | ||||
| return OPERATOR_CANCELLED; | 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 */ | /* special case, adds customdata, sets defaults */ | ||||
| if (!area_split_menu_init(C, op)) { | if (!area_split_menu_init(C, op)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| sAreaSplitData *sd = (sAreaSplitData *)op->customdata; | sAreaSplitData *sd = (sAreaSplitData *)op->customdata; | ||||
| if (event->type == EVT_ACTIONZONE_AREA) { | if (event->type == EVT_ACTIONZONE_AREA) { | ||||
| /* do the split */ | /* do the split */ | ||||
| if (area_split_apply(C, op)) { | 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 */ | /* add temp handler for edge move or cancel */ | ||||
| G.moving |= G_TRANSFORM_WM; | G.moving |= G_TRANSFORM_WM; | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | switch (event->type) { | ||||
| case MIDDLEMOUSE: | case MIDDLEMOUSE: | ||||
| case EVT_TABKEY: | case EVT_TABKEY: | ||||
| if (sd->previewmode == 0) { | if (sd->previewmode == 0) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else { | else { | ||||
| if (event->val == KM_PRESS) { | if (event->val == KM_PRESS) { | ||||
| if (sd->sarea) { | if (sd->sarea) { | ||||
| int dir = RNA_property_enum_get(op->ptr, prop_dir); | const eScreenAxis dir_axis = RNA_property_enum_get(op->ptr, prop_dir); | ||||
| RNA_property_enum_set(op->ptr, prop_dir, (dir == 'v') ? 'h' : 'v'); | 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); | area_split_preview_update_cursor(C, op); | ||||
| update_factor = true; | update_factor = true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case RIGHTMOUSE: /* cancel operation */ | case RIGHTMOUSE: /* cancel operation */ | ||||
| case EVT_ESCKEY: | case EVT_ESCKEY: | ||||
| area_split_cancel(C, op); | area_split_cancel(C, op); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| case EVT_LEFTCTRLKEY: | case EVT_LEFTCTRLKEY: | ||||
| sd->do_snap = event->val == KM_PRESS; | sd->do_snap = event->val == KM_PRESS; | ||||
| update_factor = true; | update_factor = true; | ||||
| break; | break; | ||||
| } | } | ||||
| if (update_factor) { | 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->previewmode == 0) { | ||||
| if (sd->do_snap) { | if (sd->do_snap) { | ||||
| const int snap_loc = area_snap_calc_location(CTX_wm_screen(C), | const int snap_loc = area_snap_calc_location(CTX_wm_screen(C), | ||||
| SNAP_FRACTION_AND_ADJACENT, | SNAP_FRACTION_AND_ADJACENT, | ||||
| sd->delta, | sd->delta, | ||||
| sd->origval, | sd->origval, | ||||
| dir, | dir_axis, | ||||
| sd->bigger, | sd->bigger, | ||||
| sd->smaller); | sd->smaller); | ||||
| sd->delta = snap_loc - sd->origval; | 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 { | else { | ||||
| if (sd->sarea) { | if (sd->sarea) { | ||||
| ED_area_tag_redraw(sd->sarea); | ED_area_tag_redraw(sd->sarea); | ||||
| } | } | ||||
| /* area context not set */ | /* area context not set */ | ||||
| sd->sarea = BKE_screen_find_area_xy(CTX_wm_screen(C), SPACE_TYPE_ANY, event->x, event->y); | sd->sarea = BKE_screen_find_area_xy(CTX_wm_screen(C), SPACE_TYPE_ANY, event->x, event->y); | ||||
| if (sd->sarea) { | if (sd->sarea) { | ||||
| ScrArea *area = sd->sarea; | ScrArea *area = sd->sarea; | ||||
| if (dir == 'v') { | if (dir_axis == SCREEN_AXIS_V) { | ||||
| sd->origmin = area->v1->vec.x; | sd->origmin = area->v1->vec.x; | ||||
| sd->origsize = area->v4->vec.x - sd->origmin; | sd->origsize = area->v4->vec.x - sd->origmin; | ||||
| } | } | ||||
| else { | else { | ||||
| sd->origmin = area->v1->vec.y; | sd->origmin = area->v1->vec.y; | ||||
| sd->origsize = area->v2->vec.y - sd->origmin; | sd->origsize = area->v2->vec.y - sd->origmin; | ||||
| } | } | ||||
| if (sd->do_snap) { | if (sd->do_snap) { | ||||
| area->v1->editflag = area->v2->editflag = area->v3->editflag = area->v4->editflag = 1; | area->v1->editflag = area->v2->editflag = area->v3->editflag = area->v4->editflag = 1; | ||||
| const int snap_loc = area_snap_calc_location(CTX_wm_screen(C), | const int snap_loc = area_snap_calc_location(CTX_wm_screen(C), | ||||
| SNAP_FRACTION_AND_ADJACENT, | SNAP_FRACTION_AND_ADJACENT, | ||||
| sd->delta, | sd->delta, | ||||
| sd->origval, | sd->origval, | ||||
| dir, | dir_axis, | ||||
| sd->origmin + sd->origsize, | sd->origmin + sd->origsize, | ||||
| -sd->origmin); | -sd->origmin); | ||||
| area->v1->editflag = area->v2->editflag = area->v3->editflag = area->v4->editflag = 0; | area->v1->editflag = area->v2->editflag = area->v3->editflag = area->v4->editflag = 0; | ||||
| sd->delta = snap_loc - sd->origval; | sd->delta = snap_loc - sd->origval; | ||||
| } | } | ||||
| ED_area_tag_redraw(sd->sarea); | ED_area_tag_redraw(sd->sarea); | ||||
| } | } | ||||
| CTX_wm_screen(C)->do_draw = true; | CTX_wm_screen(C)->do_draw = true; | ||||
| } | } | ||||
| float fac = (float)(sd->delta + sd->origval - sd->origmin) / sd->origsize; | float fac = (float)(sd->delta + sd->origval - sd->origmin) / sd->origsize; | ||||
| RNA_float_set(op->ptr, "factor", fac); | RNA_float_set(op->ptr, "factor", fac); | ||||
| } | } | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| static const EnumPropertyItem prop_direction_items[] = { | static const EnumPropertyItem prop_direction_items[] = { | ||||
| {'h', "HORIZONTAL", 0, "Horizontal", ""}, | {SCREEN_AXIS_H, "HORIZONTAL", 0, "Horizontal", ""}, | ||||
| {'v', "VERTICAL", 0, "Vertical", ""}, | {SCREEN_AXIS_V, "VERTICAL", 0, "Vertical", ""}, | ||||
| {0, NULL, 0, NULL, NULL}, | {0, NULL, 0, NULL, NULL}, | ||||
| }; | }; | ||||
| static void SCREEN_OT_area_split(wmOperatorType *ot) | static void SCREEN_OT_area_split(wmOperatorType *ot) | ||||
| { | { | ||||
| ot->name = "Split Area"; | ot->name = "Split Area"; | ||||
| ot->description = "Split selected area into new windows"; | ot->description = "Split selected area into new windows"; | ||||
| ot->idname = "SCREEN_OT_area_split"; | ot->idname = "SCREEN_OT_area_split"; | ||||
| ot->exec = area_split_exec; | ot->exec = area_split_exec; | ||||
| ot->invoke = area_split_invoke; | ot->invoke = area_split_invoke; | ||||
| ot->modal = area_split_modal; | ot->modal = area_split_modal; | ||||
| ot->cancel = area_split_cancel; | ot->cancel = area_split_cancel; | ||||
| ot->poll = screen_active_editable; | ot->poll = screen_active_editable; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL; | ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL; | ||||
| /* rna */ | /* 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_float(ot->srna, "factor", 0.5f, 0.0, 1.0, "Factor", "", 0.0, 1.0); | ||||
| RNA_def_int_vector( | RNA_def_int_vector( | ||||
| ot->srna, "cursor", 2, NULL, INT_MIN, INT_MAX, "Cursor", "", INT_MIN, INT_MAX); | ot->srna, "cursor", 2, NULL, INT_MIN, INT_MAX, "Cursor", "", INT_MIN, INT_MAX); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 780 Lines • ▼ Show 20 Lines | |||||
| * modal() accept modal events while doing it | * modal() accept modal events while doing it | ||||
| * call apply() with active window and nonactive window | * call apply() with active window and nonactive window | ||||
| * call exit() and remove handler when LMB confirm | * call exit() and remove handler when LMB confirm | ||||
| */ | */ | ||||
| typedef struct sAreaJoinData { | typedef struct sAreaJoinData { | ||||
| ScrArea *sa1; /* Potential source area (kept). */ | ScrArea *sa1; /* Potential source area (kept). */ | ||||
| ScrArea *sa2; /* Potential target area (removed or reduced). */ | ScrArea *sa2; /* Potential target area (removed or reduced). */ | ||||
| int dir; /* Direction of potential join. */ | eScreenDir dir; /* Direction of potential join. */ | ||||
| void *draw_callback; /* call 'ED_screen_draw_join_highlight' */ | void *draw_callback; /* call #screen_draw_join_highlight */ | ||||
| } sAreaJoinData; | } sAreaJoinData; | ||||
| static void area_join_draw_cb(const struct wmWindow *UNUSED(win), void *userdata) | static void area_join_draw_cb(const struct wmWindow *UNUSED(win), void *userdata) | ||||
| { | { | ||||
| const wmOperator *op = userdata; | const wmOperator *op = userdata; | ||||
| sAreaJoinData *sd = op->customdata; | sAreaJoinData *sd = op->customdata; | ||||
| if (sd->sa1 && sd->sa2 && (sd->dir != -1)) { | if (sd->sa1 && sd->sa2 && (sd->dir != SCREEN_DIR_NONE)) { | ||||
| ED_screen_draw_join_highlight(sd->sa1, sd->sa2); | screen_draw_join_highlight(sd->sa1, sd->sa2); | ||||
| } | } | ||||
| } | } | ||||
| /* validate selection inside screen, set variables OK */ | /* validate selection inside screen, set variables OK */ | ||||
| /* return false: init failed */ | /* return false: init failed */ | ||||
| static bool area_join_init(bContext *C, wmOperator *op, ScrArea *sa1, ScrArea *sa2) | static bool area_join_init(bContext *C, wmOperator *op, ScrArea *sa1, ScrArea *sa2) | ||||
| { | { | ||||
| if (sa1 == NULL || sa2 == NULL) { | if (sa1 == NULL || sa2 == NULL) { | ||||
| /* Get areas from cursor location if not specified. */ | /* Get areas from cursor location if not specified. */ | ||||
| int cursor[2]; | int cursor[2]; | ||||
| RNA_int_get_array(op->ptr, "cursor", cursor); | RNA_int_get_array(op->ptr, "cursor", cursor); | ||||
| screen_area_edge_from_cursor(C, cursor, &sa1, &sa2); | screen_area_edge_from_cursor(C, cursor, &sa1, &sa2); | ||||
| } | } | ||||
| if (sa1 == NULL || sa2 == NULL) { | if (sa1 == NULL || sa2 == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| sAreaJoinData *jd = MEM_callocN(sizeof(sAreaJoinData), "op_area_join"); | sAreaJoinData *jd = MEM_callocN(sizeof(sAreaJoinData), "op_area_join"); | ||||
| jd->sa1 = sa1; | jd->sa1 = sa1; | ||||
| jd->sa2 = sa2; | jd->sa2 = sa2; | ||||
| jd->dir = -1; | jd->dir = SCREEN_DIR_NONE; | ||||
| op->customdata = jd; | op->customdata = jd; | ||||
| jd->draw_callback = WM_draw_cb_activate(CTX_wm_window(C), area_join_draw_cb, op); | jd->draw_callback = WM_draw_cb_activate(CTX_wm_window(C), area_join_draw_cb, op); | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* apply the join of the areas (space types) */ | /* apply the join of the areas (space types) */ | ||||
| static bool area_join_apply(bContext *C, wmOperator *op) | static bool area_join_apply(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| sAreaJoinData *jd = (sAreaJoinData *)op->customdata; | sAreaJoinData *jd = (sAreaJoinData *)op->customdata; | ||||
| if (!jd || (jd->dir == -1)) { | if (!jd || (jd->dir == SCREEN_DIR_NONE)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (!screen_area_join(C, CTX_wm_screen(C), jd->sa1, jd->sa2)) { | if (!screen_area_join(C, CTX_wm_screen(C), jd->sa1, jd->sa2)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (CTX_wm_area(C) == jd->sa2) { | if (CTX_wm_area(C) == jd->sa2) { | ||||
| CTX_wm_area_set(C, NULL); | CTX_wm_area_set(C, NULL); | ||||
| ▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | case MOUSEMOVE: { | ||||
| if (area == jd->sa1) { | if (area == jd->sa1) { | ||||
| /* Hovering current source, so change direction. */ | /* Hovering current source, so change direction. */ | ||||
| jd->sa1 = jd->sa2; | jd->sa1 = jd->sa2; | ||||
| jd->sa2 = area; | jd->sa2 = area; | ||||
| jd->dir = area_getorientation(jd->sa1, jd->sa2); | jd->dir = area_getorientation(jd->sa1, jd->sa2); | ||||
| } | } | ||||
| else if (area != jd->sa2) { | else if (area != jd->sa2) { | ||||
| jd->dir = -1; | jd->dir = SCREEN_DIR_NONE; | ||||
| } | } | ||||
| WM_event_add_notifier(C, NC_WINDOW, NULL); | 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); | 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); | 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); | 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); | WM_cursor_set(win, WM_CURSOR_W_ARROW); | ||||
| } | } | ||||
| else { | else { | ||||
| WM_cursor_set(win, WM_CURSOR_STOP); | WM_cursor_set(win, WM_CURSOR_STOP); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case LEFTMOUSE: | case LEFTMOUSE: | ||||
| if (event->val == KM_RELEASE) { | if (event->val == KM_RELEASE) { | ||||
| if (jd->dir == -1) { | if (jd->dir == SCREEN_DIR_NONE) { | ||||
| area_join_cancel(C, op); | area_join_cancel(C, op); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ED_area_tag_redraw(jd->sa1); | ED_area_tag_redraw(jd->sa1); | ||||
| ED_area_tag_redraw(jd->sa2); | ED_area_tag_redraw(jd->sa2); | ||||
| area_join_apply(C, op); | area_join_apply(C, op); | ||||
| WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL); | WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL); | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | uiItemFullO(layout, | ||||
| IFACE_("Vertical Split"), | IFACE_("Vertical Split"), | ||||
| ICON_NONE, | ICON_NONE, | ||||
| NULL, | NULL, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| 0, | 0, | ||||
| &ptr); | &ptr); | ||||
| /* store initial mouse cursor position. */ | /* store initial mouse cursor position. */ | ||||
| RNA_int_set_array(&ptr, "cursor", &event->x); | RNA_int_set_array(&ptr, "cursor", &event->x); | ||||
| RNA_enum_set(&ptr, "direction", 'v'); | RNA_enum_set(&ptr, "direction", SCREEN_AXIS_V); | ||||
| /* Horizontal Split */ | /* Horizontal Split */ | ||||
| uiItemFullO(layout, | uiItemFullO(layout, | ||||
| "SCREEN_OT_area_split", | "SCREEN_OT_area_split", | ||||
| IFACE_("Horizontal Split"), | IFACE_("Horizontal Split"), | ||||
| ICON_NONE, | ICON_NONE, | ||||
| NULL, | NULL, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| 0, | 0, | ||||
| &ptr); | &ptr); | ||||
| /* store initial mouse cursor position. */ | /* store initial mouse cursor position. */ | ||||
| RNA_int_set_array(&ptr, "cursor", &event->x); | 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) { | if (sa1 && sa2) { | ||||
| uiItemS(layout); | uiItemS(layout); | ||||
| } | } | ||||
| /* Join needs two very similar areas. */ | /* Join needs two very similar areas. */ | ||||
| if (sa1 && sa2 && (area_getorientation(sa1, sa2) != -1)) { | if (sa1 && sa2 && (area_getorientation(sa1, sa2) != -1)) { | ||||
| uiItemFullO(layout, | uiItemFullO(layout, | ||||
| ▲ Show 20 Lines • Show All 568 Lines • ▼ Show 20 Lines | uiItemFullO(layout, | ||||
| IFACE_("Vertical Split"), | IFACE_("Vertical Split"), | ||||
| ICON_NONE, | ICON_NONE, | ||||
| NULL, | NULL, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| 0, | 0, | ||||
| &ptr); | &ptr); | ||||
| RNA_int_set_array(&ptr, "cursor", loc); | RNA_int_set_array(&ptr, "cursor", loc); | ||||
| RNA_enum_set(&ptr, "direction", 'v'); | RNA_enum_set(&ptr, "direction", SCREEN_AXIS_V); | ||||
| /* Horizontal Split */ | /* Horizontal Split */ | ||||
| uiItemFullO(layout, | uiItemFullO(layout, | ||||
| "SCREEN_OT_area_split", | "SCREEN_OT_area_split", | ||||
| IFACE_("Horizontal Split"), | IFACE_("Horizontal Split"), | ||||
| ICON_NONE, | ICON_NONE, | ||||
| NULL, | NULL, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| 0, | 0, | ||||
| &ptr); | &ptr); | ||||
| RNA_int_set_array(&ptr, "cursor", &loc[0]); | RNA_int_set_array(&ptr, "cursor", &loc[0]); | ||||
| RNA_enum_set(&ptr, "direction", 'h'); | RNA_enum_set(&ptr, "direction", SCREEN_AXIS_H); | ||||
| uiItemS(layout); | uiItemS(layout); | ||||
| if (area->spacetype != SPACE_FILE) { | if (area->spacetype != SPACE_FILE) { | ||||
| uiItemO(layout, | uiItemO(layout, | ||||
| area->full ? IFACE_("Restore Areas") : IFACE_("Maximize Area"), | area->full ? IFACE_("Restore Areas") : IFACE_("Maximize Area"), | ||||
| ICON_NONE, | ICON_NONE, | ||||
| "SCREEN_OT_screen_full_area"); | "SCREEN_OT_screen_full_area"); | ||||
| ▲ Show 20 Lines • Show All 1,264 Lines • ▼ Show 20 Lines | default: | ||||
| propname = ""; | propname = ""; | ||||
| } | } | ||||
| *r_prop = RNA_struct_find_property(r_ptr, propname); | *r_prop = RNA_struct_find_property(r_ptr, propname); | ||||
| } | } | ||||
| static int space_context_cycle_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | 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"); | ||||
Severin: I don't really see the point in changing this from `direction` to `dir_cycle`. For me the… | |||||
Done Inline ActionsMade the change before adding a type for eScreenCycle, since it's a named type - agree it's not such a useful distinction. campbellbarton: Made the change before adding a type for `eScreenCycle`, since it's a named type - agree it's… | |||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| context_cycle_prop_get(CTX_wm_screen(C), CTX_wm_area(C), &ptr, &prop); | context_cycle_prop_get(CTX_wm_screen(C), CTX_wm_area(C), &ptr, &prop); | ||||
| const int old_context = RNA_property_enum_get(&ptr, prop); | const int old_context = RNA_property_enum_get(&ptr, prop); | ||||
| const int new_context = RNA_property_enum_step( | const int new_context = RNA_property_enum_step( | ||||
| C, &ptr, prop, old_context, direction == SPACE_CONTEXT_CYCLE_PREV ? -1 : 1); | C, &ptr, prop, old_context, direction == SPACE_CONTEXT_CYCLE_PREV ? -1 : 1); | ||||
| RNA_property_enum_set(&ptr, prop, new_context); | RNA_property_enum_set(&ptr, prop, new_context); | ||||
| Show All 32 Lines | |||||
| static int space_workspace_cycle_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int space_workspace_cycle_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| if (WM_window_is_temp_screen(win)) { | if (WM_window_is_temp_screen(win)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| Main *bmain = CTX_data_main(C); | 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_src = WM_window_get_active_workspace(win); | ||||
| WorkSpace *workspace_dst = NULL; | WorkSpace *workspace_dst = NULL; | ||||
| ListBase ordered; | ListBase ordered; | ||||
| BKE_id_ordered_list(&ordered, &bmain->workspaces); | BKE_id_ordered_list(&ordered, &bmain->workspaces); | ||||
| LISTBASE_FOREACH (LinkData *, link, &ordered) { | LISTBASE_FOREACH (LinkData *, link, &ordered) { | ||||
| if (link->data == workspace_src) { | if (link->data == workspace_src) { | ||||
| ▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines | |||||
I don't really see the point in changing this from direction to dir_cycle. For me the former is more clear and just rehashing that this cycles doesn't add much to the context in my mind.