3
GUIClippedRectangle::GUIClippedRectangle(int size)
5
setTextureRectangle(0,0,1,1);
6
setBordersColor(0.0f, 0.9f, 0.0f);
8
setBGColor(0.413f, 0.7f, 0.52f, 0.75f);
10
drawBackground = false;
14
void GUIClippedRectangle::setClipSize(int clipSizeArg)
16
clipSize = clamp(clipSizeArg, 0, 100);
19
int GUIClippedRectangle::getClipSize()
24
void GUIClippedRectangle::setVisibleBounds(bool visibleArg)
26
drawBounds = visibleArg;
29
bool GUIClippedRectangle::boundsVisible()
34
bool GUIClippedRectangle::loadXMLClippedRectangleInfo(const TiXmlElement *element)
39
const TiXmlElement *absolutePriority = XMLArbiter::getChildElementByName(element, "Texture");
40
setVisibleBounds(XMLArbiter::analyzeBooleanAttr(element, "drawBounds", drawBounds));
41
enableBGColor(XMLArbiter::analyzeBooleanAttr(element, "drawBackground", drawBackground));
42
setClipSize(XMLArbiter::fillComponents1i(element, "clipSize", clipSize));
45
texture.loadXMLSettings(absolutePriority);
47
for(const TiXmlElement *child = element->FirstChildElement();
49
child = child->NextSiblingElement() )
51
const char * value = child->Value();
56
if(!strcmp(value, "TextureRectangle"))
57
setTextureRectangle(XMLArbiter::fillComponents4f(child, textureRectangle));
59
if(!strcmp(value, "BordersColor"))
60
setBordersColor(XMLArbiter::fillComponents3f(child, bordersColor));
62
if(!strcmp(value, "BGColor"))
63
setBGColor(XMLArbiter::fillComponents4f(child, bgColor));
69
void GUIClippedRectangle::setBGColor(const Tuple4f& color)
71
setBGColor(color.x, color.y, color.z, color.w);
74
void GUIClippedRectangle::setBGColor(float r, float g, float b, float a)
76
bgColor.set(clamp(r, 0.0f, 255.0f),
77
clamp(g, 0.0f, 255.0f),
78
clamp(b, 0.0f, 255.0f),
79
clamp(a, 0.0f, 255.0f));
81
bgColor.x /= (bgColor.x > 1.0) ? 255.0f : 1.0f;
82
bgColor.y /= (bgColor.y > 1.0) ? 255.0f : 1.0f;
83
bgColor.z /= (bgColor.z > 1.0) ? 255.0f : 1.0f;
84
bgColor.w /= (bgColor.w > 1.0) ? 255.0f : 1.0f;
87
void GUIClippedRectangle::setBordersColor(const Tuple3f& color)
89
setBordersColor(color.x, color.y, color.z);
92
const Tuple3f &GUIClippedRectangle::getBordersColor()
97
void GUIClippedRectangle::setBordersColor(float r, float g, float b)
99
bordersColor.set(clamp(r, 0.0f, 255.0f),
100
clamp(g, 0.0f, 255.0f),
101
clamp(b, 0.0f, 255.0f));
102
bordersColor.x /= (bordersColor.x > 1.0) ? 255.0f : 1.0f;
103
bordersColor.y /= (bordersColor.y > 1.0) ? 255.0f : 1.0f;
104
bordersColor.z /= (bordersColor.z > 1.0) ? 255.0f : 1.0f;
107
void GUIClippedRectangle::renderClippedBounds()
109
if(drawBackground || drawBounds)
111
glVertexPointer(2, GL_INT, 0, vertices[0]);
112
glEnableClientState(GL_VERTEX_ARRAY);
114
if(texture.getID() && drawBackground)
116
glTexCoordPointer(2, GL_FLOAT, 0, texCoords[0]) ;
117
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
125
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
127
glDrawArrays(GL_TRIANGLE_FAN, 0, 7);
132
texture.deactivate();
133
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
139
glColor3fv(bordersColor);
140
glDrawArrays(GL_LINE_STRIP, 0, 7);
144
glDisableClientState(GL_VERTEX_ARRAY);
147
void GUIClippedRectangle::computeClippedBounds(const Tuple4i &windowBounds)
149
float yTexOffset = float(clipSize)/(windowBounds.w - windowBounds.y),
150
xTexOffset = float(clipSize)/(windowBounds.z - windowBounds.x);
152
xTexOffset *= textureRectangle.z - textureRectangle.x;
153
yTexOffset *= textureRectangle.w - textureRectangle.y;
155
vertices[0].set(windowBounds.x, windowBounds.y + clipSize);
156
vertices[1].set(windowBounds.x, windowBounds.w);
157
vertices[2].set(windowBounds.z - clipSize, windowBounds.w);
158
vertices[3].set(windowBounds.z, windowBounds.w - clipSize);
159
vertices[4].set(windowBounds.z, windowBounds.y);
160
vertices[5].set(windowBounds.x + clipSize, windowBounds.y);
161
vertices[6].set(windowBounds.x, windowBounds.y + clipSize);
163
texCoords[0].set(textureRectangle.x , textureRectangle.w - yTexOffset);
164
texCoords[1].set(textureRectangle.x , textureRectangle.y);
165
texCoords[2].set(textureRectangle.z - xTexOffset, textureRectangle.y );
166
texCoords[3].set(textureRectangle.z , textureRectangle.y + yTexOffset);
167
texCoords[4].set(textureRectangle.z , textureRectangle.w);
168
texCoords[5].set(textureRectangle.x + xTexOffset, textureRectangle.w );
169
texCoords[6].set(textureRectangle.x , textureRectangle.w - yTexOffset);
172
void GUIClippedRectangle::enableBGColor(bool enable)
174
drawBackground = enable;
177
void GUIClippedRectangle::setTextureRectangle(const Tuple4f &tr)
179
setTextureRectangle(tr.x, tr.y, tr.z, tr.w);
182
void GUIClippedRectangle::setTextureRectangle(float x, float y, float z, float w)
184
if(x > 1.0f || y > 1.0f || z > 1.0f || w > 1.0f)
187
x = clamp(x, 0.0f, float(texture.getWidth() ));
188
y = clamp(y, 0.0f, float(texture.getHeight()));
189
z = clamp(z, 0.0f, float(texture.getWidth() ));
190
w = clamp(w, 0.0f, float(texture.getHeight()));
192
x /= texture.getWidth();
193
z /= texture.getWidth();
195
w /= texture.getHeight();
196
y /= texture.getHeight();
200
textureRectangle.set(clamp(x, 0.0f, 1.0f),
201
clamp(y, 0.0f, 1.0f),
202
clamp(z, 0.0f, 1.0f),
203
clamp(w, 0.0f, 1.0f));
206
const Tuple4f &GUIClippedRectangle::getTextureRectangle()
208
return textureRectangle;
211
Texture &GUIClippedRectangle::getTexture()
216
void GUIClippedRectangle::setTexture(const Texture & textureArg)
218
texture = textureArg;
221
bool GUIClippedRectangle::isBGColorOn()
223
return drawBackground;
226
const Tuple4f &GUIClippedRectangle::getBGColor()
231
const Tuple2i *GUIClippedRectangle::getVertices() const
236
const Tuple2f *GUIClippedRectangle::getTexCoords() const