3 #define SDL_MAIN_HANDLED 5 #include <SDL2/SDL_ttf.h> 53 Color(
unsigned color = 0xFFFFFFFF);
60 Color(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a = 0xFF);
89 operator SDL_Color()
const;
131 Geometry(
Object *parent =
nullptr, std::string name =
"Geometry");
139 Geometry(
Color c,
bool fill =
false,
Object *parent =
nullptr, std::string name =
"Graphics");
154 void Color(
int r,
int g,
int b,
int a);
217 Point(
Object *parent =
nullptr, std::string name =
"Point");
260 Line(
Object *parent =
nullptr, std::string name =
"Line");
315 Sprite(
Object *parent =
nullptr, std::string name =
"Sprite");
322 Sprite(std::string path,
Object *parent =
nullptr, std::string name =
"Sprite");
342 const std::string &
GetPath()
const;
382 UniformSpritesheet(std::string path,
unsigned frameCount,
Object *parent =
nullptr, std::string name =
"UniformSpritesheet");
391 UniformSpritesheet(std::string path,
unsigned frameWidth,
unsigned frameHeight,
Object *parent =
nullptr, std::string name =
"UniformSpritesheet");
401 UniformSpritesheet(std::string path,
unsigned frameWidth,
unsigned frameHeight,
unsigned frameCount,
Object *parent =
nullptr, std::string name =
"UniformSpritesheet");
487 std::map<std::string, std::string>
_paths;
489 std::map<std::pair<std::string, int>, TTF_Font *>
_fonts;
507 void LoadFont(std::string path, std::string name);
516 TTF_Font *
GetFont(std::string name,
int size);
534 Camera(
Object *parent =
nullptr, std::string name =
"Camera");
580 Graphics(
Object *parent =
nullptr, std::string name =
"Graphics");
588 Graphics(
int w,
int h,
Object *parent =
nullptr, std::string name =
"Graphics");
Geometry(Object *parent=nullptr, std::string name="Geometry")
Constructor.
void operator()()
Updates this object and all of its children Derived classes should call or reimplement this at some p...
SDL_Point & GetPoint()
Gets the SDL_Point of this object.
SDL_Surface * GetSurface()
Gets the surface of window.
bool _done
True if the animation just looped.
Definition: Graphics.hpp:432
SDL_Rect _rect
Rectangle to represent.
Definition: Graphics.hpp:172
SDL_Rect & GetRect()
Gets the SDL_Rect of this object.
SDL_Surface * _surface
Surface loaded from _path.
Definition: Graphics.hpp:304
bool Done()
True if the animation just looped.
void SetCenter(float center)
Sets the center bias of this object.
TTF_Font * GetFont(std::string name, int size)
Gets a cached font Generates a new TTF_Font if it isn't yet cached.
Sprite(Object *parent=nullptr, std::string name="Sprite")
Constructor.
Uint8 Alpha() const
Gets alpha of the color.
Geometry class Base class for creating basic geometry like rectangles.
Definition: Graphics.hpp:118
SDL_Point _end
Ending point of the line.
Definition: Graphics.hpp:249
void OnEarlyUpdate()
Starts the frame.
SDL_Renderer * GetRenderer()
Gets the hardware accelerated renderer.
bool _fill
Determines if the object is filled or outlined.
Definition: Graphics.hpp:124
void PopulateDebugger()
Fills out the Debugger if it exists with this Object's information Derived classes should call their ...
const Color GREEN
Green.
Definition: Graphics.hpp:107
void SetFill(bool fill)
Sets the fill value of the object.
Object(Object *parent=nullptr, std::string name="Object")
Constructor Derived classes should call this in their constructors' initialization list.
void SetFrame(int frame)
Sets the current frame.
void SetGraphics(Graphics *gfx)
Sets a given Graphics' camera to this.
void PopulateDebugger()
Fills out the Debugger if it exists with this Object's information Derived classes should call their ...
Point Geometry class.
Definition: Graphics.hpp:207
void DrawText(UI::Text *text)
Draws text.
void GenerateTexture()
Generates _tex and _rect when loading the texture from _path.
SDL_Texture * GetTexture()
Gets the generated texture.
float GetFrameDelay()
Gets the current frame delay.
Color class that is used to store RGBA8 color information.
Definition: Graphics.hpp:43
SDL_Renderer * _renderer
Hardware accelerated renderer.
Definition: Graphics.hpp:567
Color _c
Color of the object.
Definition: Graphics.hpp:122
Camera class.
Definition: Graphics.hpp:523
int GetFrameCount()
Gets the total number of frames Calculates this by combining the frames of all Sprite and UniformSpri...
Sprite class.
Definition: Graphics.hpp:299
General base class Allows for parent/child relationship trees.
Definition: Object.hpp:33
SDL_Texture * _tex
Texture generated from _surface.
Definition: Graphics.hpp:306
const Color BLUE
Blue.
Definition: Graphics.hpp:109
const int DEFAULT_WINDOW_WIDTH
Default created window width.
Graphics(Object *parent=nullptr, std::string name="Graphics")
Constructor.
static unsigned _gcount
Number of Graphics Objects created Used for determining if SDL should be initialized or closed.
Definition: Graphics.hpp:561
Color(unsigned color=0xFFFFFFFF)
Constructor.
SDL_Point _start
Starting point of the line.
Definition: Graphics.hpp:247
SDL_Point & GetStart()
Gets the starting point of this object.
SDL_Surface * GetSurface()
Gets the loaded surface.
const int DEFAULT_WINDOW_HEIGHT
Default created window height.
Graphics class.
Definition: Graphics.hpp:557
void DrawLine(Line *line)
Draws a given line.
Color _background
Background color of the window.
Definition: Graphics.hpp:569
Animation(Object *parent=nullptr, std::string name="Animation")
Constructor Derived classes should call this in their constructors' initialization list.
void SelectCamera()
Finds the graphics in the main expected location and sets its camera to this Engine +— Graphics +— Ga...
Line Geometry class.
Definition: Graphics.hpp:244
Graphics * GetGraphics()
Gets the Graphics object currently using this camera.
float & GetCenter()
Gets the center bias of this object.
SDL_Point & GetEnd()
Gets the ending point of this object.
void UnloadFont(std::string name)
Removes the font from the recognized list and unloads all cached fonts by that name.
void PopulateDebugger()
Fills out the Debugger if it exists with this Object's information Derived classes should call their ...
std::map< std::string, std::string > _paths
Map of Font names to paths.
Definition: Graphics.hpp:487
void DrawSprite(Sprite *sprite)
Draws a given Sprite.
void operator()()
Updates this object and all of its children Derived classes should call or reimplement this at some p...
Green component of a color.
Definition: Graphics.hpp:35
static Graphics * Get()
Gets the main graphics object.
FontCache class Caches loaded fonts for drawing text with.
Definition: Graphics.hpp:484
const std::string & GetPath() const
Gets the path passed into the constructor.
Uint8 Green() const
Gets green of the color.
Color & Color()
Gets the color of the object.
float _delay
Delay in seconds between each frame.
Definition: Graphics.hpp:428
Camera * GetCamera()
Gets the current camera.
Red component of a color.
Definition: Graphics.hpp:33
const Color WHITE
White.
Definition: Graphics.hpp:111
Uint8 Red() const
Gets red of the color.
void End()
Shuts down and invalidates Object and all of its children An invalid child Object will be deleted by ...
void DrawRectangle(Rectangle *rect)
Draws a given Rectangle.
void SetParent(Object *parent)
Wrapper for Object::SetParent.
std::string _path
Path of file loaded as a sprite.
Definition: Graphics.hpp:302
Point(Object *parent=nullptr, std::string name="Point")
Constructor.
Blue component of a color.
Definition: Graphics.hpp:37
FontCache(Object *parent=nullptr, std::string name="FontCache")
Constructor Derived classes should call this in their constructors' initialization list.
const Color TRANSPARENT
Fully transparent.
Definition: Graphics.hpp:113
Text class.
Definition: UI.hpp:22
void End()
Frees the Window and shuts down SDL if this is the last Graphics object.
SDL_Surface * _surface
Surface of _window.
Definition: Graphics.hpp:565
int _currentFrame
Current frame of the animation.
Definition: Graphics.hpp:426
void DrawPoint(Point *point)
Draws a given point.
void operator()()
Updates this object and all of its children Derived classes should call or reimplement this at some p...
void PopulateDebugger()
Fills out the Debugger if it exists with this Object's information Derived classes should call their ...
Line(Object *parent=nullptr, std::string name="Line")
Constructor.
void operator()()
Draws the sprite to the parent Object's window if parent is of type Graphics.
Uint8 Blue() const
Gets blue of the color.
const Color BLACK
Black.
Definition: Graphics.hpp:103
static Graphics * _main
First created Graphics object.
Definition: Graphics.hpp:573
int GetFrame()
Gets the current frame.
bool Fill()
Gets the fill value of the object.
void PopulateDebugger()
Fills out the Debugger if it exists with this Object's information Derived classes should call their ...
void operator()()
Draws the sprite to the parent Object's window if parent is of type Graphics.
SDL_Point _point
Point to represent.
Definition: Graphics.hpp:210
SDL_Rect _rect
Rectangle to draw _tex with.
Definition: Graphics.hpp:308
float _center
Center bias of the line Range: (0, 1) Center point: _start * _center + _end * (1 - _center)
Definition: Graphics.hpp:253
void PopulateDebugger()
Fills out the Debugger if it exists with this Object's information Derived classes should call their ...
void SetCamera(Camera *camera)
Sets the current camera.
unsigned _c
RGBA8 color.
Definition: Graphics.hpp:47
bool operator==(const Color &rhs) const
Equality operator.
void SetFrameDelay(float delay)
Sets the frame delay.
void LoadFont(std::string path)
Adds the requested font to the list of recognized paths.
Rectangle(Object *parent=nullptr, std::string name="Rectangle")
Constructor.
Camera * _camera
Currently selected camera.
Definition: Graphics.hpp:571
const Color RED
Red.
Definition: Graphics.hpp:105
void OnLateUpdate()
Ends the frame.
void operator()()
Updates this object and all of its children Derived classes should call or reimplement this at some p...
float _remainingDelay
Delay in seconds before the next frame change.
Definition: Graphics.hpp:430
Alpha component of a color.
Definition: Graphics.hpp:39
void End()
Shuts down and invalidates Object and all of its children An invalid child Object will be deleted by ...
Aspen engine namespace.
Definition: Audio.hpp:8
Camera(Object *parent=nullptr, std::string name="Camera")
Constructor Derived classes should call this in their constructors' initialization list.
Graphics * _gfx
Graphics object currently using the Camera.
Definition: Graphics.hpp:526
Rectangle Geometry class.
Definition: Graphics.hpp:169
std::map< std::pair< std::string, int >, TTF_Font * > _fonts
Map of (Font name, Font size) to loaded fonts.
Definition: Graphics.hpp:489
void SetBGColor(int r, int g, int b)
Sets the window's background color.
SDL_Rect & GetRect()
Gets the rectangle _tex is drawn to.
void PopulateDebugger()
Fills out the Debugger if it exists with this Object's information Derived classes should call their ...
Animation class Gets all animation frames from child Sprite and UniformSpritesheet Objects.
Definition: Graphics.hpp:423
SDL_Window * GetWindow()
Gets the window.
COLOR_MASK
Masks used to extract individual color components from a color.
Definition: Graphics.hpp:30
SDL_Window * _window
Window to be displayed.
Definition: Graphics.hpp:563