Support texture resizing.
This commit is contained in:
parent
e2bd48ec90
commit
739b75b0b6
8 changed files with 29 additions and 14 deletions
|
@ -5,16 +5,18 @@
|
||||||
namespace cloonel {
|
namespace cloonel {
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
Character::Character (const std::string& parPath, SDLMain* parMain) :
|
Character::Character (const std::string& parPath, SDLMain* parMain, ushort2 parSize) :
|
||||||
Placeable(0.0f, 0.0f),
|
Placeable(0.0f, 0.0f),
|
||||||
|
Drawable(parSize),
|
||||||
m_texture(new Texture(parPath, parMain, false))
|
m_texture(new Texture(parPath, parMain, false))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
Character::Character (const std::string&& parPath, SDLMain* parMain) :
|
Character::Character (const std::string&& parPath, SDLMain* parMain, ushort2 parSize) :
|
||||||
Placeable(0.0f, 0.0f),
|
Placeable(0.0f, 0.0f),
|
||||||
|
Drawable(parSize),
|
||||||
m_texture(new Texture(parPath, parMain, false))
|
m_texture(new Texture(parPath, parMain, false))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -27,6 +29,9 @@ namespace cloonel {
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
void Character::Prepare() {
|
void Character::Prepare() {
|
||||||
|
const SDLMain* const sdlmain = m_texture->SDLObject();
|
||||||
|
const int2 screensize(sdlmain->DefWidthHeight());
|
||||||
|
|
||||||
m_texture->Reload();
|
m_texture->Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +45,6 @@ namespace cloonel {
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
void Character::Draw() const {
|
void Character::Draw() const {
|
||||||
const int2 pos(m_pos + 0.5f);
|
const int2 pos(m_pos + 0.5f);
|
||||||
m_texture->Render(pos);
|
m_texture->Render(pos, m_wh);
|
||||||
}
|
}
|
||||||
} //namespace cloonel
|
} //namespace cloonel
|
||||||
|
|
|
@ -13,8 +13,8 @@ namespace cloonel {
|
||||||
|
|
||||||
class Character : public Placeable, public Drawable {
|
class Character : public Placeable, public Drawable {
|
||||||
public:
|
public:
|
||||||
Character ( const std::string& parPath, SDLMain* parMain );
|
Character ( const std::string& parPath, SDLMain* parMain, ushort2 parSize );
|
||||||
Character ( const std::string&& parPath, SDLMain* parMain );
|
Character ( const std::string&& parPath, SDLMain* parMai, ushort2 parSize );
|
||||||
virtual ~Character ( void ) noexcept;
|
virtual ~Character ( void ) noexcept;
|
||||||
|
|
||||||
void Prepare ( void );
|
void Prepare ( void );
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
#ifndef idC5A880D06A03407DB4E9FC21593A47FB
|
#ifndef idC5A880D06A03407DB4E9FC21593A47FB
|
||||||
#define idC5A880D06A03407DB4E9FC21593A47FB
|
#define idC5A880D06A03407DB4E9FC21593A47FB
|
||||||
|
|
||||||
|
#include "vector.hpp"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace cloonel {
|
namespace cloonel {
|
||||||
class Drawable {
|
class Drawable {
|
||||||
public:
|
public:
|
||||||
Drawable ( void ) = default;
|
Drawable ( void ) = default;
|
||||||
|
Drawable ( uint16_t parWidth, uint16_t parHeight ) : m_wh(parWidth, parHeight) {}
|
||||||
|
explicit Drawable ( ushort2 parWH ) : m_wh(parWH) {}
|
||||||
virtual ~Drawable ( void ) noexcept = default;
|
virtual ~Drawable ( void ) noexcept = default;
|
||||||
|
|
||||||
virtual void Draw ( void ) const = 0;
|
virtual void Draw ( void ) const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ushort2 m_wh;
|
||||||
};
|
};
|
||||||
} //namespace cloonel
|
} //namespace cloonel
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace cloonel {
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
void GameplaySceneClassic::Prepare() {
|
void GameplaySceneClassic::Prepare() {
|
||||||
std::unique_ptr<MoverSine> moverSine(new MoverSine());
|
std::unique_ptr<MoverSine> moverSine(new MoverSine());
|
||||||
std::unique_ptr<Character> player(new Character("resources/graphics/player.png", SDLObject()));
|
std::unique_ptr<Character> player(new Character("resources/graphics/player.png", SDLObject(), ushort2(80, 120)));
|
||||||
|
|
||||||
player->Prepare();
|
player->Prepare();
|
||||||
player->SwapMover(moverSine.get());
|
player->SwapMover(moverSine.get());
|
||||||
|
|
|
@ -13,8 +13,7 @@ namespace cloonel {
|
||||||
SDLMain::SDLMain (const char* parGameName, int parWidth, int parHeight) :
|
SDLMain::SDLMain (const char* parGameName, int parWidth, int parHeight) :
|
||||||
m_gameName(parGameName),
|
m_gameName(parGameName),
|
||||||
m_localData(new LocalData),
|
m_localData(new LocalData),
|
||||||
m_defWidth(parWidth),
|
m_defWH(parWidth, parHeight)
|
||||||
m_defHeight(parHeight)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +41,7 @@ namespace cloonel {
|
||||||
throw std::runtime_error(SDL_GetError());
|
throw std::runtime_error(SDL_GetError());
|
||||||
parInitSDL.initialized = true;
|
parInitSDL.initialized = true;
|
||||||
|
|
||||||
SDL_Window* const win = SDL_CreateWindow(m_gameName.c_str(), 100, 100, m_defWidth, m_defHeight, SDL_WINDOW_SHOWN);
|
SDL_Window* const win = SDL_CreateWindow(m_gameName.c_str(), 100, 100, m_defWH.x(), m_defWH.y(), SDL_WINDOW_SHOWN);
|
||||||
if (!win)
|
if (!win)
|
||||||
throw std::runtime_error(SDL_GetError());
|
throw std::runtime_error(SDL_GetError());
|
||||||
parInitSDL.window = win;
|
parInitSDL.window = win;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef id8E7A054DAC9040B887F2620EFD229EE8
|
#ifndef id8E7A054DAC9040B887F2620EFD229EE8
|
||||||
#define id8E7A054DAC9040B887F2620EFD229EE8
|
#define id8E7A054DAC9040B887F2620EFD229EE8
|
||||||
|
|
||||||
|
#include "vector.hpp"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
struct SDL_Renderer;
|
struct SDL_Renderer;
|
||||||
|
@ -13,6 +14,7 @@ namespace cloonel {
|
||||||
|
|
||||||
void Init ( void );
|
void Init ( void );
|
||||||
SDL_Renderer* GetRenderer ( void );
|
SDL_Renderer* GetRenderer ( void );
|
||||||
|
const int2& DefWidthHeight ( void ) const { return m_defWH; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct LocalData;
|
struct LocalData;
|
||||||
|
@ -22,8 +24,7 @@ namespace cloonel {
|
||||||
|
|
||||||
const std::string m_gameName;
|
const std::string m_gameName;
|
||||||
std::unique_ptr<LocalData> m_localData;
|
std::unique_ptr<LocalData> m_localData;
|
||||||
const int m_defWidth;
|
const int2 m_defWH;
|
||||||
const int m_defHeight;
|
|
||||||
};
|
};
|
||||||
} //namespace cloonel
|
} //namespace cloonel
|
||||||
|
|
||||||
|
|
|
@ -223,9 +223,9 @@ namespace cloonel {
|
||||||
|
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
void Texture::Render (int2 parPos) const {
|
void Texture::Render (int2 parPos, ushort2 parSize) const {
|
||||||
assert(IsLoaded());
|
assert(IsLoaded());
|
||||||
const SDL_Rect dest = { parPos.x(), parPos.y(), m_size.x(), m_size.y() };
|
const SDL_Rect dest = { parPos.x(), parPos.y(), parSize.x(), parSize.y() };
|
||||||
SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, &dest);
|
SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, &dest);
|
||||||
}
|
}
|
||||||
} //namespace cloonel
|
} //namespace cloonel
|
||||||
|
|
|
@ -17,7 +17,9 @@ namespace cloonel {
|
||||||
void Reload ( void );
|
void Reload ( void );
|
||||||
void Destroy ( void ) noexcept;
|
void Destroy ( void ) noexcept;
|
||||||
bool IsLoaded ( void ) const { return nullptr != m_texture; }
|
bool IsLoaded ( void ) const { return nullptr != m_texture; }
|
||||||
void Render ( int2 parPos ) const;
|
void Render ( int2 parPos ) const { Render(parPos, m_size); }
|
||||||
|
void Render ( int2 parPos, ushort2 parSize ) const;
|
||||||
|
const SDLMain* SDLObject ( void ) const { return m_sdlmain; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string m_path;
|
const std::string m_path;
|
||||||
|
|
Loading…
Reference in a new issue