[Change] Cleaned up the scrollbar renderer.
This commit is contained in:
parent
fff2863c86
commit
2f5ca43840
@ -71,6 +71,7 @@ typedef struct Widget_ {
|
||||
int selected; /* Currently selected option. */
|
||||
int pos; /* Current topmost option (in view). */
|
||||
void (*fptr) (unsigned int, char*); /* Modify callback. */
|
||||
int height; /**< Real height. */
|
||||
} lst;
|
||||
/* Widget rect. */
|
||||
struct {
|
||||
@ -172,6 +173,7 @@ static void toolkit_renderInput(Widget* inp, double bx, double by);
|
||||
static void toolkit_renderImageArray(Widget* iar, double bx, double by);
|
||||
static void toolkit_drawOutline(double x, double y, double w,
|
||||
double h, double b, glColour* c, glColour* lc);
|
||||
static void toolkit_drawScrollbar(double x, double y, double w, double h, double pos);
|
||||
static void toolkit_clip(double x, double y, double w, double h);
|
||||
static void toolkit_unclip(void);
|
||||
static void toolkit_drawRect(double x, double y, double w, double h,
|
||||
@ -288,6 +290,12 @@ void window_addList(const unsigned int wid, const int x, const int y,
|
||||
wgt->h = (double) h - ((h % (gl_defFont.h+2)) + 2);
|
||||
toolkit_setPos(wdw, wgt, x, y);
|
||||
|
||||
/* Check if needs scrollbar. */
|
||||
if(2 + (nitems * (gl_defFont.h + 2)) > (int)wgt->h)
|
||||
wgt->dat.lst.height = (2 + gl_defFont.h) * nitems + 2;
|
||||
else
|
||||
wgt->dat.lst.height = 0;
|
||||
|
||||
if(wdw->focus == -1)
|
||||
/* Initialize the focus. */
|
||||
toolkit_nextFocus();
|
||||
@ -1137,8 +1145,10 @@ static void toolkit_renderImage(Widget* img, double bx, double by) {
|
||||
/* Render the list. */
|
||||
static void toolkit_renderList(Widget* lst, double bx, double by) {
|
||||
int i;
|
||||
double x, y, tx, ty;
|
||||
double x, y, tx, ty, miny;
|
||||
double w, scroll_pos;
|
||||
|
||||
w = lst->w;
|
||||
x = bx + lst->x;
|
||||
y = by + lst->y;
|
||||
|
||||
@ -1150,22 +1160,36 @@ static void toolkit_renderList(Widget* lst, double bx, double by) {
|
||||
/* Outter outline. */
|
||||
toolkit_drawOutline(x, y, lst->w, lst->h, 1., toolkit_colDark, NULL);
|
||||
|
||||
/* Draw scrollbar. */
|
||||
if(lst->dat.lst.height > 0) {
|
||||
/* We need to make room for list. */
|
||||
w -= 10.;
|
||||
|
||||
scroll_pos = (double)lst->dat.lst.pos / ((double)lst->dat.lst.height - lst->h);
|
||||
toolkit_drawScrollbar(x + lst->w - 10., y, 10., lst->h, scroll_pos);
|
||||
}
|
||||
|
||||
|
||||
/* Draw selected. */
|
||||
toolkit_drawRect(x,
|
||||
y-1.+lst->h-(1+lst->dat.lst.selected-lst->dat.lst.pos)*(gl_defFont.h+2.),
|
||||
lst->w, gl_defFont.h+2., &cHilight, NULL);
|
||||
y-1.+lst->h-(1+lst->dat.lst.selected-lst->dat.lst.pos)*(gl_defFont.h+2.),
|
||||
w, gl_defFont.h+2., &cHilight, NULL);
|
||||
|
||||
|
||||
/* Draw content. */
|
||||
tx = (double)SCREEN_W/2. + x+2.;
|
||||
ty = (double)SCREEN_H/2. + y+lst->h - 2. - gl_defFont.h;
|
||||
miny = ty - lst->h;
|
||||
y = ty-2.;
|
||||
w -= 4;
|
||||
|
||||
for(i = lst->dat.lst.pos; i < lst->dat.lst.noptions; i++) {
|
||||
gl_printMax(&gl_defFont, (int)lst->w-4,
|
||||
gl_printMax(&gl_defFont, (int)w-4,
|
||||
tx, ty, &cBlack, lst->dat.lst.options[i]);
|
||||
|
||||
ty -= 2 + gl_defFont.h;
|
||||
if(ty-y > lst->h) break;
|
||||
/* Check if out if bounds. */
|
||||
if(ty < miny) break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1242,7 +1266,7 @@ static void toolkit_renderInput(Widget* inp, double bx, double by) {
|
||||
static void toolkit_renderImageArray(Widget* iar, double bx, double by) {
|
||||
int i, j;
|
||||
double x, y, w, h, xcurs, ycurs;
|
||||
double scroll_pos, sx, sy;
|
||||
double scroll_pos;
|
||||
int xelem, yelem, xspace;
|
||||
glColour* c, *dc, *lc;
|
||||
int is_selected;
|
||||
@ -1263,21 +1287,8 @@ static void toolkit_renderImageArray(Widget* iar, double bx, double by) {
|
||||
toolkit_drawRect(x, y, iar->w, iar->h, &cBlack, NULL);
|
||||
|
||||
/* Scrollbar. */
|
||||
|
||||
/* scrollbar background. */
|
||||
toolkit_drawRect(x+iar->w - 10., y, 10., iar->h,
|
||||
toolkit_colDark, toolkit_col);
|
||||
toolkit_drawOutline(x + iar->w - 10., y, 10., iar->h, 1.,
|
||||
toolkit_colLight, toolkit_col);
|
||||
toolkit_drawOutline(x + iar->w - 10., y, 10., iar->h, 2.,
|
||||
toolkit_colDark, NULL);
|
||||
|
||||
/* The bar */
|
||||
scroll_pos = iar->dat.iar.pos / (h * (yelem - (int)(iar->h / h)));
|
||||
sx = x + iar->w - 10.;
|
||||
sy = y + iar->h - (iar->h - 30.) * scroll_pos - 30.;
|
||||
toolkit_drawRect(sx, sy, 10., 30., toolkit_colLight, toolkit_col);
|
||||
toolkit_drawOutline(sx, sy, 10., 30., 0., toolkit_colDark, NULL);
|
||||
toolkit_drawScrollbar(x + iar->w - 10., y, 10., iar->h, scroll_pos);
|
||||
|
||||
/* Main drawing loop. */
|
||||
toolkit_clip(x, y, iar->w, iar->h);
|
||||
@ -1335,6 +1346,20 @@ static void toolkit_renderImageArray(Widget* iar, double bx, double by) {
|
||||
toolkit_drawOutline(x, y+1, iar->w-1, iar->h-1, 2., toolkit_colDark, NULL);
|
||||
}
|
||||
|
||||
static void toolkit_drawScrollbar(double x, double y, double w, double h, double pos) {
|
||||
double sy;
|
||||
|
||||
/* Scrollbar background. */
|
||||
toolkit_drawRect(x, y, w, h, toolkit_colDark, toolkit_col);
|
||||
toolkit_drawOutline(x, y, w, h, 1., toolkit_colLight, toolkit_col);
|
||||
toolkit_drawOutline(x, y, w, h, 2., toolkit_colDark, NULL);
|
||||
|
||||
/* Bar itself. */
|
||||
sy = y + (h - 30.) * (1.-pos);
|
||||
toolkit_drawRect(x, sy, w, 30., toolkit_colLight, toolkit_col);
|
||||
toolkit_drawOutline(x, sy, w, 30., 0., toolkit_colDark, NULL);
|
||||
}
|
||||
|
||||
/* Handle input for input widget. */
|
||||
static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key) {
|
||||
int n;
|
||||
|
Loading…
Reference in New Issue
Block a user