nomlib
Loading...
Searching...
No Matches
nom::Gradient Class Reference

Rectangle fill class with dithered, linear gradient colors. More...

#include <Gradient.hpp>

Inheritance diagram for nom::Gradient:
[legend]

Public Types

enum  FillDirection { Top = 0 , Bottom , Left , Right }
typedef Gradient self_type
typedef Transformable derived_class
typedef self_type * raw_ptr
typedef std::unique_ptr< self_type > unique_ptr
typedef std::shared_ptr< self_type > shared_ptr
Public Types inherited from nom::Transformable
typedef Transformable self_type
Public Types inherited from nom::IDrawable
typedef IDrawable self_type
typedef self_type * raw_ptr
 A type definition for a C pointer – raw pointer – to an IDrawable object.
typedef std::unique_ptr< self_type > unique_ptr
 A type definition for a C++11 std::unique_ptr to an IDrawable object.
typedef std::shared_ptr< self_type > shared_ptr
 A type definition for a C++11 std::shared_ptr to an IDrawable object.
typedef const RenderWindow RenderTarget
Public Types inherited from nom::IObject
typedef IObject self_type
typedef IObjectraw_ptr

Public Member Functions

 Gradient (void)
 Default constructor; initialize the object to an invalid state.
 Gradient (const Color4iColors &colors, const Point2i &pos, const Size2i &size, const Point2i &margin, Gradient::FillDirection direction)
 Construct a complete object state.
virtual ~Gradient (void)
 Destructor.
IDrawable::raw_ptr clone (void) const
 Implements the required IDrawable::clone method.
ObjectTypeInfo type (void) const
 Re-implements the IObject::type method.
Texturetexture () const
 Get the underlying texture of the rendered gradient.
bool valid (void) const
 Query the validity of the object.
const Color4i & start_color (void) const
 Get the first (starting) color used in the gradient fill.
const Color4i & end_color (void) const
 Get the last (ending) color used in the gradient fill.
Gradient::FillDirection fill_direction (void) const
bool dithering (void) const
const Point2i & margins (void) const
const Color4iColors & colors (void) const
 Get the gradient colors container.
void set_position (const Point2i &coords)
 Re-implements the Transformable::set_position method.
void set_size (const Size2i &size)
 Re-implements the Transformable::set_size method.
void set_colors (const Color4iColors &colors)
 Set the gradient colors used in the rendering of the gradient fill.
void reverse_colors (void)
 Swap the first and last color used in the gradient fill.
void set_fill_direction (Gradient::FillDirection direction)
void set_margins (const Point2i &margin)
void set_dithering (bool state)
void draw (RenderTarget &target) const
 Implements the IDrawable::draw method.
Public Member Functions inherited from nom::Transformable
 Transformable (const Point2i &pos, const Size2i &size)
 Transformable (const IntRect &bounds)
 Construct an object using a complete set of coordinates (bounds).
ObjectTypeInfo type () const override
 Re-implements the IObject::type method.
const Point2i & position (void) const
 Getter for stored positioning coordinates.
const Size2i & size (void) const
 Getter for stored size dimensions.
virtual void set_bounds (const IntRect &bounds)
 Set the complete bounds of the object – position (X, Y) and size (width and height) dimensions.
void set_position (int x, int y)
void set_size (int w, int h)
virtual void translate (const Point2i &pos)
Public Member Functions inherited from nom::IDrawable
 IDrawable (void)
 Do nothing at all default constructor.
virtual ~IDrawable (void)
 Do nothing at all destructor.
Public Member Functions inherited from nom::IObject
 IObject (void)
 Default constructor.
virtual ~IObject (void)
 Virtual destructor.
virtual bool is_type (const ObjectTypeInfo &rhs) const
 Compare this object type with another object's type.

Private Member Functions

void update (void)
 Implements the IDrawable::update method.
void strategy_top_down (void)
void strategy_left_right (void)
bool update_cache ()
 Synchronize the texture cache with the generated rectangles.

Private Attributes

std::vector< Rectanglerectangles_
 Rectangles cache; this is used to build the texture cache.
std::shared_ptr< Texturetexture_
 Render cache for the gradient.
Color4iColors gradient_
 The starting & ending colors used in the gradient fill.
Point2i margins_
 Additional offset coordinates, in pixels.
enum Gradient::FillDirection fill_direction_
 Color fill axis – X or Y increment.
bool dithering_
 Dithering (of gradient colors) state.

Additional Inherited Members

Static Public Member Functions inherited from nom::IObject
template<typename Base, typename Derived>
static bool is_a (const Derived object)
 Compare two objects to determine if a derived class inherits from a base class object.
static void * operator new (nom::size_type mem)
static void operator delete (void *ptr)
Static Public Attributes inherited from nom::IObject
static uint64 total_alloc_bytes
static uint64 total_dealloc_bytes

Detailed Description

Rectangle fill class with dithered, linear gradient colors.

nom::Gradient is a beautiful class that paints as rectangle coordinates would, but with dithered, linear gradient effects applied. Color range and fill direction are the two likely features of your interest.

Usage example:

#include <nomlib/graphics.hpp>
nom::Gradient linear;
linear.set_size ( 64, 64 );
linear.set_margins ( 4, 4 );
linear.set_fill_direction ( nom::Gradient::FillDirection::Top ); */

Definition at line 51 of file Gradient.hpp.

Member Typedef Documentation

◆ derived_class

typedef Transformable nom::Gradient::derived_class

Definition at line 56 of file Gradient.hpp.

◆ raw_ptr

typedef self_type* nom::Gradient::raw_ptr

Definition at line 58 of file Gradient.hpp.

◆ self_type

typedef Gradient nom::Gradient::self_type

Definition at line 55 of file Gradient.hpp.

◆ shared_ptr

typedef std::shared_ptr<self_type> nom::Gradient::shared_ptr

Definition at line 60 of file Gradient.hpp.

◆ unique_ptr

typedef std::unique_ptr<self_type> nom::Gradient::unique_ptr

Definition at line 59 of file Gradient.hpp.

Member Enumeration Documentation

◆ FillDirection

Todo
Rename me – Direction seems fitting? Jeffrey Carpenter i8deg.nosp@m.rees.nosp@m.@gmai.nosp@m.l.co.nosp@m.m @ 2013-10-05

Definition at line 65 of file Gradient.hpp.

Constructor & Destructor Documentation

◆ Gradient() [1/2]

nom::Gradient::Gradient ( void )

Default constructor; initialize the object to an invalid state.

Remarks
At the very minimum, you must set the position & size to get a rendered object on screen. The default gradient colors is an opaque Color4i::Blue set as both the starting and ending color fill to signify an invalid object state.

◆ Gradient() [2/2]

nom::Gradient::Gradient ( const Color4iColors & colors,
const Point2i & pos,
const Size2i & size,
const Point2i & margin,
Gradient::FillDirection direction )

Construct a complete object state.

Parameters
colorsThe list of Color4i objects to be used in the gradient.

Member Function Documentation

◆ draw()

void nom::Gradient::draw ( RenderTarget & target) const
virtual

Implements the IDrawable::draw method.

Remarks
target This parameter is not currently used; the current rendering context is instead used.

Implements nom::IDrawable.

◆ set_position()

void nom::Gradient::set_position ( const Point2i & coords)
virtual

Re-implements the Transformable::set_position method.

Remarks
Thie method call is necessary in order to ensure the internal object state remains consistent.

Reimplemented from nom::Transformable.

◆ set_size()

void nom::Gradient::set_size ( const Size2i & size)
virtual

Re-implements the Transformable::set_size method.

Remarks
Thie method call is necessary in order to ensure the internal object state remains consistent.

Reimplemented from nom::Transformable.

◆ texture()

Texture * nom::Gradient::texture ( ) const

Get the underlying texture of the rendered gradient.

Returns
A pointer to a new nom::Texture instance of the stored texture used for rendering the gradient. The returned pointer is owned by the caller.
Remarks
This is not a deep-copy of the texture.

◆ type()

ObjectTypeInfo nom::Gradient::type ( void ) const
virtual

Re-implements the IObject::type method.

Remarks
This uniquely identifies the object's type.

Reimplemented from nom::IDrawable.

◆ update()

void nom::Gradient::update ( void )
privatevirtual

Implements the IDrawable::update method.

Implements nom::IDrawable.

◆ update_cache()

bool nom::Gradient::update_cache ( )
private

Synchronize the texture cache with the generated rectangles.

Returns
Boolean TRUE when the texture cache has been successfully updated, boolean FALSE when it hasn't been updated, such as when the rendering context is invalid, or if the driver does not support FBOs.

◆ valid()

bool nom::Gradient::valid ( void ) const

Query the validity of the object.

Remarks
A valid object must have both the positioning & size bounding coordinates be set to a non-null object value. See nom::Point2i::null and nom::Size2i::null for their respective values.
Note
A default constructed object is in an invalid state.

Member Data Documentation

◆ dithering_

bool nom::Gradient::dithering_
private

Dithering (of gradient colors) state.

Definition at line 203 of file Gradient.hpp.

◆ fill_direction_

enum Gradient::FillDirection nom::Gradient::fill_direction_
private

Color fill axis – X or Y increment.

Definition at line 200 of file Gradient.hpp.

◆ gradient_

Color4iColors nom::Gradient::gradient_
private

The starting & ending colors used in the gradient fill.

Todo
Finish implementing vectorized color container support; we only use the first and last color of whatever is set in the container at the moment.

Definition at line 194 of file Gradient.hpp.

◆ margins_

Point2i nom::Gradient::margins_
private

Additional offset coordinates, in pixels.

Definition at line 197 of file Gradient.hpp.

◆ rectangles_

std::vector<Rectangle> nom::Gradient::rectangles_
private

Rectangles cache; this is used to build the texture cache.

Definition at line 180 of file Gradient.hpp.

◆ texture_

std::shared_ptr<Texture> nom::Gradient::texture_
private

Render cache for the gradient.

Remarks
This greatly optimizes performance of this class when there are a large number of rectangles being drawn (i.e.: high resolution gradient being used as a backdrop, or several gradient objects).

Definition at line 187 of file Gradient.hpp.


The documentation for this class was generated from the following file: