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 #include "CEGUIRenderableFrame.h"
00027 #include "CEGUIImage.h"
00028 #include "CEGUIExceptions.h"
00029
00030
00031 namespace CEGUI
00032 {
00033
00034
00035
00036
00037 RenderableFrame::RenderableFrame(void)
00038 {
00039 d_left = d_right = d_top = d_bottom = NULL;
00040 d_topleft = d_topright = d_bottomleft = d_bottomright = NULL;
00041 }
00042
00043
00044
00045
00046
00047 RenderableFrame::~RenderableFrame(void)
00048 {
00049 }
00050
00051
00052
00053
00054
00055 void RenderableFrame::setImages(const Image* topleft, const Image* topright, const Image* bottomleft, const Image* bottomright, const Image* left, const Image* top, const Image* right, const Image* bottom)
00056 {
00057 d_topleft = topleft;
00058 d_topright = topright;
00059 d_bottomleft = bottomleft;
00060 d_bottomright = bottomright;
00061
00062 d_left = left;
00063 d_right = right;
00064 d_top = top;
00065 d_bottom = bottom;
00066 }
00067
00068
00069
00070
00071
00072 void RenderableFrame::draw_impl(const Vector3& position, const Rect& clip_rect) const
00073 {
00074 Vector3 final_pos(position);
00075 float org_width = d_area.getWidth(), org_height = d_area.getHeight();
00076 Size final_size;
00077 ColourRect final_colours(d_colours);
00078 bool calcColoursPerImage = !(d_useColoursPerImage || d_colours.isMonochromatic());
00079 float leftfactor, rightfactor, topfactor, bottomfactor;
00080
00081
00082 float coord_adj, size_adj;
00083
00084
00085 if (d_top != NULL) {
00086
00087
00088 if (d_topleft != NULL) {
00089 size_adj = (d_topleft->getWidth() - d_topleft->getOffsetX());
00090 coord_adj = d_topleft->getWidth();
00091 }
00092 else {
00093 coord_adj = 0;
00094 size_adj = 0;
00095 }
00096
00097
00098 if (d_topright != NULL) {
00099 size_adj += (d_topright->getWidth() + d_topright->getOffsetX());
00100 }
00101
00102 final_size.d_width = org_width - size_adj;
00103 final_size.d_height = d_top->getHeight();
00104 final_pos.d_x = position.d_x + coord_adj;
00105 final_pos.d_y = position.d_y;
00106
00107
00108 if (calcColoursPerImage)
00109 {
00110 leftfactor = (final_pos.d_x - position.d_x + d_top->getOffsetX()) / org_width;
00111 rightfactor = leftfactor + final_size.d_width / org_width;
00112 topfactor = (final_pos.d_y - position.d_y + d_top->getOffsetY()) / org_height;
00113 bottomfactor = topfactor + final_size.d_height / org_height;
00114
00115 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00116 }
00117
00118 d_top->draw(final_pos, final_size, clip_rect, final_colours);
00119 }
00120
00121
00122 if (d_bottom != NULL) {
00123
00124
00125 if (d_bottomleft != NULL) {
00126 size_adj = (d_bottomleft->getWidth() - d_bottomleft->getOffsetX());
00127 coord_adj = d_bottomleft->getWidth();
00128 }
00129 else {
00130 coord_adj = 0;
00131 size_adj = 0;
00132 }
00133
00134
00135 if (d_bottomright != NULL) {
00136 size_adj += (d_bottomright->getWidth() + d_bottomright->getOffsetX());
00137 }
00138
00139 final_size.d_width = org_width - size_adj;
00140 final_size.d_height = d_bottom->getHeight();
00141 final_pos.d_x = position.d_x + coord_adj;
00142 final_pos.d_y = position.d_y + org_height - final_size.d_height;
00143
00144
00145 if (calcColoursPerImage)
00146 {
00147 leftfactor = (final_pos.d_x - position.d_x + d_bottom->getOffsetX()) / org_width;
00148 rightfactor = leftfactor + final_size.d_width / org_width;
00149 topfactor = (final_pos.d_y - position.d_y + d_bottom->getOffsetY()) / org_height;
00150 bottomfactor = topfactor + final_size.d_height / org_height;
00151
00152 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00153 }
00154
00155 d_bottom->draw(final_pos, final_size, clip_rect, final_colours);
00156 }
00157
00158
00159 if (d_left != NULL) {
00160
00161
00162 if (d_topleft != NULL) {
00163 size_adj = (d_topleft->getHeight() - d_topleft->getOffsetY());
00164 coord_adj = d_topleft->getHeight();
00165 }
00166 else {
00167 coord_adj = 0;
00168 size_adj = 0;
00169 }
00170
00171
00172 if (d_bottomleft != NULL) {
00173 size_adj += (d_bottomleft->getHeight() + d_bottomleft->getOffsetY());
00174 }
00175
00176 final_size.d_height = org_height - size_adj;
00177 final_size.d_width = d_left->getWidth();
00178 final_pos.d_y = position.d_y + coord_adj;
00179 final_pos.d_x = position.d_x;
00180
00181
00182 if (calcColoursPerImage)
00183 {
00184 leftfactor = (final_pos.d_x - position.d_x + d_left->getOffsetX()) / org_width;
00185 rightfactor = leftfactor + final_size.d_width / org_width;
00186 topfactor = (final_pos.d_y - position.d_y + d_left->getOffsetY()) / org_height;
00187 bottomfactor = topfactor + final_size.d_height / org_height;
00188
00189 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00190 }
00191
00192 d_left->draw(final_pos, final_size, clip_rect, final_colours);
00193 }
00194
00195
00196 if (d_right != NULL) {
00197
00198
00199 if (d_topright != NULL) {
00200 size_adj = (d_topright->getHeight() - d_topright->getOffsetY());
00201 coord_adj = d_topright->getHeight();
00202 }
00203 else {
00204 coord_adj = 0;
00205 size_adj = 0;
00206 }
00207
00208
00209 if (d_bottomright != NULL) {
00210 size_adj += (d_bottomright->getHeight() + d_bottomright->getOffsetY());
00211 }
00212
00213
00214 final_size.d_height = org_height - size_adj;
00215 final_size.d_width = d_right->getWidth();
00216 final_pos.d_y = position.d_y + coord_adj;
00217 final_pos.d_x = position.d_x + org_width - final_size.d_width;
00218
00219
00220 if (calcColoursPerImage)
00221 {
00222 leftfactor = (final_pos.d_x - position.d_x + d_right->getOffsetX()) / org_width;
00223 rightfactor = leftfactor + final_size.d_width / org_width;
00224 topfactor = (final_pos.d_y - position.d_y + d_right->getOffsetY()) / org_height;
00225 bottomfactor = topfactor + final_size.d_height / org_height;
00226
00227 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00228 }
00229
00230 d_right->draw(final_pos, final_size, clip_rect, final_colours);
00231 }
00232
00233
00234 if (d_topleft != NULL) {
00235
00236
00237 if (calcColoursPerImage)
00238 {
00239 leftfactor = d_topleft->getOffsetX() / org_width;
00240 rightfactor = leftfactor + d_topleft->getWidth() / org_width;
00241 topfactor = d_topleft->getOffsetY() / org_height;
00242 bottomfactor = topfactor + d_topleft->getHeight() / org_height;
00243
00244 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00245 }
00246
00247 d_topleft->draw(position, clip_rect, final_colours);
00248 }
00249
00250 if (d_topright != NULL) {
00251 final_pos.d_x = position.d_x + org_width - d_topright->getWidth();
00252 final_pos.d_y = position.d_y;
00253
00254
00255 if (calcColoursPerImage)
00256 {
00257 leftfactor = (final_pos.d_x - position.d_x + d_topright->getOffsetX()) / org_width;
00258 rightfactor = leftfactor + d_topright->getWidth() / org_width;
00259 topfactor = (final_pos.d_y - position.d_y + d_topright->getOffsetY()) / org_height;
00260 bottomfactor = topfactor + d_topright->getHeight() / org_height;
00261
00262 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00263 }
00264
00265 d_topright->draw(final_pos, clip_rect, final_colours);
00266 }
00267
00268 if (d_bottomleft != NULL) {
00269 final_pos.d_x = position.d_x;
00270 final_pos.d_y = position.d_y + org_height - d_bottomleft->getHeight();
00271
00272
00273 if (calcColoursPerImage)
00274 {
00275 leftfactor = (final_pos.d_x - position.d_x + d_bottomleft->getOffsetX()) / org_width;
00276 rightfactor = leftfactor + d_bottomleft->getWidth() / org_width;
00277 topfactor = (final_pos.d_y - position.d_y + d_bottomleft->getOffsetY()) / org_height;
00278 bottomfactor = topfactor + d_bottomleft->getHeight() / org_height;
00279
00280 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00281 }
00282
00283 d_bottomleft->draw(final_pos, clip_rect, final_colours);
00284 }
00285
00286 if (d_bottomright != NULL) {
00287 final_pos.d_x = position.d_x + org_width - d_bottomright->getWidth();
00288 final_pos.d_y = position.d_y + org_height - d_bottomright->getHeight();
00289
00290
00291 if (calcColoursPerImage)
00292 {
00293 leftfactor = (final_pos.d_x - position.d_x + d_bottomright->getOffsetX()) / org_width;
00294 rightfactor = leftfactor + d_bottomright->getWidth() / org_width;
00295 topfactor = (final_pos.d_y - position.d_y + d_bottomright->getOffsetY()) / org_height;
00296 bottomfactor = topfactor + d_bottomright->getHeight() / org_height;
00297
00298 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00299 }
00300
00301 d_bottomright->draw(final_pos, clip_rect, final_colours);
00302 }
00303
00304 }
00305
00306
00307
00308
00309
00310 void RenderableFrame::setImageForLocation(FrameLocation location, const Image* image)
00311 {
00312 switch (location)
00313 {
00314 case TopLeftCorner:
00315 d_topleft = image;
00316 break;
00317
00318 case TopRightCorner:
00319 d_topright = image;
00320 break;
00321
00322 case BottomLeftCorner:
00323 d_bottomleft = image;
00324 break;
00325
00326 case BottomRightCorner:
00327 d_bottomright = image;
00328 break;
00329
00330 case LeftEdge:
00331 d_left = image;
00332 break;
00333
00334 case RightEdge:
00335 d_right = image;
00336 break;
00337
00338 case TopEdge:
00339 d_top = image;
00340 break;
00341
00342 case BottomEdge:
00343 d_bottom = image;
00344 break;
00345
00346 default:
00347 break;
00348 }
00349
00350 }
00351
00352
00353
00354
00355
00356 const Image* RenderableFrame::getImageForLocation(FrameLocation location) const
00357 {
00358 switch (location)
00359 {
00360 case TopLeftCorner:
00361 return d_topleft;
00362 break;
00363
00364 case TopRightCorner:
00365 return d_topright;
00366 break;
00367
00368 case BottomLeftCorner:
00369 return d_bottomleft;
00370 break;
00371
00372 case BottomRightCorner:
00373 return d_bottomright;
00374 break;
00375
00376 case LeftEdge:
00377 return d_left;
00378 break;
00379
00380 case RightEdge:
00381 return d_right;
00382 break;
00383
00384 case TopEdge:
00385 return d_top;
00386 break;
00387
00388 case BottomEdge:
00389 return d_bottom;
00390 break;
00391
00392 default:
00393 return NULL;
00394 break;
00395 }
00396
00397 }
00398
00399 void RenderableFrame::draw_impl(RenderCache& renderCache) const
00400 {
00401
00402
00403
00404 Rect destArea;
00405 Vector3 final_pos(0,0,0);
00406 float org_width = d_area.getWidth(), org_height = d_area.getHeight();
00407 Size final_size;
00408 ColourRect final_colours(d_colours);
00409 bool calcColoursPerImage = !(d_useColoursPerImage || d_colours.isMonochromatic());
00410 float leftfactor, rightfactor, topfactor, bottomfactor;
00411
00412
00413 float coord_adj, size_adj;
00414
00415
00416 if (d_top != NULL) {
00417
00418
00419 if (d_topleft != NULL) {
00420 size_adj = (d_topleft->getWidth() - d_topleft->getOffsetX());
00421 coord_adj = d_topleft->getWidth();
00422 }
00423 else {
00424 coord_adj = 0;
00425 size_adj = 0;
00426 }
00427
00428
00429 if (d_topright != NULL) {
00430 size_adj += (d_topright->getWidth() + d_topright->getOffsetX());
00431 }
00432
00433 final_size.d_width = org_width - size_adj;
00434 final_size.d_height = d_top->getHeight();
00435 final_pos.d_x = coord_adj;
00436 final_pos.d_y = 0;
00437
00438
00439 if (calcColoursPerImage)
00440 {
00441 leftfactor = (final_pos.d_x + d_top->getOffsetX()) / org_width;
00442 rightfactor = leftfactor + final_size.d_width / org_width;
00443 topfactor = (final_pos.d_y + d_top->getOffsetY()) / org_height;
00444 bottomfactor = topfactor + final_size.d_height / org_height;
00445
00446 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00447 }
00448
00449 destArea.d_left = final_pos.d_x;
00450 destArea.d_top = final_pos.d_y;
00451 destArea.d_right = final_pos.d_x + final_size.d_width;
00452 destArea.d_bottom = final_pos.d_y + final_size.d_height;
00453
00454 renderCache.cacheImage(*d_top, destArea, 0, final_colours);
00455 }
00456
00457
00458 if (d_bottom != NULL) {
00459
00460
00461 if (d_bottomleft != NULL) {
00462 size_adj = (d_bottomleft->getWidth() - d_bottomleft->getOffsetX());
00463 coord_adj = d_bottomleft->getWidth();
00464 }
00465 else {
00466 coord_adj = 0;
00467 size_adj = 0;
00468 }
00469
00470
00471 if (d_bottomright != NULL) {
00472 size_adj += (d_bottomright->getWidth() + d_bottomright->getOffsetX());
00473 }
00474
00475 final_size.d_width = org_width - size_adj;
00476 final_size.d_height = d_bottom->getHeight();
00477 final_pos.d_x = coord_adj;
00478 final_pos.d_y = org_height - final_size.d_height;
00479
00480
00481 if (calcColoursPerImage)
00482 {
00483 leftfactor = (final_pos.d_x + d_bottom->getOffsetX()) / org_width;
00484 rightfactor = leftfactor + final_size.d_width / org_width;
00485 topfactor = (final_pos.d_y + d_bottom->getOffsetY()) / org_height;
00486 bottomfactor = topfactor + final_size.d_height / org_height;
00487
00488 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00489 }
00490
00491 destArea.d_left = final_pos.d_x;
00492 destArea.d_top = final_pos.d_y;
00493 destArea.d_right = final_pos.d_x + final_size.d_width;
00494 destArea.d_bottom = final_pos.d_y + final_size.d_height;
00495
00496 renderCache.cacheImage(*d_bottom, destArea, 0, final_colours);
00497 }
00498
00499
00500 if (d_left != NULL) {
00501
00502
00503 if (d_topleft != NULL) {
00504 size_adj = (d_topleft->getHeight() - d_topleft->getOffsetY());
00505 coord_adj = d_topleft->getHeight();
00506 }
00507 else {
00508 coord_adj = 0;
00509 size_adj = 0;
00510 }
00511
00512
00513 if (d_bottomleft != NULL) {
00514 size_adj += (d_bottomleft->getHeight() + d_bottomleft->getOffsetY());
00515 }
00516
00517 final_size.d_height = org_height - size_adj;
00518 final_size.d_width = d_left->getWidth();
00519 final_pos.d_y = coord_adj;
00520 final_pos.d_x = 0;
00521
00522
00523 if (calcColoursPerImage)
00524 {
00525 leftfactor = (final_pos.d_x + d_left->getOffsetX()) / org_width;
00526 rightfactor = leftfactor + final_size.d_width / org_width;
00527 topfactor = (final_pos.d_y + d_left->getOffsetY()) / org_height;
00528 bottomfactor = topfactor + final_size.d_height / org_height;
00529
00530 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00531 }
00532
00533 destArea.d_left = final_pos.d_x;
00534 destArea.d_top = final_pos.d_y;
00535 destArea.d_right = final_pos.d_x + final_size.d_width;
00536 destArea.d_bottom = final_pos.d_y + final_size.d_height;
00537
00538 renderCache.cacheImage(*d_left, destArea, 0, final_colours);
00539 }
00540
00541
00542 if (d_right != NULL) {
00543
00544
00545 if (d_topright != NULL) {
00546 size_adj = (d_topright->getHeight() - d_topright->getOffsetY());
00547 coord_adj = d_topright->getHeight();
00548 }
00549 else {
00550 coord_adj = 0;
00551 size_adj = 0;
00552 }
00553
00554
00555 if (d_bottomright != NULL) {
00556 size_adj += (d_bottomright->getHeight() + d_bottomright->getOffsetY());
00557 }
00558
00559
00560 final_size.d_height = org_height - size_adj;
00561 final_size.d_width = d_right->getWidth();
00562 final_pos.d_y = coord_adj;
00563 final_pos.d_x = org_width - final_size.d_width;
00564
00565
00566 if (calcColoursPerImage)
00567 {
00568 leftfactor = (final_pos.d_x + d_right->getOffsetX()) / org_width;
00569 rightfactor = leftfactor + final_size.d_width / org_width;
00570 topfactor = (final_pos.d_y + d_right->getOffsetY()) / org_height;
00571 bottomfactor = topfactor + final_size.d_height / org_height;
00572
00573 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00574 }
00575
00576 destArea.d_left = final_pos.d_x;
00577 destArea.d_top = final_pos.d_y;
00578 destArea.d_right = final_pos.d_x + final_size.d_width;
00579 destArea.d_bottom = final_pos.d_y + final_size.d_height;
00580
00581 renderCache.cacheImage(*d_right, destArea, 0, final_colours);
00582 }
00583
00584
00585 if (d_topleft != NULL) {
00586
00587
00588 if (calcColoursPerImage)
00589 {
00590 leftfactor = d_topleft->getOffsetX() / org_width;
00591 rightfactor = leftfactor + d_topleft->getWidth() / org_width;
00592 topfactor = d_topleft->getOffsetY() / org_height;
00593 bottomfactor = topfactor + d_topleft->getHeight() / org_height;
00594
00595 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00596 }
00597
00598 destArea.d_left = 0;
00599 destArea.d_top = 0;
00600 destArea.d_right = d_topleft->getWidth();
00601 destArea.d_bottom = d_topleft->getHeight();
00602
00603 renderCache.cacheImage(*d_topleft, destArea, 0, final_colours);
00604 }
00605
00606 if (d_topright != NULL) {
00607 final_pos.d_x = org_width - d_topright->getWidth();
00608 final_pos.d_y = 0;
00609
00610
00611 if (calcColoursPerImage)
00612 {
00613 leftfactor = (final_pos.d_x + d_topright->getOffsetX()) / org_width;
00614 rightfactor = leftfactor + d_topright->getWidth() / org_width;
00615 topfactor = (final_pos.d_y + d_topright->getOffsetY()) / org_height;
00616 bottomfactor = topfactor + d_topright->getHeight() / org_height;
00617
00618 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00619 }
00620
00621 destArea.d_left = final_pos.d_x;
00622 destArea.d_top = final_pos.d_y;
00623 destArea.d_right = final_pos.d_x + d_topright->getWidth();
00624 destArea.d_bottom = final_pos.d_y + d_topright->getHeight();
00625
00626 renderCache.cacheImage(*d_topright, destArea, 0, final_colours);
00627 }
00628
00629 if (d_bottomleft != NULL) {
00630 final_pos.d_x = 0;
00631 final_pos.d_y = org_height - d_bottomleft->getHeight();
00632
00633
00634 if (calcColoursPerImage)
00635 {
00636 leftfactor = (final_pos.d_x + d_bottomleft->getOffsetX()) / org_width;
00637 rightfactor = leftfactor + d_bottomleft->getWidth() / org_width;
00638 topfactor = (final_pos.d_y + d_bottomleft->getOffsetY()) / org_height;
00639 bottomfactor = topfactor + d_bottomleft->getHeight() / org_height;
00640
00641 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00642 }
00643
00644 destArea.d_left = final_pos.d_x;
00645 destArea.d_top = final_pos.d_y;
00646 destArea.d_right = final_pos.d_x + d_bottomleft->getWidth();
00647 destArea.d_bottom = final_pos.d_y + d_bottomleft->getHeight();
00648
00649 renderCache.cacheImage(*d_bottomleft, destArea, 0, final_colours);
00650 }
00651
00652 if (d_bottomright != NULL) {
00653 final_pos.d_x = org_width - d_bottomright->getWidth();
00654 final_pos.d_y = org_height - d_bottomright->getHeight();
00655
00656
00657 if (calcColoursPerImage)
00658 {
00659 leftfactor = (final_pos.d_x + d_bottomright->getOffsetX()) / org_width;
00660 rightfactor = leftfactor + d_bottomright->getWidth() / org_width;
00661 topfactor = (final_pos.d_y + d_bottomright->getOffsetY()) / org_height;
00662 bottomfactor = topfactor + d_bottomright->getHeight() / org_height;
00663
00664 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00665 }
00666
00667 destArea.d_left = final_pos.d_x;
00668 destArea.d_top = final_pos.d_y;
00669 destArea.d_right = final_pos.d_x + d_bottomright->getWidth();
00670 destArea.d_bottom = final_pos.d_y + d_bottomright->getHeight();
00671
00672 renderCache.cacheImage(*d_bottomright, destArea, 0, final_colours);
00673 }
00674 }
00675
00676 }