Aether
SDL2 based UI Framework for NX
Drawable.hpp
1 #ifndef AETHER_DRAWABLE_HPP
2 #define AETHER_DRAWABLE_HPP
3 
4 #include "Aether/types/Colour.hpp"
5 #include "Aether/types/ImageData.hpp"
6 #include "Aether/Renderer.hpp"
7 
8 // Forward declare types as we only need a pointer here
9 namespace Aether {
10  class Renderer;
11 };
12 struct SDL_Surface;
13 struct SDL_Texture;
14 
15 namespace Aether {
22  class Drawable {
23  public:
27  enum class Type {
28  None,
29  Surface,
30  Texture
31  };
32 
33  private:
37  union Data {
38  SDL_Surface * surface;
39  SDL_Texture * texture;
40  } data;
41 
42  Colour colour_;
43  Renderer * renderer;
44  Type type_;
46  unsigned int width_;
47  unsigned int height_;
49  int maskX;
50  int maskY;
51  int maskW;
52  int maskH;
54  public:
59  Drawable();
60 
69  Drawable(Renderer * renderer, SDL_Surface * surf, const unsigned int width, const unsigned int height);
70 
79  Drawable(Renderer * renderer, SDL_Texture * tex, const unsigned int width, const unsigned int height);
80 
86 
92  void setColour(const Colour & colour);
93 
102  void setMask(const int x, const int y, const unsigned int width, const unsigned int height);
103 
112  void render(const int x, const int y, const unsigned int width = 0, const unsigned int height = 0);
113 
121  bool convertToTexture();
122 
128  Type type();
129 
135  int width();
136 
142  int height();
143 
147  ~Drawable();
148  };
149 };
150 
151 #endif
void setColour(const Colour &colour)
Set colour to tint Drawable with when rendered.
Type
Type of raw data stored.
Definition: Drawable.hpp:27
ImageData getImageData()
Returns the ImageData for the currently stored image.
void render(const int x, const int y, const unsigned int width=0, const unsigned int height=0)
Render the Drawable on screen at the given coordinates.
bool convertToTexture()
Convert the contained surface to a texture. Has no effect if the Drawable does not contain a surface...
int width()
Returns the width of the Drawable in pixels.
Aether's main renderer instance. It provides all methods relating to drawing directly to the screen...
Definition: Renderer.hpp:30
Stores RGBA values representing a colour. Each component can be within the range 0 to 255 (inclusive)...
Definition: Colour.hpp:9
Stores either a surface or texture which can be drawn on screen by providing a renderer to render()...
Definition: Drawable.hpp:22
int height()
Returns the height of the Drawable in pixels.
A Texture is an element that stores a texture to render in the window. It can't be instantiated alone...
Definition: Texture.hpp:24
Base namespace for all Aether related classes and functions.
~Drawable()
Destructor ensures contained data is deleted appropriately.
Drawable()
Height of mask.
Represents an object containing the raw pixel data for an image/texture as an array, along with required metadata such as width and height.
Definition: ImageData.hpp:16
void setMask(const int x, const int y, const unsigned int width, const unsigned int height)
Set the mask (area to draw)
Type type()
Returns the type of the data stored.