///////////////////////////////////////////////////////////////////////////////////////////
// SpriteManager.h
//
//  Definition of the SpriteManager class, which handles the drawing of sprites.

#pragma once

#include "Device.h"
#include "Texture.h"

using namespace System;
using namespace System::ComponentModel;
            
namespace Sunlight
{
    namespace DirectX
    {
        namespace Graphics
        {
            __gc public class Sprite;

            // Manages the drawing of Sprite objects.
            public __gc class SpriteManager
            {
            public:
                // This needs to be public so Sprite can get to it...
                __nogc struct SpriteVertex
                {
                    float       x, y, z, rhw;   // The transformed position for the vertex.
                    unsigned    dwColor;        // The vertex colour.
                    float       tu, tv;         // Texture co-ordinates.
                };

            protected:
                static const int VertexFormat = (int)(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1);
    
                __gc class ObjectListElement
                {
                public:
                    ObjectListElement(Sprite *pSprite);
                    ObjectListElement(Sprite *pSprite, int nShadowDepth);

                    Texture         *TextureObject;
                    SpriteVertex Vertices __nogc [4];
                    bool            Shadowed;
                };

                IDirect3DVertexBuffer8  __nogc  *m_vb;
                int                             m_nVBSize;
                Collections::ArrayList          *m_plistObjects;
                Device                          *m_pDevice;

                // Called before the parent device is released or reset.
                void OnDeviceRelease(Object *sender, EventArgs *e);
                // Destroys the Direct3D vertex buffer associated with this object.
                void Destroy();

            public:
                SpriteManager();
                ~SpriteManager();

                // The Device object on which this sprite manager will draw.
                __property Device *get_DeviceObject();
                __property void set_DeviceObject(Device *);

                // Draw a Sprite object with this SpriteManager.
                void Draw(Sprite *sprite);
                // Complete the drawing of all the Sprite objects.
                void FinishDraw();
                // Abort drawing of all the Sprite objects, without displaying any.
                void AbortDraw();
            };
        }
    }
}