TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
graphconfig.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 file : graphconfig.cpp
4 created : Sun Jun 9 16:30:25 CEST 2002
5 copyright : (C) 2001-2026 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
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <tgfclient.h>
28#include <graphic.h>
29#include <portability.h>
30
31#include "graphconfig.h"
32
33static void *scrHandle = NULL;
34static int FovEditId;
35static int FovFactorValue = 100;
36static int SmokeEditId;
37static int SmokeValue = 300;
38static int SkidEditId;
39static int SkidValue = 20;
40static int LodFactorEditId;
41static tdble LodFactorValue = 1.0;
42
43// Wheel detail.
48
49static float LabelColor[] = {1.0, 0.0, 1.0, 1.0};
51static int curOptionWheelDetail = 0;
53
54
55
56
57static void ExitGraphicOptions(void *prevMenu)
58{
59 GfuiScreenActivate(prevMenu);
60}
61
62
63
64
83
84
85
86
87static void ChangeFov(void)
88{
89 char *val;
90 const int BUFSIZE = 1024;
91 char buf[BUFSIZE];
92
94 FovFactorValue = strtol(val, (char **)NULL, 0);
95 snprintf(buf, BUFSIZE, "%d", FovFactorValue);
97}
98
99
100
101
102static void ChangeLodFactor(void)
103{
104 char *val;
105 const int BUFSIZE = 1024;
106 char buf[BUFSIZE];
107
109 sscanf(val, "%g", &LodFactorValue);
110 snprintf(buf, BUFSIZE, "%g", LodFactorValue);
112}
113
114
115
116
117static void ChangeSmoke(void)
118{
119 char *val;
120 const int BUFSIZE = 1024;
121 char buf[BUFSIZE];
122
124 SmokeValue = strtol(val, (char **)NULL, 0);
125 snprintf(buf, BUFSIZE, "%d", SmokeValue);
127}
128
129
130
131
132static void ChangeSkid(void)
133{
134 char *val;
135 const int BUFSIZE = 1024;
136 char buf[BUFSIZE];
137
139 SkidValue = strtol(val, (char **)NULL, 0);
140 snprintf(buf, BUFSIZE, "%d", SkidValue);
142}
143
144
145
146
162
163
164
165
166void *GraphMenuInit(void *prevMenu)
167{
168 const int x = 50;
169 int y = 370;
170 const int x2 = 220;
171 const int dy = 30;
172 const int width = 130;
173 const int center = x2 + width/2;
174
175 /* screen already created */
176 if (scrHandle) {
177 return scrHandle;
178 }
179
180 const int BUFSIZE = 1024;
181 char buf[BUFSIZE];
182
183 scrHandle = GfuiMenuScreenCreate("Graphic Configuration");
184
185 GfuiScreenAddBgImg(scrHandle, "data/img/splash-graphconf.png");
186
187 snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), GR_PARAM_FILE);
189
190 GfuiLabelCreate(scrHandle, "Visibility (%):", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0);
192 snprintf(buf, BUFSIZE, "%d", FovFactorValue);
194 x2+10, y, width-20, 16, tGfuiAction(), ChangeFov);
195
196 y -= dy;
199 snprintf(buf, BUFSIZE, "%d", SmokeValue);
201 x2+10, y, width-20, 16, tGfuiAction(), ChangeSmoke);
202
203 y -= dy;
206 snprintf(buf, BUFSIZE, "%d", SkidValue);
208 x2+10, y, width-20, 16, tGfuiAction(), ChangeSkid);
209
210 y -= dy;
213 snprintf(buf, BUFSIZE, "%g", LodFactorValue);
215 x2+10, y, width-20, 16, tGfuiAction(), ChangeLodFactor);
216
217
218 // Wheel detail option
219 y -= dy;
220 GfuiLabelCreate(scrHandle, "Wheel rendering:", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0);
221
222 GfuiGrButtonCreateAction(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png",
223 "data/img/arrow-left.png", "data/img/arrow-left-pushed.png",
224 x2, y-5, GFUI_ALIGN_HL_VB, 1,
226
227 GfuiGrButtonCreateAction(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png",
228 "data/img/arrow-right.png", "data/img/arrow-right-pushed.png",
229 x2+width, y-5, GFUI_ALIGN_HR_VB, 1,
231
232 // Read wheel detail parameter.
233 int i;
235 for (i = 0; i < nbOptionsWheelDetail; i++) {
236 if (strcmp(optionName, wheelDetailOptionList[i]) == 0) {
238 break;
239 }
240 }
241
244
245 // Navigation
247 [prevMenu] { SaveGraphicOptions(prevMenu); }, tGfuiAction(), tGfuiAction());
248
250 [prevMenu] { GfuiScreenActivate(prevMenu); }, tGfuiAction(), tGfuiAction());
251
252 GfuiAddKeyAction(scrHandle, 27, "Cancel", [prevMenu] { GfuiScreenActivate(prevMenu); }, tGfuiAction());
253
255
256 return scrHandle;
257}
static Vector y[4]
Definition Convex.cpp:56
static void * scrHandle
static float LabelColor[]
static void ChangeSkid(void)
static int SmokeEditId
static int FovFactorValue
static const char * wheelDetailOptionList[]
static void ChangeFov(void)
static int SkidEditId
static int SmokeValue
static int FovEditId
static void ChangeLodFactor(void)
static void ChangeSmoke(void)
static int curOptionWheelDetail
static const int nbOptionsWheelDetail
static void ExitGraphicOptions(void *prevMenu)
static int SkidValue
static int WheelDetailOptionId
static tdble LodFactorValue
static int LodFactorEditId
static void SaveGraphicOptions(void *prevMenu)
static void changeWheelDetailState(int delta)
void * GraphMenuInit(void *prevMenu)
#define GR_ATT_WHEELRENDERING_DETAILED
Definition graphic.h:58
#define GR_ATT_SMOKENB
Definition graphic.h:83
#define GR_ATT_WHEELRENDERING
Definition graphic.h:57
#define GR_ATT_WHEELRENDERING_SIMPLE
Definition graphic.h:59
#define GR_SCT_GRAPHIC
Definition graphic.h:82
#define GR_ATT_LODFACTOR
Definition graphic.h:91
#define GR_ATT_MAXSTRIPBYWHEEL
Definition graphic.h:87
#define GR_ATT_FOVFACT
Definition graphic.h:90
#define GR_PARAM_FILE
Definition graphic.h:40
void * grHandle
Definition grmain.cpp:58
float tdble
Floating point type used in TORCS.
Definition tgf.h:47
void GfuiLabelSetText(void *scr, int id, const char *text)
Change the text of a label.
Definition guilabel.cpp:193
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
int GfuiEditboxCreateAction(void *scr, const char *text, int font, int x, int y, int width, int maxlen, const tGfuiAction &onFocus, const tGfuiAction &onFocusLost, int margin)
Add an edit box to a screen.
Definition guiedit.cpp:53
void * GfuiMenuScreenCreate(const char *title)
Create a new menu screen.
Definition guimenu.cpp:77
void GfuiEditboxSetString(void *scr, int id, const char *text)
Set a new string.
Definition guiedit.cpp:390
char * GfuiEditboxGetString(void *scr, int id)
Get the current text of an edit box.
Definition guiedit.cpp:364
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
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
Definition params.cpp:2534
int GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
Set a numerical parameter in the parameter set handle.
Definition params.cpp:2737
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
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_STD
Return a new handle sharing cached data for this filename, if available.
Definition tgf.h:264
#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