SDL2lazy
SlSprite.h
Go to the documentation of this file.
1 // part of SDL2lazy
2 // author: Ulrike Hager
3 
11 #ifndef SLSPRITE_H
12 #define SLSPRITE_H
13 
14 
15 #include <cstdint>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 #include <SDL2/SDL.h>
21 #include <SDL2/SDL_image.h>
22 
23 #include "SlRenderOptions.h"
24 #include "SlTexture.h"
25 
26 
27 
33 {
36  SDL_Rect destinationRect = {0,0,0,0};
43  uint8_t color[4] = {0x00, 0x00, 0x00, 0xFF};
46  uint32_t renderOptions = SL_RENDER_DEFAULT;
49  double angle = 0;
50 };
51 
52 
53 
59 class SlSprite
60 {
61  public:
69  SlSprite(const std::string& name, SlTexture* texture, int x = 0, int y = 0, int width = 0, int height = 0);
70 
71  ~SlSprite();
74  SlSprite(const SlSprite&) = delete;
77  SlSprite &operator=(const SlSprite&) = delete;
78 
85  SlSprite* addDestination(int x, int y, uint32_t renderOptions = SL_RENDER_DEFAULT);
88  SlSprite* centerInSprite(const std::shared_ptr<SlSprite> otherSprite, unsigned int destinationThis = 0, unsigned int destinationOther = 0);
91  SlSprite* centerAt( unsigned int x, unsigned int y, unsigned int destination = 0);
94  void clearDestinations();
97  SDL_Rect destination(unsigned int i = 0);
100  void destinationDimension(int& width, int& height, unsigned int i = 0);
103  void destinationOrigin(int& x, int& y, unsigned int i = 0);
106  bool hasDestination();
109  bool is_inside(const int& x, const int& y, const unsigned int& dest = 0);
112  void moveDestinationOriginBy(int x, int y, unsigned int i = 0);
115  std::string name() const {return name_;}
118  void render(SDL_Renderer* renderer);
122  void render(SDL_Renderer* renderer, unsigned int i);
123 
127  void setAngle(double angle, unsigned int i = 0);
131  void setColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 0xFF, unsigned int i = 0);
136  void setDestination(const SDL_Rect& dstRect, unsigned int i = 0);
141  void setDestination(int x, int y, int w, int h, unsigned int i = 0);
146  void setDestinationDimension(int width, int height, unsigned int i = 0);
150  void setDestinationOrigin(int x, int y, unsigned int i = 0);
154  void setRenderOptions(uint32_t renderOptions, unsigned int i = 0);
157  unsigned int size() {return destinations_.size();}
160  std::string textureName() const {return texture_->name();}
161 
162 
163  protected:
166  SlSprite();
170  SlSprite(const std::string& name);
173  SlSprite(SlTexture* texture);
176  std::string name_ = "unnamedSprite";
180  SDL_Rect sourceRect_ = {0,0,0,0};
186  std::vector<SlRenderSettings> destinations_;
187 
188 };
189 
190 
191 #endif // SLSPRITE_H
SlSprite * addDestination(int x, int y, uint32_t renderOptions=SL_RENDER_DEFAULT)
Definition: SlSprite.cc:83
std::string name_
Definition: SlSprite.h:176
void setDestinationDimension(int width, int height, unsigned int i=0)
Definition: SlSprite.cc:302
SlTexture class for creating SDL_Textures.
unsigned int size()
Definition: SlSprite.h:157
void destinationOrigin(int &x, int &y, unsigned int i=0)
Definition: SlSprite.cc:159
bool hasDestination()
Definition: SlSprite.cc:171
uint8_t color[4]
Definition: SlSprite.h:43
void destinationDimension(int &width, int &height, unsigned int i=0)
Definition: SlSprite.cc:148
SDL_Rect sourceRect_
Definition: SlSprite.h:180
void setDestination(const SDL_Rect &dstRect, unsigned int i=0)
Definition: SlSprite.cc:279
void clearDestinations()
Definition: SlSprite.cc:128
std::string textureName() const
Definition: SlSprite.h:160
SlSprite * centerInSprite(const std::shared_ptr< SlSprite > otherSprite, unsigned int destinationThis=0, unsigned int destinationOther=0)
Definition: SlSprite.cc:112
std::string name() const
Definition: SlTexture.h:84
void setDestinationOrigin(int x, int y, unsigned int i=0)
Definition: SlSprite.cc:313
double angle
Definition: SlSprite.h:49
Definition: SlSprite.h:59
SlSprite & operator=(const SlSprite &)=delete
SlSprite * addDefaultDestination()
Definition: SlSprite.cc:70
SlSprite()
Definition: SlSprite.cc:40
std::vector< SlRenderSettings > destinations_
Definition: SlSprite.h:186
Definition: SlSprite.h:32
void setAngle(double angle, unsigned int i=0)
Definition: SlSprite.cc:254
void render(SDL_Renderer *renderer)
Definition: SlSprite.cc:202
std::string name() const
Definition: SlSprite.h:115
SlSprite * centerAt(unsigned int x, unsigned int y, unsigned int destination=0)
Definition: SlSprite.cc:97
SDL_Rect destination(unsigned int i=0)
Definition: SlSprite.cc:136
void setRenderOptions(uint32_t renderOptions, unsigned int i=0)
Definition: SlSprite.cc:325
void moveDestinationOriginBy(int x, int y, unsigned int i=0)
Definition: SlSprite.cc:192
SDL_Rect destinationRect
Definition: SlSprite.h:36
void setColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha=0xFF, unsigned int i=0)
Definition: SlSprite.cc:264
Definition: SlTexture.h:27
bool is_inside(const int &x, const int &y, const unsigned int &dest=0)
Definition: SlSprite.cc:179
SlTexture * texture_
Definition: SlSprite.h:183
enum SlRenderOptions
uint32_t renderOptions
Definition: SlSprite.h:46