#ifndef TEXTURE_SECTION_H
#define TEXTURE_SECTION_H

#include <d3d8.h>


struct tTextureSection
{

  enum eFlags
  {
    TSF_DEFAULT       = 0x00000000,
    TSF_ROTATE_90     = 0x00000001,
    TSF_ROTATE_180    = 0x00000002,
    TSF_ROTATE_270    = 0x00000003,
    TSF_H_MIRROR      = 0x00000004,
    TSF_V_MIRROR      = 0x00000008,
    TSF_HCENTER       = 0x00000010,
    TSF_VCENTER       = 0x00000020,
    TSF_ALIGN_BOTTOM  = 0x00000040,
    TSF_ALIGN_RIGHT   = 0x00000080,

    TSF_CENTERED    = TSF_HCENTER | TSF_VCENTER,
  };

  IDirect3DTexture8*        pTexture;
  int                       Width,
                            Height,
                            XOffset,
                            YOffset;
  float                     TU[2],
                            TV[2];
  DWORD                     Flags;


  tTextureSection( IDirect3DTexture8* pTexture = NULL, int X = 0, int Y = 0, int Width = -1, int Height = -1, DWORD Flags = 0 ) :
    pTexture( pTexture ),
    Width( Width ),
    Height( Height ),
    XOffset( X ),
    YOffset( Y ),
    Flags( Flags )
  {
    if ( ( pTexture )
    &&   ( Width == -1 )
    &&   ( Height == -1 ) )
    {
      Width  = 256;
      Height = 256;
    }
    if ( Width == -1 )
    {
      Width = 0;
    }
    if ( Height == -1 )
    {
      Height = 0;
    }
    CalcTexCoords();
  }

  void CalcTexCoords()
  {
    if ( pTexture )
    {
      TU[0] = (float)XOffset / 256.0f;
      TV[0] = (float)YOffset / 256.0f;
      TU[1] = (float)( XOffset + Width ) / 256.0f;
      TV[1] = (float)( YOffset + Height ) / 256.0f;
    }
    else
    {
      TU[0] = 0.0f;
      TV[0] = 0.0f;
      TU[1] = 0.0f;
      TV[1] = 0.0f;
    }
  }

};

#endif // TEXTURE_SECTION_H