Aspen
2D C++ Class-Based Object Oriented Game Engine
Aspen::Graphics::Graphics Class Reference

Graphics class. More...

#include <Graphics.hpp>

Inheritance diagram for Aspen::Graphics::Graphics:
Aspen::Object::Object

Public Member Functions

 Graphics (Object *parent=nullptr, std::string name="Graphics")
 Constructor. More...
 
 Graphics (int w, int h, Object *parent=nullptr, std::string name="Graphics")
 Constructor Derived classes should call this in their constructors' initialization list. More...
 
 ~Graphics ()
 Destructor.
 
void operator() ()
 Updates this object and all of its children Derived classes should call or reimplement this at some point in their operator() This won't run if the Object isn't Active.
 
void OnEarlyUpdate ()
 Starts the frame.
 
void OnLateUpdate ()
 Ends the frame.
 
void SetBGColor (int r, int g, int b)
 Sets the window's background color. More...
 
SDL_Surface * GetSurface ()
 Gets the surface of window. More...
 
SDL_Window * GetWindow ()
 Gets the window. More...
 
SDL_Renderer * GetRenderer ()
 Gets the hardware accelerated renderer. More...
 
void DrawRectangle (Rectangle *rect)
 Draws a given Rectangle. More...
 
void DrawRectangle (SDL_Rect *rect, Color c, bool fill=true)
 Draws a given Rectangle. More...
 
void DrawPoint (Point *point)
 Draws a given point. More...
 
void DrawPoint (SDL_Point *point, Color c)
 Draws a given point. More...
 
void DrawLine (Line *line)
 Draws a given line. More...
 
void DrawLine (SDL_Point *start, SDL_Point *end, Color c)
 Draws a specified line. More...
 
void DrawSprite (Sprite *sprite)
 Draws a given Sprite. More...
 
void DrawSprite (Sprite *sprite, SDL_Rect clip)
 Draws a given Sprite. More...
 
void DrawText (UI::Text *text)
 Draws text. More...
 
void DrawText (UI::Text *text, SDL_Rect clip)
 Draws text. More...
 
void SetCamera (Camera *camera)
 Sets the current camera. More...
 
CameraGetCamera ()
 Gets the current camera. More...
 
void End ()
 Frees the Window and shuts down SDL if this is the last Graphics object.
 
void PopulateDebugger ()
 Fills out the Debugger if it exists with this Object's information Derived classes should call their base class's version of this method.
 
- Public Member Functions inherited from Aspen::Object::Object
 Object (Object *parent=nullptr, std::string name="Object")
 Constructor Derived classes should call this in their constructors' initialization list. More...
 
virtual ~Object ()
 Destructor This will End and then delete all child Objects.
 
const ObjectParent () const
 Gets the parent of this Object. More...
 
ObjectParent ()
 Gets the parent of this Object. More...
 
const ObjectRoot () const
 Gets the root Object of the parent/child tree this Object is a part of. More...
 
ObjectRoot ()
 Gets the root Object of the parent/child tree this Object is a part of. More...
 
Transform::TransformGetTransform ()
 Gets the first child Transform::Transform. More...
 
const Transform::TransformGetTransform () const
 Gets the first child Transform::Transform. More...
 
Physics::ColliderGetCollider ()
 Gets the first child Physics::Collider. More...
 
const Physics::ColliderGetCollider () const
 Gets the first child Physics::Collider. More...
 
Physics::RigidbodyGetRigidbody ()
 Gets the first child Physics::Rigidbody. More...
 
const Physics::RigidbodyGetRigidbody () const
 Gets the first child Physics::Rigidbody. More...
 
void AddChild (Object *child)
 Adds child to this Object's list of children This will also set child's _parent to this This will do nothing if child is already in the list of children Useful for adding an already created Object as a child or passing in the return operator new with parameters. More...
 
template<typename T >
T * CreateChild ()
 Creates a new child of type T Useful for creating an object with no constructor parameters and/or modifying it later. More...
 
template<typename T >
T * CreateChild (std::string name)
 Creates a new child of type T Useful for creating an object with no constructor parameters and/or modifying it later. More...
 
void RemoveChild (Object *child)
 Removes child from this Object's list of children This will also set child's _parent to nullptr This will do nothing if child is not in the Object's list of children. More...
 
void RemoveChild (unsigned index)
 Removes the child at index from this Object's list of children This will also set the child's _parent to nullptr This will do nothing if index is out of range of the Object's list of children. More...
 
Objectoperator[] (unsigned index)
 Gets the child at index from this Object's list of children. More...
 
int operator[] (Object *child)
 Gets the index of a given child in this Object's list of children. More...
 
ObjectGetLastChild ()
 Gets the youngest child from this Object's list of children. More...
 
int ParentCount ()
 Determines the generation of this object in the parent/child tree. More...
 
template<typename T >
T * FindAncestorOfType () const
 Finds the closest ancestor Object of a type applicable to that which was requested. More...
 
template<typename T >
const T * FindChildOfType () const
 Finds the first child Object of a type applicable to that which was requested. More...
 
template<typename T >
T * FindChildOfType ()
 Finds the first child Object of a type applicable to that which was requested. More...
 
template<typename T >
const std::vector< T * > FindChildrenOfType () const
 Finds all children Objects of a type applicable to that which was requested. More...
 
template<typename T >
std::vector< T * > FindChildrenOfType ()
 Finds all children Objects of a type applicable to that which was requested. More...
 
template<typename T >
const std::vector< T * > FindDescendentsOfType () const
 Recursively finds all descendent Objects of a type applicable to that which was requested. More...
 
template<typename T >
std::vector< T * > FindDescendentsOfType ()
 Recursively finds all descendent Objects of a type applicable to that which was requested. More...
 
const bool & Valid () const
 Determines if the Object is valid. More...
 
bool Active () const
 Determines if the Object is active. More...
 
void SetActive (bool active)
 Sets active status of the object Triggers OnActivate or OnDeactivate appropriately. More...
 
void Activate ()
 Activates the object Triggers OnActivate appropriately.
 
void Deactivate ()
 Deactivates the object Triggers OnDeactivate appropriately.
 
 operator bool () const
 Converts Object to bool by calling Valid Example: ``` Object o; while (o) o(); ```.
 
void PrintTree (Log::Log &log) const
 Uses Log::Log to print the parent/children tree of this Object. More...
 
void PrintTree () const
 Uses Log::Log to print the parent/children tree of this Object Uses Log::Debug.
 
std::string Name () const
 Gets the Object's name. More...
 
unsigned ChildrenCount () const
 Determines the number of immediate children the Object has. More...
 
std::vector< Object * > & Children ()
 Gets the list of Objects that are children of this Object. More...
 
bool HasAncestor (const Object *other) const
 Determines if the provided Object is an ancestor of this Object. More...
 
virtual void OnStart ()
 Run when the Object is created.
 
virtual void OnActivate ()
 Run when the Object is activated Run after OnStart.
 
virtual void OnUpdate ()
 Run every frame.
 
virtual void OnDeactivate ()
 Run when the Object is deactivated Run before OnEnd.
 
virtual void OnEnd ()
 Run when the Object is ended/destroyed.
 
virtual void OnCollision (Physics::Collision c)
 Run when a collision occurs. More...
 
virtual void OnMouseEnter ()
 Run when the mouse enters the Object.
 
virtual void OnMouseOver ()
 Run while the mouse is over the Object.
 
virtual void OnMouseExit ()
 Run when the mouse leaves the Object.
 
virtual void OnMouseClick ()
 Run when the mouse is clicked while over the Object.
 
virtual void OnMouseRelease ()
 Run when the mouse is released while over the Object.
 

Static Public Member Functions

static GraphicsGet ()
 Gets the main graphics object. More...
 

Private Attributes

SDL_Window * _window
 Window to be displayed.
 
SDL_Surface * _surface
 Surface of _window.
 
SDL_Renderer * _renderer
 Hardware accelerated renderer.
 
Color _background
 Background color of the window.
 
Camera_camera
 Currently selected camera.
 

Static Private Attributes

static unsigned _gcount
 Number of Graphics Objects created Used for determining if SDL should be initialized or closed.
 
static Graphics_main
 First created Graphics object.
 

Additional Inherited Members

- Protected Member Functions inherited from Aspen::Object::Object
void SetParent (Object *parent)
 Sets _parent to the given Object Used by AddChild, CreateChild, etc.
 
void TriggerOnStart ()
 Runs OnStart if the object is currently active for the first time.
 
void TriggerOnActivate ()
 Runs OnActivate if the object is currently active.
 
void TriggerOnDeactivate ()
 Runs OnDeactivate if the object is currently active (being deactivated)
 
- Protected Attributes inherited from Aspen::Object::Object
const std::string _name
 Name of object.
 
Object_parent
 Parent/owner of this Object.
 
std::vector< Object * > _children
 List of children Objects.
 
bool _valid
 Determines if the Object is valid Derived classes can set this to false in their Constructors if they couldn't be created properly.
 
bool _active
 Determines if the Object is currently updated.
 
bool _started
 Determines if the Object has been started Set to true during the first update.
 
Transform::Transform_transform
 First child Transform::Transform.
 
Physics::Collider_collider
 First child Physics::Collider.
 
Physics::Rigidbody_rigidbody
 First child Physics::Rigidbody.
 
- Static Protected Attributes inherited from Aspen::Object::Object
static int _count
 Total number of Objects in existence.
 

Detailed Description

Graphics class.

Constructor & Destructor Documentation

◆ Graphics() [1/2]

Aspen::Graphics::Graphics::Graphics ( Object parent = nullptr,
std::string  name = "Graphics" 
)

Constructor.

Parameters
parentParent Object to be passed to Object constructor
nameObject name Set by derived classes to a string representation of their type

◆ Graphics() [2/2]

Aspen::Graphics::Graphics::Graphics ( int  w,
int  h,
Object parent = nullptr,
std::string  name = "Graphics" 
)

Constructor Derived classes should call this in their constructors' initialization list.

Parameters
wWidth of window
hHeight of window
parentParent Object to be passed to Object constructor
nameObject name Set by derived classes to a string representation of their type

Member Function Documentation

◆ DrawLine() [1/2]

void Aspen::Graphics::Graphics::DrawLine ( Line line)

Draws a given line.

Parameters
lineLine to draw

◆ DrawLine() [2/2]

void Aspen::Graphics::Graphics::DrawLine ( SDL_Point *  start,
SDL_Point *  end,
Color  c 
)

Draws a specified line.

Parameters
startStarting point
endEnding point
cColor to draw in

◆ DrawPoint() [1/2]

void Aspen::Graphics::Graphics::DrawPoint ( Point point)

Draws a given point.

Parameters
pointPoint to draw

◆ DrawPoint() [2/2]

void Aspen::Graphics::Graphics::DrawPoint ( SDL_Point *  point,
Color  c 
)

Draws a given point.

Parameters
pointPoint to draw
cColor to draw in

◆ DrawRectangle() [1/2]

void Aspen::Graphics::Graphics::DrawRectangle ( Rectangle rect)

Draws a given Rectangle.

Parameters
rectRectangle to draw

◆ DrawRectangle() [2/2]

void Aspen::Graphics::Graphics::DrawRectangle ( SDL_Rect *  rect,
Color  c,
bool  fill = true 
)

Draws a given Rectangle.

Parameters
rectRectangle to draw
cColor to draw in
fillDetermines if the rectangle is filled or outlined

◆ DrawSprite() [1/2]

void Aspen::Graphics::Graphics::DrawSprite ( Sprite sprite)

Draws a given Sprite.

Parameters
spriteSprite to draw

◆ DrawSprite() [2/2]

void Aspen::Graphics::Graphics::DrawSprite ( Sprite sprite,
SDL_Rect  clip 
)

Draws a given Sprite.

Parameters
spriteSprite to draw
clipClipping rectangle to apply as a mask

◆ DrawText() [1/2]

void Aspen::Graphics::Graphics::DrawText ( UI::Text text)

Draws text.

Parameters
textText to draw

◆ DrawText() [2/2]

void Aspen::Graphics::Graphics::DrawText ( UI::Text text,
SDL_Rect  clip 
)

Draws text.

Parameters
textText to draw
clipClipping rectangle to apply as a mask

◆ Get()

static Graphics* Aspen::Graphics::Graphics::Get ( )
static

Gets the main graphics object.

Returns
_main

◆ GetCamera()

Camera* Aspen::Graphics::Graphics::GetCamera ( )

Gets the current camera.

Returns
Current camera

◆ GetRenderer()

SDL_Renderer* Aspen::Graphics::Graphics::GetRenderer ( )

Gets the hardware accelerated renderer.

Returns
_renderer

◆ GetSurface()

SDL_Surface* Aspen::Graphics::Graphics::GetSurface ( )

Gets the surface of window.

Returns
_surface

◆ GetWindow()

SDL_Window* Aspen::Graphics::Graphics::GetWindow ( )

Gets the window.

Returns
_window

◆ SetBGColor()

void Aspen::Graphics::Graphics::SetBGColor ( int  r,
int  g,
int  b 
)

Sets the window's background color.

Parameters
rRed value from 0x00 to 0xFF
gGreen value from 0x00 to 0xFF
bBlue value from 0x00 to 0xFF

◆ SetCamera()

void Aspen::Graphics::Graphics::SetCamera ( Camera camera)

Sets the current camera.

Parameters
cameraCamera to use

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