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/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
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
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
00071 MMSWidget::copyWidget((MMSWidget*)newWidget);
00072
00073 return newWidget;
00074 }
00075
00076 bool MMSArrowWidget::init() {
00077
00078 if (!MMSWidget::init())
00079 return false;
00080
00081 return true;
00082 }
00083
00084 bool MMSArrowWidget::release() {
00085
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
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
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 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
00146 this->surface->lock();
00147
00148
00149 if (MMSWidget::draw(backgroundFilled)) {
00150
00151
00152 MMSFBRectangle surfaceGeom = getSurfaceGeometry();
00153
00154
00155 MMSFBColor color;
00156 getForeground(&color);
00157 this->current_fgcolor = color;
00158 this->current_fgset = true;
00159
00160 if (color.a) {
00161
00162 this->surface->setDrawingColorAndFlagsByBrightnessAndOpacity(color, getBrightness(), getOpacity());
00163
00164
00165 switch (getDirection()) {
00166 case MMSDIRECTION_LEFT:
00167 case MMSDIRECTION_NOTSET:
00168
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
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
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
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
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
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
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
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
00217 break;
00218 }
00219 }
00220
00221
00222 updateWindowSurfaceWithSurface(!*backgroundFilled);
00223 }
00224
00225
00226 this->surface->unlock();
00227
00228
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
00248
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
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
00309
00310
00311 void MMSArrowWidget::setColor(MMSFBColor color, bool refresh) {
00312 myArrowWidgetClass.setColor(color);
00313
00314
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
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
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
00357