#if !defined(AFX_TEXTUREDOC_H__53F452CA_7721_4EF0_B2F6_5D28A6CAFFD2__INCLUDED_)
#define AFX_TEXTUREDOC_H__53F452CA_7721_4EF0_B2F6_5D28A6CAFFD2__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// TextureDoc.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CTextureDoc document
#include <imagelib\image.h>
#include <stuff\stuff.hpp>

class CCell
{
	int AddVert(int,int);
	int GetXDim();
	int GetYDim();

	int V1,V2;	// Upper left and lower right index in vertex array
	bool bSplit;
public:
	CCell();
	~CCell();

	Image *m_image;
	CCell *m_arrChildren[4];
	CString name;

	int state;	// 0 == empty, 1 == partial, 2==full
	int CreateCell(int,int);
	CCell *FillCell(Image *);
	int SplitCell(int,int);
	int SetVerts(int,int);
	int GetV1();
	int GetV2();
	CPoint GetPoint1();
};

class CTextureDoc : public CDocument
{
protected:
	CTextureDoc();           // protected constructor used by dynamic creation
	DECLARE_DYNCREATE(CTextureDoc)

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CTextureDoc)
	public:
	virtual void Serialize(CArchive& ar);   // overridden for document i/o
	virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
	virtual void SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU = TRUE);
	virtual void OnCloseDocument();
	protected:
	virtual BOOL OnNewDocument();
	virtual BOOL SaveModified();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CTextureDoc();
	Stuff::Page *GetPage(int);
	Image *GetImage(int);
	void SetImage(Image* pImage, int i);
	int ReplacePage(Stuff::Page *,Stuff::Page *);
	int GetCount();
	Image *LoadTexture(Stuff::Page *);

#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

	// Generated message map functions
protected:
	CPtrList m_listFlags;
	CPtrList m_listPages;
	CPtrList m_listImages;
	int ConstructPage(CCell *pCell,Stuff::Page *page);
	int BuildMegaTexture(CCell *pCell,Image *pImage);
	Image *ArrangeTextures(Stuff::Page *);
	int SetDefaults(Stuff::Page *page, Image *pImage);
	void ClearAllPages();

	//Stuff::Page *m_pPage;
	//{{AFX_MSG(CTextureDoc)
	afx_msg void OnFileSave();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TEXTUREDOC_H__53F452CA_7721_4EF0_B2F6_5D28A6CAFFD2__INCLUDED_)
