~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to source/Irrlicht/CGUIImage.cpp

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 
 
5
#include "CGUIImage.h"
 
6
#ifdef _IRR_COMPILE_WITH_GUI_
 
7
 
 
8
#include "IGUISkin.h"
 
9
#include "IGUIEnvironment.h"
 
10
#include "IVideoDriver.h"
 
11
 
 
12
namespace irr
 
13
{
 
14
namespace gui
 
15
{
 
16
 
 
17
 
 
18
//! constructor
 
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)
 
22
{
 
23
        #ifdef _DEBUG
 
24
        setDebugName("CGUIImage");
 
25
        #endif
 
26
}
 
27
 
 
28
 
 
29
//! destructor
 
30
CGUIImage::~CGUIImage()
 
31
{
 
32
        if (Texture)
 
33
                Texture->drop();
 
34
}
 
35
 
 
36
 
 
37
//! sets an image
 
38
void CGUIImage::setImage(video::ITexture* image)
 
39
{
 
40
        if (image == Texture)
 
41
                return;
 
42
 
 
43
        if (Texture)
 
44
                Texture->drop();
 
45
 
 
46
        Texture = image;
 
47
 
 
48
        if (Texture)
 
49
                Texture->grab();
 
50
}
 
51
 
 
52
//! Gets the image texture
 
53
video::ITexture* CGUIImage::getImage() const
 
54
{
 
55
        return Texture;
 
56
}
 
57
 
 
58
//! sets the color of the image
 
59
void CGUIImage::setColor(video::SColor color)
 
60
{
 
61
        Color = color;
 
62
}
 
63
 
 
64
//! Gets the color of the image
 
65
video::SColor CGUIImage::getColor() const
 
66
{
 
67
        return Color;
 
68
}
 
69
 
 
70
//! draws the element and its children
 
71
void CGUIImage::draw()
 
72
{
 
73
        if (!IsVisible)
 
74
                return;
 
75
 
 
76
        IGUISkin* skin = Environment->getSkin();
 
77
        video::IVideoDriver* driver = Environment->getVideoDriver();
 
78
 
 
79
        core::rect<s32> rect = AbsoluteRect;
 
80
 
 
81
        if (Texture)
 
82
        {
 
83
                if (ScaleImage)
 
84
                {
 
85
                        const video::SColor Colors[] = {Color,Color,Color,Color};
 
86
 
 
87
                        driver->draw2DImage(Texture, AbsoluteRect,
 
88
                                core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Texture->getOriginalSize())),
 
89
                                &AbsoluteClippingRect, Colors, UseAlphaChannel);
 
90
                }
 
91
                else
 
92
                {
 
93
                        driver->draw2DImage(Texture, AbsoluteRect.UpperLeftCorner,
 
94
                                core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Texture->getOriginalSize())),
 
95
                                &AbsoluteClippingRect, Color, UseAlphaChannel);
 
96
                }
 
97
        }
 
98
        else
 
99
        {
 
100
                skin->draw2DRectangle(this, skin->getColor(EGDC_3D_DARK_SHADOW), AbsoluteRect, &AbsoluteClippingRect);
 
101
        }
 
102
 
 
103
        IGUIElement::draw();
 
104
}
 
105
 
 
106
 
 
107
//! sets if the image should use its alpha channel to draw itself
 
108
void CGUIImage::setUseAlphaChannel(bool use)
 
109
{
 
110
        UseAlphaChannel = use;
 
111
}
 
112
 
 
113
 
 
114
//! sets if the image should use its alpha channel to draw itself
 
115
void CGUIImage::setScaleImage(bool scale)
 
116
{
 
117
        ScaleImage = scale;
 
118
}
 
119
 
 
120
 
 
121
//! Returns true if the image is scaled to fit, false if not
 
122
bool CGUIImage::isImageScaled() const
 
123
{
 
124
        _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
 
125
        return ScaleImage;
 
126
}
 
127
 
 
128
//! Returns true if the image is using the alpha channel, false if not
 
129
bool CGUIImage::isAlphaChannelUsed() const
 
130
{
 
131
        _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
 
132
        return UseAlphaChannel;
 
133
}
 
134
 
 
135
 
 
136
//! Writes attributes of the element.
 
137
void CGUIImage::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
 
138
{
 
139
        IGUIImage::serializeAttributes(out,options);
 
140
 
 
141
        out->addTexture ("Texture", Texture);
 
142
        out->addBool    ("UseAlphaChannel", UseAlphaChannel);
 
143
        out->addColor   ("Color", Color);
 
144
        out->addBool    ("ScaleImage", ScaleImage);
 
145
 
 
146
}
 
147
 
 
148
 
 
149
//! Reads attributes of the element
 
150
void CGUIImage::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
 
151
{
 
152
        IGUIImage::deserializeAttributes(in,options);
 
153
 
 
154
        setImage(in->getAttributeAsTexture("Texture"));
 
155
        setUseAlphaChannel(in->getAttributeAsBool("UseAlphaChannel"));
 
156
        setColor(in->getAttributeAsColor("Color"));
 
157
        setScaleImage(in->getAttributeAsBool("ScaleImage"));
 
158
}
 
159
 
 
160
 
 
161
} // end namespace gui
 
162
} // end namespace irr
 
163
 
 
164
 
 
165
#endif // _IRR_COMPILE_WITH_GUI_
 
166