Gradient.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_SDL2_GRADIENT_HPP
30 #define NOMLIB_SDL2_GRADIENT_HPP
31 
32 #include <iostream>
33 #include <string>
34 #include <vector>
35 #include <memory>
36 #include <utility>
37 
38 #include "nomlib/config.hpp"
39 #include "nomlib/math/Coords.hpp"
40 #include "nomlib/math/Color.hpp"
41 #include "nomlib/graphics/IDrawable.hpp"
42 #include "nomlib/graphics/shapes/Rectangle.hpp"
43 #include "nomlib/system/make_unique.hpp"
44 
45 namespace nom {
46 
48 class Gradient:
49  public IDrawable
50 
51 {
52  public:
53  typedef std::shared_ptr<Gradient> SharedPtr;
54  typedef std::unique_ptr<Gradient> UniquePtr;
55  typedef Gradient* RawPtr;
56 
61  {
62  Top = 0, // Top down
63  Bottom, // Bottom's up!
64  Left, // Left to right
65  Right // Right to left
66  };
67 
70  Gradient ( void );
71 
75  Gradient (
76  Color gradient_color[2],
77  const Coords& bounds, int32 x_margin, int32 y_margin,
78  Gradient::FillDirection direction
79  );
80 
82  virtual ~Gradient ( void );
83 
85  void initialize (
86  Color gradient_color[2],
87  const Coords& bounds, int32 x_margin, int32 y_margin,
88  Gradient::FillDirection direction
89  );
90 
91  const Coords getPosition ( void ) const;
92  const Coords getSize ( void ) const;
93  Color getStartColor ( void ) const;
94  Color getEndColor ( void ) const;
95  Gradient::FillDirection getFillDirection ( void ) const;
96  bool dithering ( void ) const;
97 
98  void setStartColor ( const Color& starting_color );
99  void setEndColor ( const Color& ending_color );
100  void reverseColors ( void );
101  void setFillDirection ( Gradient::FillDirection direction );
102  void setPosition ( int32 x, int32 y );
103  void setSize ( int32 width, int32 height );
104  void setMargins ( int32 x, int32 y );
105  void enableDithering ( bool toggle );
106 
107  void update ( void );
108  void draw ( RenderTarget target ) const;
109 
110  private:
111  void strategyTopDown ( void );
112  void strategyLeftToRight ( void );
113 
121 
130 
133 
135  int32 x_margin;
136 
138  int32 y_margin;
139 
142 
145 };
146 
147 
148 } // namespace nom
149 
150 #endif // include guard defined
151 
168 
171 
void initialize(Color gradient_color[2], const Coords &bounds, int32 x_margin, int32 y_margin, Gradient::FillDirection direction)
Fully initialize this object.
Definition: Gradient.cpp:68
void update(void)
Definition: Gradient.cpp:209
virtual ~Gradient(void)
Destructor; OK to inherit me.
Definition: Gradient.cpp:66
IDrawable::UniqueDrawables rectangles
Definition: Gradient.hpp:120
void draw(RenderTarget target) const
Render the object onto the primary video buffer – your visible screen.
Definition: Gradient.cpp:233
int32 x_margin
x coordinate offset
Definition: Gradient.hpp:135
bool enable_dithering
Toggle automatic dithering of colors.
Definition: Gradient.hpp:144
Gradient(void)
Definition: Gradient.cpp:33
Base interface class for grouping objects under a united front.
Definition: IDrawable.hpp:43
enum Gradient::FillDirection fill_direction
Color fill axis – X or Y increment.
Definition: Gradient.hpp:141
Rectangle fill class with dithered, linear gradient colors.
Definition: Gradient.hpp:48
Coords coords
Rendering coordinates (X, Y, width &amp; height)
Definition: Gradient.hpp:132
Color gradient[2]
Definition: Gradient.hpp:129
Coordinate values (x, y, z, width, height ) wrapper.
Definition: Coords.hpp:44
int32 y_margin
y coordinate offset
Definition: Gradient.hpp:138
std::vector< std::unique_ptr< IDrawable > > UniqueDrawables
std::unique_ptr vector container type
Definition: IDrawable.hpp:54
Utility class container for RGBA colors.
Definition: Color.hpp:43