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 "CEGUIImage.h"
00027 #include "CEGUIExceptions.h"
00028 #include "CEGUITexture.h"
00029 #include "CEGUIImageset.h"
00030 #include "CEGUIRenderer.h"
00031 #include "CEGUIPropertyHelper.h"
00032 #include <cmath>
00033 #include <iostream>
00034
00035
00036 namespace CEGUI
00037 {
00038
00039
00040
00041
00042 Image::Image(const Imageset* owner, const String& name, const Rect& area, const Point& render_offset, float horzScaling, float vertScaling) :
00043 d_owner(owner),
00044 d_area(area),
00045 d_offset(render_offset),
00046 d_name(name)
00047 {
00048 if (d_owner == NULL)
00049 {
00050 throw NullObjectException((utf8*)"Image::Image - Imageset pointer passed to Image constructor must not be null.");
00051 }
00052
00053
00054 setHorzScaling(horzScaling);
00055 setVertScaling(vertScaling);
00056
00057
00058 }
00059
00060
00061
00062
00063 Image::Image(const Image& image) :
00064 d_owner(image.d_owner),
00065 d_area(image.d_area),
00066 d_offset(image.d_offset),
00067 d_scaledWidth(image.d_scaledWidth),
00068 d_scaledHeight(image.d_scaledHeight),
00069 d_scaledOffset(image.d_scaledOffset),
00070 d_name(image.d_name)
00071 {
00072 }
00073
00074
00075
00076
00077 Image::~Image(void)
00078 {
00079 }
00080
00081
00082
00083
00084
00085 void Image::setHorzScaling(float factor)
00086 {
00087 d_scaledWidth = PixelAligned(d_area.getWidth() * factor);
00088 d_scaledOffset.d_x = PixelAligned(d_offset.d_x * factor);
00089 }
00090
00091
00092
00093
00094
00095 void Image::setVertScaling(float factor)
00096 {
00097 d_scaledHeight = PixelAligned(d_area.getHeight() * factor);
00098 d_scaledOffset.d_y = PixelAligned(d_offset.d_y * factor);
00099 }
00100
00101
00102
00103
00104
00105 void Image::draw(const Rect& dest_rect, float z, const Rect& clip_rect, const ColourRect& colours, QuadSplitMode quad_split_mode) const
00106 {
00107 Rect dest(dest_rect);
00108
00109
00110 dest.offset(d_scaledOffset);
00111
00112
00113 d_owner->draw(d_area, dest, z, clip_rect, colours, quad_split_mode);
00114 }
00115
00116
00117
00118
00119
00120 const String& Image::getName(void) const
00121 {
00122 return d_name;
00123 }
00124
00125
00126
00127
00128
00129 const String& Image::getImagesetName(void) const
00130 {
00131 return d_owner->getName();
00132 }
00133
00134
00135
00136
00137 const Rect& Image::getSourceTextureArea(void) const
00138 {
00139 return d_area;
00140 }
00141
00142
00143
00144
00145
00146 void Image::writeXMLToStream(OutStream& out_stream) const
00147 {
00148 out_stream << "<Image Name=\"" << d_name.c_str() << "\" ";
00149 out_stream << "XPos=\"" << PropertyHelper::uintToString(static_cast<uint>(d_area.d_left)) << "\" ";
00150 out_stream << "YPos=\"" << PropertyHelper::uintToString(static_cast<uint>(d_area.d_top)) << "\" ";
00151 out_stream << "Width=\"" << PropertyHelper::uintToString(static_cast<uint>(d_area.getWidth())) << "\" ";
00152 out_stream << "Height=\"" << PropertyHelper::uintToString(static_cast<uint>(d_area.getHeight())) << "\" ";
00153
00154 if (d_offset.d_x != 0.0f)
00155 out_stream << "XOffset=\"" << PropertyHelper::intToString(static_cast<int>(d_offset.d_x)) << "\" ";
00156
00157 if (d_offset.d_y != 0.0f)
00158 out_stream << "YOffset=\"" << PropertyHelper::intToString(static_cast<int>(d_offset.d_x)) << "\" ";
00159
00160 out_stream << "/>" << std::endl;
00161 }
00162
00163
00164 }