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

Base class for bitmap objects. More...

#include <Sprite.hpp>

Inheritance diagram for nom::Sprite:
[legend]

Public Types

typedef Sprite self_type
typedef Transformable derived_class
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

bool init_with_color (const Color4i &color, const Size2i &dims)
 Construct a sprite from a dimension and color.
ObjectTypeInfo type () const override
 Re-implements the IObject::type method.
virtual void set_position (const Point2i &pos) override
 Re-implements Transformable::set_position.
virtual void set_size (const Size2i &dims) override
 Re-implements Transformable::set_size.
std::unique_ptr< Sprite > clone () const
 Implements the required IDrawable::clone method.
std::shared_ptr< Texturetexture () const
bool valid () const
Color4i color () const
 Get the texture color of the sprite.
BlendMode color_blend_mode () const
 Get the color blend mode of the sprite.
uint8 alpha () const
 Get the alpha value of the sprite.
bool set_texture (Texture &tex)
 Construct a sprite from an existing texture source.
bool set_texture (Texture *tex)
 Construct a sprite from an existing texture source.
bool set_texture (std::shared_ptr< Texture > &tex)
 Construct a sprite from an existing texture source.
bool set_alpha (uint8 opacity)
bool set_color (const Color4i &color)
bool set_color_blend_mode (BlendMode blend)
void release_texture ()
 Free the stored texture.
virtual void draw (RenderTarget &target) const override
 Render the object onto the primary video buffer – your visible screen.
virtual void draw (RenderTarget &target, real64 angle) const
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.

Protected Attributes

std::shared_ptr< Texturetexture_
 The underlying texture for the sprite.

Private Member Functions

virtual void update () override

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

Base class for bitmap objects.

Definition at line 48 of file Sprite.hpp.

Member Typedef Documentation

◆ derived_class

typedef Transformable nom::Sprite::derived_class

Definition at line 52 of file Sprite.hpp.

◆ self_type

typedef Sprite nom::Sprite::self_type

Definition at line 51 of file Sprite.hpp.

Member Function Documentation

◆ draw() [1/2]

virtual void nom::Sprite::draw ( RenderTarget & ) const
overridevirtual

Render the object onto the primary video buffer – your visible screen.

Implements nom::IDrawable.

Reimplemented in nom::SpriteBatch.

◆ draw() [2/2]

virtual void nom::Sprite::draw ( RenderTarget & target,
real64 angle ) const
virtual

Draw a rotated nom::Sprite on a nom::RenderWindow

Parameters
targetReference to an active nom::RenderWindow
angleRotation angle in degrees

Reimplemented in nom::SpriteBatch.

◆ init_with_color()

bool nom::Sprite::init_with_color ( const Color4i & color,
const Size2i & dims )

Construct a sprite from a dimension and color.

\params color The color to fill the sprite bounds with. \params dims The width and height, in pixels, of the sprite.

Returns
Boolean TRUE on successful construction, or boolean FALSE when construction has failed, such as when the texture is invalid, or a failure to allocate the necessary memory.
Remarks
The position of the sprite will be initialized to Point2i::zero.

◆ release_texture()

void nom::Sprite::release_texture ( )

Free the stored texture.

Remarks
This decrements the shared reference count, potentially freeing the resource.

◆ set_position()

virtual void nom::Sprite::set_position ( const Point2i & pos)
overridevirtual

Re-implements Transformable::set_position.

Reimplemented from nom::Transformable.

◆ set_size()

virtual void nom::Sprite::set_size ( const Size2i & dims)
overridevirtual

Re-implements Transformable::set_size.

Reimplemented from nom::Transformable.

◆ set_texture() [1/3]

bool nom::Sprite::set_texture ( std::shared_ptr< Texture > & tex)

Construct a sprite from an existing texture source.

\params tex An existing, valid nom::Texture pointer.

Returns
Boolean TRUE on successful construction, or boolean FALSE when construction has failed, such as when the texture is invalid, or a failure to allocate the necessary memory.

◆ set_texture() [2/3]

bool nom::Sprite::set_texture ( Texture & tex)

Construct a sprite from an existing texture source.

\params tex An existing, valid nom::Texture reference.

Returns
Boolean TRUE on successful construction, or boolean FALSE when construction has failed, such as when the texture is invalid, or a failure to allocate the necessary memory.
Remarks
The passed in nom::Texture instance must outlive the destruction of this sprite!

◆ set_texture() [3/3]

bool nom::Sprite::set_texture ( Texture * tex)

Construct a sprite from an existing texture source.

\params tex An existing, valid nom::Texture pointer.

Returns
Boolean TRUE on successful construction, or boolean FALSE when construction has failed, such as when the texture is invalid, or a failure to allocate the necessary memory.
Remarks
The ownership of the pointer is transferred to this sprite.

◆ type()

ObjectTypeInfo nom::Sprite::type ( ) const
overridevirtual

Re-implements the IObject::type method.

Remarks
This uniquely identifies the object's type.

Reimplemented from nom::IDrawable.

Reimplemented in nom::SpriteBatch.

◆ update()

virtual void nom::Sprite::update ( )
overrideprivatevirtual

Intended to be used internally by the class re-implementing this method; for use in preparing the buffer to be drawn using the draw method call. Whereas both Update & Draw are typically publicly exposed to the end-user, only the Draw method call should be expected of the end-user to be explicitly called.

Todo
Not all the interfaced (inherited) IDrawable objects in this library conform to the expectations stated above. We need to first figure out if we wish to stay on this course (of expectation), or diverge all together. Undecided. Jeffrey Carpenter i8deg.nosp@m.rees.nosp@m.@gmai.nosp@m.l.co.nosp@m.m @ 2013-10-03

Implements nom::IDrawable.

Reimplemented in nom::SpriteBatch.

Member Data Documentation

◆ texture_

std::shared_ptr<Texture> nom::Sprite::texture_
protected

The underlying texture for the sprite.

Definition at line 152 of file Sprite.hpp.


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