29 #include "nomlib/graphics/Gradient.hpp"
35 Color gradient_color[2];
37 gradient_color[1] = Color::Gray;
41 Coords ( 0, 0, 0, 0 ), 0, 0, Gradient::FillDirection::Left
46 Color gradient_color[2],
47 const Coords& bounds, int32 x_margin, int32 y_margin,
50 : gradient {}, coords { bounds },
51 x_margin ( x_margin ), y_margin ( y_margin ), fill_direction ( direction ),
52 enable_dithering (
true )
54 this->setStartColor ( gradient_color[0] );
55 this->setEndColor ( gradient_color[1] );
69 Color gradient_color[2],
71 int32 x_margin, int32 y_margin,
75 this->setStartColor ( gradient_color[0] );
76 this->setEndColor ( gradient_color[1] );
77 this->setSize ( bounds.width, bounds.height );
78 this->setPosition ( bounds.x, bounds.y );
79 this->setMargins ( x_margin, y_margin );
80 this->setFillDirection ( direction );
83 this->enableDithering (
true );
86 const Coords Gradient::getPosition (
void )
const
91 const Coords Gradient::getSize (
void )
const
96 bool Gradient::dithering (
void )
const
101 void Gradient::setPosition ( int32 x, int32 y )
107 void Gradient::setSize ( int32 width, int32 height )
109 this->
coords.width = width;
110 this->
coords.height = height;
113 Color Gradient::getStartColor (
void )
const
118 Color Gradient::getEndColor (
void )
const
123 void Gradient::setStartColor (
const Color& starting_color )
128 void Gradient::setEndColor (
const Color& ending_color )
133 void Gradient::reverseColors (
void )
148 void Gradient::setMargins ( int32 x, int32 y )
154 void Gradient::enableDithering (
bool toggle )
159 void Gradient::strategyTopDown (
void )
163 float currentR = (float)
gradient[0].red;
164 float currentG = (float)
gradient[0].green;
165 float currentB = (float)
gradient[0].blue;
167 float destR = (float) (
gradient[1].red -
gradient[0].red ) / ( float ) ( this->
coords.height - this->y_margin );
168 float destG = (float) (
gradient[1].green -
gradient[0].green ) / ( float ) ( this->
coords.height - this->y_margin );
169 float destB = (float) (
gradient[1].blue -
gradient[0].blue ) / ( float ) ( this->
coords.height - this->y_margin );
171 for ( uint32 rows = this->
coords.y + this->y_margin; rows < y_offset; rows++ )
173 this->
rectangles.push_back (
IDrawable::UniquePtr (
new Rectangle ( Coords ( this->
coords.x + this->x_margin, rows, this->coords.width - this->x_margin, 1 ), Color ( currentR, currentG, currentB ) ) ) );
175 if ( this->dithering() )
184 void Gradient::strategyLeftToRight (
void )
188 float currentR = (float)
gradient[0].red;
189 float currentG = (float)
gradient[0].green;
190 float currentB = (float)
gradient[0].blue;
192 float destR = (float) (
gradient[1].red -
gradient[0].red ) / ( float ) ( this->
coords.width - this->x_margin );
193 float destG = (float) (
gradient[1].green -
gradient[0].green ) / ( float ) ( this->
coords.width - this->x_margin );
194 float destB = (float) (
gradient[1].blue -
gradient[0].blue ) / ( float ) ( this->
coords.width - this->x_margin );
196 for ( uint32 rows = this->
coords.x + this->x_margin; rows < x_offset; rows++ )
198 this->
rectangles.push_back (
IDrawable::UniquePtr (
new Rectangle ( Coords ( rows, this->
coords.y + this->y_margin, 1, this->coords.height - this->y_margin ), Color ( currentR, currentG, currentB ) ) ) );
200 if ( this->dithering() )
213 if ( this->getFillDirection() == FillDirection::Top )
215 this->strategyTopDown();
217 else if ( this->getFillDirection() == FillDirection::Bottom )
219 this->reverseColors();
220 this->strategyTopDown();
222 else if ( this->getFillDirection() == FillDirection::Left )
224 this->strategyLeftToRight();
226 else if ( this->getFillDirection() == FillDirection::Right )
228 this->reverseColors();
229 this->strategyLeftToRight();
235 for (
auto idx = 0; idx != this->
rectangles.size(); ++idx )
void initialize(Color gradient_color[2], const Coords &bounds, int32 x_margin, int32 y_margin, Gradient::FillDirection direction)
Fully initialize this object.
virtual ~Gradient(void)
Destructor; OK to inherit me.
IDrawable::UniqueDrawables rectangles
void draw(RenderTarget target) const
Render the object onto the primary video buffer – your visible screen.
int32 x_margin
x coordinate offset
bool enable_dithering
Toggle automatic dithering of colors.
static const Color LightGray
Additional predefined color constants.
enum Gradient::FillDirection fill_direction
Color fill axis – X or Y increment.
Coords coords
Rendering coordinates (X, Y, width & height)
std::unique_ptr< IDrawable > UniquePtr
std::unique_ptr definition type for your convenience, sir!
Coordinate values (x, y, z, width, height ) wrapper.
int32 y_margin
y coordinate offset
Utility class container for RGBA colors.