diff options
Diffstat (limited to 'source/blender/editors/screen/screen_ops.c')
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 118 |
1 files changed, 76 insertions, 42 deletions
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index fb269740109..e2d6a9aa6ca 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -753,7 +753,6 @@ static AZone *area_actionzone_refresh_xy(ScrArea *sa, const int xy[2], const boo if (az->direction == AZ_SCROLL_HOR) { az->alpha = 1.0f; v2d->alpha_hor = 255; - v2d->size_hor = V2D_SCROLL_HEIGHT; redraw = true; } } @@ -761,7 +760,6 @@ static AZone *area_actionzone_refresh_xy(ScrArea *sa, const int xy[2], const boo if (az->direction == AZ_SCROLL_VERT) { az->alpha = 1.0f; v2d->alpha_vert = 255; - v2d->size_vert = V2D_SCROLL_WIDTH; redraw = true; } } @@ -775,9 +773,6 @@ static AZone *area_actionzone_refresh_xy(ScrArea *sa, const int xy[2], const boo alpha = 1.0f - dist_fac; v2d->alpha_hor = alpha * 255; - v2d->size_hor = round_fl_to_int( - V2D_SCROLL_HEIGHT - - ((V2D_SCROLL_HEIGHT - V2D_SCROLL_HEIGHT_MIN) * dist_fac)); } else if (az->direction == AZ_SCROLL_VERT) { dist_fac = BLI_rcti_length_x(&v2d->vert, local_xy[0]) / AZONEFADEIN; @@ -785,9 +780,6 @@ static AZone *area_actionzone_refresh_xy(ScrArea *sa, const int xy[2], const boo alpha = 1.0f - dist_fac; v2d->alpha_vert = alpha * 255; - v2d->size_vert = round_fl_to_int( - V2D_SCROLL_WIDTH - - ((V2D_SCROLL_WIDTH - V2D_SCROLL_WIDTH_MIN) * dist_fac)); } az->alpha = alpha; redraw = true; @@ -1140,7 +1132,7 @@ static int area_dupli_invoke(bContext *C, wmOperator *op, const wmEvent *event) newwin->scene = scene; - WM_window_set_active_workspace(newwin, workspace); + BKE_workspace_active_set(newwin->workspace_hook, workspace); /* allocs new screen and adds to newly created window, using window size */ layout_new = ED_workspace_layout_add(bmain, workspace, newwin, BKE_workspace_layout_name_get(layout_old)); newsc = BKE_workspace_layout_screen_get(layout_new); @@ -1219,11 +1211,11 @@ typedef struct sAreaMoveData { SNAP_NONE = 0, /* Snap to an invisible grid with a unit defined in AREAGRID */ SNAP_AREAGRID, - /* Snap to mid-point and adjacent edges. */ - SNAP_MIDPOINT_AND_ADJACENT, + /* Snap to fraction (half, third.. etc) and adjacent edges. */ + SNAP_FRACTION_AND_ADJACENT, /* Snap to either bigger or smaller, nothing in-between (used for * global areas). This has priority over other snap types, if it is - * used, toggling SNAP_MIDPOINT_AND_ADJACENT doesn't work. */ + * used, toggling SNAP_FRACTION_AND_ADJACENT doesn't work. */ SNAP_BIGGER_SMALLER_ONLY, } snap_type; } sAreaMoveData; @@ -1368,32 +1360,50 @@ static int area_snap_calc_location( const int bigger, const int smaller) { BLI_assert(snap_type != SNAP_NONE); - int final_loc = -1; - const int m_loc = origval + delta; + int m_cursor_final = -1; + const int m_cursor = origval + delta; + const int m_span = (float)(bigger + smaller); + const int m_min = origval - smaller; + // const int axis_max = axis_min + m_span; switch (snap_type) { case SNAP_AREAGRID: - final_loc = m_loc; + m_cursor_final = m_cursor; if (delta != bigger && delta != -smaller) { - final_loc -= (m_loc % AREAGRID); - CLAMP(final_loc, origval - smaller, origval + bigger); + m_cursor_final -= (m_cursor % AREAGRID); + CLAMP(m_cursor_final, origval - smaller, origval + bigger); } break; case SNAP_BIGGER_SMALLER_ONLY: - final_loc = (m_loc >= bigger) ? bigger : smaller; + m_cursor_final = (m_cursor >= bigger) ? bigger : smaller; break; - case SNAP_MIDPOINT_AND_ADJACENT: + case SNAP_FRACTION_AND_ADJACENT: { const int axis = (dir == 'v') ? 0 : 1; - int snap_dist; - int dist; + int snap_dist_best = INT_MAX; { - /* Test the snap to middle. */ - int middle = origval + (bigger - smaller) / 2; - snap_dist = abs(m_loc - middle); - final_loc = middle; + const float div_array[] = { + /* Middle. */ + 1.0f / 2.0f, + /* Thirds. */ + 1.0f / 3.0f, 2.0f / 3.0f, + /* Quaters. */ + 1.0f / 4.0f, 3.0f / 4.0f, + /* Eighth. */ + 1.0f / 8.0f, 3.0f / 8.0f, + 5.0f / 8.0f, 7.0f / 8.0f, + }; + /* Test the snap to the best division. */ + for (int i = 0; i < ARRAY_SIZE(div_array); i++) { + const int m_cursor_test = m_min + round_fl_to_int(m_span * div_array[i]); + const int snap_dist_test = abs(m_cursor - m_cursor_test); + if (snap_dist_best >= snap_dist_test) { + snap_dist_best = snap_dist_test; + m_cursor_final = m_cursor_test; + } + } } for (const ScrVert *v1 = sc->vertbase.first; v1; v1 = v1->next) { @@ -1410,10 +1420,10 @@ static int area_snap_calc_location( const int v_loc2 = (&v2->vec.x)[axis]; /* Do not snap to the vertices at the ends. */ if ((origval - smaller) < v_loc2 && v_loc2 < (origval + bigger)) { - dist = abs(m_loc - v_loc2); - if (dist <= snap_dist) { - snap_dist = dist; - final_loc = v_loc2; + const int snap_dist_test = abs(m_cursor - v_loc2); + if (snap_dist_best >= snap_dist_test) { + snap_dist_best = snap_dist_test; + m_cursor_final = v_loc2; } } } @@ -1426,9 +1436,9 @@ static int area_snap_calc_location( } BLI_assert(ELEM(snap_type, SNAP_BIGGER_SMALLER_ONLY) || - IN_RANGE_INCL(final_loc, origval - smaller, origval + bigger)); + IN_RANGE_INCL(m_cursor_final, origval - smaller, origval + bigger)); - return final_loc; + return m_cursor_final; } /* moves selected screen edge amount of delta, used by split & move */ @@ -1580,7 +1590,7 @@ static int area_move_modal(bContext *C, wmOperator *op, const wmEvent *event) case KM_MODAL_SNAP_ON: if (md->snap_type != SNAP_BIGGER_SMALLER_ONLY) { - md->snap_type = SNAP_MIDPOINT_AND_ADJACENT; + md->snap_type = SNAP_FRACTION_AND_ADJACENT; } break; @@ -2062,7 +2072,7 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event) if (sd->previewmode == 0) { if (sd->do_snap) { const int snap_loc = area_snap_calc_location( - CTX_wm_screen(C), SNAP_MIDPOINT_AND_ADJACENT, sd->delta, sd->origval, dir, + CTX_wm_screen(C), SNAP_FRACTION_AND_ADJACENT, sd->delta, sd->origval, dir, sd->bigger, sd->smaller); sd->delta = snap_loc - sd->origval; } @@ -2090,7 +2100,7 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event) sa->v1->editflag = sa->v2->editflag = sa->v3->editflag = sa->v4->editflag = 1; const int snap_loc = area_snap_calc_location( - CTX_wm_screen(C), SNAP_MIDPOINT_AND_ADJACENT, sd->delta, sd->origval, dir, + CTX_wm_screen(C), SNAP_FRACTION_AND_ADJACENT, sd->delta, sd->origval, dir, sd->origmin + sd->origsize, -sd->origmin); sa->v1->editflag = sa->v2->editflag = sa->v3->editflag = sa->v4->editflag = 0; @@ -3669,27 +3679,38 @@ static void SCREEN_OT_header_toggle_menus(wmOperatorType *ot) /** \name Header Tools Operator * \{ */ +static bool header_context_menu_poll(bContext *C) +{ + ScrArea *sa = CTX_wm_area(C); + return (sa && sa->spacetype != SPACE_STATUSBAR); +} + void ED_screens_header_tools_menu_create(bContext *C, uiLayout *layout, void *UNUSED(arg)) { ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); const char *but_flip_str = (ar->alignment == RGN_ALIGN_TOP) ? IFACE_("Flip to Bottom") : IFACE_("Flip to Top"); - uiItemO(layout, IFACE_("Toggle Header"), ICON_NONE, "SCREEN_OT_header"); + if (!ELEM(sa->spacetype, SPACE_TOPBAR)) { + uiItemO(layout, IFACE_("Toggle Header"), ICON_NONE, "SCREEN_OT_header"); + } /* default is WM_OP_INVOKE_REGION_WIN, which we don't want here. */ uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT); - uiItemO(layout, but_flip_str, ICON_NONE, "SCREEN_OT_region_flip"); + if (!ELEM(sa->spacetype, SPACE_TOPBAR)) { + uiItemO(layout, but_flip_str, ICON_NONE, "SCREEN_OT_region_flip"); + } + uiItemO(layout, IFACE_("Collapse Menus"), (sa->flag & HEADER_NO_PULLDOWN) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT, "SCREEN_OT_header_toggle_menus"); - uiItemS(layout); - /* file browser should be fullscreen all the time, topbar should * never be. But other regions can be maximized/restored... */ if (!ELEM(sa->spacetype, SPACE_FILE, SPACE_TOPBAR)) { + uiItemS(layout); + const char *but_str = sa->full ? IFACE_("Tile Area") : IFACE_("Maximize Area"); uiItemO(layout, but_str, ICON_NONE, "SCREEN_OT_screen_full_area"); } @@ -3718,6 +3739,7 @@ static void SCREEN_OT_header_context_menu(wmOperatorType *ot) ot->idname = "SCREEN_OT_header_context_menu"; /* api callbacks */ + ot->poll = header_context_menu_poll; ot->invoke = header_context_menu_invoke; } @@ -4866,8 +4888,8 @@ void ED_keymap_screen(wmKeyConfig *keyconf) RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_screen_set", RIGHTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", 1); RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_screen_set", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", -1); #endif - WM_keymap_add_item(keymap, "SCREEN_OT_screen_full_area", SPACEKEY, KM_PRESS, KM_SHIFT, 0); - kmi = WM_keymap_add_item(keymap, "SCREEN_OT_screen_full_area", SPACEKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0); + WM_keymap_add_item(keymap, "SCREEN_OT_screen_full_area", SPACEKEY, KM_PRESS, KM_CTRL, 0); + kmi = WM_keymap_add_item(keymap, "SCREEN_OT_screen_full_area", SPACEKEY, KM_PRESS, KM_CTRL | KM_ALT, 0); RNA_boolean_set(kmi->ptr, "use_hide_panels", true); #ifdef USE_WM_KEYMAP_27X @@ -4886,9 +4908,11 @@ void ED_keymap_screen(wmKeyConfig *keyconf) /* tests */ WM_keymap_add_item(keymap, "SCREEN_OT_region_quadview", QKEY, KM_PRESS, KM_CTRL | KM_ALT, 0); + + WM_keymap_add_item(keymap, "SCREEN_OT_repeat_last", RKEY, KM_PRESS, KM_SHIFT, 0); + #ifdef USE_WM_KEYMAP_27X WM_keymap_verify_item(keymap, "SCREEN_OT_repeat_history", RKEY, KM_PRESS, KM_CTRL | KM_ALT, 0); - WM_keymap_add_item(keymap, "SCREEN_OT_repeat_last", RKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_verify_item(keymap, "SCREEN_OT_region_flip", F5KEY, KM_PRESS, 0, 0); WM_keymap_verify_item(keymap, "SCREEN_OT_redo_last", F6KEY, KM_PRESS, 0, 0); WM_keymap_verify_item(keymap, "SCRIPT_OT_reload", F8KEY, KM_PRESS, 0, 0); @@ -4966,9 +4990,19 @@ void ED_keymap_screen(wmKeyConfig *keyconf) RNA_boolean_set(kmi->ptr, "next", false); +#ifdef USE_WM_KEYMAP_27X /* play (forward and backwards) */ WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT, 0); - RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0)->ptr, "reverse", true); + RNA_boolean_set( + WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0)->ptr, + "reverse", true); +#else + /* play (forward and backwards) */ + WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", SPACEKEY, KM_PRESS, KM_SHIFT, 0); + RNA_boolean_set( + WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", SPACEKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0)->ptr, + "reverse", true); +#endif WM_keymap_add_item(keymap, "SCREEN_OT_animation_cancel", ESCKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", MEDIAPLAY, KM_PRESS, 0, 0); |