00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "xrb_progressbar.hpp"
00012
00013 #include "xrb_render.hpp"
00014
00015 using namespace Xrb;
00016
00017 namespace Xrb
00018 {
00019
00020 ProgressBar::ProgressBar (
00021 GrowOrientation const grow_orientation,
00022 ContainerWidget *const parent,
00023 std::string const &name)
00024 :
00025 Widget(parent, name),
00026 m_receiver_set_progress(&ProgressBar::SetProgress, this)
00027 {
00028 ASSERT1(grow_orientation < GO_COUNT);
00029 m_grow_orientation = grow_orientation;
00030 m_progress = 0.0f;
00031 m_color = Color(1.0f, 1.0f, 1.0f, 1.0f);
00032 }
00033
00034 ProgressBar::~ProgressBar ()
00035 {
00036 }
00037
00038 void ProgressBar::Draw (RenderContext const &render_context) const
00039 {
00040 ASSERT1(m_progress >= 0.0f && m_progress <= 1.0f);
00041
00042
00043 Widget::Draw(render_context);
00044
00045 ScreenCoordRect progress_rect(ScreenRect());
00046 Float const remaining_progress = 1.0f - m_progress;
00047
00048 if (m_grow_orientation == GO_RIGHT)
00049 progress_rect.m_top_right[Dim::X] -=
00050 static_cast<ScreenCoord>(
00051 remaining_progress *
00052 static_cast<Float>(progress_rect.Width()));
00053 else if (m_grow_orientation == GO_LEFT)
00054 progress_rect.m_bottom_left[Dim::X] +=
00055 static_cast<ScreenCoord>(
00056 remaining_progress *
00057 static_cast<Float>(progress_rect.Width()));
00058 else if (m_grow_orientation == GO_UP)
00059 progress_rect.m_top_right[Dim::Y] -=
00060 static_cast<ScreenCoord>(
00061 remaining_progress *
00062 static_cast<Float>(progress_rect.Height()));
00063 else if (m_grow_orientation == GO_DOWN)
00064 progress_rect.m_bottom_left[Dim::Y] +=
00065 static_cast<ScreenCoord>(
00066 remaining_progress *
00067 static_cast<Float>(progress_rect.Height()));
00068 else
00069 ASSERT1(false && "Invalid ProgressBar::GrowOrientation");
00070
00071 ASSERT1(progress_rect.Width() >= 0);
00072 ASSERT1(progress_rect.Height() >= 0);
00073 Render::DrawScreenRect(render_context, m_color, progress_rect);
00074 }
00075
00076 }
00077