]>
Dogcows Code - chaz/yoink/blob - src/Hud.cc
58bc7210422e54b0b0a98fb03b1835277db8e90e
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/log.hh>
14 #include <moof/opengl.hh>
15 #include <moof/video.hh>
20 ProgressBar::ProgressBar(const moof::sprite
& tilemap
, int index
) :
22 mTilemap(tilemap
, index
)
24 // TODO this is now broken
25 moof::scalar half
= (mTexCoords
[2] - mTexCoords
[0]) / 2.0 + mTexCoords
[0];
26 mMidCoords
[0] = half
- 0.01;
27 mMidCoords
[1] = half
+ 0.01;
30 void ProgressBar::resize(const moof::rectangle
& rect
)
32 moof::log_info
<< "rect: " << rect
.min
<< ", " << rect
.max
<< std::endl
;
33 moof::scalar height
= rect
.max
[1] - rect
.min
[1];
34 moof::scalar halfHeight
= height
/ 2.0;
36 mWidth
= rect
.max
[0] - rect
.min
[0] - height
;
39 mVertices
[0] = rect
.min
;
40 mVertices
[1] = moof::vector2(rect
.min
[0] + halfHeight
, rect
.min
[1]);
41 mVertices
[2] = mVertices
[1];
42 mVertices
[3] = moof::vector2(rect
.min
[0] + height
, rect
.min
[1]);
43 mVertices
[4] = moof::vector2(rect
.min
[0] + height
, rect
.max
[1]);
44 mVertices
[5] = moof::vector2(rect
.min
[0] + halfHeight
, rect
.max
[1]);
45 mVertices
[6] = mVertices
[5];
46 mVertices
[7] = moof::vector2(rect
.min
[0], rect
.max
[1]);
48 setProgress(mProgress
);
51 void ProgressBar::setProgress(moof::scalar progress
)
53 moof::scalar halfHeight
= (mVertices
[7][1] - mVertices
[0][1]) / 2.0;
55 mVertices
[2][0] = mVertices
[1][0] + progress
* mWidth
;
56 mVertices
[3][0] = mVertices
[1][0] + progress
* mWidth
+ halfHeight
;
57 mVertices
[4][0] = mVertices
[1][0] + progress
* mWidth
+ halfHeight
;
58 mVertices
[5][0] = mVertices
[1][0] + progress
* mWidth
;
63 void ProgressBar::draw(moof::scalar alpha
) const
65 if (moof::is_equal(mProgress
, 0.0))
67 // don't draw anything if the progress is 0%
71 glColor4f(1.0f
, 1.0f
, 1.0f
, 0.85f
);
75 glTexCoord(mTexCoords
[0], mTexCoords
[1]);
76 glVertex(mVertices
[0]);
77 glTexCoord(mMidCoords
[0], mTexCoords
[3]);
78 glVertex(mVertices
[1]);
79 glTexCoord(mMidCoords
[0], mTexCoords
[5]);
80 glVertex(mVertices
[6]);
81 glTexCoord(mTexCoords
[6], mTexCoords
[7]);
82 glVertex(mVertices
[7]);
84 glTexCoord(mMidCoords
[0], mTexCoords
[1]);
85 glVertex(mVertices
[1]);
86 glTexCoord(mMidCoords
[1], mTexCoords
[3]);
87 glVertex(mVertices
[2]);
88 glTexCoord(mMidCoords
[1], mTexCoords
[5]);
89 glVertex(mVertices
[5]);
90 glTexCoord(mMidCoords
[0], mTexCoords
[7]);
91 glVertex(mVertices
[6]);
93 glTexCoord(mMidCoords
[1], mTexCoords
[1]);
94 glVertex(mVertices
[2]);
95 glTexCoord(mTexCoords
[2], mTexCoords
[3]);
96 glVertex(mVertices
[3]);
97 glTexCoord(mTexCoords
[4], mTexCoords
[5]);
98 glVertex(mVertices
[4]);
99 glTexCoord(mMidCoords
[1], mTexCoords
[7]);
100 glVertex(mVertices
[5]);
105 Hud::Hud(GameState
& state
) :
107 mBar1(moof::sprite("StatusBars"), 0),
108 mBar2(moof::sprite("StatusBars"), 2),
111 moof::video
* video
= moof::video::current();
112 ASSERT(video
&& "a current video context should be set");
113 resize(video
->width(), video
->height());
117 void Hud::resize(int width
, int height
)
119 moof::matrix_orthographic_RH(mProjection
, SCALAR(0.0),
120 moof::scalar(width
), SCALAR(0.0),
121 moof::scalar(height
),
122 SCALAR(1.0), SCALAR(-1.0), moof::z_clip_neg_one
);
124 // position the two progress bars at the top-left of the screen
125 mBar1
.resize(moof::rectangle(20, height
- 51, 0.7 * width
, height
- 3));
126 mBar2
.resize(moof::rectangle(20, height
- 28, 0.7 * width
, height
- 70));
128 setBar1Progress(0.05);
129 setBar2Progress(0.0);
133 void Hud::update(moof::scalar t
, moof::scalar dt
)
135 state_
.interp
.update(t
, dt
);
136 setBar1Progress(state_
.interp
.state(dt
));
137 setBar2Progress(1.0 - state_
.interp
.state(dt
));
140 void Hud::draw(moof::scalar alpha
) const
142 glMatrixMode(GL_PROJECTION
);
144 glLoadMatrix(mProjection
.data());
146 glMatrixMode(GL_MODELVIEW
);
150 glDisable(GL_DEPTH_TEST
);
157 glEnable(GL_DEPTH_TEST
);
159 glMatrixMode(GL_PROJECTION
);
162 glMatrixMode(GL_MODELVIEW
);
166 bool Hud::handle_event(const moof::event
& event
)
171 if (event
.key
.keysym
.sym
== SDLK_h
)
173 // don't want the hud anymore
174 parent().remove_child(this);
176 moof::log_warning("okay bye bye hud");
181 case SDL_VIDEORESIZE
:
182 resize(event
.resize
.w
, event
.resize
.h
);
This page took 0.042493 seconds and 4 git commands to generate.