]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUIImage.h
581fe1b5f685d7437ba7d1cf7eb844663c6b8333
[irrlicht.git] / source / Irrlicht / CGUIImage.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __C_GUI_IMAGE_H_INCLUDED__\r
6 #define __C_GUI_IMAGE_H_INCLUDED__\r
7 \r
8 #include "IrrCompileConfig.h"\r
9 #ifdef _IRR_COMPILE_WITH_GUI_\r
10 \r
11 #include "IGUIImage.h"\r
12 \r
13 namespace irr\r
14 {\r
15 namespace gui\r
16 {\r
17 \r
18         class CGUIImage : public IGUIImage\r
19         {\r
20         public:\r
21 \r
22                 //! constructor\r
23                 CGUIImage(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle);\r
24 \r
25                 //! destructor\r
26                 virtual ~CGUIImage();\r
27 \r
28                 //! sets an image\r
29                 void setImage(video::ITexture* image) override;\r
30 \r
31                 //! Gets the image texture\r
32                 video::ITexture* getImage() const override;\r
33 \r
34                 //! sets the color of the image\r
35                 void setColor(video::SColor color) override;\r
36 \r
37                 //! sets if the image should scale to fit the element\r
38                 void setScaleImage(bool scale) override;\r
39 \r
40                 //! draws the element and its children\r
41                 void draw() override;\r
42 \r
43                 //! sets if the image should use its alpha channel to draw itself\r
44                 void setUseAlphaChannel(bool use) override;\r
45 \r
46                 //! Gets the color of the image\r
47                 video::SColor getColor() const override;\r
48 \r
49                 //! Returns true if the image is scaled to fit, false if not\r
50                 bool isImageScaled() const override;\r
51 \r
52                 //! Returns true if the image is using the alpha channel, false if not\r
53                 bool isAlphaChannelUsed() const override;\r
54 \r
55                 //! Sets the source rectangle of the image. By default the full image is used.\r
56                 void setSourceRect(const core::rect<s32>& sourceRect) override;\r
57 \r
58                 //! Returns the customized source rectangle of the image to be used.\r
59                 core::rect<s32> getSourceRect() const override;\r
60 \r
61                 //! Restrict drawing-area.\r
62                 void setDrawBounds(const core::rect<f32>& drawBoundUVs) override;\r
63 \r
64                 //! Get drawing-area restrictions.\r
65                 core::rect<f32> getDrawBounds() const override;\r
66 \r
67                 //! Sets whether to draw a background color (EGDC_3D_DARK_SHADOW) when no texture is set\r
68                 void setDrawBackground(bool draw) override\r
69                 {\r
70                         DrawBackground = draw;\r
71                 }\r
72 \r
73                 //! Checks if a background is drawn when no texture is set\r
74                 bool isDrawBackgroundEnabled() const  override\r
75                 {\r
76                         return DrawBackground;\r
77                 }\r
78 \r
79         protected:\r
80                 void checkBounds(core::rect<s32>& rect)\r
81                 {\r
82                         f32 clipWidth = (f32)rect.getWidth();\r
83                         f32 clipHeight = (f32)rect.getHeight();\r
84 \r
85                         rect.UpperLeftCorner.X += core::round32(DrawBounds.UpperLeftCorner.X*clipWidth);\r
86                         rect.UpperLeftCorner.Y += core::round32(DrawBounds.UpperLeftCorner.Y*clipHeight);\r
87                         rect.LowerRightCorner.X -= core::round32((1.f-DrawBounds.LowerRightCorner.X)*clipWidth);\r
88                         rect.LowerRightCorner.Y -= core::round32((1.f-DrawBounds.LowerRightCorner.Y)*clipHeight);\r
89                 }\r
90 \r
91         private:\r
92                 video::ITexture* Texture;\r
93                 video::SColor Color;\r
94                 bool UseAlphaChannel;\r
95                 bool ScaleImage;\r
96                 core::rect<s32> SourceRect;\r
97                 core::rect<f32> DrawBounds;\r
98                 bool DrawBackground;\r
99         };\r
100 \r
101 \r
102 } // end namespace gui\r
103 } // end namespace irr\r
104 \r
105 #endif // _IRR_COMPILE_WITH_GUI_\r
106 \r
107 #endif // __C_GUI_IMAGE_H_INCLUDED__\r