sparrowMapping

sparrowMapping is for handling different mappings of controls.  You don’t to have think like “A is jumping” but “Jump button is jumping”.  You define your own buttons with mapping to real existing buttons, which are changeable.  ;)

You first have to define a pool with every button the user shall be able to choice.  Afterwards you can add buttons and give the users possibilites to change the button mapping.

Summary
sparrowMappingsparrowMapping is for handling different mappings of controls.
Macros
SP_MAPPING_SET_MAXThe total number of different mapping sets to create.
SP_MAPPING_MAXThe maximal number of buttons to create.
Defines for the strategy of <spMapSetStrategy>.
Functions
spInitMappingInits sparrowMapping.
spMapClean();Deletes all mappings and all buttons in the pool.
spMapPoolAddEvery button, which shall be useable by the user have to be added to the button pool.
spMapSetStrategySets the strategy to be used if a button mapping is changed, but the mapping already exists.
spMapButtonAddAdds a semantic button identified by name or a self given ID (advise: Use #define MY_FIRE_BUTTON 0 or similar for the id).
spMapChangeChanges the mapping of an existing button with the setup strategy (see spMapSetStrategy).
spMapChangeNextInPoolSets the mapping to the next possible button in the pool.
spMapChangePreviousInPoolSets the mapping to the previous possible button in the pool.
spMapGetByIDReturns the state of the button given by the id.
spMapSetByIDSets the state of the button given by the id.
spMapGetByNameReturns the state of the button given by the name.
spMapSetByNameSets the state of the button given by the name.
spMapCaptionByIDReturns the caption of the semantic button via it’s ID.
spMapCaptionByNameReturns the caption of the semantic button via it’s name.
spMapButtonByIDReturns the caption of the real button behind the mapping via it’s ID.
spMapButtonByNameReturns the caption of the real button behind the mapping via it’s name.
spMapPoolByIDReturns the real button id of the real button behind the mapping via it’s ID.
spMapPoolByNameReturns the real button id of the real button behind the mapping via it’s name.
spMapStartChangeByIDStarts the changing of the mapping of a buttons identified by it’s ID.
spMapStartChangeByNameStarts the changing of the mapping of a buttons identified by it’s name.
spMapContinueChangeInterpretates to user input to change the mapping of a semantic button.
spMapLastCollisionNameReturns the name of the semantic button caption of last collision if spMapContinueChange returned 2.
spMapLastCollisionPoolReturns the name of the pool button of last collision if spMapContinueChange returned 2.
spMapCancelChangeCancels the mapping change started with spMapStartChangeByID or spMapStartChangeByName.
spMapLoadLoads a mapping.
spMapSaveSaves a mapping.

Macros

SP_MAPPING_SET_MAX

The total number of different mapping sets to create.

SP_MAPPING_MAX

The maximal number of buttons to create.  This may appeal strange, why to limit the count of buttons, but most of the sparrow3d does only have 8 buttons (most of the time A,B,X,Y,L,R and Start and Select or similar) and using two mappings for one real buttons is not possible.

Defines for the strategy of <spMapSetStrategy>.

SP_MAPPING_NONEUse no strategy at all.  Just set the button.
SP_MAPPING_SWITCHIf the button is already used by another mapping switch the mappings.  Otherwise just set it.
SP_MAPPING_OTHER_INVALIDIf the button is already used by another mapping delete the other mapping.
SP_MAPPING_CANCELIf the button is already used, don’t set it to the new mapping, but keep the old.

Functions

spInitMapping

PREFIX void spInitMapping(void)

Inits sparrowMapping.  This function should be called by spInitCore.

spMapClean();

PREFIX void spMapClean(void)

Deletes all mappings and all buttons in the pool.

spMapPoolAdd

PREFIX void spMapPoolAdd(int button_id,
char *caption)

Every button, which shall be useable by the user have to be added to the button pool.

Parameters

button_idthe real sparrow3d button id of the button, e.g.  SP_BUTTON_A or SP_BUTTON_LEFT.
captionthe caption of the button.  Later used from spMapButtonByID and spMapButtonByName.

spMapSetStrategy

PREFIX void spMapSetStrategy(int strategy)

Sets the strategy to be used if a button mapping is changed, but the mapping already exists.

Parameters

strategymay be SP_MAPPING_NONE, which means no strategy use, SP_MAPPING_SWITCH, which means, that the mappings are switched at conflict, SP_MAPPING_OTHER_INVALID, which deletes the conflict mapping if it already exists or SP_MAPPING_CANCEL, which means, if the button is already used, don’t set it to the new mapping, but keep the old one.

spMapButtonAdd

PREFIX void spMapButtonAdd(int id,
char *name,
char *caption,
int poolButton)

Adds a semantic button identified by name or a self given ID (advise: Use #define MY_FIRE_BUTTON 0 or similar for the id).

Parameters

idthe self choosen id.  Have to be between 0 and SP_MAPPING_MAX-1.
namethe name of the semantic button.  However identifying via id is much faster!  However name is needed for saving the button mapping in a config file
captionthe caption of the button, may be “Fire” or “Select”, whatever you need.  The user should semanticly understand this caption
poolButtonthe real sparrow3d button (e.g.  SP_BUTTON_A) to be used.  Don’t forget to add this button via spMapPoolAdd before!

spMapChange

PREFIX int spMapChange(int id,
int poolButton)

Changes the mapping of an existing button with the setup strategy (see spMapSetStrategy).

Parameters

idbutton id to change
poolButtonreal sparrow3d button to change the mapping to.  Don’t forget to add this button to the pool first with spMapPoolAdd!

Returns

int0 if the button was changed or 1 if not.  This can happen, if the strategy is SP_MAPPING_CANCEL and the button was already used.

spMapChangeNextInPool

PREFIX void spMapChangeNextInPool(int id)

Sets the mapping to the next possible button in the pool.

Parameters

idid the change.

See also

spMapChangePreviousInPool

spMapChangePreviousInPool

PREFIX void spMapChangePreviousInPool(int id)

Sets the mapping to the previous possible button in the pool.

Parameters

idid the change.

See also

spMapChangeNextInPool

spMapGetByID

PREFIX int spMapGetByID(int id)

Returns the state of the button given by the id.  This is much faster than spMapGetByName.

Parameters

idthe id of the button

Returns

int0 not pressed, 1 pressed

spMapSetByID

PREFIX void spMapSetByID(int id,
int value)

Sets the state of the button given by the id.  This is much faster than spMapSetByName.

Parameters

idthe id of the button
valuevalue to set, where 0 means not pressed and 1 means pressed

spMapGetByName

PREFIX int spMapGetByName(char *name)

Returns the state of the button given by the name.  This is much slower than spMapGetByID.

Parameters

namethe name of the button

Returns

int0 not pressed, 1 pressed

spMapSetByName

PREFIX void spMapSetByName(char *name,
int value)

Sets the state of the button given by the name.  This is much slower than spMapSetByID.

Parameters

namethe name of the button
valuevalue to set, where 0 means not pressed and 1 means pressed

spMapCaptionByID

PREFIX char* spMapCaptionByID(int id)

Returns the caption of the semantic button via it’s ID.  Much faster than spMapCaptionByName.

Parameters

idthe id of the button

Returns

char*the name of the button

spMapCaptionByName

PREFIX char* spMapCaptionByName(char *name)

Returns the caption of the semantic button via it’s name.  Much slower than spMapCaptionByID.

Parameters

namethe name of the button

Returns

char*the name of the button

spMapButtonByID

PREFIX char* spMapButtonByID(int id)

Returns the caption of the real button behind the mapping via it’s ID.  Much faster than spMapButtonByName.

Parameters

idthe id of the button

Returns

char*the name of the mapped button

spMapButtonByName

PREFIX char* spMapButtonByName(char *name)

Returns the caption of the real button behind the mapping via it’s name.  Much slower than spMapButtonByID.

Parameters

namethe name of the button

Returns

char*the name of the mapped button

spMapPoolByID

PREFIX int spMapPoolByID(int id)

Returns the real button id of the real button behind the mapping via it’s ID.

Parameters

idthe id of the button

Returns

intthe button id of the mapped button like SP_BUTTON_A

spMapPoolByName

PREFIX int spMapPoolByName(char *name)

Returns the real button id of the real button behind the mapping via it’s name.  Much slower than spMapPoolByID.

Parameters

namethe name of the button

Returns

intthe button id of the mapped button like SP_BUTTON_A

spMapStartChangeByID

PREFIX void spMapStartChangeByID(int id)

Starts the changing of the mapping of a buttons identified by it’s ID.  Use spMapContinueChange to interpretate the user input.

Parameters

idthe id of the semantic button to change it’s mapping

spMapStartChangeByName

PREFIX void spMapStartChangeByName(char *name)

Starts the changing of the mapping of a buttons identified by it’s name.  Use spMapContinueChange to interpretate the user input.

Parameters

namethe name of the semantic button to change it’s mapping

spMapContinueChange

PREFIX int spMapContinueChange(void)

Interpretates to user input to change the mapping of a semantic button.  The whole process is started with spMapStartChangeByID or spMapStartChangeByName.

Returns

int0 means changes are still in progress, so maybe some functions of the program should be supressed like going back to another menu or similar.  1 means the button mapping has been changed just now with this call, what is e.g. a good time to save the mapping.  -1 means no button changing process is running right know.  If 2 is returned the function is done, but no new button was set.  That is the case, if the strategy is SP_MAPPING_CANCEL, but the mapped was already in use.  The collision semantic button and pool button can be read via spMapLastCollisionName and spMapLastCollisionPool.

spMapLastCollisionName

Returns the name of the semantic button caption of last collision if spMapContinueChange returned 2.

Returns

char*caption of the semantic button, may be NULL!

spMapLastCollisionPool

PREFIX char* spMapLastCollisionPool(void)

Returns the name of the pool button of last collision if spMapContinueChange returned 2.

Returns

char*name of the pool button, may be NULL!

spMapCancelChange

PREFIX void spMapCancelChange(void)

Cancels the mapping change started with spMapStartChangeByID or spMapStartChangeByName.  No new mapping is set!  spMapContinueChange will just throw -1 like always when nothing is to do.  ;)

spMapLoad

PREFIX void spMapLoad(char *subfolder,
char *filename)

Loads a mapping.  Important: You should first create the pool, than add your semantic buttons (same as in the saved mapping!) and then load the config.  If no config is there yet, the value set by you will be kept.

Parameters

subfoldersubfolder for the config to be used.  Not used on any system, but this should be the name of your application, so that the config is read e.g. from ~/.config/subfolder/filename
filenamefilename to read from

spMapSave

PREFIX void spMapSave(char *subfolder,
char *filename)

Saves a mapping.  Important: You should first create the pool, than add your semantic buttons (same as in the saved mapping!) and then load the config.  If no config is there yet, the value set by you will be kept.

Parameters

subfoldersubfolder for the config to be used.  Not used on any system, but this should be the name of your application, so that the config is saved e.g. to ~/.config/subfolder/filename
filenamefilename to save to
PREFIX void spInitMapping(void)
Inits sparrowMapping.
PREFIX void spMapClean(void)
Deletes all mappings and all buttons in the pool.
PREFIX void spMapPoolAdd(int button_id,
char *caption)
Every button, which shall be useable by the user have to be added to the button pool.
PREFIX void spMapSetStrategy(int strategy)
Sets the strategy to be used if a button mapping is changed, but the mapping already exists.
PREFIX void spMapButtonAdd(int id,
char *name,
char *caption,
int poolButton)
Adds a semantic button identified by name or a self given ID (advise: Use #define MY_FIRE_BUTTON 0 or similar for the id).
PREFIX int spMapChange(int id,
int poolButton)
Changes the mapping of an existing button with the setup strategy (see spMapSetStrategy).
PREFIX void spMapChangeNextInPool(int id)
Sets the mapping to the next possible button in the pool.
PREFIX void spMapChangePreviousInPool(int id)
Sets the mapping to the previous possible button in the pool.
PREFIX int spMapGetByID(int id)
Returns the state of the button given by the id.
PREFIX void spMapSetByID(int id,
int value)
Sets the state of the button given by the id.
PREFIX int spMapGetByName(char *name)
Returns the state of the button given by the name.
PREFIX void spMapSetByName(char *name,
int value)
Sets the state of the button given by the name.
PREFIX char* spMapCaptionByID(int id)
Returns the caption of the semantic button via it’s ID.
PREFIX char* spMapCaptionByName(char *name)
Returns the caption of the semantic button via it’s name.
PREFIX char* spMapButtonByID(int id)
Returns the caption of the real button behind the mapping via it’s ID.
PREFIX char* spMapButtonByName(char *name)
Returns the caption of the real button behind the mapping via it’s name.
PREFIX int spMapPoolByID(int id)
Returns the real button id of the real button behind the mapping via it’s ID.
PREFIX int spMapPoolByName(char *name)
Returns the real button id of the real button behind the mapping via it’s name.
PREFIX void spMapStartChangeByID(int id)
Starts the changing of the mapping of a buttons identified by it’s ID.
PREFIX void spMapStartChangeByName(char *name)
Starts the changing of the mapping of a buttons identified by it’s name.
PREFIX int spMapContinueChange(void)
Interpretates to user input to change the mapping of a semantic button.
PREFIX char* spMapLastCollisionPool(void)
Returns the name of the pool button of last collision if spMapContinueChange returned 2.
PREFIX void spMapCancelChange(void)
Cancels the mapping change started with spMapStartChangeByID or spMapStartChangeByName.
PREFIX void spMapLoad(char *subfolder,
char *filename)
Loads a mapping.
PREFIX void spMapSave(char *subfolder,
char *filename)
Saves a mapping.
PREFIX void spInitCore(void)
spInitCore initializes SDL, SDL_TTF and other stuff.
If the button is already used, don’t set it to the new mapping, but keep the old.
Returns the name of the semantic button caption of last collision if spMapContinueChange returned 2.
Close