2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 1998 - 2000 , Matthes Bender
* Copyright ( c ) 2001 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
* Copyright ( c ) 2011 - 2013 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
/* A piece of a DirectDraw surface */
# ifndef INC_C4Facet
# define INC_C4Facet
2016-04-03 18:07:56 +00:00
# include "graphics/C4Draw.h"
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
const int32_t C4FCT_None = 0 ,
2009-05-08 13:28:41 +00:00
2011-08-03 23:30:37 +00:00
C4FCT_Left = 1 ,
C4FCT_Right = 2 ,
C4FCT_Top = 4 ,
C4FCT_Bottom = 8 ,
C4FCT_Center = 16 ,
2009-05-08 13:28:41 +00:00
2011-08-03 23:30:37 +00:00
C4FCT_Alignment = C4FCT_Left | C4FCT_Right | C4FCT_Top | C4FCT_Bottom | C4FCT_Center ,
2009-05-08 13:28:41 +00:00
2011-08-03 23:30:37 +00:00
C4FCT_Half = 32 ,
C4FCT_Double = 64 ,
C4FCT_Triple = 128 ;
2009-05-08 13:28:41 +00:00
// tuple of two integers
struct C4Vec2D
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
int32_t x , y ;
C4Vec2D ( int32_t x = 0 , int32_t y = 0 ) : x ( x ) , y ( y ) { }
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
2011-09-30 20:15:51 +00:00
class C4DrawTransform : public C4BltTransform
2010-03-28 17:58:21 +00:00
{
public :
int32_t FlipDir ; // +1 or -1; multiplied as x-flip
C4DrawTransform ( C4DrawTransform & rCopy , float iOffX , float iOffY ) // ctor doing transform at given offset - doesn't init FlipDir (for temp use only)
2009-05-08 13:28:41 +00:00
{
2010-03-28 17:58:21 +00:00
SetTransformAt ( rCopy , iOffX , iOffY ) ;
}
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
C4DrawTransform ( )
{
// ctor without matrix initialization
FlipDir = 1 ;
}
C4DrawTransform ( int32_t iFlipDir )
{
// ctor setting flipdir only
FlipDir = iFlipDir ;
// set identity
Set ( 1 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 ) ;
}
~ C4DrawTransform ( )
{
}
// do transform at given offset - doesn't init FlipDir (for temp use only)
void SetTransformAt ( C4DrawTransform & rCopy , float iOffX , float iOffY ) ;
void Set ( float fA , float fB , float fC , float fD , float fE , float fF , float fG , float fH , float fI )
2010-03-27 16:05:02 +00:00
{
2010-03-28 17:58:21 +00:00
// set values; apply flipdir
2011-09-30 20:15:51 +00:00
C4BltTransform : : Set ( fA * FlipDir , fB , fC , fD , fE , fF , fG , fH , fI ) ;
2010-03-28 17:58:21 +00:00
}
void SetFlipDir ( int32_t iNewFlipDir )
{
// no change?
if ( iNewFlipDir = = FlipDir ) return ;
// set and apply in matrix
FlipDir = iNewFlipDir ; mat [ 0 ] = - mat [ 0 ] ;
}
2011-09-01 13:35:12 +00:00
bool IsIdentity ( ) const
2010-03-28 17:58:21 +00:00
{
2011-09-01 13:35:12 +00:00
return ( mat [ 0 ] = = 1.0f ) & & ( mat [ 1 ] = = 0.0f ) & & ( mat [ 2 ] = = 0.0f )
& & ( mat [ 3 ] = = 0.0f ) & & ( mat [ 4 ] = = 1.0f ) & & ( mat [ 5 ] = = 0.0f )
& & ( mat [ 6 ] = = 0.0f ) & & ( mat [ 7 ] = = 0.0f ) & & ( mat [ 8 ] = = 1.0f )
2010-03-28 17:58:21 +00:00
& & ( FlipDir = = 1 ) ; // flipdir must be 1, because otherwise matrices flipped by action+script would be removed
}
// default comparison op won't work :(
bool operator = = ( const C4DrawTransform & rCmp ) const
{
return ( mat [ 0 ] = = rCmp . mat [ 0 ] ) & & ( mat [ 1 ] = = rCmp . mat [ 1 ] ) & & ( mat [ 2 ] = = rCmp . mat [ 2 ] )
& & ( mat [ 3 ] = = rCmp . mat [ 3 ] ) & & ( mat [ 4 ] = = rCmp . mat [ 4 ] ) & & ( mat [ 5 ] = = rCmp . mat [ 5 ] )
& & ( mat [ 6 ] = = rCmp . mat [ 6 ] ) & & ( mat [ 7 ] = = rCmp . mat [ 7 ] ) & & ( mat [ 8 ] = = rCmp . mat [ 8 ] ) & & ( FlipDir = = rCmp . FlipDir ) ;
}
C4DrawTransform * operator & ( ) { return this ; }
void CompileFunc ( StdCompiler * pComp ) ;
// rounded pixel offsets generated by this transformation
int32_t GetXOffset ( ) const { return static_cast < int32_t > ( mat [ 2 ] ) ; }
int32_t GetYOffset ( ) const { return static_cast < int32_t > ( mat [ 5 ] ) ; }
} ;
class C4Facet
{
public :
2011-10-03 14:07:07 +00:00
C4Surface * Surface ;
2012-10-28 14:33:58 +00:00
float X , Y , Wdt , Hgt ;
2010-03-28 17:58:21 +00:00
public :
C4Facet ( ) ;
2012-10-28 14:33:58 +00:00
C4Facet ( C4Surface * pSfc , float iX , float iY , float iWdt , float iHgt )
2009-05-08 13:28:41 +00:00
: Surface ( pSfc ) , X ( iX ) , Y ( iY ) , Wdt ( iWdt ) , Hgt ( iHgt ) { }
2010-03-28 17:58:21 +00:00
public :
void Default ( ) ;
2011-10-03 14:06:41 +00:00
void Set ( C4Surface & rSfc ) ;
2012-10-28 14:33:58 +00:00
void Set ( C4Surface * nsfc , float nx , float ny , float nwdt , float nhgt ) ;
2010-03-28 17:58:21 +00:00
void Set ( const C4Facet & cpy ) { * this = cpy ; }
void Expand ( int32_t iLeft = 0 , int32_t iRight = 0 , int32_t iTop = 0 , int32_t iBottom = 0 ) ;
void DrawEnergyLevelEx ( int32_t iLevel , int32_t iRange , const C4Facet & gfx , int32_t bar_idx ) ; // draw energy level using graphics
2011-10-03 14:07:07 +00:00
void DrawX ( C4Surface * sfcTarget , float iX , float iY , float iWdt , float iHgt , int32_t iPhaseX = 0 , int32_t iPhaseY = 0 ) const ;
void DrawXFloat ( C4Surface * sfcTarget , float fX , float fY , float fWdt , float fHgt ) const ;
2010-03-28 17:58:21 +00:00
void DrawValue ( C4Facet & cgo , int32_t iValue , int32_t iPhaseX = 0 , int32_t iPhaseY = 0 , int32_t iAlign = C4FCT_Center ) ;
void DrawValue2 ( C4Facet & cgo , int32_t iValue1 , int32_t iValue2 , int32_t iPhaseX = 0 , int32_t iPhaseY = 0 , int32_t iAlign = C4FCT_Center , int32_t * piUsedWidth = NULL ) ;
void Draw ( C4Facet & cgo , bool fAspect = true , int32_t iPhaseX = 0 , int32_t iPhaseY = 0 , bool fTransparent = true ) ;
void DrawFullScreen ( C4Facet & cgo ) ;
2011-10-03 14:07:07 +00:00
void DrawT ( C4Surface * sfcTarget , float iX , float iY , int32_t iPhaseX , int32_t iPhaseY , C4DrawTransform * pTransform ) ; // draw with transformation (if pTransform is assigned)
2010-03-28 17:58:21 +00:00
void DrawT ( C4Facet & cgo , bool fAspect , int32_t iPhaseX , int32_t iPhaseY , C4DrawTransform * pTransform ) ;
2012-02-25 16:35:24 +00:00
void DrawTUnscaled ( C4Surface * sfcTarget , float iX , float iY , int32_t iPhaseX , int32_t iPhaseY , C4DrawTransform * pTransform ) ; // interpret source coordinates as unscaled
void DrawTUnscaled ( C4Facet & cgo , bool fAspect , int32_t iPhaseX , int32_t iPhaseY , C4DrawTransform * pTransform ) ;
2011-10-03 14:07:07 +00:00
void DrawXT ( C4Surface * sfcTarget , float iX , float iY , int32_t iWdt , int32_t iHgt , int32_t iPhaseX , int32_t iPhaseY , C4DrawTransform * pTransform ) ;
2010-03-28 17:58:21 +00:00
void DrawClr ( C4Facet & cgo , bool fAspect = true , DWORD dwClr = 0 ) ; // set surface color and draw
2011-10-03 14:07:07 +00:00
void DrawXClr ( C4Surface * sfcTarget , int32_t iX , int32_t iY , int32_t iWdt , int32_t iHgt , DWORD dwClr ) ; // set surface color and draw
2010-03-28 17:58:21 +00:00
void DrawValue2Clr ( C4Facet & cgo , int32_t iValue1 , int32_t iValue2 , DWORD dwClr ) ; // set surface color and draw
2011-10-03 14:07:07 +00:00
void DrawXR ( C4Surface * sfcTarget , int32_t iX , int32_t iY , int32_t iWdt , int32_t iHgt , int32_t iPhaseX = 0 , int32_t iPhaseY = 0 , int32_t r = 0 ) ; // draw rotated
void Draw ( C4Surface * sfcTarget , float iX , float iY , int32_t iPhaseX = 0 , int32_t iPhaseY = 0 ) ;
2010-03-28 17:58:21 +00:00
bool GetPhaseNum ( int32_t & rX , int32_t & rY ) ; // return number of phases in this graphic
C4Facet GetSection ( int32_t iSection ) ;
C4Facet GetPhase ( int iPhaseX = 0 , int iPhaseY = 0 ) ;
C4Facet GetFraction ( int32_t percentWdt , int32_t percentHgt = 0 , int32_t alignX = C4FCT_Left , int32_t alignY = C4FCT_Top ) ;
C4Facet TruncateSection ( int32_t iAlign = C4FCT_Left ) ;
C4Facet Truncate ( int32_t iAlign , int32_t iSize ) ;
int32_t GetSectionCount ( ) ;
int32_t GetWidthByHeight ( int32_t iHeight ) // calc width so it matches facet aspect to height
{ return iHeight * Wdt / ( Hgt ? Hgt : 1 ) ; }
int32_t GetHeightByWidth ( int32_t iWidth ) // calc height so it matches facet aspect to width
{ return iWidth * Hgt / ( Wdt ? Wdt : 1 ) ; }
} ;
2009-05-08 13:28:41 +00:00
# endif // INC_C4Facet