00001 #ifdef WIN32
00002 #pragma warning(disable : 4786 )
00003 #endif
00004
00005 #include "CSBorder.h"
00006 #include "CSLAF.h"
00007 #include "CSHelper.h"
00008 #include "CSGrafikElement.h"
00009
00010 const char *CSBorder::CLASS = "CSBorder";
00011 const char *CSRoundedBorder::CLASS = "CSRoundedBorder";
00012
00013 CSBorder::CSBorder()
00014 {
00015 static char *functionName="CSBorder";
00016 LOG_ENTER
00017 mBorderOuterEdgeWidth = 0;
00018 mBorderInnerEdgeWidth = 0;
00019 mBorderInterEdgeWidth = 0;
00020 mState = BORDER_STATE_DEFAULT;
00021 LOG_EXIT
00022 }
00023
00024 void CSBorder::paint(SDL_Surface *destination, SDL_Rect *area)
00025 {
00026 static char *functionName="paint";
00027 CSLAF *laf = CSLAF::getCurrentLAF();
00028 int type = mType;
00029 if ((!(mState & BORDER_STATE_VISIBLE)) || (type == BORDER_TYPE_NONE))
00030 {
00031 return;
00032 }
00033
00034 mShadeBrighter = CSHelper::colorPercent(laf->getBorderDefaultBrightestColor(), 100);
00035 mShadeBright = CSHelper::colorPercent(laf->getBorderDefaultBrightestColor(), 70);
00036 mShadeDark = CSHelper::colorPercent(laf->getBorderDefaultBrightestColor(), 50);
00037 mShadeDarker = CSHelper::colorPercent(laf->getBorderDefaultBrightestColor(), 20);
00038
00039
00040 if (type & BORDER_TYPE_UP)
00041 {
00042
00043 if (mState & BORDER_STATE_PRESSED)
00044 {
00045
00046 type = type & (~BORDER_TYPE_UP);
00047 }
00048 else
00049 {
00050
00051 if (mState & BORDER_STATE_HOVERING)
00052 {
00053
00054 if (type & BORDER_TYPE_HOVER)
00055 {
00056
00057 type = type | BORDER_TYPE_UP;
00058 }
00059 else
00060 {
00061
00062 return;
00063
00064 }
00065 }
00066 else
00067 {
00068
00069 type = type | BORDER_TYPE_UP;
00070 }
00071 }
00072 }
00073 else
00074 {
00075 }
00076
00077
00078 SDL_Rect copy;
00079 int o = 0;
00080 if (type & BORDER_TYPE_UP)
00081 {
00082 if (mBorderOuterEdgeWidth)
00083 {
00084 SDL_Rect a = *area;
00085 a.x += o;
00086 a.y += o;
00087 a.h = mBorderOuterEdgeWidth;
00088 a.w = a.w - 2*o;
00089 if (a.w > 60000) a.w = 0;
00090 if (mType & BORDER_TYPE_SINGLE_COLOR)
00091 {
00092 copy = a;
00093 SDL_FillRect(destination, ©, COLOR(destination, mShadeDarker));
00094 a.y = area->h+area->y - (mBorderOuterEdgeWidth+o);
00095 copy = a;
00096 SDL_FillRect(destination, ©, COLOR(destination, mShadeDarker));
00097 }
00098 else
00099 {
00100 copy = a;
00101 SDL_FillRect(destination, ©, COLOR(destination, mShadeBrighter));
00102 a.y = area->h+area->y - (mBorderOuterEdgeWidth+o);
00103 copy = a;
00104 SDL_FillRect(destination, ©, COLOR(destination, mShadeDarker));
00105 }
00106
00107 a = *area;
00108 a.x += o;
00109 a.y += o;
00110 a.w = mBorderOuterEdgeWidth;
00111 a.h = a.h - 2*o;
00112 if (a.h > 60000) a.h = 0;
00113 if (mType & BORDER_TYPE_SINGLE_COLOR)
00114 {
00115 copy = a;
00116 SDL_FillRect(destination, ©, COLOR(destination, mShadeDarker));
00117 a.x = area->w+area->x - (mBorderOuterEdgeWidth +o);
00118 copy = a;
00119 SDL_FillRect(destination, ©, COLOR(destination, mShadeDarker));
00120 }
00121 else
00122 {
00123 copy = a;
00124 SDL_FillRect(destination, ©, COLOR(destination, mShadeDarker));
00125 a.x = area->w+area->x - (mBorderOuterEdgeWidth +o);
00126 copy = a;
00127 SDL_FillRect(destination, ©, COLOR(destination, mShadeBrighter));
00128 }
00129 }
00130 o+=mBorderOuterEdgeWidth;
00131 if (type & BORDER_TYPE_DOUBLE)
00132 {
00133
00134 if (mBorderInnerEdgeWidth)
00135 {
00136 SDL_Rect a = *area;
00137 a.x += o;
00138 a.y += o;
00139 a.h = mBorderInnerEdgeWidth;
00140 a.w = a.w - 2*o;
00141 if (a.w > 60000) a.w = 0;
00142 if (mType & BORDER_TYPE_SINGLE_COLOR)
00143 {
00144 copy = a;
00145 SDL_FillRect(destination, ©, COLOR(destination, mShadeDark));
00146 a.y = area->h+area->y - (mBorderInnerEdgeWidth+o);
00147 copy = a;
00148 SDL_FillRect(destination, ©, COLOR(destination, mShadeDark));
00149 }
00150 else
00151 {
00152 copy = a;
00153 SDL_FillRect(destination, ©, COLOR(destination, mShadeBright));
00154 a.y = area->h+area->y - (mBorderInnerEdgeWidth+o);
00155 copy = a;
00156 SDL_FillRect(destination, ©, COLOR(destination, mShadeDark));
00157 }
00158
00159 a = *area;
00160 a.x += o;
00161 a.y += o;
00162 a.w = mBorderInnerEdgeWidth;
00163 a.h = a.h - 2*o;
00164 if (a.h > 60000) a.h = 0;
00165 if (mType & BORDER_TYPE_SINGLE_COLOR)
00166 {
00167 copy = a;
00168 SDL_FillRect(destination, ©, COLOR(destination, mShadeDark));
00169 a.x = area->w+area->x - (mBorderInnerEdgeWidth +o);
00170 copy = a;
00171 SDL_FillRect(destination, ©, COLOR(destination, mShadeDark));
00172 }
00173 else
00174 {
00175 copy = a;
00176 SDL_FillRect(destination, ©, COLOR(destination, mShadeDark));
00177 a.x = area->w+area->x - (mBorderInnerEdgeWidth +o);
00178 copy = a;
00179 SDL_FillRect(destination, ©, COLOR(destination, mShadeBright));
00180 }
00181 }
00182 }
00183 o+=mBorderInnerEdgeWidth;
00184 if (type & BORDER_TYPE_INTER)
00185 {
00186 SDL_Rect a = *area;
00187 a.x += o + mBorderInterEdgeWidth;
00188 a.y += o + mBorderInterEdgeWidth;
00189 a.w = a.w - 2*o - (2*mBorderInterEdgeWidth);
00190 a.h = a.h - 2*o - (2*mBorderInterEdgeWidth);
00191 if (a.w > 60000) a.w = 0;
00192 if (a.h > 60000) a.h = 0;
00193
00194 int typeSave = type;
00195 type = type - BORDER_TYPE_INTER - BORDER_TYPE_UP;
00196 paint(destination, &a);
00197 type = typeSave;
00198 }
00199 }
00200 else
00201 {
00202 if (mBorderOuterEdgeWidth)
00203 {
00204 SDL_Rect a = *area;
00205 a.x += o;
00206 a.y += o;
00207 a.h = mBorderOuterEdgeWidth;
00208 a.w = a.w - 2*o;
00209 if (a.w > 60000) a.w = 0;
00210 copy = a;
00211 SDL_FillRect(destination, ©, COLOR(destination, mShadeDarker));
00212 a.y = area->h+area->y - (mBorderOuterEdgeWidth+o);
00213 copy = a;
00214 SDL_FillRect(destination, ©, COLOR(destination, mShadeBrighter));
00215
00216 a = *area;
00217 a.x += o;
00218 a.y += o;
00219 a.w = mBorderOuterEdgeWidth;
00220 a.h = a.h - 2*o;
00221 if (a.h > 60000) a.h = 0;
00222 copy = a;
00223 SDL_FillRect(destination, ©, COLOR(destination, mShadeBrighter));
00224 a.x = area->w+area->x - (mBorderOuterEdgeWidth +o);
00225 copy = a;
00226 SDL_FillRect(destination, ©, COLOR(destination, mShadeDarker));
00227 }
00228 o+=mBorderOuterEdgeWidth;
00229 if (type & BORDER_TYPE_DOUBLE)
00230 {
00231 if (mBorderInnerEdgeWidth)
00232 {
00233 SDL_Rect a = *area;
00234 a.x += o;
00235 a.y += o;
00236 a.h = mBorderInnerEdgeWidth;
00237 a.w = a.w - 2*o;
00238 if (a.w > 60000) a.w = 0;
00239 copy = a;
00240 SDL_FillRect(destination, ©, COLOR(destination, mShadeDark));
00241 a.y = area->h+area->y - (mBorderInnerEdgeWidth+o);
00242 copy = a;
00243 SDL_FillRect(destination, ©, COLOR(destination, mShadeBright));
00244
00245 a = *area;
00246 a.x += o;
00247 a.y += o;
00248 a.w = mBorderInnerEdgeWidth;
00249 a.h = a.h - 2*o;
00250 if (a.h > 60000) a.h = 0;
00251 copy = a;
00252 SDL_FillRect(destination, ©, COLOR(destination, mShadeBright));
00253 a.x = area->w+area->x - (mBorderInnerEdgeWidth +o);
00254 copy = a;
00255 SDL_FillRect(destination, ©, COLOR(destination, mShadeDark));
00256 }
00257 }
00258 if (type & BORDER_TYPE_INTER)
00259 {
00260 SDL_Rect a = *area;
00261 a.x += o + mBorderInterEdgeWidth;
00262 a.y += o + mBorderInterEdgeWidth;
00263 a.w = a.w - 2*o - (2*mBorderInterEdgeWidth);
00264 a.h = a.h - 2*o - (2*mBorderInterEdgeWidth);
00265 if (a.w > 60000) a.w = 0;
00266 if (a.h > 60000) a.h = 0;
00267
00268 int typeSave = type;
00269 type = type - BORDER_TYPE_INTER - BORDER_TYPE_UP;
00270 paint(destination, &a);
00271 type = typeSave;
00272 }
00273 o+=mBorderInnerEdgeWidth;
00274 }
00275 }
00276
00277 int CSBorder::getTotalWidth()
00278 {
00279 return getSizeEast() + getSizeWest();
00280 }
00281
00282 int CSBorder::getTotalHeight()
00283 {
00284 return getSizeSouth() + getSizeNorth();
00285 }
00286
00287 int CSBorder::getSizeSouth()
00288 {
00289 int size = 0;
00290 if (mType == BORDER_TYPE_NONE)
00291 {
00292 return 0;
00293 }
00294 if (mType & BORDER_TYPE_INTER)
00295 {
00296 size += mBorderInterEdgeWidth;
00297 }
00298 if (mType & BORDER_TYPE_DOUBLE)
00299 {
00300 size += mBorderInnerEdgeWidth;
00301 }
00302 size += mBorderOuterEdgeWidth;
00303 return size;
00304 }
00305
00306 int CSBorder::getSizeNorth()
00307 {
00308 int size = 0;
00309 if (mType == BORDER_TYPE_NONE)
00310 {
00311 return 0;
00312 }
00313 if (mType & BORDER_TYPE_INTER)
00314 {
00315 size += mBorderInterEdgeWidth;
00316 }
00317 if (mType & BORDER_TYPE_DOUBLE)
00318 {
00319 size += mBorderInnerEdgeWidth;
00320 }
00321 size += mBorderOuterEdgeWidth;
00322 return size;
00323 }
00324
00325 int CSBorder::getSizeEast()
00326 {
00327 int size = 0;
00328 if (mType == BORDER_TYPE_NONE)
00329 {
00330 return 0;
00331 }
00332 if (mType & BORDER_TYPE_INTER)
00333 {
00334 size += mBorderInterEdgeWidth;
00335 }
00336 if (mType & BORDER_TYPE_DOUBLE)
00337 {
00338 size += mBorderInnerEdgeWidth;
00339 }
00340 size += mBorderOuterEdgeWidth;
00341 return size;
00342 }
00343
00344 int CSBorder::getSizeWest()
00345 {
00346 int size = 0;
00347 if (mType == BORDER_TYPE_NONE)
00348 {
00349 return 0;
00350 }
00351 if (mType & BORDER_TYPE_INTER)
00352 {
00353 size += mBorderInterEdgeWidth;
00354 }
00355 if (mType & BORDER_TYPE_DOUBLE)
00356 {
00357 size += mBorderInnerEdgeWidth;
00358 }
00359 size += mBorderOuterEdgeWidth;
00360 return size;
00361 }
00362
00363 CSBorder *CSBorder::getBorder(int type)
00364 {
00365 CSBorder *border = new CSBorder();
00366 border->mType = type;
00367 if (border->mType == BORDER_TYPE_NONE)
00368 {
00369 border->mBorderOuterEdgeWidth = 0;
00370 border->mBorderInnerEdgeWidth = 0;
00371 border->mBorderInterEdgeWidth = 0;
00372 }
00373 else
00374 {
00375 border->mBorderOuterEdgeWidth = 1;
00376 border->mBorderInnerEdgeWidth = 1;
00377 border->mBorderInterEdgeWidth = 2;
00378 }
00379 return border;
00380 }
00381
00382 void CSRoundedBorder::paint(SDL_Surface *destination, SDL_Rect *area)
00383 {
00384 static char *functionName="paint";
00385 CSLAF *laf = CSLAF::getCurrentLAF();
00386 int type = mType;
00387 if ((!(mState & BORDER_STATE_VISIBLE)) || (type == BORDER_TYPE_NONE))
00388 {
00389 return;
00390 }
00391
00392 mShadeBrighter = CSHelper::colorPercent(laf->getBorderDefaultBrightestColor(), 100);
00393 mShadeBright = CSHelper::colorPercent(laf->getBorderDefaultBrightestColor(), 70);
00394 mShadeDark = CSHelper::colorPercent(laf->getBorderDefaultBrightestColor(), 50);
00395 mShadeDarker = CSHelper::colorPercent(laf->getBorderDefaultBrightestColor(), 20);
00396
00397
00398 if (type & BORDER_TYPE_UP)
00399 {
00400
00401 if (mState & BORDER_STATE_PRESSED)
00402 {
00403
00404 type = type & (~BORDER_TYPE_UP);
00405 }
00406 else
00407 {
00408
00409 if (mState & BORDER_STATE_HOVERING)
00410 {
00411
00412 if (type & BORDER_TYPE_HOVER)
00413 {
00414
00415 type = type | BORDER_TYPE_UP;
00416 }
00417 else
00418 {
00419
00420 return;
00421
00422 }
00423 }
00424 else
00425 {
00426
00427 type = type | BORDER_TYPE_UP;
00428 }
00429 }
00430 }
00431 else
00432 {
00433 }
00434
00435
00436 SDL_Rect copy;
00437 int o = 0;
00438 if (type & BORDER_TYPE_UP)
00439 {
00440 if (mBorderOuterEdgeWidth)
00441 {
00442 SDL_Rect a = *area;
00443 a.x += o;
00444 a.y += o;
00445 a.h = area->h;
00446 a.w = a.w - 2*o;
00447 if (a.w > 60000) a.w = 0;
00448 copy = a;
00449 if (mType & BORDER_TYPE_SINGLE_COLOR)
00450 {
00451 SDLMain::DrawRoundRectNorth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDarker), mCorner, mBorderOuterEdgeWidth);
00452 SDLMain::DrawRoundRectSouth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDarker), mCorner, mBorderOuterEdgeWidth);
00453 SDLMain::DrawRoundRectWest(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDarker), mCorner, mBorderOuterEdgeWidth);
00454 SDLMain::DrawRoundRectEast(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDarker), mCorner, mBorderOuterEdgeWidth);
00455 }
00456 else
00457 {
00458 SDLMain::DrawRoundRectNorth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeBrighter), mCorner, mBorderOuterEdgeWidth);
00459 SDLMain::DrawRoundRectSouth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDarker), mCorner, mBorderOuterEdgeWidth);
00460 SDLMain::DrawRoundRectWest(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDarker), mCorner, mBorderOuterEdgeWidth);
00461 SDLMain::DrawRoundRectEast(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeBrighter), mCorner, mBorderOuterEdgeWidth);
00462 }
00463 }
00464 o+=mBorderOuterEdgeWidth;
00465 if (type & BORDER_TYPE_DOUBLE)
00466 {
00467 if (mBorderInnerEdgeWidth)
00468 {
00469 SDL_Rect a = *area;
00470 a.x += o;
00471 a.y += o;
00472 a.h = a.h - 2*o;
00473 a.w = a.w - 2*o;
00474 if (a.w > 60000) a.w = 0;
00475 copy = a;
00476 if (mType & BORDER_TYPE_SINGLE_COLOR)
00477 {
00478 SDLMain::DrawRoundRectNorth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDark), mCorner, mBorderInnerEdgeWidth);
00479 SDLMain::DrawRoundRectSouth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDark), mCorner, mBorderInnerEdgeWidth);
00480 SDLMain::DrawRoundRectWest(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDark), mCorner, mBorderInnerEdgeWidth);
00481 SDLMain::DrawRoundRectEast(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDark), mCorner, mBorderInnerEdgeWidth);
00482 }
00483 else
00484 {
00485 SDLMain::DrawRoundRectNorth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeBright), mCorner, mBorderInnerEdgeWidth);
00486 SDLMain::DrawRoundRectSouth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDark), mCorner, mBorderInnerEdgeWidth);
00487 SDLMain::DrawRoundRectWest(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDark), mCorner, mBorderInnerEdgeWidth);
00488 SDLMain::DrawRoundRectEast(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeBright), mCorner, mBorderInnerEdgeWidth);
00489 }
00490 }
00491 }
00492
00493 o+=mBorderInnerEdgeWidth;
00494 if (type & BORDER_TYPE_INTER)
00495 {
00496 SDL_Rect a = *area;
00497 a.x += o + mBorderInterEdgeWidth;
00498 a.y += o + mBorderInterEdgeWidth;
00499 a.w = a.w - 2*o - (2*mBorderInterEdgeWidth);
00500 a.h = a.h - 2*o - (2*mBorderInterEdgeWidth);
00501 if (a.w > 60000) a.w = 0;
00502 if (a.h > 60000) a.h = 0;
00503
00504 int typeSave = type;
00505 type = type - BORDER_TYPE_INTER - BORDER_TYPE_UP;
00506 paint(destination, &a);
00507 type = typeSave;
00508 }
00509 }
00510 else
00511 {
00512 if (mBorderOuterEdgeWidth)
00513 {
00514 SDL_Rect a = *area;
00515 a.x += o;
00516 a.y += o;
00517 a.h = area->h;
00518 a.w = a.w - 2*o;
00519 if (a.w > 60000) a.w = 0;
00520 copy = a;
00521 SDLMain::DrawRoundRectNorth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDarker), mCorner, mBorderOuterEdgeWidth);
00522 SDLMain::DrawRoundRectSouth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeBrighter), mCorner, mBorderOuterEdgeWidth);
00523 SDLMain::DrawRoundRectWest(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeBrighter), mCorner, mBorderOuterEdgeWidth);
00524 SDLMain::DrawRoundRectEast(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDarker), mCorner, mBorderOuterEdgeWidth);
00525 }
00526 o+=mBorderOuterEdgeWidth;
00527 if (type & BORDER_TYPE_DOUBLE)
00528 {
00529 if (mBorderInnerEdgeWidth)
00530 {
00531 SDL_Rect a = *area;
00532 a.x += o;
00533 a.y += o;
00534 a.h = a.h - 2*o;
00535 a.w = a.w - 2*o;
00536 if (a.w > 60000) a.w = 0;
00537 copy = a;
00538 SDLMain::DrawRoundRectNorth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDark), mCorner, mBorderOuterEdgeWidth);
00539 SDLMain::DrawRoundRectSouth(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeBright), mCorner, mBorderOuterEdgeWidth);
00540 SDLMain::DrawRoundRectWest(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeBright), mCorner, mBorderOuterEdgeWidth);
00541 SDLMain::DrawRoundRectEast(destination, copy.x, copy.y, copy.w, copy.h, COLOR(destination, mShadeDark), mCorner, mBorderOuterEdgeWidth);
00542 }
00543 }
00544 if (type & BORDER_TYPE_INTER)
00545 {
00546 SDL_Rect a = *area;
00547 a.x += o + mBorderInterEdgeWidth;
00548 a.y += o + mBorderInterEdgeWidth;
00549 a.w = a.w - 2*o - (2*mBorderInterEdgeWidth);
00550 a.h = a.h - 2*o - (2*mBorderInterEdgeWidth);
00551 if (a.w > 60000) a.w = 0;
00552 if (a.h > 60000) a.h = 0;
00553
00554 int typeSave = type;
00555 type = type - BORDER_TYPE_INTER - BORDER_TYPE_UP;
00556 paint(destination, &a);
00557 type = typeSave;
00558 }
00559 o+=mBorderInnerEdgeWidth;
00560 }
00561 }
00562
00563
00564 CSRoundedBorder *CSRoundedBorder::getBorder(int type)
00565 {
00566 CSRoundedBorder *border = new CSRoundedBorder();
00567 border->mType = type;
00568 if (border->mType == BORDER_TYPE_NONE)
00569 {
00570 border->mBorderOuterEdgeWidth = 0;
00571 border->mBorderInnerEdgeWidth = 0;
00572 border->mBorderInterEdgeWidth = 0;
00573 }
00574 else
00575 {
00576 border->mBorderOuterEdgeWidth = 1;
00577 border->mBorderInnerEdgeWidth = 1;
00578 border->mBorderInterEdgeWidth = 2;
00579 }
00580 return border;
00581 }