ref: d9b4a120f0c7d48e2901361eb6faa9704ca2d608
parent: 9830943f0ead458292de34c3fe4877966c3dbdba
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Jun 16 12:48:37 EDT 2020
add and use CLAMP
--- a/zuke.c
+++ b/zuke.c
@@ -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 @@
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 @@
}
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);