~ubuntu-branches/ubuntu/precise/stellarium/precise

« back to all changes in this revision

Viewing changes to src/loadingbar.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2008-05-19 21:28:23 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080519212823-m5nfiuntxstxzxj7
Tags: 0.9.1-4
Add libxcursor-dev, libxfixes-dev, libxinerama-dev, libqt4-opengl-dev to
build-deps (Closes: #479906)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Stellarium
3
 
 * Copyright (C) 2005 Fabien Chereau
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
18
 
 */
19
 
 
20
 
#include "loadingbar.h"
21
 
 
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)
26
 
{
27
 
        splashx = prj->getViewportPosX() + (screenw - width)/2;
28
 
        splashy = prj->getViewportPosY() + (screenh - height)/2;
29
 
        barx = prj->getViewportPosX() + (screenw - barwidth)/2;
30
 
        bary = splashy + 34;
31
 
        barfont = new s_font(font_size, font_name);
32
 
        extraTextFont = new s_font(extraTextSize, font_name);
33
 
        assert(barfont);
34
 
        assert(extraTextFont);
35
 
        if (!splash_tex.empty()) splash = new s_texture(splash_tex, TEX_LOAD_TYPE_PNG_ALPHA);
36
 
        extraTextPos.set(extraTextPosx, extraTextPosy);
37
 
}
38
 
        
39
 
LoadingBar::~LoadingBar()
40
 
{
41
 
        delete barfont;
42
 
        delete extraTextFont;
43
 
        if (splash) delete splash;
44
 
        barfont = NULL;
45
 
}
46
 
 
47
 
void LoadingBar::Draw(float val)
48
 
{
49
 
        // percent complete bar only draws in 2d mode
50
 
        prj->set_orthographic_projection();
51
 
  
52
 
        // Draw the splash screen if available
53
 
        if (splash)
54
 
        {
55
 
                glEnable(GL_BLEND);
56
 
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
57
 
                glEnable(GL_TEXTURE_2D);
58
 
                glColor3f(1, 1, 1);
59
 
                glDisable(GL_CULL_FACE);
60
 
                glBindTexture(GL_TEXTURE_2D, splash->getID());
61
 
 
62
 
                glBegin(GL_QUADS);
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);
71
 
                glEnd();
72
 
        }
73
 
        glDisable(GL_BLEND);
74
 
        glDisable(GL_TEXTURE_2D);
75
 
 
76
 
        // black out background of text for redraws (so can keep sky unaltered)
77
 
        glColor3f(0, 0, 0);
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);
87
 
        glEnd();
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);
98
 
        glEnd();
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);
109
 
        glEnd();
110
 
        
111
 
        glColor3f(1, 1, 1);
112
 
        glEnable(GL_TEXTURE_2D);
113
 
        barfont->print(barx, bary-5, message);
114
 
        extraTextFont->print(splashx + extraTextPos[0], splashy + extraTextPos[1], extraText);
115
 
        
116
 
        SDL_GL_SwapBuffers();   // And swap the buffers
117
 
        
118
 
        prj->reset_perspective_projection();
119
 
}