123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533 |
- /* Copyright (c) 2002-2012 Croteam Ltd.
- This program is free software; you can redistribute it and/or modify
- it under the terms of version 2 of the GNU General Public License as published by
- the Free Software Foundation
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
- // BrowseWindow.cpp : implementation file
- //
- #include "stdafx.h"
- #include "BrowseWindow.h"
- #include <shlobj.h>
- #include <Engine/Templates/Stock_CTextureData.h>
- #include <Engine/Templates/Stock_CEntityClass.h>
- #ifdef _DEBUG
- #undef new
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- INDEX _iLastHittedItem = -1;
- static CTFileName _fnRightClickedItemFileName;
- static BOOL _bRightClickedIsSelected;
- /////////////////////////////////////////////////////////////////////////////
- // CBrowseWindow
- CBrowseWindow::CBrowseWindow()
- {
- m_pDrawPort = NULL;
- m_pViewPort = NULL;
- m_iLastHittedItem = 0;
- m_bDirectoryOpen = FALSE;
- }
- CBrowseWindow::~CBrowseWindow()
- {
- if( m_pViewPort != NULL)
- {
- _pGfx->DestroyWindowCanvas( m_pViewPort);
- m_pViewPort = NULL;
- }
- }
- BEGIN_MESSAGE_MAP(CBrowseWindow, CWnd)
- //{{AFX_MSG_MAP(CBrowseWindow)
- ON_WM_VSCROLL()
- ON_WM_PAINT()
- ON_WM_DROPFILES()
- ON_WM_SIZE()
- ON_COMMAND(ID_INSERT_ITEMS, OnInsertItems)
- ON_WM_LBUTTONDOWN()
- ON_COMMAND(ID_DELETE_ITEMS, OnDeleteItems)
- ON_COMMAND(ID_BIG_ICONS, OnBigIcons)
- ON_COMMAND(ID_MEDIUM_ICONS, OnMediumIcons)
- ON_COMMAND(ID_SMALL_ICONS, OnSmallIcons)
- ON_COMMAND(ID_SHOW_DESCRIPTION, OnShowDescription)
- ON_COMMAND(ID_SHOW_FILENAME, OnShowFilename)
- ON_WM_LBUTTONDBLCLK()
- ON_COMMAND(ID_RECREATE_TEXTURE, OnRecreateTexture)
- ON_COMMAND(ID_CREATE_AND_ADD_TEXTURE, OnCreateAndAddTexture)
- ON_COMMAND(ID_SELECT_BY_TEXTURE_IN_SELECTED_SECTORS, OnSelectByTextureInSelectedSectors)
- ON_COMMAND(ID_SELECT_BY_TEXTURE_IN_WORLD, OnSelectByTextureInWorld)
- ON_COMMAND(ID_SELECT_FOR_DROP_MARKER, OnSelectForDropMarker)
- ON_COMMAND(ID_SET_AS_CURRENT_TEXTURE, OnSetAsCurrentTexture)
- ON_COMMAND(ID_CONVERT_CLASS, OnConvertClass)
- ON_WM_MOUSEMOVE()
- ON_COMMAND(ID_MICRO_ICONS, OnMicroIcons)
- ON_COMMAND(ID_SELECT_EXCEPT_TEXTURES, OnSelectExceptTextures)
- ON_COMMAND(ID_ADD_TEXTURES_FROM_WORLD, OnAddTexturesFromWorld)
- ON_COMMAND(ID_SHOW_TREE_SHORTCUTS, OnShowTreeShortcuts)
- ON_COMMAND(ID_EXPORT_TEXTURE, OnExportTexture)
- ON_COMMAND(ID_BROWSER_CONTEXT_HELP, OnBrowserContextHelp)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CBrowseWindow message handlers
- BOOL CBrowseWindow::AttachToControl( CWnd *pwndParent)
- {
- BOOL bResult = TRUE;
- bResult = Create( NULL, NULL, WS_BORDER|WS_VISIBLE|WS_VSCROLL, CRect(0,0,10,10),
- pwndParent, IDW_BROWSER);
- if( bResult)
- {
- DragAcceptFiles();
- }
- SetFocus();
- EnableToolTips( TRUE);
- return bResult;
- }
- void CBrowseWindow::SetBrowserPtr( CBrowser *pBrowser)
- {
- m_pBrowser = pBrowser;
- }
- void CBrowseWindow::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- int iPosition = GetScrollPos(SB_VERT);
- int intMin, intMax;
- GetScrollRange( SB_VERT, &intMin, &intMax);
- INDEX iMin = intMin;
- INDEX iMax = intMax;
- switch( nSBCode )
- {
- case SB_THUMBTRACK:
- case SB_THUMBPOSITION:
- {
- SetScrollPos(SB_VERT, nPos);
- break;
- }
- case SB_LINEDOWN:
- {
- iPosition = Clamp( iPosition+m_IconHeight, iMin, iMax);
- SetScrollPos(SB_VERT, iPosition);
- break;
- }
- case SB_PAGEDOWN:
- {
- iPosition = Clamp( iPosition+m_IconsInColumn*m_IconHeight, iMin, iMax);
- SetScrollPos(SB_VERT, iPosition);
- break;
- }
- case SB_LINEUP:
- {
- iPosition = Clamp( iPosition-m_IconHeight, iMin, iMax);
- SetScrollPos(SB_VERT, iPosition);
- break;
- }
- case SB_PAGEUP:
- {
- iPosition = Clamp( iPosition-m_IconsInColumn*m_IconHeight, iMin, iMax);
- SetScrollPos(SB_VERT, iPosition);
- break;
- }
- }
- CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
- Invalidate(FALSE);
- }
- #define BOX( dp, xs, ys, w, h, color, type) \
- dp->DrawLine( xs, ys, xs, ys+h, color, type); \
- dp->DrawLine( xs, ys+h, xs+w, ys+h, color, type); \
- dp->DrawLine( xs+w, ys+h, xs+w, ys, color, type); \
- dp->DrawLine( xs+w, ys, xs, ys, color, type);
- #define ICONS_TRAY_WIDTH 16
- #define ICONS_TRAY_HEIGHT 16
- void CBrowseWindow::OnPaint()
- {
- {
- CPaintDC dc(this); // device context for painting (does BeginPaint()/EndPaint()!)
- }
- CWorldEditorApp *pApp = (CWorldEditorApp *)AfxGetApp();
- PIXaabbox2D rectPict;
- INDEX i;
- if (m_pDrawPort==NULL || !m_pDrawPort->Lock()) {
- return;
- }
- // To write description
- m_pDrawPort->SetFont( theApp.m_pfntSystem);
- m_pDrawPort->SetTextAspect( 1.0f);
-
- // clear browsing window
- m_pDrawPort->FillZBuffer( ZBUF_BACK);
- m_pDrawPort->Fill( C_BLACK | CT_OPAQUE);
-
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- if (pVTNDir==NULL) {
- m_pDrawPort->Unlock();
- return;
- }
-
- if(m_bDirectoryOpen)
- {
- INDEX iYOffset = GetScrollPos( SB_VERT);
- INDEX iLineVisible = iYOffset/m_IconHeight;
- PIX pixStart = iYOffset%m_IconHeight;
- for( i=0; i<m_IconsVisible+m_IconsInLine; i++)
- {
- CVirtualTreeNode *pVTN = GetItem( i + iLineVisible*m_IconsInLine);
- if( pVTN == NULL)
- {
- break;
- }
-
- PIX x = (i%m_IconsInLine) * m_IconWidth;
- PIX y = (i/m_IconsInLine) * m_IconHeight - pixStart + ICONS_TRAY_HEIGHT + 1;
-
- switch( pVTNDir->vtn_bmBrowsingMode)
- {
- case BM_ICONS_MICRO:
- case BM_ICONS_SMALL:
- case BM_ICONS_MEDIUM:
- case BM_ICONS_LARGE:
- {
- PIX pixIconWidth = m_IconWidth;
- PIX pixIconHeight = m_IconHeight;
- // if we are browsing large icons, leave some space for icon text
- if( pVTNDir->vtn_bmBrowsingMode == BM_ICONS_LARGE)
- {
- pixIconHeight -= STRING_HEIGHT;
- }
- // set error texture
- CTextureData *ptdIcon = pApp->m_ptdError;
- if( pVTN->vtn_pTextureData != NULL)
- {
- ptdIcon = pVTN->vtn_pTextureData;
- }
- // get texture width and height
- PIX pixTextureWidth = ptdIcon->GetWidth();
- PIX pixTextureHeight= ptdIcon->GetHeight();
- // apply texture aspect ratio to icon
- if( pixTextureWidth>pixTextureHeight)
- {
- pixIconHeight /= pixTextureWidth/pixTextureHeight;
- }
- else
- {
- pixIconWidth /= pixTextureHeight/pixTextureWidth;
- }
-
- // if we have large icons
- if( pVTNDir->vtn_bmBrowsingMode == BM_ICONS_LARGE)
- {
- // rectangle for texture polygon is smaller because of subtitling info text
- rectPict = PIXaabbox2D(
- PIX2D(x+m_IconWidth/2-pixIconWidth/2+1, y+m_IconHeight/2-pixIconHeight/2+1),
- PIX2D(x+m_IconWidth/2+pixIconWidth/2-2, y+m_IconHeight/2+pixIconHeight/2-2-STRING_HEIGHT));
- }
- else
- {
- // texture box covers maximum space
- rectPict = PIXaabbox2D(
- PIX2D(x+m_IconWidth/2-pixIconWidth/2+1, y+m_IconHeight/2-pixIconHeight/2+1),
- PIX2D(x+m_IconWidth/2+pixIconWidth/2-2, y+m_IconHeight/2+pixIconHeight/2-2));
- }
-
- // draw icon
- CTextureObject toIcon;
- toIcon.SetData( ptdIcon);
- m_pDrawPort->PutTexture( &toIcon, rectPict);
-
- // if we have large icons
- if( pVTNDir->vtn_bmBrowsingMode == BM_ICONS_LARGE)
- {
- // type info text
- if( pVTN->vtn_fnItem.FileExt() == ".tex")
- {
- m_pDrawPort->PutText( pVTN->vtn_fnItem.FileName(), x, y + m_IconHeight-2-STRING_HEIGHT);
- }
- else
- {
- m_pDrawPort->PutText( pVTN->vtn_strName, x, y + m_IconHeight-2-STRING_HEIGHT);
- }
- }
-
- if( pVTN->vtn_bSelected)
- {
- BOX( m_pDrawPort, x, y, m_IconWidth-1, m_IconHeight-1, C_WHITE|CT_OPAQUE, _FULL_);
- BOX( m_pDrawPort, x, y, m_IconWidth-1, m_IconHeight-1, C_lRED|CT_OPAQUE, _POINT_);
- }
- break;
- }
- case BM_DESCRIPTION:
- case BM_FILENAME:
- {
- // First paint little icon
- rectPict = PIXaabbox2D( PIX2D(x, y), PIX2D(x+STRING_HEIGHT, y+STRING_HEIGHT));
- if( pVTN->vtn_pTextureData != NULL)
- {
- CTextureObject toIcon;
- toIcon.SetData( pVTN->vtn_pTextureData);
- m_pDrawPort->PutTexture( &toIcon, rectPict);
- }
- else
- {
- m_pDrawPort->PutTexture( pApp->m_ptoError, rectPict);
- }
- // if we are using descriptive name
- if( pVTNDir->vtn_bmBrowsingMode == BM_DESCRIPTION)
- {
- if( pVTN->vtn_fnItem.FileExt() == ".tex")
- {
- m_pDrawPort->PutText( pVTN->vtn_fnItem.FileName(), x + STRING_HEIGHT, y);
- }
- else
- {
- m_pDrawPort->PutText( pVTN->vtn_strName, x + STRING_HEIGHT, y);
- }
- }
- // if we are using file name
- else
- {
- m_pDrawPort->PutText( pVTN->vtn_fnItem, x + STRING_HEIGHT, y);
- }
-
- if( pVTN->vtn_bSelected)
- {
- BOX( m_pDrawPort, x, y, m_IconWidth-1, m_IconHeight-1, C_WHITE|CT_OPAQUE, _FULL_);
- BOX( m_pDrawPort, x, y, m_IconWidth-1, m_IconHeight-1, C_lRED|CT_OPAQUE, _POINT_);
- }
- break;
- }
- default:
- {
- ASSERTALWAYS( "Unrecognizible browsing type found !");
- }
- }
- }
- }
-
- // draw icons tray
- CTextureObject to;
- to.SetData(theApp.m_ptdIconsTray);
- INDEX iSelected=0;
- switch( pVTNDir->vtn_bmBrowsingMode)
- {
- case BM_ICONS_MICRO: iSelected = 0; break;
- case BM_ICONS_SMALL: iSelected = 1; break;
- case BM_ICONS_MEDIUM: iSelected = 2; break;
- case BM_ICONS_LARGE: iSelected = 3; break;
- case BM_DESCRIPTION: iSelected = 4; break;
- case BM_FILENAME: iSelected = 5; break;
- }
-
- FLOAT fRatio = theApp.m_ptdIconsTray->GetWidth()/theApp.m_ptdIconsTray->GetPixWidth();
- MEX2D mex2dStart = MEX2D(0, MEX(iSelected*16*fRatio));
- MEX2D mex2dEnd = MEX2D(MEX(16*8*fRatio), MEX((iSelected*16+16)*fRatio));
- MEXaabbox2D boxTexture = MEXaabbox2D( mex2dStart, mex2dEnd);
- PIXaabbox2D boxScreen = PIXaabbox2D( PIX2D(0, 0), PIX2D(8*16, 16));
- m_pDrawPort->Fill( 0, 0, m_pDrawPort->GetWidth(), 17, C_BLACK|CT_OPAQUE);
- m_pDrawPort->PutTexture( &to, boxScreen, boxTexture);
-
- m_pDrawPort->Unlock();
- m_pViewPort->SwapBuffers();
- }
- void CBrowseWindow::OnContextMenu( CPoint point)
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- if( pVTNDir == NULL)
- {
- AfxMessageBox( L"Virtual tree doesn't yet exists. Create at least one virtual directory "
- L"to be able to insert items into it.");
- return;
- }
- CWorldEditorDoc *pDoc = theApp.GetDocument();
- // convert coordinates from screen to client
- CPoint ptClientCoordinates = point;
- ScreenToClient( &ptClientCoordinates);
- // Add hit icon to selection
- FLOAT fDummyX, fDummyY;
- INDEX iHittedItem = HitItem( ptClientCoordinates, fDummyX, fDummyY);
- _fnRightClickedItemFileName = CTString("");
- if( iHittedItem != -1)
- {
- CVirtualTreeNode *pVTN = GetItem( iHittedItem);
- ASSERT( pVTN != NULL);
- _fnRightClickedItemFileName = pVTN->vtn_fnItem;
- _bRightClickedIsSelected = pVTN->vtn_bSelected;
- }
- CMenu menu;
- if( menu.LoadMenu(IDR_BROWSERPOPUP))
- {
- CMenu* pPopup = menu.GetSubMenu(0);
- UINT iRecreateTextureCommandState = MF_DISABLED|MF_GRAYED;
- if( _fnRightClickedItemFileName.FileExt()==CTString(".tex") ||
- _fnRightClickedItemFileName.FileExt()==CTString(".tbn") )
- {
- iRecreateTextureCommandState = MF_ENABLED;
- }
- // enable recreate texture and set as current texture commands if texture right-clicked
- pPopup->EnableMenuItem(ID_RECREATE_TEXTURE, iRecreateTextureCommandState);
- pPopup->EnableMenuItem(ID_SET_AS_CURRENT_TEXTURE, iRecreateTextureCommandState);
- pPopup->EnableMenuItem(ID_EXPORT_TEXTURE, iRecreateTextureCommandState);
- UINT iSelectForDropMarkerCommandState = MF_DISABLED|MF_GRAYED;
- if( _fnRightClickedItemFileName.FileExt()==CTString(".ecl"))
- {
- iSelectForDropMarkerCommandState = MF_ENABLED;
- }
- // enable recreate texture command if texture right-clicked
- pPopup->EnableMenuItem(ID_SELECT_FOR_DROP_MARKER, iSelectForDropMarkerCommandState);
- if( pDoc == NULL)
- {
- pPopup->EnableMenuItem(ID_ADD_TEXTURES_FROM_WORLD, MF_DISABLED|MF_GRAYED);
- pPopup->EnableMenuItem(ID_SELECT_EXCEPT_TEXTURES, MF_DISABLED|MF_GRAYED);
- }
- // enable select by texture commands only if texture is right-clicked and document exists
- UINT iSelectByTextureCommandState = MF_DISABLED|MF_GRAYED;
- if( (_fnRightClickedItemFileName.FileExt()==CTString(".tex")) && (pDoc!=NULL))
- {
- iSelectByTextureCommandState = MF_ENABLED;
- }
- UINT iConvertClassCommandState = MF_DISABLED|MF_GRAYED;
- if( (_fnRightClickedItemFileName.FileExt()==CTString(".ecl")) &&
- (pDoc!=NULL) &&
- (pDoc->m_selEntitySelection.Count() != 0) &&
- (pDoc->m_iMode == ENTITY_MODE) )
- {
- iConvertClassCommandState = MF_ENABLED;
- }
- pPopup->EnableMenuItem(ID_SELECT_BY_TEXTURE_IN_SELECTED_SECTORS, iSelectByTextureCommandState);
- pPopup->EnableMenuItem(ID_SELECT_BY_TEXTURE_IN_WORLD, iSelectByTextureCommandState);
- pPopup->EnableMenuItem(ID_CONVERT_CLASS, iConvertClassCommandState);
-
- UINT iClassHelp = MF_DISABLED|MF_GRAYED;
- if( _fnRightClickedItemFileName.FileExt()==CTString(".ecl"))
- {
- iClassHelp = MF_ENABLED;
- }
- pPopup->EnableMenuItem(ID_BROWSER_CONTEXT_HELP, iClassHelp);
- pPopup->TrackPopupMenu(TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_LEFTALIGN,
- point.x, point.y, this);
- }
- }
- INDEX CBrowseWindow::HitItem( CPoint point, FLOAT &fHitXOffset, FLOAT &fHitYOffset) const
- {
- PIXaabbox2D rectItem;
- PIXaabbox2D boxPoint;
- INDEX i;
- INDEX iYOffset = GetScrollPos( SB_VERT);
- INDEX iLineVisible = iYOffset/m_IconHeight;
- PIX pixStart = iYOffset%m_IconHeight;
- for( i=0; i<m_IconsVisible; i++)
- {
- CVirtualTreeNode *pVTN = GetItem( i + iLineVisible*m_IconsInLine);
- if( pVTN == NULL)
- {
- break;
- }
- PIX x = i%m_IconsInLine * m_IconWidth;
- PIX y = i/m_IconsInLine * m_IconHeight - pixStart + ICONS_TRAY_HEIGHT + 1;
- rectItem = PIXaabbox2D( PIX2D(x, y), PIX2D(x+m_IconWidth, y+m_IconHeight));
- boxPoint = PIXaabbox2D( PIX2D(point.x, point.y) );
- if( (rectItem & boxPoint) == boxPoint)
- {
- fHitXOffset = FLOAT((point.x-x))/m_IconWidth;
- fHitYOffset = FLOAT((point.y-y))/m_IconHeight;
- return (i + iLineVisible*m_IconsInLine);
- }
- }
- return -1;
- }
- HGLOBAL CreateHDrop( const CTFileName &fnToDrag, BOOL bAddAppPath/*=TRUE*/)
- {
- CTFileName fnFullToDrag;
- if( bAddAppPath)
- {
- fnFullToDrag = _fnmApplicationPath + fnToDrag;
- }
- else
- {
- fnFullToDrag = fnToDrag;
- }
- HGLOBAL hGlobal;
- // allocate space for DROPFILE structure plus the number of file and one extra byte for final NULL terminator
- hGlobal = GlobalAlloc(GHND|GMEM_SHARE,(DWORD) (sizeof(DROPFILES)+strlen(fnFullToDrag)+2));
- if(hGlobal == NULL)
- return hGlobal;
- LPDROPFILES pDropFiles;
- char *pchDropFileName;
- pDropFiles = (LPDROPFILES)GlobalLock(hGlobal);
- pchDropFileName = ((char *)pDropFiles)+sizeof(DROPFILES);
- // set the offset where the starting point of the file start
- pDropFiles->pFiles = sizeof(DROPFILES);
- // filename does not contain wide characters
- pDropFiles->fWide = FALSE;
- // we want drop point's coordinates in client area
- pDropFiles->fNC = FALSE;
- strcpy(pchDropFileName, (const char *)fnFullToDrag);
- // final null terminator as per CF_HDROP Format specs.
- pchDropFileName[strlen(pchDropFileName)+1]=0;
- GlobalUnlock(hGlobal);
- return hGlobal;
- }
- void CBrowseWindow::OnLButtonDown(UINT nFlags, CPoint point)
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- if( pVTNDir == NULL) return;
- // if we hitted icons tray
- if( (point.x < ICONS_TRAY_WIDTH*6) && (point.y < (ICONS_TRAY_HEIGHT + 1)) )
- {
- INDEX iSelected = point.x/ICONS_TRAY_WIDTH;
- switch( iSelected)
- {
- case 0: pVTNDir->vtn_bmBrowsingMode = BM_ICONS_MICRO; break;
- case 1: pVTNDir->vtn_bmBrowsingMode = BM_ICONS_SMALL; break;
- case 2: pVTNDir->vtn_bmBrowsingMode = BM_ICONS_MEDIUM; break;
- case 3: pVTNDir->vtn_bmBrowsingMode = BM_ICONS_LARGE; break;
- case 4: pVTNDir->vtn_bmBrowsingMode = BM_DESCRIPTION; break;
- case 5: pVTNDir->vtn_bmBrowsingMode = BM_FILENAME; break;
- }
- Refresh();
- return;
- }
- // toggle hitted icon selection status
- FLOAT fDummyX, fDummyY;
- INDEX iHittedItem = HitItem( point, fDummyX, fDummyY);
- if( iHittedItem == -1) return;
- BOOL bShift = (nFlags & MK_SHIFT);
- BOOL bCtrl = (nFlags & MK_CONTROL);
- if( !bCtrl)
- {
- FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- it->vtn_bSelected = FALSE;
- }
- }
- INDEX ctItems = 0;
- {FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- if( !it->vtn_bIsDirectory) ctItems++;
- }}
- INDEX iMin = iHittedItem;
- INDEX iMax = iHittedItem;
- if( bShift)
- {
- iMin = ClampDn( Min( m_iLastHittedItem, iHittedItem), (INDEX)0);
- iMax = ClampUp( Max( m_iLastHittedItem, iHittedItem), ctItems);
- }
- INDEX iCurrent = 0;
- FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- CVirtualTreeNode &vtn = *it;
- if( !vtn.vtn_bIsDirectory)
- {
- if( (iCurrent >= iMin) && (iCurrent <= iMax) )
- {
- if( bCtrl&&!bShift)
- {
- vtn.vtn_bSelected = !vtn.vtn_bSelected;
- }
- else
- {
- vtn.vtn_bSelected = TRUE;
- }
- }
- iCurrent++;
- }
- }
- if( !bShift) m_iLastHittedItem = iHittedItem;
- CVirtualTreeNode *pVTNHit = GetItem( iHittedItem);
- HGLOBAL hglobal = CreateHDrop( pVTNHit->vtn_fnItem);
- m_DataSource.CacheGlobalData( CF_HDROP, hglobal);
- m_DataSource.DoDragDrop( DROPEFFECT_COPY);
- Invalidate( FALSE);
- }
- void CBrowseWindow::OnDropFiles(HDROP hDropInfo)
- {
- CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
- INDEX iNoOfFiles = DragQueryFile( hDropInfo, 0xFFFFFFFF, NULL, 0);
- char chrFile[ 256];
- // get dropped coordinates
- CPoint point;
- DragQueryPoint( hDropInfo, &point);
- CVirtualTreeNode *pVTN = m_pBrowser->GetSelectedDirectory();
- if( pVTN != NULL)
- {
- CloseDirectory( pVTN);
- for( INDEX i=0; i<iNoOfFiles; i++)
- {
- DragQueryFileA( hDropInfo, i, chrFile, 256);
- CTFileName fnDroped = CTString(chrFile);
- if( fnDroped != CTString("") )
- {
- try
- {
- fnDroped.RemoveApplicationPath_t();
- InsertItem( fnDroped, point);
- }
- catch( char *err_str)
- {
- AfxMessageBox( CString(err_str));
- }
- }
- }
- OpenDirectory( pVTN);
- }
- else
- {
- AfxMessageBox( L"ERROR: Virtual tree doesn't exist.");
- }
- CWnd::OnDropFiles(hDropInfo);
- }
- CVirtualTreeNode *CBrowseWindow::GetItem( INDEX iItem) const
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- if( pVTNDir == NULL)
- {
- return NULL;
- }
- INDEX ct=0;
- FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- //
- if( !it->vtn_bIsDirectory)
- {
- if( ct == iItem)
- {
- return( &it.Current());
- }
- ct++;
- }
- }
- return NULL;
- }
- INDEX CBrowseWindow::GetItemNo( CVirtualTreeNode *pVTN)
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- if( pVTNDir == NULL)
- {
- return -1;
- }
- if( pVTNDir->vtn_lhChildren.IsEmpty())
- {
- return -1;
- }
- INDEX ct=0;
- FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- if( !it->vtn_bIsDirectory)
- {
- if( &it.Current() == pVTN)
- {
- return( ct);
- }
- ct++;
- }
- }
- return -1;
- }
- void CBrowseWindow::InsertItem( CTFileName fnItem, CPoint pt)
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- if( pVTNDir == NULL)
- {
- return;
- }
- FLOAT fHitXRatio;
- FLOAT fHitYRatio;
- INDEX iHittedItem = HitItem( pt, fHitXRatio, fHitYRatio);
- CVirtualTreeNode *pVTNHit = NULL;
- if( iHittedItem != -1)
- {
- pVTNHit = GetItem( iHittedItem);
- }
- CVirtualTreeNode *pvtnToRemove = NULL;
- // check for all items in current virtual tree directory
- FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- // if it isn't directory means that it is item
- if( !it->vtn_bIsDirectory)
- {
- // don't allow inserting same item twice
- if( it->vtn_fnItem == fnItem)
- {
- if( pt.x == -1) return;
- pvtnToRemove = &it.Current();
- }
- }
- }
- if( (pVTNHit == pvtnToRemove) && (pVTNHit != NULL) ) return;
- if( pvtnToRemove != NULL)
- {
- pvtnToRemove->vtn_lnInDirectory.Remove();
- if( pvtnToRemove->vtn_pTextureData != NULL)
- {
- _pTextureStock->Release( pvtnToRemove->vtn_pTextureData);
- }
- delete pvtnToRemove;
- }
- // if item is texture
- if( fnItem.FileExt() == ".tex")
- {
- CTextureData *ptdTexture;
- // try to
- try
- {
- // obtain texture
- ptdTexture = _pTextureStock->Obtain_t( fnItem);
- }
- // catch and
- catch( char *err_str)
- {
- // report errors
- AfxMessageBox( CString(err_str));
- return;
- }
- // now it must be valid
- ASSERT( ptdTexture != NULL);
- // get texture dimensions
- MEX mexWidth = ptdTexture->GetWidth();
- MEX mexHeight = ptdTexture->GetHeight();
- // release texture, we don't need it any more
- _pTextureStock->Release( ptdTexture);
- // mark both dimensions as incorrect
- BOOL bWidthOk = FALSE;
- BOOL bHeightOk = FALSE;
- // see if both width and height are potentions of 2
- for( INDEX i=0; i<32; i++)
- {
- // check width, mark if correct
- if( (1L << i) == mexWidth) bWidthOk = TRUE;
- if( (1L << i) == mexHeight) bHeightOk = TRUE;
- }
- // if width or height are not potentios of 2
- if( !bWidthOk || !bHeightOk)
- {
- char err_str[ 256];
- sprintf( err_str, "Dropped texture \"%s\" has incorrect dimensions %.2f x %.2f."
- "All textures must have dimensions that are potentions of 2.",
- (CTString&)fnItem, METERS_MEX( mexWidth), METERS_MEX( mexHeight));
- AfxMessageBox( CString(err_str));
- return;
- }
- }
- else if( fnItem.FileExt() == ".ecl")
- {
- // obtain class
- CEntityClass *pec = _pEntityClassStock->Obtain_t( fnItem);
- // get thumbnail file name from the class
- CTFileName fnThumbnail = CTString(pec->ec_pdecDLLClass->dec_strIconFileName);
- // release class
- _pEntityClassStock->Release( pec);
- // if thumbnail's name is "", don't add this item
- if( fnThumbnail == CTString("") )
- {
- return;
- }
- }
- CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
- CVirtualTreeNode *pVTN = new CVirtualTreeNode;
- pVTN->vtn_fnItem = fnItem;
- pVTN->vtn_bIsDirectory = FALSE;
- pVTN->vtn_strName = fnItem.FileName();
- if( pVTNDir->vtn_lhChildren.Count() == 0)
- {
- pVTN->vtn_bSelected = TRUE;
- }
- if( pt.x == -1)
- {
- pVTNDir->vtn_lhChildren.AddTail( pVTN->vtn_lnInDirectory);
- }
- else
- {
- if( iHittedItem == -1)
- {
- pVTNDir->vtn_lhChildren.AddTail( pVTN->vtn_lnInDirectory);
- }
- else if( ((m_IconsInLine != 1) && (fHitXRatio < 0.5f)) ||
- ((m_IconsInLine == 1) && (fHitYRatio < 0.5f)) )
- {
- ASSERT( pVTNHit != NULL);
- pVTNHit->vtn_lnInDirectory.AddBefore( pVTN->vtn_lnInDirectory);
- }
- else
- {
- ASSERT( pVTNHit != NULL);
- pVTNHit->vtn_lnInDirectory.AddAfter( pVTN->vtn_lnInDirectory);
- }
- }
- m_pBrowser->m_bVirtualTreeChanged = TRUE;
- Invalidate(FALSE);
- }
- void CBrowseWindow::DeleteSelectedItems()
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- if( pVTNDir == NULL)
- {
- return;
- }
- FORDELETELIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- if( !it->vtn_bIsDirectory)
- {
- if( it->vtn_bSelected)
- {
- it->vtn_lnInDirectory.Remove();
- if( it->vtn_pTextureData != NULL)
- {
- _pTextureStock->Release( it->vtn_pTextureData);
- }
- delete &it.Current();
- }
- }
- }
- m_pBrowser->m_bVirtualTreeChanged = TRUE;
- Invalidate(FALSE);
- }
- void CBrowseWindow::Refresh(void)
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- if( (pVTNDir == NULL) || (!m_bDirectoryOpen) )
- {
- return;
- }
- switch( pVTNDir->vtn_bmBrowsingMode)
- {
- case BM_ICONS_MICRO:
- {
- m_IconWidth = 16;
- m_IconHeight = 16;
- break;
- }
- case BM_ICONS_SMALL:
- {
- m_IconWidth = 32;
- m_IconHeight = 32;
- break;
- }
- case BM_ICONS_MEDIUM:
- {
- m_IconWidth = 64;
- m_IconHeight = 64;
- break;
- }
- case BM_ICONS_LARGE:
- {
- m_IconWidth = 128;
- // allow some space for text
- m_IconHeight = 128 + STRING_HEIGHT;
- break;
- }
- case BM_DESCRIPTION:
- case BM_FILENAME:
- {
- m_IconWidth = m_BrowseWndWidth - 8;
- m_IconHeight = STRING_HEIGHT;
- break;
- }
- default:
- {
- ASSERTALWAYS( "Unrecognizible browsing type found !");
- }
- }
- m_IconsInLine = m_BrowseWndWidth/m_IconWidth;
- if( m_IconsInLine == 0)
- {
- m_IconsInLine = 1;
- }
- m_IconsInColumn = m_BrowseWndHeight/m_IconHeight + 1;
- m_IconsVisible = m_IconsInLine * m_IconsInColumn;
- INDEX iItemsCt = -1;
- if( !pVTNDir->vtn_lhChildren.IsEmpty())
- {
- iItemsCt = GetItemNo( LIST_TAIL( pVTNDir->vtn_lhChildren,
- CVirtualTreeNode, vtn_lnInDirectory) );
- }
- INDEX ctLines = iItemsCt/m_IconsInLine;
- SetScrollRange( SB_VERT, 0, ctLines*m_IconHeight);
- Invalidate(FALSE);
- }
- void CBrowseWindow::OpenDirectory( CVirtualTreeNode *pVTNDir)
- {
- CWorldEditorApp *pApp = (CWorldEditorApp *)AfxGetApp();
- CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
- if(m_bDirectoryOpen || pVTNDir==NULL)
- {
- return;
- }
- ASSERT( pVTNDir != NULL);
- // remember name of last opened virtual tree
- theApp.m_strOpenedVTDirectory = theApp.GetNameForVirtualTreeNode( pVTNDir);
- wchar_t achrOpenedDirectoryMessage[ 256];
- swprintf( achrOpenedDirectoryMessage, L"Opened directory: \"%s\"",
- CString(theApp.m_strOpenedVTDirectory));
- // put selected directory name into status line
- pMainFrame->m_wndStatusBar.SetPaneText( STATUS_LINE_PANE, achrOpenedDirectoryMessage, TRUE);
- FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- try
- {
- // if not directory
- if( !it->vtn_bIsDirectory)
- {
- CTFileName fnThumbnail; // thumbnail's file name
- // if texture
- if( it->vtn_fnItem.FileExt() == ".tex")
- {
- // use same texture for thumbnail
- fnThumbnail = it->vtn_fnItem;
- }
- // if world
- else if ( it->vtn_fnItem.FileExt() == ".wld")
- {
- // use file name with extension .tbn for thumbnail
- fnThumbnail = it->vtn_fnItem.FileDir() + it->vtn_fnItem.FileName() + ".tbn";
- // use base name for description
- it->vtn_strName = it->vtn_fnItem.FileName();
- }
- // if class
- else if ( it->vtn_fnItem.FileExt() == ".ecl")
- {
- // obtain class
- CEntityClass *pec = _pEntityClassStock->Obtain_t( it->vtn_fnItem);
- // get thumbnail file name from the class
- fnThumbnail = CTString(pec->ec_pdecDLLClass->dec_strIconFileName);
- // get description name from the class
- it->vtn_strName = pec->ec_pdecDLLClass->dec_strName;
- // release class
- _pEntityClassStock->Release( pec);
- }
- // if unknown extension
- else
- {
- // use no thumbnail
- fnThumbnail = CTString("");
- }
- // if no thumbnail
- if( fnThumbnail == "")
- {
- it->vtn_pTextureData = NULL;
- }
- // if there is valid thumbnail file name
- else
- {
- // obtain thumbnail
- it->vtn_pTextureData = _pTextureStock->Obtain_t( fnThumbnail);
- // must be valid
- ASSERT( it->vtn_pTextureData != NULL);
- // if it is really texture, type full info
- if( it->vtn_fnItem.FileExt() == ".tex")
- {
- // use base name and dimension for desription
- it->vtn_strName = (CTString&)it->vtn_fnItem+" "+it->vtn_pTextureData->GetDescription();
- }
- // else description is just item's file name
- else
- {
- it->vtn_strName = it->vtn_fnItem.FileName();
- }
- }
- }
- }
- catch( char *error)
- {
- // ingnore errors
- (void) error;
- it->vtn_pTextureData = NULL;
- }
- }
- SetScrollPos(SB_VERT, 0);
- m_bDirectoryOpen = TRUE;
- Refresh();
- Invalidate(FALSE);
- }
- void CBrowseWindow::CloseDirectory( CVirtualTreeNode *pVTN)
- {
- if( !m_bDirectoryOpen)
- {
- return;
- }
- ASSERT( pVTN != NULL);
- FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTN->vtn_lhChildren, it)
- {
- if( !it->vtn_bIsDirectory)
- {
- if( it->vtn_pTextureData != NULL)
- {
- _pTextureStock->Release( it->vtn_pTextureData);
- it->vtn_pTextureData = NULL;
- }
- }
- }
- m_bDirectoryOpen = FALSE;
- }
- void CBrowseWindow::OnSize(UINT nType, int cx, int cy)
- {
- CWnd::OnSize(nType, cx, cy);
- // if window canvas is valid
- if( m_pViewPort!=NULL)
- {
- // resize it
- m_pViewPort->Resize();
- Refresh();
- }
- }
- void CBrowseWindow::OnInsertItems()
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- if( pVTNDir == NULL)
- {
- AfxMessageBox( L"ERROR: Virtual tree doesn't exist.");
- return;
- }
- char *pFilters = "Items (*.tex, *.wld, *.ecl)\0*.tex;*.wld;*.ecl\0"
- "World Files (*.wld)\0*.wld\0"
- "Texture files (*.tex)\0*.tex\0"
- "Class files (*.ecl)\0*.ecl\0"
- "All files (*.*)\0*.*\0\0";
- // call file requester for opening textures
- CDynamicArray<CTFileName> afnItems;
- _EngineGUI.FileRequester( "Insert items", pFilters, KEY_NAME_CREATE_TEXTURE_DIR,
- "Textures\\", "", &afnItems);
- if( afnItems.Count() == 0) return;
- // insert items
- FOREACHINDYNAMICARRAY( afnItems, CTFileName, itItem)
- {
- try
- {
- InsertItem( *itItem, CPoint(-1, -1));
- }
- catch( char *err_str)
- {
- AfxMessageBox( CString(err_str));
- }
- }
- CloseDirectory( pVTNDir);
- OpenDirectory( pVTNDir);
- }
- void CBrowseWindow::OnDeleteItems()
- {
- DeleteSelectedItems();
- }
- void CBrowseWindow::OnBigIcons()
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- ASSERT( pVTNDir != NULL);
- pVTNDir->vtn_bmBrowsingMode = BM_ICONS_LARGE;
- Refresh();
- }
- void CBrowseWindow::OnMediumIcons()
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- ASSERT( pVTNDir != NULL);
- pVTNDir->vtn_bmBrowsingMode = BM_ICONS_MEDIUM;
- Refresh();
- }
- void CBrowseWindow::OnMicroIcons()
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- ASSERT( pVTNDir != NULL);
- pVTNDir->vtn_bmBrowsingMode = BM_ICONS_MICRO;
- Refresh();
- }
- void CBrowseWindow::OnSmallIcons()
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- ASSERT( pVTNDir != NULL);
- pVTNDir->vtn_bmBrowsingMode = BM_ICONS_SMALL;
- Refresh();
- }
- void CBrowseWindow::OnShowDescription()
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- ASSERT( pVTNDir != NULL);
- pVTNDir->vtn_bmBrowsingMode = BM_DESCRIPTION;
- Refresh();
- }
- void CBrowseWindow::OnShowFilename()
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- ASSERT( pVTNDir != NULL);
- pVTNDir->vtn_bmBrowsingMode = BM_FILENAME;
- Refresh();
- }
- void CBrowseWindow::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
- // get hitted item's index
- FLOAT fDummyX, fDummyY;
- INDEX iHittedItem = HitItem( point, fDummyX, fDummyY);
- // if hit none reported, return
- if( iHittedItem == -1)
- {
- return;
- }
- // get item object from hitted index
- CVirtualTreeNode *pVTN = GetItem( iHittedItem);
- // must not be null
- ASSERT( pVTN != NULL);
- // get item's file name
- CTFileName fnItem = pVTN->vtn_fnItem;
- // if it is texture
- if( fnItem.FileExt() == ".tex")
- {
- CWorldEditorDoc *pDoc = theApp.GetDocument();
- if(pDoc!=NULL && pDoc->GetEditingMode()==TERRAIN_MODE)
- {
- CTerrainLayer *ptlLayer=GetLayer();
- CTerrain *ptTerrain=GetTerrain();
- if(ptlLayer!=NULL && ptTerrain!=NULL)
- {
- try
- {
- ptlLayer->SetLayerTexture_t(fnItem);
- theApp.m_ctTerrainPageCanvas.MarkChanged();
- ptTerrain->RefreshTerrain();
- }
- catch(char *strError)
- {
- (void) strError;
- }
- }
- }
- else
- {
- // set it as new primitive's material default texture
- theApp.SetNewActiveTexture( _fnmApplicationPath + fnItem);
- // paste new active texture over polygon selection
- theApp.TexturizeSelection();
- }
- }
- // if it is world (template)
- else if( fnItem.FileExt() == ".wld")
- {
- // open document with item's file name
- theApp.m_pDocTemplate->OpenDocumentFile( CString(_fnmApplicationPath + fnItem));
- }
- }
- void CBrowseWindow::OnRecreateTexture()
- {
- if( _bRightClickedIsSelected)
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- ASSERT( pVTNDir != NULL);
- FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- if( it->vtn_bSelected && it->vtn_fnItem.FileExt()==CTString(".tex") )
- {
- _EngineGUI.CreateTexture( it->vtn_fnItem);
- }
- }
- }
- else if( _fnRightClickedItemFileName.FileExt()==CTString(".tex"))
- {
- _EngineGUI.CreateTexture( _fnRightClickedItemFileName);
- }
- Refresh();
- CWorldEditorDoc *pDoc = theApp.GetDocument();
- if( pDoc != NULL) pDoc->UpdateAllViews( NULL);
- }
- void CBrowseWindow::OnSelectByTextureInSelectedSectors()
- {
- SelectByTextures( TRUE, FALSE);
- }
- void CBrowseWindow::OnCreateAndAddTexture()
- {
- CDynamicArray<CTFileName> afnCreatedTextures;
- CTFileName fnCreatedTexture = _EngineGUI.CreateTexture( CTString(""), &afnCreatedTextures);
- if( afnCreatedTextures.Count() != 0)
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- if( pVTNDir != NULL)
- {
- CloseDirectory( pVTNDir);
- }
- // insert created textures
- FOREACHINDYNAMICARRAY( afnCreatedTextures, CTFileName, itTexture)
- {
- CTFileName &fn=*itTexture;
- InsertItem( fn, CPoint(-1, -1));
- }
- if( pVTNDir != NULL)
- {
- OpenDirectory( pVTNDir);
- }
- }
- }
- void CBrowseWindow::OnSelectForDropMarker()
- {
- theApp.m_fnClassForDropMarker = _fnRightClickedItemFileName;
- }
- void CBrowseWindow::OnSetAsCurrentTexture()
- {
- // set it as new primitive's material default texture
- theApp.SetNewActiveTexture( _fnmApplicationPath + _fnRightClickedItemFileName);
- }
- void CBrowseWindow::OnConvertClass()
- {
- if( _fnRightClickedItemFileName.FileExt()!=CTString(".ecl"))
- {
- WarningMessage( "Only classes can be used for converting classe");
- return;
- }
- try
- {
- CWorldEditorDoc *pDoc = theApp.GetDocument();
- FOREACHINDYNAMICCONTAINER(pDoc->m_selEntitySelection, CEntity, iten)
- {
- // create the entity of requested class
- CEntity *penNewClass;
- penNewClass = pDoc->m_woWorld.CreateEntity_t(
- iten->GetPlacement(), _fnRightClickedItemFileName);
- // try to copy entity properties
- CDLLEntityClass *pdecDLLClassNew = penNewClass->GetClass()->ec_pdecDLLClass;
- for(;pdecDLLClassNew!=NULL; pdecDLLClassNew = pdecDLLClassNew->dec_pdecBase)
- {
- for(INDEX iPropertyNew=0; iPropertyNew<pdecDLLClassNew->dec_ctProperties; iPropertyNew++)
- {
- CEntityProperty &epPropertyNew = pdecDLLClassNew->dec_aepProperties[iPropertyNew];
- CDLLEntityClass *pdecDLLClassOld = iten->GetClass()->ec_pdecDLLClass;
- for(;pdecDLLClassOld!=NULL; pdecDLLClassOld = pdecDLLClassOld->dec_pdecBase)
- {
- for(INDEX iPropertyOld=0; iPropertyOld<pdecDLLClassOld->dec_ctProperties; iPropertyOld++)
- {
- CEntityProperty &epPropertyOld = pdecDLLClassOld->dec_aepProperties[iPropertyOld];
- if( (CTString(epPropertyNew.ep_strName) == epPropertyOld.ep_strName) &&
- (epPropertyNew.ep_eptType == epPropertyOld.ep_eptType) )
- {
- penNewClass->CopyOneProperty( epPropertyOld, epPropertyNew, *iten, FALSE);
- }
- }
- }
- }
- }
- // prepare the entity
- penNewClass->Initialize();
- }
- CWorldEditorView *pWorldEditorView = theApp.GetActiveView();
- if( pWorldEditorView != NULL)
- {
- pWorldEditorView->OnDeleteEntities();
- }
- }
- catch( char *err_str)
- {
- AfxMessageBox( CString(err_str));
- }
- }
- static void GetToolTipText(void *pBrowser, char *pToolTipText)
- {
- CBrowseWindow *pBrowseWindow = (CBrowseWindow *) pBrowser;
- pBrowseWindow->GetToolTipText( pToolTipText);
- }
- void CBrowseWindow::GetToolTipText( char *pToolTipText)
- {
- CPoint point;
- ::GetCursorPos(&point);
- ScreenToClient(&point);
- // get hitted item's index
- FLOAT fDummyX, fDummyY;
- INDEX iHittedItem = HitItem( point, fDummyX, fDummyY);
- // if hit none reported, return
- if( iHittedItem == -1)
- {
- strcpy( pToolTipText, "");
- return;
- }
- // get item object from hitted index
- CVirtualTreeNode *pVTN = GetItem( iHittedItem);
- strcpy(pToolTipText, pVTN->vtn_strName);
- }
- void CBrowseWindow::OnMouseMove(UINT nFlags, CPoint point)
- {
- theApp.m_cttToolTips.MouseMoveNotify( m_hWnd, 500, &::GetToolTipText, this);
- CWnd::OnMouseMove(nFlags, point);
- }
- void CBrowseWindow::OnSelectByTextureInWorld()
- {
- SelectByTextures( FALSE, FALSE);
- }
- void CBrowseWindow::OnSelectExceptTextures( void)
- {
- SelectByTextures( FALSE, TRUE);
- }
- void CBrowseWindow::SelectByTextures( BOOL bInSelectedSectors, BOOL bExceptSelected)
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- CWorldEditorDoc *pDoc = theApp.GetDocument();
- if( pDoc == NULL) return;
-
- // for each entity in the world
- FOREACHINDYNAMICCONTAINER(pDoc->m_woWorld.wo_cenEntities, CEntity, iten) {
- // if it is brush entity
- if (iten->en_RenderType == CEntity::RT_BRUSH) {
- // for each mip in its brush
- FOREACHINLIST(CBrushMip, bm_lnInBrush, iten->en_pbrBrush->br_lhBrushMips, itbm) {
- // for all sectors in this mip
- FOREACHINDYNAMICARRAY(itbm->bm_abscSectors, CBrushSector, itbsc) {
- // if sector is selected
- if( !bInSelectedSectors || itbsc->IsSelected(BSCF_SELECTED))
- {
- // for all polygons in sector
- FOREACHINSTATICARRAY(itbsc->bsc_abpoPolygons, CBrushPolygon, itbpo)
- {
- // if it is not non translucent portal and is not selected and has same texture
- if ( /*(!(itbpo->bpo_ulFlags&BPOF_PORTAL) || (itbpo->bpo_ulFlags&BPOF_TRANSLUCENT) ||
- (itbpo->bpo_bppProperties.bpp_uwPretenderDistance!=0) ) &&*/
- !itbpo->IsSelected(BPOF_SELECTED) &&
- (itbpo->bpo_abptTextures[pDoc->m_iTexture].bpt_toTexture.GetData() != NULL) )
- {
- CTFileName fnTexture = itbpo->bpo_abptTextures[pDoc->m_iTexture].bpt_toTexture.GetData()->GetName();
- BOOL bSelect = bExceptSelected;
- FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- if( _bRightClickedIsSelected)
- {
- if(it->vtn_bSelected && it->vtn_fnItem.FileExt()==CTString(".tex") &&
- fnTexture == it->vtn_fnItem)
- {
- bSelect = !bExceptSelected;
- break;
- }
- }
- else if( fnTexture == _fnRightClickedItemFileName)
- {
- bSelect = !bExceptSelected;
- break;
- }
- }
- if( bSelect) pDoc->m_selPolygonSelection.Select(*itbpo);
- }
- }
- }
- }
- }
- }
- }
- pDoc->SetEditingMode( POLYGON_MODE);
- pDoc->m_chSelections.MarkChanged();
- pDoc->UpdateAllViews( NULL);
- }
- void CBrowseWindow::OnAddTexturesFromWorld()
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- CWorldEditorDoc *pDoc = theApp.GetDocument();
- if (pDoc == NULL) return;
-
- CloseDirectory( pVTNDir);
- // for each entity in the world
- FOREACHINDYNAMICCONTAINER(pDoc->m_woWorld.wo_cenEntities, CEntity, iten) {
- // if it is brush entity
- if (iten->en_RenderType == CEntity::RT_BRUSH) {
- // for each mip in its brush
- FOREACHINLIST(CBrushMip, bm_lnInBrush, iten->en_pbrBrush->br_lhBrushMips, itbm) {
- // for all sectors in this mip
- FOREACHINDYNAMICARRAY(itbm->bm_abscSectors, CBrushSector, itbsc) {
- // for all polygons in sector
- FOREACHINSTATICARRAY(itbsc->bsc_abpoPolygons, CBrushPolygon, itbpo)
- {
- try
- {
- CTextureObject &to1 = itbpo->bpo_abptTextures[0].bpt_toTexture;
- if(to1.GetData() != NULL)
- InsertItem( to1.GetData()->GetName(), CPoint(-1, -1));
- CTextureObject &to2 = itbpo->bpo_abptTextures[1].bpt_toTexture;
- if(to2.GetData() != NULL)
- InsertItem( to2.GetData()->GetName(), CPoint(-1, -1));
- CTextureObject &to3 = itbpo->bpo_abptTextures[2].bpt_toTexture;
- if(to3.GetData() != NULL)
- InsertItem( to3.GetData()->GetName(), CPoint(-1, -1));
- }
- catch( char *err_str)
- {
- AfxMessageBox( CString(err_str));
- }
- }
- }
- }
- }
- }
- OpenDirectory( pVTNDir);
- }
- void CBrowseWindow::OnShowTreeShortcuts()
- {
- CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
- pMainFrame->OnShowTreeShortcuts();
- }
- void ExportTexture( CTFileName fnTexture)
- {
- CTextureData *ptd;
- CImageInfo ii;
- try
- {
- ptd = _pTextureStock->Obtain_t( fnTexture);
- for( INDEX iFrame=0; iFrame<ptd->td_ctFrames; iFrame++)
- {
- ptd->Export_t( ii, iFrame);
- // obtain name for export file
- CTFileName fnFrame;
- if( ptd->td_ctFrames == 1)
- {
- fnFrame = fnTexture.NoExt()+".tga";
- }
- else
- {
- fnFrame.PrintF("%s%03d.tga", (const char *)fnTexture.NoExt(), iFrame);
- }
- // if file exists, ask for substitution name
- if( FileExists( fnFrame) && iFrame==0 )
- {
- CTString strDefaultDir = fnFrame.FileDir();
- CTString strDefaultFile = fnFrame.FileName()+fnFrame.FileExt();
- // invoke "Save as" dialog
- fnFrame = _EngineGUI.FileRequester( "Save As", FILTER_TGA FILTER_END,
- "Export texture directory", strDefaultDir, strDefaultFile, NULL, FALSE);
- }
- if( fnFrame != "")
- {
- ii.SaveTGA_t(fnFrame);
- ii.Clear();
- }
- }
- }
- catch( char *strError)
- {
- AfxMessageBox( CString(strError));
- ii.Clear();
- }
- }
- void CBrowseWindow::OnExportTexture()
- {
- if( _bRightClickedIsSelected)
- {
- CVirtualTreeNode *pVTNDir = m_pBrowser->GetSelectedDirectory();
- ASSERT( pVTNDir != NULL);
- FOREACHINLIST( CVirtualTreeNode, vtn_lnInDirectory, pVTNDir->vtn_lhChildren, it)
- {
- if( it->vtn_bSelected && it->vtn_fnItem.FileExt()==CTString(".tex") ||
- it->vtn_bSelected && it->vtn_fnItem.FileExt()==CTString(".tbn") )
- {
- ExportTexture( it->vtn_fnItem);
- }
- }
- }
- else if( _fnRightClickedItemFileName.FileExt()==CTString(".tex") ||
- _fnRightClickedItemFileName.FileExt()==CTString(".tbn") )
- {
- ExportTexture( _fnRightClickedItemFileName);
- }
- }
- void CBrowseWindow::OnBrowserContextHelp()
- {
- if( _fnRightClickedItemFileName.FileExt()==CTString(".ecl"))
- {
- theApp.DisplayHelp(_fnRightClickedItemFileName, HH_DISPLAY_TOPIC, NULL);
- }
- }
|