00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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
00106
00107 int l = (int)(((double)pr.my_width / 100.0) * my_percentCurrent);
00108 pr.my_width = l;
00109
00110
00111 PG_ThemeWidget::eventBlit(srf, src, dst);
00112
00113
00114 SDL_Surface* ind = PG_ThemeWidget::CreateThemedSurface(
00115 pr,
00116 &my_pbGradient,
00117 my_pbBackground,
00118 my_pbBackmode,
00119 my_pbBlend);
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
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
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
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
00161
00162
00163