LPCGame
A Simple 2d Game Engine
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Window Class Reference

Handles the window. More...

#include <window.h>

Static Public Member Functions

static void Init (std::string title="Window")
 
static void Quit ()
 Quit SDL.
 
static void DrawTexture (SDL_Texture *tex, const Rectf &dstRect, Recti *clip=NULL, float angle=0.0, Vector2f pivot=Vector2f(0, 0), SDL_RendererFlip flip=SDL_FLIP_NONE)
 
static void Draw (Image *image, const Rectf &dstRect, Recti *clip=NULL, float angle=0.0, Vector2f pivot=Vector2f(0, 0), int flip=SDL_FLIP_NONE)
 
static void Draw (AnimatedImage *img, const Rectf &dstRect, float angle=0.0, Vector2f pivot=Vector2f(0, 0), int flip=SDL_FLIP_NONE)
 
static void Draw (Text *text, const Rectf &dstRect, float angle=0.0, Vector2f pivot=Vector2f(0, 0), int flip=SDL_FLIP_NONE)
 
static SDL_Texture * LoadTexture (std::string file)
 
static SDL_Texture * RenderText (std::string message, std::string fontFile, Color color, int fontSize)
 
static SDL_Texture * SurfaceToTexture (SDL_Surface *surf)
 
static void Clear ()
 Clear the renderer.
 
static void Present ()
 Present the renderer, ie. update screen.
 
static void HandleEvents (SDL_Event &e)
 
static Recti Box ()
 Get the window's box.
 
static void ShowAvgFps (bool log)
 

Detailed Description

Handles the window.

Window management class, provides a simple wrapper around the SDL_Window and SDL_Renderer functionalities

Member Function Documentation

void Window::Draw ( Image image,
const Rectf dstRect,
Recti clip = NULL,
float  angle = 0.0,
Vector2f  pivot = Vector2f(0, 0),
int  flip = SDL_FLIP_NONE 
)
static

Draw an Image to the screen and apply some rotation and flip if desired

Parameters
imageThe image to draw
dstRectThe destination rectangle to draw too
clipThe clip rect to apply to the texture
angleThe angle to rotate the image in degrees
pivotThe point to rotate around, note: default (0, 0) corresponds to destination rect center, offsets correspond to distance from image center
flipThe flip to apply to the image, default is none
void Window::Draw ( AnimatedImage img,
const Rectf dstRect,
float  angle = 0.0,
Vector2f  pivot = Vector2f(0, 0),
int  flip = SDL_FLIP_NONE 
)
static

Draw an Image to the screen with no extra effects

Parameters
imageThe image to draw
dstRectThe destination rectangle to draw too Drawn an Image to the screen with some clip applied the version passing with reference is for testing only
imageThe image to draw
dstRectThe destination rectangle to draw too
clipThe clip to apply to the image Draw an AnimatedImage object to the screen using the active animation clip
imgThe AnimatedImage to draw
dstRectThe destination rect to draw too Draw an AnimatedImage object to the screen using the active animation clip and apply some rotation and flip if desired
imgThe AnimatedImage to draw
dstRectThe destination rectangle to draw too
angleThe angle to rotate the image in degrees
pivotThe point to rotate around, note: default (0, 0) corresponds to destination rect center, offsets correspond to distance from image center
flipThe flip to apply to the image, default is none
void Window::Draw ( Text text,
const Rectf dstRect,
float  angle = 0.0,
Vector2f  pivot = Vector2f(0, 0),
int  flip = SDL_FLIP_NONE 
)
static

Draw a Text object to the screen at some position

Parameters
textThe text type to draw
dstRectThe destination rect to draw too, w and h vals will be queried from texture Draw a Text object to the screen at some position
textThe text type to draw
dstRectThe destination rect to draw too, w and h vals will be queried from texture
angleThe angle to rotate the image in degrees
pivotThe point to rotate around, default (0, 0) corresponds to destination rect center, offsets correspond to distance from image center
flipThe flip to apply to the image, default is none
void Window::DrawTexture ( SDL_Texture *  tex,
const Rectf dstRect,
Recti clip = NULL,
float  angle = 0.0,
Vector2f  pivot = Vector2f(0, 0),
SDL_RendererFlip  flip = SDL_FLIP_NONE 
)
static

Draw a texture to the screen with optional stretching applied

Parameters
texThe SDL_Texture* to draw
dstRectThe destination rect to draw to, specifies x,y,w,h of image
clipThe clip rect to apply to the texture, if desired
angleThe angle to rotate the image in degrees, default is 0
pivotThe point to rotate around, default (0, 0) corresponds to destination rect center, offsets correspond to distance from image center
flipThe flip to apply to the image, default is none
Note
Why are there copies of this function instead of default paramaters? LuaBind doesn't seem to recognize default paramaters, or I didn't figure it out and as such had to write a version of the function for each call
void Window::HandleEvents ( SDL_Event &  e)
static

Handle window events

Parameters
eThe SDL_Event to handle
void Window::Init ( std::string  title = "Window")
static

Initialize SDL, setup the window and renderer

Parameters
titleThe window title
SDL_Texture * Window::LoadTexture ( std::string  file)
static

Load an image file as a SDL_Texture and return it

Parameters
fileThe image file to load
Returns
SDL_Texture* of the texture loaded
Exceptions
runtime_errorif image failed to load
SDL_Texture * Window::RenderText ( std::string  message,
std::string  fontFile,
Color  color,
int  fontSize 
)
static

Generate a texture containing the message we want to display

Parameters
messageThe message we want to display
fontFileThe font we want to use to render the text
colorThe color we want the text to be
fontSizeThe size we want the font to be
Returns
An SDL_Texture containing the rendered message
void Window::ShowAvgFps ( bool  log)
static

Print the average framerate. To limit io action, will only print every 5 seconds

Parameters
logIf we want to print to the debug log or not, True for debug log
SDL_Texture * Window::SurfaceToTexture ( SDL_Surface *  surf)
static

Convert an SDL_Surface to a texture and return the texture and free the surface

Parameters
surfThe SDL_Surface* to be converted
Returns
The SDL_Texture* created from the surface

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