Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgprogressbar.cpp

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2007-04-13 16:16:04 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pgprogressbar.cpp,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #include "pgapplication.h"
00030 #include "pgprogressbar.h"
00031 #include "pgdraw.h"
00032 #include "pgtheme.h"
00033 
00034 PG_ProgressBar::PG_ProgressBar(PG_Widget* parent, const PG_Rect& r, const std::string& style) : PG_ThemeWidget(parent, r) {
00035 
00036         my_percentCurrent = 0;
00037         my_drawPercentage = true;
00038 
00039         my_colorText.r = 0xFF;
00040         my_colorText.g = 0xFF;
00041         my_colorText.b = 0xFF;
00042 
00043         // fill in default gradient
00044         my_pbGradient.colors[0].r = 0x00;
00045         my_pbGradient.colors[0].g = 0x00;
00046         my_pbGradient.colors[0].b = 0x00;
00047 
00048         my_pbGradient.colors[1].r = 0x00;
00049         my_pbGradient.colors[1].g = 0x00;
00050         my_pbGradient.colors[1].b = 0xFF;
00051 
00052         my_pbGradient.colors[2].r = 0x00;
00053         my_pbGradient.colors[2].g = 0x00;
00054         my_pbGradient.colors[2].b = 0x00;
00055 
00056         my_pbGradient.colors[3].r = 0x00;
00057         my_pbGradient.colors[3].g = 0x00;
00058         my_pbGradient.colors[3].b = 0xFF;
00059 
00060         my_pbBackground = NULL;
00061         my_pbBackmode = PG_Draw::TILE;
00062         my_pbBlend = 255;
00063         my_bordersize = 1;
00064 
00065         LoadThemeStyle(style);
00066 }
00067 
00068 PG_ProgressBar::~PG_ProgressBar() {}
00069 
00070 void PG_ProgressBar::SetDrawPercentage(bool drawit) {
00071         if(drawit != my_drawPercentage) {
00072                 my_drawPercentage = drawit;
00073                 Update();
00074         }
00075 }
00076 
00077 
00078 void PG_ProgressBar::LoadThemeStyle(const std::string& widgettype) {
00079         PG_Theme* t = PG_Application::GetTheme();
00080 
00081         PG_ThemeWidget::LoadThemeStyle(widgettype, "Background");
00082 
00083         my_pbBackground = t->FindSurface(widgettype, "Indicator", "background");
00084 
00085         PG_Gradient* g = t->FindGradient(widgettype, "Indicator", "gradient");
00086 
00087         if(g) {
00088                 my_pbGradient = *g;
00089         }
00090 
00091         t->GetProperty(widgettype, "Indicator", "backmode", my_pbBackmode);
00092         t->GetProperty(widgettype, "Indicator", "blend", my_pbBlend);
00093 }
00094 
00095 void PG_ProgressBar::eventBlit(SDL_Surface* srf, const PG_Rect& src, const PG_Rect& dst) {
00096         PG_Rect pr(
00097             my_xpos + 1,
00098             my_ypos + 2,
00099             my_width - 2,
00100             my_height - 4);
00101 
00102         PG_Rect my_src, my_dst;
00103         char *buf;
00104 
00105         // get length of progress indicator
00106 
00107         int l = (int)(((double)pr.my_width / 100.0) * my_percentCurrent);
00108         pr.my_width = l;
00109 
00110         // draw our superclass
00111         PG_ThemeWidget::eventBlit(srf, src, dst);
00112 
00113         // draw the gradient
00114         SDL_Surface* ind = PG_ThemeWidget::CreateThemedSurface(
00115                                pr,
00116                                &my_pbGradient,
00117                                my_pbBackground,                 // currently no background
00118                                my_pbBackmode,   // backmode
00119                                my_pbBlend);                     // background blend
00120 
00121         GetClipRects(my_src, my_dst, pr);
00122         PG_Draw::BlitSurface(ind, my_src, PG_Application::GetScreen(), my_dst);
00123 
00124         PG_ThemeWidget::DeleteThemedSurface(ind);
00125 
00126         if(my_drawPercentage) {
00127                 buf = new char[my_text.length() + 64];
00128                 // draw the percentage
00129                 if (my_text.length() == 0)
00130                         sprintf(buf, "%i%%", (int)my_percentCurrent);
00131                 else
00132                         sprintf(buf, my_text.c_str(), (int)my_percentCurrent);
00133 
00134                 Uint16 w, h;
00135                 GetTextSize(w,h, buf);
00136 
00137                 // !! textrectangle can be bigger than the widget
00138                 int x = (my_width - w)/2;
00139                 int y = (my_height - h)/2;
00140 
00141                 DrawText(x, y, buf);
00142 
00143                 delete[] buf;
00144         }
00145 }
00146 
00147 // Why a double? -Dave
00148 void PG_ProgressBar::SetProgress(double p) {
00149         if(p < 0)
00150                 p = 0;
00151         if(p >100)
00152                 p = 100;
00153         if(my_percentCurrent != p) {
00154                 my_percentCurrent = p;
00155                 Update();
00156         }
00157 }
00158 
00159 /*
00160  * Local Variables:
00161  * c-basic-offset: 8
00162  * End:
00163  */

Generated on Tue Jun 24 01:27:48 2008 for Advanced Strategic Command by  doxygen 1.4.2