TORCS  1.3.9
The Open Racing Car Simulator
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 by Eric Espie
6  email : eric.espie@torcs.org
7  version : $Id$
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <tgfclient.h>
29 #include <graphic.h>
30 #include <portability.h>
31 
32 #include "graphconfig.h"
33 
34 static void *scrHandle = NULL;
35 static int FovEditId;
36 static int FovFactorValue = 100;
37 static int SmokeEditId;
38 static int SmokeValue = 300;
39 static int SkidEditId;
40 static int SkidValue = 20;
41 static int LodFactorEditId;
42 static tdble LodFactorValue = 1.0;
43 
44 // Wheel detail.
45 static const char *wheelDetailOptionList[] = {
48 };
49 
50 static float LabelColor[] = {1.0, 0.0, 1.0, 1.0};
51 static const int nbOptionsWheelDetail = sizeof(wheelDetailOptionList) / sizeof(wheelDetailOptionList[0]);
52 static int curOptionWheelDetail = 0;
54 
55 
56 
57 
58 static void ExitGraphicOptions(void *prevMenu)
59 {
60  GfuiScreenActivate(prevMenu);
61 }
62 
63 
64 
65 
66 static void SaveGraphicOptions(void *prevMenu)
67 {
68  const int BUFSIZE = 1024;
69  char buf[BUFSIZE];
70 
71  snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), GR_PARAM_FILE);
73 
79 
80  GfParmWriteFile(NULL, grHandle, "graph");
82  ExitGraphicOptions(prevMenu);
83 }
84 
85 
86 
87 
88 static void ChangeFov(void * /* dummy */)
89 {
90  char *val;
91  const int BUFSIZE = 1024;
92  char buf[BUFSIZE];
93 
95  FovFactorValue = strtol(val, (char **)NULL, 0);
96  snprintf(buf, BUFSIZE, "%d", FovFactorValue);
98 }
99 
100 
101 
102 
103 static void ChangeLodFactor(void * /* dummy */)
104 {
105  char *val;
106  const int BUFSIZE = 1024;
107  char buf[BUFSIZE];
108 
110  sscanf(val, "%g", &LodFactorValue);
111  snprintf(buf, BUFSIZE, "%g", LodFactorValue);
113 }
114 
115 
116 
117 
118 static void ChangeSmoke(void * /* dummy */)
119 {
120  char *val;
121  const int BUFSIZE = 1024;
122  char buf[BUFSIZE];
123 
125  SmokeValue = strtol(val, (char **)NULL, 0);
126  snprintf(buf, BUFSIZE, "%d", SmokeValue);
128 }
129 
130 
131 
132 
133 static void ChangeSkid(void * /* dummy */)
134 {
135  char *val;
136  const int BUFSIZE = 1024;
137  char buf[BUFSIZE];
138 
140  SkidValue = strtol(val, (char **)NULL, 0);
141  snprintf(buf, BUFSIZE, "%d", SkidValue);
143 }
144 
145 
146 
147 
148 static void changeWheelDetailState(void *vp)
149 {
150  if (vp == 0) {
152  if (curOptionWheelDetail < 0) {
154  }
155  } else {
159  }
160  }
162 }
163 
164 
165 
166 
167 void *GraphMenuInit(void *prevMenu)
168 {
169  const int x = 50;
170  int y = 370;
171  const int x2 = 220;
172  const int dy = 30;
173  const int width = 130;
174  const int center = x2 + width/2;
175 
176  /* screen already created */
177  if (scrHandle) {
178  return scrHandle;
179  }
180 
181  const int BUFSIZE = 1024;
182  char buf[BUFSIZE];
183 
184  scrHandle = GfuiMenuScreenCreate("Graphic Configuration");
185 
186  GfuiScreenAddBgImg(scrHandle, "data/img/splash-graphconf.png");
187 
188  snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), GR_PARAM_FILE);
190 
191  GfuiLabelCreate(scrHandle, "Visibility (%):", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0);
193  snprintf(buf, BUFSIZE, "%d", FovFactorValue);
195  x2+10, y, width-20, 16, NULL, (tfuiCallback)NULL, ChangeFov);
196 
197  y -= dy;
200  snprintf(buf, BUFSIZE, "%d", SmokeValue);
202  x2+10, y, width-20, 16, NULL, (tfuiCallback)NULL, ChangeSmoke);
203 
204  y -= dy;
207  snprintf(buf, BUFSIZE, "%d", SkidValue);
209  x2+10, y, width-20, 16, NULL, (tfuiCallback)NULL, ChangeSkid);
210 
211  y -= dy;
214  snprintf(buf, BUFSIZE, "%g", LodFactorValue);
216  x2+10, y, width-20, 16, NULL, (tfuiCallback)NULL, ChangeLodFactor);
217 
218 
219  // Wheel detail option
220  y -= dy;
221  GfuiLabelCreate(scrHandle, "Wheel rendering:", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0);
222 
223  GfuiGrButtonCreate(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png",
224  "data/img/arrow-left.png", "data/img/arrow-left-pushed.png",
225  x2, y-5, GFUI_ALIGN_HL_VB, 1,
226  (void*)-1, changeWheelDetailState,
227  NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
228 
229  GfuiGrButtonCreate(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png",
230  "data/img/arrow-right.png", "data/img/arrow-right-pushed.png",
231  x2+width, y-5, GFUI_ALIGN_HR_VB, 1,
232  (void*)1, changeWheelDetailState,
233  NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
234 
235  // Read wheel detail parameter.
236  int i;
238  for (i = 0; i < nbOptionsWheelDetail; i++) {
239  if (strcmp(optionName, wheelDetailOptionList[i]) == 0) {
241  break;
242  }
243  }
244 
247 
248  // Navigation
250  prevMenu, SaveGraphicOptions, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
251 
253  prevMenu, GfuiScreenActivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
254 
255  GfuiAddKey(scrHandle, 27, "Cancel", prevMenu, GfuiScreenActivate, NULL);
256 
258 
259  return scrHandle;
260 }
#define GR_ATT_MAXSTRIPBYWHEEL
Definition: graphic.h:87
static int FovFactorValue
Definition: graphconfig.cpp:36
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:2477
char * GfuiEditboxGetString(void *scr, int id)
Get the string.
Definition: guiedit.cpp:358
#define GR_ATT_WHEELRENDERING_DETAILED
Definition: graphic.h:58
#define GFUI_MOUSE_UP
Definition: tgfclient.h:80
static tdble LodFactorValue
Definition: graphconfig.cpp:42
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
Definition: params.cpp:1157
int GfuiButtonCreate(void *scr, const char *text, int font, int x, int y, int width, int align, int mouse, void *userDataOnPush, tfuiCallback onPush, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
Add a button to a screen.
Definition: guibutton.cpp:248
#define GFPARM_RMODE_STD
if handle already openned return it
Definition: tgf.h:265
static int WheelDetailOptionId
Definition: graphconfig.cpp:53
static void SaveGraphicOptions(void *prevMenu)
Definition: graphconfig.cpp:66
#define GR_ATT_FOVFACT
Definition: graphic.h:90
char * GetLocalDir(void)
Definition: tgf.cpp:231
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
Definition: params.cpp:1834
void GfuiAddKey(void *scr, unsigned char key, const char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased)
Add a Keyboard callback to a screen.
Definition: gui.cpp:742
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:142
void * GfuiMenuScreenCreate(const char *title)
Create a new menu screen.
Definition: guimenu.cpp:76
static void * scrHandle
Definition: graphconfig.cpp:34
static const int nbOptionsWheelDetail
Definition: graphconfig.cpp:51
int GfuiEditboxCreate(void *scr, const char *text, int font, int x, int y, int width, int maxlen, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost, int margin)
Add a editbox to a screen.
Definition: guiedit.cpp:57
static int curOptionWheelDetail
Definition: graphconfig.cpp:52
void GfuiScreenAddBgImg(void *scr, const char *filename)
Add an image background to a screen.
Definition: gui.cpp:961
void * GraphMenuInit(void *prevMenu)
int GfParmWriteFile(const char *file, void *parmHandle, const char *name)
Write parameter set into file.
Definition: params.cpp:1610
#define GFUI_ALIGN_HR_VB
Definition: tgfclient.h:75
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:2311
The Gaming Framework API (client part).
#define GR_ATT_WHEELRENDERING_SIMPLE
Definition: graphic.h:59
#define GFUI_FONT_LARGE
Definition: tgfclient.h:168
static int FovEditId
Definition: graphconfig.cpp:35
static int SmokeEditId
Definition: graphconfig.cpp:37
#define GR_ATT_SMOKENB
Definition: graphic.h:83
void GfuiEditboxSetString(void *scr, int id, const char *text)
Set a new string.
Definition: guiedit.cpp:383
static void ChangeSmoke(void *)
void GfuiLabelSetText(void *scr, int id, const char *text)
Change the text of a label.
Definition: guilabel.cpp:212
float tdble
Floating point type used in TORCS.
Definition: tgf.h:48
static void ChangeSkid(void *)
#define GR_ATT_WHEELRENDERING
Definition: graphic.h:57
static int LodFactorEditId
Definition: graphconfig.cpp:41
static void ChangeFov(void *)
Definition: graphconfig.cpp:88
void GfuiLabelSetColor(void *scr, int id, float *color)
Change the color of a label.
Definition: guilabel.cpp:239
static int SmokeValue
Definition: graphconfig.cpp:38
Graphic Module Interface Definition.
static void changeWheelDetailState(void *vp)
#define GR_SCT_GRAPHIC
Definition: graphic.h:82
static void ChangeLodFactor(void *)
void(* tfuiCallback)(void *)
Definition: tgfclient.h:105
void GfuiScreenActivate(void *screen)
Activate a screen and make it current.
Definition: gui.cpp:467
#define GR_PARAM_FILE
Definition: graphic.h:42
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:2586
#define GFUI_ALIGN_HC_VB
Definition: tgfclient.h:72
static float LabelColor[]
Definition: graphconfig.cpp:50
#define GFUI_ALIGN_HL_VB
Definition: tgfclient.h:69
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:2392
static Vector y[4]
Definition: Convex.cpp:56
int GfuiGrButtonCreate(void *scr, const char *disabled, const char *enabled, const char *focused, const char *pushed, int x, int y, int align, int mouse, void *userDataOnPush, tfuiCallback onPush, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
Add a graphical button to a screen.
Definition: guibutton.cpp:62
#define GFUI_FONT_MEDIUM_C
Definition: tgfclient.h:173
static int SkidEditId
Definition: graphconfig.cpp:39
static void ExitGraphicOptions(void *prevMenu)
Definition: graphconfig.cpp:58
void * grHandle
Definition: grmain.cpp:59
#define GFUI_FONT_MEDIUM
Definition: tgfclient.h:169
static const char * wheelDetailOptionList[]
Definition: graphconfig.cpp:45
#define GR_ATT_LODFACTOR
Definition: graphic.h:91
#define GFPARM_RMODE_CREAT
Create the file if doesn&#39;t exist.
Definition: tgf.h:267
static int SkidValue
Definition: graphconfig.cpp:40