MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
imagelayer.h
1 //© Copyright 2010 - 2012 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef _uiimagelayer_h
42 #define _uiimagelayer_h
43 
44 #include "UI/renderlayer.h"
45 #include "UI/sprite.h"
46 
47 namespace Mezzanine
48 {
49  namespace UI
50  {
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @class ImageLayer
53  /// @headerfile imagelayer.h
54  /// @brief This layer is for placing images and basic colours in it's parents' quad space.
55  /// @details
56  ///////////////////////////////////////
58  {
59  protected:
60  Sprite* LayerSprite;
61  Real BorderWidth;
62  ColourValue FillColours[4];
63  ColourValue BorderColours[4];
64 
65  /// @copydoc SimpleRenderer::RedrawImpl(bool Force)
66  virtual void RedrawImpl(bool Force);
67  /// @brief Draws the border, if any is set.
68  void DrawBorder(const Vector2& TopLeft, const Vector2& TopRight, const Vector2& BottomLeft, const Vector2& BottomRight,
69  const Vector2& OuterTopLeft, const Vector2& OuterTopRight, const Vector2& OuterBottomLeft, const Vector2& OuterBottomRight);
70  /// @brief Draws the main rectangle.
71  void DrawFill(const Vector2& TopLeft, const Vector2& TopRight, const Vector2& BottomLeft, const Vector2& BottomRight);
72  public:
73  /// @brief Class constructor.
74  /// @param ParentRenderable The renderable that created this layer.
75  ImageLayer(QuadRenderable* ParentRenderable);
76  /// @brief Class destructor.
77  virtual ~ImageLayer();
78 
79  ///////////////////////////////////////////////////////////////////////////////
80  // Utility
81 
82  /// @copydoc RenderLayer::GetLayerType() const
83  virtual RenderLayer::RenderLayerType GetLayerType() const;
84 
85  ///////////////////////////////////////////////////////////////////////////////
86  // Fill Methods
87 
88  /// @brief Sets the colour of the layer.
89  /// @param Colour A colour value representing the colour to be set.
90  virtual void SetColour(const ColourValue& Colour);
91  /// @brief Sets the colour for one corner the layer.
92  /// @param Corner Which corner the colour should be applied to.
93  /// @param Colour A colour value representing the colour to be set.
94  virtual void SetColour(const UI::QuadCorner Corner, const ColourValue& Colour);
95  /// @brief Sets the fill image(if provided in the atlas) of the layer.
96  /// @param PSprite A pointer to the sprite to set as the fill.
97  virtual void SetSprite(Sprite* PSprite);
98  /// @brief Sets the fill image(if provided in the atlas) of the layer.
99  /// @param SpriteName The name of the sprite to set as the fill.
100  virtual void SetSprite(const String& SpriteName);
101  /// @brief Sets the fill image(if provided in the atlas) of the layer.
102  /// @param SpriteName The name of the sprite to set as the fill.
103  /// @param Atlas The Atlas to load the sprite from.
104  virtual void SetSprite(const String& SpriteName, const String& Atlas);
105  /// @brief Sets a colour gradient to be applied to this layer.
106  /// @param Grad The direction/style of gradient to enable.
107  /// @param ColourA The colour to apply to the first side of the gradient.
108  /// @param ColourB The colour to apply to the second side of the gradient.
109  virtual void SetGradient(const UI::Gradient Grad, const ColourValue& ColourA, const ColourValue& ColourB);
110  /// @brief Gets the colour of a corner of this layer.
111  /// @param Corner The corner to get the colour for.
112  /// @return Returns the colour of the specified corner.
113  virtual const ColourValue& GetColour(const UI::QuadCorner Corner) const;
114  /// @brief Gets whether or not this layer is entirely transparent.
115  /// @return Returns true if all quad corners of this layer have their value set to zero, false otherwise.
116  virtual bool IsCompletelyTransparent() const;
117 
118  ///////////////////////////////////////////////////////////////////////////////
119  // Border Methods
120 
121  /// @brief Sets the width of the border for this renderable.
122  /// @param Width The width to set for the border.
123  virtual void SetBorderWidth(const Real Width);
124  /// @brief Sets the colour of the border for this renderable.
125  /// @param Colour The colour to set for the border.
126  virtual void SetBorderColour(const ColourValue& Colour);
127  /// @brief Sets the colour of one side of the border for this renderable.
128  /// @param Side The side to have the colour applied to.
129  /// @param Colour The colour to be applied.
130  virtual void SetBorderColour(const UI::Border Side, const ColourValue& Colour);
131  /// @brief Sets all parameters for enabling a border.
132  /// @param Width The width to set for the border.
133  /// @param Colour The colour to be applied to all sides of the border.
134  virtual void SetBorder(const Real Width, const ColourValue& Colour);
135  /// @brief Sets all parameters for enabling a border.
136  /// @param Width The width to set for the border.
137  /// @param North The colour to apply to the north side of the border.
138  /// @param South The colour to apply to the south side of the border.
139  /// @param East The colour to apply to the east side of the border.
140  /// @param West The colour to apply to the west side of the border.
141  virtual void SetBorder(const Real Width, const ColourValue& North, const ColourValue& South, const ColourValue& East, const ColourValue& West);
142  /// @brief Disables any border set on this renderable if one is currently set.
143  virtual void NoBorder();
144  /// @brief Gets the border width of this renderable.
145  /// @return Returns a Real with the currently set width of the border.
146  virtual Real GetBorderWidth() const;
147  /// @brief Gets the colour of a border on this renderable.
148  /// @param Side The side to retrieve the colour for.
149  /// @return Returns the colour of the border on the specified side.
150  virtual const ColourValue& GetBorderColour(const UI::Border Side) const;
151 
152  ///////////////////////////////////////////////////////////////////////////////
153  // Serialization
154 
155  /// @copydoc SimpleRenderer::ProtoSerializeProperties(XML::Node&) const
156  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
157  /// @copydoc SimpleRenderer::ProtoDeSerializeProperties(const XML::Node&)
158  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
159 
160  /// @copydoc SimpleRenderer::GetDerivedSerializableName() const
161  virtual String GetDerivedSerializableName() const;
162  /// @copydoc SimpleRenderer::GetSerializableName()
163  static String GetSerializableName();
164  };//ImageLayer
165  }//UI
166 }//Mezzanine
167 
168 #endif