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

@ -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;