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
00029
00030 namespace CEGUI
00031 {
00032
00033
00034
00035
00036 RenderableFrame::RenderableFrame(void)
00037 {
00038 d_left = d_right = d_top = d_bottom = NULL;
00039 d_topleft = d_topright = d_bottomleft = d_bottomright = NULL;
00040 }
00041
00042
00043
00044
00045
00046 RenderableFrame::~RenderableFrame(void)
00047 {
00048 }
00049
00050
00051
00052
00053
00054 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)
00055 {
00056 d_topleft = topleft;
00057 d_topright = topright;
00058 d_bottomleft = bottomleft;
00059 d_bottomright = bottomright;
00060
00061 d_left = left;
00062 d_right = right;
00063 d_top = top;
00064 d_bottom = bottom;
00065 }
00066
00067
00068
00069
00070
00071 void RenderableFrame::draw_impl(const Vector3& position, const Rect& clip_rect) const
00072 {
00073 Vector3 final_pos(position);
00074 float org_width = d_area.getWidth(), org_height = d_area.getHeight();
00075 Size final_size;
00076 ColourRect final_colours;
00077 float leftfactor, rightfactor, topfactor, bottomfactor;
00078
00079
00080 float coord_adj, size_adj;
00081
00082
00083 if (d_top != NULL) {
00084
00085
00086 if (d_topleft != NULL) {
00087 size_adj = (d_topleft->getWidth() - d_topleft->getOffsetX());
00088 coord_adj = d_topleft->getWidth();
00089 }
00090 else {
00091 coord_adj = 0;
00092 size_adj = 0;
00093 }
00094
00095
00096 if (d_topright != NULL) {
00097 size_adj += (d_topright->getWidth() + d_topright->getOffsetX());
00098 }
00099
00100 final_size.d_width = org_width - size_adj;
00101 final_size.d_height = d_top->getHeight();
00102 final_pos.d_x = position.d_x + coord_adj;
00103
00104
00105 if (d_useColoursPerImage)
00106 {
00107 final_colours = d_colours;
00108 }
00109 else
00110 {
00111 leftfactor = (final_pos.d_x - position.d_x) / org_width;
00112 rightfactor = (final_pos.d_x + final_size.d_width - position.d_x) / org_width;
00113 topfactor = (final_pos.d_y - position.d_y) / org_height;
00114 bottomfactor = (final_pos.d_y + final_size.d_height - position.d_y) / org_height;
00115 if( rightfactor > 1 ) rightfactor = 1;
00116 if( bottomfactor > 1 ) bottomfactor = 1;
00117
00118 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00119 }
00120
00121 d_top->draw(final_pos, final_size, clip_rect, final_colours);
00122 }
00123
00124
00125 if (d_bottom != NULL) {
00126
00127
00128 if (d_bottomleft != NULL) {
00129 size_adj = (d_bottomleft->getWidth() - d_bottomleft->getOffsetX());
00130 coord_adj = d_bottomleft->getWidth();
00131 }
00132 else {
00133 coord_adj = 0;
00134 size_adj = 0;
00135 }
00136
00137
00138 if (d_bottomright != NULL) {
00139 size_adj += (d_bottomright->getWidth() + d_bottomright->getOffsetX());
00140 }
00141
00142 final_size.d_width = org_width - size_adj;
00143 final_size.d_height = d_bottom->getHeight();
00144 final_pos.d_x = position.d_x + coord_adj;
00145 final_pos.d_y = position.d_y + org_height - final_size.d_height;
00146
00147
00148 if (d_useColoursPerImage)
00149 {
00150 final_colours = d_colours;
00151 }
00152 else
00153 {
00154 leftfactor = (final_pos.d_x - position.d_x) / org_width;
00155 rightfactor = (final_pos.d_x + final_size.d_width - position.d_x) / org_width;
00156 topfactor = (final_pos.d_y - position.d_y) / org_height;
00157 bottomfactor = (final_pos.d_y + final_size.d_height - position.d_y) / org_height;
00158 if( rightfactor > 1 ) rightfactor = 1;
00159 if( bottomfactor > 1 ) bottomfactor = 1;
00160
00161 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00162 }
00163
00164 d_bottom->draw(final_pos, final_size, clip_rect, final_colours);
00165 }
00166
00167
00168 final_pos.d_x = position.d_x;
00169
00170
00171 if (d_left != NULL) {
00172
00173
00174 if (d_topleft != NULL) {
00175 size_adj = (d_topleft->getHeight() - d_topleft->getOffsetY());
00176 coord_adj = d_topleft->getHeight();
00177 }
00178 else {
00179 coord_adj = 0;
00180 size_adj = 0;
00181 }
00182
00183
00184 if (d_bottomleft != NULL) {
00185 size_adj += (d_bottomleft->getHeight() + d_bottomleft->getOffsetY());
00186 }
00187
00188 final_size.d_height = org_height - size_adj;
00189 final_size.d_width = d_left->getWidth();
00190 final_pos.d_y = position.d_y + coord_adj;
00191
00192
00193 if (d_useColoursPerImage)
00194 {
00195 final_colours = d_colours;
00196 }
00197 else
00198 {
00199 leftfactor = (final_pos.d_x - position.d_x) / org_width;
00200 rightfactor = (final_pos.d_x + final_size.d_width - position.d_x) / org_width;
00201 topfactor = (final_pos.d_y - position.d_y) / org_height;
00202 bottomfactor = (final_pos.d_y + final_size.d_height - position.d_y) / org_height;
00203 if( rightfactor > 1 ) rightfactor = 1;
00204 if( bottomfactor > 1 ) bottomfactor = 1;
00205
00206 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00207 }
00208
00209 d_left->draw(final_pos, final_size, clip_rect, final_colours);
00210 }
00211
00212
00213 if (d_right != NULL) {
00214
00215
00216 if (d_topright != NULL) {
00217 size_adj = (d_topright->getHeight() - d_topright->getOffsetY());
00218 coord_adj = d_topright->getHeight();
00219 }
00220 else {
00221 coord_adj = 0;
00222 size_adj = 0;
00223 }
00224
00225
00226 if (d_bottomright != NULL) {
00227 size_adj += (d_bottomright->getHeight() + d_bottomright->getOffsetY());
00228 }
00229
00230
00231 final_size.d_height = org_height - size_adj;
00232 final_size.d_width = d_right->getWidth();
00233 final_pos.d_y = position.d_y + coord_adj;
00234 final_pos.d_x = position.d_x + org_width - final_size.d_width;
00235
00236
00237 if (d_useColoursPerImage)
00238 {
00239 final_colours = d_colours;
00240 }
00241 else
00242 {
00243 leftfactor = (final_pos.d_x - position.d_x) / org_width;
00244 rightfactor = (final_pos.d_x + final_size.d_width - position.d_x) / org_width;
00245 topfactor = (final_pos.d_y - position.d_y) / org_height;
00246 bottomfactor = (final_pos.d_y + final_size.d_height - position.d_y) / org_height;
00247 if( rightfactor > 1 ) rightfactor = 1;
00248 if( bottomfactor > 1 ) bottomfactor = 1;
00249
00250 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00251 }
00252
00253 d_right->draw(final_pos, final_size, clip_rect, final_colours);
00254 }
00255
00256
00257 if (d_topleft != NULL) {
00258
00259
00260 if (d_useColoursPerImage)
00261 {
00262 final_colours = d_colours;
00263 }
00264 else
00265 {
00266 leftfactor = 0;
00267 rightfactor = (d_topleft->getWidth()) / org_width;
00268 topfactor = 0;
00269 bottomfactor = (d_topleft->getHeight()) / org_height;
00270 if( rightfactor > 1 ) rightfactor = 1;
00271 if( bottomfactor > 1 ) bottomfactor = 1;
00272
00273 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00274 }
00275
00276 d_topleft->draw(position, clip_rect, final_colours);
00277 }
00278
00279 if (d_topright != NULL) {
00280 final_pos.d_x = position.d_x + org_width - d_topright->getWidth();
00281 final_pos.d_y = position.d_y;
00282
00283
00284 if (d_useColoursPerImage)
00285 {
00286 final_colours = d_colours;
00287 }
00288 else
00289 {
00290 leftfactor = (final_pos.d_x - position.d_x) / org_width;
00291 rightfactor = (final_pos.d_x + d_topright->getWidth() - position.d_x) / org_width;
00292 topfactor = (final_pos.d_y - position.d_y) / org_height;
00293 bottomfactor = (final_pos.d_y + d_topright->getHeight() - position.d_y) / org_height;
00294 if( rightfactor > 1 ) rightfactor = 1;
00295 if( bottomfactor > 1 ) bottomfactor = 1;
00296
00297 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00298 }
00299
00300 d_topright->draw(final_pos, clip_rect, final_colours);
00301 }
00302
00303 if (d_bottomleft != NULL) {
00304 final_pos.d_x = position.d_x;
00305 final_pos.d_y = position.d_y + org_height - d_bottomleft->getHeight();
00306
00307
00308 if (d_useColoursPerImage)
00309 {
00310 final_colours = d_colours;
00311 }
00312 else
00313 {
00314 leftfactor = (final_pos.d_x - position.d_x) / org_width;
00315 rightfactor = (final_pos.d_x + d_bottomleft->getWidth() - position.d_x) / org_width;
00316 topfactor = (final_pos.d_y - position.d_y) / org_height;
00317 bottomfactor = (final_pos.d_y + d_bottomleft->getHeight() - position.d_y) / org_height;
00318 if( rightfactor > 1 ) rightfactor = 1;
00319 if( bottomfactor > 1 ) bottomfactor = 1;
00320
00321 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00322 }
00323
00324 d_bottomleft->draw(final_pos, clip_rect, final_colours);
00325 }
00326
00327 if (d_bottomright != NULL) {
00328 final_pos.d_x = position.d_x + org_width - d_bottomright->getWidth();
00329 final_pos.d_y = position.d_y + org_height - d_bottomright->getHeight();
00330
00331
00332 if (d_useColoursPerImage)
00333 {
00334 final_colours = d_colours;
00335 }
00336 else
00337 {
00338 leftfactor = (final_pos.d_x - position.d_x) / org_width;
00339 rightfactor = (final_pos.d_x + d_bottomright->getWidth() - position.d_x) / org_width;
00340 topfactor = (final_pos.d_y - position.d_y) / org_height;
00341 bottomfactor = (final_pos.d_y + d_bottomright->getHeight() - position.d_y) / org_height;
00342 if( rightfactor > 1 ) rightfactor = 1;
00343 if( bottomfactor > 1 ) bottomfactor = 1;
00344
00345 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00346 }
00347
00348 d_bottomright->draw(final_pos, clip_rect, final_colours);
00349 }
00350
00351 }
00352
00353
00354
00355
00356
00357 void RenderableFrame::setImageForLocation(FrameLocation location, const Image* image)
00358 {
00359 switch (location)
00360 {
00361 case TopLeftCorner:
00362 d_topleft = image;
00363 break;
00364
00365 case TopRightCorner:
00366 d_topright = image;
00367 break;
00368
00369 case BottomLeftCorner:
00370 d_bottomleft = image;
00371 break;
00372
00373 case BottomRightCorner:
00374 d_bottomright = image;
00375 break;
00376
00377 case LeftEdge:
00378 d_left = image;
00379 break;
00380
00381 case RightEdge:
00382 d_right = image;
00383 break;
00384
00385 case TopEdge:
00386 d_top = image;
00387 break;
00388
00389 case BottomEdge:
00390 d_bottom = image;
00391 break;
00392
00393 default:
00394 break;
00395 }
00396
00397 }
00398
00399
00400
00401
00402
00403 const Image* RenderableFrame::getImageForLocation(FrameLocation location) const
00404 {
00405 switch (location)
00406 {
00407 case TopLeftCorner:
00408 return d_topleft;
00409 break;
00410
00411 case TopRightCorner:
00412 return d_topright;
00413 break;
00414
00415 case BottomLeftCorner:
00416 return d_bottomleft;
00417 break;
00418
00419 case BottomRightCorner:
00420 return d_bottomright;
00421 break;
00422
00423 case LeftEdge:
00424 return d_left;
00425 break;
00426
00427 case RightEdge:
00428 return d_right;
00429 break;
00430
00431 case TopEdge:
00432 return d_top;
00433 break;
00434
00435 case BottomEdge:
00436 return d_bottom;
00437 break;
00438
00439 default:
00440 return NULL;
00441 break;
00442 }
00443
00444 }
00445
00446
00447 }