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

mmsarrowwidget.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-2012 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/mmsarrowwidget.h"
00034 
00035 MMSArrowWidget::MMSArrowWidget(MMSWindow *root, string className, MMSTheme *theme) {
00036     create(root, className, theme);
00037 }
00038 
00039 MMSArrowWidget::~MMSArrowWidget() {
00040 }
00041 
00042 bool MMSArrowWidget::create(MMSWindow *root, string className, MMSTheme *theme) {
00043     this->type = MMSWIDGETTYPE_ARROW;
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->arrowWidgetClass = this->da->theme->getArrowWidgetClass(className);
00050     this->da->baseWidgetClass = &(this->da->theme->arrowWidgetClass.widgetClass);
00051     if (this->arrowWidgetClass) this->da->widgetClass = &(this->arrowWidgetClass->widgetClass); else this->da->widgetClass = NULL;
00052 
00053     this->last_pressed = false;
00054     this->current_fgset = false;
00055 
00056     return MMSWidget::create(root, true, false, false, true, true, true, true);
00057 }
00058 
00059 MMSWidget *MMSArrowWidget::copyWidget() {
00060     /* create widget */
00061     MMSArrowWidget *newWidget = new MMSArrowWidget(this->rootwindow, className);
00062 
00063     newWidget->className = this->className;
00064     newWidget->arrowWidgetClass = this->arrowWidgetClass;
00065     newWidget->myArrowWidgetClass = this->myArrowWidgetClass;
00066     newWidget->last_pressed = this->last_pressed;
00067     newWidget->current_fgset = this->current_fgset;
00068     newWidget->current_fgcolor = this->current_fgcolor;
00069 
00070     /* copy base widget */
00071     MMSWidget::copyWidget((MMSWidget*)newWidget);
00072 
00073     return newWidget;
00074 }
00075 
00076 bool MMSArrowWidget::init() {
00077     // init widget basics
00078     if (!MMSWidget::init())
00079         return false;
00080 
00081     return true;
00082 }
00083 
00084 bool MMSArrowWidget::release() {
00085     // release widget basics
00086     if (!MMSWidget::release())
00087         return false;
00088 
00089     return true;
00090 }
00091 
00092 void MMSArrowWidget::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 MMSArrowWidget::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 MMSArrowWidget::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 MMSArrowWidget::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     // lock
00146     this->surface->lock();
00147 
00148     // draw widget basics
00149     if (MMSWidget::draw(backgroundFilled)) {
00150 
00151         // draw my things
00152         MMSFBRectangle surfaceGeom = getSurfaceGeometry();
00153 
00154         // get color
00155         MMSFBColor color;
00156         getForeground(&color);
00157         this->current_fgcolor   = color;
00158         this->current_fgset     = true;
00159 
00160         if (color.a) {
00161             /* prepare for drawing */
00162             this->surface->setDrawingColorAndFlagsByBrightnessAndOpacity(color, getBrightness(), getOpacity());
00163 
00164             /* draw triangle */
00165             switch (getDirection()) {
00166                 case MMSDIRECTION_LEFT:
00167                 case MMSDIRECTION_NOTSET:
00168                     /* draw triangle */
00169                     this->surface->drawTriangle(
00170                                     surfaceGeom.x,                     surfaceGeom.y + surfaceGeom.h/2,
00171                                     surfaceGeom.x + surfaceGeom.w - 1, surfaceGeom.y,
00172                                     surfaceGeom.x + surfaceGeom.w - 1, surfaceGeom.y + surfaceGeom.h - 1 + (surfaceGeom.h % 2 - 1));
00173                     /* fill triangle */
00174                     this->surface->fillTriangle(
00175                                     surfaceGeom.x,                     surfaceGeom.y + surfaceGeom.h/2,
00176                                     surfaceGeom.x + surfaceGeom.w - 1, surfaceGeom.y,
00177                                     surfaceGeom.x + surfaceGeom.w - 1, surfaceGeom.y + surfaceGeom.h - 1 + (surfaceGeom.h % 2 - 1));
00178                     break;
00179                 case MMSDIRECTION_RIGHT:
00180                     /* draw triangle */
00181                     this->surface->drawTriangle(
00182                                     surfaceGeom.x + surfaceGeom.w - 1, surfaceGeom.y + surfaceGeom.h/2,
00183                                     surfaceGeom.x,                     surfaceGeom.y,
00184                                     surfaceGeom.x,                     surfaceGeom.y + surfaceGeom.h - 1 + (surfaceGeom.h % 2 - 1));
00185                     /* fill triangle */
00186                     this->surface->fillTriangle(
00187                                     surfaceGeom.x + surfaceGeom.w - 1, surfaceGeom.y + surfaceGeom.h/2,
00188                                     surfaceGeom.x,                     surfaceGeom.y,
00189                                     surfaceGeom.x,                     surfaceGeom.y + surfaceGeom.h - 1 + (surfaceGeom.h % 2 - 1));
00190                     break;
00191                 case MMSDIRECTION_UP:
00192                     /* draw triangle */
00193                     this->surface->drawTriangle(
00194                                     surfaceGeom.x + surfaceGeom.w/2,                            surfaceGeom.y,
00195                                     surfaceGeom.x,                                              surfaceGeom.y + surfaceGeom.h - 1,
00196                                     surfaceGeom.x + surfaceGeom.w - 1 + (surfaceGeom.w % 2 - 1),surfaceGeom.y + surfaceGeom.h - 1);
00197                     /* fill triangle */
00198                     this->surface->fillTriangle(
00199                                     surfaceGeom.x + surfaceGeom.w/2,                            surfaceGeom.y,
00200                                     surfaceGeom.x,                                              surfaceGeom.y + surfaceGeom.h - 1,
00201                                     surfaceGeom.x + surfaceGeom.w - 1 + (surfaceGeom.w % 2 - 1),surfaceGeom.y + surfaceGeom.h - 1);
00202                     break;
00203                 case MMSDIRECTION_DOWN:
00204                     /* draw triangle */
00205                     this->surface->drawTriangle(
00206                                     surfaceGeom.x + surfaceGeom.w/2,                            surfaceGeom.y + surfaceGeom.h - 1,
00207                                     surfaceGeom.x,                                              surfaceGeom.y,
00208                                     surfaceGeom.x + surfaceGeom.w - 1 + (surfaceGeom.w % 2 - 1),surfaceGeom.y);
00209                     /* fill triangle */
00210                     this->surface->fillTriangle(
00211                                     surfaceGeom.x + surfaceGeom.w/2,                            surfaceGeom.y + surfaceGeom.h - 1,
00212                                     surfaceGeom.x,                                              surfaceGeom.y,
00213                                     surfaceGeom.x + surfaceGeom.w - 1 + (surfaceGeom.w % 2 - 1),surfaceGeom.y);
00214                     break;
00215             }
00216         }
00217 
00218         /* update window surface with an area of surface */
00219         updateWindowSurfaceWithSurface(!*backgroundFilled);
00220     }
00221 
00222     /* unlock */
00223     this->surface->unlock();
00224 
00225     /* draw widgets debug frame */
00226     return MMSWidget::drawDebug();
00227 }
00228 
00229 
00230 void MMSArrowWidget::handleInput(MMSInputEvent *inputevent) {
00231     MMSWidget::handleInput(inputevent);
00232 
00233     if (inputevent->type == MMSINPUTEVENTTYPE_BUTTONPRESS) {
00234         this->last_pressed = isPressed();
00235     }
00236     else
00237     if (inputevent->type == MMSINPUTEVENTTYPE_BUTTONRELEASE) {
00238         if (this->last_pressed) {
00239             if (this->parent_rootwindow) {
00240                 bool submitinput = true;
00241                 if (getCheckSelected())
00242                     submitinput = (isSelected());
00243                 if (submitinput) {
00244                     // if selected the arrow widget submits an input event
00245                     // according to its direction
00246                     MMSInputEvent ievt;
00247                     ievt.type = MMSINPUTEVENTTYPE_KEYPRESS;
00248                     switch (getDirection()) {
00249                     case MMSDIRECTION_LEFT:
00250                         ievt.key = MMSKEY_CURSOR_LEFT;
00251                         break;
00252                     case MMSDIRECTION_RIGHT:
00253                         ievt.key = MMSKEY_CURSOR_RIGHT;
00254                         break;
00255                     case MMSDIRECTION_UP:
00256                         ievt.key = MMSKEY_CURSOR_UP;
00257                         break;
00258                     case MMSDIRECTION_DOWN:
00259                         ievt.key = MMSKEY_CURSOR_DOWN;
00260                         break;
00261                     default:
00262                         ievt.key = MMSKEY_UNKNOWN;
00263                         break;
00264                     }
00265                     if (ievt.key != MMSKEY_UNKNOWN) {
00266                         this->parent_rootwindow->handleInput(&ievt);
00267                     }
00268                 }
00269             }
00270             this->last_pressed = false;
00271         }
00272     }
00273     else
00274     if (inputevent->type == MMSINPUTEVENTTYPE_AXISMOTION) {
00275         this->last_pressed = isPressed();
00276     }
00277 }
00278 
00279 /***********************************************/
00280 /* begin of theme access methods (get methods) */
00281 /***********************************************/
00282 
00283 #define GETARROW(x) \
00284     if (this->myArrowWidgetClass.is##x()) return myArrowWidgetClass.get##x(); \
00285     else if ((arrowWidgetClass)&&(arrowWidgetClass->is##x())) return arrowWidgetClass->get##x(); \
00286     else return this->da->theme->arrowWidgetClass.get##x();
00287 
00288 MMSFBColor MMSArrowWidget::getColor() {
00289     GETARROW(Color);
00290 }
00291 
00292 MMSFBColor MMSArrowWidget::getSelColor() {
00293     GETARROW(SelColor);
00294 }
00295 
00296 MMSDIRECTION MMSArrowWidget::getDirection() {
00297     GETARROW(Direction);
00298 }
00299 
00300 bool MMSArrowWidget::getCheckSelected() {
00301     GETARROW(CheckSelected);
00302 }
00303 
00304 /***********************************************/
00305 /* begin of theme access methods (set methods) */
00306 /***********************************************/
00307 
00308 void MMSArrowWidget::setColor(MMSFBColor color, bool refresh) {
00309     myArrowWidgetClass.setColor(color);
00310 
00311     // refresh required?
00312     enableRefresh((color != this->current_fgcolor));
00313 
00314     this->refresh(refresh);
00315 }
00316 
00317 void MMSArrowWidget::setSelColor(MMSFBColor selcolor, bool refresh) {
00318     myArrowWidgetClass.setSelColor(selcolor);
00319 
00320     // refresh required?
00321     enableRefresh((selcolor != this->current_fgcolor));
00322 
00323     this->refresh(refresh);
00324 }
00325 
00326 void MMSArrowWidget::setDirection(MMSDIRECTION direction, bool refresh) {
00327     myArrowWidgetClass.setDirection(direction);
00328 
00329     // refresh is required
00330     enableRefresh();
00331 
00332     this->refresh(refresh);
00333 }
00334 
00335 void MMSArrowWidget::setCheckSelected(bool checkselected) {
00336     myArrowWidgetClass.setCheckSelected(checkselected);
00337 }
00338 
00339 void MMSArrowWidget::updateFromThemeClass(MMSArrowWidgetClass *themeClass) {
00340     if (themeClass->isColor())
00341         setColor(themeClass->getColor());
00342     if (themeClass->isSelColor())
00343         setSelColor(themeClass->getSelColor());
00344     if (themeClass->isDirection())
00345         setDirection(themeClass->getDirection());
00346     if (themeClass->isCheckSelected())
00347         setCheckSelected(themeClass->getCheckSelected());
00348 
00349     MMSWidget::updateFromThemeClass(&(themeClass->widgetClass));
00350 }
00351 
00352 /***********************************************/
00353 /* end of theme access methods                 */
00354 /***********************************************/

Generated by doxygen