From 4d3dfd56374a296f158eeff56b1ec94336320906 Mon Sep 17 00:00:00 2001 From: Allanis Date: Tue, 4 Mar 2014 00:31:04 +0000 Subject: [PATCH] [Fix] Fixed possible key repeat blocking. --- src/toolkit.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/src/toolkit.c b/src/toolkit.c index b26a301..ee35b66 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -151,6 +151,7 @@ static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key); static void toolkit_mouseEvent(SDL_Event* event); static int toolkit_keyEvent(SDL_Event* event); static void toolkit_imgarrMove(Widget* iar, double ry); +static void toolkit_clearKey(void); /* Focus. */ static void toolkit_nextFocus(void); static int toolkit_isFocusable(Widget* wgt); @@ -554,6 +555,7 @@ unsigned int window_create(char* name, const int x, const int y, wdw->id = wid; wdw->name = strdup(name); + /* Sane defaults. */ wdw->hidden = 0; wdw->focus = -1; wdw->accept_fptr = NULL; @@ -680,7 +682,10 @@ void window_close(unsigned int wid, char* str) { } -/* Destroy a window. */ +/** + * @brief Destroy a window. + * @param wid ID of window to destroy. + */ void window_destroy(const unsigned int wid) { int i, j; @@ -710,8 +715,16 @@ void window_destroy(const unsigned int wid) { toolkit = 0; /* Disable the toolkit. */ if(paused) unpause_game(); } + + /* Clear key repeat, since toolkit could miss the keyup event. */ + toolkit_clearKey(); } +/** + * @brief wid Window to destroy widget in. + * @param wid Window to destroy widget in. + * @param wgtname Name of the wdiget to destroy. + */ void window_destroyWidget(unsigned int wid, const char* wgtname) { Window* w = window_wget(wid); int i; @@ -740,6 +753,18 @@ void window_destroyWidget(unsigned int wid, const char* wgtname) { (w->nwidgets)--; /* Not that we don't actually realloc the space.. */ } +/** + * @breif Draw an outline. + * + * If lc is NULL, colour will be flat! + * @param x X position to draw at. + * @param y Y position to draw at. + * @param w Width. + * @param h Height. + * @param b Border width. + * @param c Colour. + * @param lc Light colour. + */ static void toolkit_drawOutline(double x, double y, double w, double h, double b, glColour* c, glColour* lc) { @@ -780,7 +805,13 @@ static void toolkit_drawRect(double x, double y, double w, double h, glEnd(); } -/* Set up 2d clipping planes around a rectangle. */ +/** + * @brief Set up 2d clipping planes around a rectangle. + * @param x X position of the rectangle. + * @param y Y position of the rectangle. + * @param w Width of the rectangle. + * @param h Height of the rectangle. + */ static void toolkit_clip(double x, double y, double w, double h) { GLdouble ctop[4] = { 0., 1., 0., -y }; GLdouble cbot[4] = { 0., -1., 0., y+h }; @@ -798,6 +829,9 @@ static void toolkit_clip(double x, double y, double w, double h) { glEnable(GL_CLIP_PLANE3); } +/** + * @brief Clears the 2D clipping planes. + */ static void toolkit_unclip(void) { glDisable(GL_CLIP_PLANE0); glDisable(GL_CLIP_PLANE1); @@ -806,7 +840,10 @@ static void toolkit_unclip(void) { } -/* Render a window. */ +/** + * @brief Render a window. + * @param w Window to render. + */ static void window_render(Window* w) { int i; double x, y, wid, hei; @@ -1437,7 +1474,7 @@ static void toolkit_mouseEvent(SDL_Event* event) { toolkit_listScroll(wgt, +1); break; } - if(event->button.button == SDL_BUTTON_WHEELDOWN) { + else if(event->button.button == SDL_BUTTON_WHEELDOWN) { toolkit_listScroll(wgt, -1); break; } @@ -1450,7 +1487,7 @@ static void toolkit_mouseEvent(SDL_Event* event) { //input_key = 0; /* Hack to avoid weird bug with permascroll. */ } - if(wgt->type == WIDGET_IMAGEARRAY) + else if(wgt->type == WIDGET_IMAGEARRAY) toolkit_imgarrFocus(wgt, x-wgt->x, y-wgt->y); break; @@ -1508,6 +1545,12 @@ static void toolkit_unregKey(SDLKey key) { } } +static void toolkit_clearKey(void) { + input_key = 0; + input_keyTime = 0; + input_keyCounter = 0; +} + static int toolkit_keyEvent(SDL_Event* event) { Window* wdw; Widget* wgt;