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: loadingscreen.cpp,v 1.2.2.5 2014/05/20 12:20:05 berniw Exp $
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
20 /** @file
21 Loading screen.
22 @author Eric Espie, Bernhard Wymann
23 @version $Id: loadingscreen.cpp,v 1.2.2.5 2014/05/20 12:20:05 berniw Exp $
24 */
25
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
rmDeativate(void *)44 static void rmDeativate(void * /* dummy */)
45 {
46 }
47
48
49 /** @brief Set up loading screen
50 * @ingroup racemantools
51 * @param title Screen title.
52 * @param bgimg Optionnal backgrounf image (NULL for no img).
53 */
RmLoadingScreenStart(const char * title,const char * bgimg)54 void RmLoadingScreenStart(const char *title, const char *bgimg)
55 {
56 int i;
57 int y;
58
59 if (GfuiScreenIsActive(menuHandle)) {
60 /* Already active */
61 return;
62 }
63
64 if (menuHandle) {
65 GfuiScreenRelease(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;
75 rmTextId[i] = GfuiLabelCreateEx(menuHandle, "", white[i], GFUI_FONT_MEDIUM_C, 60, y,
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) {
87 GfuiScreenAddBgImg(menuHandle, bgimg);
88 }
89
90 GfuiScreenActivate(menuHandle);
91 GfuiDisplay();
92 }
93
94
95 /** @brief Shut down loading screen
96 * @ingroup racemantools
97 */
RmShutdownLoadingScreen(void)98 void RmShutdownLoadingScreen(void)
99 {
100 if (menuHandle) {
101 GfuiScreenRelease(menuHandle);
102 menuHandle = 0;
103 // TODO: release rmTextLines here instead of in RmLoadingScreenStart, or both?
104 }
105 }
106
107
108 /** @brief Set a new line of text on the loading screen
109 * @ingroup racemantools
110 * @param[in] text Text to display
111 */
RmLoadingScreenSetText(const char * text)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]) {
131 GfuiLabelSetText(menuHandle, rmTextId[j], rmTextLines[i]);
132 }
133 j++;
134 i = (i + 1) % TEXTLINES;
135 } while (i != rmCurText);
136
137 GfuiDisplay();
138 }
139 }