Debian Codegraph @

prboom2/src/gl_progress.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2000 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 *
31 *---------------------------------------------------------------------
32 */
33
34 #include "gl_opengl.h"
35
36 #include <SDL.h>
37
38 #include "gl_intern.h"
39 #include "i_video.h"
40 #include "hu_lib.h"
41 #include "hu_stuff.h"
42
43 #include "dsda/font.h"
44 #include "dsda/utility.h"
45
46 static GLuint progress_texid = 0;
47 static unsigned int lastupdate = 0;
48
49 int gld_ProgressStart(void)
50 {
51 if (!progress_texid)
52 {
53 progress_texid = CaptureScreenAsTexID();
54 lastupdate = SDL_GetTicks() - 100;
55 return true;
56 }
57
58 return false;
59 }
60
61 int gld_ProgressRestoreScreen(void)
62 {
63 int total_w, total_h;
64 float fU1, fU2, fV1, fV2;
65
66 if (progress_texid)
67 {
68 total_w = gld_GetTexDimension(SCREENWIDTH);
69 total_h = gld_GetTexDimension(SCREENHEIGHT);
70
71 fU1 = 0.0f;
72 fV1 = (float)SCREENHEIGHT / (float)total_h;
73 fU2 = (float)SCREENWIDTH / (float)total_w;
74 fV2 = 0.0f;
75
76 gld_EnableTexture2D(GL_TEXTURE0_ARB, true);
77
78 glBindTexture(GL_TEXTURE_2D, progress_texid);
79 glColor3f(1.0f, 1.0f, 1.0f);
80
81 glBegin(GL_TRIANGLE_STRIP);
82 {
83 glTexCoord2f(fU1, fV1); glVertex2f(0.0f, 0.0f);
84 glTexCoord2f(fU1, fV2); glVertex2f(0.0f, (float)SCREENHEIGHT);
85 glTexCoord2f(fU2, fV1); glVertex2f((float)SCREENWIDTH, 0.0f);
86 glTexCoord2f(fU2, fV2); glVertex2f((float)SCREENWIDTH, (float)SCREENHEIGHT);
87 }
88 glEnd();
89
90 return true;
91 }
92
93 return false;
94 }
95
96 int gld_ProgressEnd(void)
97 {
98 if (progress_texid != 0)
99 {
100 gld_ProgressRestoreScreen();
101 I_FinishUpdate();
102 gld_ProgressRestoreScreen();
103 glDeleteTextures(1, &progress_texid);
104 progress_texid = 0;
105 return true;
106 }
107
108 return false;
109 }
110
111 static hu_textline_t w_precache;
112
113 static void gld_InitProgressUpdate(void)
114 {
115 HUlib_initTextLine
116 (
117 &w_precache,
118 16,
119 186,
120 &hud_font,
121 CR_DEFAULT,
122 VPT_ALIGN_LEFT_BOTTOM
123 );
124 }
125
126 void gld_ProgressUpdate(const char * text, int progress, int total)
127 {
128 int len;
129 static char last_text[32] = {0};
130 unsigned int tic;
131
132 if (!progress_texid)
133 return;
134
135 // do not do it often
136 tic = SDL_GetTicks();
137 if (tic - lastupdate < 100)
138 return;
139 lastupdate = tic;
140
141 DO_ONCE
142 gld_InitProgressUpdate();
143 END_ONCE
144
145 if (text && *text && strcmp(last_text, text))
146 {
147 const char *s;
148 strcpy(last_text, text);
149
150 HUlib_clearTextLine(&w_precache);
151 s = text;
152 while (*s)
153 HUlib_addCharToTextLine(&w_precache, *(s++));
154 HUlib_setTextXCenter(&w_precache);
155 }
156
157 gld_ProgressRestoreScreen();
158 HUlib_drawTextLine(&w_precache, false);
159
160 len = MIN(SCREENWIDTH, (int)((int64_t)SCREENWIDTH * progress / total));
161 V_FillRect(0, 0, SCREENHEIGHT - 4, len - 0, 4, 4);
162 if (len > 4)
163 {
164 V_FillRect(0, 2, SCREENHEIGHT - 3, len - 4, 2, 31);
165 }
166
167 I_FinishUpdate();
168 }