Simplified the VControl interface some.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2687 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2007-01-30 07:12:37 +00:00
parent 6fa3426157
commit 94fd412f2e
3 changed files with 28 additions and 52 deletions
+4 -4
View File
@@ -449,20 +449,20 @@ RemoveInputState (int template, int control, int index)
void void
RebindInputState (int template, int control, int index) RebindInputState (int template, int control, int index)
{ {
SDL_Event e; VCONTROL_GESTURE g;
/* Remove the old binding on this spot */ /* Remove the old binding on this spot */
RemoveInputState (template, control, index); RemoveInputState (template, control, index);
/* Wait for the next interesting bit of user input */ /* Wait for the next interesting bit of user input */
VControl_ClearEvent (); VControl_ClearGesture ();
while (!VControl_GetLastEvent (&e)) while (!VControl_GetLastGesture (&g))
{ {
TaskSwitch (); TaskSwitch ();
} }
/* And now, add the new binding. */ /* And now, add the new binding. */
VControl_AddBinding (&e, &ImmediateInputState.key[template][control]); VControl_AddGestureBinding (&g, &ImmediateInputState.key[template][control]);
} }
void void
+21 -42
View File
@@ -233,6 +233,7 @@ key_uninit (void)
for (i = 0; i < num_sdl_keys; i++) for (i = 0; i < num_sdl_keys; i++)
bindings[i] = NULL; bindings[i] = NULL;
HFree (bindings); HFree (bindings);
bindings = NULL;
pool = NULL; pool = NULL;
#ifdef HAVE_JOYSTICK #ifdef HAVE_JOYSTICK
@@ -402,59 +403,38 @@ deactivate (keybinding *i)
} }
} }
int static void
VControl_AddBinding (SDL_Event *e, int *target) event2gesture (SDL_Event *e, VCONTROL_GESTURE *g)
{
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)
{ {
switch (e->type) switch (e->type)
{ {
case SDL_KEYDOWN: case SDL_KEYDOWN:
VControl_RemoveKeyBinding (e->key.keysym.sym, target); g->type = VCONTROL_KEY;
g->gesture.key = e->key.keysym.sym;
break; break;
#ifdef HAVE_JOYSTICK #ifdef HAVE_JOYSTICK
case SDL_JOYAXISMOTION: 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; break;
case SDL_JOYHATMOTION: 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; break;
case SDL_JOYBUTTONDOWN: 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; break;
#endif /* HAVE_JOYSTICK */ #endif /* HAVE_JOYSTICK */
default: default:
log_add (log_Warning, "VControl_RemoveBinding didn't understand argument event"); g->type = VCONTROL_NONE;
break; break;
} }
} }
@@ -516,7 +496,6 @@ VControl_RemoveGestureBinding (VCONTROL_GESTURE *g, int *target)
} }
} }
int int
VControl_AddKeyBinding (SDLKey symbol, int *target) VControl_AddKeyBinding (SDLKey symbol, int *target)
{ {
@@ -1242,17 +1221,17 @@ VControl_NextBinding (VCONTROL_GESTURE *gesture)
/* Tracking the last interesting event */ /* Tracking the last interesting event */
void void
VControl_ClearEvent (void) VControl_ClearGesture (void)
{ {
event_ready = 0; event_ready = 0;
} }
int 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; return event_ready;
} }
+3 -6
View File
@@ -48,9 +48,6 @@ typedef struct {
} VCONTROL_GESTURE; } VCONTROL_GESTURE;
/* Control of bindings */ /* 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); int VControl_AddGestureBinding (VCONTROL_GESTURE *g, int *target);
void VControl_RemoveGestureBinding (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); void VControl_StartIterByName (char *targetname);
int VControl_NextBinding (VCONTROL_GESTURE *gesture); 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. */ control keys. */
void VControl_ClearEvent (void); void VControl_ClearGesture (void);
int VControl_GetLastEvent (SDL_Event *e); int VControl_GetLastGesture (VCONTROL_GESTURE *g);
#endif #endif