3
* Copyright (C) 2005 Fabien Chereau
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "loadingbar.h"
22
LoadingBar::LoadingBar(Projector* _prj, float font_size, const string& font_name, const string& splash_tex,
23
int screenw, int screenh, const wstring& extraTextString, float extraTextSize,
24
float extraTextPosx, float extraTextPosy) :
25
prj(_prj), width(512), height(512), barwidth(400), barheight(10), extraText(extraTextString)
27
splashx = prj->getViewportPosX() + (screenw - width)/2;
28
splashy = prj->getViewportPosY() + (screenh - height)/2;
29
barx = prj->getViewportPosX() + (screenw - barwidth)/2;
31
barfont = new s_font(font_size, font_name);
32
extraTextFont = new s_font(extraTextSize, font_name);
34
assert(extraTextFont);
35
if (!splash_tex.empty()) splash = new s_texture(splash_tex, TEX_LOAD_TYPE_PNG_ALPHA);
36
extraTextPos.set(extraTextPosx, extraTextPosy);
39
LoadingBar::~LoadingBar()
43
if (splash) delete splash;
47
void LoadingBar::Draw(float val)
49
// percent complete bar only draws in 2d mode
50
prj->set_orthographic_projection();
52
// Draw the splash screen if available
56
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
57
glEnable(GL_TEXTURE_2D);
59
glDisable(GL_CULL_FACE);
60
glBindTexture(GL_TEXTURE_2D, splash->getID());
63
glTexCoord2i(0, 0); // Bottom Left
64
glVertex3f(splashx, splashy, 0.0f);
65
glTexCoord2i(1, 0); // Bottom Right
66
glVertex3f(splashx + width, splashy, 0.0f);
67
glTexCoord2i(1, 1); // Top Right
68
glVertex3f(splashx + width, splashy + height, 0.0f);
69
glTexCoord2i(0, 1); // Top Left
70
glVertex3f(splashx, splashy + height, 0.0f);
74
glDisable(GL_TEXTURE_2D);
76
// black out background of text for redraws (so can keep sky unaltered)
78
glBegin(GL_TRIANGLE_STRIP);
79
glTexCoord2i(1, 0); // Bottom Right
80
glVertex3f(barx + barwidth, bary-17, 0.0f);
81
glTexCoord2i(0, 0); // Bottom Left
82
glVertex3f(barx, bary-17, 0.0f);
83
glTexCoord2i(1, 1); // Top Right
84
glVertex3f(barx + barwidth, bary-5, 0.0f);
85
glTexCoord2i(0, 1); // Top Left
86
glVertex3f(barx, bary-5, 0.0f);
88
glColor3f(0.8, 0.8, 1);
89
glBegin(GL_TRIANGLE_STRIP);
90
glTexCoord2i(1, 0); // Bottom Right
91
glVertex3f(barx + barwidth, bary + barheight, 0.0f);
92
glTexCoord2i(0, 0); // Bottom Left
93
glVertex3f(barx, bary + barheight, 0.0f);
94
glTexCoord2i(1, 1); // Top Right
95
glVertex3f(barx + barwidth, bary, 0.0f);
96
glTexCoord2i(0, 1); // Top Left
97
glVertex3f(barx, bary, 0.0f);
99
glColor3f(0.4f, 0.4f, 0.6f);
100
glBegin(GL_TRIANGLE_STRIP);
101
glTexCoord2i(1, 0); // Bottom Right
102
glVertex3f(-1 + barx + barwidth * val, bary + barheight - 1, 0.0f);
103
glTexCoord2i(0, 0); // Bottom Left
104
glVertex3f(1 + barx, bary + barheight - 1, 0.0f);
105
glTexCoord2i(1, 1); // Top Right
106
glVertex3f(-1 + barx + barwidth * val, bary + 1, 0.0f);
107
glTexCoord2i(0, 1); // Top Left
108
glVertex3f(1 + barx, bary + 1, 0.0f);
112
glEnable(GL_TEXTURE_2D);
113
barfont->print(barx, bary-5, message);
114
extraTextFont->print(splashx + extraTextPos[0], splashy + extraTextPos[1], extraText);
116
SDL_GL_SwapBuffers(); // And swap the buffers
118
prj->reset_perspective_projection();