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
00030
00031
00032
00033 #include "mmsgui/mmsprogressbarwidget.h"
00034
00035 MMSProgressBarWidget::MMSProgressBarWidget(MMSWindow *root, string className, MMSTheme *theme) : MMSWidget() {
00036 create(root, className, theme);
00037 }
00038
00039 MMSProgressBarWidget::~MMSProgressBarWidget() {
00040 }
00041
00042 bool MMSProgressBarWidget::create(MMSWindow *root, string className, MMSTheme *theme) {
00043 this->type = MMSWIDGETTYPE_PROGRESSBAR;
00044 this->className = className;
00045
00046
00047 this->da = new MMSWIDGET_DRAWABLE_ATTRIBUTES;
00048 if (theme) this->da->theme = theme; else this->da->theme = globalTheme;
00049 this->progressBarWidgetClass = this->da->theme->getProgressBarWidgetClass(className);
00050 this->da->baseWidgetClass = &(this->da->theme->progressBarWidgetClass.widgetClass);
00051 if (this->progressBarWidgetClass) this->da->widgetClass = &(this->progressBarWidgetClass->widgetClass); else this->da->widgetClass = NULL;
00052
00053 this->current_fgset = false;
00054
00055 return MMSWidget::create(root, true, false, false, true, true, true, true);
00056 }
00057
00058 MMSWidget *MMSProgressBarWidget::copyWidget() {
00059
00060 MMSProgressBarWidget *newWidget = new MMSProgressBarWidget(this->rootwindow, className);
00061
00062 newWidget->className = this->className;
00063 newWidget->progressBarWidgetClass = this->progressBarWidgetClass;
00064 newWidget->myProgressBarWidgetClass = this->myProgressBarWidgetClass;
00065
00066 newWidget->current_fgcolor = this->current_fgcolor;
00067 newWidget->current_fgset = this->current_fgset;
00068
00069
00070 MMSWidget::copyWidget((MMSWidget*)newWidget);
00071
00072 return newWidget;
00073 }
00074
00075
00076 bool MMSProgressBarWidget::init() {
00077
00078 if (!MMSWidget::init())
00079 return false;
00080
00081 return true;
00082 }
00083
00084 bool MMSProgressBarWidget::release() {
00085
00086 if (!MMSWidget::release())
00087 return false;
00088
00089 return true;
00090 }
00091
00092 void MMSProgressBarWidget::getForeground(MMSFBColor *color) {
00093 color->a = 0;
00094
00095 if (isSelected()) {
00096 *color = getSelColor();
00097 }
00098 else {
00099 *color = getColor();
00100 }
00101 }
00102
00103 bool MMSProgressBarWidget::enableRefresh(bool enable) {
00104 if (!MMSWidget::enableRefresh(enable)) return false;
00105
00106
00107 this->current_fgset = false;
00108
00109 return true;
00110 }
00111
00112 bool MMSProgressBarWidget::checkRefreshStatus() {
00113 if (MMSWidget::checkRefreshStatus()) return true;
00114
00115 if (this->current_fgset) {
00116
00117 MMSFBColor color;
00118 getForeground(&color);
00119
00120 if (color == this->current_fgcolor) {
00121
00122 return false;
00123 }
00124 }
00125
00126
00127 enableRefresh();
00128
00129 return true;
00130 }
00131
00132 bool MMSProgressBarWidget::draw(bool *backgroundFilled) {
00133 bool myBackgroundFilled = false;
00134
00135 if(!surface)
00136 return false;
00137
00138 if (backgroundFilled) {
00139 if (this->has_own_surface)
00140 *backgroundFilled = false;
00141 }
00142 else
00143 backgroundFilled = &myBackgroundFilled;
00144
00145
00146 if (MMSWidget::draw(backgroundFilled)) {
00147
00148 if(getProgress() > 0) {
00149
00150 this->surface->lock();
00151
00152
00153 MMSFBRectangle surfaceGeom = getSurfaceGeometry();
00154
00155
00156 MMSFBColor color;
00157 getForeground(&color);
00158 this->current_fgcolor = color;
00159 this->current_fgset = true;
00160
00161 if (color.a) {
00162
00163 this->surface->setDrawingColorAndFlagsByBrightnessAndOpacity(color, getBrightness(), getOpacity());
00164
00165
00166 this->surface->fillRectangle(surfaceGeom.x, surfaceGeom.y,
00167 (int)((double)getProgress() / (double)100 * (double)surfaceGeom.w), surfaceGeom.h);
00168 }
00169
00170
00171 this->surface->unlock();
00172 }
00173
00174
00175 updateWindowSurfaceWithSurface(!*backgroundFilled);
00176 }
00177
00178
00179 return MMSWidget::drawDebug();
00180 }
00181
00182
00183
00184
00185
00186 #define GETPBAR(x) \
00187 if (this->myProgressBarWidgetClass.is##x()) return myProgressBarWidgetClass.get##x(); \
00188 else if ((progressBarWidgetClass)&&(progressBarWidgetClass->is##x())) return progressBarWidgetClass->get##x(); \
00189 else return this->da->theme->progressBarWidgetClass.get##x();
00190
00191 MMSFBColor MMSProgressBarWidget::getColor() {
00192 GETPBAR(Color);
00193 }
00194
00195 MMSFBColor MMSProgressBarWidget::getSelColor() {
00196 GETPBAR(SelColor);
00197 }
00198
00199 unsigned int MMSProgressBarWidget::getProgress() {
00200 GETPBAR(Progress);
00201 }
00202
00203
00204
00205
00206 void MMSProgressBarWidget::setColor(MMSFBColor color, bool refresh) {
00207 myProgressBarWidgetClass.setColor(color);
00208
00209
00210 enableRefresh((color != this->current_fgcolor));
00211
00212 this->refresh(refresh);
00213 }
00214
00215 void MMSProgressBarWidget::setSelColor(MMSFBColor selcolor, bool refresh) {
00216 myProgressBarWidgetClass.setSelColor(selcolor);
00217
00218
00219 enableRefresh((selcolor != this->current_fgcolor));
00220
00221 this->refresh(refresh);
00222 }
00223
00224 void MMSProgressBarWidget::setProgress(unsigned int progress, bool refresh) {
00225 if(progress>100)
00226 progress = 100;
00227 myProgressBarWidgetClass.setProgress(progress);
00228
00229
00230 enableRefresh();
00231
00232 this->refresh(refresh);
00233 }
00234
00235
00236 void MMSProgressBarWidget::updateFromThemeClass(MMSProgressBarWidgetClass *themeClass) {
00237 if (themeClass->isColor())
00238 setColor(themeClass->getColor());
00239 if (themeClass->isSelColor())
00240 setSelColor(themeClass->getSelColor());
00241 if (themeClass->isProgress())
00242 setProgress(themeClass->getProgress());
00243
00244 MMSWidget::updateFromThemeClass(&(themeClass->widgetClass));
00245 }
00246
00247
00248
00249