Sprite.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_SPRITE_HPP
30 #define NOMLIB_SDL2_SPRITE_HPP
31 
32 #include <iostream>
33 #include <string>
34 #include <memory>
35 
36 #include "nomlib/config.hpp"
37 #include "nomlib/math/Transformable.hpp"
38 #include "nomlib/math/Rect-inl.hpp"
39 #include "nomlib/math/Point2-inl.hpp"
40 #include "nomlib/graphics/Texture.hpp"
41 #include "nomlib/graphics/Renderer.hpp"
42 
43 namespace nom {
44 
46 class Sprite:
47  public Transformable
48 {
49  public:
52  Sprite ( void );
53 
55  Sprite ( int32 width, int32 height );
56 
58  Sprite& operator = ( const Sprite& other );
59 
61  virtual ~Sprite ( void );
62 
63  const Point2i size ( void ) const;
64  const Point2i position ( void ) const;
65 
67  uint32 getState ( void ) const;
68 
70  void setState ( uint32 state );
71 
73  bool load (
74  const std::string& filename,
75  const Color& colorkey,
76  bool use_cache = false
77  );
78 
79  virtual void update ( void );
80  void draw ( RenderTarget target ) const;
81 
87  void draw ( RenderTarget target, const double angle ) const;
88 
90  bool resize ( enum ResizeAlgorithm scaling_algorithm );
91 
92  bool resize ( const Point2f& scale_factor );
93 
94  protected:
97 
99  uint32 state;
100 
103 };
104 
105 
106 } // namespace nom
107 
108 #endif // include guard defined
int32 scale_factor
Scale factor applied if the resize method is called.
Definition: Sprite.hpp:102
virtual void update(void)
Definition: Sprite.cpp:104
virtual ~Sprite(void)
Destructor.
Definition: Sprite.cpp:56
bool resize(enum ResizeAlgorithm scaling_algorithm)
Rescale the font with a chosen resizing algorithm.
Definition: Sprite.cpp:121
Texture sprite
Object that holds our sprite image.
Definition: Sprite.hpp:96
bool load(const std::string &filename, const Color &colorkey, bool use_cache=false)
Load a new image onto the Sprite.
Definition: Sprite.cpp:81
void draw(RenderTarget target) const
Render the object onto the primary video buffer – your visible screen.
Definition: Sprite.cpp:109
uint32 state
Convenience instance variable (user-defined)
Definition: Sprite.hpp:99
Sprite(void)
Definition: Sprite.cpp:33
Sprite & operator=(const Sprite &other)
Copy assignment operator.
Definition: Sprite.cpp:46
uint32 getState(void) const
Get the object&#39;s state.
Definition: Sprite.cpp:71
void setState(uint32 state)
Set a new state.
Definition: Sprite.cpp:76
Utility class container for RGBA colors.
Definition: Color.hpp:43
Base class for bitmap objects.
Definition: Sprite.hpp:46