Support drawing textures without doing any clipping.

This commit is contained in:
King_DuckZ 2014-03-25 10:32:34 +01:00
parent 0674f2d28d
commit 79fbf0faf7
4 changed files with 29 additions and 10 deletions

View file

@ -68,6 +68,6 @@ namespace cloonel {
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
void Character::Draw() const {
m_texture->Render(GetPos(), WidthHeight(), m_screenRatio.Ratio());
m_texture->Render(GetPos(), WidthHeight(), m_screenRatio.Ratio(), true);
}
} //namespace cloonel

View file

@ -107,6 +107,9 @@ namespace cloonel {
GraphicFormat GuessGraphicFormatFromName (const std::string& parPath) __attribute__((pure));
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());
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
///--------------------------------------------------------------------------
@ -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());
const float2 pos(parPos * parScaling);
@ -355,13 +366,20 @@ namespace cloonel {
RectFloat dest(pos, pos + siz);
RectFloat src(float2(0.0f), m_size);
const RectFloat clip(float2(0.0f), static_cast<float2>(m_sdlmain->WidthHeight()));
const bool visible = ClipRect(src, dest, clip);
if (not visible)
return;
if (parClip) {
const RectFloat clip(float2(0.0f), static_cast<float2>(m_sdlmain->WidthHeight()));
const bool visible = ClipRect(src, dest, clip);
if (not visible)
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);
//std::cout << "src = " << src.from << " - " << src.to << ", size is " << m_size << "\n";
SDL_Rect sdldst(dest);
sdldst.y = m_sdlmain->WidthHeight().y() - sdldst.y - sdldst.h;

View file

@ -36,8 +36,8 @@ namespace cloonel {
void Reload ( void );
void Destroy ( void ) noexcept;
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& parSize, const float2& parScaling ) const;
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, bool parClip ) const;
const SDLMain* SDLObject ( void ) const { return m_sdlmain; }
private:

View file

@ -67,12 +67,13 @@ namespace cloonel {
const ushort2 grid(static_cast<ushort2>(m_tileCount.tileCount()));
const float2& sz = m_tileCount.tileSize();
//TODO: add code to tell the renderer if the current tile will need clipping or not
float2 dest;
dest.y() = 0.0f;
for (uint16_t y = 0; y < grid.y(); ++y) {
dest.x() = 0.0f;
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.y() += sz.y();