#pragma once

#include "SpriteStamp.h"

struct LayerSpriteCompare
{
	bool operator() ( SpriteStamp* sprite1, SpriteStamp* sprite2 ) const {
		D3DXVECTOR3* sprite1Position = sprite1->getPosition();
		D3DXVECTOR3* sprite2Position = sprite2->getPosition();
		D3DXVECTOR3* sprite1Center = sprite1->getCenter();
		D3DXVECTOR3* sprite2Center = sprite2->getCenter();
		RECT* sprite1Clip = sprite1->getClippingRect();
		RECT* sprite2Clip = sprite2->getClippingRect();
		int sprite1Y = 0;
		int sprite2Y = 0;

		//// Figure the bottom y of sprite 1

		// Set to position
		if ( sprite1Position != NULL ) {
			sprite1Y = ( int ) sprite1Position->y;
		} else {
			sprite1Y = 0;
		}
		// Take into account clipping rect
		if ( sprite1Clip != NULL ) {
			sprite1Y += sprite1Clip->bottom - sprite1Clip->top;
		} else {
			sprite1Y += sprite1->getTotalHeight();
		}
		// Take into account center
		if ( sprite1Center != NULL ) {
			sprite1Y -= ( int ) sprite1Center->y;
		}

		//// Figure the bottom y of sprite 2

		// Set to position
		if ( sprite2Position != NULL ) {
			sprite2Y = ( int ) sprite2Position->y;
		} else {
			sprite2Y = 0;
		}

		// Take into account clipping rect
		if ( sprite1Clip != NULL ) {
			sprite1Y += sprite1Clip->bottom - sprite1Clip->top;
		} else {
			sprite1Y += sprite1->getTotalHeight();
		}

		// Take into account center
		if ( sprite2Center != NULL ) {
			sprite2Y -= ( int ) sprite2Center->y;
		}

		return sprite2Y < sprite1Y;
	}
};
