From 6db445613816bd773d34e16d0a23d8086fb09edb Mon Sep 17 00:00:00 2001 From: Petter Rodhelind Date: Wed, 25 Oct 2017 01:50:06 +0200 Subject: samterm: Add mouse scrolling. This makes it possible to use the scroll wheel to simulate button 1 and button 3 clicks in the scroll bar. It scrolls in the same way with variable scroll sections. Further down, more lines per scroll etc... --- src/cmd/samterm/main.c | 13 ++++++++----- src/cmd/samterm/scroll.c | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 14 deletions(-) (limited to 'src/cmd/samterm') diff --git a/src/cmd/samterm/main.c b/src/cmd/samterm/main.c index c37fa08b..a97516c4 100644 --- a/src/cmd/samterm/main.c +++ b/src/cmd/samterm/main.c @@ -110,19 +110,21 @@ threadmain(int argc, char *argv[]) nwhich = flwhich(mousep->xy); if(nwhich && nwhich!=which) current(nwhich); - scr = which && ptinrect(mousep->xy, which->scroll); + //scr = which && ptinrect(mousep->xy, which->scroll); + scr = which && (ptinrect(mousep->xy, which->scroll) || mousep->buttons&(8|16)); if(mousep->buttons) flushtyping(1); if(chording && chord==1 && !mousep->buttons) chord = 0; if(chording && chord) chord |= mousep->buttons; - else if(mousep->buttons&1){ + else if(mousep->buttons&(1|8)){ if(nwhich){ if(nwhich!=which) current(nwhich); else if(scr) - scroll(which, 1); + //scroll(which, 1); + scroll(which, (mousep->buttons&8) ? 4 : 1); else{ t=(Text *)which->user1; if(flselect(which)){ @@ -139,9 +141,10 @@ threadmain(int argc, char *argv[]) scroll(which, 2); else menu2hit(); - }else if((mousep->buttons&4)){ + }else if((mousep->buttons&(4|16))){ if(scr) - scroll(which, 3); + //scroll(which, 3); + scroll(which, (mousep->buttons&16) ? 5 : 3); else menu3hit(); } diff --git a/src/cmd/samterm/scroll.c b/src/cmd/samterm/scroll.c index 12614751..dd44bc3d 100644 --- a/src/cmd/samterm/scroll.c +++ b/src/cmd/samterm/scroll.c @@ -115,7 +115,7 @@ scroll(Flayer *l, int but) draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min); do{ oin = in; - in = abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2; + in = (but > 3) || (but == 2) || abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2; if(oin && !in) scrunmark(l, r); if(in){ @@ -126,9 +126,11 @@ scroll(Flayer *l, int but) my = s.min.y; if(my >= s.max.y) my = s.max.y; - if(!eqpt(mousep->xy, Pt(x, my))) - moveto(mousectl, Pt(x, my)); - if(but == 1){ + if(!eqpt(mousep->xy, Pt(x, my))) { + if (but <=3) + moveto(mousectl, Pt(x, my)); + } + if(but == 1 || but == 4){ p0 = l->origin-frcharofpt(&l->f, Pt(s.max.x, my)); rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot); y = rt.min.y; @@ -136,7 +138,7 @@ scroll(Flayer *l, int but) y = my; if(y > s.max.y-2) y = s.max.y-2; - }else if(but == 3){ + }else if(but == 3 || but == 5){ p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my)); rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot); y = rt.min.y; @@ -147,22 +149,24 @@ scroll(Flayer *l, int but) scrmark(l, r); } } - }while(button(but)); + }while(but <=3 && button(but)); if(in){ h = s.max.y-s.min.y; scrunmark(l, r); p0 = 0; - if(but == 1) + if(but == 1 || but == 4) { p0 = (long)(my-s.min.y)/l->f.font->height+1; - else if(but == 2){ + but = 1; + }else if(but == 2){ if(tot > 1024L*1024L) p0 = ((tot>>10)*(y-s.min.y)/h)<<10; else p0 = tot*(y-s.min.y)/h; - }else if(but == 3){ + }else if(but == 3 || but == 5){ p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my)); if(p0 > tot) p0 = tot; + but = 3; } scrorigin(l, but, p0); } -- cgit v1.2.3