Add project files.
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
#include "cAnimatedSprite.hpp"
|
||||
|
||||
using VideoEngine::cAnimatedSprite;
|
||||
|
||||
cAnimatedSprite::cAnimatedSprite( const unsigned long int x /*= 0*/, const unsigned long int y /*= 0*/,
|
||||
const unsigned long int fps /*= 16*/ )
|
||||
: m_nextTime(0), m_RATE(0)
|
||||
{
|
||||
setFPS(fps);
|
||||
setIncrement(x, y);
|
||||
}
|
||||
|
||||
cAnimatedSprite::cAnimatedSprite( const cAnimatedSprite& copy )
|
||||
: m_nextTime(0), m_RATE(0)
|
||||
{
|
||||
setFPS(copy.getFPS());
|
||||
setIncrement(copy.getXIncrement(), copy.getYIncrement());
|
||||
}
|
||||
|
||||
cAnimatedSprite::~cAnimatedSprite()
|
||||
{
|
||||
}
|
||||
|
||||
///Functions
|
||||
void cAnimatedSprite::UptoDown()
|
||||
{
|
||||
//if (TimeLeft() == 0)
|
||||
//{
|
||||
signed long int x = 0;
|
||||
signed long int y = 0;
|
||||
getStartImageArea(x, y);
|
||||
y += m_yIncrement;
|
||||
if (y >= signed(getImage()->getHeight()))
|
||||
y = 1;
|
||||
setStartImageArea(x, y);
|
||||
//}
|
||||
Draw();
|
||||
}
|
||||
|
||||
void cAnimatedSprite::DowntoUp()
|
||||
{
|
||||
//if (TimeLeft() == 0)
|
||||
//{
|
||||
signed long int x = 0;
|
||||
signed long int y = 0;
|
||||
|
||||
getStartImageArea(x, y);
|
||||
y -= m_yIncrement;
|
||||
if (y < 1)
|
||||
y = getImage()->getHeight() - m_yIncrement;
|
||||
setStartImageArea(x, y);
|
||||
//}
|
||||
Draw();
|
||||
}
|
||||
|
||||
void cAnimatedSprite::LefttoRight()
|
||||
{
|
||||
signed long int x = 0;
|
||||
signed long int y = 0;
|
||||
|
||||
getStartImageArea(x, y);
|
||||
if (x >= signed(getImage()->getWidth()))
|
||||
setStartImageArea(1,y);
|
||||
if (TimeLeft() == 0)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
getStartImageArea(x, y);
|
||||
x += m_xIncrement;
|
||||
if (x >= signed(getImage()->getWidth()))
|
||||
x = 1;
|
||||
setStartImageArea(x, y);
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
void cAnimatedSprite::RighttoLeft()
|
||||
{
|
||||
if (TimeLeft() == 0)
|
||||
{
|
||||
signed long int x = 0;
|
||||
signed long int y = 0;
|
||||
|
||||
getStartImageArea(x, y);
|
||||
x -= m_xIncrement;
|
||||
if (x <= 1)
|
||||
x = getImage()->getWidth() - m_xIncrement;
|
||||
setStartImageArea(x, y);
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
///Sets
|
||||
void cAnimatedSprite::setXIncrement( const unsigned long int x )
|
||||
{
|
||||
m_xIncrement = x;
|
||||
}
|
||||
|
||||
void cAnimatedSprite::setYIncrement( const unsigned long int y )
|
||||
{
|
||||
m_yIncrement = y;
|
||||
}
|
||||
|
||||
void cAnimatedSprite::setIncrement( const unsigned long int y, const unsigned long int x )
|
||||
{
|
||||
m_xIncrement = x;
|
||||
m_yIncrement = y;
|
||||
}
|
||||
|
||||
void cAnimatedSprite::setFPS( const unsigned long int fps /*= 16*/ )
|
||||
{
|
||||
m_fps = fps;
|
||||
m_RATE = (1000 / m_fps);
|
||||
m_nextTime = ((unsigned long int)SDL_GetTicks()) + m_RATE;
|
||||
}
|
||||
|
||||
///Gets
|
||||
const unsigned long int cAnimatedSprite::getXIncrement() const
|
||||
{
|
||||
return m_xIncrement;
|
||||
}
|
||||
|
||||
const unsigned long int cAnimatedSprite::getYIncrement() const
|
||||
{
|
||||
return m_yIncrement;
|
||||
}
|
||||
|
||||
void cAnimatedSprite::getIncrement( unsigned long int& x, unsigned long int& y ) const
|
||||
{
|
||||
x = m_xIncrement;
|
||||
y = m_yIncrement;
|
||||
}
|
||||
|
||||
const unsigned long int cAnimatedSprite::getFPS() const
|
||||
{
|
||||
return m_fps;
|
||||
}
|
||||
|
||||
const unsigned long int cAnimatedSprite::TimeLeft()
|
||||
{
|
||||
unsigned long int now = (unsigned long int)SDL_GetTicks();
|
||||
|
||||
if(m_nextTime <= now)
|
||||
{
|
||||
AddTimeandRate();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
void cAnimatedSprite::AddTimeandRate()
|
||||
{
|
||||
m_nextTime += m_RATE;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#ifndef _CANIMATEDSPRITE_HPP_
|
||||
#define _CANIMATEDSPRITE_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cSprite.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
namespace VideoEngine {
|
||||
class EXPORT_FROM_MYDLL cAnimatedSprite : public cSprite
|
||||
{
|
||||
public:
|
||||
cAnimatedSprite( const unsigned long int x = 0, const unsigned long int y = 0, const unsigned long int fps = 16 );
|
||||
/* Copy constructor */
|
||||
cAnimatedSprite( const cAnimatedSprite& copy );
|
||||
~cAnimatedSprite();
|
||||
|
||||
///Functions
|
||||
/* Runs down the image */
|
||||
void UptoDown();
|
||||
/* Runs up the image */
|
||||
void DowntoUp();
|
||||
/* Runs right of the image */
|
||||
void LefttoRight();
|
||||
/* Runs Left of the image */
|
||||
void RighttoLeft();
|
||||
|
||||
///Sets
|
||||
/* Sets the x increment */
|
||||
void setXIncrement( const unsigned long int x );
|
||||
/* Sets the y increment */
|
||||
void setYIncrement( const unsigned long int y );
|
||||
/* Sets the how fare the sprite should move along the image */
|
||||
void setIncrement( const unsigned long int x, const unsigned long int y );
|
||||
/* Sets the speed of going from one frame to the next */
|
||||
void setFPS( const unsigned long int fps = 16 );
|
||||
|
||||
///Gets
|
||||
/* Gets the x increment */
|
||||
const unsigned long int getXIncrement() const;
|
||||
/* Gets the y increment */
|
||||
const unsigned long int getYIncrement() const;
|
||||
/* Gets how fare the sprite should move along the image */
|
||||
void getIncrement( unsigned long int& x, unsigned long int& y ) const;
|
||||
|
||||
/* Gets the speed of going from one frame to the next */
|
||||
const unsigned long int getFPS() const;
|
||||
|
||||
private:
|
||||
const unsigned long int TimeLeft();
|
||||
void AddTimeandRate();
|
||||
|
||||
private:
|
||||
///Variables
|
||||
unsigned long int m_xIncrement;// = 0
|
||||
unsigned long int m_yIncrement;// = 0
|
||||
|
||||
unsigned long int m_fps;// = 16
|
||||
|
||||
unsigned long int m_nextTime;// = 0
|
||||
|
||||
unsigned long int m_RATE;// = 0
|
||||
|
||||
};/// END CLASS DEFINITION cAnimatedSprite
|
||||
}/// END NAMESPACE DEFINITION VideoEngine
|
||||
#endif/// END IFNDEF _CANIMATEDSPRITE_HPP_
|
||||
@@ -0,0 +1,118 @@
|
||||
#include "cCamera.hpp"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cRenderer.hpp"
|
||||
#include "../UtilityEngine/cUtility.hpp"
|
||||
|
||||
using VideoEngine::cCamera;
|
||||
using UtilityEngine::cUtility;
|
||||
|
||||
cCamera::cCamera( const signed long int xPos /*= 0*/, const signed long int yPos /*= 0*/,
|
||||
const unsigned long int reswidth /*= 640*/, const unsigned long int reshight /*= 480*/ )
|
||||
: mp_texture(nullptr)
|
||||
{
|
||||
m_position.x = Sint16(xPos);
|
||||
m_position.y = Sint16(yPos);
|
||||
|
||||
m_position.w = Uint16(reswidth);
|
||||
m_position.h = Uint16(reshight);
|
||||
|
||||
CreateCamera();
|
||||
}
|
||||
|
||||
cCamera::cCamera( const cCamera& copy )
|
||||
{
|
||||
m_position.x = Sint16(copy.getXPos());
|
||||
m_position.y = Sint16(copy.getYPos());
|
||||
|
||||
m_position.w = Uint16(copy.getWidthRes());
|
||||
m_position.h = Uint16(copy.getHeightRes());
|
||||
|
||||
setTexture(copy.getTexture());
|
||||
}
|
||||
|
||||
cCamera::~cCamera()
|
||||
{
|
||||
DeleteCamera();
|
||||
}
|
||||
|
||||
void cCamera::Draw()
|
||||
{
|
||||
cRenderer::Inst().Render(mp_texture, nullptr, &m_position);
|
||||
}
|
||||
|
||||
void cCamera::SaveImage( const cString& fileName, const cString& dir /*= ""*/ )
|
||||
{
|
||||
cRenderer::Inst().SaveTexture(mp_texture, fileName, dir);
|
||||
}
|
||||
|
||||
///Sets
|
||||
void cCamera::setXPosandYPos( const signed long int xPos /*= 0*/, const signed long int yPos /*= 0*/ )
|
||||
{
|
||||
m_position.x = Sint16(xPos);
|
||||
m_position.y = Sint16(yPos);
|
||||
|
||||
CreateCamera();
|
||||
}
|
||||
|
||||
void cCamera::setResWidthandResHeight( const unsigned long int reswidth /*= 640*/, const unsigned long int reshight /*= 480*/ )
|
||||
{
|
||||
m_position.w = Uint16(reswidth);
|
||||
m_position.h = Uint16(reshight);
|
||||
|
||||
CreateCamera();
|
||||
}
|
||||
|
||||
void cCamera::setTexture( SDL_Texture* texture )
|
||||
{
|
||||
DeleteCamera();
|
||||
CreateCamera();
|
||||
|
||||
cRenderer::Inst().CopyTexture(texture, mp_texture);
|
||||
}
|
||||
|
||||
///Gets
|
||||
const unsigned long int cCamera::getXPos() const
|
||||
{
|
||||
return m_position.x;
|
||||
}
|
||||
|
||||
const unsigned long int cCamera::getYPos() const
|
||||
{
|
||||
return m_position.y;
|
||||
}
|
||||
|
||||
const unsigned long int cCamera::getWidthRes() const
|
||||
{
|
||||
return m_position.w;
|
||||
}
|
||||
|
||||
const unsigned long int cCamera::getHeightRes() const
|
||||
{
|
||||
return m_position.h;
|
||||
}
|
||||
|
||||
SDL_Texture* cCamera::getCameraView() const
|
||||
{
|
||||
return mp_texture;
|
||||
}
|
||||
|
||||
SDL_Texture* cCamera::getTexture() const
|
||||
{
|
||||
return mp_texture;
|
||||
}
|
||||
|
||||
void cCamera::CreateCamera()
|
||||
{
|
||||
DeleteCamera();
|
||||
mp_texture = cRenderer::Inst().NewTexture(m_position.w, m_position.h, SDL_TEXTUREACCESS_TARGET);
|
||||
|
||||
if (mp_texture == nullptr)
|
||||
cUtility::Inst().Message("Unable to create camera.", __AT__);
|
||||
}
|
||||
|
||||
void cCamera::DeleteCamera()
|
||||
{
|
||||
if (mp_texture != nullptr)
|
||||
SDL_DestroyTexture(mp_texture);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef _CCAMERA_HPP_
|
||||
#define _CCAMERA_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace VideoEngine {
|
||||
class EXPORT_FROM_MYDLL cCamera
|
||||
{
|
||||
public:
|
||||
cCamera( const signed long int xPos = 0, const signed long int yPos = 0,
|
||||
const unsigned long int reswidth = 640, const unsigned long int reshight = 480 );
|
||||
/* Copy constructor */
|
||||
cCamera( const cCamera& copy );
|
||||
~cCamera();
|
||||
|
||||
/* Draws the camera on the video buffer */
|
||||
void Draw();
|
||||
|
||||
/* Saves the Camera Image to a BMP file */
|
||||
void SaveImage( const cString& fileName, const cString& dir = "" );
|
||||
|
||||
///Sets
|
||||
/* Sets the x and y position on the video buffer */
|
||||
void setXPosandYPos( const signed long int xPos = 0, const signed long int yPos = 0 );
|
||||
/* Sets the width and height the camera should be */
|
||||
void setResWidthandResHeight( const unsigned long int reswidth = 640, const unsigned long int reshight = 480 );
|
||||
/* Sets the Surface */
|
||||
void setTexture( SDL_Texture* texture );
|
||||
|
||||
///Gets
|
||||
/* Gets the x position of the camera */
|
||||
const unsigned long int getXPos() const;
|
||||
/* Gets the y position of the camera */
|
||||
const unsigned long int getYPos() const;
|
||||
|
||||
/* Gets the width of the camera */
|
||||
const unsigned long int getWidthRes() const;
|
||||
/* Gets the height of the camera */
|
||||
const unsigned long int getHeightRes() const;
|
||||
|
||||
/* Gets the SDL_Renderer of the camera */
|
||||
SDL_Texture* getCameraView() const;
|
||||
|
||||
/* Gets the Surface of the camera */
|
||||
SDL_Texture* getTexture() const;
|
||||
|
||||
private:
|
||||
///Functions
|
||||
void CreateCamera();
|
||||
void DeleteCamera();
|
||||
|
||||
private:
|
||||
///Variables
|
||||
SDL_Rect m_position;
|
||||
|
||||
SDL_Texture* mp_texture;// = nullptr
|
||||
|
||||
//std::vector<cSprite*> m_sprites;
|
||||
//LinkList::cLList m_sprites;
|
||||
};/// END CLASS DEFINITION cCamera
|
||||
}/// END NAMESPACE DEFINITION VideoEngine
|
||||
#endif/// END IFNDEF _CCAMERA_HPP_
|
||||
@@ -0,0 +1,257 @@
|
||||
#include "cImage.hpp"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cRenderer.hpp"
|
||||
#include "../UtilityEngine/cUtility.hpp"
|
||||
|
||||
using VideoEngine::cImage;
|
||||
using UtilityEngine::cUtility;
|
||||
|
||||
cImage::cImage( const cString& dir /*= ""*/, const cString& filename /*= ""*/, const bool transparent /*= false*/,
|
||||
const unsigned char red /*= 0*/, const unsigned char blue /*= 0*/, const unsigned char green /*= 255*/,
|
||||
const unsigned char translevel /*= 255*/)
|
||||
: mp_texture(nullptr), m_dir(dir), m_fileName(filename), m_transparent(transparent),
|
||||
m_transRed(red), m_transBlue(blue), m_transGreen(green), m_transLevel(translevel)
|
||||
{
|
||||
if (m_fileName != (char*)"")
|
||||
LoadImage();
|
||||
if (mp_texture != nullptr)
|
||||
TransparentSetup();
|
||||
}
|
||||
|
||||
cImage::cImage( SDL_Surface* surface )
|
||||
: mp_texture(nullptr), m_dir(""), m_fileName(""), m_transparent(false),
|
||||
m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255)
|
||||
{
|
||||
setImage(surface);
|
||||
}
|
||||
|
||||
cImage::cImage( SDL_Texture* texture )
|
||||
: mp_texture(nullptr), m_dir(""), m_fileName(""), m_transparent(false),
|
||||
m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255)
|
||||
{
|
||||
setImage(texture);
|
||||
}
|
||||
|
||||
cImage::cImage( const cImage& copy, const bool surfaceCopy /*= true*/)
|
||||
: mp_texture(nullptr), m_dir(copy.getDir()),
|
||||
m_fileName(copy.getFileName()), m_transparent(copy.getTransparent()), m_transRed(copy.getRedTrans()),
|
||||
m_transBlue(copy.getBlueTrans()), m_transGreen(copy.getGreenTrans()), m_transLevel(copy.getLevelTrans())
|
||||
{
|
||||
if (surfaceCopy == true)
|
||||
mp_texture = copy.getImage();
|
||||
}
|
||||
|
||||
cImage::~cImage()
|
||||
{
|
||||
UnloadImage();
|
||||
}
|
||||
|
||||
///Functions
|
||||
void cImage::SaveImage( const cString& fileName, const cString& dir /*= ""*/ )
|
||||
{
|
||||
cRenderer::Inst().SaveTexture( mp_texture, fileName, dir );
|
||||
}
|
||||
|
||||
const cImage* cImage::NewImage( SDL_Rect& area ) const
|
||||
{
|
||||
cImage* rtn = new cImage(*this, false);
|
||||
|
||||
SDL_Texture* tempTexture = cRenderer::Inst().NewTexture(area.w, area.h, SDL_TEXTUREACCESS_TARGET);
|
||||
|
||||
if (tempTexture != nullptr) {
|
||||
cRenderer::Inst().RenderToTexture(tempTexture, nullptr, mp_texture, &area);
|
||||
rtn->setImage(tempTexture);
|
||||
} else
|
||||
cUtility::Inst().Message("No texture created.", __AT__);
|
||||
|
||||
|
||||
/*SDL_Surface* tempsurface = SDL_CreateRGBSurface(cVideo::Instance().getVideoSettings(), area.w, area.h, cVideo::Instance().getColour(),
|
||||
mp_texture->format->Rmask, mp_texture->format->Gmask, mp_texture->format->Bmask, mp_texture->format->Amask);
|
||||
cVideo::Instance().Render(tempsurface, nullptr, mp_texture, &area);
|
||||
rtn->setImage(tempsurface);*/
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
///Sets
|
||||
void cImage::setDir( const cString& dir )
|
||||
{
|
||||
m_dir = dir;
|
||||
}
|
||||
|
||||
void cImage::setFileName( const cString& filename )
|
||||
{
|
||||
m_fileName = filename;
|
||||
LoadImage();
|
||||
}
|
||||
|
||||
void cImage::setFileNameandDir( const cString& filename, const cString& dir /*= ""*/ )
|
||||
{
|
||||
setDir(dir);
|
||||
setFileName(filename);
|
||||
}
|
||||
|
||||
void cImage::setTransparent( const bool transparent /*= true*/ )
|
||||
{
|
||||
m_transparent = transparent;
|
||||
TransparentSetup();
|
||||
}
|
||||
|
||||
void cImage::setColourTrans( const unsigned char red /*= 0*/, const unsigned char blue /*= 0*/, const unsigned char green /*= 255*/ )
|
||||
{
|
||||
m_transRed = red;
|
||||
m_transBlue = blue;
|
||||
m_transGreen = green;
|
||||
TransparentSetup();
|
||||
}
|
||||
|
||||
void cImage::setLevelTrans( const unsigned char translevel /*= 255*/ )
|
||||
{
|
||||
m_transLevel = translevel;
|
||||
}
|
||||
|
||||
///Gets
|
||||
SDL_Surface* cImage::getSurface() const
|
||||
{
|
||||
return cRenderer::Inst().TextureToSurface(mp_texture);
|
||||
}
|
||||
|
||||
SDL_Texture* cImage::getImage() const
|
||||
{
|
||||
return mp_texture;
|
||||
}
|
||||
|
||||
const unsigned long int cImage::getWidth() const
|
||||
{
|
||||
unsigned long int w = 0;
|
||||
unsigned long int h = 0;
|
||||
|
||||
getWH(w, h);
|
||||
return w;
|
||||
}
|
||||
|
||||
const unsigned long int cImage::getHeight() const
|
||||
{
|
||||
unsigned long int w = 0;
|
||||
unsigned long int h = 0;
|
||||
|
||||
getWH(w, h);
|
||||
return h;
|
||||
}
|
||||
|
||||
const SDL_Rect cImage::getWH() const
|
||||
{
|
||||
unsigned long int w = 0;
|
||||
unsigned long int h = 0;
|
||||
|
||||
getWH(w, h);
|
||||
SDL_Rect rtn = { 0, 0, (int)w, (int)h};
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cImage::getWH( unsigned long int& w, unsigned long int& h ) const
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
if (mp_texture != nullptr)
|
||||
if (SDL_QueryTexture(mp_texture, nullptr, nullptr, &width, &height) < 0)
|
||||
cUtility::Inst().Message("Unable to get Width or Height. SDL_QueryTexture:", __AT__, cUtility::eTypeSDL::SDL);
|
||||
w = width;
|
||||
h = height;
|
||||
}
|
||||
|
||||
const cString cImage::getDir() const
|
||||
{
|
||||
return m_dir;
|
||||
}
|
||||
|
||||
const cString cImage::getFileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
const bool cImage::getTransparent() const
|
||||
{
|
||||
return m_transparent;
|
||||
}
|
||||
|
||||
void cImage::getColourTrans( unsigned char& red, unsigned char& blue, unsigned char& green ) const
|
||||
{
|
||||
red = m_transRed;
|
||||
blue = m_transBlue;
|
||||
green = m_transGreen;
|
||||
}
|
||||
|
||||
const unsigned char cImage::getRedTrans() const
|
||||
{
|
||||
return m_transRed;
|
||||
}
|
||||
|
||||
const unsigned char cImage::getBlueTrans() const
|
||||
{
|
||||
return m_transBlue;
|
||||
}
|
||||
|
||||
const unsigned char cImage::getGreenTrans() const
|
||||
{
|
||||
return m_transGreen;
|
||||
}
|
||||
|
||||
const unsigned char cImage::getLevelTrans() const
|
||||
{
|
||||
return m_transLevel;
|
||||
}
|
||||
|
||||
//protected:
|
||||
void cImage::setImage( SDL_Surface* surface )
|
||||
{
|
||||
UnloadImage();
|
||||
|
||||
mp_texture = cRenderer::Inst().SurfaceToTexture(surface);
|
||||
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
void cImage::setImage( SDL_Texture* texture )
|
||||
{
|
||||
UnloadImage();
|
||||
mp_texture = texture;
|
||||
}
|
||||
|
||||
///private
|
||||
///Functions
|
||||
void cImage::TransparentSetup()
|
||||
{
|
||||
if( (m_transparent == true) && (mp_texture != nullptr) ) {
|
||||
if ((SDL_SetTextureColorMod(mp_texture, m_transRed, m_transGreen, m_transBlue) | SDL_SetTextureAlphaMod(mp_texture, m_transLevel)) < 0)
|
||||
cUtility::Inst().Message("Unable to set Transparent. SDL_SetTextureColorMod:", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
//LoadImage();
|
||||
}
|
||||
|
||||
void cImage::LoadImage()
|
||||
{
|
||||
UnloadImage();
|
||||
|
||||
SDL_Texture* tempText = nullptr;
|
||||
|
||||
if (m_fileName != "")
|
||||
{
|
||||
cString temp = m_dir + m_fileName;
|
||||
|
||||
if ((tempText = IMG_LoadTexture( cRenderer::Inst().getRenderer(), temp.c_str() )) == nullptr)
|
||||
cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_LoadTexture():", __AT__, cUtility::eTypeSDL::IMAGE);
|
||||
}
|
||||
}
|
||||
|
||||
void cImage::UnloadImage()
|
||||
{
|
||||
if (mp_texture != nullptr)
|
||||
{
|
||||
SDL_DestroyTexture(mp_texture);
|
||||
mp_texture = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
#ifndef _CIMAGE_HPP_
|
||||
#define _CIMAGE_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
#include <SDL_image.h>
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace VideoEngine {
|
||||
class EXPORT_FROM_MYDLL cImage
|
||||
{
|
||||
public:
|
||||
cImage( const cString& dir = "", const cString& filename = "", const bool transparent = false,
|
||||
const unsigned char red = 0, const unsigned char blue = 0, const unsigned char green = 255,
|
||||
const unsigned char translevel = 255);
|
||||
cImage( SDL_Surface* surface );
|
||||
cImage( SDL_Texture* texture );
|
||||
/* Copy constructor */
|
||||
cImage( const cImage& copy, const bool surfaceCopy = true );
|
||||
~cImage();
|
||||
|
||||
/* Saves the Image to a BMP file */
|
||||
void SaveImage( const cString& fileName, const cString& dir = "" );
|
||||
/* Creates a New Image based on input */
|
||||
const cImage* NewImage( SDL_Rect& area ) const;
|
||||
|
||||
///Sets
|
||||
/* Sets the Directory of the image */
|
||||
void setDir( const cString& dir );
|
||||
/* Sets the File Name of the image */
|
||||
void setFileName( const cString& filename );
|
||||
/* Sets the File Name and the Directory of the image */
|
||||
void setFileNameandDir( const cString& filename, const cString& dir = "" );
|
||||
|
||||
/* Sets Transparent on if set to true */
|
||||
void setTransparent( const bool transparent = true );
|
||||
/* Sets the colour to be made transparent */
|
||||
void setColourTrans( const unsigned char red = 0, const unsigned char blue = 0, const unsigned char green = 255 );
|
||||
/* Sets the level of the transparent 255 = clear, 0 = solid */
|
||||
void setLevelTrans( const unsigned char translevel = 255 );
|
||||
|
||||
///Gets
|
||||
/* Gets a pointer to the SDL_Surface */
|
||||
SDL_Surface* getSurface() const;
|
||||
/* Gets a pointer to the SDL_Texture */
|
||||
SDL_Texture* getImage() const;
|
||||
/* Gets the width of the image */
|
||||
const unsigned long int getWidth() const;
|
||||
/* Gets the Height of the image */
|
||||
const unsigned long int getHeight() const;
|
||||
/* Gets the Width and Height of the image */
|
||||
const SDL_Rect getWH() const;
|
||||
/* Gets the Width and Height of the image */
|
||||
void getWH( unsigned long int& w, unsigned long int& h ) const;
|
||||
|
||||
/* Gets the Directory of the image */
|
||||
const cString getDir() const;
|
||||
/* Gets the File Name of the image */
|
||||
const cString getFileName() const;
|
||||
|
||||
/* Gets return true if transparent on false if off */
|
||||
const bool getTransparent() const;
|
||||
/* Gets return the colour to be made transparent */
|
||||
void getColourTrans( unsigned char& red, unsigned char& blue, unsigned char& green ) const;
|
||||
/* Gets the transparent red colour */
|
||||
const unsigned char getRedTrans() const;
|
||||
/* Gets the transparent blue colour */
|
||||
const unsigned char getBlueTrans() const;
|
||||
/* Gets the transparent green colour */
|
||||
const unsigned char getGreenTrans() const;
|
||||
/* Gets the transparent level 255 = clear, 0 = solid */
|
||||
const unsigned char getLevelTrans() const;
|
||||
|
||||
protected:
|
||||
/* Protected so only derived class can access. *.
|
||||
/* Sets the image to surface */
|
||||
void setImage( SDL_Surface* surface );
|
||||
void setImage( SDL_Texture* texture );
|
||||
|
||||
private:
|
||||
///Functions
|
||||
void TransparentSetup();
|
||||
virtual void LoadImage(); //cFont over rides this
|
||||
void UnloadImage();
|
||||
|
||||
private:
|
||||
///Variables
|
||||
SDL_Texture* mp_texture;// = nullptr
|
||||
|
||||
cString m_dir;// = ""
|
||||
cString m_fileName;// = ""
|
||||
|
||||
//char m_dir[255];
|
||||
//char m_fileName[255];
|
||||
|
||||
bool m_transparent;// = false
|
||||
|
||||
unsigned char m_transRed;// = 0
|
||||
unsigned char m_transBlue;// = 0
|
||||
unsigned char m_transGreen;// = 255
|
||||
|
||||
unsigned char m_transLevel;// = 255
|
||||
};/// END CLASS DEFINITION cImage
|
||||
}/// END NAMESPACE DEFINITION VideoEngine
|
||||
#endif/// END IFNDEF _CIMAGE_HPP_
|
||||
@@ -0,0 +1,274 @@
|
||||
#include "cRenderer.hpp"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cVideo.hpp"
|
||||
#include "../UtilityEngine/cUtility.hpp"
|
||||
|
||||
using VideoEngine::cRenderer;
|
||||
using VideoEngine::cVideo;
|
||||
using UtilityEngine::cUtility;
|
||||
|
||||
/*static*/ cRenderer* cRenderer::sp_inst = nullptr;
|
||||
|
||||
//private:
|
||||
cRenderer::cRenderer()
|
||||
{
|
||||
Setup();
|
||||
}
|
||||
|
||||
cRenderer::~cRenderer()
|
||||
{
|
||||
CleanUp();
|
||||
}
|
||||
|
||||
//public:
|
||||
///Functions
|
||||
/*static*/ cRenderer& cRenderer::Inst()
|
||||
{
|
||||
if (sp_inst == nullptr)
|
||||
sp_inst = new cRenderer();
|
||||
return *sp_inst;
|
||||
}
|
||||
|
||||
/*static*/ void cRenderer::Delete()
|
||||
{
|
||||
delete sp_inst;
|
||||
sp_inst = nullptr;
|
||||
}
|
||||
|
||||
const bool cRenderer::Setup()
|
||||
{
|
||||
bool rtn = false;
|
||||
if (cVideo::Inst().IsInit() == false)
|
||||
cUtility::Inst().Message("Unable to setup until SDL_Video is initialized.");
|
||||
else {
|
||||
mp_renderer = cVideo::Inst().CreateRender();
|
||||
if (mp_renderer != nullptr)
|
||||
rtn = true;
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cRenderer::CleanUp()
|
||||
{
|
||||
SDL_DestroyRenderer(mp_renderer);
|
||||
mp_renderer = nullptr;
|
||||
}
|
||||
|
||||
void cRenderer::Render( SDL_Texture* texture, SDL_Rect* srcrect, SDL_Rect* dstrect )
|
||||
{
|
||||
cRenderer::Render(texture, srcrect, mp_renderer, dstrect);
|
||||
}
|
||||
|
||||
void cRenderer::Render( SDL_Surface* surface, SDL_Rect* srcrect, SDL_Rect* dstrect )
|
||||
{
|
||||
SDL_Texture* texture = SurfaceToTexture(surface);
|
||||
Render( texture, srcrect, dstrect );
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
|
||||
void cRenderer::Render( SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect )
|
||||
{
|
||||
if (SDL_BlitSurface(src, srcrect, dst, dstrect) < 0)
|
||||
cUtility::Inst().Message("Unable to BlitSurface. SDL_BlitSurface():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
|
||||
void cRenderer::Render( SDL_Texture* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect )
|
||||
{
|
||||
src;
|
||||
srcrect;
|
||||
dst;
|
||||
dstrect;
|
||||
//???????
|
||||
}
|
||||
|
||||
void cRenderer::Render( SDL_Texture* src, const SDL_Rect* srcrect, SDL_Renderer* dst, SDL_Rect* dstrect )
|
||||
{
|
||||
if (SDL_RenderCopy(dst, src, srcrect, dstrect) < 0)
|
||||
cUtility::Inst().Message("Unable to copy Texture to Renderer. SDL_RenderCopy():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
|
||||
void cRenderer::RenderToTexture( SDL_Texture* src, SDL_Rect* srcrect, SDL_Texture* dst, SDL_Rect* dstrect )
|
||||
{
|
||||
SetRenderTarget(dst);
|
||||
Render( src, srcrect, dstrect );
|
||||
ResetRenderTarget();
|
||||
}
|
||||
|
||||
void cRenderer::RenderDrawColor( const SDL_Colour& colour )
|
||||
{
|
||||
if (SDL_SetRenderDrawColor(mp_renderer, colour.r, colour.g, colour.b, colour.a) < 0)
|
||||
cUtility::Inst().Message("Unable to set render draw colour. SDL_SetRenderDrawColor():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
|
||||
void cRenderer::RenderDrawRect( const SDL_Rect& rect, SDL_Texture* dst /*= nullptr */ )
|
||||
{
|
||||
SetRenderTarget(dst);
|
||||
if (SDL_RenderFillRect(mp_renderer, &rect) < 0)
|
||||
cUtility::Inst().Message("Unable to draw rectangle. SDL_RenderFillRect():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
ResetRenderTarget();
|
||||
}
|
||||
|
||||
void cRenderer::ScreenShot( const cString& filename, const cString& dir /*= ""*/ )
|
||||
{
|
||||
SDL_Surface* infoSurface = SDL_GetWindowSurface(VideoEngine::cVideo::Inst().getWindow());
|
||||
SDL_Surface* saveSurface = NewSurface();
|
||||
|
||||
if (infoSurface == NULL) {
|
||||
cUtility::Inst().Message("Failed to create info surface from window.\n", __AT__, cUtility::eTypeSDL::SDL);
|
||||
} else {
|
||||
if (SDL_RenderReadPixels(mp_renderer, &infoSurface->clip_rect, infoSurface->format->format, saveSurface->pixels, infoSurface->w * infoSurface->format->BytesPerPixel) != 0)
|
||||
cUtility::Inst().Message("Failed to read pixel data from SDL_Renderer object.\n", __AT__, cUtility::eTypeSDL::SDL);
|
||||
else
|
||||
SaveSurface(saveSurface, filename, dir);
|
||||
SDL_FreeSurface(infoSurface);
|
||||
infoSurface = NULL;
|
||||
}
|
||||
SDL_FreeSurface(saveSurface);
|
||||
saveSurface = NULL;
|
||||
}
|
||||
|
||||
|
||||
void cRenderer::SaveSurface( SDL_Surface* surface, const cString& fileName, const cString& dir /*= ""*/ )
|
||||
{
|
||||
cString temp = dir + fileName;
|
||||
if (SDL_SaveBMP(surface, temp.c_str()) < 0)
|
||||
cUtility::Inst().Message("Unable to save Surface. SDL_SaveBMP()", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
|
||||
void cRenderer::SaveTexture( SDL_Texture* texture, const cString& fileName, const cString& dir /*= ""*/ )
|
||||
{
|
||||
SDL_Surface* surface = TextureToSurface(texture);
|
||||
|
||||
if (surface != nullptr)
|
||||
SaveSurface(surface, fileName, dir);
|
||||
else
|
||||
cUtility::Inst().Message("Unable to create Surface from Texture. TextureToSurface():", __AT__);
|
||||
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
SDL_Texture* cRenderer::SurfaceToTexture( SDL_Surface* surface )
|
||||
{
|
||||
SDL_Texture* rtn = nullptr;
|
||||
rtn = SDL_CreateTextureFromSurface( mp_renderer, surface );
|
||||
if ( rtn == nullptr)
|
||||
cUtility::Inst().Message("Unable to create Texture. SDL_CreateTextureFromSurface():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
SDL_Surface* cRenderer::TextureToSurface( SDL_Texture* texture )
|
||||
{
|
||||
SDL_Surface* rtn = nullptr;
|
||||
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
|
||||
if (SDL_QueryTexture(texture, nullptr, nullptr, &w, &h) < 0)
|
||||
cUtility::Inst().Message("Unable to Query Texture. SDL_QueryTexture():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
rtn = NewSurface(w, h);
|
||||
|
||||
void* srcPixels = nullptr;
|
||||
int srcPitch = 0;
|
||||
|
||||
//Lock texture for manipulation
|
||||
if (SDL_LockTexture( texture, nullptr, &srcPixels, &srcPitch ) < 0)
|
||||
cUtility::Inst().Message("Unable to lock texture. SDL_LockTexture():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
if (SDL_LockSurface(rtn))
|
||||
cUtility::Inst().Message("Unable to lock surface rtn. SDL_LockSurface():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
//Copy loaded/formatted surface pixels
|
||||
memcpy( rtn->pixels, srcPixels, srcPitch * h );
|
||||
|
||||
//Unlock texture to update
|
||||
SDL_UnlockSurface(rtn);
|
||||
SDL_UnlockTexture( texture );
|
||||
|
||||
srcPixels = nullptr;
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cRenderer::CopyTexture( SDL_Texture* src, SDL_Texture* dst )
|
||||
{
|
||||
void* srcPixels = nullptr;
|
||||
int srcPitch = 0;
|
||||
|
||||
void* dstPixels = nullptr;
|
||||
int dstPitch = 0;
|
||||
|
||||
int height = 0;
|
||||
|
||||
if (SDL_QueryTexture( src, nullptr, nullptr, nullptr, &height ) < 0)
|
||||
cUtility::Inst().Message("Unable to query texture. SDL_QueryTexture():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
//Lock texture for manipulation
|
||||
if (SDL_LockTexture( src, nullptr, &srcPixels, &srcPitch ) < 0)
|
||||
cUtility::Inst().Message("Unable to lock texture src. SDL_LockTexture():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
if (SDL_LockTexture( dst, nullptr, &dstPixels, &dstPitch ) < 0)
|
||||
cUtility::Inst().Message("Unable to lock texture dst. SDL_LockTexture():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
//Copy loaded/formatted surface pixels
|
||||
memcpy( dstPixels, srcPixels, srcPitch * height );
|
||||
|
||||
//Unlock texture to update
|
||||
SDL_UnlockTexture( dst );
|
||||
SDL_UnlockTexture( src );
|
||||
srcPixels = nullptr;
|
||||
dstPixels = nullptr;
|
||||
|
||||
}
|
||||
|
||||
SDL_Surface* cRenderer::CopySurface( SDL_Surface* src )
|
||||
{
|
||||
return SDL_ConvertSurface( src, src->format, src->flags );
|
||||
}
|
||||
|
||||
SDL_Surface* cRenderer::NewSurface( long int width /*= -1*/, long int height /*= -1*/ ) const
|
||||
{
|
||||
if (width < 0)
|
||||
width = cVideo::Inst().getWidth();
|
||||
if (height < 0)
|
||||
height = cVideo::Inst().getHeight();
|
||||
|
||||
SDL_Surface* rtn = SDL_CreateRGBSurface(cVideo::Inst().getVideoSettings(), width, height, cVideo::Inst().getColour(), cVideo::Inst().getRmask(), cVideo::Inst().getGmask(), cVideo::Inst().getBmask(), cVideo::Inst().getAmask());
|
||||
|
||||
if (rtn == nullptr)
|
||||
cUtility::Inst().Message("Unable to create surface. SDL_CreateRGBSurface():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
SDL_Texture* cRenderer::NewTexture( long int width, long int height, const unsigned long int access /*= SDL_TEXTUREACCESS_TARGET*/ ) const
|
||||
{
|
||||
if (width < 0)
|
||||
width = cVideo::Inst().getWidth();
|
||||
if (height < 0)
|
||||
height = cVideo::Inst().getHeight();
|
||||
|
||||
SDL_Texture* rtn = SDL_CreateTexture(mp_renderer, SDL_PIXELFORMAT_ABGR8888, access, width, height);
|
||||
if (rtn == nullptr)
|
||||
cUtility::Inst().Message("Unable to create texture. SDL_CreateTexture:", __AT__, cUtility::eTypeSDL::SDL);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cRenderer::SetRenderTarget( SDL_Texture* target /*= nullptr*/ )
|
||||
{
|
||||
if (SDL_SetRenderTarget(mp_renderer, target) < 0)
|
||||
cUtility::Inst().Message("Unable to set render target to dst. SDL_SetRenderTarget():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
|
||||
void cRenderer::ResetRenderTarget()
|
||||
{
|
||||
if (SDL_SetRenderTarget(mp_renderer, nullptr) < 0)
|
||||
cUtility::Inst().Message("Unable to set render target to mp_rend. SDL_SetRenderTarget():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
|
||||
SDL_Renderer* cRenderer::getRenderer()
|
||||
{
|
||||
return mp_renderer;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef _CRENDERER_HPP_
|
||||
#define _CRENDERER_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace VideoEngine {
|
||||
/* Singleton */
|
||||
class EXPORT_FROM_MYDLL cRenderer
|
||||
{
|
||||
private:
|
||||
cRenderer();
|
||||
~cRenderer();
|
||||
|
||||
public:
|
||||
static cRenderer& Inst();
|
||||
static void Delete();
|
||||
|
||||
/* Creates the Renderer */
|
||||
const bool Setup();
|
||||
/* Uses */
|
||||
void CleanUp();
|
||||
|
||||
void Render( SDL_Texture* texture, SDL_Rect* srcrect, SDL_Rect* dstrect );
|
||||
void Render( SDL_Surface* surface, SDL_Rect* srcrect, SDL_Rect* dstrect );
|
||||
void Render( SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect );
|
||||
void Render( SDL_Texture* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect );
|
||||
void Render( SDL_Texture* src, const SDL_Rect* srcrect, SDL_Renderer* dst, SDL_Rect* dstrect );
|
||||
|
||||
void RenderToTexture( SDL_Texture* src, SDL_Rect* srcrect, SDL_Texture* dst, SDL_Rect* dstrect );
|
||||
|
||||
void RenderDrawColor( const SDL_Colour& colour );
|
||||
void RenderDrawRect( const SDL_Rect& rect, SDL_Texture* dst = nullptr );
|
||||
|
||||
void ScreenShot(const cString& filename, const cString& dir = "");
|
||||
void SaveSurface( SDL_Surface* surface, const cString& fileName, const cString& dir = "" );
|
||||
void SaveTexture( SDL_Texture* texture, const cString& fileName, const cString& dir = "" );
|
||||
|
||||
SDL_Texture* SurfaceToTexture( SDL_Surface* surface );
|
||||
SDL_Surface* TextureToSurface( SDL_Texture* texture );
|
||||
|
||||
void CopyTexture( SDL_Texture* src, SDL_Texture* dst );
|
||||
|
||||
SDL_Surface* CopySurface( SDL_Surface* src );
|
||||
|
||||
SDL_Surface* NewSurface( long int width = -1, long int height = -1 ) const;
|
||||
SDL_Texture* NewTexture( long int width = -1, long int height = -1, const unsigned long int access = SDL_TEXTUREACCESS_TARGET ) const;
|
||||
|
||||
void SetRenderTarget( SDL_Texture* target = nullptr );
|
||||
void ResetRenderTarget();
|
||||
|
||||
///Sets
|
||||
|
||||
///Gets
|
||||
SDL_Renderer* getRenderer();
|
||||
|
||||
private:
|
||||
SDL_Renderer* mp_renderer;
|
||||
|
||||
static cRenderer* sp_inst;// = nullptr
|
||||
};/// END CLASS DEFINITION cRenderer
|
||||
}/// END NAMESPACE DEFINITION VideoEngine
|
||||
#endif/// END IFNDEF _CRENDERER_HPP_
|
||||
@@ -0,0 +1,277 @@
|
||||
#include "cSprite.hpp"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cRenderer.hpp"
|
||||
|
||||
using VideoEngine::cSprite;
|
||||
using MathEngine::iVector2;
|
||||
using MathEngine::iVector4;
|
||||
|
||||
cSprite::cSprite( const signed long int xpos /*= 0*/, const signed long int ypos /*= 0*/, const signed long int xarea /*= 0*/,
|
||||
const signed long int yarea /*= 0*/, const unsigned long int warea /*= 0*/, const unsigned long int harea /*= 0*/,
|
||||
VideoEngine::cImage** image /*= nullptr*/, VideoEngine::cCamera** camera /*= nullptr*/ )
|
||||
: mpp_image(image), mpp_camera(camera)
|
||||
{
|
||||
setPosition(Sint16(xpos), Sint16(ypos));
|
||||
|
||||
setStartImageArea(Sint16(xarea), Sint16(yarea));
|
||||
setEndImageArea(Uint16(warea), Uint16(harea));
|
||||
}
|
||||
|
||||
cSprite::cSprite( VideoEngine::cImage** image, VideoEngine::cCamera** camera /*= nullptr*/ )
|
||||
: mpp_image(image), mpp_camera(camera)
|
||||
{
|
||||
setPosition(0, 0);
|
||||
|
||||
setStartImageArea(0, 0);
|
||||
setEndImageArea(Uint16((*mpp_image)->getWidth()), Uint16((*mpp_image)->getHeight()));
|
||||
}
|
||||
|
||||
//cSprite::cSprite( TextTypeEngine::cText** image, VideoEngine::cCamera** camera /*= nullptr*/ )
|
||||
/*: mpp_camera(camera)
|
||||
{
|
||||
image;
|
||||
//VideoEngine::cImage* im = VideoEngine::cImage(*image);
|
||||
setPosition(0, 0);
|
||||
|
||||
setStartImageArea(0, 0);
|
||||
setEndImageArea(Uint16((*mpp_image)->getWidth()), Uint16((*mpp_image)->getHeight()));
|
||||
}*/
|
||||
|
||||
cSprite& cSprite::operator=( const cSprite& copy )
|
||||
{
|
||||
if (this != ©)
|
||||
{
|
||||
mpp_image = nullptr;
|
||||
mpp_camera = nullptr;
|
||||
|
||||
signed long int x = 0;
|
||||
signed long int y = 0;
|
||||
|
||||
unsigned long int h = 0;
|
||||
unsigned long int w = 0;
|
||||
|
||||
copy.getPosition(x, y);
|
||||
setPosition(x, y);
|
||||
|
||||
copy.getStartImageArea(x, y);
|
||||
copy.getEndImageArea(w, h);
|
||||
|
||||
setStartImageArea(x, y);
|
||||
setEndImageArea(w, h);
|
||||
|
||||
*mpp_image = copy.getImage();
|
||||
*mpp_camera = copy.getCamera();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
cSprite::~cSprite()
|
||||
{
|
||||
mpp_image = nullptr;
|
||||
mpp_camera = nullptr;
|
||||
}
|
||||
|
||||
///Functions
|
||||
void cSprite::Draw()
|
||||
{
|
||||
SDL_Texture* texture = (*mpp_image)->getImage();
|
||||
|
||||
if (mpp_camera != nullptr && *mpp_camera != nullptr) {
|
||||
CameraDraw();
|
||||
//surface = (*mpp_camera)->getCameraView();
|
||||
}
|
||||
|
||||
if (mpp_image != nullptr && *mpp_image != nullptr)
|
||||
cRenderer::Inst().Render( texture, &m_imageArea, &m_position);
|
||||
}
|
||||
|
||||
void cSprite::CameraDraw()
|
||||
{
|
||||
if ((mpp_image != nullptr) && (mpp_camera != nullptr) && (*mpp_image != nullptr) && (*mpp_camera != nullptr))
|
||||
cRenderer::Inst().RenderToTexture((*mpp_image)->getImage(), &m_imageArea, (*mpp_camera)->getCameraView(), &m_position);
|
||||
//RendererDraw( (*mpp_camera)->getCameraView() );
|
||||
}
|
||||
//
|
||||
// void cSprite::RendererDraw( SDL_Renderer* rend )
|
||||
// {
|
||||
// cVideo::Instance().RenderToTexture()
|
||||
// if ((rend != nullptr) && (mpp_image != nullptr) && (*mpp_image != nullptr))
|
||||
// Video::Instance().Render((*mpp_image)->getImage(), &m_imageArea, rend, &m_position);
|
||||
// }
|
||||
|
||||
void cSprite::DefaltDraw()
|
||||
{
|
||||
if (mpp_image != nullptr && *mpp_image != nullptr)
|
||||
cRenderer::Inst().Render( (*mpp_image)->getImage(), nullptr, nullptr);
|
||||
}
|
||||
|
||||
void cSprite::AddPosX( const signed long int x )
|
||||
{
|
||||
m_position.x += Sint16(x);
|
||||
}
|
||||
|
||||
void cSprite::AddPosY( const signed long int y )
|
||||
{
|
||||
m_position.y += Sint16(y);
|
||||
}
|
||||
|
||||
void cSprite::SaveImage( const cString& fileName, const cString& dir /*= ""*/ )
|
||||
{
|
||||
if (mpp_image != nullptr && *mpp_image != nullptr) {
|
||||
SDL_Texture* temp = (*mpp_image)->getImage();//(*mpp_image)->NewImage(this->getImageArea())->getImage();
|
||||
|
||||
cRenderer::Inst().SaveTexture( temp, fileName, dir );
|
||||
}
|
||||
}
|
||||
|
||||
///Sets
|
||||
void cSprite::setPosX( const signed long int x )
|
||||
{
|
||||
setPosition( x, getPosY());
|
||||
}
|
||||
|
||||
void cSprite::setPosY( const signed long int y )
|
||||
{
|
||||
setPosition( getPosX(), y );
|
||||
}
|
||||
|
||||
void cSprite::setPosition( const signed long int x, const signed long int y )
|
||||
{
|
||||
m_position.x = (signed short int)x;
|
||||
m_position.y = (signed short int)y;
|
||||
setPositionEnd();
|
||||
}
|
||||
|
||||
void cSprite::setPosition( const MathEngine::iVector2& position /*= MathEngine::iVector2(0,0)*/ )
|
||||
{
|
||||
setPosition(position.x, position.y);
|
||||
}
|
||||
|
||||
void cSprite::setImageArea( const MathEngine::iVector4& area /*= MathEngine::iVector4(0,0,0,0)*/)
|
||||
{
|
||||
if (area == iVector4(0,0,0,0)) {
|
||||
setStartImageArea(0,0);
|
||||
if ((mpp_image != nullptr) && (*mpp_image != nullptr))
|
||||
setEndImageArea((*mpp_image)->getWidth(), (*mpp_image)->getHeight());
|
||||
} else {
|
||||
setStartImageArea( area.x, area.y );
|
||||
setEndImageArea( area.z, area.w );
|
||||
}
|
||||
}
|
||||
|
||||
/// Top left starting area.
|
||||
void cSprite::setStartImageArea( const signed long int x, const signed long int y )
|
||||
{
|
||||
m_imageArea.x = (signed short int)x;
|
||||
m_imageArea.y = (signed short int)y;
|
||||
}
|
||||
|
||||
/// Bottom right image ends.
|
||||
void cSprite::setEndImageArea( const unsigned long int w, const unsigned long int h )
|
||||
{
|
||||
m_imageArea.w = (unsigned short int)w;
|
||||
m_imageArea.h = (unsigned short int)h;
|
||||
|
||||
setPositionEnd();
|
||||
}
|
||||
|
||||
void cSprite::setImage( VideoEngine::cImage** image )
|
||||
{
|
||||
mpp_image = image;
|
||||
}
|
||||
|
||||
void cSprite::setCamera( VideoEngine::cCamera** camera )
|
||||
{
|
||||
mpp_camera = camera;
|
||||
}
|
||||
|
||||
///Get's
|
||||
const signed long int cSprite::getPosX() const
|
||||
{
|
||||
return m_position.x;
|
||||
}
|
||||
|
||||
const signed long int cSprite::getPosY() const
|
||||
{
|
||||
return m_position.y;
|
||||
}
|
||||
|
||||
void cSprite::getPosition( signed long int& x, signed long int& y ) const
|
||||
{
|
||||
x = m_position.x;
|
||||
y = m_position.y;
|
||||
}
|
||||
|
||||
const MathEngine::iVector4 cSprite::getPosition() const
|
||||
{
|
||||
return iVector4(m_position);
|
||||
}
|
||||
|
||||
void cSprite::getStartImageArea( signed long int& x, signed long int& y ) const
|
||||
{
|
||||
x = m_imageArea.x;
|
||||
y = m_imageArea.y;
|
||||
}
|
||||
|
||||
void cSprite::getEndImageArea( unsigned long int& w, unsigned long int& h ) const
|
||||
{
|
||||
w = m_imageArea.w;
|
||||
h = m_imageArea.h;
|
||||
}
|
||||
|
||||
const SDL_Rect& cSprite::getImageArea() const
|
||||
{
|
||||
return m_imageArea;
|
||||
}
|
||||
|
||||
const unsigned long int cSprite::getWidth() const
|
||||
{
|
||||
return m_imageArea.w;
|
||||
}
|
||||
|
||||
const unsigned long int cSprite::getHeight() const
|
||||
{
|
||||
return m_imageArea.h;
|
||||
}
|
||||
|
||||
VideoEngine::cImage* cSprite::getImage() const
|
||||
{
|
||||
if (mpp_image == nullptr)
|
||||
return nullptr;
|
||||
else
|
||||
return (*mpp_image);
|
||||
}
|
||||
|
||||
VideoEngine::cCamera* cSprite::getCamera() const
|
||||
{
|
||||
if (mpp_camera == nullptr)
|
||||
return nullptr;
|
||||
else
|
||||
return (*mpp_camera);
|
||||
}
|
||||
|
||||
const bool cSprite::getImageSetup() const
|
||||
{
|
||||
bool rtn = false;
|
||||
if ((mpp_image != nullptr) && (*mpp_image != nullptr))
|
||||
rtn = true;
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const bool cSprite::getCameraSetup() const
|
||||
{
|
||||
bool rtn = false;
|
||||
if ((mpp_camera != nullptr) && (*mpp_camera != nullptr))
|
||||
rtn = true;
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cSprite::setPositionEnd()
|
||||
{
|
||||
m_position.w = m_imageArea.w;
|
||||
m_position.h = m_imageArea.h;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
#ifndef _CSPRITE_HPP_
|
||||
#define _CSPRITE_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cImage.hpp"
|
||||
#include "cCamera.hpp"
|
||||
|
||||
#include "../TextTypeEngine/cText.hpp"
|
||||
#include "../MathEngine/iVector/iVector2.hpp"
|
||||
#include "../MathEngine/iVector/iVector4.hpp"
|
||||
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace VideoEngine {
|
||||
class EXPORT_FROM_MYDLL cSprite
|
||||
{
|
||||
public:
|
||||
cSprite( VideoEngine::cImage** image, VideoEngine::cCamera** camera = nullptr );
|
||||
cSprite( const signed long int xpos = 0, const signed long int ypos = 0, const signed long int xarea = 0,
|
||||
const signed long int yarea = 0, const unsigned long int warea = 0, const unsigned long int harea = 0,
|
||||
VideoEngine::cImage** image = nullptr, VideoEngine::cCamera** camera = nullptr );
|
||||
|
||||
cSprite& operator=( const cSprite& copy );
|
||||
~cSprite();
|
||||
|
||||
///Functions
|
||||
/* Draws the sprite to the video buffer */
|
||||
void Draw();
|
||||
/* Draws the sprite to the camera */
|
||||
void CameraDraw();
|
||||
/* Draws the sprite to a SDL_Renderer */
|
||||
/*void RendererDraw( SDL_Renderer* rend );*/
|
||||
/* Draws the sprite to the video buffer with out positioning it */
|
||||
void DefaltDraw();
|
||||
|
||||
void AddPosX( const signed long int x );
|
||||
void AddPosY( const signed long int y );
|
||||
|
||||
void SaveImage( const cString& fileName, const cString& dir = "" );
|
||||
|
||||
///Sets
|
||||
/* Sets the X position of the sprite on the surface, camera or video buffer */
|
||||
void setPosX( const signed long int x );
|
||||
/* Sets the Y position of the sprite on the surface, camera or video buffer */
|
||||
void setPosY( const signed long int y );
|
||||
/* Sets the position of the sprite on the surface, camera or video buffer */
|
||||
void setPosition( const signed long int x, const signed long int y );
|
||||
/* Sets the position of the sprite on the surface, camera or video buffer */
|
||||
void setPosition( const MathEngine::iVector2& position = MathEngine::iVector2(0,0) );
|
||||
|
||||
/* Sets the start and end of the image area */
|
||||
void setImageArea( const MathEngine::iVector4& area = MathEngine::iVector4(0,0,0,0) );
|
||||
/* Sets the top left of the area to take from the image */
|
||||
void setStartImageArea( const signed long int x, const signed long int y ); /// Top left starting area.
|
||||
/* Sets the bottom right of the area to take from the image */
|
||||
void setEndImageArea( const unsigned long int w, const unsigned long int h ); /// Bottom right image ends.
|
||||
|
||||
/* Sets the pointer to a pointer for the image that the sprite will use */
|
||||
void setImage( VideoEngine::cImage** image );
|
||||
/* Sets the pointer to a pointer for the camera the sprite will be draw on */
|
||||
void setCamera( VideoEngine::cCamera** camera );
|
||||
|
||||
///Gets
|
||||
/* Gets the X position of the sprite on the surface, camera or video buffer */
|
||||
const signed long int getPosX() const;
|
||||
/* Gets the Y position of the sprite on the surface, camera of video buffer */
|
||||
const signed long int getPosY() const;
|
||||
/* Gets the position of the sprite on the surface, camera or video buffer */
|
||||
void getPosition( signed long int& x, signed long int& y ) const;
|
||||
/* Gets the position of the sprite on the surface, camera or video buffer */
|
||||
const MathEngine::iVector4 getPosition() const;
|
||||
|
||||
/* Gets the top left of the area to take from the image */
|
||||
void getStartImageArea( signed long int& x, signed long int& y ) const;
|
||||
/* Gets the bottom right of the area to take from the image */
|
||||
void getEndImageArea( unsigned long int& w, unsigned long int& h ) const;
|
||||
/* Gets the area of the image */
|
||||
const SDL_Rect& getImageArea() const;
|
||||
|
||||
/* Gets the width of the sprite */
|
||||
const unsigned long int getWidth() const;
|
||||
/* Gets the height of the sprite */
|
||||
const unsigned long int getHeight() const;
|
||||
|
||||
/* Gets a pointer to the image used by the sprite */
|
||||
VideoEngine::cImage* getImage() const;
|
||||
/* Gets a pointer to the camera used by the sprite */
|
||||
VideoEngine::cCamera* getCamera() const;
|
||||
|
||||
/* Gets returns true if image pointer is not null other wise returns false */
|
||||
const bool getImageSetup() const;
|
||||
/* Gets returns true if camera pointer is not null other wise returns false */
|
||||
const bool getCameraSetup() const;
|
||||
|
||||
private:
|
||||
void setPositionEnd();
|
||||
|
||||
private:
|
||||
///Variables
|
||||
SDL_Rect m_position; /// Were the Sprite will be position on the screen (Upper Left)
|
||||
|
||||
SDL_Rect m_imageArea; /// What part of the image to take
|
||||
|
||||
VideoEngine::cImage** mpp_image;// = nullptr
|
||||
VideoEngine::cCamera** mpp_camera;// = nullptr
|
||||
};/// END CLASS DEFINITION cSprite
|
||||
}/// END NAMESPACE DEFINITION VideoEngine
|
||||
#endif/// END IFNDEF _CSPRITE_HPP_
|
||||
@@ -0,0 +1,269 @@
|
||||
#include "cVideo.hpp"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "cRenderer.hpp"
|
||||
#include "../UtilityEngine/cUtility.hpp"
|
||||
|
||||
using VideoEngine::cVideo;
|
||||
using VideoEngine::cRenderer;
|
||||
using UtilityEngine::cUtility;
|
||||
|
||||
/*static*/ cVideo* cVideo::sp_inst = nullptr;
|
||||
|
||||
cVideo::cVideo()
|
||||
: m_xPos(100), m_yPos(100), m_width(640), m_height(480), m_colour(32),
|
||||
m_hardwareVideo(false), m_fullscreen(false), m_vsync(false),
|
||||
m_videoSettings(SDL_RENDERER_SOFTWARE), mp_window(nullptr),
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
m_rmask(0xff000000),
|
||||
m_gmask(0x00ff0000),
|
||||
m_bmask(0x0000ff00),
|
||||
m_amask(0x000000ff)
|
||||
#else
|
||||
m_rmask(0x000000ff),
|
||||
m_gmask(0x0000ff00),
|
||||
m_bmask(0x00ff0000),
|
||||
m_amask(0xff000000)
|
||||
#endif
|
||||
{}
|
||||
|
||||
cVideo::~cVideo()
|
||||
{
|
||||
CleanUp();
|
||||
}
|
||||
|
||||
///Functions
|
||||
/*static*/ cVideo& cVideo::Inst()
|
||||
{
|
||||
if (sp_inst == nullptr)
|
||||
sp_inst = new cVideo();
|
||||
return *sp_inst;
|
||||
}
|
||||
|
||||
/*static*/ void cVideo::Delete()
|
||||
{
|
||||
delete sp_inst;
|
||||
sp_inst = nullptr;
|
||||
}
|
||||
|
||||
const bool cVideo::Initialize() const
|
||||
{
|
||||
bool rtn = IsInit();
|
||||
|
||||
if (rtn == false) {
|
||||
if(SDL_InitSubSystem(SDL_INIT_VIDEO) == 0) {
|
||||
cUtility::Inst().Message("Video Initialized.");
|
||||
rtn = true;
|
||||
} else
|
||||
cUtility::Inst().Message("Could not initialize Video. SDL_InitSubSystem():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const bool cVideo::Setup()
|
||||
{
|
||||
bool rtn = false;
|
||||
CleanUp();
|
||||
VideoSettings();
|
||||
|
||||
mp_window = SDL_CreateWindow("Hello World!", 100, 100, m_width, m_height, SDL_WINDOW_SHOWN);
|
||||
if (mp_window == nullptr)
|
||||
cUtility::Inst().Message("Unable to set Window. SDL_CreateWindow():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
else
|
||||
rtn = true;
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void cVideo::CleanUp()
|
||||
{
|
||||
SDL_DestroyWindow(mp_window);
|
||||
mp_window = nullptr;
|
||||
}
|
||||
|
||||
void cVideo::Display()
|
||||
{
|
||||
SDL_RenderPresent(cRenderer::Inst().getRenderer());
|
||||
}
|
||||
|
||||
void cVideo::ScreenShot( const cString& filename, const cString& dir /*= ""*/ )
|
||||
{
|
||||
VideoEngine::cRenderer::Inst().ScreenShot(filename, dir);
|
||||
}
|
||||
|
||||
SDL_Renderer* cVideo::CreateRender()
|
||||
{
|
||||
SDL_Renderer* rtn = nullptr;
|
||||
if (mp_window != nullptr)
|
||||
rtn = SDL_CreateRenderer(mp_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
|
||||
|
||||
if (rtn == nullptr)
|
||||
cUtility::Inst().Message("Unable to set Renderer. SDL_CreateRenderer():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
|
||||
void cVideo::VideoSettings()
|
||||
{
|
||||
m_videoSettings = 0;
|
||||
|
||||
if (m_hardwareVideo == true)
|
||||
{
|
||||
m_videoSettings = (m_videoSettings | SDL_RENDERER_ACCELERATED);
|
||||
if (m_vsync == true)
|
||||
m_videoSettings = (m_videoSettings | SDL_RENDERER_PRESENTVSYNC);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_videoSettings = (m_videoSettings | SDL_RENDERER_SOFTWARE);
|
||||
m_vsync = false;
|
||||
}
|
||||
|
||||
if (m_fullscreen == true)
|
||||
m_videoSettings = (m_videoSettings | SDL_WINDOW_FULLSCREEN);
|
||||
}
|
||||
|
||||
///Set's
|
||||
void cVideo::setWidth( const unsigned long int width /*= 640*/ )
|
||||
{
|
||||
m_width = width;
|
||||
}
|
||||
|
||||
void cVideo::setHeight( const unsigned long int height /*= 480*/ )
|
||||
{
|
||||
m_height = height;
|
||||
}
|
||||
|
||||
void cVideo::setColour( const unsigned long int colour /*= 32*/ )
|
||||
{
|
||||
m_colour = colour;
|
||||
}
|
||||
|
||||
void cVideo::setCaption( const cString& caption /*= ""*/ )
|
||||
{
|
||||
if (mp_window != nullptr)
|
||||
SDL_SetWindowTitle(mp_window, caption.c_str());
|
||||
else
|
||||
cUtility::Inst().Message("No window to set caption to.");
|
||||
}
|
||||
|
||||
void cVideo::setHardwareVideo( const bool hardware /*= false*/ )
|
||||
{
|
||||
m_hardwareVideo = hardware;
|
||||
VideoSettings();
|
||||
}
|
||||
|
||||
void cVideo::setFullScreen( const bool fullscreen /*= false*/ )
|
||||
{
|
||||
m_fullscreen = fullscreen;
|
||||
VideoSettings();
|
||||
}
|
||||
|
||||
void cVideo::setVSync( const bool vsync /*= false*/ )
|
||||
{
|
||||
m_vsync = vsync;
|
||||
VideoSettings();
|
||||
}
|
||||
|
||||
void cVideo::setDisplayMode( const SDL_DisplayMode& mode )
|
||||
{
|
||||
if (SDL_SetWindowDisplayMode(mp_window, &mode) < 0)
|
||||
cUtility::Inst().Message("Unable to set display mode. SDL_SetWindowDisplayMode()", __AT__, cUtility::eTypeSDL::SDL);
|
||||
}
|
||||
|
||||
///Gets
|
||||
const bool cVideo::IsInit() const
|
||||
{
|
||||
bool rtn = false;
|
||||
|
||||
if (SDL_WasInit(SDL_INIT_VIDEO) != 0) {
|
||||
cUtility::Inst().Message("Video is initialized.");
|
||||
rtn = true;
|
||||
} else
|
||||
cUtility::Inst().Message("Video is not initialized.");
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const unsigned long int cVideo::getWidth() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
const unsigned long int cVideo::getHeight() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
const unsigned long int cVideo::getColour() const
|
||||
{
|
||||
return m_colour;
|
||||
}
|
||||
|
||||
const cString cVideo::getCaption() const
|
||||
{
|
||||
cString rtn = "";
|
||||
|
||||
if (mp_window != nullptr)
|
||||
rtn = SDL_GetWindowTitle(mp_window);
|
||||
else
|
||||
cUtility::Inst().Message("No window to get caption from.");
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
const bool cVideo::getHardwareVideo() const
|
||||
{
|
||||
return m_hardwareVideo;
|
||||
}
|
||||
|
||||
const bool cVideo::getFullScreen() const
|
||||
{
|
||||
return m_fullscreen;
|
||||
}
|
||||
|
||||
const bool cVideo::getVSync() const
|
||||
{
|
||||
return m_vsync;
|
||||
}
|
||||
|
||||
const unsigned long int cVideo::getVideoSettings() const
|
||||
{
|
||||
return m_videoSettings;
|
||||
}
|
||||
|
||||
SDL_Window* cVideo::getWindow()
|
||||
{
|
||||
return mp_window;
|
||||
}
|
||||
|
||||
SDL_DisplayMode cVideo::getDisplayMode() const
|
||||
{
|
||||
SDL_DisplayMode display;
|
||||
|
||||
if (SDL_GetWindowDisplayMode(mp_window, &display) < 0 )
|
||||
cUtility::Inst().Message("Could not get display mode. SDL_GetWindowDisplayMode():", __AT__, cUtility::eTypeSDL::SDL);
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
const unsigned long int cVideo::getRmask() const
|
||||
{
|
||||
return m_rmask;
|
||||
}
|
||||
|
||||
const unsigned long int cVideo::getGmask() const
|
||||
{
|
||||
return m_gmask;
|
||||
}
|
||||
|
||||
const unsigned long int cVideo::getBmask() const
|
||||
{
|
||||
return m_bmask;
|
||||
}
|
||||
|
||||
const unsigned long int cVideo::getAmask() const
|
||||
{
|
||||
return m_amask;
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
#ifndef _CVIDEO_HPP_
|
||||
#define _CVIDEO_HPP_
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL.h>
|
||||
|
||||
/*** DLL Header File ***/
|
||||
#include "dllExport.h"
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../UtilityEngine/cString.hpp"
|
||||
#include "../MathEngine/iVector/iVector2.hpp"
|
||||
|
||||
using UtilityEngine::cString;
|
||||
|
||||
namespace VideoEngine {
|
||||
/* Singleton */
|
||||
class EXPORT_FROM_MYDLL cVideo
|
||||
{
|
||||
private:
|
||||
cVideo();
|
||||
~cVideo();
|
||||
|
||||
public:
|
||||
///Functions
|
||||
static cVideo& Inst();
|
||||
static void Delete();
|
||||
|
||||
const bool Initialize() const;
|
||||
|
||||
/* Creates the cVideo's mp_buff and mp_screen surfaces */
|
||||
const bool Setup();
|
||||
/* Uses SDL_Freesurface to delete cVideo's mp_buff and mp_screen surfaces */
|
||||
void CleanUp();
|
||||
|
||||
/* Used to Display the new frame */
|
||||
void Display();
|
||||
|
||||
/* ScreenShot */
|
||||
void ScreenShot( const cString& filename, const cString& dir = "" );
|
||||
|
||||
SDL_Renderer* CreateRender();
|
||||
|
||||
///Sets
|
||||
/* Sets the videos width resolution */
|
||||
void setWidth( const unsigned long int width = 640 );
|
||||
/* Sets the videos height resolution */
|
||||
void setHeight( const unsigned long int height = 480 );
|
||||
/* Sets the videos colour depth in bits */
|
||||
void setColour( const unsigned long int colour = 32 );
|
||||
/* Sets the caption on the displayed window */
|
||||
void setCaption( const cString& caption = "" );
|
||||
|
||||
/* Sets video to use hardware surfaces if true other wise software surfaces are used */
|
||||
void setHardwareVideo( const bool hardware = false );
|
||||
/* Sets the video to full screen if true other wise a window is used */
|
||||
void setFullScreen( const bool fullscreen = false );
|
||||
/* Sets the video to use double buffering other wise no buffering is used */
|
||||
void setVSync( const bool vsync = false );
|
||||
|
||||
void setDisplayMode( const SDL_DisplayMode& mode );
|
||||
|
||||
///Gets
|
||||
/* Gets return true if video was initialized */
|
||||
const bool IsInit() const;
|
||||
/* Gets the videos width resolution */
|
||||
const unsigned long int getWidth() const;
|
||||
/* Gets the videos height resolution */
|
||||
const unsigned long int getHeight() const;
|
||||
/* Gets the videos colour depth in bits */
|
||||
const unsigned long int getColour() const;
|
||||
/* Gets the caption displayed on the window */
|
||||
const cString getCaption() const;
|
||||
|
||||
/* Gets returns true if hardware surfaces are being used other wise false is return */
|
||||
const bool getHardwareVideo() const;
|
||||
/* Gets returns true if full screen is being used other wise false is return */
|
||||
const bool getFullScreen() const;
|
||||
/* Gets returns true if Double Buffering is being used other wise false is return */
|
||||
const bool getVSync() const;
|
||||
|
||||
/* Gets returns the SDL video flags */
|
||||
const unsigned long int getVideoSettings() const;
|
||||
|
||||
/* Gets returns the SDL_Window pointer */
|
||||
SDL_Window* getWindow();
|
||||
|
||||
/* Gets returns the Display Mode */
|
||||
SDL_DisplayMode getDisplayMode() const;
|
||||
|
||||
/* Gets returns the Red mask value */
|
||||
const unsigned long int getRmask() const;
|
||||
/* Gets returns the Green mask value */
|
||||
const unsigned long int getGmask() const;
|
||||
/* Gets returns the Blue mask value */
|
||||
const unsigned long int getBmask() const;
|
||||
/* Gets returns the Alpha mask value */
|
||||
const unsigned long int getAmask() const;
|
||||
|
||||
private:
|
||||
///Functions
|
||||
void VideoSettings();
|
||||
|
||||
private:
|
||||
///Variables
|
||||
SDL_Window* mp_window;// = nullptr
|
||||
//SDL_Renderer* mp_rend;// = nullptr
|
||||
|
||||
unsigned long int m_xPos;// = 100
|
||||
unsigned long int m_yPos;// = 100
|
||||
unsigned long int m_width;// = 640
|
||||
unsigned long int m_height;// = 480
|
||||
unsigned long int m_colour;// = 32
|
||||
|
||||
bool m_hardwareVideo;// = false
|
||||
bool m_fullscreen;// = false
|
||||
bool m_vsync;// = false
|
||||
|
||||
unsigned long int m_videoSettings;// = SDL_RENDERER_SOFTWARE
|
||||
|
||||
static cVideo* sp_inst;// = nullptr
|
||||
|
||||
/*SDL interprets each pixel as a 32-bit number, so our masks must depend
|
||||
on the endianness (byte order) of the machine */
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
const unsigned long int m_rmask;// = 0xff000000;
|
||||
const unsigned long int m_gmask;// = 0x00ff0000;
|
||||
const unsigned long int m_bmask;// = 0x0000ff00;
|
||||
const unsigned long int m_amask;// = 0x000000ff;
|
||||
#else
|
||||
const unsigned long int m_rmask;// = 0x000000ff;
|
||||
const unsigned long int m_gmask;// = 0x0000ff00;
|
||||
const unsigned long int m_bmask;// = 0x00ff0000;
|
||||
const unsigned long int m_amask;// = 0xff000000;
|
||||
#endif
|
||||
};/// END CLASS DEFINITION cVideo
|
||||
}/// END NAMESPACE DEFINITION VideoEngine
|
||||
#endif/// END IFNDEF _CVIDEO_HPP_
|
||||
Reference in New Issue
Block a user