D:/Zythum/DinoKod/MapEditor/BrushView.cpp

00001 // BrushView.cpp : fichier d'implémentation
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "MapEditor.h"
00006 #include "MapEditorDoc.h"
00007 #include "BrushView.h"
00008 #include "GameMapEditor.h"
00009 #include "MapEditorInterface.h"
00010 
00011 #include "LandscapeView.h"
00012 
00013 
00014 // CBrushView
00015 
00016 IMPLEMENT_DYNCREATE(CBrushView, CTreeView)
00017 
00018 CBrushView::CBrushView()
00019 {
00020 }
00021 
00022 CBrushView::~CBrushView()
00023 {
00024 }
00025 
00026 BEGIN_MESSAGE_MAP(CBrushView, CTreeView)
00027         ON_WM_CREATE()
00028 END_MESSAGE_MAP()
00029 
00030 
00031 // Diagnostics CBrushView
00032 
00033 #ifdef _DEBUG
00034 void CBrushView::AssertValid() const
00035 {
00036         CTreeView::AssertValid();
00037 }
00038 
00039 void CBrushView::Dump(CDumpContext& dc) const
00040 {
00041         CTreeView::Dump(dc);
00042 }
00043 #endif //_DEBUG
00044 
00045 
00046 // Gestionnaires de messages CBrushView
00047 int CBrushView::OnCreate(LPCREATESTRUCT lpCreateStruct)
00048 {
00049         if (CView::OnCreate(lpCreateStruct) == -1)
00050                 return -1;
00051 
00052         ((CMapEditorDoc*)m_pDocument)->m_pBrushView = this;
00053 
00054         return 0;
00055 }
00056 
00057 BOOL CBrushView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
00058 {
00059         return CTreeView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
00060 }
00061 
00062 void CBrushView::Refresh()
00063 {
00064         HTREEITEM       hExpandItem = GetTreeCtrl().GetParentItem( GetTreeCtrl().GetSelectedItem() );
00065 
00066         GetTreeCtrl().DeleteAllItems();
00067 
00068         KGameMapEditor*                 pGameMapEditor = ((CMapEditorDoc*)m_pDocument)->m_pLandscapeView->GetpGameMapEditor();
00069         if( !pGameMapEditor )
00070                 return;
00071 
00072         KMapEditorInterface*    pMapEditorInterface = pGameMapEditor->GetInterface();
00073         if( !pMapEditorInterface )
00074                 return;
00075 
00076         KLandModelObject*       pLandModel;
00077         for( pLandModel = pMapEditorInterface->GetFirstLandModel(); pLandModel; pLandModel = pMapEditorInterface->GetNextLandModel( pLandModel ) )
00078         {
00079                 AddLandModel( TVI_ROOT, pLandModel, pLandModel->m_sModelName.GetpString() );
00080                 //GetTreeCtrl().InsertItem( pLandModel->m_sModelName.GetpString(), -1, -1 );
00081         }
00082 }
00083 
00084 void CBrushView::AddLandModelObject( KLandModelObject* pLandModel )
00085 {
00086         AddLandModel( TVI_ROOT, pLandModel, pLandModel->m_sModelName.GetpString() );
00087 }
00088 
00089 void CBrushView::AddLandModel( HTREEITEM hFather, KLandModelObject* pLandModel, const char* pModelName )
00090 {
00091         char    pItemName[256];
00092         u32             i, j;
00093 
00094         // Découpe le nom en morceau
00095         i = 0;
00096         while( ( pModelName[i] == '\\' ) || ( pModelName[i] == '/' ) )
00097         {
00098                 i ++;
00099         }
00100 
00101         if( pModelName[i] == '\0' )
00102                 return;
00103 
00104         j = 0;
00105         for( ; i < 256; i ++ )
00106         {
00107                 if( ( pModelName[i] == '\0' ) || ( pModelName[i] == '\\' ) || ( pModelName[i] == '/' ) )
00108                         break;
00109                 pItemName[j++] = pModelName[i];
00110         }
00111         pItemName[j++] = '\0';
00112 
00113         // Fin ?
00114         if( pModelName[i] == '\0' )
00115         {
00116                 char    pItemText[1024];
00117 
00118                 sprintf( pItemText, "%s ( X:%0.f Y:%.0f Z:%.0f )", pItemName, pLandModel->m_WorldMatrix._41, pLandModel->m_WorldMatrix._42, pLandModel->m_WorldMatrix._43 );
00119                 GetTreeCtrl().InsertItem( pItemText, -1, -1, hFather );
00120                 return;
00121         }
00122 
00123         // Recherche si le nom existe
00124         HTREEITEM       hItem;
00125         for( hItem = GetTreeCtrl().GetChildItem( hFather ); hItem; hItem = GetTreeCtrl().GetNextSiblingItem( hItem ) )
00126         {
00127                 if( GetTreeCtrl().GetItemText( hItem ) == CString( pItemName ) )
00128                 {
00129                         AddLandModel( hItem, pLandModel, &pModelName[i + 1] );
00130                         return;
00131                 }
00132         }
00133 
00134         hItem = GetTreeCtrl().InsertItem( pItemName, -1, -1, hFather );
00135         AddLandModel( hItem, pLandModel, &pModelName[i] );
00136 }
00137 
00138 BOOL CBrushView::PreCreateWindow(CREATESTRUCT& cs)
00139 {
00140         // TODO : ajoutez ici votre code spécialisé et/ou l'appel de la classe de base
00141         cs.style |= TVS_LINESATROOT | TVS_HASBUTTONS | TVS_HASLINES;
00142 
00143         return CTreeView::PreCreateWindow(cs);
00144 }

Generated on Sun Mar 25 20:02:12 2007 for Zythum Project by  doxygen 1.5.1-p1