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/CEGUIStaticImage.h"
00027 #include "CEGUIImagesetManager.h"
00028 #include "CEGUIImageset.h"
00029
00030
00031 namespace CEGUI
00032 {
00033 const String StaticImage::EventNamespace("StaticImage");
00034
00035
00036
00037
00038 StaticImageProperties::Image StaticImage::d_imageProperty;
00039 StaticImageProperties::ImageColours StaticImage::d_imageColoursProperty;
00040 StaticImageProperties::VertFormatting StaticImage::d_vertFormattingProperty;
00041 StaticImageProperties::HorzFormatting StaticImage::d_horzFormattingProperty;
00042
00043
00044
00045
00046
00047 StaticImage::StaticImage(const String& type, const String& name) :
00048 Static(type, name),
00049 d_imageCols(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)
00050 {
00051 addStaticImageProperties();
00052
00053
00054 d_image.setHorzFormatting(RenderableImage::HorzStretched);
00055 d_image.setVertFormatting(RenderableImage::VertStretched);
00056 }
00057
00058
00059
00060
00061
00062 StaticImage::~StaticImage(void)
00063 {
00064 }
00065
00066
00067
00068
00069
00070 void StaticImage::setImage(const Image* image)
00071 {
00072 d_image.setImage(image);
00073 requestRedraw();
00074 }
00075
00076
00077
00078
00079
00080 void StaticImage::setImage(const String& imageset, const String& image)
00081 {
00082 setImage(&ImagesetManager::getSingleton().getImageset(imageset)->getImage(image));
00083 }
00084
00085
00086
00087
00088
00089 void StaticImage::setImageColours(const ColourRect& colours)
00090 {
00091 d_imageCols = colours;
00092 updateRenderableImageColours();
00093
00094 requestRedraw();
00095 }
00096
00097
00098
00099
00100
00101 void StaticImage::setImageColours(const colour& top_left_colour, const colour& top_right_colour, const colour& bottom_left_colour, const colour& bottom_right_colour)
00102 {
00103 d_imageCols.d_top_left = top_left_colour;
00104 d_imageCols.d_top_right = top_right_colour;
00105 d_imageCols.d_bottom_left = bottom_left_colour;
00106 d_imageCols.d_bottom_right = bottom_right_colour;
00107 updateRenderableImageColours();
00108
00109 requestRedraw();
00110 }
00111
00112
00113
00114
00115
00116 void StaticImage::setFormatting(HorzFormatting h_fmt, VertFormatting v_fmt)
00117 {
00118 d_image.setHorzFormatting((RenderableImage::HorzFormatting)h_fmt);
00119 d_image.setVertFormatting((RenderableImage::VertFormatting)v_fmt);
00120
00121 requestRedraw();
00122 }
00123
00124
00125
00126
00127
00128 void StaticImage::setVerticalFormatting(VertFormatting v_fmt)
00129 {
00130 d_image.setVertFormatting((RenderableImage::VertFormatting)v_fmt);
00131
00132 requestRedraw();
00133 }
00134
00135
00136
00137
00138
00139 void StaticImage::setHorizontalFormatting(HorzFormatting h_fmt)
00140 {
00141 d_image.setHorzFormatting((RenderableImage::HorzFormatting)h_fmt);
00142
00143 requestRedraw();
00144 }
00145
00146
00147
00148
00149
00150
00151 void StaticImage::updateRenderableImageColours(void)
00152 {
00153 float alpha = getEffectiveAlpha();
00154
00155 d_image.setColours(
00156 calculateModulatedAlphaColour(d_imageCols.d_top_left, alpha),
00157 calculateModulatedAlphaColour(d_imageCols.d_top_right, alpha),
00158 calculateModulatedAlphaColour(d_imageCols.d_bottom_left, alpha),
00159 calculateModulatedAlphaColour(d_imageCols.d_bottom_right, alpha)
00160 );
00161
00162 }
00163
00164
00165
00166
00167
00168 void StaticImage::populateRenderCache()
00169 {
00170
00171 Static::populateRenderCache();
00172
00173
00174
00175
00176
00177 d_image.draw(d_renderCache);
00178 }
00179
00180
00181
00182
00183
00184 void StaticImage::onSized(WindowEventArgs& e)
00185 {
00186
00187 Static::onSized(e);
00188
00189 d_image.setSize(getUnclippedInnerRect().getSize());
00190
00191 e.handled = true;
00192 }
00193
00194
00195
00196
00197
00198 void StaticImage::onAlphaChanged(WindowEventArgs& e)
00199 {
00200
00201 Static::onAlphaChanged(e);
00202
00203
00204 updateRenderableImageColours();
00205
00206 e.handled = true;
00207 }
00208
00209
00210
00211
00212
00213 void StaticImage::onStaticFrameChanged(WindowEventArgs& e)
00214 {
00215
00216 Static::onStaticFrameChanged(e);
00217
00218
00219
00220 Rect absRect(getUnclippedPixelRect());
00221 Rect innerRect(getUnclippedInnerRect());
00222 d_image.setSize(innerRect.getSize());
00223 d_image.setPosition(Point(innerRect.d_left - absRect.d_left, innerRect.d_top - absRect.d_top));
00224
00225 e.handled = true;
00226 }
00227
00228
00229
00230
00231 void StaticImage::addStaticImageProperties(void)
00232 {
00233 addProperty(&d_imageProperty);
00234 addProperty(&d_imageColoursProperty);
00235 addProperty(&d_vertFormattingProperty);
00236 addProperty(&d_horzFormattingProperty);
00237 }
00238
00239
00240 }