widget: Convert the keymap menu from W_TABFORM to ListTabWidget.

Removed a sort-of bubble sort.
master
Cyp 2013-03-10 00:14:11 +01:00
parent 052f577eec
commit 34381f03fd
1 changed files with 28 additions and 108 deletions

View File

@ -33,6 +33,7 @@
#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/sound/audio.h"
#include "lib/sound/audio_id.h"
#include "lib/widget/button.h"
#include "frend.h"
#include "frontend.h"
@ -49,7 +50,6 @@
// defines
#define KM_FORM 10200
#define KM_FORM_TABS 10201
#define KM_RETURN 10202
#define KM_DEFAULT 10203
@ -62,10 +62,9 @@
#define KM_Y 20
#define KM_SX FRONTEND_SIDEX
#define BUTTONSPERKEYMAPPAGE 20
#define KM_ENTRYW (FRONTEND_BOTFORMW - 80)
#define KM_ENTRYH (( (KM_H-50)/BUTTONSPERKEYMAPPAGE )-3 )
#define KM_ENTRYH (16)
// ////////////////////////////////////////////////////////////////////////////
@ -289,16 +288,14 @@ static void displayKeyMap(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset)
iV_DrawText(sKey, x + 364, y + (psWidget->height() / 2) + 3);
}
static bool keyMappingSort(KEY_MAPPING const *a, KEY_MAPPING const *b)
{
return strcmp(a->pName, b->pName) < 0;
}
// ////////////////////////////////////////////////////////////////////////////
bool startKeyMapEditor(bool first)
{
KEY_MAPPING *psMapping;
UDWORD mapcount = 0;
UDWORD bubbleCount;
bool bAtEnd,bGotOne;
KEY_MAPPING *psPresent = NULL, *psNext;
char test[255];
addBackdrop();
addSideText(FRONTEND_SIDETEXT, KM_SX, KM_Y, _("KEY MAPPING"));
@ -321,115 +318,38 @@ bool startKeyMapEditor(bool first)
addMultiBut(psWScreen,KM_FORM,KM_DEFAULT,
11,45,
56,38,
iV_GetImageWidth(FrontImages, IMAGE_KEYMAP_DEFAULT), iV_GetImageWidth(FrontImages, IMAGE_KEYMAP_DEFAULT),
_("Select Default"),
IMAGE_KEYMAP_DEFAULT, IMAGE_KEYMAP_DEFAULT_HI, IMAGE_KEYMAP_DEFAULT_HI); // default.
/* Better be none that come after this...! */
sstrcpy(test, "zzzzzzzzzzzzzzzzzzzzz");
psMapping = NULL;
//count mappings required.
for(psMapping = keyMappings; psMapping; psMapping = psMapping->psNext)
{
if( (psMapping->status!=KEYMAP__DEBUG)&&(psMapping->status!=KEYMAP___HIDE)) // if it's not a debug mapping..
{
mapcount++;
if(strcmp(psMapping->pName,test) < 0)
{
/* Best one found so far */
sstrcpy(test, psMapping->pName);
psPresent = psMapping;
}
}
}
// add tab form..
W_FORMINIT sFormInit;
sFormInit.formID = KM_FORM;
sFormInit.id = KM_FORM_TABS;
sFormInit.style = WFORM_TABBED;
sFormInit.x = 50;
sFormInit.y = 10;
sFormInit.width = KM_W- 100;
sFormInit.height = KM_H- 4;
sFormInit.numMajor = numForms(mapcount, BUTTONSPERKEYMAPPAGE);
sFormInit.majorPos = WFORM_TABTOP;
sFormInit.majorSize = OBJ_TABWIDTH+3;
sFormInit.majorOffset = OBJ_TABOFFSET;
sFormInit.tabVertOffset = (OBJ_TABHEIGHT/2);
sFormInit.tabMajorThickness = OBJ_TABHEIGHT;
sFormInit.pUserData = &StandardTab;
sFormInit.pTabDisplay = intDisplayTab;
widgAddForm(psWScreen, &sFormInit);
IntListTabWidget *kmList = new IntListTabWidget(kmForm);
kmList->setChildSize(KM_ENTRYW, KM_ENTRYH);
kmList->setChildSpacing(3, 3);
kmList->setGeometry(52, 10, KM_ENTRYW, KM_H - 10 - 25);
//Put the buttons on it
W_BUTINIT sButInit;
sButInit.formID = KM_FORM_TABS;
sButInit.width = KM_ENTRYW;
sButInit.height = KM_ENTRYH;
sButInit.pDisplay = displayKeyMap;
sButInit.x = 2;
sButInit.y = 16;
sButInit.id = KM_START;
/* Add our first mapping to the form */
sButInit.pUserData= psPresent;
widgAddButton(psWScreen, &sButInit);
sButInit.id++;
sButInit.y += KM_ENTRYH +3;
/* Now add the others... */
bubbleCount = 0;
bAtEnd = false;
/* Stop when the right number or when aphabetically last - not sure...! */
while(bubbleCount<mapcount-1 && !bAtEnd)
std::vector<KEY_MAPPING *> mappings;
for (KEY_MAPPING *m = keyMappings; m != nullptr; m = m->psNext)
{
/* Same test as before for upper limit */
sstrcpy(test, "zzzzzzzzzzzzzzzzzzzzz");
for(psMapping = keyMappings,psNext = NULL,bGotOne = false; psMapping; psMapping = psMapping->psNext)
if (m->status != KEYMAP__DEBUG && m->status != KEYMAP___HIDE) // if it's not a debug mapping..
{
/* Only certain mappings get displayed */
if( (psMapping->status!=KEYMAP__DEBUG)&&(psMapping->status!=KEYMAP___HIDE)) // if it's not a debug mapping..
{
/* If it's alphabetically good but better then next one */
if(strcmp(psMapping->pName,test) < 0 && strcmp(psMapping->pName,psPresent->pName) > 0)
{
/* Keep a record of it */
sstrcpy(test, psMapping->pName);
psNext = psMapping;
bGotOne = true;
}
}
}
/* We found one matching criteria */
if(bGotOne)
{
psPresent = psNext;
bubbleCount++;
sButInit.pUserData= psNext;
widgAddButton(psWScreen, &sButInit);
// move on..
sButInit.id++;
/* Might be no more room on the page */
if ( (sButInit.y + KM_ENTRYH+5 ) > (3+ (BUTTONSPERKEYMAPPAGE*(KM_ENTRYH+3))))
{
sButInit.y = 16;
sButInit.majorID += 1;
}
else
{
sButInit.y += KM_ENTRYH +3;
}
}
else
{
/* The previous one we found was alphabetically last - time to stop */
bAtEnd = true;
mappings.push_back(m);
}
}
std::sort(mappings.begin(), mappings.end(), keyMappingSort);
/* Add our first mapping to the form */
/* Now add the others... */
for (std::vector<KEY_MAPPING *>::const_iterator i = mappings.begin(); i != mappings.end(); ++i)
{
W_BUTTON *button = new W_BUTTON(kmList);
button->id = KM_START + (i - mappings.begin());
button->pUserData = *i;
button->displayFunction = displayKeyMap;
kmList->addWidgetToLayout(button);
}
/* Stop when the right number or when aphabetically last - not sure...! */
/* Go home... */
return true;
}