TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
simuconfig.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 file : simuconfig.cpp
4 created : Wed Nov 3 21:48:26 CET 2004
5 copyright : (C) 2004 by Eric EspiƩ, Bernhard Wymann
6 email : berniw@bluewin.ch
7
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <tgfclient.h>
26#include <raceinit.h>
27
28#include "simuconfig.h"
29#include <portability.h>
30
31static float LabelColor[] = {1.0, 0.0, 1.0, 1.0};
32
33/* list of available simulation engine */
34static const char *simuVersionList[] = {"simuv2", "simuv3"};
35static const int nbVersions = sizeof(simuVersionList) / sizeof(simuVersionList[0]);
36static int curVersion = 0;
37
38/* gui label id */
39static int SimuVersionId;
40
41/* gui screen handles */
42static void *scrHandle = NULL;
43static void *prevHandle = NULL;
44
45
46static void ReadSimuCfg(void)
47{
48 const char *versionName;
49 int i;
50
51 const int BUFSIZE = 1024;
52 char buf[BUFSIZE];
53 snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), RACE_ENG_CFG);
54
55 void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);
56 versionName = GfParmGetStr(paramHandle, "Modules", "simu", simuVersionList[0]);
57
58 for (i = 0; i < nbVersions; i++) {
59 if (strcmp(versionName, simuVersionList[i]) == 0) {
60 curVersion = i;
61 break;
62 }
63 }
64
65 GfParmReleaseHandle(paramHandle);
66
68}
69
70
71/* Save the choosen values in the corresponding parameter file */
72static void SaveSimuVersion(void)
73{
74 const int BUFSIZE = 1024;
75 char buf[BUFSIZE];
76 snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), RACE_ENG_CFG);
77
78 void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);
79 GfParmSetStr(paramHandle, "Modules", "simu", simuVersionList[curVersion]);
80 GfParmWriteFile(NULL, paramHandle, "raceengine");
81 GfParmReleaseHandle(paramHandle);
82
83 /* return to previous screen */
85 return;
86}
87
88/* change the simulation version */
89static void
91{
92 if (delta < 0) {
93 curVersion--;
94 if (curVersion < 0) {
96 }
97 } else {
98 curVersion++;
99 if (curVersion == nbVersions) {
100 curVersion = 0;
101 }
102 }
104}
105
106
107static void onActivate(void)
108{
109 ReadSimuCfg();
110}
111
112
113/* Menu creation */
114void *
115SimuMenuInit(void *prevMenu)
116{
117 int x, y, x2, x3, x4, dy;
118
119 /* screen already created */
120 if (scrHandle) {
121 return scrHandle;
122 }
123 prevHandle = prevMenu;
124
126 GfuiTitleCreate(scrHandle, "Simulation Configuration", 0);
127 GfuiScreenAddBgImg(scrHandle, "data/img/splash-simucfg.png");
128
129 x = 20;
130 x2 = 240;
131 x3 = x2 + 100;
132 x4 = x2 + 200;
133 y = 370;
134 dy = 30;
135
136 y -= dy;
137 GfuiLabelCreate(scrHandle, "Simulation version:", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0);
138 GfuiGrButtonCreateAction(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png",
139 "data/img/arrow-left.png", "data/img/arrow-left-pushed.png",
140 x2, y, GFUI_ALIGN_HL_VB, 1,
141 [] { ChangeSimuVersion(-1); }, tGfuiAction(), tGfuiAction());
142 GfuiGrButtonCreateAction(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png",
143 "data/img/arrow-right.png", "data/img/arrow-right-pushed.png",
144 x4, y, GFUI_ALIGN_HR_VB, 1,
145 [] { ChangeSimuVersion(1); }, tGfuiAction(), tGfuiAction());
148
151
153 [prevMenu] { GfuiScreenActivate(prevMenu); }, tGfuiAction(), tGfuiAction());
154
156 GfuiAddKeyAction(scrHandle, 27, "Cancel Selection", [prevMenu] { GfuiScreenActivate(prevMenu); }, tGfuiAction());
157 GfuiAddSKeyAction(scrHandle, GLUT_KEY_F12, "Screen-Shot", [] { GfuiScreenShot(NULL); }, tGfuiAction());
158 GfuiAddSKeyAction(scrHandle, GLUT_KEY_LEFT, "Previous Version in list", [] { ChangeSimuVersion(-1); }, tGfuiAction());
159 GfuiAddSKeyAction(scrHandle, GLUT_KEY_RIGHT, "Next Version in list", [] { ChangeSimuVersion(1); }, tGfuiAction());
160
161 ReadSimuCfg();
162
163 return scrHandle;
164}
static Vector y[4]
Definition Convex.cpp:56
static void * prevHandle
static void * scrHandle
static void onActivate(void)
static float LabelColor[]
void * GfuiScreenCreateExAction(float *bgColor, const tGfuiAction &onActivate, const tGfuiAction &onDeactivate, int mouseAllowed)
Create a screen.
Definition gui.cpp:619
void GfuiLabelSetText(void *scr, int id, const char *text)
Change the text of a label.
Definition guilabel.cpp:193
int GfuiTitleCreate(void *scr, const char *text, int maxlen)
Add a Title to the screen.
Definition guilabel.cpp:150
void GfuiAddKeyAction(void *scr, unsigned char key, const char *descr, const tGfuiAction &onKeyPressed, const tGfuiAction &onKeyReleased)
Add a Keyboard callback to a screen.
Definition gui.cpp:809
void GfuiScreenAddBgImg(void *scr, const char *filename)
Add an image background to a screen.
Definition gui.cpp:1058
void GfuiAddSKeyAction(void *scr, int key, const char *descr, const tGfuiAction &onKeyPressed, const tGfuiAction &onKeyReleased)
Add a Special Keyboard shortcut to the screen.
Definition gui.cpp:895
int GfuiLabelCreate(void *scr, const char *text, int font, int x, int y, int align, int maxlen)
Add a label to a screen.
Definition guilabel.cpp:121
void GfuiLabelSetColor(void *scr, int id, float *color)
Change the color of a label.
Definition guilabel.cpp:221
int GfuiGrButtonCreateAction(void *scr, const char *disabled, const char *enabled, const char *focused, const char *pushed, int x, int y, int align, int mouse, const tGfuiAction &onPush, const tGfuiAction &onFocus, const tGfuiAction &onFocusLost)
Add a graphical button to a screen.
Definition guibutton.cpp:58
void GfuiScreenActivate(void *screen)
Activate a screen and make it current.
Definition gui.cpp:508
int GfuiButtonCreateAction(void *scr, const char *text, int font, int x, int y, int width, int align, int mouse, const tGfuiAction &onPush, const tGfuiAction &onFocus, const tGfuiAction &onFocusLost)
Add a button to a screen.
const char * GfParmGetStr(void *parmHandle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
Definition params.cpp:2453
int GfParmSetStr(void *handle, const char *path, const char *key, const char *val)
Set a string parameter in the parameter set handle.
Definition params.cpp:2623
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
Definition params.cpp:1963
int GfParmWriteFile(const char *file, void *parmHandle, const char *name)
Write parameter set into file.
Definition params.cpp:1732
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
Definition params.cpp:1173
void GfuiScreenShot(void *)
Save a screen shot in png format.
Definition gui.cpp:998
#define RACE_ENG_CFG
Definition raceinit.h:29
void * SimuMenuInit(void *prevMenu)
static int SimuVersionId
static const int nbVersions
static void ChangeSimuVersion(int delta)
static void SaveSimuVersion(void)
static void ReadSimuCfg(void)
static int curVersion
static void onActivate(void)
static const char * simuVersionList[]
char * GetLocalDir(void)
Definition tgf.cpp:230
#define GFPARM_RMODE_CREAT
Allow an empty in-memory set on file-open failure; does not write a file.
Definition tgf.h:266
#define GFPARM_RMODE_REREAD
Clear shared cached data and reread the file.
Definition tgf.h:265
#define GFUI_FONT_LARGE
Definition tgfclient.h:248
#define GFUI_FONT_MEDIUM
Definition tgfclient.h:249
#define GFUI_FONT_MEDIUM_C
Definition tgfclient.h:253
#define GFUI_ALIGN_HL_VB
Definition tgfclient.h:71
#define GFUI_MOUSE_UP
Definition tgfclient.h:82
std::function< void()> tGfuiAction
Definition tgfclient.h:107
#define GFUI_ALIGN_HR_VB
Definition tgfclient.h:77
#define GFUI_ALIGN_HC_VB
Definition tgfclient.h:74