00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017
00018 #include "global.hpp"
00019
00020 #include "widgets/progressbar.hpp"
00021
00022 #include "font.hpp"
00023 #include "marked-up_text.hpp"
00024 #include "video.hpp"
00025
00026 namespace gui {
00027
00028 progress_bar::progress_bar(CVideo& video) : widget(video), progress_(0)
00029 {}
00030
00031 void progress_bar::set_progress_percent(int progress)
00032 {
00033 progress_ = progress;
00034 set_dirty();
00035 }
00036
00037 void progress_bar::set_text(const std::string& text)
00038 {
00039 text_ = text;
00040 set_dirty();
00041 }
00042
00043 void progress_bar::draw_contents()
00044 {
00045 surface surf = video().getSurface();
00046 SDL_Rect area = location();
00047
00048 if(area.w >= 2 && area.h >= 2) {
00049 int fcr = 21, fcg = 53, fcb = 80;
00050 int bcr = 0, bcg = 0, bcb = 0;
00051 int gcr = 255, gcg = 255, gcb = 255;
00052 int lightning_thickness = 2;
00053 static const SDL_Color selected_text_color = {0xCC,0xCC,0xCC,0};
00054
00055 SDL_Rect inner_area = create_rect(area.x + 1
00056 , area.y + 1
00057 , area.w - 2
00058 , area.h - 2);
00059
00060 sdl_fill_rect(surf,&area,SDL_MapRGB(surf->format,bcr,bcg,bcb));
00061 sdl_fill_rect(surf,&inner_area,SDL_MapRGB(surf->format,gcr,gcg,gcb));
00062
00063 inner_area.w = (inner_area.w*progress_)/100;
00064 sdl_fill_rect(surf,&inner_area,SDL_MapRGB(surf->format,fcr,fcg,fcb));
00065
00066 SDL_Rect lightning = inner_area;
00067 lightning.h = lightning_thickness;
00068
00069 sdl_fill_rect(surf,&lightning,SDL_MapRGB(surf->format,(fcr*3+255)/4,(fcg*3+255)/4,(fcb*3+255)/4));
00070 lightning.y = inner_area.y+inner_area.h-lightning.h;
00071
00072 sdl_fill_rect(surf,&lightning,SDL_MapRGB(surf->format,fcr/2,fcg/2,fcb/2));
00073
00074 const std::string text = text_.empty() ? str_cast(progress_) + "%" :
00075 text_ + " (" + str_cast(progress_) + "%)";
00076 SDL_Rect text_area = font::text_area(text,font::SIZE_NORMAL);
00077
00078 text_area.x = area.x + area.w/2 - text_area.w/2;
00079 text_area.y = area.y + area.h/2 - text_area.h/2;
00080
00081 font::draw_text(
00082 &video(),
00083 location(),
00084 font::SIZE_NORMAL,
00085 font::BLACK_COLOR,
00086 text,
00087 text_area.x,
00088 text_area.y
00089 );
00090
00091
00092
00093 SDL_Rect selected_text_location = location();
00094 selected_text_location.w = inner_area.w;
00095 selected_text_location.h = inner_area.h;
00096 {
00097 clip_rect_setter clippy(surf, &selected_text_location);
00098 font::draw_text(
00099 &video(),
00100 selected_text_location,
00101 font::SIZE_NORMAL,
00102 selected_text_color,
00103 text,
00104 text_area.x,
00105 text_area.y
00106 );
00107 }
00108 }
00109
00110 update_rect(location());
00111 }
00112
00113 }