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-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/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                 default:
00216                     // TODO: handle MMSDIRECTION_UP_LEFT, ...
00217                     break;
00218             }
00219         }
00220 
00221         /* update window surface with an area of surface */
00222         updateWindowSurfaceWithSurface(!*backgroundFilled);
00223     }
00224 
00225     /* unlock */
00226     this->surface->unlock();
00227 
00228     /* draw widgets debug frame */
00229     return MMSWidget::drawDebug();
00230 }
00231 
00232 
00233 void MMSArrowWidget::handleInput(MMSInputEvent *inputevent) {
00234     MMSWidget::handleInput(inputevent);
00235 
00236     if (inputevent->type == MMSINPUTEVENTTYPE_BUTTONPRESS) {
00237         this->last_pressed = isPressed();
00238     }
00239     else
00240     if (inputevent->type == MMSINPUTEVENTTYPE_BUTTONRELEASE) {
00241         if (this->last_pressed) {
00242             if (this->parent_rootwindow) {
00243                 bool submitinput = true;
00244                 if (getCheckSelected())
00245                     submitinput = (isSelected());
00246                 if (submitinput) {
00247                     // if selected the arrow widget submits an input event
00248                     // according to its direction
00249                     MMSInputEvent ievt;
00250                     ievt.type = MMSINPUTEVENTTYPE_KEYPRESS;
00251                     switch (getDirection()) {
00252                     case MMSDIRECTION_LEFT:
00253                         ievt.key = MMSKEY_CURSOR_LEFT;
00254                         break;
00255                     case MMSDIRECTION_RIGHT:
00256                         ievt.key = MMSKEY_CURSOR_RIGHT;
00257                         break;
00258                     case MMSDIRECTION_UP:
00259                         ievt.key = MMSKEY_CURSOR_UP;
00260                         break;
00261                     case MMSDIRECTION_DOWN:
00262                         ievt.key = MMSKEY_CURSOR_DOWN;
00263                         break;
00264                     default:
00265                         ievt.key = MMSKEY_UNKNOWN;
00266                         break;
00267                     }
00268                     if (ievt.key != MMSKEY_UNKNOWN) {
00269                         this->parent_rootwindow->handleInput(&ievt);
00270                     }
00271                 }
00272             }
00273             this->last_pressed = false;
00274         }
00275     }
00276     else
00277     if (inputevent->type == MMSINPUTEVENTTYPE_AXISMOTION) {
00278         this->last_pressed = isPressed();
00279     }
00280 }
00281 
00282 /***********************************************/
00283 /* begin of theme access methods (get methods) */
00284 /***********************************************/
00285 
00286 #define GETARROW(x) \
00287     if (this->myArrowWidgetClass.is##x()) return myArrowWidgetClass.get##x(); \
00288     else if ((arrowWidgetClass)&&(arrowWidgetClass->is##x())) return arrowWidgetClass->get##x(); \
00289     else return this->da->theme->arrowWidgetClass.get##x();
00290 
00291 MMSFBColor MMSArrowWidget::getColor() {
00292     GETARROW(Color);
00293 }
00294 
00295 MMSFBColor MMSArrowWidget::getSelColor() {
00296     GETARROW(SelColor);
00297 }
00298 
00299 MMSDIRECTION MMSArrowWidget::getDirection() {
00300     GETARROW(Direction);
00301 }
00302 
00303 bool MMSArrowWidget::getCheckSelected() {
00304     GETARROW(CheckSelected);
00305 }
00306 
00307 /***********************************************/
00308 /* begin of theme access methods (set methods) */
00309 /***********************************************/
00310 
00311 void MMSArrowWidget::setColor(MMSFBColor color, bool refresh) {
00312     myArrowWidgetClass.setColor(color);
00313 
00314     // refresh required?
00315     enableRefresh((color != this->current_fgcolor));
00316 
00317     this->refresh(refresh);
00318 }
00319 
00320 void MMSArrowWidget::setSelColor(MMSFBColor selcolor, bool refresh) {
00321     myArrowWidgetClass.setSelColor(selcolor);
00322 
00323     // refresh required?
00324     enableRefresh((selcolor != this->current_fgcolor));
00325 
00326     this->refresh(refresh);
00327 }
00328 
00329 void MMSArrowWidget::setDirection(MMSDIRECTION direction, bool refresh) {
00330     myArrowWidgetClass.setDirection(direction);
00331 
00332     // refresh is required
00333     enableRefresh();
00334 
00335     this->refresh(refresh);
00336 }
00337 
00338 void MMSArrowWidget::setCheckSelected(bool checkselected) {
00339     myArrowWidgetClass.setCheckSelected(checkselected);
00340 }
00341 
00342 void MMSArrowWidget::updateFromThemeClass(MMSArrowWidgetClass *themeClass) {
00343     if (themeClass->isColor())
00344         setColor(themeClass->getColor());
00345     if (themeClass->isSelColor())
00346         setSelColor(themeClass->getSelColor());
00347     if (themeClass->isDirection())
00348         setDirection(themeClass->getDirection());
00349     if (themeClass->isCheckSelected())
00350         setCheckSelected(themeClass->getCheckSelected());
00351 
00352     MMSWidget::updateFromThemeClass(&(themeClass->widgetClass));
00353 }
00354 
00355 /***********************************************/
00356 /* end of theme access methods                 */
00357 /***********************************************/

Generated by doxygen