]>
Dogcows Code - chaz/yoink/blob - src/Hud.cc
5687ac88bdb1c27ab2f998775662ef951255c670
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
8 *****************************************************************************/
10 #include <moof/aabb.hh>
11 #include <moof/debug.hh>
12 #include <moof/opengl.hh>
13 #include <moof/video.hh>
18 ProgressBar::ProgressBar(const moof::sprite
& tilemap
, int index
) :
20 mTilemap(tilemap
, index
)
22 // TODO this is now broken
23 moof::scalar half
= (mTexCoords
[2] - mTexCoords
[0]) / 2.0 + mTexCoords
[0];
24 mMidCoords
[0] = half
- 0.01;
25 mMidCoords
[1] = half
+ 0.01;
28 void ProgressBar::resize(const moof::rectangle
& rect
)
30 moof::log_info
<< "rect: " << rect
.min
<< ", " << rect
.max
<< std::endl
;
31 moof::scalar height
= rect
.max
[1] - rect
.min
[1];
32 moof::scalar halfHeight
= height
/ 2.0;
34 mWidth
= rect
.max
[0] - rect
.min
[0] - height
;
37 mVertices
[0] = rect
.min
;
38 mVertices
[1] = moof::vector2(rect
.min
[0] + halfHeight
, rect
.min
[1]);
39 mVertices
[2] = mVertices
[1];
40 mVertices
[3] = moof::vector2(rect
.min
[0] + height
, rect
.min
[1]);
41 mVertices
[4] = moof::vector2(rect
.min
[0] + height
, rect
.max
[1]);
42 mVertices
[5] = moof::vector2(rect
.min
[0] + halfHeight
, rect
.max
[1]);
43 mVertices
[6] = mVertices
[5];
44 mVertices
[7] = moof::vector2(rect
.min
[0], rect
.max
[1]);
46 setProgress(mProgress
);
49 void ProgressBar::setProgress(moof::scalar progress
)
51 moof::scalar halfHeight
= (mVertices
[7][1] - mVertices
[0][1]) / 2.0;
53 mVertices
[2][0] = mVertices
[1][0] + progress
* mWidth
;
54 mVertices
[3][0] = mVertices
[1][0] + progress
* mWidth
+ halfHeight
;
55 mVertices
[4][0] = mVertices
[1][0] + progress
* mWidth
+ halfHeight
;
56 mVertices
[5][0] = mVertices
[1][0] + progress
* mWidth
;
61 void ProgressBar::draw(moof::scalar alpha
) const
63 if (moof::is_equal(mProgress
, 0.0)) return;
64 // don't draw anything if the progress is 0%
66 glColor4f(1.0f
, 1.0f
, 1.0f
, 0.85f
);
70 glTexCoord(mTexCoords
[0], mTexCoords
[1]);
71 glVertex(mVertices
[0]);
72 glTexCoord(mMidCoords
[0], mTexCoords
[3]);
73 glVertex(mVertices
[1]);
74 glTexCoord(mMidCoords
[0], mTexCoords
[5]);
75 glVertex(mVertices
[6]);
76 glTexCoord(mTexCoords
[6], mTexCoords
[7]);
77 glVertex(mVertices
[7]);
79 glTexCoord(mMidCoords
[0], mTexCoords
[1]);
80 glVertex(mVertices
[1]);
81 glTexCoord(mMidCoords
[1], mTexCoords
[3]);
82 glVertex(mVertices
[2]);
83 glTexCoord(mMidCoords
[1], mTexCoords
[5]);
84 glVertex(mVertices
[5]);
85 glTexCoord(mMidCoords
[0], mTexCoords
[7]);
86 glVertex(mVertices
[6]);
88 glTexCoord(mMidCoords
[1], mTexCoords
[1]);
89 glVertex(mVertices
[2]);
90 glTexCoord(mTexCoords
[2], mTexCoords
[3]);
91 glVertex(mVertices
[3]);
92 glTexCoord(mTexCoords
[4], mTexCoords
[5]);
93 glVertex(mVertices
[4]);
94 glTexCoord(mMidCoords
[1], mTexCoords
[7]);
95 glVertex(mVertices
[5]);
100 Hud::Hud(GameState
& state
) :
102 mBar1(moof::sprite("StatusBars"), 0),
103 mBar2(moof::sprite("StatusBars"), 2),
106 ASSERT(moof::video::ready() && "a current video context should be set");
107 moof::video
& video
= moof::video::current();
108 resize(video
.width(), video
.height());
111 void Hud::resize(int width
, int height
)
113 moof::matrix_orthographic_RH(mProjection
, SCALAR(0.0),
114 moof::scalar(width
), SCALAR(0.0),
115 moof::scalar(height
), SCALAR(1.0),
116 SCALAR(-1.0), moof::z_clip_neg_one
);
118 // position the two progress bars at the top-left of the screen
119 mBar1
.resize(moof::rectangle(20, height
- 51, 0.7 * width
, height
- 3));
120 mBar2
.resize(moof::rectangle(20, height
- 28, 0.7 * width
, height
- 70));
122 setBar1Progress(0.05);
123 setBar2Progress(0.0);
126 void Hud::update(moof::scalar t
, moof::scalar dt
)
128 state_
.interp
.update(t
, dt
);
129 setBar1Progress(state_
.interp
.state(dt
));
130 setBar2Progress(1.0 - state_
.interp
.state(dt
));
133 void Hud::draw(moof::scalar alpha
) const
135 glMatrixMode(GL_PROJECTION
);
137 glLoadMatrix(mProjection
.data());
139 glMatrixMode(GL_MODELVIEW
);
143 glDisable(GL_DEPTH_TEST
);
150 glEnable(GL_DEPTH_TEST
);
152 glMatrixMode(GL_PROJECTION
);
155 glMatrixMode(GL_MODELVIEW
);
159 bool Hud::handle_event(const moof::event
& event
)
164 if (event
.key
.keysym
.sym
== SDLK_h
)
166 // don't want the hud anymore
167 //parent().remove_child(this);
169 moof::log_warning("okay bye bye hud");
174 case SDL_VIDEORESIZE
:
175 resize(event
.resize
.w
, event
.resize
.h
);
This page took 0.04455 seconds and 4 git commands to generate.