[Fix] Fixed possible key repeat blocking.

This commit is contained in:
Allanis 2014-03-04 00:31:04 +00:00
parent e9276b5704
commit 4d3dfd5637

View File

@ -151,6 +151,7 @@ static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key);
static void toolkit_mouseEvent(SDL_Event* event); static void toolkit_mouseEvent(SDL_Event* event);
static int toolkit_keyEvent(SDL_Event* event); static int toolkit_keyEvent(SDL_Event* event);
static void toolkit_imgarrMove(Widget* iar, double ry); static void toolkit_imgarrMove(Widget* iar, double ry);
static void toolkit_clearKey(void);
/* Focus. */ /* Focus. */
static void toolkit_nextFocus(void); static void toolkit_nextFocus(void);
static int toolkit_isFocusable(Widget* wgt); 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->id = wid;
wdw->name = strdup(name); wdw->name = strdup(name);
/* Sane defaults. */
wdw->hidden = 0; wdw->hidden = 0;
wdw->focus = -1; wdw->focus = -1;
wdw->accept_fptr = NULL; 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) { void window_destroy(const unsigned int wid) {
int i, j; int i, j;
@ -710,8 +715,16 @@ void window_destroy(const unsigned int wid) {
toolkit = 0; /* Disable the toolkit. */ toolkit = 0; /* Disable the toolkit. */
if(paused) unpause_game(); 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) { void window_destroyWidget(unsigned int wid, const char* wgtname) {
Window* w = window_wget(wid); Window* w = window_wget(wid);
int i; 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.. */ (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, static void toolkit_drawOutline(double x, double y, double w, double h,
double b, glColour* c, glColour* lc) { double b, glColour* c, glColour* lc) {
@ -780,7 +805,13 @@ static void toolkit_drawRect(double x, double y, double w, double h,
glEnd(); 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) { static void toolkit_clip(double x, double y, double w, double h) {
GLdouble ctop[4] = { 0., 1., 0., -y }; GLdouble ctop[4] = { 0., 1., 0., -y };
GLdouble cbot[4] = { 0., -1., 0., y+h }; 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); glEnable(GL_CLIP_PLANE3);
} }
/**
* @brief Clears the 2D clipping planes.
*/
static void toolkit_unclip(void) { static void toolkit_unclip(void) {
glDisable(GL_CLIP_PLANE0); glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1); 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) { static void window_render(Window* w) {
int i; int i;
double x, y, wid, hei; double x, y, wid, hei;
@ -1437,7 +1474,7 @@ static void toolkit_mouseEvent(SDL_Event* event) {
toolkit_listScroll(wgt, +1); toolkit_listScroll(wgt, +1);
break; break;
} }
if(event->button.button == SDL_BUTTON_WHEELDOWN) { else if(event->button.button == SDL_BUTTON_WHEELDOWN) {
toolkit_listScroll(wgt, -1); toolkit_listScroll(wgt, -1);
break; break;
} }
@ -1450,7 +1487,7 @@ static void toolkit_mouseEvent(SDL_Event* event) {
//input_key = 0; /* Hack to avoid weird bug with permascroll. */ //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); toolkit_imgarrFocus(wgt, x-wgt->x, y-wgt->y);
break; 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) { static int toolkit_keyEvent(SDL_Event* event) {
Window* wdw; Window* wdw;
Widget* wgt; Widget* wgt;