diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2018-05-07 02:31:18 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2018-05-07 12:42:12 +0300 |
commit | 51efeb683451d896531baac949de65043edff0b6 (patch) | |
tree | a36b7c037205b77a78a0b0266a7e9ca4571a0a5a /source/blender/editors/screen/screen_ops.c | |
parent | 4ec467d3b52744ba2aa4f938973efa27202b23ee (diff) |
UI: Hide & shrink scroll-bars based on cursor position
Scroll-bars are now hidden unless the cursor approaches them, in which case they
smoothly grow and become more & more visible. Note that since 0d309144020168e55,
scroll-bars are drawn on top of editor contents. There's no more jumping of
buttons when scroll-bars appear.
Technical notes:
* AZones are used to adjust scrollbars based on mouse movements
We may want to support screen level AZones if we want scrollbars to also
smoothly appear when approaching them from a different area.
I also plan to make further changes to AZones to clean up stuff a bit.
* Had to move AZone handling to a post ARegion init stage, since we need the
updated View2D data from there.
* View2D masks and scroller rectangles are now updated on every redraw. It's
cheap to do that though.
Diffstat (limited to 'source/blender/editors/screen/screen_ops.c')
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 3d18e9cbaee..df0466075ef 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -710,6 +710,59 @@ AZone *is_in_area_actionzone(ScrArea *sa, const int xy[2]) ED_area_tag_redraw(sa); break; } + else if (az->type == AZONE_REGION_SCROLL) { + ARegion *ar = az->ar; + View2D *v2d = &ar->v2d; + const short isect_value = UI_view2d_mouse_in_scrollers(ar, v2d, xy[0], xy[1]); + bool redraw = false; + + if (isect_value == 'h') { + if (az->direction == AZ_SCROLL_HOR) { + az->alpha = 1.0f; + v2d->alpha_hor = 255; + v2d->size_hor = V2D_SCROLL_HEIGHT; + redraw = true; + } + } + else if (isect_value == 'v') { + if (az->direction == AZ_SCROLL_VERT) { + az->alpha = 1.0f; + v2d->alpha_vert = 255; + v2d->size_vert = V2D_SCROLL_WIDTH; + redraw = true; + } + } + else { + const int local_xy[2] = {xy[0] - ar->winrct.xmin, xy[1] - ar->winrct.ymin}; + float dist_fac = 0.0f, alpha = 0.0f; + + if (az->direction == AZ_SCROLL_HOR) { + dist_fac = BLI_rcti_length_y(&v2d->hor, local_xy[1]) / AZONEFADEIN; + CLAMP(dist_fac, 0.0f, 1.0f); + 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; + CLAMP(dist_fac, 0.0f, 1.0f); + 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; + } + + if (redraw) { + ED_area_tag_redraw(sa); + } + /* Don't return! */ + } } } @@ -772,6 +825,9 @@ static int actionzone_invoke(bContext *C, wmOperator *op, const wmEvent *event) actionzone_exit(op); return OPERATOR_FINISHED; } + else if (ELEM(sad->az->type, AZONE_REGION_SCROLL)) { + return OPERATOR_PASS_THROUGH; + } else { /* add modal handler */ WM_event_add_modal_handler(C, op); |