Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsprogressbarwidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
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     // init attributes for drawable widgets
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     // create widget
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     // copy base widget
00070     MMSWidget::copyWidget((MMSWidget*)newWidget);
00071 
00072     return newWidget;
00073 }
00074 
00075 
00076 bool MMSProgressBarWidget::init() {
00077     // init widget basics
00078     if (!MMSWidget::init())
00079         return false;
00080 
00081     return true;
00082 }
00083 
00084 bool MMSProgressBarWidget::release() {
00085     // release widget basics
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     // mark foreground as not set
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         // current foreground initialized
00117         MMSFBColor color;
00118         getForeground(&color);
00119 
00120         if (color == this->current_fgcolor) {
00121             // foreground color not changed, so we do not enable refreshing
00122             return false;
00123         }
00124     }
00125 
00126     // (re-)enable refreshing
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     // draw widget basics
00146     if (MMSWidget::draw(backgroundFilled)) {
00147         /* if progress is 0, fillRectangle uses the whole surface, however nothing more is needed */
00148         if(getProgress() > 0) {
00149             // lock
00150             this->surface->lock();
00151 
00152             // draw my things
00153             MMSFBRectangle surfaceGeom = getSurfaceGeometry();
00154 
00155             // get color
00156             MMSFBColor color;
00157             getForeground(&color);
00158             this->current_fgcolor   = color;
00159             this->current_fgset     = true;
00160 
00161             if (color.a) {
00162                 // prepare for drawing
00163                 this->surface->setDrawingColorAndFlagsByBrightnessAndOpacity(color, getBrightness(), getOpacity());
00164 
00165                 // fill the rectangle
00166                 this->surface->fillRectangle(surfaceGeom.x, surfaceGeom.y,
00167                                             (int)((double)getProgress() / (double)100 * (double)surfaceGeom.w), surfaceGeom.h);
00168             }
00169 
00170             // unlock
00171             this->surface->unlock();
00172         }
00173 
00174         // update window surface with an area of surface
00175         updateWindowSurfaceWithSurface(!*backgroundFilled);
00176     }
00177 
00178     // draw widgets debug frame
00179     return MMSWidget::drawDebug();
00180 }
00181 
00182 /***********************************************/
00183 /* begin of theme access methods (get methods) */
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 /* begin of theme access methods (set methods) */
00205 /***********************************************/
00206 void MMSProgressBarWidget::setColor(MMSFBColor color, bool refresh) {
00207     myProgressBarWidgetClass.setColor(color);
00208 
00209     // refresh required?
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     // refresh required?
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     // refresh is required
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 /* end of theme access methods                 */
00249 /***********************************************/

Generated by doxygen