[Add] List widget renders. Time to make it actually work properly?
This commit is contained in:
parent
961875a799
commit
f0fa480fb4
12
src/land.c
12
src/land.c
@ -42,11 +42,23 @@ static void news_close(char* str);
|
|||||||
|
|
||||||
// The local market.
|
// The local market.
|
||||||
static void commodity_exchange(void) {
|
static void commodity_exchange(void) {
|
||||||
|
char** goods;
|
||||||
|
int ngoods;
|
||||||
|
|
||||||
|
goods = malloc(sizeof(char*)*3);
|
||||||
|
goods[0] = strdup("Heya!");
|
||||||
|
goods[1] = strdup("Just");
|
||||||
|
goods[2] = strdup("testing.");
|
||||||
|
ngoods = 3;
|
||||||
|
|
||||||
secondary_wid = window_create("Commodity Exchange", -1, -1, COMMODITY_WIDTH, COMMODITY_HEIGHT);
|
secondary_wid = window_create("Commodity Exchange", -1, -1, COMMODITY_WIDTH, COMMODITY_HEIGHT);
|
||||||
|
|
||||||
window_addButton(secondary_wid, -20, 20,
|
window_addButton(secondary_wid, -20, 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose",
|
||||||
"Close", commodity_exchange_close);
|
"Close", commodity_exchange_close);
|
||||||
|
|
||||||
|
window_addList(secondary_wid, 20, -40, COMMODITY_WIDTH-30, COMMODITY_HEIGHT-80-BUTTON_HEIGHT,
|
||||||
|
"lstGoods", goods, ngoods, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void commodity_exchange_close(char* str) {
|
static void commodity_exchange_close(char* str) {
|
||||||
|
@ -48,6 +48,7 @@ typedef struct Widget_ {
|
|||||||
char** options; // Pointer to the options.
|
char** options; // Pointer to the options.
|
||||||
int noptions; // total number of options.
|
int noptions; // total number of options.
|
||||||
int selected; // Currently selected option.
|
int selected; // Currently selected option.
|
||||||
|
int pos; // Current topmost option (in view).
|
||||||
} lst;
|
} lst;
|
||||||
} dat;
|
} dat;
|
||||||
} Widget;
|
} Widget;
|
||||||
@ -175,8 +176,9 @@ void window_addList(const unsigned int wid, const int x, const int y,
|
|||||||
wgt->dat.lst.options = items;
|
wgt->dat.lst.options = items;
|
||||||
wgt->dat.lst.noptions = nitems;
|
wgt->dat.lst.noptions = nitems;
|
||||||
wgt->dat.lst.selected = defitem; // -1 would be none.
|
wgt->dat.lst.selected = defitem; // -1 would be none.
|
||||||
|
wgt->dat.lst.pos = 0;
|
||||||
wgt->w = (double) w;
|
wgt->w = (double) w;
|
||||||
wgt->h = (double) h;
|
wgt->h = (double) h - ((h % (gl_defFont.h+2)) + 2);
|
||||||
if(x < 0) wgt->x = wdw->w - wgt->w + x;
|
if(x < 0) wgt->x = wdw->w - wgt->w + x;
|
||||||
else wgt->x = (double) x;
|
else wgt->x = (double) x;
|
||||||
if(y < 0) wgt->y = wdw->h - wgt->h + y;
|
if(y < 0) wgt->y = wdw->h - wgt->h + y;
|
||||||
@ -664,10 +666,37 @@ static void toolkit_renderImage(Widget* img, double bx, double by) {
|
|||||||
|
|
||||||
// Render the list.
|
// Render the list.
|
||||||
static void toolkit_renderList(Widget* lst, double bx, double by) {
|
static void toolkit_renderList(Widget* lst, double bx, double by) {
|
||||||
double x, y;
|
int i;
|
||||||
|
double x, y, tx, ty;
|
||||||
|
glColour* lc, *c, *oc;
|
||||||
|
|
||||||
x = bx + lst->x;
|
x = bx + lst->x;
|
||||||
y = by + lst->y;
|
y = by + lst->y;
|
||||||
|
|
||||||
|
lc = &cGrey90;
|
||||||
|
c = &cGrey70;
|
||||||
|
oc = &cGrey30;
|
||||||
|
|
||||||
|
// List bg.
|
||||||
|
toolkit_drawRect(x, y, lst->w, lst->h, &cWhite, NULL);
|
||||||
|
|
||||||
|
// Inner outline.
|
||||||
|
toolkit_drawOutline(x, y, lst->w, lst->h, 1., lc, c);
|
||||||
|
// Outter outline.
|
||||||
|
toolkit_drawOutline(x, y, lst->w, lst->h, 2., oc, NULL);
|
||||||
|
|
||||||
|
// Draw content.
|
||||||
|
tx = (double)gl_screen.w/2. + x+2.;
|
||||||
|
ty = (double)gl_screen.h/2. + y+lst->h - 2. - gl_defFont.h;
|
||||||
|
y = ty-2.;
|
||||||
|
|
||||||
|
for(i = lst->dat.lst.pos; i < lst->dat.lst.noptions; i++) {
|
||||||
|
gl_printMax(&gl_defFont, (int)lst->w-4,
|
||||||
|
tx, ty, &cBlack, lst->dat.lst.options[i]);
|
||||||
|
|
||||||
|
ty -= 2 + gl_defFont.h;
|
||||||
|
if(ty-y > lst->h) break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the window.
|
// Render the window.
|
||||||
|
@ -19,6 +19,11 @@ void window_addText(const unsigned int wid, const int x, const int y,
|
|||||||
void window_addImage(const unsigned int wid, const int x, const int y,
|
void window_addImage(const unsigned int wid, const int x, const int y,
|
||||||
char* name, glTexture* image);
|
char* name, glTexture* image);
|
||||||
|
|
||||||
|
void window_addList(const unsigned int wid,
|
||||||
|
const int x, const int y, // Position.
|
||||||
|
const int w, const int h, // Size.
|
||||||
|
char* name, char** items, int nitems, int defitem);
|
||||||
|
|
||||||
// Modification
|
// Modification
|
||||||
void window_modifyText(const unsigned int wid, char* name, char* newstring);
|
void window_modifyText(const unsigned int wid, char* name, char* newstring);
|
||||||
void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
|
void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
|
||||||
|
Loading…
Reference in New Issue
Block a user