progressbar.cpp

Go to the documentation of this file.
00001 /* $Id: progressbar.cpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
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 }

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs