Support drawing textures without doing any clipping.
This commit is contained in:
parent
0674f2d28d
commit
79fbf0faf7
4 changed files with 29 additions and 10 deletions
|
@ -68,6 +68,6 @@ namespace cloonel {
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
void Character::Draw() const {
|
void Character::Draw() const {
|
||||||
m_texture->Render(GetPos(), WidthHeight(), m_screenRatio.Ratio());
|
m_texture->Render(GetPos(), WidthHeight(), m_screenRatio.Ratio(), true);
|
||||||
}
|
}
|
||||||
} //namespace cloonel
|
} //namespace cloonel
|
||||||
|
|
|
@ -107,6 +107,9 @@ namespace cloonel {
|
||||||
|
|
||||||
GraphicFormat GuessGraphicFormatFromName (const std::string& parPath) __attribute__((pure));
|
GraphicFormat GuessGraphicFormatFromName (const std::string& parPath) __attribute__((pure));
|
||||||
bool ClipRect ( RectFloat& parSrc, RectFloat& parDest, const RectFloat& parClip );
|
bool ClipRect ( RectFloat& parSrc, RectFloat& parDest, const RectFloat& parClip );
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
bool IsRectCompletelyInsideRect ( const RectFloat& parInner, const RectFloat& parOuter ) __attribute__((pure));
|
||||||
|
#endif
|
||||||
|
|
||||||
///----------------------------------------------------------------------
|
///----------------------------------------------------------------------
|
||||||
///----------------------------------------------------------------------
|
///----------------------------------------------------------------------
|
||||||
|
@ -288,6 +291,14 @@ namespace cloonel {
|
||||||
assert(parDest.IsValid());
|
assert(parDest.IsValid());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
///----------------------------------------------------------------------
|
||||||
|
///----------------------------------------------------------------------
|
||||||
|
bool IsRectCompletelyInsideRect (const RectFloat& parInner, const RectFloat& parOuter) {
|
||||||
|
return parInner.from >= parOuter.from and parInner.to <= parOuter.to;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
|
@ -347,7 +358,7 @@ namespace cloonel {
|
||||||
|
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
void Texture::Render (const float2& parPos, const float2& parSize, const float2& parScaling) const {
|
void Texture::Render (const float2& parPos, const float2& parSize, const float2& parScaling, bool parClip) const {
|
||||||
assert(IsLoaded());
|
assert(IsLoaded());
|
||||||
|
|
||||||
const float2 pos(parPos * parScaling);
|
const float2 pos(parPos * parScaling);
|
||||||
|
@ -355,13 +366,20 @@ namespace cloonel {
|
||||||
RectFloat dest(pos, pos + siz);
|
RectFloat dest(pos, pos + siz);
|
||||||
RectFloat src(float2(0.0f), m_size);
|
RectFloat src(float2(0.0f), m_size);
|
||||||
|
|
||||||
|
if (parClip) {
|
||||||
const RectFloat clip(float2(0.0f), static_cast<float2>(m_sdlmain->WidthHeight()));
|
const RectFloat clip(float2(0.0f), static_cast<float2>(m_sdlmain->WidthHeight()));
|
||||||
const bool visible = ClipRect(src, dest, clip);
|
const bool visible = ClipRect(src, dest, clip);
|
||||||
if (not visible)
|
if (not visible)
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
else {
|
||||||
|
const RectFloat clip(float2(0.0f), static_cast<float2>(m_sdlmain->WidthHeight()));
|
||||||
|
assert(IsRectCompletelyInsideRect(dest, clip));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const SDL_Rect sdlsrc(src);
|
const SDL_Rect sdlsrc(src);
|
||||||
//std::cout << "src = " << src.from << " - " << src.to << ", size is " << m_size << "\n";
|
|
||||||
SDL_Rect sdldst(dest);
|
SDL_Rect sdldst(dest);
|
||||||
sdldst.y = m_sdlmain->WidthHeight().y() - sdldst.y - sdldst.h;
|
sdldst.y = m_sdlmain->WidthHeight().y() - sdldst.y - sdldst.h;
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,8 @@ 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 ( const float2& parPos, const float2& parScaling ) const { Render(parPos, m_size, parScaling); }
|
void Render ( const float2& parPos, const float2& parScaling, bool parClip ) const { Render(parPos, m_size, parScaling, parClip); }
|
||||||
void Render ( const float2& parPos, const float2& parSize, const float2& parScaling ) const;
|
void Render ( const float2& parPos, const float2& parSize, const float2& parScaling, bool parClip ) const;
|
||||||
const SDLMain* SDLObject ( void ) const { return m_sdlmain; }
|
const SDLMain* SDLObject ( void ) const { return m_sdlmain; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -67,12 +67,13 @@ namespace cloonel {
|
||||||
const ushort2 grid(static_cast<ushort2>(m_tileCount.tileCount()));
|
const ushort2 grid(static_cast<ushort2>(m_tileCount.tileCount()));
|
||||||
const float2& sz = m_tileCount.tileSize();
|
const float2& sz = m_tileCount.tileSize();
|
||||||
|
|
||||||
|
//TODO: add code to tell the renderer if the current tile will need clipping or not
|
||||||
float2 dest;
|
float2 dest;
|
||||||
dest.y() = 0.0f;
|
dest.y() = 0.0f;
|
||||||
for (uint16_t y = 0; y < grid.y(); ++y) {
|
for (uint16_t y = 0; y < grid.y(); ++y) {
|
||||||
dest.x() = 0.0f;
|
dest.x() = 0.0f;
|
||||||
for (uint16_t x = 0; x < grid.x(); ++x) {
|
for (uint16_t x = 0; x < grid.x(); ++x) {
|
||||||
m_tile->Render(dest, sz, float2(1.0f));
|
m_tile->Render(dest, sz, float2(1.0f), true);
|
||||||
dest.x() += sz.x();
|
dest.x() += sz.x();
|
||||||
}
|
}
|
||||||
dest.y() += sz.y();
|
dest.y() += sz.y();
|
||||||
|
|
Loading…
Reference in a new issue