1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
6
#ifdef _IRR_COMPILE_WITH_GUI_
9
#include "IGUIEnvironment.h"
10
#include "IVideoDriver.h"
19
CGUIImage::CGUIImage(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
20
: IGUIImage(environment, parent, id, rectangle), Texture(0), Color(255,255,255,255),
21
UseAlphaChannel(false), ScaleImage(false)
24
setDebugName("CGUIImage");
30
CGUIImage::~CGUIImage()
38
void CGUIImage::setImage(video::ITexture* image)
52
//! Gets the image texture
53
video::ITexture* CGUIImage::getImage() const
58
//! sets the color of the image
59
void CGUIImage::setColor(video::SColor color)
64
//! Gets the color of the image
65
video::SColor CGUIImage::getColor() const
70
//! draws the element and its children
71
void CGUIImage::draw()
76
IGUISkin* skin = Environment->getSkin();
77
video::IVideoDriver* driver = Environment->getVideoDriver();
79
core::rect<s32> rect = AbsoluteRect;
85
const video::SColor Colors[] = {Color,Color,Color,Color};
87
driver->draw2DImage(Texture, AbsoluteRect,
88
core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Texture->getOriginalSize())),
89
&AbsoluteClippingRect, Colors, UseAlphaChannel);
93
driver->draw2DImage(Texture, AbsoluteRect.UpperLeftCorner,
94
core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Texture->getOriginalSize())),
95
&AbsoluteClippingRect, Color, UseAlphaChannel);
100
skin->draw2DRectangle(this, skin->getColor(EGDC_3D_DARK_SHADOW), AbsoluteRect, &AbsoluteClippingRect);
107
//! sets if the image should use its alpha channel to draw itself
108
void CGUIImage::setUseAlphaChannel(bool use)
110
UseAlphaChannel = use;
114
//! sets if the image should use its alpha channel to draw itself
115
void CGUIImage::setScaleImage(bool scale)
121
//! Returns true if the image is scaled to fit, false if not
122
bool CGUIImage::isImageScaled() const
124
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
128
//! Returns true if the image is using the alpha channel, false if not
129
bool CGUIImage::isAlphaChannelUsed() const
131
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
132
return UseAlphaChannel;
136
//! Writes attributes of the element.
137
void CGUIImage::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
139
IGUIImage::serializeAttributes(out,options);
141
out->addTexture ("Texture", Texture);
142
out->addBool ("UseAlphaChannel", UseAlphaChannel);
143
out->addColor ("Color", Color);
144
out->addBool ("ScaleImage", ScaleImage);
149
//! Reads attributes of the element
150
void CGUIImage::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
152
IGUIImage::deserializeAttributes(in,options);
154
setImage(in->getAttributeAsTexture("Texture"));
155
setUseAlphaChannel(in->getAttributeAsBool("UseAlphaChannel"));
156
setColor(in->getAttributeAsColor("Color"));
157
setScaleImage(in->getAttributeAsBool("ScaleImage"));
161
} // end namespace gui
162
} // end namespace irr
165
#endif // _IRR_COMPILE_WITH_GUI_