[Add] Selected list thingy actually renders. You can focus it too.

This commit is contained in:
Allanis 2013-03-06 14:54:11 +00:00
parent f0fa480fb4
commit 9ac872aac4
4 changed files with 21 additions and 4 deletions

View File

@ -20,6 +20,8 @@ glColour cRed = { .r = 0.80, .g = 0.20, .b = 0.20, .a = 1 };
// Game specific.
glColour cConsole = { .r = 0.1, .g = 0.9, .b = 0.1, .a = 1. };
glColour cDConsole = { .r = 0.0, .g = 0.7, .b = 0.0, .a = 1. };
// Toolkit.
glColour cHilight = { .r = 0.1, .g = 0.9, .b = 0.1, .a = 0.3 };
// Objects
glColour cInert = { .r = 0.6, .g = 0.6, .b = 0.6, .a = 1. };
glColour cNeutral = { .r = 0.9, .g = 1.0, .b = 0.3, .a = 1. };

View File

@ -29,6 +29,8 @@ extern glColour cRed;
// Game specific.
extern glColour cConsole;
extern glColour cDConsole;
// Toolkit.
extern glColour cHilight;
// Objects.
extern glColour cInert;
extern glColour cNeutral;

View File

@ -58,7 +58,7 @@ static void commodity_exchange(void) {
"Close", commodity_exchange_close);
window_addList(secondary_wid, 20, -40, COMMODITY_WIDTH-30, COMMODITY_HEIGHT-80-BUTTON_HEIGHT,
"lstGoods", goods, ngoods, -1);
"lstGoods", goods, ngoods, 0);
}
static void commodity_exchange_close(char* str) {

View File

@ -183,6 +183,10 @@ void window_addList(const unsigned int wid, const int x, const int y,
else wgt->x = (double) x;
if(y < 0) wgt->y = wdw->h - wgt->h + y;
else wgt->y = (double) y;
if(wdw->focus == -1)
// Initialize the focus.
toolkit_nextFocus();
}
// Return pointer to newly allocated widget.
@ -681,9 +685,13 @@ static void toolkit_renderList(Widget* lst, double bx, double by) {
toolkit_drawRect(x, y, lst->w, lst->h, &cWhite, NULL);
// Inner outline.
toolkit_drawOutline(x, y, lst->w, lst->h, 1., lc, c);
toolkit_drawOutline(x, y, lst->w, lst->h, 0., lc, c);
// Outter outline.
toolkit_drawOutline(x, y, lst->w, lst->h, 2., oc, NULL);
toolkit_drawOutline(x, y, lst->w, lst->h, 1., oc, NULL);
// Draw selected.
toolkit_drawRect(x, y-1.+lst->h-(1+lst->dat.lst.selected-lst->dat.lst.pos)*(gl_defFont.h+3.),
lst->w, gl_defFont.h+2., &cHilight, NULL);
// Draw content.
tx = (double)gl_screen.w/2. + x+2.;
@ -803,6 +811,10 @@ static int toolkit_keyEvent(SDL_Event* event) {
if(event->type == SDL_KEYDOWN)
toolkit_triggerFocus();
return 1;
case SDLK_UP:
case SDLK_DOWN:
// TODO: list up/down.
return 0;
default:
return 0;
}
@ -817,7 +829,8 @@ static void toolkit_nextFocus(void) {
else if(wdw->focus >= wdw->nwidgets)
wdw->focus = -1;
else if((++wdw->focus+1) && // Just increment.
(wdw->widgets[wdw->focus].type == WIDGET_BUTTON))
((wdw->widgets[wdw->focus].type == WIDGET_BUTTON) ||
(wdw->widgets[wdw->focus].type == WIDGET_LIST)))
return;
else
toolkit_nextFocus();