diff options
Diffstat (limited to 'source/blender/editors/space_text/text_ops.c')
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 92 |
1 files changed, 66 insertions, 26 deletions
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 95cb8078f7c..7eb0ab67d8e 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -2002,15 +2002,21 @@ static void screen_skip(SpaceText *st, ARegion *ar, int lines) if(st->top<0) st->top= 0; } +/* quick enum for tsc->zone (scroller handles) */ +enum { + SCROLLHANDLE_BAR, + SCROLLHANDLE_MIN_OUTSIDE, + SCROLLHANDLE_MAX_OUTSIDE +} TextScrollerHandle_Zone; + typedef struct TextScroll { short old[2]; - short hold[2]; short delta[2]; int first; - int characters; - int lines; int scrollbar; + + int zone; } TextScroll; static int scroll_exec(bContext *C, wmOperator *op) @@ -2035,40 +2041,42 @@ static void scroll_apply(bContext *C, wmOperator *op, wmEvent *event) SpaceText *st= CTX_wm_space_text(C); ARegion *ar= CTX_wm_region(C); TextScroll *tsc= op->customdata; - short *mval= event->mval; + short mval[2]= {event->x, event->y}; + short txtdelta[2] = {0, 0}; text_update_character_width(st); if(tsc->first) { tsc->old[0]= mval[0]; tsc->old[1]= mval[1]; - tsc->hold[0]= mval[0]; - tsc->hold[1]= mval[1]; tsc->first= 0; } + tsc->delta[0]+= mval[0] - tsc->old[0]; + tsc->delta[1]+= mval[1] - tsc->old[1]; + if(!tsc->scrollbar) { - tsc->delta[0]= (tsc->hold[0]-mval[0])/st->cwidth; - tsc->delta[1]= (mval[1]-tsc->hold[1])/st->lheight; + txtdelta[0]= -tsc->delta[0]/st->cwidth; + txtdelta[1]= tsc->delta[1]/st->lheight; + + tsc->delta[0]%= st->cwidth; + tsc->delta[1]%= st->lheight; + } + else { + txtdelta[1]= -tsc->delta[1]*st->pix_per_line; + tsc->delta[1]+= txtdelta[1]/st->pix_per_line; } - else - tsc->delta[1]= (tsc->hold[1]-mval[1])*st->pix_per_line; - - if(tsc->delta[0] || tsc->delta[1]) { - screen_skip(st, ar, tsc->delta[1]); - tsc->lines += tsc->delta[1]; + if(txtdelta[0] || txtdelta[1]) { + screen_skip(st, ar, txtdelta[1]); if(st->wordwrap) { st->left= 0; } else { - st->left+= tsc->delta[0]; + st->left+= txtdelta[0]; if(st->left<0) st->left= 0; } - - tsc->hold[0]= mval[0]; - tsc->hold[1]= mval[1]; ED_area_tag_redraw(CTX_wm_area(C)); } @@ -2087,13 +2095,30 @@ static void scroll_exit(bContext *C, wmOperator *op) static int scroll_modal(bContext *C, wmOperator *op, wmEvent *event) { + TextScroll *tsc= op->customdata; + SpaceText *st= CTX_wm_space_text(C); + ARegion *ar= CTX_wm_region(C); + switch(event->type) { case MOUSEMOVE: - scroll_apply(C, op, event); + if(tsc->zone == SCROLLHANDLE_BAR) + scroll_apply(C, op, event); break; case LEFTMOUSE: case RIGHTMOUSE: case MIDDLEMOUSE: + if(ELEM(tsc->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) { + int last; + + st->top+= st->viewlines * (tsc->zone==SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1); + + last= text_get_total_lines(st, ar); + last= last - (st->viewlines/2); + + CLAMP(st->top, 0, last); + + ED_area_tag_redraw(CTX_wm_area(C)); + } scroll_exit(C, op); return OPERATOR_FINISHED; } @@ -2118,6 +2143,7 @@ static int scroll_invoke(bContext *C, wmOperator *op, wmEvent *event) tsc= MEM_callocN(sizeof(TextScroll), "TextScroll"); tsc->first= 1; + tsc->zone= SCROLLHANDLE_BAR; op->customdata= tsc; st->flags|= ST_SCROLL_SELECT; @@ -2125,11 +2151,11 @@ static int scroll_invoke(bContext *C, wmOperator *op, wmEvent *event) if (event->type == MOUSEPAN) { text_update_character_width(st); - tsc->hold[0] = event->prevx; - tsc->hold[1] = event->prevy; + tsc->old[0] = event->x; + tsc->old[1] = event->x; /* Sensitivity of scroll set to 4pix per line/char */ - event->mval[0] = event->prevx + (event->x - event->prevx)*st->cwidth/4; - event->mval[1] = event->prevy + (event->y - event->prevy)*st->lheight/4; + tsc->delta[0] = (event->x - event->prevx)*st->cwidth/4; + tsc->delta[1] = (event->y - event->prevy)*st->lheight/4; tsc->first = 0; tsc->scrollbar = 0; scroll_apply(C, op, event); @@ -2160,7 +2186,7 @@ void TEXT_OT_scroll(wmOperatorType *ot) ot->poll= text_space_edit_poll; /* flags */ - ot->flag= OPTYPE_BLOCKING; + ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER; /* properties */ RNA_def_int(ot->srna, "lines", 1, INT_MIN, INT_MAX, "Lines", "Number of lines to scroll.", -100, 100); @@ -2174,18 +2200,32 @@ static int scroll_bar_invoke(bContext *C, wmOperator *op, wmEvent *event) ARegion *ar= CTX_wm_region(C); TextScroll *tsc; short *mval= event->mval; + int zone= -1; if(RNA_property_is_set(op->ptr, "lines")) return scroll_exec(C, op); /* verify we are in the right zone */ - if(!(mval[0]>ar->winx-TXT_SCROLL_WIDTH && mval[0]<ar->winx-TXT_SCROLL_SPACE - && mval[1]>TXT_SCROLL_SPACE && mval[1]<ar->winy)) + if(mval[0]>st->txtbar.xmin && mval[0]<st->txtbar.xmax) { + if(mval[1]>=st->txtbar.ymin && mval[1]<=st->txtbar.ymax) { + /* mouse inside scroll handle */ + zone = SCROLLHANDLE_BAR; + } + else if(mval[1]>TXT_SCROLL_SPACE && mval[1]<ar->winy-TXT_SCROLL_SPACE) { + if(mval[1]<st->txtbar.ymin) zone= SCROLLHANDLE_MIN_OUTSIDE; + else zone= SCROLLHANDLE_MAX_OUTSIDE; + } + } + + if(zone == -1) { + /* we are outside slider - nothing to do */ return OPERATOR_PASS_THROUGH; + } tsc= MEM_callocN(sizeof(TextScroll), "TextScroll"); tsc->first= 1; tsc->scrollbar= 1; + tsc->zone= zone; op->customdata= tsc; st->flags|= ST_SCROLL_SELECT; |