00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "global.hpp"
00016
00017 #include "widgets/progressbar.hpp"
00018
00019 #include "font.hpp"
00020 #include "marked-up_text.hpp"
00021 #include "util.hpp"
00022 #include "video.hpp"
00023
00024 namespace gui {
00025
00026 progress_bar::progress_bar(CVideo& video) : widget(video), progress_(0)
00027 {}
00028
00029 void progress_bar::set_progress_percent(int progress)
00030 {
00031 progress_ = progress;
00032 set_dirty();
00033 }
00034
00035 void progress_bar::set_text(const std::string& text)
00036 {
00037 text_ = text;
00038 set_dirty();
00039 }
00040
00041 void progress_bar::draw_contents()
00042 {
00043 surface const surf = video().getSurface();
00044 SDL_Rect area = location();
00045
00046 if(area.w >= 2 && area.h >= 2) {
00047 SDL_Rect inner_area = {area.x+1,area.y+1,area.w-2,area.h-2};
00048 SDL_FillRect(surf,&area,SDL_MapRGB(surf->format,0,0,0));
00049 SDL_FillRect(surf,&inner_area,SDL_MapRGB(surf->format,255,255,255));
00050
00051 inner_area.w = (inner_area.w*progress_)/100;
00052 SDL_FillRect(surf,&inner_area,SDL_MapRGB(surf->format,21,53,80));
00053
00054 const std::string text = text_.empty() ? str_cast(progress_) + "%" :
00055 text_ + " (" + str_cast(progress_) + "%)";
00056 SDL_Rect text_area = font::text_area(text,font::SIZE_NORMAL);
00057
00058 text_area.x = area.x + area.w/2 - text_area.w/2;
00059 text_area.y = area.y + area.h/2 - text_area.h/2;
00060
00061 font::draw_text(&video(),location(),font::SIZE_NORMAL,font::BLACK_COLOUR,text,text_area.x,text_area.y);
00062 }
00063
00064 update_rect(location());
00065 }
00066
00067 }