Fixed memory leaks (joystick management in controlconfig.cpp and joystickconfig.cpp ; converted menus XML file handles not released) and more F1,F12,ESC,Ret in menus

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@1701 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: bc635864e02fc7c86e1a5c896ef71839a1648887
Former-commit-id: 93ce282e5bbc82d4f73a70fedc8ccde00ad81f5f
This commit is contained in:
pouillot 2009-10-31 17:56:08 +00:00
parent 6d694e97fb
commit 1dc1ef8123
16 changed files with 205 additions and 171 deletions

View file

@ -45,10 +45,13 @@ void * exitMenuInit(void *prevMenu, void *menuHandle)
menuHandle = GfuiScreenCreate();
void *param = LoadMenuXML("quitscreen.xml");
void *param = LoadMenuXML("quitscreen.xml");
CreateStaticControls(param,menuHandle);
CreateButtonControl(menuHandle,param,"yesquit",NULL,endofprog);
CreateButtonControl(menuHandle,param,"nobacktogame",prevMenu,GfuiScreenActivate);
GfParmReleaseHandle(param);
GfuiMenuDefaultKeysAdd(menuHandle);
GfuiAddKey(menuHandle, (unsigned char)27, "No, Back to Game",

View file

@ -33,7 +33,7 @@ void *menuHandle = NULL;
tModList *RacemanModLoaded = (tModList*)NULL;
static void
onActivatePlayerConfig(void * /* dummy */)
PlayerConfigActivate(void * /* dummy */)
{
/* Here, we need to call OptionOptionInit each time the firing button
is pressed, and not only once at the Main menu initialization,
@ -81,14 +81,17 @@ MainMenuInit(void)
//Add buttons and create based on xml
CreateButtonControl(menuHandle,param,"race",ReSinglePlayerInit(menuHandle), GfuiScreenActivate);
CreateButtonControl(menuHandle,param,"configure",NULL,onActivatePlayerConfig);
CreateButtonControl(menuHandle,param,"configure",NULL,PlayerConfigActivate);
CreateButtonControl(menuHandle,param,"options",OptionOptionInit(menuHandle),GfuiScreenActivate);
CreateButtonControl(menuHandle,param,"credits",menuHandle,CreditsScreenActivate);
CreateButtonControl(menuHandle,param,"quit",MainExitMenuInit(menuHandle), GfuiScreenActivate);
void* exitMenu = MainExitMenuInit(menuHandle);
CreateButtonControl(menuHandle,param,"quit",exitMenu, GfuiScreenActivate);
GfParmReleaseHandle(param);
GfuiMenuDefaultKeysAdd(menuHandle);
GfuiAddKey(menuHandle, (unsigned char)27, "Quit Game",
MainExitMenuInit(menuHandle), GfuiScreenActivate, NULL);
exitMenu, GfuiScreenActivate, NULL);
return 0;
}

View file

@ -39,6 +39,7 @@ OptionOptionInit(void *prevMenu)
1);
void *param = LoadMenuXML("optionsmenu.xml");
CreateStaticControls(param,optionHandle);
CreateButtonControl(optionHandle,param,"graphic",GraphMenuInit(optionHandle),GfuiScreenActivate);
@ -48,6 +49,8 @@ OptionOptionInit(void *prevMenu)
CreateButtonControl(optionHandle,param,"opengl",OpenGLMenuInit(optionHandle),GfuiScreenActivate);
CreateButtonControl(optionHandle,param,"back",prevMenu,GfuiScreenActivate);
GfParmReleaseHandle(param);
GfuiMenuDefaultKeysAdd(optionHandle);
GfuiAddKey(optionHandle, 27, "Back", prevMenu, GfuiScreenActivate, NULL);

View file

@ -106,10 +106,10 @@ static tCmdDispInfo CmdDispInfo[] = {
{ GEAR_MODE_GRID, 190 }
};
static jsJoystick *Joystick[GFCTRL_JOY_NUMBER] = {NULL};
static float JoyAxis[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER] = {0};
static jsJoystick *Joystick[GFCTRL_JOY_NUMBER];
static float JoyAxis[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
static float JoyAxisCenter[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
static int JoyButtons[GFCTRL_JOY_NUMBER] = {0};
static int JoyButtons[GFCTRL_JOY_NUMBER];
static float SteerSensVal;
static float DeadZoneVal;
@ -157,13 +157,28 @@ onDeadZoneChange(void * /* dummy */)
}
/* Quit current menu */
static void
onQuit(void *prevMenu)
{
/* Release joysticks */
for (int jsInd = 0; jsInd < GFCTRL_JOY_NUMBER; jsInd++)
if (Joystick[jsInd]) {
delete Joystick[jsInd];
Joystick[jsInd] = 0;
}
/* Back to previous screen */
GfuiScreenActivate(prevMenu);
}
/* Save settings in the players preferences and go back to previous screen */
static void
onSave(void * /* dummy */)
onSave(void *prevMenu)
{
ControlPutSettings();
GfuiScreenActivate(PrevScrHandle);
onQuit(prevMenu);
}
static void
@ -397,7 +412,19 @@ onPush(void *vi)
static void
onActivate(void * /* dummy */)
{
int cmd;
// Create and test joysticks ; only keep the up and running ones.
for (int jsInd = 0; jsInd < GFCTRL_JOY_NUMBER; jsInd++) {
if (!Joystick[jsInd])
Joystick[jsInd] = new jsJoystick(jsInd);
if (Joystick[jsInd]->notWorking()) {
/* don't configure the joystick */
delete Joystick[jsInd];
Joystick[jsInd] = 0;
} else {
GfOut("Detected joystick #%d type '%s' %d axes\n",
jsInd, Joystick[jsInd]->getName(), Joystick[jsInd]->getNumAxes());
}
}
if (ReloadValues) {
@ -405,7 +432,7 @@ onActivate(void * /* dummy */)
ControlGetSettings();
/* For each control : */
for (cmd = 0; cmd < MaxCmd; cmd++) {
for (int cmd = 0; cmd < MaxCmd; cmd++) {
/* Show / hide control editbox according to selected gear changing mode code */
if (GearChangeMode & CmdDispInfo[cmd].gearChangeModeMask)
@ -436,8 +463,7 @@ DevCalibrate(void *menu)
void *
ControlMenuInit(void *prevMenu, void *prefHdle, unsigned index, tGearChangeMode gearChangeMode)
{
int x, x2, i;
int jsInd;
int x, x2, i;
ReloadValues = 1;
@ -456,23 +482,11 @@ ControlMenuInit(void *prevMenu, void *prefHdle, unsigned index, tGearChangeMode
return ScrHandle;
}
/* Initialize joysticks layer */
for (jsInd = 0; jsInd < GFCTRL_JOY_NUMBER; jsInd++) {
if (Joystick[jsInd] == NULL) {
Joystick[jsInd] = new jsJoystick(jsInd);
}
if (Joystick[jsInd]->notWorking()) {
/* don't configure the joystick */
delete Joystick[jsInd];
Joystick[jsInd] = NULL;
}
else {
GfOut("Detected joystick #%d type '%s' %d axes\n",
jsInd, Joystick[jsInd]->getName(), Joystick[jsInd]->getNumAxes());
}
}
/* Initialize joysticks array */
for (int jsInd = 0; jsInd < GFCTRL_JOY_NUMBER; jsInd++)
Joystick[jsInd] = 0;
/* Create screen */
ScrHandle = GfuiScreenCreateEx((float*)NULL, NULL, onActivate, NULL, (tfuiCallback)NULL, 1);
void *param = LoadMenuXML("controlconfigmenu.xml");
@ -509,8 +523,8 @@ ControlMenuInit(void *prevMenu, void *prefHdle, unsigned index, tGearChangeMode
DeadZoneEditId = CreateEditControl(ScrHandle,param,"Steer Dead Zone Edit",NULL,NULL,onDeadZoneChange);
/* Save button and associated keyboard shortcut */
CreateButtonControl(ScrHandle,param,"save",NULL,onSave);
GfuiAddKey(ScrHandle, 13 /* Return */, "Save", NULL, onSave, NULL);
CreateButtonControl(ScrHandle,param,"save",PrevScrHandle,onSave);
GfuiAddKey(ScrHandle, 13 /* Return */, "Save", PrevScrHandle, onSave, NULL);
/* Mouse calibration screen access button */
MouseCalButton = CreateButtonControl(ScrHandle,param,"mousecalibrate",MouseCalMenuInit(ScrHandle, Cmd, MaxCmd), DevCalibrate);
@ -519,13 +533,15 @@ ControlMenuInit(void *prevMenu, void *prefHdle, unsigned index, tGearChangeMode
JoyCalButton = CreateButtonControl(ScrHandle,param,"joycalibrate",JoyCalMenuInit(ScrHandle, Cmd, MaxCmd), DevCalibrate);
/* Cancel button and associated keyboard shortcut */
GfuiAddKey(ScrHandle, 27 /* Escape */, "Cancel", prevMenu, GfuiScreenActivate, NULL);
CreateButtonControl(ScrHandle,param,"cancel",prevMenu,GfuiScreenActivate);
CreateButtonControl(ScrHandle,param,"cancel",PrevScrHandle,onQuit);
GfuiAddKey(ScrHandle, 27 /* Escape */, "Cancel", PrevScrHandle, onQuit, NULL);
/* General callbacks for keyboard keys and special keys */
GfuiKeyEventRegister(ScrHandle, onKeyAction);
GfuiSKeyEventRegister(ScrHandle, onSKeyAction);
GfParmReleaseHandle(param);
return ScrHandle;
}

View file

@ -1050,7 +1050,9 @@ DriverMenuInit(void *prevMenu)
CreateButtonControl(ScrHandle,param,"accept",NULL, SaveDrvList);
CreateButtonControl(ScrHandle,param,"cancel",NULL, QuitDriverConfig);
/* Keybord shortcuts */
GfParmReleaseHandle(param);
/* Keyboard shortcuts */
GfuiAddKey(ScrHandle, 13 /* Return */, "Save Drivers", NULL, SaveDrvList, NULL);
GfuiAddKey(ScrHandle, 27 /* Escape */, "Cancel Selection", NULL, QuitDriverConfig, NULL);
GfuiAddSKey(ScrHandle, GLUT_KEY_F1, "Help", ScrHandle, GfuiHelpScreen, NULL);

View file

@ -166,6 +166,8 @@ GraphMenuInit(void *prevMenu)
CreateButtonControl(scrHandle, param, "accept", prevMenu, SaveGraphicOptions);
CreateButtonControl(scrHandle, param, "cancel", prevMenu, GfuiScreenActivate);
GfParmReleaseHandle(param);
GfuiAddKey(scrHandle, 13, "Save", prevMenu, SaveGraphicOptions, NULL);
GfuiAddKey(scrHandle, 27, "Cancel", prevMenu, GfuiScreenActivate, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_F1, "Help", scrHandle, GfuiHelpScreen, NULL);

View file

@ -37,10 +37,10 @@ static int maxCmd;
static char buf[1024];
static jsJoystick *js[GFCTRL_JOY_NUMBER] = {NULL};
static float ax[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER] = {0};
static int rawb[GFCTRL_JOY_NUMBER] = {0};
static jsJoystick *Joystick[GFCTRL_JOY_NUMBER];
static float JoyAxis[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
static float JoyAxisCenter[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
static int JoyButtons[GFCTRL_JOY_NUMBER];
#define NB_STEPS 6
@ -70,16 +70,24 @@ static int LabMaxId[4];
static void
onBack(void *prevMenu)
{
int index;
/* Release up and running joysticks */
for (index = 0; index < GFCTRL_JOY_NUMBER; index++)
if (Joystick[index]) {
delete Joystick[index];
Joystick[index] = 0;
}
/* Back to previous screen */
GfuiScreenActivate(prevMenu);
}
static float axCenter[GFCTRL_JOY_MAX_AXES * GFCTRL_JOY_NUMBER];
static void advanceStep (void)
{
do {
CalState++;
} while ((Cmd[CalState + OFFSET_CMD].ref.type != GFCTRL_TYPE_JOY_AXIS) && (CalState < NB_STEPS));
} while (Cmd[CalState + OFFSET_CMD].ref.type != GFCTRL_TYPE_JOY_AXIS && CalState < NB_STEPS);
}
@ -90,24 +98,24 @@ JoyCalAutomaton(void)
switch (CalState) {
case 0:
memcpy(axCenter, ax, sizeof(axCenter));
memcpy(JoyAxisCenter, JoyAxis, sizeof(JoyAxisCenter));
advanceStep();
break;
case 1:
axis = Cmd[CalState + OFFSET_CMD].ref.index;
Cmd[CalState + OFFSET_CMD].min = ax[axis];
Cmd[CalState + OFFSET_CMD].max = axCenter[axis];
Cmd[CalState + OFFSET_CMD].min = JoyAxis[axis];
Cmd[CalState + OFFSET_CMD].max = JoyAxisCenter[axis];
Cmd[CalState + OFFSET_CMD].pow = 1.0;
sprintf(buf, "%.2g", ax[axis]);
sprintf(buf, "%.2g", JoyAxis[axis]);
GfuiLabelSetText(scrHandle2, LabMinId[0], buf);
advanceStep();
break;
case 2:
axis = Cmd[CalState + OFFSET_CMD].ref.index;
Cmd[CalState + OFFSET_CMD].min = axCenter[axis];
Cmd[CalState + OFFSET_CMD].max = ax[axis];
Cmd[CalState + OFFSET_CMD].min = JoyAxisCenter[axis];
Cmd[CalState + OFFSET_CMD].max = JoyAxis[axis];
Cmd[CalState + OFFSET_CMD].pow = 1.0;
sprintf(buf, "%.2g", ax[axis]);
sprintf(buf, "%.2g", JoyAxis[axis]);
GfuiLabelSetText(scrHandle2, LabMaxId[0], buf);
advanceStep();
break;
@ -115,12 +123,12 @@ JoyCalAutomaton(void)
case 4:
case 5:
axis = Cmd[CalState + OFFSET_CMD].ref.index;
Cmd[CalState + OFFSET_CMD].min = axCenter[axis];
Cmd[CalState + OFFSET_CMD].max = ax[axis]*1.1;
Cmd[CalState + OFFSET_CMD].min = JoyAxisCenter[axis];
Cmd[CalState + OFFSET_CMD].max = JoyAxis[axis]*1.1;
Cmd[CalState + OFFSET_CMD].pow = 1.2;
sprintf(buf, "%.2g", axCenter[axis]);
sprintf(buf, "%.2g", JoyAxisCenter[axis]);
GfuiLabelSetText(scrHandle2, LabMinId[CalState - 2], buf);
sprintf(buf, "%.2g", ax[axis]*1.1);
sprintf(buf, "%.2g", JoyAxis[axis]*1.1);
GfuiLabelSetText(scrHandle2, LabMaxId[CalState - 2], buf);
advanceStep();
break;
@ -137,23 +145,23 @@ Idle2(void)
int index;
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
if (js[index]) {
js[index]->read(&b, &ax[index * GFCTRL_JOY_MAX_AXES]);
if (Joystick[index]) {
Joystick[index]->read(&b, &JoyAxis[index * GFCTRL_JOY_MAX_AXES]);
/* Joystick buttons */
for (i = 0, mask = 1; i < 32; i++, mask *= 2) {
if (((b & mask) != 0) && ((rawb[index] & mask) == 0)) {
if (((b & mask) != 0) && ((JoyButtons[index] & mask) == 0)) {
/* Button fired */
JoyCalAutomaton();
if (CalState >= NB_STEPS) {
glutIdleFunc(0);
}
glutPostRedisplay();
rawb[index] = b;
JoyButtons[index] = b;
return;
}
}
rawb[index] = b;
JoyButtons[index] = b;
}
}
@ -169,15 +177,26 @@ onActivate(void * /* dummy */)
int index;
int step;
// Create and test joysticks ; only keep the up and running ones.
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
Joystick[index] = new jsJoystick(index);
if (Joystick[index]->notWorking()) {
/* don't configure the joystick */
delete Joystick[index];
Joystick[index] = 0;
}
}
CalState = 0;
GfuiLabelSetText(scrHandle2, InstId, Instructions[CalState]);
glutIdleFunc(Idle2);
glutPostRedisplay();
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
if (js[index]) {
js[index]->read(&rawb[index], &ax[index * GFCTRL_JOY_MAX_AXES]); /* initial value */
if (Joystick[index]) {
Joystick[index]->read(&JoyButtons[index], &JoyAxis[index * GFCTRL_JOY_MAX_AXES]); /* initial value */
}
}
for (i = 0; i < 4; i++) {
if (i > 0) {
step = i + 2;
@ -207,9 +226,9 @@ JoyCalMenuInit(void *prevMenu, tCmdInfo *cmd, int maxcmd)
return scrHandle2;
}
// Create screen and controls.
scrHandle2 = GfuiScreenCreateEx(NULL, NULL, onActivate, NULL, NULL, 1);
GfuiTitleCreate(scrHandle2, "Joystick Calibration", 0);
GfuiMenuDefaultKeysAdd(scrHandle2);
GfuiScreenAddBgImg(scrHandle2, "data/img/splash-joycal.png");
@ -225,17 +244,6 @@ JoyCalMenuInit(void *prevMenu, tCmdInfo *cmd, int maxcmd)
y -= dy;
}
for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
if (js[index] == NULL) {
js[index] = new jsJoystick(index);
}
if (js[index]->notWorking()) {
/* don't configure the joystick */
js[index] = NULL;
}
}
InstId = GfuiLabelCreate(scrHandle2, Instructions[0], GFUI_FONT_MEDIUM, 320, 80, GFUI_ALIGN_HC_VB, 60);
GfuiButtonCreate(scrHandle2, "Back", GFUI_FONT_LARGE, 160, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP,
@ -244,6 +252,11 @@ JoyCalMenuInit(void *prevMenu, tCmdInfo *cmd, int maxcmd)
GfuiButtonCreate(scrHandle2, "Reset", GFUI_FONT_LARGE, 480, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP,
NULL, onActivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
// Register keyboard shortcuts.
GfuiMenuDefaultKeysAdd(scrHandle2);
GfuiAddKey(scrHandle2, 27, "Back", prevMenu, onBack, NULL);
GfuiAddKey(scrHandle2, 13, "Back", prevMenu, onBack, NULL);
return scrHandle2;
}

View file

@ -175,7 +175,6 @@ MouseCalMenuInit(void *prevMenu, tCmdInfo *cmd, int maxcmd)
scrHandle2 = GfuiScreenCreateEx(NULL, NULL, onActivate2, NULL, NULL, 1);
GfuiTitleCreate(scrHandle2, "Mouse Calibration", 0);
GfuiMenuDefaultKeysAdd(scrHandle2);
GfuiScreenAddBgImg(scrHandle2, "data/img/splash-mousecal.png");
@ -191,5 +190,9 @@ MouseCalMenuInit(void *prevMenu, tCmdInfo *cmd, int maxcmd)
GfuiButtonCreate(scrHandle2, "Reset", GFUI_FONT_LARGE, 480, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP,
NULL, onActivate2, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
GfuiMenuDefaultKeysAdd(scrHandle2);
GfuiAddKey(scrHandle2, 27, "Back", prevMenu, GfuiScreenActivate, NULL);
GfuiAddKey(scrHandle2, 13, "Back", prevMenu, GfuiScreenActivate, NULL);
return scrHandle2;
}

View file

@ -209,6 +209,8 @@ void * OpenGLMenuInit(void *prevMenu)
CreateButtonControl(scrHandle,param,"accept",NULL, saveOpenGLOption);
CreateButtonControl(scrHandle,param,"cancel",prevMenu, GfuiScreenActivate);
GfParmReleaseHandle(param);
GfuiAddKey(scrHandle, 13, "Save", NULL, saveOpenGLOption, NULL);
GfuiAddKey(scrHandle, 27, "Cancel Selection", prevMenu, GfuiScreenActivate, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_F1, "Help", scrHandle, GfuiHelpScreen, NULL);
@ -216,7 +218,5 @@ void * OpenGLMenuInit(void *prevMenu)
GfuiAddSKey(scrHandle, GLUT_KEY_LEFT, "Previous Option in list", (void*)0, changeTextureCompressState, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_RIGHT, "Next Option in list", (void*)1, changeTextureCompressState, NULL);
readOpenGLCfg();
return scrHandle;
}

View file

@ -132,6 +132,8 @@ SimuMenuInit(void *prevMenu)
CreateButtonControl(scrHandle,param,"accept",NULL,SaveSimuVersion);
CreateButtonControl(scrHandle,param,"cancel",prevMenu,GfuiScreenActivate);
GfParmReleaseHandle(param);
GfuiAddKey(scrHandle, 13, "Save", NULL, SaveSimuVersion, NULL);
GfuiAddKey(scrHandle, 27, "Cancel Selection", prevMenu, GfuiScreenActivate, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_F1, "Help", scrHandle, GfuiHelpScreen, NULL);
@ -139,7 +141,5 @@ SimuMenuInit(void *prevMenu)
GfuiAddSKey(scrHandle, GLUT_KEY_LEFT, "Previous Version in list", (void*)0, ChangeSimuVersion, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_RIGHT, "Next Version in list", (void*)1, ChangeSimuVersion, NULL);
ReadSimuCfg();
return scrHandle;
}

View file

@ -70,7 +70,7 @@ static void readSoundCfg(void)
}
}
VolumeValue = GfParmGetNum(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_VOLUME, "%", 100.0f);
VolumeValue = GfParmGetNum(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_VOLUME, "%", 100.0f);
if (VolumeValue>100.0f) {
VolumeValue = 100.0f;
}
@ -118,12 +118,11 @@ static void changeSoundState(void *vp)
GfuiLabelSetText(scrHandle, SoundOptionId, soundOptionList[curOption]);
}
// Volume
/*
/*// Volume
static void changeVolume(void * )
{
char *val;
char buf[1024];
char buf[256];
val = GfuiEditboxGetString(scrHandle, VolumeValueId);
sscanf(val, "%g", &VolumeValue);
sprintf(buf, "%g", VolumeValue);
@ -155,12 +154,12 @@ void * SoundMenuInit(void *prevMenu)
CreateButtonControl(scrHandle,param,"soundleftarrow",(void*)-1,changeSoundState);
CreateButtonControl(scrHandle,param,"soundrightarrow",(void*)1,changeSoundState);
SoundOptionId = CreateLabelControl(scrHandle,param,"soundlabel");
CreateButtonControl(scrHandle,param,"accept",NULL,saveSoundOption);
CreateButtonControl(scrHandle,param,"cancel",prevMenu,GfuiScreenActivate);
GfParmReleaseHandle(param);
GfuiAddKey(scrHandle, 13, "Save", NULL, saveSoundOption, NULL);
GfuiAddKey(scrHandle, 27, "Cancel Selection", prevMenu, GfuiScreenActivate, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_F1, "Help", scrHandle, GfuiHelpScreen, NULL);
@ -168,7 +167,5 @@ void * SoundMenuInit(void *prevMenu)
GfuiAddSKey(scrHandle, GLUT_KEY_LEFT, "Previous Option in list", (void*)0, changeSoundState, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_RIGHT, "Next Option in list", (void*)1, changeSoundState, NULL);
readSoundCfg();
return scrHandle;
}

View file

@ -283,6 +283,8 @@ ReRacemanMenu(void)
CreateButtonControl(racemanMenuHdle,param2,"load",racemanMenuHdle,reLoadMenu);
}
GfParmReleaseHandle(param2);
GfuiMenuDefaultKeysAdd(racemanMenuHdle);
GfuiAddKey(racemanMenuHdle, 27, "Back to Main menu", ReInfo->_reMenuScreen, GfuiScreenActivate, NULL);
@ -319,8 +321,6 @@ ReNewTrackMenu(void)
str = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_NAME, "");
GfuiTitleCreate(newTrackMenuHdle, str, strlen(str));
GfuiMenuDefaultKeysAdd(newTrackMenuHdle);
sprintf(buf, "Race Day #%d/%d on %s",
(int)GfParmGetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_TRACK, NULL, 1),
GfParmGetEltNb(params, RM_SECT_TRACKS),
@ -342,7 +342,8 @@ ReNewTrackMenu(void)
"Abandon", "Abandon The Race",
ReInfo->_reMenuScreen, GfuiScreenActivate);
GfuiAddKey(newTrackMenuHdle, 27, "Abandon", ReInfo->_reMenuScreen, GfuiScreenActivate, NULL);
GfuiMenuDefaultKeysAdd(newTrackMenuHdle);
GfuiAddKey(newTrackMenuHdle, 27, "Abandon", ReInfo->_reMenuScreen, GfuiScreenActivate, NULL);
GfuiScreenActivate(newTrackMenuHdle);

View file

@ -394,6 +394,7 @@ rmRaceResults(void *prevHdle, tRmInfo *info, int start)
GfuiAddKey(rmScrHdle, (unsigned char)27, "", prevHdle, GfuiScreenReplace, NULL);
GfuiAddKey(rmScrHdle, (unsigned char)13, "", prevHdle, GfuiScreenReplace, NULL);
GfuiAddSKey(rmScrHdle, GLUT_KEY_F1, "Help", rmScrHdle, GfuiHelpScreen, NULL);
GfuiAddSKey(rmScrHdle, GLUT_KEY_F12, "Take a Screen Shot", NULL, GfuiScreenShot, NULL);
GfuiScreenActivate(rmScrHdle);

View file

@ -493,7 +493,8 @@ GfuiScreenIsActive(void *screen)
void
GfuiScreenActivate(void *screen)
{
if ((GfuiScreen) && (GfuiScreen->onDeactivate)) GfuiScreen->onDeactivate(GfuiScreen->userDeactData);
if (GfuiScreen && GfuiScreen->onDeactivate)
GfuiScreen->onDeactivate(GfuiScreen->userDeactData);
GfuiScreen = (tGfuiScreen*)screen;
@ -515,7 +516,8 @@ GfuiScreenActivate(void *screen)
glutDisplayFunc(GfuiDisplayNothing);
}
if (GfuiScreen->onActivate) GfuiScreen->onActivate(GfuiScreen->userActData);
if (GfuiScreen->onActivate)
GfuiScreen->onActivate(GfuiScreen->userActData);
if (GfuiScreen->onlyCallback == 0)
{

View file

@ -94,6 +94,7 @@ dispInfo(void *cbinfo)
{
GfuiVisibilitySet(((tMnuCallbackInfo*)cbinfo)->screen, ((tMnuCallbackInfo*)cbinfo)->labelId, 1);
}
static void
remInfo(void *cbinfo)
{
@ -324,7 +325,6 @@ GetHAlignment(std::string strAlignH)
align = 0x20;
}
return align;
}
@ -341,7 +341,7 @@ Color GetColor(unsigned int color)
bool GetColorFromXML(void *param,const char *pControlName,const char *pField,Color &color)
{
std::string strValue = GfParmGetStr(param,pControlName,pField,"");
const std::string strValue = GfParmGetStr(param,pControlName,pField,"");
if (strValue == "")
return false;
@ -355,7 +355,7 @@ bool GetColorFromXML(void *param,const char *pControlName,const char *pField,Col
bool
ReadBoolean(void *param,const char *pControlName,const char *pField)
{
std::string strValue = GfParmGetStr(param, pControlName,pField,"yes");
const std::string strValue = GfParmGetStr(param, pControlName,pField,"yes");
if (strValue == "no")
return false;
@ -365,8 +365,8 @@ ReadBoolean(void *param,const char *pControlName,const char *pField)
bool
GetControlValues(void *param,const char *pControlName,std::string &strText,std::string &strTip,int &x,int &y,int &textSize,int &alignment)
{
std::string strControlName = pControlName;
strControlName = "dynamiccontrols/"+strControlName;
std::string strControlName("dynamiccontrols/");
strControlName += pControlName;
strText = GfParmGetStr(param, strControlName.c_str(), "text", "");
strTip = GfParmGetStr(param, strControlName.c_str(), "tip", "");
@ -387,7 +387,6 @@ int
CreateStaticImage(void *menuHandle,void *param,const char *pControlName)
{
std::string strImage;
//int id;
int x,y,w,h;
strImage = GfParmGetStr(param, pControlName, "image", "");
@ -413,8 +412,8 @@ int
CreateStaticImageControl(void *menuHandle,void *param,const char *pControlName)
{
int labelId;
std::string strControlName = pControlName;
strControlName = "dynamiccontrols/"+strControlName;
std::string strControlName("dynamiccontrols/");
strControlName += pControlName;
labelId = CreateStaticImage(menuHandle,param,strControlName.c_str());
return labelId;
@ -461,8 +460,8 @@ int
CreateLabelControl(void *menuHandle,void *param,const char *pControlName)
{
int labelId;
std::string strControlName = pControlName;
strControlName = "dynamiccontrols/"+strControlName;
std::string strControlName("dynamiccontrols/");
strControlName += pControlName;
labelId = CreateLabel(menuHandle,param,strControlName.c_str());
return labelId;
@ -484,11 +483,10 @@ CreateTextButtonControl(void *menuHandle,void *param,const char *pControlName,vo
textsize = GetFontSize(strTextsize);
std::string strAlignH = GfParmGetStr(param, pControlName, "alignH", "");
int alignH = GetHAlignment(strAlignH);
width = (int)GfParmGetNum(param,pControlName,"width",NULL,0.0);
if (width == 0)
width = GFUI_BTNSZ;
width = GFUI_BTNSZ;
Color c,fc,pc;
bool bColor = GetColorFromXML(param,pControlName,"color",c);
@ -508,64 +506,48 @@ CreateTextButtonControl(void *menuHandle,void *param,const char *pControlName,vo
imgY = (int)GfParmGetNum(param,pControlName,"imagey",NULL,0.0);
imgWidth = (int)GfParmGetNum(param,pControlName,"imagewidth",NULL,20.0);
imgHeight = (int)GfParmGetNum(param,pControlName,"imageheight",NULL,20.0);
tMnuCallbackInfo * cbinfo = NULL;
if (strTip!="")
if (!strTip.empty())
{
cbinfo = (tMnuCallbackInfo*)calloc(1, sizeof(tMnuCallbackInfo));
tMnuCallbackInfo * cbinfo = (tMnuCallbackInfo*)calloc(1, sizeof(tMnuCallbackInfo));
cbinfo->screen = menuHandle;
cbinfo->labelId = GfuiTipCreate(menuHandle, strTip.c_str(), strTip.length());
GfuiVisibilitySet(menuHandle, cbinfo->labelId, 0);
id = GfuiButtonCreate(menuHandle,
strText.c_str(),
textsize,
x, y, width, alignH, GFUI_MOUSE_UP,
userdata, onpush,
(void*)cbinfo, dispInfo,
remInfo);
GfuiButtonShowBox(menuHandle,id,bShowbox);
GfuiButtonSetImage(menuHandle,id,imgX,imgY,imgWidth,imgHeight,
strDisabledImage.c_str(),strEnabledImage.c_str(),strFocusedImage.c_str(),strPushedImage.c_str());
userDataOnFocus = (void*)cbinfo;
onFocus = dispInfo;
onFocusLost = remInfo;
}
else
{
id = GfuiButtonCreate(menuHandle,
strText.c_str(),
textsize,
x, y, width, alignH, GFUI_MOUSE_UP,
userdata, onpush,
userDataOnFocus, onFocus,
onFocusLost);
GfuiButtonShowBox(menuHandle,id,bShowbox);
GfuiButtonSetImage(menuHandle,id,imgX,imgY,imgWidth,imgHeight,
strDisabledImage.c_str(),strEnabledImage.c_str(),strFocusedImage.c_str(),strPushedImage.c_str());
}
id = GfuiButtonCreate(menuHandle,
strText.c_str(),
textsize,
x, y, width, alignH, GFUI_MOUSE_UP,
userdata, onpush,
userDataOnFocus, onFocus,
onFocusLost);
if (bColor)
GfuiButtonSetColor(menuHandle,id,c);
GfuiButtonShowBox(menuHandle,id,bShowbox);
GfuiButtonSetImage(menuHandle,id,imgX,imgY,imgWidth,imgHeight,
strDisabledImage.c_str(),strEnabledImage.c_str(),
strFocusedImage.c_str(),strPushedImage.c_str());
if (bFocusColor)
GfuiButtonSetFocusColor(menuHandle,id,fc);
if (bPushedColor)
GfuiButtonSetPushedColor(menuHandle,id,pc);
if (bColor)
GfuiButtonSetColor(menuHandle,id,c);
if (bFocusColor)
GfuiButtonSetFocusColor(menuHandle,id,fc);
return id;
if (bPushedColor)
GfuiButtonSetPushedColor(menuHandle,id,pc);
return id;
}
int
CreateImageButtonControl(void *menuHandle,void *param,const char *pControlName,void *userdata, tfuiCallback onpush, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
{
std::string strTip,strText;
//int textsize;
int alignment;
int id = -1;
int x,y,w,h;
@ -608,8 +590,8 @@ CreateButtonControl(void *menuHandle,void *param,const char *pControlName,void *
int
CreateButtonControlEx(void *menuHandle,void *param,const char *pControlName,void *userdata, tfuiCallback onpush, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
{
std::string strControlName = pControlName;
strControlName = "dynamiccontrols/"+strControlName;
std::string strControlName("dynamiccontrols/");
strControlName += pControlName;
const std::string strType = GfParmGetStr(param, strControlName.c_str(), "type", "");
if (strType == "textbutton")
@ -617,7 +599,7 @@ CreateButtonControlEx(void *menuHandle,void *param,const char *pControlName,void
else if(strType == "imagebutton")
return CreateImageButtonControl(menuHandle,param,strControlName.c_str(),userdata,onpush,NULL,NULL,NULL);
else
printf("Error: Unknown button type '%s'\n", strType.c_str());
GfError("Error: Unknown button type '%s'\n", strType.c_str());
return -1;
}
@ -625,10 +607,10 @@ CreateButtonControlEx(void *menuHandle,void *param,const char *pControlName,void
int
CreateEditControl(void *menuHandle,void *param,const char *pControlName,void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
{
std::string strControlName = pControlName;
strControlName = "dynamiccontrols/"+strControlName;
std::string strControlName("dynamiccontrols/");
strControlName += pControlName;
std::string strType = GfParmGetStr(param, strControlName.c_str(), "type", "");
const std::string strType = GfParmGetStr(param, strControlName.c_str(), "type", "");
if (strType != "editbox")
return -1;
@ -729,7 +711,7 @@ CreateStaticControls(void *param,void *menuHandle)
for (int i=1;i<=nControls;i++)
{
std::string strType;
char buf[1024];
char buf[32];
sprintf(buf, "staticcontrols/%i",i);
strType = GfParmGetStr(param, buf, "type", "");
@ -747,7 +729,7 @@ CreateStaticControls(void *param,void *menuHandle)
}
else
{
printf("ERROR unknown static control type = %s\n",strType.c_str());
GfError("Errot: Unknown static control type '%s'\n", strType.c_str());
}
}
@ -757,10 +739,10 @@ CreateStaticControls(void *param,void *menuHandle)
void *
LoadMenuXML(const char *pMenuPath)
LoadMenuXML(const char *pszMenuPath)
{
std::string strPath = pMenuPath;
strPath = "data/menu/"+strPath;
std::string strPath("data/menu/");
strPath += pszMenuPath;
void *param = NULL;
char buf[1024];

View file

@ -789,29 +789,26 @@ onActivate(void * /* dummy */)
@param precMenu previous menu to return to
*/
void *
GfScrMenuInit(void *precMenu)
GfScrMenuInit(void *prevMenu)
{
sprintf(buf, "%s%s", GetLocalDir(), GFSCR_CONF_FILE);
paramHdle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
sprintf(buf, "%s%s", GetLocalDir(), GFSCR_CONF_FILE);
paramHdle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
if (scrHandle)
return scrHandle;
if (scrHandle) return scrHandle;
scrHandle = GfuiScreenCreateEx((float*)NULL, NULL, onActivate, NULL, (tfuiCallback)NULL, 1);
void *param = LoadMenuXML("screenconfigmenu.xml");
CreateStaticControls(param,scrHandle);
scrHandle = GfuiScreenCreateEx((float*)NULL, NULL, onActivate, NULL, (tfuiCallback)NULL, 1);
void *param = LoadMenuXML("screenconfigmenu.xml");
CreateStaticControls(param,scrHandle);
CreateButtonControl(scrHandle,param,"resleftarrow",(void*)-1,ResPrevNext);
CreateButtonControl(scrHandle,param,"resrightarrow",(void*)1,ResPrevNext);
ResLabelId = CreateLabelControl(scrHandle,param,"reslabel");
GfuiAddSKey(scrHandle, GLUT_KEY_LEFT, "Previous Resolution", (void*)-1, ResPrevNext, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_RIGHT, "Next Resolution", (void*)1, ResPrevNext, NULL);
GfuiAddKey(scrHandle, 13, "Apply Mode", NULL, GfScrReinit, NULL);
GfuiButtonCreate(scrHandle, "Apply", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP,
NULL, GfScrReinit, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
GfuiAddKey(scrHandle, 27, "Cancel", precMenu, GfuiScreenActivate, NULL);
GfuiButtonCreate(scrHandle, "Back", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP,
precMenu, GfuiScreenActivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
GfuiButtonCreate(scrHandle, "Apply", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP,
NULL, GfScrReinit, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
GfuiButtonCreate(scrHandle, "Back", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP,
prevMenu, GfuiScreenActivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
CreateButtonControl(scrHandle,param,"depthleftarrow",(void*)-1,DepthPrevNext);
CreateButtonControl(scrHandle,param,"depthrightarrow",(void*)1,DepthPrevNext);
@ -829,8 +826,17 @@ GfScrMenuInit(void *precMenu)
CreateButtonControl(scrHandle,param,"vmleftarrow",(void*)-1, VInitPrevNext);
CreateButtonControl(scrHandle,param,"vmrightarrow",(void*)1, VInitPrevNext);
VInitLabelId = CreateLabelControl(scrHandle,param,"vmlabel");
GfParmReleaseHandle(param);
GfuiAddKey(scrHandle, 13, "Apply Mode", NULL, GfScrReinit, NULL);
GfuiAddKey(scrHandle, 27, "Cancel", prevMenu, GfuiScreenActivate, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_LEFT, "Previous Resolution", (void*)-1, ResPrevNext, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_RIGHT, "Next Resolution", (void*)1, ResPrevNext, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_F1, "Help", scrHandle, GfuiHelpScreen, NULL);
GfuiAddSKey(scrHandle, GLUT_KEY_F12, "Screen-Shot", NULL, GfuiScreenShot, NULL);
return scrHandle;
return scrHandle;
}