~ft/zuke

d9b4a120f0c7d48e2901361eb6faa9704ca2d608 — Sigrid Haflínudóttir 7 months ago 9830943
add and use CLAMP
1 files changed, 4 insertions(+), 11 deletions(-)

M zuke.c
M zuke.c => zuke.c +4 -11
@@ 6,6 6,7 @@

#define MAX(a,b) ((a)>=(b)?(a):(b))
#define MIN(a,b) ((a)<=(b)?(a):(b))
#define CLAMP(x,min,max) MAX(min, MIN(max, x))

typedef struct Player Player;



@@ 963,7 964,7 @@ ev:
				if(scrollsz >= plnum)
					break;
				scroll = (m.xy.y - screen->r.min.y - Scrollheight/4)*(plnum-scrollsz) / (Dy(screen->r)-Scrollheight/2);
				scroll = MAX(0, MIN(scroll, plnum-scrollsz-1));
				scroll = CLAMP(scroll, 0, plnum-scrollsz-1);
				redraw(1);
			}else if(m.buttons == 1 || m.buttons == 2){
				pcur = scroll + n;


@@ 1085,20 1086,12 @@ ev:
		}

		if(pcur != oldpcur){
			if(pcur < 0)
				pcur = 0;
			else if(pcur >= plnum)
				pcur = plnum - 1;

			pcur = CLAMP(pcur, 0, plnum-1);
			if(pcur < scroll)
				scroll = pcur;
			else if(pcur > scroll + scrollsz)
				scroll = pcur - scrollsz;

			if(scroll > plnum - scrollsz)
				scroll = plnum - scrollsz;
			if(scroll < 0)
				scroll = 0;
			scroll = CLAMP(scroll, 0, plnum-scrollsz);

			if(pcur != oldpcur)
				redraw(1);