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 "CEGUIRenderableImage.h"
00027 #include "CEGUIImage.h"
00028 #include "CEGUIExceptions.h"
00029
00030
00031 namespace CEGUI
00032 {
00033
00034
00035
00036
00037 RenderableImage::RenderableImage(void) :
00038 d_horzFormat(LeftAligned),
00039 d_vertFormat(TopAligned),
00040 d_quadSplitMode(TopLeftToBottomRight),
00041 d_image(NULL)
00042 {
00043 }
00044
00045
00046
00047
00048
00049 RenderableImage::~RenderableImage(void)
00050 {
00051 }
00052
00053
00054
00055
00056
00057 void RenderableImage::draw_impl(const Vector3& position, const Rect& clip_rect) const
00058 {
00059 ColourRect final_colours;
00060
00061
00062 if (d_image == NULL)
00063 return;
00064
00065
00066 Rect final_clipper(position.d_x, position.d_y, 0, 0);
00067 final_clipper.setSize(d_area.getSize());
00068 final_clipper = clip_rect.getIntersection(final_clipper);
00069
00070 Size imgSize(d_image->getSize());
00071
00072
00073 uint horzTiles = (d_horzFormat == HorzTiled) ? (uint)((d_area.getWidth() + (imgSize.d_width - 1)) / imgSize.d_width) : 1;
00074 uint vertTiles = (d_vertFormat == VertTiled) ? (uint)((d_area.getHeight() + (imgSize.d_height - 1)) / imgSize.d_height) : 1;
00075
00076
00077 float baseX;
00078
00079 switch (d_horzFormat)
00080 {
00081 case HorzStretched:
00082 imgSize.d_width = d_area.getWidth();
00083
00084
00085 case HorzTiled:
00086 case LeftAligned:
00087 baseX = position.d_x;
00088 break;
00089
00090 case HorzCentred:
00091 baseX = position.d_x + PixelAligned((d_area.getWidth() - imgSize.d_width) / 2);
00092 break;
00093
00094 case RightAligned:
00095 baseX = position.d_x + d_area.getWidth() - imgSize.d_width;
00096 break;
00097
00098 default:
00099 throw InvalidRequestException((utf8*)"An unknown horizontal formatting value was specified in a RenderableImage object.");
00100 }
00101
00102
00103 float baseY;
00104
00105 switch (d_vertFormat)
00106 {
00107 case VertStretched:
00108 imgSize.d_height = d_area.getHeight();
00109
00110
00111 case VertTiled:
00112 case TopAligned:
00113 baseY = position.d_y;
00114 break;
00115
00116 case VertCentred:
00117 baseY = position.d_y + PixelAligned((d_area.getHeight() - imgSize.d_height) / 2);
00118 break;
00119
00120 case BottomAligned:
00121 baseY = position.d_y + d_area.getHeight() - imgSize.d_height;
00122 break;
00123
00124 default:
00125 throw InvalidRequestException((utf8*)"An unknown vertical formatting value was specified in a RenderableImage object.");
00126 }
00127
00128 Vector3 drawpos(0,baseY, position.d_z);
00129
00130
00131 for (uint row = 0; row < vertTiles; ++row)
00132 {
00133 drawpos.d_x = baseX;
00134
00135 for (uint col = 0; col < horzTiles; ++col)
00136 {
00137 if (d_useColoursPerImage)
00138 {
00139 final_colours = d_colours;
00140 }
00141 else
00142 {
00143 float leftfactor = (drawpos.d_x - baseX) / d_area.getWidth();
00144 float rightfactor = (drawpos.d_x + imgSize.d_width - baseX) / d_area.getWidth();
00145 float topfactor = (drawpos.d_y - baseY) / d_area.getHeight();
00146 float bottomfactor = (drawpos.d_y + imgSize.d_height - baseY) / d_area.getHeight();
00147 if( rightfactor > 1 ) rightfactor = 1;
00148 if( bottomfactor > 1 ) bottomfactor = 1;
00149
00150 final_colours = d_colours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor);
00151 }
00152
00153 d_image->draw(drawpos, imgSize, final_clipper, final_colours, d_quadSplitMode);
00154 drawpos.d_x += imgSize.d_width;
00155 }
00156
00157 drawpos.d_y += imgSize.d_height;
00158 }
00159
00160 }
00161
00162 }