ref: 52965c9a8366b1b30742215543032ef863f0b217
dir: /scroll.c/
#include <u.h> #include <libc.h> #include <draw.h> #include <thread.h> #include <mouse.h> #include <frame.h> #include "scroll.h" enum { Scrollwid = 12, /* width of scroll bar */ Scrollgap = 4, /* gap right of scroll bar */ }; Rectangle scrollinit(Scroll *s, Rectangle r, Image *b, Image **cols) { if(cols != nil) memmove(s->cols, cols, sizeof(s->cols)); s->r = r; s->r.max.x = r.min.x + Scrollwid; s->image = b; r.min.x += Scrollwid + Scrollgap; return r; } void scrollpos(Scroll *s, uint p₀, uint p₁, uint tot) { Rectangle q; int h; q = s->r; h = Dy(q); if(tot > 1024*1024){ tot>>=10; p₀>>=10; p₁>>=10; } if(tot > 0){ q.min.y += h*p₀/tot; q.max.y = q.min.y+h*(p₁-p₀)/tot; } draw(s->image, s->r, s->cols[BORD], nil, ZP); draw(s->image, insetrect(q, 1), s->cols[BACK], nil, ZP); } int scrollscr(Scroll *s, Mouse *m, uint *p₀) { return -1; }