diff --git a/Docs/Luadoc/Lua.xml b/Docs/Luadoc/Lua.xml
index 994dd0d681..7bc689fade 100644
--- a/Docs/Luadoc/Lua.xml
+++ b/Docs/Luadoc/Lua.xml
@@ -1511,6 +1511,8 @@
+
+
diff --git a/Docs/Luadoc/LuaDocumentation.xml b/Docs/Luadoc/LuaDocumentation.xml
index d40e06f3b2..c2d718859b 100644
--- a/Docs/Luadoc/LuaDocumentation.xml
+++ b/Docs/Luadoc/LuaDocumentation.xml
@@ -4277,6 +4277,13 @@ save yourself some time, copy this for undocumented things:
Sets the custom image rectangle. (Works in image pixel space.)
+
+ Sets custom offsets for the corners of the Sprite. Coordinates are paired,
+ corner order is upper left, lower left, lower right, upper right.
+
+
+ Turns off the custom pos coords for the sprite.
+
Set the to mode.
diff --git a/src/Sprite.cpp b/src/Sprite.cpp
index 21db165257..3d2f09f285 100644
--- a/src/Sprite.cpp
+++ b/src/Sprite.cpp
@@ -23,6 +23,7 @@ Sprite::Sprite()
m_iCurState = 0;
m_fSecsIntoState = 0.0f;
m_bUsingCustomTexCoords = false;
+ m_bUsingCustomPosCoords = false;
m_bSkipNextUpdate = true;
m_EffectMode = EffectMode_Normal;
@@ -47,9 +48,11 @@ Sprite::Sprite( const Sprite &cpy ):
CPY( m_iCurState );
CPY( m_fSecsIntoState );
CPY( m_bUsingCustomTexCoords );
+ CPY( m_bUsingCustomPosCoords );
CPY( m_bSkipNextUpdate );
CPY( m_EffectMode );
memcpy( m_CustomTexCoords, cpy.m_CustomTexCoords, sizeof(m_CustomTexCoords) );
+ memcpy( m_CustomPosCoords, cpy.m_CustomPosCoords, sizeof(m_CustomPosCoords) );
CPY( m_fRememberedClipWidth );
CPY( m_fRememberedClipHeight );
CPY( m_fTexCoordVelocityX );
@@ -474,6 +477,14 @@ void Sprite::DrawTexture( const TweenState *state )
v[1].p = RageVector3( croppedQuadVerticies.left, croppedQuadVerticies.bottom, 0 ); // bottom left
v[2].p = RageVector3( croppedQuadVerticies.right, croppedQuadVerticies.bottom, 0 ); // bottom right
v[3].p = RageVector3( croppedQuadVerticies.right, croppedQuadVerticies.top, 0 ); // top right
+ if( m_bUsingCustomPosCoords )
+ {
+ for( int i=0; i < 4; ++i)
+ {
+ v[i].p.x+= m_CustomPosCoords[i*2];
+ v[i].p.y+= m_CustomPosCoords[(i*2)+1];
+ }
+ }
DISPLAY->ClearAllTextures();
DISPLAY->SetTexture( TextureUnit_1, m_pTexture? m_pTexture->GetTexHandle():0 );
@@ -803,6 +814,15 @@ void Sprite::SetCustomImageCoords( float fImageCoords[8] ) // order: top left, b
SetCustomTextureCoords( fImageCoords );
}
+void Sprite::SetCustomPosCoords( float fPosCoords[8] ) // order: top left, bottom left, bottom right, top right
+{
+ m_bUsingCustomPosCoords= true;
+ for( int i=0; i<8; ++i )
+ {
+ m_CustomPosCoords[i]= fPosCoords[i];
+ }
+}
+
const RectF *Sprite::GetCurrentTextureCoordRect() const
{
return GetTextureCoordRectForState( m_iCurState );
@@ -839,6 +859,11 @@ void Sprite::StopUsingCustomCoords()
m_bUsingCustomTexCoords = false;
}
+void Sprite::StopUsingCustomPosCoords()
+{
+ m_bUsingCustomPosCoords = false;
+}
+
void Sprite::SetTexCoordVelocity(float fVelX, float fVelY)
{
m_fTexCoordVelocityX = fVelX;
@@ -1035,6 +1060,21 @@ public:
* Commands that take effect immediately (ignoring the tweening queue): */
static int customtexturerect( T* p, lua_State *L ) { p->SetCustomTextureRect( RectF(FArg(1),FArg(2),FArg(3),FArg(4)) ); return 0; }
static int SetCustomImageRect( T* p, lua_State *L ) { p->SetCustomImageRect( RectF(FArg(1),FArg(2),FArg(3),FArg(4)) ); return 0; }
+ static int SetCustomPosCoords( T* p, lua_State *L )
+ {
+ float coords[8];
+ for( int i=0; i<8; ++i )
+ {
+ coords[i]= FArg(i+1);
+ if( isnan(coords[i]) )
+ {
+ coords[i]= 0.0f;
+ }
+ }
+ p->SetCustomPosCoords(coords);
+ return 0;
+ }
+ static int StopUsingCustomPosCoords( T* p, lua_State *L ) { p->StopUsingCustomPosCoords(); return 0; }
static int texcoordvelocity( T* p, lua_State *L ) { p->SetTexCoordVelocity( FArg(1),FArg(2) ); return 0; }
static int scaletoclipped( T* p, lua_State *L ) { p->ScaleToClipped( FArg(1),FArg(2) ); return 0; }
static int CropTo( T* p, lua_State *L ) { p->CropTo( FArg(1),FArg(2) ); return 0; }
@@ -1076,6 +1116,8 @@ public:
ADD_METHOD( LoadBackground );
ADD_METHOD( customtexturerect );
ADD_METHOD( SetCustomImageRect );
+ ADD_METHOD( SetCustomPosCoords );
+ ADD_METHOD( StopUsingCustomPosCoords );
ADD_METHOD( texcoordvelocity );
ADD_METHOD( scaletoclipped );
ADD_METHOD( CropTo );
diff --git a/src/Sprite.h b/src/Sprite.h
index 3a941ec28c..0697fc8aec 100644
--- a/src/Sprite.h
+++ b/src/Sprite.h
@@ -52,9 +52,11 @@ public:
void SetCustomTextureCoords( float fTexCoords[8] );
void SetCustomImageRect( RectF rectImageCoords ); // in image pixel space
void SetCustomImageCoords( float fImageCoords[8] );
+ void SetCustomPosCoords( float fPosCoords[8] );
const RectF *GetCurrentTextureCoordRect() const;
const RectF *GetTextureCoordRectForState( int iState ) const;
void StopUsingCustomCoords();
+ void StopUsingCustomPosCoords();
void GetActiveTextureCoords(float fTexCoordsOut[8]) const;
void StretchTexCoords( float fX, float fY );
void AddImageCoords( float fX, float fY ); // in image pixel space
@@ -99,6 +101,7 @@ private:
EffectMode m_EffectMode;
bool m_bUsingCustomTexCoords;
+ bool m_bUsingCustomPosCoords;
bool m_bSkipNextUpdate;
/**
* @brief Set up the coordinates for the texture.
@@ -107,6 +110,16 @@ private:
* The remaining six are for the (x, y) coordinates for bottom left,
* bottom right, and top right respectively. */
float m_CustomTexCoords[8];
+ /**
+ * @brief Set up the coordinates for the position.
+ *
+ * These are offsets for the quad the sprite will be drawn to.
+ * The first two are the (x, y) offsets for the top left.
+ * The remaining six are for the (x, y) coordinates for bottom left,
+ * bottom right, and top right respectively.
+ * These are offsets instead of a replacement for m_size to avoid
+ * complicating the cropping code. */
+ float m_CustomPosCoords[8];
// Remembered clipped dimensions are applied on Load().
// -1 means no remembered dimensions;