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