mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-04 22:15:33 +02:00
Shrink missized blits
This commit is contained in:
parent
edb3f83777
commit
2247f1d9b7
2 changed files with 85 additions and 4 deletions
|
@ -949,8 +949,84 @@ void Bitmap::blt(int x, int y,
|
||||||
source, rect, opacity);
|
source, rect, opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bitmap::stretchBlt(const IntRect &destRect,
|
static bool shrinkRects(float &sourcePos, float &sourceLen, const int &sBitmapLen,
|
||||||
const Bitmap &source, const IntRect &sourceRect,
|
float &destPos, float &destLen, const int &dBitmapLen, bool normalize = false)
|
||||||
|
{
|
||||||
|
float sStart = sourceLen > 0 ? sourcePos : sourceLen + sourcePos;
|
||||||
|
float sEnd = sourceLen > 0 ? sourceLen + sourcePos : sourcePos;
|
||||||
|
float sLength = sEnd - sStart;
|
||||||
|
|
||||||
|
if (sStart >= 0 && sEnd < sBitmapLen)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (sStart >= sBitmapLen || sEnd < 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
float dStart = destLen > 0 ? destPos: destLen + destPos;
|
||||||
|
float dEnd = destLen > 0 ? destLen + destPos : destPos;
|
||||||
|
float dLength = dEnd - dStart;
|
||||||
|
|
||||||
|
float delta = sEnd - sBitmapLen;
|
||||||
|
float dDelta;
|
||||||
|
if (delta > 0)
|
||||||
|
{
|
||||||
|
dDelta = (delta / sLength) * dLength;
|
||||||
|
sLength -= delta;
|
||||||
|
sEnd = sBitmapLen;
|
||||||
|
dEnd -= dDelta;
|
||||||
|
dLength -= dDelta;
|
||||||
|
}
|
||||||
|
if (sStart < 0)
|
||||||
|
{
|
||||||
|
dDelta = (sStart / sLength) * dLength;
|
||||||
|
sLength += sStart;
|
||||||
|
sStart = 0;
|
||||||
|
dStart -= dDelta;
|
||||||
|
dLength += dDelta;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!normalize)
|
||||||
|
{
|
||||||
|
sourcePos = sourceLen > 0 ? sStart : sEnd;
|
||||||
|
sourceLen = sourceLen > 0 ? sLength : -sLength;
|
||||||
|
destPos = destLen > 0 ? dStart : dEnd;
|
||||||
|
destLen = destLen > 0 ? dLength : -dLength;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Ensure the source rect has positive dimensions, for blitting from mega surfaces
|
||||||
|
destPos = (destLen > 0 == sourceLen > 0) ? dStart : dEnd;
|
||||||
|
destLen = (destLen > 0 == sourceLen > 0) ? dLength : -dLength;
|
||||||
|
sourcePos = sStart;
|
||||||
|
sourceLen = sLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool shrinkRects(int &sourcePos, int &sourceLen, const int &sBitmapLen,
|
||||||
|
int &destPos, int &destLen, const int &dBitmapLen)
|
||||||
|
{
|
||||||
|
float fSourcePos = sourcePos;
|
||||||
|
float fSourceLen = sourceLen;
|
||||||
|
float fDestPos = destPos;
|
||||||
|
float fDestLen = destLen;
|
||||||
|
|
||||||
|
bool ret = shrinkRects(fSourcePos, fSourceLen, sBitmapLen, fDestPos, fDestLen, dBitmapLen, true);
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
ret = shrinkRects(fDestPos, fDestLen, dBitmapLen, fSourcePos, fSourceLen, sBitmapLen);
|
||||||
|
|
||||||
|
sourcePos = round(fSourcePos);
|
||||||
|
sourceLen = round(fSourceLen);
|
||||||
|
destPos = round(fDestPos);
|
||||||
|
destLen = round(fDestLen);
|
||||||
|
|
||||||
|
return ret || sourceLen == 0 || destLen == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bitmap::stretchBlt(IntRect destRect,
|
||||||
|
const Bitmap &source, IntRect sourceRect,
|
||||||
int opacity)
|
int opacity)
|
||||||
{
|
{
|
||||||
guardDisposed();
|
guardDisposed();
|
||||||
|
@ -988,6 +1064,11 @@ void Bitmap::stretchBlt(const IntRect &destRect,
|
||||||
if (opacity == 0)
|
if (opacity == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(shrinkRects(sourceRect.x, sourceRect.w, source.width(), destRect.x, destRect.w, width()))
|
||||||
|
return;
|
||||||
|
if(shrinkRects(sourceRect.y, sourceRect.h, source.height(), destRect.y, destRect.h, height()))
|
||||||
|
return;
|
||||||
|
|
||||||
SDL_Surface *srcSurf = source.megaSurface();
|
SDL_Surface *srcSurf = source.megaSurface();
|
||||||
|
|
||||||
if (srcSurf && shState->config().subImageFix)
|
if (srcSurf && shState->config().subImageFix)
|
||||||
|
|
|
@ -66,8 +66,8 @@ public:
|
||||||
const Bitmap &source, IntRect rect,
|
const Bitmap &source, IntRect rect,
|
||||||
int opacity = 255);
|
int opacity = 255);
|
||||||
|
|
||||||
void stretchBlt(const IntRect &destRect,
|
void stretchBlt(IntRect destRect,
|
||||||
const Bitmap &source, const IntRect &sourceRect,
|
const Bitmap &source, IntRect sourceRect,
|
||||||
int opacity = 255);
|
int opacity = 255);
|
||||||
|
|
||||||
void fillRect(int x, int y,
|
void fillRect(int x, int y,
|
||||||
|
|
Loading…
Add table
Reference in a new issue