diff options
author | David Walter Seikel | 2016-03-28 22:28:34 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-03-28 22:28:34 +1000 |
commit | 7028cbe09c688437910a25623098762bf0fa592d (patch) | |
tree | 10b5af58277d9880380c2251f109325542c4e6eb /src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImage.cpp | |
parent | Move lemon to the src/others directory. (diff) | |
download | SledjHamr-7028cbe09c688437910a25623098762bf0fa592d.zip SledjHamr-7028cbe09c688437910a25623098762bf0fa592d.tar.gz SledjHamr-7028cbe09c688437910a25623098762bf0fa592d.tar.bz2 SledjHamr-7028cbe09c688437910a25623098762bf0fa592d.tar.xz |
Move Irrlicht to src/others.
Diffstat (limited to 'src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImage.cpp')
-rw-r--r-- | src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImage.cpp | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImage.cpp b/src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImage.cpp new file mode 100644 index 0000000..17d30e0 --- /dev/null +++ b/src/others/irrlicht-1.8.1/source/Irrlicht/CGUIImage.cpp | |||
@@ -0,0 +1,164 @@ | |||
1 | // Copyright (C) 2002-2012 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 | if (Texture) | ||
80 | { | ||
81 | if (ScaleImage) | ||
82 | { | ||
83 | const video::SColor Colors[] = {Color,Color,Color,Color}; | ||
84 | |||
85 | driver->draw2DImage(Texture, AbsoluteRect, | ||
86 | core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Texture->getOriginalSize())), | ||
87 | &AbsoluteClippingRect, Colors, UseAlphaChannel); | ||
88 | } | ||
89 | else | ||
90 | { | ||
91 | driver->draw2DImage(Texture, AbsoluteRect.UpperLeftCorner, | ||
92 | core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Texture->getOriginalSize())), | ||
93 | &AbsoluteClippingRect, Color, UseAlphaChannel); | ||
94 | } | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | skin->draw2DRectangle(this, skin->getColor(EGDC_3D_DARK_SHADOW), AbsoluteRect, &AbsoluteClippingRect); | ||
99 | } | ||
100 | |||
101 | IGUIElement::draw(); | ||
102 | } | ||
103 | |||
104 | |||
105 | //! sets if the image should use its alpha channel to draw itself | ||
106 | void CGUIImage::setUseAlphaChannel(bool use) | ||
107 | { | ||
108 | UseAlphaChannel = use; | ||
109 | } | ||
110 | |||
111 | |||
112 | //! sets if the image should use its alpha channel to draw itself | ||
113 | void CGUIImage::setScaleImage(bool scale) | ||
114 | { | ||
115 | ScaleImage = scale; | ||
116 | } | ||
117 | |||
118 | |||
119 | //! Returns true if the image is scaled to fit, false if not | ||
120 | bool CGUIImage::isImageScaled() const | ||
121 | { | ||
122 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
123 | return ScaleImage; | ||
124 | } | ||
125 | |||
126 | //! Returns true if the image is using the alpha channel, false if not | ||
127 | bool CGUIImage::isAlphaChannelUsed() const | ||
128 | { | ||
129 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
130 | return UseAlphaChannel; | ||
131 | } | ||
132 | |||
133 | |||
134 | //! Writes attributes of the element. | ||
135 | void CGUIImage::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const | ||
136 | { | ||
137 | IGUIImage::serializeAttributes(out,options); | ||
138 | |||
139 | out->addTexture ("Texture", Texture); | ||
140 | out->addBool ("UseAlphaChannel", UseAlphaChannel); | ||
141 | out->addColor ("Color", Color); | ||
142 | out->addBool ("ScaleImage", ScaleImage); | ||
143 | |||
144 | } | ||
145 | |||
146 | |||
147 | //! Reads attributes of the element | ||
148 | void CGUIImage::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) | ||
149 | { | ||
150 | IGUIImage::deserializeAttributes(in,options); | ||
151 | |||
152 | setImage(in->getAttributeAsTexture("Texture")); | ||
153 | setUseAlphaChannel(in->getAttributeAsBool("UseAlphaChannel")); | ||
154 | setColor(in->getAttributeAsColor("Color")); | ||
155 | setScaleImage(in->getAttributeAsBool("ScaleImage")); | ||
156 | } | ||
157 | |||
158 | |||
159 | } // end namespace gui | ||
160 | } // end namespace irr | ||
161 | |||
162 | |||
163 | #endif // _IRR_COMPILE_WITH_GUI_ | ||
164 | |||