// FeatureProps.cpp : implementation file
//

#include "stdafx.h"
#include "ImageGrinder.h"
#include "FeatureProps.h"
#include "..\..\Libraries\ImageLib\Image.h"
#include <Compost\TexturePool.hpp>
#include <Compost\FeatureGrid.hpp>
#include "ImageCache.h"


const char featureErrorMessages[][255] =
{
	"No error.",								//	0
		"No feature texture set.",
		"No mask 0 set.",
		"No mask 1 set.",
		"Feature texture not in 555 mode.",
		"Feature texture not in 4444 mode.",	//	5
		"Mask 0 not in 1 mode.",
		"Mask 1 not in 1 mode.",
		"Mask 0 not in 555 mode.",
		"Mask 0 not in 1.1 mode.",
		"Mask 0 not in 1.MipMap mode.",			//	10
		"Mask 0 too big for 555_1 mode.",
		"Mask 1 too big for 555_2 mode.",
		"Mask 0 too small for 555_1_S mode.",
		"Feature texture size not power of 2.",
		"Mask 0 size not power of 2.",			//	15
		"Mask 1 size not power of 2.",
};

/////////////////////////////////////////////////////////////////////////////
// CFeatureProps dialog


CFeatureProps::CFeatureProps(CWnd* pParent /*=NULL*/)
: CDialog(CFeatureProps::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFeatureProps)
	m_fname = _T("");
	m_tname = _T("");
	m_xoffset = 0;
	m_zoffset = 0;
	m_Mask0FlipHor = FALSE;
	m_Mask0FlipVert = FALSE;
	m_Mask1FlipHor = FALSE;
	m_Mask1FlipVert = FALSE;
	m_TextureFlipHor = FALSE;
	m_TextureFlipVert = FALSE;
	m_BlendMode = -1;
	m_Stretch = FALSE;
	//}}AFX_DATA_INIT
}


void CFeatureProps::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFeatureProps)
	DDX_Control(pDX, IDC_MATLIST, m_MatList);
	DDX_Control(pDX, IDC_MASK1PREVIEW, m_Mask1PreviewPane);
	DDX_Control(pDX, IDC_MASK0PREVIEW, m_Mask0PreviewPane);
	DDX_Control(pDX, IDC_PREVIEWFRAME, m_PreviewPane);
	DDX_Control(pDX, IDC_HEIGHT, m_hcon);
	DDX_Control(pDX, IDC_WIDTH, m_wcon);
	DDX_Control(pDX, IDC_MASK1LIST, m_Mask1List);
	DDX_Control(pDX, IDC_MASK0LIST, m_Mask0List);
	DDX_Control(pDX, IDC_TEXTURELIST, m_TextureList);
	DDX_Text(pDX, IDC_NAME, m_fname);
	DDX_Text(pDX, IDC_XOFF, m_xoffset);
	DDX_Text(pDX, IDC_ZOFF, m_zoffset);
	DDX_Check(pDX, IDC_MASK0FLIPHOR, m_Mask0FlipHor);
	DDX_Check(pDX, IDC_MASK0FLIPVERT, m_Mask0FlipVert);
	DDX_Check(pDX, IDC_MASK1FLIPHOR, m_Mask1FlipHor);
	DDX_Check(pDX, IDC_MASK1FLIPVERT, m_Mask1FlipVert);
	DDX_Check(pDX, IDC_TEXTUREFLIPHOR, m_TextureFlipHor);
	DDX_Check(pDX, IDC_TEXTUREFLIPVERT, m_TextureFlipVert);
	DDX_CBIndex(pDX, IDC_BLENDMODE, m_BlendMode);
	DDX_Check(pDX, IDC_STRETCH, m_Stretch);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFeatureProps, CDialog)
//{{AFX_MSG_MAP(CFeatureProps)
ON_CBN_SELCHANGE(IDC_MASK0LIST, OnSelchangeMask0list)
ON_CBN_SELCHANGE(IDC_MASK1LIST, OnSelchangeMask1list)
ON_CBN_SELCHANGE(IDC_TEXTURELIST, OnSelchangeTexturelist)
ON_CBN_SELCHANGE(IDC_BLENDMODE, OnSelchangeBlendmode)
	ON_BN_CLICKED(IDC_STRETCH, OnStretch)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFeatureProps message handlers

int CFeatureProps::DoModal(Compost::Tool_Feature *fet,int maxX,int maxZ) 
{
	XLen=maxX;
	YLen=maxZ;
	
	fetptr=fet;
	feature_data=*fetptr;
	return CDialog::DoModal();
}

BOOL CFeatureProps::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	
	//Fill ListBoxes;
	
	for(int i=0;i<Compost::MaterialEntriesCount;i++)
	{
		if(!Compost::MaterialEntries[i].MatName) break;
		int itm = m_MatList.AddString((char *)Compost::MaterialEntries[i].MatName);
		m_MatList.SetItemData(itm, i);
	}
	m_MatList.SetCurSel(feature_data.GetMaterial());

	m_Stretch = feature_data.IsStretched();

	Compost::Feature_Texture *FTexture;
	Stuff::TableIteratorOf<Compost::Feature_Texture*, int> imageTableIterator(Compost::TexturePool::Instance->GetImageTable());
	
	int sel;
	int idx;
	CString texture_name,ttype,basename;
	while(NULL!=(FTexture=imageTableIterator.ReadAndNext()))
	{
		basename=(char *)(*(FTexture->GetName()));
		switch(FTexture->GetTextureMode())
		{
		case Compost::Feature_Texture::NoMode: ttype="None"; break;
		case Compost::Feature_Texture::FTT_555: ttype="5"; break;
		case Compost::Feature_Texture::FTT_4444: ttype="4";break;
		case Compost::Feature_Texture::FTT_1:		ttype="1";break;
		case Compost::Feature_Texture::FTT_1_1 : ttype="11";break;
		case Compost::Feature_Texture::FTT_1_M : ttype="1M";break;
		}
		
		texture_name.Format("%s-%s-%ix%i",basename,ttype,FTexture->width,FTexture->height);
		
		if(FTexture->depth!=1)
		{
			idx=m_TextureList.AddString(texture_name);
			m_TextureList.SetItemDataPtr(idx,FTexture);
			
		}
		
		if(FTexture->depth==1)
		{
			idx=m_Mask0List.AddString(texture_name);
			m_Mask0List.SetItemDataPtr(idx,FTexture);
		}		
		
		if(FTexture->depth==1)
		{
			idx=m_Mask1List.AddString(texture_name);
			m_Mask1List.SetItemDataPtr(idx,FTexture);
		}
		
	}
	
	m_Mask0List.InsertString(0,"none");
	m_Mask1List.InsertString(0,"none");
	
	
	sel=0;
	for(i=0;i<m_TextureList.GetCount();i++)
	{
		FTexture=(Compost::Feature_Texture *)m_TextureList.GetItemDataPtr(i);
		if(FTexture==feature_data.GetFeatureTexture())
			sel=i;
	}
	m_TextureList.SetCurSel(sel);
	
	if(feature_data.GetBlendMode()!=Compost::Feature::Blend_Mode::StretchMultiply)
	{
		sel=0;
		for(i=0;i<m_Mask0List.GetCount();i++)
		{
			FTexture=(Compost::Feature_Texture *)m_Mask0List.GetItemDataPtr(i);
			if(FTexture==feature_data.GetFeatureMask0())
				sel=i;
		}
		m_Mask0List.SetCurSel(sel);
	}
	
	if(sel!=0)
	{
		sel=0;
		for(i=0;i<m_Mask1List.GetCount();i++)
		{
			FTexture=(Compost::Feature_Texture *)m_Mask1List.GetItemDataPtr(i);
			if(FTexture==feature_data.GetFeatureMask1())
				sel=i;
		}
	}
	
	m_Mask1List.SetCurSel(sel);
	
	sel=0;
	
	
	m_Mask1List.EnableWindow(m_Mask0List.GetCurSel()!=0);
	
	m_fname=CString((const char *)(*(feature_data.GetName())));
	//	m_xoffset=feature_data.GetTextureXPos();
	//	m_zoffset=feature_data.GetTextureZPos();
	
	int num;
	CString tstr;
	
	m_hcon.ResetContent();
	for(num=8;num<=XLen;num<<=1)
	{
		tstr.Format("%i",num);
		m_hcon.AddString(tstr);
	}
	
	m_wcon.ResetContent();
	for(num=8;num<=YLen;num<<=1)
	{
		tstr.Format("%i",num);
		m_wcon.AddString(tstr);
	}
	
	m_wcon.SetCurSel(Compost::GetPow(feature_data.GetFeatureWidth())-3);
	m_hcon.SetCurSel(Compost::GetPow(feature_data.GetFeatureHeight())-3);
	
	m_TextureFlipHor = (feature_data.GetFlipMode() & Compost::Feature::Flip_Mode::Texture_Horizontal_Flip) ? true:false;
	m_TextureFlipVert = (feature_data.GetFlipMode() & Compost::Feature::Flip_Mode::Texture_Vertical_Flip) ? true:false;
	m_Mask0FlipHor = (feature_data.GetFlipMode() & Compost::Feature::Flip_Mode::Mask0_Horizontal_Flip) ? true:false;
	m_Mask0FlipVert = (feature_data.GetFlipMode() & Compost::Feature::Flip_Mode::Mask0_Vertical_Flip) ? true:false;
	m_Mask1FlipHor = (feature_data.GetFlipMode() & Compost::Feature::Flip_Mode::Mask1_Horizontal_Flip) ? true:false;
	m_Mask1FlipVert = (feature_data.GetFlipMode() & Compost::Feature::Flip_Mode::Mask1_Vertical_Flip) ? true:false;
	
	switch(feature_data.GetBlendMode())
	{
	case Compost::Feature::Blend_Mode::Paste: 
		m_BlendMode=0; 
		m_Mask0List.EnableWindow(FALSE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case Compost::Feature::Blend_Mode::Added: 
		m_BlendMode=1; 
		m_Mask0List.EnableWindow(FALSE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case Compost::Feature::Blend_Mode::Multiply: 
		m_BlendMode=2; 
		m_Mask0List.EnableWindow(FALSE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case Compost::Feature::Blend_Mode::Blend555_1: 
		m_BlendMode=3; 
		m_Mask0List.EnableWindow(TRUE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case Compost::Feature::Blend_Mode::Blend555_2: 
		m_BlendMode=4; 
		m_Mask0List.EnableWindow(TRUE);
		m_Mask1List.EnableWindow(TRUE);
		break;
	case Compost::Feature::Blend_Mode::Blend4444: 
		m_BlendMode=5; 
		m_Mask0List.EnableWindow(FALSE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case Compost::Feature::Blend_Mode::StretchMultiply: 
		m_BlendMode=6; 
		feature_data.SetFeatureMask0(NULL);
		m_Mask0List.EnableWindow(FALSE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case Compost::Feature::Blend_Mode::Blend555_1_1: 
		m_BlendMode=7; 
		m_Mask0List.EnableWindow(TRUE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case Compost::Feature::Blend_Mode::Blend555_1_S: 
		m_BlendMode=8; 
		m_Mask0List.EnableWindow(TRUE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	}
	
	UpdateData(FALSE);
	CRect rct;
	CDC *pDC=GetDC();
	
	m_PreviewPane.GetClientRect(&rct);
	PrvBmp.CreateCompatibleBitmap(pDC,rct.Width(),rct.Height());
	
	m_Mask0PreviewPane.GetClientRect(&rct);
	M0Prv.CreateCompatibleBitmap(pDC,rct.Width(),rct.Height());
	
	m_Mask1PreviewPane.GetClientRect(&rct);
	M1Prv.CreateCompatibleBitmap(pDC,rct.Width(),rct.Height());
	
	
	ReleaseDC(pDC);
	
	UpdateMask0Pane();
	UpdateMask1Pane();
	UpdateTexturePane();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CFeatureProps::OnOK() 
{
	FillData();
	int errorHandle = feature_data.IsValidFeature();
	if(errorHandle==0)
	{ 
		*fetptr=feature_data;
		CDialog::OnOK();
	}
	else
	{
		MessageBox(featureErrorMessages[errorHandle], "Something is wrong here", MB_ICONSTOP | MB_OK);
	}
}

void CFeatureProps::OnSelchangeMask0list() 
{
	
	if(m_Mask0List.GetCurSel()==0)
	{
		m_Mask1List.SetCurSel(0);
		m_Mask1List.EnableWindow(FALSE);
	}
	else
	{
		m_Mask1List.EnableWindow(TRUE);
	}	
	
	
	UpdateMask0Pane();
	
}

void CFeatureProps::OnSelchangeMask1list() 
{
	UpdateMask1Pane();
	
}

void CFeatureProps::OnSelchangeTexturelist() 
{
	
	UpdateTexturePane();
}


void CFeatureProps::FillData()
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	feature_data.SetName((LPCSTR)m_fname);
	//	feature_data.SetTextureXPos(m_xoffset & ~15);
	//	feature_data.SetTextureZPos(m_zoffset & ~15);

	feature_data.SetStretchMode(m_Stretch ? 1 : 0);
	if(!feature_data.IsStretched())
	{
		feature_data.SetFeatureWidth(1<<(m_wcon.GetCurSel()+3));
		feature_data.SetFeatureHeight(1<<(m_hcon.GetCurSel()+3));
	}
	else
	{
		feature_data.SetFeatureWidth(XLen);
		feature_data.SetFeatureHeight(YLen);
	}
		
	feature_data.SetFeatureTexture((Compost::Feature_Texture *)m_TextureList.GetItemDataPtr(m_TextureList.GetCurSel()));	

	Compost::Feature_Texture *cft = (Compost::Feature_Texture *)m_Mask0List.GetItemDataPtr(m_Mask0List.GetCurSel());
	if((int)cft>0)
	{
		feature_data.SetFeatureMask0(cft);
	}
	
	cft = (Compost::Feature_Texture *)m_Mask1List.GetItemDataPtr(m_Mask1List.GetCurSel());
	if((int)cft>0)
	{
		feature_data.SetFeatureMask1(cft);
	}
	
	
	if(m_TextureFlipHor)
	{
		feature_data.SetFlipMode(Compost::Feature::Flip_Mode::Texture_Horizontal_Flip);
	}
	else
	{
		feature_data.ClearFlipMode(Compost::Feature::Flip_Mode::Texture_Horizontal_Flip);
	}
	if(m_TextureFlipVert)
	{
		feature_data.SetFlipMode(Compost::Feature::Flip_Mode::Texture_Vertical_Flip);
	}
	else
	{
		feature_data.ClearFlipMode(Compost::Feature::Flip_Mode::Texture_Vertical_Flip);
	}
	if(m_Mask0FlipHor)
	{
		feature_data.SetFlipMode(Compost::Feature::Flip_Mode::Mask0_Horizontal_Flip);
	}
	else
	{
		feature_data.ClearFlipMode(Compost::Feature::Flip_Mode::Mask0_Horizontal_Flip);
	}
	if(m_Mask0FlipVert)
	{
		feature_data.SetFlipMode(Compost::Feature::Flip_Mode::Mask0_Vertical_Flip);
	}
	else
	{
		feature_data.ClearFlipMode(Compost::Feature::Flip_Mode::Mask0_Vertical_Flip);
	}
	if(m_Mask1FlipHor)
	{
		feature_data.SetFlipMode(Compost::Feature::Flip_Mode::Mask1_Horizontal_Flip);
	}
	else
	{
		feature_data.ClearFlipMode(Compost::Feature::Flip_Mode::Mask1_Horizontal_Flip);
	}
	if(m_Mask1FlipVert)
	{
		feature_data.SetFlipMode(Compost::Feature::Flip_Mode::Mask1_Vertical_Flip);
	}
	else
	{
		feature_data.ClearFlipMode(Compost::Feature::Flip_Mode::Mask1_Vertical_Flip);
	}
	
	switch(m_BlendMode)
	{
	case 0 :feature_data.SetBlendMode(Compost::Feature::Blend_Mode::Paste);			break;
	case 1 :feature_data.SetBlendMode(Compost::Feature::Blend_Mode::Added);		break;
	case 2 :feature_data.SetBlendMode(Compost::Feature::Blend_Mode::Multiply);		break;
	case 3 :feature_data.SetBlendMode(Compost::Feature::Blend_Mode::Blend555_1);	break;
	case 4 :feature_data.SetBlendMode(Compost::Feature::Blend_Mode::Blend555_2);	break;
	case 5 :feature_data.SetBlendMode(Compost::Feature::Blend_Mode::Blend4444);		break;
	case 6 :
	{
		feature_data.SetBlendMode(Compost::Feature::Blend_Mode::StretchMultiply);		
		feature_data.SetFeatureMask0((Compost::Feature_Texture *)m_TextureList.GetItemDataPtr(m_TextureList.GetCurSel()));
	}
	break;
	case 7 :feature_data.SetBlendMode(Compost::Feature::Blend_Mode::Blend555_1_1);	break;
	case 8 :feature_data.SetBlendMode(Compost::Feature::Blend_Mode::Blend555_1_S);	break;
	}
	
	Compost::TexturePool::Instance->Load(feature_data.GetFeatureTexture());
	Compost::TexturePool::Instance->Load(feature_data.GetFeatureMask0());
	Compost::TexturePool::Instance->Load(feature_data.GetFeatureMask1());
	
	feature_data.SetMaterial(m_MatList.GetCurSel());
}

void CFeatureProps::UpdateTexturePane()
{
	FillData();
	
	if(feature_data.GetFeatureTexture()==NULL)	return;
	
	CDC *pDC=GetDC(),memDC;
	
	memDC.CreateCompatibleDC(pDC);
	memDC.SelectObject(&PrvBmp);
	memDC.SetStretchBltMode(COLORONCOLOR);
	
	CString str;
	CString tpath(Compost::TexturePool::Instance->GetTexturePath());
	
	str=(char *)*(((Compost::Feature_Texture *)(m_TextureList.GetItemDataPtr(m_TextureList.GetCurSel())))->GetName());
	str=tpath+"\\"+str+".tga";
	
	BITMAP bmp;
	PrvBmp.GetBitmap(&bmp);
	
	ImageChain *imgchn=CImageCache::Instance->GetChain(str);
	Image *img=imgchn->GetPrvImage();
	if(!img)
	{
		imgchn->BuildPrvImg(bmp.bmWidth+(4-bmp.bmWidth%4),bmp.bmHeight+(4-bmp.bmHeight%4));
		img=imgchn->GetPrvImage();
	}
	
	BITMAPINFO       binf;
	binf.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
	binf.bmiHeader.biWidth=img->GetWidth(); 
	binf.bmiHeader.biHeight=-img->GetHeight();
	binf.bmiHeader.biPlanes=1;
	binf.bmiHeader.biBitCount=img->GetBpp();
	binf.bmiHeader.biCompression=BI_RGB;
	binf.bmiHeader.biSizeImage=0;
	binf.bmiHeader.biClrImportant=0;
	
	SetDIBitsToDevice(memDC,0,0,bmp.bmWidth,
		bmp.bmHeight,0,0,0,img->GetHeight(),img->Lock(),
		&binf,DIB_RGB_COLORS);  
	
	
	img->UnLock();
	memDC.DeleteDC();
	ReleaseDC(pDC);
	
	m_PreviewPane.SetBitmap(PrvBmp);	
}

void CFeatureProps::UpdateMask0Pane()
{
	UpdateData(TRUE);
	if(m_BlendMode==6) return;
	FillData();
	
	if(feature_data.GetFeatureMask0()==NULL)	return;
	
	CDC *pDC=GetDC(),memDC;
	
	memDC.CreateCompatibleDC(pDC);
	memDC.SelectObject(&M0Prv);
	memDC.SetStretchBltMode(COLORONCOLOR);
	BITMAP bmp;
	M0Prv.GetBitmap(&bmp);
	
	CString str;
	CString tpath(Compost::TexturePool::Instance->GetTexturePath());
	
	str=(char *)*(((Compost::Feature_Texture *)(m_Mask0List.GetItemDataPtr(m_Mask0List.GetCurSel())))->GetName());
	str=tpath+"\\"+str+".tga";
	
	
	ImageChain *imgchn=CImageCache::Instance->GetChain(str);
	Image *img=imgchn->GetPrvImage();
	if(!img)
	{
		imgchn->BuildPrvImg(bmp.bmWidth+(4-bmp.bmWidth%4),bmp.bmHeight+(4-bmp.bmHeight%4));
		img=imgchn->GetPrvImage();
	}
	
	BITMAPINFO       binf;
	binf.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
	binf.bmiHeader.biWidth=img->GetWidth(); 
	binf.bmiHeader.biHeight=-img->GetHeight();
	binf.bmiHeader.biPlanes=1;
	binf.bmiHeader.biBitCount=img->GetBpp();
	binf.bmiHeader.biCompression=BI_RGB;
	binf.bmiHeader.biSizeImage=0;
	binf.bmiHeader.biClrImportant=0;
	
	SetDIBitsToDevice(memDC,0,0,bmp.bmWidth,
		bmp.bmHeight,0,0,0,img->GetHeight(),img->Lock(),
		&binf,DIB_RGB_COLORS);  
	
	
	img->UnLock();
	memDC.DeleteDC();
	ReleaseDC(pDC);
	
	m_Mask0PreviewPane.SetBitmap(M0Prv);
}

void CFeatureProps::UpdateMask1Pane()
{
	FillData();
	
	if(feature_data.GetFeatureMask1()==NULL)	return;
	
	CDC *pDC=GetDC(),memDC;
	
	memDC.CreateCompatibleDC(pDC);
	memDC.SelectObject(&M1Prv);
	memDC.SetStretchBltMode(COLORONCOLOR);
	BITMAP bmp;
	M1Prv.GetBitmap(&bmp);
	
	CString str;
	CString tpath(Compost::TexturePool::Instance->GetTexturePath());
	
	str=(char *)*(((Compost::Feature_Texture *)(m_Mask1List.GetItemDataPtr(m_Mask1List.GetCurSel())))->GetName());
	str=tpath+"\\"+str+".tga";
	
	
	ImageChain *imgchn=CImageCache::Instance->GetChain(str);
	Image *img=imgchn->GetPrvImage();
	if(!img)
	{
		imgchn->BuildPrvImg(bmp.bmWidth+(4-bmp.bmWidth%4),bmp.bmHeight+(4-bmp.bmHeight%4));
		img=imgchn->GetPrvImage();
	}
	
	BITMAPINFO       binf;
	binf.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
	binf.bmiHeader.biWidth=img->GetWidth(); 
	binf.bmiHeader.biHeight=-img->GetHeight();
	binf.bmiHeader.biPlanes=1;
	binf.bmiHeader.biBitCount=img->GetBpp();
	binf.bmiHeader.biCompression=BI_RGB;
	binf.bmiHeader.biSizeImage=0;
	binf.bmiHeader.biClrImportant=0;
	
	SetDIBitsToDevice(memDC,0,0,bmp.bmWidth,
		bmp.bmHeight,0,0,0,img->GetHeight(),img->Lock(),
		&binf,DIB_RGB_COLORS);  
	
	
	img->UnLock();
	memDC.DeleteDC();
	ReleaseDC(pDC);
	
	m_Mask1PreviewPane.SetBitmap(M1Prv);
}



void CFeatureProps::OnSelchangeBlendmode() 
{
	UpdateData(TRUE);
	switch(m_BlendMode)
	{
	case 0: 
		m_Mask0List.EnableWindow(FALSE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case 1: 
		m_Mask0List.EnableWindow(FALSE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case 2: 
		m_Mask0List.EnableWindow(FALSE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case 3: 
		m_Mask0List.EnableWindow(TRUE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case 4: 
		m_Mask0List.EnableWindow(TRUE);
		m_Mask1List.EnableWindow(TRUE);
		break;
	case 5: 
		m_Mask0List.EnableWindow(FALSE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case 6: 
		m_Mask0List.EnableWindow(FALSE);
		m_Mask1List.EnableWindow(FALSE);
		break;
	case 7: 
		m_Mask0List.EnableWindow(TRUE);
		m_Mask1List.EnableWindow(FALSE);
		
		m_Mask0List.ResetContent();
		
		Compost::Feature_Texture *FTexture;
		Stuff::TableIteratorOf<Compost::Feature_Texture*, int> imageTableIterator(Compost::TexturePool::Instance->GetImageTable());
		
		int sel,i;
		int idx;
		while(NULL!=(FTexture=imageTableIterator.ReadAndNext()))
		{
			if(FTexture->depth==1)
			{
				idx=m_Mask0List.AddString((char *)(*(FTexture->GetName())));
				m_Mask0List.SetItemDataPtr(idx,FTexture);
			}		
		}
		
		m_Mask0List.InsertString(0,"none");
		
		sel=0;
		for(i=0;i<m_Mask0List.GetCount();i++)
		{
			FTexture=(Compost::Feature_Texture *)m_Mask0List.GetItemDataPtr(i);
			if(FTexture==feature_data.GetFeatureMask0())
				sel=i;
		}
		m_Mask0List.SetCurSel(sel);
		
		break;
	}
	
}

void CFeatureProps::OnStretch() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_wcon.EnableWindow(!m_Stretch);
	m_hcon.EnableWindow(!m_Stretch);
}
