diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2013-12-13 03:04:05 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2013-12-13 03:04:05 +0400 |
commit | a53e864cf4b5f2a37f34602469c0998ec7cd5ad4 (patch) | |
tree | b97b80cbe53abcc3c025bd61e2abf0e1f9f0aeca | |
parent | 51b9d85b091cbc31d73968f0652e59dd83247ca2 (diff) |
Fix T37572: text editor scrolling not working well with Mac trackpad panning.
The trackpad would give isolated mouse pan events with a distance smaller than
one line or character. For other 2D views this is all accumulated in floats,
but in the text editor it only keeps track of integers, and the small mouse pan
events got lost due to rounding.
Now it keeps track of sub-line or sub-character scroll offsets to avoid this.
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_draw.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 48 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_space_types.h | 2 |
4 files changed, 39 insertions, 18 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index e51b3a6f27e..37d2ec787ed 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6414,7 +6414,9 @@ static bool direct_link_screen(FileData *fd, bScreen *sc) else if (sl->spacetype == SPACE_TEXT) { SpaceText *st= (SpaceText *)sl; - st->drawcache= NULL; + st->drawcache = NULL; + st->scroll_accum[0] = 0.0f; + st->scroll_accum[1] = 0.0f; } else if (sl->spacetype == SPACE_TIME) { SpaceTime *stime = (SpaceTime *)sl; diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index e92cab72042..4504963a572 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -1495,6 +1495,9 @@ void text_scroll_to_cursor(SpaceText *st, ScrArea *sa) if (st->top < 0) st->top = 0; if (st->left < 0) st->left = 0; + + st->scroll_accum[0] = 0.0f; + st->scroll_accum[1] = 0.0f; } void text_update_cursor_moved(bContext *C) diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index dd5e282587d..2849db7330a 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -38,6 +38,7 @@ #include "DNA_text_types.h" #include "BLI_blenlib.h" +#include "BLI_math.h" #include "BLF_translation.h" @@ -180,7 +181,10 @@ static int text_new_exec(bContext *C, wmOperator *UNUSED(op)) } else if (st) { st->text = text; + st->left = 0; st->top = 0; + st->scroll_accum[0] = 0.0f; + st->scroll_accum[1] = 0.0f; text_drawcache_tag_update(st, 1); } @@ -251,7 +255,10 @@ static int text_open_exec(bContext *C, wmOperator *op) } else if (st) { st->text = text; + st->left = 0; st->top = 0; + st->scroll_accum[0] = 0.0f; + st->scroll_accum[1] = 0.0f; } text_drawcache_tag_update(st, 1); @@ -2115,8 +2122,8 @@ enum { }; typedef struct TextScroll { - short old[2]; - short delta[2]; + int old[2]; + int delta[2]; int first; int scrollbar; @@ -2153,39 +2160,48 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event) ARegion *ar = CTX_wm_region(C); TextScroll *tsc = op->customdata; int mval[2] = {event->x, event->y}; - short txtdelta[2] = {0, 0}; + int scroll_steps[2] = {0, 0}; text_update_character_width(st); + /* compute mouse move distance */ if (tsc->first) { tsc->old[0] = mval[0]; tsc->old[1] = mval[1]; tsc->first = 0; } - tsc->delta[0] += mval[0] - tsc->old[0]; - tsc->delta[1] += mval[1] - tsc->old[1]; + if (event->type != MOUSEPAN) { + tsc->delta[0] = mval[0] - tsc->old[0]; + tsc->delta[1] = mval[1] - tsc->old[1]; + } + /* accumulate scroll, in float values for events that give less than one + * line offset but taken together should still scroll */ if (!tsc->scrollbar) { - txtdelta[0] = -tsc->delta[0] / st->cwidth; - txtdelta[1] = tsc->delta[1] / (st->lheight_dpi + TXT_LINE_SPACING); - - tsc->delta[0] %= st->cwidth; - tsc->delta[1] %= (st->lheight_dpi + TXT_LINE_SPACING); + st->scroll_accum[0] += -tsc->delta[0] / (float)st->cwidth; + st->scroll_accum[1] += tsc->delta[1] / (float)(st->lheight_dpi + TXT_LINE_SPACING); } else { - txtdelta[1] = -tsc->delta[1] * st->pix_per_line; - tsc->delta[1] += txtdelta[1] / st->pix_per_line; + st->scroll_accum[1] += -tsc->delta[1] * st->pix_per_line; } - if (txtdelta[0] || txtdelta[1]) { - txt_screen_skip(st, ar, txtdelta[1]); + /* round to number of lines to scroll */ + scroll_steps[0] = (int)st->scroll_accum[0]; + scroll_steps[1] = (int)st->scroll_accum[1]; + + st->scroll_accum[0] -= scroll_steps[0]; + st->scroll_accum[1] -= scroll_steps[1]; + + /* perform vertical and/or horizontal scroll */ + if (scroll_steps[0] || scroll_steps[1]) { + txt_screen_skip(st, ar, scroll_steps[1]); if (st->wordwrap) { st->left = 0; } else { - st->left += txtdelta[0]; + st->left += scroll_steps[0]; if (st->left < 0) st->left = 0; } @@ -2352,8 +2368,6 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev tsc->old[0] = ar->winrct.xmin + BLI_rcti_cent_x(&st->txtbar); tsc->old[1] = ar->winrct.ymin + BLI_rcti_cent_y(&st->txtbar); - tsc->delta[0] = 0; - tsc->delta[1] = 0; tsc->first = 0; tsc->zone = SCROLLHANDLE_BAR; text_scroll_apply(C, op, event); diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index 4fe0920b7c6..9038885f6af 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -849,6 +849,8 @@ typedef struct SpaceText { char pad[4]; void *drawcache; /* cache for faster drawing */ + + float scroll_accum[2]; /* runtime, for scroll increments smaller than a line */ } SpaceText; |