From 94fd412f2ebbb6a2356878e7f19787043e593b58 Mon Sep 17 00:00:00 2001 From: mcmartin Date: Tue, 30 Jan 2007 07:12:37 +0000 Subject: [PATCH] Simplified the VControl interface some. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2687 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/libs/input/sdl/input.c | 8 +-- sc2/src/sc2code/libs/input/sdl/vcontrol.c | 63 ++++++++--------------- sc2/src/sc2code/libs/input/sdl/vcontrol.h | 9 ++-- 3 files changed, 28 insertions(+), 52 deletions(-) diff --git a/sc2/src/sc2code/libs/input/sdl/input.c b/sc2/src/sc2code/libs/input/sdl/input.c index 569cda1f3..59c4f882b 100644 --- a/sc2/src/sc2code/libs/input/sdl/input.c +++ b/sc2/src/sc2code/libs/input/sdl/input.c @@ -449,20 +449,20 @@ RemoveInputState (int template, int control, int index) void RebindInputState (int template, int control, int index) { - SDL_Event e; + VCONTROL_GESTURE g; /* Remove the old binding on this spot */ RemoveInputState (template, control, index); /* Wait for the next interesting bit of user input */ - VControl_ClearEvent (); - while (!VControl_GetLastEvent (&e)) + VControl_ClearGesture (); + while (!VControl_GetLastGesture (&g)) { TaskSwitch (); } /* And now, add the new binding. */ - VControl_AddBinding (&e, &ImmediateInputState.key[template][control]); + VControl_AddGestureBinding (&g, &ImmediateInputState.key[template][control]); } void diff --git a/sc2/src/sc2code/libs/input/sdl/vcontrol.c b/sc2/src/sc2code/libs/input/sdl/vcontrol.c index 41e27720e..09792a914 100644 --- a/sc2/src/sc2code/libs/input/sdl/vcontrol.c +++ b/sc2/src/sc2code/libs/input/sdl/vcontrol.c @@ -233,6 +233,7 @@ key_uninit (void) for (i = 0; i < num_sdl_keys; i++) bindings[i] = NULL; HFree (bindings); + bindings = NULL; pool = NULL; #ifdef HAVE_JOYSTICK @@ -402,59 +403,38 @@ deactivate (keybinding *i) } } -int -VControl_AddBinding (SDL_Event *e, int *target) -{ - int result; - switch (e->type) - { - case SDL_KEYDOWN: - result = VControl_AddKeyBinding (e->key.keysym.sym, target); - break; - -#ifdef HAVE_JOYSTICK - case SDL_JOYAXISMOTION: - result = VControl_AddJoyAxisBinding (e->jaxis.which, e->jaxis.axis, (e->jaxis.value < 0) ? -1 : 1, target); - break; - case SDL_JOYHATMOTION: - result = VControl_AddJoyHatBinding (e->jhat.which, e->jhat.hat, e->jhat.value, target); - break; - case SDL_JOYBUTTONDOWN: - result = VControl_AddJoyButtonBinding (e->jbutton.which, e->jbutton.button, target); - break; -#endif /* HAVE_JOYSTICK */ - - default: - log_add (log_Warning, "VControl_AddBinding didn't understand argument event"); - result = -1; - break; - } - return result; -} - -void -VControl_RemoveBinding (SDL_Event *e, int *target) +static void +event2gesture (SDL_Event *e, VCONTROL_GESTURE *g) { switch (e->type) { case SDL_KEYDOWN: - VControl_RemoveKeyBinding (e->key.keysym.sym, target); + g->type = VCONTROL_KEY; + g->gesture.key = e->key.keysym.sym; break; #ifdef HAVE_JOYSTICK case SDL_JOYAXISMOTION: - VControl_RemoveJoyAxisBinding (e->jaxis.which, e->jaxis.axis, (e->jaxis.value < 0) ? -1 : 1, target); + g->type = VCONTROL_JOYAXIS; + g->gesture.axis.port = e->jaxis.which; + g->gesture.axis.index = e->jaxis.axis; + g->gesture.axis.polarity = (e->jaxis.value < 0) ? -1 : 1; break; case SDL_JOYHATMOTION: - VControl_RemoveJoyHatBinding (e->jhat.which, e->jhat.hat, e->jhat.value, target); + g->type = VCONTROL_JOYHAT; + g->gesture.hat.port = e->jhat.which; + g->gesture.hat.index = e->jhat.hat; + g->gesture.hat.dir = e->jhat.value; break; case SDL_JOYBUTTONDOWN: - VControl_RemoveJoyButtonBinding (e->jbutton.which, e->jbutton.button, target); + g->type = VCONTROL_JOYBUTTON; + g->gesture.button.port = e->jbutton.which; + g->gesture.button.index = e->jbutton.button; break; #endif /* HAVE_JOYSTICK */ default: - log_add (log_Warning, "VControl_RemoveBinding didn't understand argument event"); + g->type = VCONTROL_NONE; break; } } @@ -516,7 +496,6 @@ VControl_RemoveGestureBinding (VCONTROL_GESTURE *g, int *target) } } - int VControl_AddKeyBinding (SDLKey symbol, int *target) { @@ -1242,17 +1221,17 @@ VControl_NextBinding (VCONTROL_GESTURE *gesture) /* Tracking the last interesting event */ void -VControl_ClearEvent (void) +VControl_ClearGesture (void) { event_ready = 0; } int -VControl_GetLastEvent (SDL_Event *e) +VControl_GetLastGesture (VCONTROL_GESTURE *g) { - if (event_ready && e != NULL) + if (event_ready && g != NULL) { - *e = last_interesting; + event2gesture(&last_interesting, g); } return event_ready; } diff --git a/sc2/src/sc2code/libs/input/sdl/vcontrol.h b/sc2/src/sc2code/libs/input/sdl/vcontrol.h index 21b101e4b..1e65f92b4 100644 --- a/sc2/src/sc2code/libs/input/sdl/vcontrol.h +++ b/sc2/src/sc2code/libs/input/sdl/vcontrol.h @@ -48,9 +48,6 @@ typedef struct { } VCONTROL_GESTURE; /* Control of bindings */ -int VControl_AddBinding (SDL_Event *e, int *target); -void VControl_RemoveBinding (SDL_Event *e, int *target); - int VControl_AddGestureBinding (VCONTROL_GESTURE *g, int *target); void VControl_RemoveGestureBinding (VCONTROL_GESTURE *g, int *target); @@ -116,10 +113,10 @@ void VControl_StartIter (int *target); void VControl_StartIterByName (char *targetname); int VControl_NextBinding (VCONTROL_GESTURE *gesture); -/* Tracking the "last interesting event." Used to poll to find new +/* Tracking the "last interesting gesture." Used to poll to find new control keys. */ -void VControl_ClearEvent (void); -int VControl_GetLastEvent (SDL_Event *e); +void VControl_ClearGesture (void); +int VControl_GetLastGesture (VCONTROL_GESTURE *g); #endif