From 9ac872aac4eba326b37764b953b9aa28ffd58e94 Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 6 Mar 2013 14:54:11 +0000 Subject: [PATCH] [Add] Selected list thingy actually renders. You can focus it too. --- src/colour.c | 2 ++ src/colour.h | 2 ++ src/land.c | 2 +- src/toolkit.c | 19 ++++++++++++++++--- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/colour.c b/src/colour.c index 4231b5a..67bbc41 100644 --- a/src/colour.c +++ b/src/colour.c @@ -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. }; diff --git a/src/colour.h b/src/colour.h index 5524795..8757256 100644 --- a/src/colour.h +++ b/src/colour.h @@ -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; diff --git a/src/land.c b/src/land.c index 06d52d9..64e2298 100644 --- a/src/land.c +++ b/src/land.c @@ -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) { diff --git a/src/toolkit.c b/src/toolkit.c index a4aa2b8..d7e5feb 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -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();