// FeatureProps.cpp : implementation file // #include "stdafx.h" #include "ImageGrinder.h" #include "FeatureProps.h" #include "..\..\Libraries\ImageLib\Image.h" #include #include #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 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;i0) { 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 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