TORCS  1.3.9
The Open Racing Car Simulator
loadingscreen.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  file : loadingscreen.cpp
4  created : Sun Feb 25 00:34:46 /etc/localtime 2001
5  copyright : (C) 2000-2014 by Eric Espie, Bernhard Wymann
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 <stdlib.h>
27 #ifdef WIN32
28 #include <windows.h>
29 #endif
30 #include <tgfclient.h>
31 #include <car.h>
32 
33 static void *menuHandle = NULL;
34 #define TEXTLINES 23
35 static int rmTextId[TEXTLINES];
36 static char *rmTextLines[TEXTLINES] = {0};
37 static int rmCurText;
38 
39 float black[4] = { 0.0, 0.0, 0.0, 0.0 };
40 float white[TEXTLINES][4];
41 
42 
43 
44 static void rmDeativate(void * /* dummy */)
45 {
46 }
47 
48 
54 void RmLoadingScreenStart(const char *title, const char *bgimg)
55 {
56  int i;
57  int y;
58 
60  /* Already active */
61  return;
62  }
63 
64  if (menuHandle) {
66  }
67  menuHandle = GfuiScreenCreateEx(black, NULL, NULL, NULL, rmDeativate, 0);
68 
69  GfuiTitleCreate(menuHandle, title, strlen(title));
70 
71  /* create TEXTLINES lines of text */
72  for (i = 0, y = 400; i < TEXTLINES; i++, y -= 16) {
73  white[i][0] = white[i][1] = white[i][2] = 1.0;
74  white[i][3] = (float)i * 0.0421 + 0.2;
76  GFUI_ALIGN_HL_VB, 100);
77  if (rmTextLines[i]) {
78  /* free old text */
79  free(rmTextLines[i]);
80  rmTextLines[i] = NULL;
81  }
82  }
83 
84  rmCurText = 0;
85 
86  if (bgimg) {
88  }
89 
91  GfuiDisplay();
92 }
93 
94 
99 {
100  if (menuHandle) {
102  menuHandle = 0;
103  // TODO: release rmTextLines here instead of in RmLoadingScreenStart, or both?
104  }
105 }
106 
107 
112 void RmLoadingScreenSetText(const char *text)
113 {
114  int i, j;
115 
116  GfOut("%s\n", text);
117 
118  if (menuHandle) {
119  if (text) {
120  if (rmTextLines[rmCurText]) {
121  free(rmTextLines[rmCurText]);
122  }
123  rmTextLines[rmCurText] = strdup(text);
124  rmCurText = (rmCurText + 1) % TEXTLINES;
125  }
126 
127  i = rmCurText;
128  j = 0;
129  do {
130  if (rmTextLines[i]) {
132  }
133  j++;
134  i = (i + 1) % TEXTLINES;
135  } while (i != rmCurText);
136 
137  GfuiDisplay();
138  }
139 }
float white[TEXTLINES][4]
float black[4]
static char * rmTextLines[TEXTLINES]
void GfuiDisplay(void)
Display function for the GUI to be called during redisplay of glut.
Definition: gui.cpp:136
void GfuiScreenRelease(void *scr)
Release the given screen.
Definition: gui.cpp:618
void GfuiScreenAddBgImg(void *scr, const char *filename)
Add an image background to a screen.
Definition: gui.cpp:961
#define TEXTLINES
The Gaming Framework API (client part).
void * GfuiScreenCreateEx(float *bgColor, void *userDataOnActivate, tfuiCallback onActivate, void *userDataOnDeactivate, tfuiCallback onDeactivate, int mouseAllowed)
Create a screen.
Definition: gui.cpp:578
static void * menuHandle
void GfuiLabelSetText(void *scr, int id, const char *text)
Change the text of a label.
Definition: guilabel.cpp:212
#define GfOut
Definition: tgf.h:373
int GfuiScreenIsActive(void *screen)
Tell if the screen is active or not.
Definition: gui.cpp:456
static int rmTextId[TEXTLINES]
static int rmCurText
This is the car structure.
void GfuiScreenActivate(void *screen)
Activate a screen and make it current.
Definition: gui.cpp:467
#define GFUI_ALIGN_HL_VB
Definition: tgfclient.h:69
static Vector y[4]
Definition: Convex.cpp:56
int GfuiLabelCreateEx(void *scr, const char *text, float *fgColor, int font, int x, int y, int align, int maxlen)
Create a new label (extended version).
Definition: guilabel.cpp:63
int GfuiTitleCreate(void *scr, const char *text, int maxlen)
Add a Title to the screen.
Definition: guilabel.cpp:170
void RmShutdownLoadingScreen(void)
Shut down loading screen.
void RmLoadingScreenStart(const char *title, const char *bgimg)
Set up loading screen.
#define GFUI_FONT_MEDIUM_C
Definition: tgfclient.h:173
void RmLoadingScreenSetText(const char *text)
Set a new line of text on the loading screen.
static void rmDeativate(void *)