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 "elements/CEGUIStatic.h"
00027 #include "CEGUIImagesetManager.h"
00028 #include "CEGUIImageset.h"
00029
00030
00031
00032 namespace CEGUI
00033 {
00034 const String Static::EventNamespace("Static");
00035
00036
00037
00038
00039 StaticProperties::FrameEnabled Static::d_frameEnabledProperty;
00040 StaticProperties::BackgroundEnabled Static::d_backgroundEnabledProperty;
00041 StaticProperties::FrameColours Static::d_frameColoursProperty;
00042 StaticProperties::BackgroundColours Static::d_backgroundColoursProperty;
00043 StaticProperties::BackgroundImage Static::d_backgroundImageProperty;
00044 StaticProperties::TopLeftFrameImage Static::d_topLeftFrameProperty;
00045 StaticProperties::TopRightFrameImage Static::d_topRightFrameProperty;
00046 StaticProperties::BottomLeftFrameImage Static::d_bottomLeftFrameProperty;
00047 StaticProperties::BottomRightFrameImage Static::d_bottomRightFrameProperty;
00048 StaticProperties::LeftFrameImage Static::d_leftFrameProperty;
00049 StaticProperties::RightFrameImage Static::d_rightFrameProperty;
00050 StaticProperties::TopFrameImage Static::d_topFrameProperty;
00051 StaticProperties::BottomFrameImage Static::d_bottomFrameProperty;
00052
00053
00054
00055
00056
00057 Static::Static(const String& type, const String& name) :
00058 Window(type, name),
00059 d_frameEnabled(false),
00060 d_frameCols(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF),
00061 d_backgroundEnabled(false),
00062 d_backgroundCols(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF),
00063 d_background(NULL),
00064 d_left_width(0),
00065 d_right_width(0),
00066 d_top_height(0),
00067 d_bottom_height(0)
00068 {
00069 addStaticProperties();
00070 }
00071
00072
00073
00074
00075
00076 Static::~Static(void)
00077 {
00078 }
00079
00080
00081
00082
00083
00084
00085 Rect Static::getUnclippedInnerRect(void) const
00086 {
00087
00088 if (d_frameEnabled)
00089 {
00090 Rect tmp(Window::getUnclippedInnerRect());
00091 tmp.d_left += d_left_width;
00092 tmp.d_right -= d_right_width;
00093 tmp.d_top += d_top_height;
00094 tmp.d_bottom -= d_bottom_height;
00095 return tmp;
00096 }
00097
00098 else
00099 {
00100 return Window::getUnclippedInnerRect();
00101 }
00102
00103 }
00104
00105
00106
00107
00108
00109 void Static::setFrameEnabled(bool setting)
00110 {
00111 if (d_frameEnabled != setting)
00112 {
00113 d_frameEnabled = setting;
00114 WindowEventArgs args(this);
00115 onStaticFrameChanged(args);
00116 requestRedraw();
00117 }
00118 }
00119
00120
00121
00122
00123
00124
00125 void Static::setFrameImages(const Image* topleft, const Image* topright, const Image* bottomleft, const Image* bottomright, const Image* left, const Image* top, const Image* right, const Image* bottom)
00126 {
00127
00128 d_frame.setImages(topleft, topright, bottomleft, bottomright, left, top, right, bottom);
00129
00130
00131 d_left_width = (left != NULL) ? left->getWidth() : 0.0f;
00132 d_right_width = (right != NULL) ? right->getWidth() : 0.0f;
00133 d_top_height = (top != NULL) ? top->getHeight() : 0.0f;
00134 d_bottom_height = (bottom != NULL) ? bottom->getHeight() : 0.0f;
00135
00136
00137 if (d_frameEnabled)
00138 {
00139 WindowEventArgs args(this);
00140 onStaticFrameChanged(args);
00141 requestRedraw();
00142 }
00143
00144 }
00145
00146
00147
00148
00149
00150 void Static::setFrameColours(const ColourRect& colours)
00151 {
00152 d_frameCols = colours;
00153 updateRenderableFrameColours();
00154
00155
00156 if (d_frameEnabled)
00157 {
00158 WindowEventArgs args(this);
00159 onStaticFrameChanged(args);
00160 requestRedraw();
00161 }
00162
00163 }
00164
00165
00166
00167
00168
00169 void Static::setFrameColours(const colour& top_left_colour, const colour& top_right_colour, const colour& bottom_left_colour, const colour& bottom_right_colour)
00170 {
00171 d_frameCols.d_top_left = top_left_colour;
00172 d_frameCols.d_top_right = top_right_colour;
00173 d_frameCols.d_bottom_left = bottom_left_colour;
00174 d_frameCols.d_bottom_right = bottom_right_colour;
00175 updateRenderableFrameColours();
00176
00177
00178 if (d_frameEnabled)
00179 {
00180 WindowEventArgs args(this);
00181 onStaticFrameChanged(args);
00182 requestRedraw();
00183 }
00184
00185 }
00186
00187
00188
00189
00190
00191 void Static::setBackgroundEnabled(bool setting)
00192 {
00193 if (d_backgroundEnabled != setting)
00194 {
00195 d_backgroundEnabled = setting;
00196 requestRedraw();
00197 }
00198
00199 }
00200
00201
00202
00203
00204
00205 void Static::setBackgroundImage(const Image* image)
00206 {
00207 d_background = image;
00208
00209 if (d_backgroundEnabled)
00210 {
00211 requestRedraw();
00212 }
00213
00214 }
00215
00216
00217
00218
00219
00220 void Static::setBackgroundImage(const String& imageset, const String& image)
00221 {
00222 setBackgroundImage(&ImagesetManager::getSingleton().getImageset(imageset)->getImage(image));
00223 }
00224
00225
00226
00227
00228
00229 void Static::setBackgroundColours(const ColourRect& colours)
00230 {
00231 d_backgroundCols = colours;
00232
00233 if (d_backgroundEnabled)
00234 {
00235 requestRedraw();
00236 }
00237
00238 }
00239
00240
00241
00242
00243
00244 void Static::setBackgroundColours(const colour& top_left_colour, const colour& top_right_colour, const colour& bottom_left_colour, const colour& bottom_right_colour)
00245 {
00246 d_backgroundCols.d_top_left = top_left_colour;
00247 d_backgroundCols.d_top_right = top_right_colour;
00248 d_backgroundCols.d_bottom_left = bottom_left_colour;
00249 d_backgroundCols.d_bottom_right = bottom_right_colour;
00250
00251 if (d_backgroundEnabled)
00252 {
00253 requestRedraw();
00254 }
00255
00256 }
00257
00258
00259
00260
00261
00262
00263 void Static::updateRenderableFrameColours(void)
00264 {
00265 float alpha = getEffectiveAlpha();
00266
00267 d_frame.setColours(
00268 calculateModulatedAlphaColour(d_frameCols.d_top_left, alpha),
00269 calculateModulatedAlphaColour(d_frameCols.d_top_right, alpha),
00270 calculateModulatedAlphaColour(d_frameCols.d_bottom_left, alpha),
00271 calculateModulatedAlphaColour(d_frameCols.d_bottom_right, alpha)
00272 );
00273
00274 }
00275
00276
00277
00278
00279
00280
00281 colour Static::calculateModulatedAlphaColour(const colour& col, float alpha) const
00282 {
00283 colour temp(col);
00284 temp.setAlpha(temp.getAlpha() * alpha);
00285 return temp;
00286 }
00287
00288
00289
00290
00291
00292 void Static::populateRenderCache()
00293 {
00294 Rect backgroundRect(Point(0,0), getAbsoluteSize());
00295
00296
00297 if (d_frameEnabled)
00298 {
00299 d_frame.draw(d_renderCache);
00300
00301
00302 backgroundRect.d_left += d_left_width;
00303 backgroundRect.d_right -= d_right_width;
00304 backgroundRect.d_top += d_top_height;
00305 backgroundRect.d_bottom -= d_bottom_height;
00306 }
00307
00308
00309 if (d_backgroundEnabled && (d_background != NULL))
00310 {
00311
00312 ColourRect colours(d_backgroundCols);
00313 colours.modulateAlpha(getEffectiveAlpha());
00314
00315 d_renderCache.cacheImage(*d_background, backgroundRect, 0, colours);
00316 }
00317
00318 }
00319
00320
00321
00322
00323
00324 void Static::onSized(WindowEventArgs& e)
00325 {
00326
00327 Window::onSized(e);
00328
00329
00330 d_frame.setSize(getAbsoluteSize());
00331
00332 e.handled = true;
00333 }
00334
00335
00336
00337
00338
00339 void Static::onAlphaChanged(WindowEventArgs& e)
00340 {
00341
00342 Window::onAlphaChanged(e);
00343
00344
00345 updateRenderableFrameColours();
00346
00347 e.handled = true;
00348 }
00349
00350
00351
00352
00353
00354 const Image* Static::getImageForFrameLocation(FrameLocation location) const
00355 {
00356 return d_frame.getImageForLocation(location);
00357 }
00358
00359
00360
00361
00362
00363 const Image* Static::getBackgroundImage(void) const
00364 {
00365 return d_background;
00366 }
00367
00368
00369
00370
00371
00372 void Static::setImageForFrameLocation(FrameLocation location, const Image* image)
00373 {
00374 d_frame.setImageForLocation(location, image);
00375
00376
00377 switch (location)
00378 {
00379 case LeftEdge:
00380 d_left_width = (image != NULL) ? image->getWidth() : 0;
00381 break;
00382
00383 case RightEdge:
00384 d_right_width = (image != NULL) ? image->getWidth() : 0;
00385 break;
00386
00387 case TopEdge:
00388 d_top_height = (image != NULL) ? image->getHeight() : 0;
00389 break;
00390
00391 case BottomEdge:
00392 d_bottom_height = (image != NULL) ? image->getHeight() : 0;
00393 break;
00394
00395 default:
00396 break;
00397 }
00398
00399 }
00400
00401
00402
00403
00404 void Static::addStaticProperties(void)
00405 {
00406 addProperty(&d_frameEnabledProperty);
00407 addProperty(&d_backgroundEnabledProperty);
00408 addProperty(&d_frameColoursProperty);
00409 addProperty(&d_backgroundColoursProperty);
00410 addProperty(&d_backgroundImageProperty);
00411 addProperty(&d_topLeftFrameProperty);
00412 addProperty(&d_topRightFrameProperty);
00413 addProperty(&d_bottomLeftFrameProperty);
00414 addProperty(&d_bottomRightFrameProperty);
00415 addProperty(&d_leftFrameProperty);
00416 addProperty(&d_topFrameProperty);
00417 addProperty(&d_rightFrameProperty);
00418 addProperty(&d_bottomFrameProperty);
00419 }
00420
00421 }