]>
Dogcows Code - chaz/yoink/blob - src/Hud.cc
f4134cf737fd468acee3b76acc5a3166bfc00611
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #include <Moof/Aabb.hh>
13 #include <Moof/Core.hh>
14 #include <Moof/Log.hh>
15 #include <Moof/OpenGL.hh>
16 #include <Moof/Video.hh>
21 ProgressBar::ProgressBar(const Mf::Texture
& tilemap
,
22 Mf::Texture::TileIndex index
) :
26 tilemap
.getTileCoords(index
, mTexCoords
);
28 Mf::Scalar half
= (mTexCoords
[2] - mTexCoords
[0]) / 2.0 + mTexCoords
[0];
29 mMidCoords
[0] = half
- 0.01;
30 mMidCoords
[1] = half
+ 0.01;
33 void ProgressBar::resize(const Mf::Rectangle
& rect
)
35 Mf::logInfo
<< "rect: " << rect
.min
<< ", " << rect
.max
<< std::endl
;
36 Mf::Scalar height
= rect
.max
[1] - rect
.min
[1];
37 Mf::Scalar halfHeight
= height
/ 2.0;
39 mWidth
= rect
.max
[0] - rect
.min
[0] - height
;
42 mVertices
[0] = rect
.min
;
43 mVertices
[1] = Mf::Vector2(rect
.min
[0] + halfHeight
, rect
.min
[1]);
44 mVertices
[2] = mVertices
[1];
45 mVertices
[3] = Mf::Vector2(rect
.min
[0] + height
, rect
.min
[1]);
46 mVertices
[4] = Mf::Vector2(rect
.min
[0] + height
, rect
.max
[1]);
47 mVertices
[5] = Mf::Vector2(rect
.min
[0] + halfHeight
, rect
.max
[1]);
48 mVertices
[6] = mVertices
[5];
49 mVertices
[7] = Mf::Vector2(rect
.min
[0], rect
.max
[1]);
51 setProgress(mProgress
);
54 void ProgressBar::setProgress(Mf::Scalar progress
)
56 Mf::Scalar halfHeight
= (mVertices
[7][1] - mVertices
[0][1]) / 2.0;
58 mVertices
[2][0] = mVertices
[1][0] + progress
* mWidth
;
59 mVertices
[3][0] = mVertices
[1][0] + progress
* mWidth
+ halfHeight
;
60 mVertices
[4][0] = mVertices
[1][0] + progress
* mWidth
+ halfHeight
;
61 mVertices
[5][0] = mVertices
[1][0] + progress
* mWidth
;
66 void ProgressBar::draw(Mf::Scalar alpha
) const
68 if (Mf::isEqual(mProgress
, 0.0))
70 // don't draw anything if the progress is 0%
74 glColor4f(1.0f
, 1.0f
, 1.0f
, 0.85f
);
78 glTexCoord(mTexCoords
[0], mTexCoords
[1]);
79 glVertex(mVertices
[0]);
80 glTexCoord(mMidCoords
[0], mTexCoords
[3]);
81 glVertex(mVertices
[1]);
82 glTexCoord(mMidCoords
[0], mTexCoords
[5]);
83 glVertex(mVertices
[6]);
84 glTexCoord(mTexCoords
[6], mTexCoords
[7]);
85 glVertex(mVertices
[7]);
87 glTexCoord(mMidCoords
[0], mTexCoords
[1]);
88 glVertex(mVertices
[1]);
89 glTexCoord(mMidCoords
[1], mTexCoords
[3]);
90 glVertex(mVertices
[2]);
91 glTexCoord(mMidCoords
[1], mTexCoords
[5]);
92 glVertex(mVertices
[5]);
93 glTexCoord(mMidCoords
[0], mTexCoords
[7]);
94 glVertex(mVertices
[6]);
96 glTexCoord(mMidCoords
[1], mTexCoords
[1]);
97 glVertex(mVertices
[2]);
98 glTexCoord(mTexCoords
[2], mTexCoords
[3]);
99 glVertex(mVertices
[3]);
100 glTexCoord(mTexCoords
[4], mTexCoords
[5]);
101 glVertex(mVertices
[4]);
102 glTexCoord(mMidCoords
[1], mTexCoords
[7]);
103 glVertex(mVertices
[5]);
108 Hud::Hud(GameState
& state
) :
110 mBar1(Mf::Texture("StatusBars"), 0),
111 mBar2(Mf::Texture("StatusBars"), 2),
115 "no current video context from which to get dimensions");
116 resize(Mf::video
->getWidth(), Mf::video
->getHeight());
120 void Hud::resize(int width
, int height
)
122 cml::matrix_orthographic_RH(mProjection
,
124 Mf::Scalar(width
), SCALAR(0.0), Mf::Scalar(height
),
125 SCALAR(1.0), SCALAR(-1.0), cml::z_clip_neg_one
);
127 // position the two progress bars at the top-left of the screen
128 mBar1
.resize(Mf::Rectangle(20, height
- 51, 0.7 * width
, height
- 3));
129 mBar2
.resize(Mf::Rectangle(20, height
- 28, 0.7 * width
, height
- 70));
131 setBar1Progress(0.05);
132 setBar2Progress(0.0);
136 void Hud::update(Mf::Scalar t
, Mf::Scalar dt
)
138 mState
.interp
.update(t
, dt
);
139 setBar1Progress(mState
.interp
.getState(dt
));
140 setBar2Progress(1.0 - mState
.interp
.getState(dt
));
143 void Hud::draw(Mf::Scalar alpha
) const
145 glMatrixMode(GL_PROJECTION
);
147 glLoadMatrix(mProjection
.data());
149 glMatrixMode(GL_MODELVIEW
);
153 glDisable(GL_DEPTH_TEST
);
160 glEnable(GL_DEPTH_TEST
);
162 glMatrixMode(GL_PROJECTION
);
165 glMatrixMode(GL_MODELVIEW
);
169 bool Hud::handleEvent(const Mf::Event
& event
)
174 if (event
.key
.keysym
.sym
== SDLK_h
)
176 // don't want the hud anymore
178 Mf::logWarning("okay bye bye hud");
183 case SDL_VIDEORESIZE
:
184 resize(event
.resize
.w
, event
.resize
.h
);
This page took 0.042186 seconds and 4 git commands to generate.