]>
Dogcows Code - chaz/yoink/blob - src/Hud.cc
a7e141e1ef8a7d57138ffb1fc9a2dff80421e2e7
2 /*******************************************************************************
4 Copyright (c) 2009, Charles McGarvey
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *******************************************************************************/
29 #include <Moof/OpenGL.hh>
36 ProgressBar::ProgressBar(const Tilemap
& tilemap
, Tilemap::Index index
) :
40 tilemap
.getTileCoords(index
, mTexCoords
);
42 Mf::Scalar half
= (mTexCoords
[2] - mTexCoords
[0]) / 2.0 + mTexCoords
[0];
43 mMidCoords
[0] = half
- 0.01;
44 mMidCoords
[1] = half
+ 0.01;
47 void ProgressBar::resize(const Mf::Rectangle
& rect
)
49 Mf::Scalar height
= rect
.max
[1] - rect
.min
[1];
50 Mf::Scalar halfHeight
= height
/ 2.0;
52 mWidth
= rect
.max
[0] - rect
.min
[0] - height
;
55 mVertices
[0] = rect
.min
;
56 mVertices
[1] = Mf::Vector2(rect
.min
[0] + halfHeight
, rect
.min
[1]);
57 mVertices
[2] = mVertices
[1];
58 mVertices
[3] = Mf::Vector2(rect
.min
[0] + height
, rect
.min
[1]);
59 mVertices
[4] = Mf::Vector2(rect
.min
[0] + height
, rect
.max
[1]);
60 mVertices
[5] = Mf::Vector2(rect
.min
[0] + halfHeight
, rect
.max
[1]);
61 mVertices
[6] = mVertices
[5];
62 mVertices
[7] = Mf::Vector2(rect
.min
[0], rect
.max
[1]);
64 setProgress(mProgress
);
67 void ProgressBar::setProgress(Mf::Scalar progress
)
69 Mf::Scalar halfHeight
= (mVertices
[7][1] - mVertices
[0][1]) / 2.0;
71 mVertices
[2][0] = mVertices
[1][0] + progress
* mWidth
;
72 mVertices
[3][0] = mVertices
[1][0] + progress
* mWidth
+ halfHeight
;
73 mVertices
[4][0] = mVertices
[1][0] + progress
* mWidth
+ halfHeight
;
74 mVertices
[5][0] = mVertices
[1][0] + progress
* mWidth
;
79 void ProgressBar::draw(Mf::Scalar alpha
) const
81 if (Mf::isEqual(mProgress
, 0.0))
83 // don't draw anything if the progress is 0%
87 glColor4f(1.0f
, 1.0f
, 1.0f
, 0.85f
);
91 glTexCoord2(mTexCoords
[0], mTexCoords
[1]);
92 glVertex2v(mVertices
[0].data());
93 glTexCoord2(mMidCoords
[0], mTexCoords
[3]);
94 glVertex2v(mVertices
[1].data());
95 glTexCoord2(mMidCoords
[0], mTexCoords
[5]);
96 glVertex2v(mVertices
[6].data());
97 glTexCoord2(mTexCoords
[6], mTexCoords
[7]);
98 glVertex2v(mVertices
[7].data());
100 glTexCoord2(mMidCoords
[0], mTexCoords
[1]);
101 glVertex2v(mVertices
[1].data());
102 glTexCoord2(mMidCoords
[1], mTexCoords
[3]);
103 glVertex2v(mVertices
[2].data());
104 glTexCoord2(mMidCoords
[1], mTexCoords
[5]);
105 glVertex2v(mVertices
[5].data());
106 glTexCoord2(mMidCoords
[0], mTexCoords
[7]);
107 glVertex2v(mVertices
[6].data());
109 glTexCoord2(mMidCoords
[1], mTexCoords
[1]);
110 glVertex2v(mVertices
[2].data());
111 glTexCoord2(mTexCoords
[2], mTexCoords
[3]);
112 glVertex2v(mVertices
[3].data());
113 glTexCoord2(mTexCoords
[4], mTexCoords
[5]);
114 glVertex2v(mVertices
[4].data());
115 glTexCoord2(mMidCoords
[1], mTexCoords
[7]);
116 glVertex2v(mVertices
[5].data());
122 mBar1(Tilemap("StatusBars"), 0),
123 mBar2(Tilemap("StatusBars"), 2),
130 void Hud::resize(int width
, int height
)
132 cml::matrix_orthographic_RH(mProjection
,
134 Mf::Scalar(width
), SCALAR(0.0), Mf::Scalar(height
),
135 SCALAR(1.0), SCALAR(-1.0), cml::z_clip_neg_one
);
137 // position the two progress bars at the top-left of the screen
138 mBar1
.resize(Mf::Rectangle(20, height
- 51,
139 0.7 * width
, height
- 3));
140 mBar2
.resize(Mf::Rectangle(20, height
- 28,
141 0.7 * width
, height
- 70));
143 setBar1Progress(0.05);
144 setBar2Progress(0.0);
148 void Hud::draw(Mf::Scalar alpha
) const
150 glMatrixMode(GL_PROJECTION
);
152 glLoadMatrix(mProjection
.data());
154 glMatrixMode(GL_MODELVIEW
);
158 glDisable(GL_DEPTH_TEST
);
165 glEnable(GL_DEPTH_TEST
);
167 glMatrixMode(GL_PROJECTION
);
170 glMatrixMode(GL_MODELVIEW
);
174 bool Hud::handleEvent(Mf::Event
& event
)
178 case SDL_VIDEORESIZE
:
179 resize(event
.resize
.w
, event
.resize
.h
);
187 /** vim: set ts=4 sw=4 tw=80: *************************************************/
This page took 0.043911 seconds and 4 git commands to generate.