MainFrm.cpp 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // MainFrm.cpp : implementation of the CMainFrame class
  13. //
  14. #include "stdafx.h"
  15. #include "MainFrm.h"
  16. #include <Engine/Templates/Stock_CTextureData.h>
  17. #include <process.h>
  18. #ifdef _DEBUG
  19. #undef new
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. extern COLOR acol_ColorizePallete[];
  25. FLOAT _fLastNumKeyDownTime=-1;
  26. FLOAT _fLastTimePressureApplied=-1;
  27. #define BRUSH_PRESSURE_DELAY 0.25f
  28. #define BRUSH_PRESSURE_SUB_DELAY 0.5f
  29. #define GET_COLOR_FROM_INI(iColor, strColorIndex) \
  30. {char chrColor[ 16];\
  31. COLOR colResult;\
  32. sprintf( chrColor, "0x%08x", acol_ColorizePallete[iColor]);\
  33. strcpy( chrColor, CStringA(theApp.GetProfileString( L"Custom picker colors", L"Color" strColorIndex, CString(chrColor))));\
  34. sscanf( chrColor, "0x%08x", &colResult);\
  35. acol_ColorizePallete[iColor] = colResult;}
  36. #define SET_COLOR_TO_INI(iColor, strColorIndex) \
  37. {char chrColor[ 16];\
  38. sprintf( chrColor, "0x%08x", acol_ColorizePallete[iColor]);\
  39. theApp.WriteProfileString( L"Custom picker colors", L"Color" strColorIndex, CString(chrColor));}
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CMainFrame
  42. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  43. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  44. ON_COMMAND_EX(ID_VIEW_PROPERTYCOMBO, OnBarCheck)
  45. ON_UPDATE_COMMAND_UI(ID_VIEW_PROPERTYCOMBO, OnUpdateControlBarMenu)
  46. ON_COMMAND_EX(ID_VIEW_BROWSEDIALOGBAR, OnBarCheck)
  47. ON_UPDATE_COMMAND_UI(ID_VIEW_BROWSEDIALOGBAR, OnUpdateControlBarMenu)
  48. //{{AFX_MSG_MAP(CMainFrame)
  49. ON_WM_CREATE()
  50. ON_COMMAND(ID_VIRTUAL_TREE, OnVirtualTree)
  51. ON_WM_CLOSE()
  52. ON_WM_CANCELMODE()
  53. ON_WM_INITMENU()
  54. ON_COMMAND(ID_VIEW_INFOWINDOW, OnViewInfowindow)
  55. ON_UPDATE_COMMAND_UI(ID_VIEW_INFOWINDOW, OnUpdateViewInfowindow)
  56. ON_COMMAND(ID_VIEW_CSGTOOLS, OnViewCsgtools)
  57. ON_UPDATE_COMMAND_UI(ID_VIEW_CSGTOOLS, OnUpdateViewCsgtools)
  58. ON_COMMAND(ID_VIEW_PROJECTIONS_BAR, OnViewProjectionsBar)
  59. ON_UPDATE_COMMAND_UI(ID_VIEW_PROJECTIONS_BAR, OnUpdateViewProjectionsBar)
  60. ON_COMMAND(ID_VIEW_WORK_BAR, OnViewWorkBar)
  61. ON_UPDATE_COMMAND_UI(ID_VIEW_WORK_BAR, OnUpdateViewWorkBar)
  62. ON_WM_ACTIVATEAPP()
  63. ON_COMMAND(ID_CREATE_TEXTURE, OnCreateTexture)
  64. ON_COMMAND(ID_CALL_MODELER, OnCallModeler)
  65. ON_COMMAND(ID_CALL_TEXMAKER, OnCallTexmaker)
  66. ON_COMMAND(ID_VIEW_SETTINGS_AND_UTILITY_BAR, OnViewSettingsAndUtilityBar)
  67. ON_UPDATE_COMMAND_UI(ID_VIEW_SETTINGS_AND_UTILITY_BAR, OnUpdateViewSettingsAndUtilityBar)
  68. ON_COMMAND(ID_VIEW_SHADOWS_AND_TEXTURE_BAR, OnViewShadowsAndTextureBar)
  69. ON_UPDATE_COMMAND_UI(ID_VIEW_SHADOWS_AND_TEXTURE_BAR, OnUpdateViewShadowsAndTextureBar)
  70. ON_COMMAND(ID_VIEW_SELECT_ENTITY_BAR, OnViewSelectEntityBar)
  71. ON_UPDATE_COMMAND_UI(ID_VIEW_SELECT_ENTITY_BAR, OnUpdateViewSelectEntityBar)
  72. ON_COMMAND(ID_VIEW_VIEW_TOOLS_BAR, OnViewViewToolsBar)
  73. ON_UPDATE_COMMAND_UI(ID_VIEW_VIEW_TOOLS_BAR, OnUpdateViewViewToolsBar)
  74. ON_COMMAND(ID_VIEW_VIEW_TOOLS_BAR2, OnViewViewToolsBar2)
  75. ON_UPDATE_COMMAND_UI(ID_VIEW_VIEW_TOOLS_BAR2, OnUpdateViewViewToolsBar2)
  76. ON_COMMAND(ID_GAME_AUDIO, OnGameAudio)
  77. ON_COMMAND(ID_GAME_VIDEO, OnGameVideo)
  78. ON_COMMAND(ID_GAME_PLAYER, OnGamePlayer)
  79. ON_COMMAND(ID_GAME_SELECT_PLAYER, OnGameSelectPlayer)
  80. ON_COMMAND(ID_SHOW_TREE_SHORTCUTS, OnShowTreeShortcuts)
  81. ON_COMMAND(ID_MENU_SHORTCUT01, OnMenuShortcut01)
  82. ON_COMMAND(ID_MENU_SHORTCUT02, OnMenuShortcut02)
  83. ON_COMMAND(ID_MENU_SHORTCUT03, OnMenuShortcut03)
  84. ON_COMMAND(ID_MENU_SHORTCUT04, OnMenuShortcut04)
  85. ON_COMMAND(ID_MENU_SHORTCUT05, OnMenuShortcut05)
  86. ON_COMMAND(ID_MENU_SHORTCUT06, OnMenuShortcut06)
  87. ON_COMMAND(ID_MENU_SHORTCUT07, OnMenuShortcut07)
  88. ON_COMMAND(ID_MENU_SHORTCUT08, OnMenuShortcut08)
  89. ON_COMMAND(ID_MENU_SHORTCUT09, OnMenuShortcut09)
  90. ON_COMMAND(ID_MENU_SHORTCUT10, OnMenuShortcut10)
  91. ON_COMMAND(ID_STORE_MENU_SHORTCUT01, OnStoreMenuShortcut01)
  92. ON_COMMAND(ID_STORE_MENU_SHORTCUT02, OnStoreMenuShortcut02)
  93. ON_COMMAND(ID_STORE_MENU_SHORTCUT03, OnStoreMenuShortcut03)
  94. ON_COMMAND(ID_STORE_MENU_SHORTCUT04, OnStoreMenuShortcut04)
  95. ON_COMMAND(ID_STORE_MENU_SHORTCUT05, OnStoreMenuShortcut05)
  96. ON_COMMAND(ID_STORE_MENU_SHORTCUT06, OnStoreMenuShortcut06)
  97. ON_COMMAND(ID_STORE_MENU_SHORTCUT07, OnStoreMenuShortcut07)
  98. ON_COMMAND(ID_STORE_MENU_SHORTCUT08, OnStoreMenuShortcut08)
  99. ON_COMMAND(ID_STORE_MENU_SHORTCUT09, OnStoreMenuShortcut09)
  100. ON_COMMAND(ID_STORE_MENU_SHORTCUT10, OnStoreMenuShortcut10)
  101. ON_COMMAND(ID_CONSOLE, OnConsole)
  102. ON_COMMAND(ID_VIEW_MIP_TOOLS_BAR, OnViewMipToolsBar)
  103. ON_UPDATE_COMMAND_UI(ID_VIEW_MIP_TOOLS_BAR, OnUpdateViewMipToolsBar)
  104. ON_COMMAND(ID_TOOL_RECREATE_TEXTURE, OnToolRecreateTexture)
  105. ON_COMMAND(ID_RECREATE_CURRENT_TEXTURE, OnRecreateCurrentTexture)
  106. ON_COMMAND(ID_LIGHT_ANIMATION, OnLightAnimation)
  107. ON_WM_TIMER()
  108. ON_COMMAND(ID_HELP_FINDER, OnHelpFinder)
  109. //}}AFX_MSG_MAP
  110. // Global help commands - modified to use html-help
  111. //ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
  112. //ON_COMMAND(ID_HELP, OnHelpFinder)
  113. ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
  114. END_MESSAGE_MAP()
  115. static UINT indicators[] =
  116. {
  117. ID_SEPARATOR, // status line indicator
  118. ID_SEPARATOR,
  119. ID_SEPARATOR,
  120. ID_SEPARATOR,
  121. ID_SEPARATOR,
  122. };
  123. #define STD_BROWSER_WIDTH 162
  124. #define STD_BROWSER_HEIGHT 400
  125. #define STD_PROPERTYCOMBO_WIDTH 162
  126. #define STD_PROPERTYCOMBO_HEIGHT 144
  127. #define SET_BAR_SIZE( bar, dx, dy) \
  128. bar.m_Size.cx = dx; \
  129. bar.m_Size.cy = dy; \
  130. bar.CalcDynamicLayout(0, LM_HORZDOCK)
  131. #define LOAD_BAR_STATE( WName, HName, bar, dx, dy) \
  132. bar.m_Size.cx = (AfxGetApp()->GetProfileInt(_T("General"),_T(WName),dx)); \
  133. bar.m_Size.cy = (AfxGetApp()->GetProfileInt(_T("General"),_T(HName),dy)); \
  134. bar.CalcDynamicLayout(0, LM_HORZDOCK)
  135. #define SAVE_BAR_STATE( WName, HName, bar) \
  136. AfxGetApp()->WriteProfileInt( _T("General"),_T(WName), bar.m_Size.cx); \
  137. AfxGetApp()->WriteProfileInt( _T("General"),_T(HName), bar.m_Size.cy)
  138. // test buffer keys, return pressed buffer number
  139. extern INDEX TestKeyBuffers(void)
  140. {
  141. INDEX iResult = -1;
  142. if( (GetKeyState( '1') & 128) != 0) iResult = 0;
  143. if( (GetKeyState( '2') & 128) != 0) iResult = 1;
  144. if( (GetKeyState( '3') & 128) != 0) iResult = 2;
  145. if( (GetKeyState( '4') & 128) != 0) iResult = 3;
  146. if( (GetKeyState( '5') & 128) != 0) iResult = 4;
  147. if( (GetKeyState( '6') & 128) != 0) iResult = 5;
  148. if( (GetKeyState( '7') & 128) != 0) iResult = 6;
  149. if( (GetKeyState( '8') & 128) != 0) iResult = 7;
  150. if( (GetKeyState( '9') & 128) != 0) iResult = 8;
  151. if( (GetKeyState( '0') & 128) != 0) iResult = 9;
  152. return iResult;
  153. }
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CMainFrame construction/destruction
  156. CMainFrame::CMainFrame()
  157. {
  158. m_pInfoFrame = NULL;
  159. m_pColorPalette = NULL;
  160. m_pwndToolTip = NULL;
  161. }
  162. CMainFrame::~CMainFrame()
  163. {
  164. // info frame window will be destroyed trough auto destroy object mechanism
  165. CWorldEditorApp *pApp = (CWorldEditorApp *)AfxGetApp();
  166. pApp->WriteProfileString(L"World editor", L"Last virtual tree", CString(m_fnLastVirtualTree));
  167. // destroy color palette
  168. if( m_pColorPalette != NULL)
  169. {
  170. delete m_pColorPalette;
  171. m_pColorPalette = NULL;
  172. }
  173. // destroy tool tip
  174. if( m_pwndToolTip != NULL)
  175. {
  176. delete m_pwndToolTip;
  177. m_pwndToolTip = NULL;
  178. }
  179. }
  180. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  181. {
  182. CWorldEditorApp *pApp = (CWorldEditorApp *)AfxGetApp();
  183. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  184. return -1;
  185. // set same styles for use with all toolbars
  186. DWORD dwToolBarStyles = WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
  187. CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_GRIPPER;
  188. CRect rectDummy(0,0,0,0);
  189. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, dwToolBarStyles, rectDummy, IDW_TOOLBAR_MAIN) ||
  190. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  191. {
  192. TRACE0("Failed to create toolbar\n");
  193. return -1; // fail to create
  194. }
  195. if (!m_wndWorkTools.CreateEx(this, TBSTYLE_FLAT, dwToolBarStyles, rectDummy, IDW_TOOLBAR_WORK) ||
  196. !m_wndWorkTools.LoadToolBar(IDR_WORK_TOOLS))
  197. {
  198. TRACE0("Failed to create work toolbar\n");
  199. return -1; // fail to create
  200. }
  201. if (!m_wndStatusBar.Create(this, WS_CHILD|WS_VISIBLE|CBRS_BOTTOM, IDW_STATUSBAR) ||
  202. !m_wndStatusBar.SetIndicators(indicators,
  203. sizeof(indicators)/sizeof(UINT)))
  204. {
  205. TRACE0("Failed to create status bar\n");
  206. return -1; // fail to create
  207. }
  208. // create pane for grid size
  209. UINT nID;
  210. UINT nStyle;
  211. int cxWidth;
  212. m_wndStatusBar.GetPaneInfo( GRID_PANE, nID, nStyle, cxWidth);
  213. cxWidth = 70;
  214. m_wndStatusBar.SetPaneInfo( GRID_PANE, nID, nStyle, cxWidth);
  215. // create pane for mouse coordinate
  216. m_wndStatusBar.GetPaneInfo( POSITION_PANE, nID, nStyle, cxWidth);
  217. cxWidth = 180;
  218. m_wndStatusBar.SetPaneInfo( POSITION_PANE, nID, nStyle, cxWidth);
  219. // create pane for icon telling editing mode
  220. m_wndStatusBar.GetPaneInfo( EDITING_MODE_ICON_PANE, nID, nStyle, cxWidth);
  221. cxWidth = 32;
  222. m_wndStatusBar.SetPaneInfo( EDITING_MODE_ICON_PANE, nID, nStyle, cxWidth);
  223. // create pane for editing mode
  224. m_wndStatusBar.GetPaneInfo( EDITING_MODE_PANE, nID, nStyle, cxWidth);
  225. cxWidth = 90;
  226. m_wndStatusBar.SetPaneInfo( EDITING_MODE_PANE, nID, nStyle, cxWidth);
  227. if (!m_wndCSGTools.CreateEx(this, TBSTYLE_FLAT, dwToolBarStyles, rectDummy, IDW_TOOLBAR_CSG) ||
  228. !m_wndCSGTools.LoadToolBar(IDR_CSG_TOOLS))
  229. {
  230. TRACE0("Failed to create CSG tools toolbar\n");
  231. return -1; // fail to create
  232. }
  233. if (!m_wndMipTools.CreateEx(this, TBSTYLE_FLAT, dwToolBarStyles, rectDummy, IDW_TOOLBAR_MIP) ||
  234. !m_wndMipTools.LoadToolBar(IDR_MIP_TOOLS))
  235. {
  236. TRACE0("Failed to create mip tools toolbar\n");
  237. return -1; // fail to create
  238. }
  239. if (!m_wndProjections.CreateEx(this, TBSTYLE_FLAT, dwToolBarStyles, rectDummy, IDW_TOOLBAR_PROJECTIONS) ||
  240. !m_wndProjections.LoadToolBar(IDR_PROJECTIONS))
  241. {
  242. TRACE0("Failed to create projections toolbar\n");
  243. return -1; // fail to create
  244. }
  245. if (!m_wndSettingsAndUtility.CreateEx(this, TBSTYLE_FLAT, dwToolBarStyles, rectDummy, IDW_TOOLBAR_SETTINGS_AND_UTILITY)
  246. || !m_wndSettingsAndUtility.LoadToolBar(IDR_SETTINGS_AND_UTILITY) )
  247. {
  248. TRACE0("Failed to create settings and utility toolbar\n");
  249. return -1; // fail to create
  250. }
  251. if (!m_wndShadowsAndTexture.CreateEx(this, TBSTYLE_FLAT, dwToolBarStyles, rectDummy, IDW_TOOLBAR_SHADOWS_AND_TEXTURE)
  252. || !m_wndShadowsAndTexture.LoadToolBar(IDR_SHADOWS_AND_TEXTURE) )
  253. {
  254. TRACE0("Failed to create shadow and texture toolbar\n");
  255. return -1;
  256. }
  257. static UINT aidShadowsAndTextureToolBar[5] =
  258. {ID_TEXTURE_1, ID_TEXTURE_2, ID_TEXTURE_3, ID_VIEW_SHADOWS_ONOFF, ID_CALCULATE_SHADOWS_ONOFF};
  259. m_wndShadowsAndTexture.SetButtons( aidShadowsAndTextureToolBar, 5);
  260. if (!m_wndSelectEntity.CreateEx(this, TBSTYLE_FLAT, dwToolBarStyles, rectDummy, IDW_TOOLBAR_SELECT_ENTITY)
  261. || !m_wndSelectEntity.LoadToolBar(IDR_SELECT_ENTITY) )
  262. {
  263. TRACE0("Failed to create select entity toolbar\n");
  264. return -1;
  265. }
  266. if (!m_wndViewTools.CreateEx(this, TBSTYLE_FLAT, dwToolBarStyles, rectDummy, IDW_TOOLBAR_VIEW_TOOLS)
  267. || !m_wndViewTools.LoadToolBar(IDR_VIEW_TOOLS) )
  268. {
  269. TRACE0("Failed to create view tools toolbar\n");
  270. return -1; // fail to create
  271. }
  272. if (!m_wndViewTools2.CreateEx(this, TBSTYLE_FLAT, dwToolBarStyles, rectDummy, IDW_TOOLBAR_VIEW_TOOLS2)
  273. || !m_wndViewTools2.LoadToolBar(IDR_VIEW_TOOLS2) )
  274. {
  275. TRACE0("Failed to create view tools 2 toolbar\n");
  276. return -1; // fail to create
  277. }
  278. // set horizontal size to item that will carry CSG destination combo box
  279. m_wndCSGTools.SetButtonInfo(0, ID_CSG_DESTINATION, TBBS_SEPARATOR, 128);
  280. CRect rect;
  281. // get dimensions of item that will carry combo
  282. m_wndCSGTools.GetItemRect(0, &rect);
  283. rect.top = 2;
  284. // set combo's drop down height
  285. rect.bottom = rect.top + 100;
  286. if (!m_CSGDesitnationCombo.Create(
  287. CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL,
  288. rect, &m_wndCSGTools, ID_CSG_DESTINATION))
  289. {
  290. TRACE0("Failed to create CSG destination combo-box\n");
  291. return FALSE;
  292. }
  293. m_CSGDesitnationCombo.SetDroppedWidth( 256);
  294. // set horizontal size to item that will carry triangularisation type combo box
  295. m_wndCSGTools.SetButtonInfo(11, ID_TRIANGULARIZE, TBBS_SEPARATOR, 100);
  296. CRect rectCombo2;
  297. // get dimensions of item that will carry combo
  298. m_wndCSGTools.GetItemRect(11, &rectCombo2);
  299. rectCombo2.top = 2;
  300. // set combo's drop down height
  301. rectCombo2.bottom = rectCombo2.top + 100;
  302. if (!m_TriangularisationCombo.Create(
  303. CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL,
  304. rectCombo2, &m_wndCSGTools, ID_TRIANGULARIZE))
  305. {
  306. TRACE0("Failed to create triangularization type combo-box\n");
  307. return FALSE;
  308. }
  309. // set horizontal size to item that will hold mip switch edit ctrl
  310. m_wndMipTools.SetButtonInfo(2, ID_EDIT_MIP_SWITCH_DISTANCE, TBBS_SEPARATOR, 64);
  311. CRect rectEdit1;
  312. // get dimensions of item that will carry edit ctrl
  313. m_wndMipTools.GetItemRect(2, &rectEdit1);
  314. rectEdit1.top = 2;
  315. rectEdit1.bottom = rectEdit1.top + 18;
  316. if (!m_ctrlEditMipSwitchDistance.Create( WS_VISIBLE|WS_BORDER,
  317. rectEdit1, &m_wndMipTools, ID_EDIT_MIP_SWITCH_DISTANCE) )
  318. {
  319. TRACE0("Failed to create mip switch distance edit control\n");
  320. return FALSE;
  321. }
  322. // Initialize dialog bar m_Browser
  323. if (!m_Browser.Create(this, CG_IDD_BROWSEDIALOGBAR,
  324. CBRS_LEFT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE | CBRS_SIZE_DYNAMIC,
  325. ID_VIEW_BROWSEDIALOGBAR))
  326. {
  327. TRACE0("Failed to create dialog bar m_Browser\n");
  328. return -1; // fail to create
  329. }
  330. // Try to load virtual tree to browser
  331. m_fnLastVirtualTree = CTString( CStringA(pApp->GetProfileString(L"World editor",
  332. L"Last virtual tree", L"VirtualTrees\\BasicVirtualTree.vrt")));
  333. if( m_fnLastVirtualTree != "")
  334. {
  335. try
  336. {
  337. m_Browser.LoadVirtualTree_t( m_fnLastVirtualTree, NULL);
  338. }
  339. catch( char *strError)
  340. {
  341. (void) strError;
  342. CTString strMessage;
  343. strMessage.PrintF("Error reading virtual tree file:\n%s.\n\nSwitching to empty virtual tree.", m_fnLastVirtualTree);
  344. AfxMessageBox( CString(strMessage));
  345. m_Browser.m_VirtualTree.MakeRoot();
  346. m_Browser.OnUpdateVirtualTreeControl();
  347. }
  348. }
  349. // Initialize dialog bar m_PropertyComboBar
  350. if (!m_PropertyComboBar.Create(this, CG_IDD_PROPERTYCOMBO,
  351. CBRS_RIGHT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE | CBRS_SIZE_DYNAMIC,
  352. ID_VIEW_PROPERTYCOMBO))
  353. {
  354. TRACE0("Failed to create dialog bar m_PropertyComboBar\n");
  355. return -1; // fail to create
  356. }
  357. // Initialize windows classic tool bar
  358. m_wndToolBar.SetWindowText(L"File tools");
  359. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  360. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  361. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  362. // Initialize work tool bar
  363. m_wndWorkTools.SetWindowText(L"Work tools");
  364. m_wndWorkTools.SetBarStyle(m_wndWorkTools.GetBarStyle() |
  365. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  366. m_wndWorkTools.EnableDocking(CBRS_ALIGN_ANY);
  367. // Initialize CSG tools tool bar
  368. m_wndCSGTools.SetWindowText(L"CSG tools");
  369. m_wndCSGTools.SetBarStyle(m_wndCSGTools.GetBarStyle() |
  370. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  371. m_wndCSGTools.EnableDocking(CBRS_ALIGN_ANY);
  372. // Initialize mip tools tool bar
  373. m_wndMipTools.SetWindowText(L"Mip tools");
  374. m_wndMipTools.SetBarStyle(m_wndMipTools.GetBarStyle() |
  375. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  376. m_wndMipTools.EnableDocking(CBRS_ALIGN_ANY);
  377. // Initialize projections tools tool bar
  378. m_wndProjections.SetWindowText(L"Projections");
  379. m_wndProjections.SetBarStyle(m_wndProjections.GetBarStyle() |
  380. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  381. m_wndProjections.EnableDocking(CBRS_ALIGN_ANY);
  382. // Initialize setting and utility tools tool bar
  383. m_wndSettingsAndUtility.SetWindowText(L"Settings and utility");
  384. m_wndSettingsAndUtility.SetBarStyle(m_wndSettingsAndUtility.GetBarStyle() |
  385. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  386. m_wndSettingsAndUtility.EnableDocking(CBRS_ALIGN_ANY);
  387. // Initialize shadows and texture tool bar
  388. m_wndShadowsAndTexture.SetWindowText(L"Shadows and texture");
  389. m_wndShadowsAndTexture.SetBarStyle(m_wndShadowsAndTexture.GetBarStyle() |
  390. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  391. m_wndShadowsAndTexture.EnableDocking(CBRS_ALIGN_ANY);
  392. // Initialize select entity tool bar
  393. m_wndSelectEntity.SetWindowText(L"Select entity");
  394. m_wndSelectEntity.SetBarStyle(m_wndSelectEntity.GetBarStyle() |
  395. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  396. m_wndSelectEntity.EnableDocking(CBRS_ALIGN_ANY);
  397. // Initialize view tools tool bar
  398. m_wndViewTools.SetWindowText(L"View tools");
  399. m_wndViewTools.SetBarStyle(m_wndViewTools.GetBarStyle() |
  400. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  401. m_wndViewTools.EnableDocking(CBRS_ALIGN_ANY);
  402. // Initialize view tools tool bar
  403. m_wndViewTools2.SetWindowText(L"View tools 2");
  404. m_wndViewTools2.SetBarStyle(m_wndViewTools2.GetBarStyle() |
  405. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  406. m_wndViewTools2.EnableDocking(CBRS_ALIGN_ANY);
  407. // Initialize browser dialog bar
  408. m_Browser.SetWindowText(L"Browser");
  409. m_Browser.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
  410. // Initialize property dialog bar
  411. m_PropertyComboBar.SetWindowText(L"Entity properties");
  412. m_PropertyComboBar.EnableDocking(CBRS_ALIGN_ANY);
  413. EnableDocking(CBRS_ALIGN_ANY);
  414. // We will set default width and height of browser and property dialog bars
  415. SET_BAR_SIZE(m_Browser, STD_BROWSER_WIDTH, STD_BROWSER_HEIGHT);
  416. SET_BAR_SIZE(m_PropertyComboBar, STD_PROPERTYCOMBO_WIDTH, STD_PROPERTYCOMBO_HEIGHT);
  417. DockControlBar(&m_wndToolBar);
  418. DockControlBar(&m_wndWorkTools);
  419. DockControlBar(&m_wndProjections);
  420. DockControlBar(&m_wndSettingsAndUtility);
  421. DockControlBar(&m_wndShadowsAndTexture);
  422. DockControlBar(&m_wndSelectEntity);
  423. DockControlBar(&m_wndViewTools);
  424. DockControlBar(&m_wndViewTools2);
  425. DockControlBar(&m_wndCSGTools);
  426. DockControlBar(&m_wndMipTools);
  427. // dock browser and properties dialog
  428. DockControlBar(&m_Browser);
  429. DockControlBar(&m_PropertyComboBar);
  430. //DockControlBarRelativeTo(&m_PropertyComboBar, &m_Browser, DOCK_UP);
  431. // We will try to load tool docked and floated positions of all ctrl bars from INI file
  432. LOAD_BAR_STATE("Browser width", "Browser height", m_Browser,
  433. STD_BROWSER_WIDTH, STD_BROWSER_HEIGHT);
  434. LOAD_BAR_STATE("Property width", "Property height", m_PropertyComboBar,
  435. STD_PROPERTYCOMBO_WIDTH, STD_PROPERTYCOMBO_HEIGHT);
  436. // set font for combo and edit boxes
  437. m_CSGDesitnationCombo.SetFont(&theApp.m_Font);
  438. m_TriangularisationCombo.SetFont(&theApp.m_Font);
  439. m_ctrlEditMipSwitchDistance.SetFont(&theApp.m_Font);
  440. LoadBarState(_T("General"));
  441. // load custom picker colors from registry
  442. GET_COLOR_FROM_INI( 0, L"00");
  443. GET_COLOR_FROM_INI( 1, L"01");
  444. GET_COLOR_FROM_INI( 2, L"02");
  445. GET_COLOR_FROM_INI( 3, L"03");
  446. GET_COLOR_FROM_INI( 4, L"04");
  447. GET_COLOR_FROM_INI( 5, L"05");
  448. GET_COLOR_FROM_INI( 6, L"06");
  449. GET_COLOR_FROM_INI( 7, L"07");
  450. GET_COLOR_FROM_INI( 8, L"08");
  451. GET_COLOR_FROM_INI( 9, L"09");
  452. GET_COLOR_FROM_INI(10, L"10");
  453. GET_COLOR_FROM_INI(11, L"11");
  454. GET_COLOR_FROM_INI(12, L"12");
  455. GET_COLOR_FROM_INI(13, L"13");
  456. GET_COLOR_FROM_INI(14, L"14");
  457. GET_COLOR_FROM_INI(15, L"15");
  458. GET_COLOR_FROM_INI(16, L"16");
  459. GET_COLOR_FROM_INI(17, L"17");
  460. GET_COLOR_FROM_INI(18, L"18");
  461. GET_COLOR_FROM_INI(19, L"19");
  462. GET_COLOR_FROM_INI(20, L"20");
  463. GET_COLOR_FROM_INI(21, L"21");
  464. GET_COLOR_FROM_INI(22, L"22");
  465. GET_COLOR_FROM_INI(23, L"23");
  466. GET_COLOR_FROM_INI(24, L"24");
  467. GET_COLOR_FROM_INI(25, L"25");
  468. GET_COLOR_FROM_INI(26, L"26");
  469. GET_COLOR_FROM_INI(27, L"27");
  470. GET_COLOR_FROM_INI(28, L"28");
  471. GET_COLOR_FROM_INI(29, L"29");
  472. GET_COLOR_FROM_INI(30, L"30");
  473. GET_COLOR_FROM_INI(31, L"31");
  474. // set distance for brush vertex selecting
  475. PIX pixResolutionWidth = GetSystemMetrics(SM_CXSCREEN);
  476. _pixDeltaAroundVertex = pixResolutionWidth/128;
  477. return 0;
  478. }
  479. void CMainFrame::DockControlBarRelativeTo(CControlBar* pbarToDock,
  480. CControlBar* pbarRelativeTo,
  481. ULONG ulDockDirection /*= DOCK_RIGHT*/)
  482. {
  483. CRect rectToDock;
  484. CRect rectRelativeTo;
  485. CRect rectResult;
  486. DWORD dw;
  487. UINT n;
  488. // get MFC to adjust the dimensions of all docked ToolBars
  489. // so that GetWindowRect will be accurate
  490. // RecalcLayout();
  491. pbarRelativeTo->GetWindowRect( &rectRelativeTo);
  492. pbarToDock->GetWindowRect( &rectToDock);
  493. PIX pixOffsetX = rectRelativeTo.Width();
  494. PIX pixOffsetY = rectRelativeTo.Height();
  495. rectResult = CRect( rectRelativeTo.left,
  496. 0/*rectRelativeTo.top*/,
  497. rectRelativeTo.left+rectToDock.Width(),
  498. /*rectRelativeTo.top+*/rectToDock.Height() );
  499. switch( ulDockDirection)
  500. {
  501. case DOCK_LEFT:
  502. {
  503. rectResult.OffsetRect( -pixOffsetX, 0);
  504. break;
  505. }
  506. case DOCK_RIGHT:
  507. {
  508. rectResult.OffsetRect( pixOffsetX+20, 0);
  509. break;
  510. }
  511. case DOCK_UP:
  512. {
  513. rectResult.OffsetRect( 0, -pixOffsetY);
  514. break;
  515. }
  516. case DOCK_DOWN:
  517. {
  518. rectResult.OffsetRect( 0, pixOffsetY);
  519. break;
  520. }
  521. }
  522. dw=pbarRelativeTo->GetBarStyle();
  523. n = 0;
  524. n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
  525. n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
  526. n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
  527. n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
  528. // When we take the default parameters on rect, DockControlBar will dock
  529. // each Toolbar on a seperate line. By calculating a rectangle, we in effect
  530. // are simulating a Toolbar being dragged to that location and docked.
  531. DockControlBar( pbarToDock, n, &rectResult);
  532. }
  533. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  534. {
  535. // TODO: Modify the Window class or styles here by modifying
  536. // the CREATESTRUCT cs
  537. cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
  538. | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
  539. return CMDIFrameWnd::PreCreateWindow(cs);
  540. }
  541. /////////////////////////////////////////////////////////////////////////////
  542. // CMainFrame diagnostics
  543. #ifdef _DEBUG
  544. void CMainFrame::AssertValid() const
  545. {
  546. CMDIFrameWnd::AssertValid();
  547. }
  548. void CMainFrame::Dump(CDumpContext& dc) const
  549. {
  550. CMDIFrameWnd::Dump(dc);
  551. }
  552. #endif //_DEBUG
  553. /////////////////////////////////////////////////////////////////////////////
  554. // CMainFrame message handlers
  555. void CMainFrame::OnVirtualTree()
  556. {
  557. if( m_Browser.m_TreeCtrl.m_bIsOpen)
  558. {
  559. m_Browser.m_TreeCtrl.CloseTreeCtrl();
  560. }
  561. else
  562. {
  563. m_Browser.m_TreeCtrl.OpenTreeCtrl();
  564. }
  565. m_Browser.m_TreeCtrl.SetFocus();
  566. }
  567. BOOL CMainFrame::DestroyWindow()
  568. {
  569. m_Browser.CloseSelectedDirectory();
  570. return CMDIFrameWnd::DestroyWindow();
  571. }
  572. void CMainFrame::OnClose()
  573. {
  574. SaveBarState(_T("General"));
  575. SAVE_BAR_STATE("Browser width", "Browser height", m_Browser);
  576. SAVE_BAR_STATE("Property width", "Property height", m_PropertyComboBar);
  577. // save custom picker colors to registry
  578. SET_COLOR_TO_INI( 0, L"00");
  579. SET_COLOR_TO_INI( 1, L"01");
  580. SET_COLOR_TO_INI( 2, L"02");
  581. SET_COLOR_TO_INI( 3, L"03");
  582. SET_COLOR_TO_INI( 4, L"04");
  583. SET_COLOR_TO_INI( 5, L"05");
  584. SET_COLOR_TO_INI( 6, L"06");
  585. SET_COLOR_TO_INI( 7, L"07");
  586. SET_COLOR_TO_INI( 8, L"08");
  587. SET_COLOR_TO_INI( 9, L"09");
  588. SET_COLOR_TO_INI(10, L"10");
  589. SET_COLOR_TO_INI(11, L"11");
  590. SET_COLOR_TO_INI(12, L"12");
  591. SET_COLOR_TO_INI(13, L"13");
  592. SET_COLOR_TO_INI(14, L"14");
  593. SET_COLOR_TO_INI(15, L"15");
  594. SET_COLOR_TO_INI(16, L"16");
  595. SET_COLOR_TO_INI(17, L"17");
  596. SET_COLOR_TO_INI(18, L"18");
  597. SET_COLOR_TO_INI(19, L"19");
  598. SET_COLOR_TO_INI(20, L"20");
  599. SET_COLOR_TO_INI(21, L"21");
  600. SET_COLOR_TO_INI(22, L"22");
  601. SET_COLOR_TO_INI(23, L"23");
  602. SET_COLOR_TO_INI(24, L"24");
  603. SET_COLOR_TO_INI(25, L"25");
  604. SET_COLOR_TO_INI(26, L"26");
  605. SET_COLOR_TO_INI(27, L"27");
  606. SET_COLOR_TO_INI(28, L"28");
  607. SET_COLOR_TO_INI(29, L"29");
  608. SET_COLOR_TO_INI(30, L"30");
  609. SET_COLOR_TO_INI(31, L"31");
  610. CMDIFrameWnd::OnClose();
  611. }
  612. void CMainFrame::OnCancelMode()
  613. {
  614. // switches out of eventual direct screen mode
  615. CWorldEditorView *pwndView = (CWorldEditorView *)GetActiveView();
  616. if (pwndView != NULL) {
  617. // get the MDIChildFrame of active window
  618. CChildFrame *pfrChild = (CChildFrame *)pwndView->GetParentFrame();
  619. ASSERT(pfrChild!=NULL);
  620. }
  621. CMDIFrameWnd::OnCancelMode();
  622. }
  623. void CMainFrame::OnInitMenu(CMenu* pMenu)
  624. {
  625. // switches out of eventual direct screen mode
  626. CWorldEditorView *pwndView = (CWorldEditorView *)GetActiveView();
  627. if (pwndView != NULL) {
  628. // get the MDIChildFrame of active window
  629. CChildFrame *pfrChild = (CChildFrame *)pwndView->GetParentFrame();
  630. ASSERT(pfrChild!=NULL);
  631. }
  632. CMDIFrameWnd::OnInitMenu(pMenu);
  633. }
  634. void CMainFrame::CustomColorPicker( PIX pixX, PIX pixY)
  635. {
  636. // calculate palette window's rectangle
  637. CRect rectWindow;
  638. rectWindow.left = pixX;
  639. rectWindow.top = pixY;
  640. rectWindow.right = rectWindow.left + 100;
  641. rectWindow.bottom = rectWindow.top + 200;
  642. COLOR colIntersectingColor;
  643. // obtain document
  644. CWorldEditorDoc *pDoc = theApp.GetDocument();
  645. // must not be null
  646. if( pDoc == NULL) return;
  647. // if polygon mode
  648. if( pDoc->m_iMode == POLYGON_MODE)
  649. {
  650. // polygon selection must contain selected polygons
  651. ASSERT(pDoc->m_selPolygonSelection.Count() != 0);
  652. // obtain intersecting color
  653. // for each of the selected polygons
  654. FOREACHINDYNAMICCONTAINER(pDoc->m_selPolygonSelection, CBrushPolygon, itbpo)
  655. {
  656. // if this is first polygon in dynamic container
  657. if( pDoc->m_selPolygonSelection.Pointer(0) == itbpo)
  658. {
  659. // it is, get color as one that others will compare with
  660. colIntersectingColor = itbpo->bpo_colColor;
  661. }
  662. else
  663. {
  664. // if selected polygon's color is not same as testing color
  665. if( colIntersectingColor != itbpo->bpo_colColor)
  666. {
  667. // set invalid color
  668. colIntersectingColor = MAX_ULONG;
  669. break;
  670. }
  671. }
  672. }
  673. }
  674. else if( pDoc->m_iMode == SECTOR_MODE)
  675. {
  676. // we must be in sector mode
  677. // sector selection must contain selected sectors
  678. ASSERT(pDoc->m_selSectorSelection.Count() != 0);
  679. // obtain intersecting color
  680. // for each of the selected sectors
  681. FOREACHINDYNAMICCONTAINER(pDoc->m_selSectorSelection, CBrushSector, itbsc)
  682. {
  683. // if this is first sector in dynamic container
  684. if( pDoc->m_selSectorSelection.Pointer(0) == itbsc)
  685. {
  686. // it is, get color as one that others will compare with
  687. colIntersectingColor = itbsc->bsc_colColor;
  688. }
  689. else
  690. {
  691. // if selected sector's color is not same as testing color
  692. if( colIntersectingColor != itbsc->bsc_colColor)
  693. {
  694. // set invalid color
  695. colIntersectingColor = MAX_ULONG;
  696. break;
  697. }
  698. }
  699. }
  700. }
  701. else
  702. {
  703. return;
  704. }
  705. INDEX iSelectedColor = -1;
  706. for( INDEX iColTab = 0; iColTab < 32; iColTab++)
  707. {
  708. if( colIntersectingColor == acol_ColorizePallete[ iColTab])
  709. {
  710. iSelectedColor = iColTab;
  711. break;
  712. }
  713. }
  714. _pcolColorToSet = NULL;
  715. if( m_pColorPalette == NULL)
  716. {
  717. // instantiate new choose color palette window
  718. m_pColorPalette = new CColorPaletteWnd;
  719. // create window
  720. BOOL bResult = m_pColorPalette->CreateEx( WS_EX_TOOLWINDOW,
  721. NULL, L"Palette", WS_CHILD|WS_POPUP|WS_VISIBLE,
  722. rectWindow.left, rectWindow.top, rectWindow.Width(), rectWindow.Height(),
  723. m_hWnd, NULL, NULL);
  724. if( !bResult)
  725. {
  726. AfxMessageBox( L"Error: Failed to create color palette");
  727. return;
  728. }
  729. // initialize canvas for active texture button
  730. _pGfx->CreateWindowCanvas( m_pColorPalette->m_hWnd, &m_pColorPalette->m_pViewPort,
  731. &m_pColorPalette->m_pDrawPort);
  732. }
  733. else
  734. {
  735. m_pColorPalette->ShowWindow(SW_SHOW);
  736. }
  737. m_pColorPalette->m_iSelectedColor = iSelectedColor;
  738. }
  739. BOOL CMainFrame::OnIdle(LONG lCount)
  740. {
  741. // Call OnIdle() for info frame's property sheet
  742. if( m_pInfoFrame != NULL)
  743. {
  744. m_pInfoFrame->m_pInfoSheet->OnIdle( lCount);
  745. }
  746. POSITION pos = theApp.m_pDocTemplate->GetFirstDocPosition();
  747. while (pos!=NULL)
  748. {
  749. CWorldEditorDoc *pDoc = (CWorldEditorDoc *)theApp.m_pDocTemplate->GetNextDoc(pos);
  750. if(pDoc!=NULL)
  751. {
  752. pDoc->OnIdle();
  753. }
  754. }
  755. // call on idle for combo boxes
  756. m_CSGDesitnationCombo.OnIdle( lCount);
  757. m_TriangularisationCombo.OnIdle( lCount);
  758. m_ctrlEditMipSwitchDistance.OnIdle( lCount);
  759. // call on idle for property combo bar
  760. m_PropertyComboBar.OnIdle( lCount);
  761. return TRUE;
  762. }
  763. /*
  764. * toggles info window
  765. */
  766. void CMainFrame::ToggleInfoWindow(void)
  767. {
  768. // toggle info state
  769. OnViewInfowindow();
  770. }
  771. /*
  772. * shows info window
  773. */
  774. void CMainFrame::ShowInfoWindow()
  775. {
  776. // if it doesn't exist or is not visible
  777. if( (m_pInfoFrame == NULL) ||
  778. (!m_pInfoFrame->IsWindowVisible()) )
  779. {
  780. // create it or toggle info state (to visible)
  781. OnViewInfowindow();
  782. }
  783. }
  784. /*
  785. * reset info window pos
  786. */
  787. void CMainFrame::ResetInfoWindowPos()
  788. {
  789. // if it exists and is visible
  790. if( (m_pInfoFrame != NULL) && (m_pInfoFrame->IsWindowVisible()) )
  791. {
  792. PIX pixScrH = ::GetSystemMetrics(SM_CYSCREEN);
  793. // obtain placement of selected entities text ctrl' window
  794. WINDOWPLACEMENT wpl;
  795. m_pInfoFrame->GetWindowPlacement( &wpl);
  796. CRect rect=wpl.rcNormalPosition;
  797. PIX pixw=rect.right-rect.left;
  798. PIX pixh=rect.bottom-rect.top;
  799. rect.left=0;
  800. rect.top=pixScrH-pixh;
  801. rect.right=rect.left+pixw;
  802. rect.bottom=rect.top+pixh;
  803. m_pInfoFrame->MoveWindow( &rect, TRUE);
  804. }
  805. }
  806. /*
  807. * hides info window
  808. */
  809. void CMainFrame::HideInfoWindow()
  810. {
  811. // if it exist and is visible
  812. if( (m_pInfoFrame != NULL) &&
  813. (m_pInfoFrame->IsWindowVisible()) )
  814. {
  815. // toggle info state (to hidden)
  816. OnViewInfowindow();
  817. }
  818. }
  819. void CMainFrame::OnViewInfowindow()
  820. {
  821. // if info doesn't yet exist, create it
  822. if( m_pInfoFrame == NULL)
  823. {
  824. // create frame window for holding sheet object
  825. m_pInfoFrame = new CInfoFrame;
  826. // set initial size of rect window
  827. CRect rectInfoWindow(0, 0, 0, 0);
  828. if( !m_pInfoFrame->Create( NULL, L"Tools info",
  829. MFS_SYNCACTIVE|WS_POPUP|WS_CAPTION|WS_SYSMENU, rectInfoWindow, this))
  830. {
  831. AfxMessageBox(L"Failed to create info frame window m_pInfoFrame");
  832. return;
  833. }
  834. //m_pInfoFrame->DragAcceptFiles();
  835. }
  836. if( m_pInfoFrame->IsWindowVisible() )
  837. {
  838. m_pInfoFrame->ShowWindow(SW_HIDE);
  839. }
  840. else
  841. {
  842. m_pInfoFrame->ShowWindow(SW_SHOW);
  843. m_pInfoFrame->m_pInfoSheet->SetFocus();
  844. }
  845. }
  846. void CMainFrame::OnUpdateViewInfowindow(CCmdUI* pCmdUI)
  847. {
  848. BOOL bInfoVisible = FALSE;
  849. if( m_pInfoFrame != NULL)
  850. {
  851. bInfoVisible = m_pInfoFrame->IsWindowVisible();
  852. }
  853. pCmdUI->SetCheck( bInfoVisible);
  854. }
  855. void CMainFrame::ApplyTreeShortcut( INDEX iVDirBuffer, BOOL bCtrl)
  856. {
  857. // if control key pressed
  858. if( bCtrl)
  859. {
  860. // remember current virtual directory into buffer
  861. INDEX iSubDirsCt;
  862. iSubDirsCt = m_Browser.GetSelectedDirectory( m_Browser.m_astrVTreeBuffer[iVDirBuffer]);
  863. m_Browser.m_aiSubDirectoriesCt[ iVDirBuffer] = iSubDirsCt;
  864. // mark that virtual tree has changed
  865. m_Browser.m_bVirtualTreeChanged = TRUE;
  866. }
  867. else
  868. {
  869. // get current directory
  870. CVirtualTreeNode *pVTN = m_Browser.GetSelectedDirectory();
  871. m_Browser.m_BrowseWindow.CloseDirectory( pVTN);
  872. // try to select directory
  873. INDEX iSubDirsCt;
  874. iSubDirsCt = m_Browser.m_aiSubDirectoriesCt[ iVDirBuffer];
  875. m_Browser.SelectVirtualDirectory( m_Browser.m_astrVTreeBuffer[iVDirBuffer], iSubDirsCt);
  876. // obtain newly selected directory
  877. pVTN = m_Browser.GetSelectedDirectory();
  878. // and open it
  879. m_Browser.m_BrowseWindow.OpenDirectory( pVTN);
  880. }
  881. }
  882. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
  883. {
  884. BOOL bAltPressed = (GetKeyState( VK_MENU)&0x8000) != 0;
  885. // alt is pressed
  886. BOOL bAlt = FALSE;
  887. if(pMsg->message==_uiMessengerMsg)
  888. {
  889. // if one application allready started
  890. HWND hwndMessenger = ::FindWindow(NULL, L"Croteam Messenger");
  891. if(hwndMessenger != NULL)
  892. {
  893. // force messenger to popup
  894. ::PostMessage( hwndMessenger, _uiMessengerForcePopup, 0, 0);
  895. }
  896. }
  897. if( pMsg->message==WM_LBUTTONDOWN)
  898. {
  899. BOOL bHasDocument = FALSE;
  900. POSITION pos = theApp.m_pDocTemplate->GetFirstDocPosition();
  901. while (pos!=NULL) {
  902. CWorldEditorDoc *pdocCurrent = (CWorldEditorDoc *)theApp.m_pDocTemplate->GetNextDoc(pos);
  903. bHasDocument = pdocCurrent!=NULL;
  904. }
  905. BOOL bMainFrameHasFocus = (this == CWnd::GetForegroundWindow());
  906. if( !bHasDocument && bMainFrameHasFocus)
  907. {
  908. static CTimerValue tvLast;
  909. static CPoint ptLast;
  910. CPoint ptNow;
  911. GetCursorPos( &ptNow);
  912. CTimerValue tvNow = _pTimer->GetHighPrecisionTimer();
  913. FLOAT tmDelta = (tvNow-tvLast).GetSeconds();
  914. if( tmDelta<0.5f && abs(ptNow.x-ptLast.x)<5 && abs(ptNow.y-ptLast.y)<5)
  915. {
  916. theApp.OnFileOpen();
  917. }
  918. tvLast=tvNow;
  919. ptLast = ptNow;
  920. }
  921. }
  922. // if we caught alt key message
  923. if( pMsg->message==WM_SYSKEYDOWN)
  924. {
  925. // get key data
  926. int lKeyData = pMsg->lParam;
  927. // test if it is ghost Alt-F4 situation
  928. if( lKeyData & (1L<<29))
  929. {
  930. // Alt key was really pressed
  931. bAlt = TRUE;
  932. }
  933. }
  934. // if we caught key down message or alt key is pressed
  935. if( (pMsg->message==WM_KEYDOWN) || bAlt)
  936. {
  937. int iVirtKey = (int) pMsg->wParam;
  938. int lKeyData = pMsg->lParam;
  939. // get scan code
  940. UWORD uwScanCode = (HIWORD( lKeyData)) & 255;
  941. // if ctrl pressed
  942. BOOL bCtrl = (GetKeyState( VK_CONTROL)&0x8000) != 0;
  943. // if left shift pressed
  944. BOOL bShift = (GetKeyState( VK_SHIFT)&0x8000) != 0;
  945. // if delete pressed
  946. BOOL bDelete = uwScanCode == 0x53;
  947. // if insert pressed
  948. BOOL bInsert = uwScanCode == 0x52;
  949. // if alt+shift+S pressed, we want to engage "Spawn flags" entity property
  950. if( bShift && bAltPressed && (iVirtKey=='S') )
  951. {
  952. CPropertyComboBox *pPropertyCombo = &m_PropertyComboBar.m_PropertyComboBox;
  953. // for all members in properties combo box
  954. for( INDEX iMember = 0; iMember<pPropertyCombo->GetCount(); iMember++)
  955. {
  956. CPropertyID *ppidPropertyID = (CPropertyID *) pPropertyCombo->GetItemData( iMember);
  957. // if this is valid property
  958. if( (ppidPropertyID != NULL) && (ppidPropertyID->pid_strName == "Spawn flags (Alt+Shift+S)") )
  959. {
  960. // select spawn flags
  961. pPropertyCombo->SetCurSel( iMember);
  962. // update property controls (show/hide) depending upon property type
  963. pPropertyCombo->SelectProperty();
  964. }
  965. }
  966. }
  967. // if alt+shift+A pressed, we want to engage "Parent" entity property
  968. if( bShift && bAltPressed && (iVirtKey=='A') )
  969. {
  970. CPropertyComboBox *pPropertyCombo = &m_PropertyComboBar.m_PropertyComboBox;
  971. // for all members in properties combo box
  972. for( INDEX iMember = 0; iMember<pPropertyCombo->GetCount(); iMember++)
  973. {
  974. CPropertyID *ppidPropertyID = (CPropertyID *) pPropertyCombo->GetItemData( iMember);
  975. // if this is valid property
  976. if( (ppidPropertyID != NULL) && (ppidPropertyID->pid_strName == "Parent (Alt+Shift+A)") )
  977. {
  978. // select spawn flags
  979. pPropertyCombo->SetCurSel( iMember);
  980. // update property controls (show/hide) depending upon property type
  981. pPropertyCombo->SelectProperty();
  982. }
  983. }
  984. }
  985. // if shift pressed, we want to engage entity property shortcut
  986. if( bShift && !bAltPressed)
  987. {
  988. CPropertyComboBox *pPropertyCombo = &m_PropertyComboBar.m_PropertyComboBox;
  989. // for all members in properties combo box
  990. for( INDEX iMember = 0; iMember<pPropertyCombo->GetCount(); iMember++)
  991. {
  992. CPropertyID *ppidPropertyID = (CPropertyID *) pPropertyCombo->GetItemData( iMember);
  993. // if this is valid property
  994. if( ppidPropertyID != NULL)
  995. {
  996. // if virtual key-code is same as shortcut for observing property
  997. if( iVirtKey == ppidPropertyID->pid_chrShortcutKey)
  998. {
  999. // select observing entity property
  1000. pPropertyCombo->SetCurSel( iMember);
  1001. // update property controls (show/hide) depending upon property type
  1002. pPropertyCombo->SelectProperty();
  1003. }
  1004. }
  1005. }
  1006. }
  1007. else if( (iVirtKey == 'Q') && !bAltPressed)
  1008. {
  1009. ToggleInfoWindow();
  1010. }
  1011. else
  1012. {
  1013. // remap key ID to number 0-9
  1014. INDEX iNum=-1;
  1015. if( iVirtKey == '0') iNum = 9;
  1016. else iNum = iVirtKey-'1';
  1017. if( (iNum>=0) && (iNum<=9) && !bAlt)
  1018. {
  1019. CWorldEditorDoc *pDoc = theApp.GetDocument();
  1020. if( pDoc != NULL && pDoc->GetEditingMode()==TERRAIN_MODE)
  1021. {
  1022. FLOAT fCurrentTime = _pTimer->GetRealTimeTick();
  1023. if(_fLastNumKeyDownTime==-1)
  1024. {
  1025. _fLastNumKeyDownTime = fCurrentTime;
  1026. return TRUE;
  1027. }
  1028. else if( fCurrentTime-_fLastNumKeyDownTime>BRUSH_PRESSURE_DELAY)
  1029. {
  1030. _fLastNumKeyDownTime = -2;
  1031. ApplyTreeShortcut( iNum, bCtrl);
  1032. return TRUE;
  1033. }
  1034. }
  1035. else
  1036. {
  1037. _fLastNumKeyDownTime = -2;
  1038. ApplyTreeShortcut( iNum, bCtrl);
  1039. return TRUE;
  1040. }
  1041. }
  1042. }
  1043. }
  1044. if( pMsg->message==WM_KEYUP)
  1045. {
  1046. // remap key ID to number 0-9
  1047. INDEX iNum=-1;
  1048. int iVirtKey = (int) pMsg->wParam;
  1049. if( iVirtKey == '0') iNum = 9;
  1050. else iNum = iVirtKey-'1';
  1051. if( (iNum>=0) && (iNum<=9) && !bAlt)
  1052. {
  1053. CWorldEditorDoc *pDoc = theApp.GetDocument();
  1054. if( pDoc != NULL && pDoc->GetEditingMode()==TERRAIN_MODE)
  1055. {
  1056. FLOAT fCurrentTime = _pTimer->GetRealTimeTick();
  1057. if( fCurrentTime-_fLastNumKeyDownTime<BRUSH_PRESSURE_DELAY)
  1058. {
  1059. if( fCurrentTime-_fLastTimePressureApplied<BRUSH_PRESSURE_SUB_DELAY)
  1060. {
  1061. INDEX iTens=floor((theApp.m_fTerrainBrushPressure-1.0f)/1024.0f*10.0f+0.5f);
  1062. if(iNum==9) iNum=-1;
  1063. INDEX iResult=(iTens*10+iNum+1)%100;
  1064. theApp.m_fTerrainBrushPressure=(iResult)/100.0f*1024.0f+1;
  1065. _fLastTimePressureApplied=-1.0f;
  1066. }
  1067. else
  1068. {
  1069. theApp.m_fTerrainBrushPressure=(iNum+1)*10/100.0f*1024.0f+1;
  1070. _fLastTimePressureApplied=fCurrentTime;
  1071. }
  1072. theApp.m_ctTerrainPageCanvas.MarkChanged();
  1073. }
  1074. }
  1075. }
  1076. _fLastNumKeyDownTime = -1;
  1077. }
  1078. return CMDIFrameWnd::PreTranslateMessage(pMsg);
  1079. }
  1080. void CMainFrame::OnViewCsgtools()
  1081. {
  1082. BOOL bVisible = ((m_wndCSGTools.GetStyle() & WS_VISIBLE) != 0);
  1083. ShowControlBar(&m_wndCSGTools, !bVisible, FALSE);
  1084. RecalcLayout();
  1085. }
  1086. void CMainFrame::OnUpdateViewCsgtools(CCmdUI* pCmdUI)
  1087. {
  1088. BOOL bVisible = ((m_wndCSGTools.GetStyle() & WS_VISIBLE) != 0);
  1089. pCmdUI->SetCheck(bVisible);
  1090. }
  1091. void CMainFrame::OnViewProjectionsBar()
  1092. {
  1093. BOOL bVisible = ((m_wndProjections.GetStyle() & WS_VISIBLE) != 0);
  1094. ShowControlBar(&m_wndProjections, !bVisible, FALSE);
  1095. RecalcLayout();
  1096. }
  1097. void CMainFrame::OnUpdateViewProjectionsBar(CCmdUI* pCmdUI)
  1098. {
  1099. BOOL bVisible = ((m_wndProjections.GetStyle() & WS_VISIBLE) != 0);
  1100. pCmdUI->SetCheck(bVisible);
  1101. }
  1102. void CMainFrame::OnViewWorkBar()
  1103. {
  1104. BOOL bVisible = ((m_wndWorkTools.GetStyle() & WS_VISIBLE) != 0);
  1105. ShowControlBar(&m_wndWorkTools, !bVisible, FALSE);
  1106. RecalcLayout();
  1107. }
  1108. void CMainFrame::OnUpdateViewWorkBar(CCmdUI* pCmdUI)
  1109. {
  1110. BOOL bVisible = ((m_wndWorkTools.GetStyle() & WS_VISIBLE) != 0);
  1111. pCmdUI->SetCheck(bVisible);
  1112. }
  1113. void CMainFrame::OnViewMipToolsBar()
  1114. {
  1115. BOOL bVisible = ((m_wndMipTools.GetStyle() & WS_VISIBLE) != 0);
  1116. ShowControlBar(&m_wndMipTools, !bVisible, FALSE);
  1117. RecalcLayout();
  1118. }
  1119. void CMainFrame::OnUpdateViewMipToolsBar(CCmdUI* pCmdUI)
  1120. {
  1121. BOOL bVisible = ((m_wndMipTools.GetStyle() & WS_VISIBLE) != 0);
  1122. pCmdUI->SetCheck(bVisible);
  1123. }
  1124. void CMainFrame::OnActivateApp(BOOL bActive, DWORD hTask)
  1125. {
  1126. CMDIFrameWnd::OnActivateApp(bActive, hTask);
  1127. // if application is activated right now
  1128. if( bActive)
  1129. {
  1130. // show mouse
  1131. while (ShowCursor(TRUE)<0);
  1132. // if browser is valid
  1133. if( ::IsWindow( m_Browser.m_BrowseWindow.m_hWnd))
  1134. {
  1135. // refresh it
  1136. m_Browser.Invalidate( FALSE);
  1137. }
  1138. // and all of the application's documents
  1139. theApp.RefreshAllDocuments();
  1140. }
  1141. }
  1142. void CMainFrame::OnCreateTexture()
  1143. {
  1144. // call create texture dialog
  1145. _EngineGUI.CreateTexture();
  1146. }
  1147. void CMainFrame::StartApplication( CTString strApplicationToRun)
  1148. {
  1149. // setup necessary data for new process
  1150. STARTUPINFOA siStartupInfo;
  1151. siStartupInfo.cb = sizeof( STARTUPINFOA);
  1152. siStartupInfo.lpReserved = NULL;
  1153. siStartupInfo.lpDesktop = NULL;
  1154. siStartupInfo.lpTitle = NULL;
  1155. siStartupInfo.dwFlags = 0;
  1156. siStartupInfo.cbReserved2 = 0;
  1157. siStartupInfo.lpReserved2 = NULL;
  1158. // here we will receive result of process creation
  1159. PROCESS_INFORMATION piProcessInformation;
  1160. // create application name to run
  1161. CTFileName fnApplicationToRun = _fnmApplicationPath + strApplicationToRun;
  1162. // create process for modeler
  1163. BOOL bSuccess = CreateProcessA(
  1164. fnApplicationToRun,
  1165. NULL,
  1166. NULL,
  1167. NULL,
  1168. FALSE,
  1169. CREATE_NEW_CONSOLE|NORMAL_PRIORITY_CLASS,
  1170. NULL,
  1171. NULL,
  1172. &siStartupInfo,
  1173. &piProcessInformation);
  1174. // if process creation was not successful
  1175. if( !bSuccess)
  1176. {
  1177. WarningMessage( "WorldEditor was unable to run \"%s\"", (CTString&)fnApplicationToRun);
  1178. }
  1179. }
  1180. void CMainFrame::OnCallModeler()
  1181. {
  1182. StartApplication( "Modeler.exe");
  1183. }
  1184. void CMainFrame::OnCallTexmaker()
  1185. {
  1186. StartApplication( "TexMaker.exe");
  1187. }
  1188. void CMainFrame::OnViewSettingsAndUtilityBar()
  1189. {
  1190. BOOL bVisible = ((m_wndSettingsAndUtility.GetStyle() & WS_VISIBLE) != 0);
  1191. ShowControlBar(&m_wndSettingsAndUtility, !bVisible, FALSE);
  1192. RecalcLayout();
  1193. }
  1194. void CMainFrame::OnUpdateViewSettingsAndUtilityBar(CCmdUI* pCmdUI)
  1195. {
  1196. BOOL bVisible = ((m_wndSettingsAndUtility.GetStyle() & WS_VISIBLE) != 0);
  1197. pCmdUI->SetCheck(bVisible);
  1198. }
  1199. void CMainFrame::OnViewShadowsAndTextureBar()
  1200. {
  1201. BOOL bVisible = ((m_wndShadowsAndTexture.GetStyle() & WS_VISIBLE) != 0);
  1202. ShowControlBar(&m_wndShadowsAndTexture, !bVisible, FALSE);
  1203. RecalcLayout();
  1204. }
  1205. void CMainFrame::OnUpdateViewShadowsAndTextureBar(CCmdUI* pCmdUI)
  1206. {
  1207. BOOL bVisible = ((m_wndShadowsAndTexture.GetStyle() & WS_VISIBLE) != 0);
  1208. pCmdUI->SetCheck(bVisible);
  1209. }
  1210. void CMainFrame::OnViewSelectEntityBar()
  1211. {
  1212. BOOL bVisible = ((m_wndSelectEntity.GetStyle() & WS_VISIBLE) != 0);
  1213. ShowControlBar(&m_wndSelectEntity, !bVisible, FALSE);
  1214. RecalcLayout();
  1215. }
  1216. void CMainFrame::OnUpdateViewSelectEntityBar(CCmdUI* pCmdUI)
  1217. {
  1218. BOOL bVisible = ((m_wndSelectEntity.GetStyle() & WS_VISIBLE) != 0);
  1219. pCmdUI->SetCheck(bVisible);
  1220. }
  1221. void CMainFrame::OnViewViewToolsBar()
  1222. {
  1223. BOOL bVisible = ((m_wndViewTools.GetStyle() & WS_VISIBLE) != 0);
  1224. ShowControlBar(&m_wndViewTools, !bVisible, FALSE);
  1225. RecalcLayout();
  1226. }
  1227. void CMainFrame::OnUpdateViewViewToolsBar(CCmdUI* pCmdUI)
  1228. {
  1229. BOOL bVisible = ((m_wndViewTools.GetStyle() & WS_VISIBLE) != 0);
  1230. pCmdUI->SetCheck(bVisible);
  1231. }
  1232. void CMainFrame::OnViewViewToolsBar2()
  1233. {
  1234. BOOL bVisible = ((m_wndViewTools2.GetStyle() & WS_VISIBLE) != 0);
  1235. ShowControlBar(&m_wndViewTools2, !bVisible, FALSE);
  1236. RecalcLayout();
  1237. }
  1238. void CMainFrame::OnUpdateViewViewToolsBar2(CCmdUI* pCmdUI)
  1239. {
  1240. BOOL bVisible = ((m_wndViewTools2.GetStyle() & WS_VISIBLE) != 0);
  1241. pCmdUI->SetCheck(bVisible);
  1242. }
  1243. void CMainFrame::OnGameAudio()
  1244. {
  1245. _pGameGUI->OnAudioQuality();
  1246. }
  1247. void CMainFrame::OnGameVideo()
  1248. {
  1249. _pGameGUI->OnVideoQuality();
  1250. }
  1251. void CMainFrame::OnGamePlayer()
  1252. {
  1253. _pGameGUI->OnPlayerSettings();
  1254. }
  1255. void CMainFrame::OnGameSelectPlayer()
  1256. {
  1257. _pGameGUI->OnSelectPlayerAndControls();
  1258. }
  1259. void CMainFrame::OnShowTreeShortcuts()
  1260. {
  1261. CDlgTreeShortcuts dlgTreeShortcuts;
  1262. dlgTreeShortcuts.DoModal();
  1263. _fLastNumKeyDownTime = -1;
  1264. BOOL bCtrl = (GetKeyState( VK_CONTROL)&0x8000) != 0;
  1265. if( dlgTreeShortcuts.m_iPressedShortcut != -1)
  1266. {
  1267. ApplyTreeShortcut( dlgTreeShortcuts.m_iPressedShortcut, bCtrl);
  1268. }
  1269. }
  1270. #define ON_MENU_SHORTCUT( function, index) \
  1271. void CMainFrame::function() { /*ApplyTreeShortcut( index, FALSE);*/ }
  1272. #define ON_STORE_MENU_SHORTCUT( function, index) \
  1273. void CMainFrame::function() { /*ApplyTreeShortcut( index, TRUE);*/ }
  1274. ON_MENU_SHORTCUT( OnMenuShortcut01, 0);
  1275. ON_STORE_MENU_SHORTCUT( OnStoreMenuShortcut01, 0);
  1276. ON_MENU_SHORTCUT( OnMenuShortcut02, 1);
  1277. ON_STORE_MENU_SHORTCUT( OnStoreMenuShortcut02, 1);
  1278. ON_MENU_SHORTCUT( OnMenuShortcut03, 2);
  1279. ON_STORE_MENU_SHORTCUT( OnStoreMenuShortcut03, 2);
  1280. ON_MENU_SHORTCUT( OnMenuShortcut04, 3);
  1281. ON_STORE_MENU_SHORTCUT( OnStoreMenuShortcut04, 3);
  1282. ON_MENU_SHORTCUT( OnMenuShortcut05, 4);
  1283. ON_STORE_MENU_SHORTCUT( OnStoreMenuShortcut05, 4);
  1284. ON_MENU_SHORTCUT( OnMenuShortcut06, 5);
  1285. ON_STORE_MENU_SHORTCUT( OnStoreMenuShortcut06, 5);
  1286. ON_MENU_SHORTCUT( OnMenuShortcut07, 6);
  1287. ON_STORE_MENU_SHORTCUT( OnStoreMenuShortcut07, 6);
  1288. ON_MENU_SHORTCUT( OnMenuShortcut08, 7);
  1289. ON_STORE_MENU_SHORTCUT( OnStoreMenuShortcut08, 7);
  1290. ON_MENU_SHORTCUT( OnMenuShortcut09, 8);
  1291. ON_STORE_MENU_SHORTCUT( OnStoreMenuShortcut09, 8);
  1292. ON_MENU_SHORTCUT( OnMenuShortcut10, 9);
  1293. ON_STORE_MENU_SHORTCUT( OnStoreMenuShortcut10, 9);
  1294. void CMainFrame::OnConsole()
  1295. {
  1296. _pGameGUI->OnInvokeConsole();
  1297. }
  1298. void CMainFrame::OnToolRecreateTexture()
  1299. {
  1300. CTFileName fnTextureToRecreate = _EngineGUI.BrowseTexture(
  1301. CTString(""), KEY_NAME_CREATE_TEXTURE_DIR, "Browse texture to recreate");
  1302. if( fnTextureToRecreate != "")
  1303. {
  1304. _EngineGUI.CreateTexture( fnTextureToRecreate);
  1305. }
  1306. }
  1307. void CMainFrame::OnRecreateCurrentTexture()
  1308. {
  1309. // there must be valid texture
  1310. if( theApp.m_ptdActiveTexture == NULL) return;
  1311. CTextureData *pTD = theApp.m_ptdActiveTexture;
  1312. CTFileName fnTextureName = pTD->GetName();
  1313. // call recreate texture dialog
  1314. _EngineGUI.CreateTexture( fnTextureName);
  1315. // try to
  1316. CTextureData *ptdTextureToReload;
  1317. try {
  1318. // obtain texture
  1319. ptdTextureToReload = _pTextureStock->Obtain_t( fnTextureName);
  1320. }
  1321. catch ( char *err_str) {
  1322. AfxMessageBox( CString(err_str));
  1323. return;
  1324. }
  1325. // reload the texture
  1326. ptdTextureToReload->Reload();
  1327. // release the texture
  1328. _pTextureStock->Release( ptdTextureToReload);
  1329. // if browser is valid
  1330. if( ::IsWindow( m_Browser.m_BrowseWindow.m_hWnd))
  1331. {
  1332. // refresh it
  1333. m_Browser.m_BrowseWindow.Refresh();
  1334. }
  1335. // obtain document
  1336. CWorldEditorDoc *pDoc = theApp.GetDocument();
  1337. if( pDoc != NULL)
  1338. {
  1339. // and refresh all views
  1340. pDoc->UpdateAllViews( NULL);
  1341. }
  1342. }
  1343. void CMainFrame::OnLightAnimation()
  1344. {
  1345. CDlgLightAnimationEditor dlgEditLightAnimation;
  1346. dlgEditLightAnimation.DoModal();
  1347. }
  1348. // character matrix
  1349. static char achrToolTip[ 256*82+1];
  1350. void CMainFrame::ManualToolTipOn( PIX pixManualX, PIX pixManualY)
  1351. {
  1352. CCustomToolTip &ctt = theApp.m_cttToolTips;
  1353. ctt.cct_pCallback( ctt.cct_pThis, achrToolTip);
  1354. //ASSERT( CTString(achrToolTip) != "");
  1355. if( CTString(achrToolTip) == "") return;
  1356. m_pwndToolTip = new CToolTipWnd;
  1357. m_pwndToolTip->m_strText = achrToolTip;
  1358. m_pwndToolTip->m_bManualControl = TRUE;
  1359. m_pwndToolTip->m_pixManualX = pixManualX;
  1360. m_pwndToolTip->m_pixManualY = pixManualY;
  1361. const wchar_t *strWindowClass = AfxRegisterWndClass( CS_OWNDC|CS_NOCLOSE);
  1362. if( !m_pwndToolTip->CreateEx( WS_EX_TOPMOST, strWindowClass, L"Tool tip",
  1363. WS_BORDER|WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, m_hWnd, 0))
  1364. {
  1365. // program must never reach this point
  1366. ASSERTALWAYS( "World Editor was unable to open tool tip window");
  1367. }
  1368. }
  1369. void CMainFrame::ManualToolTipUpdate( void)
  1370. {
  1371. CCustomToolTip &ctt = theApp.m_cttToolTips;
  1372. ctt.cct_pCallback( ctt.cct_pThis, achrToolTip);
  1373. ASSERT( CTString(achrToolTip) != "");
  1374. if( CTString(achrToolTip) == "") return;
  1375. if( m_pwndToolTip == NULL) return;
  1376. m_pwndToolTip->m_strText = achrToolTip;
  1377. m_pwndToolTip->ManualUpdate();
  1378. }
  1379. void CMainFrame::OnTimer(UINT nIDEvent)
  1380. {
  1381. POINT ptMouse;
  1382. GetCursorPos( &ptMouse);
  1383. HWND hwndUnderMouse = ::WindowFromPoint( ptMouse);
  1384. HWND hwndParent = ::GetParent( hwndUnderMouse);
  1385. CCustomToolTip &ctt = theApp.m_cttToolTips;
  1386. // if tool tip happened
  1387. if( (nIDEvent == 0) && (m_pwndToolTip == NULL) )
  1388. {
  1389. if( hwndParent == ctt.cct_hwndCaller)
  1390. {
  1391. // if game is on, disable tool tips
  1392. if( _pInput->IsInputEnabled()) return;
  1393. ctt.cct_pCallback( ctt.cct_pThis, achrToolTip);
  1394. if( CTString(achrToolTip) == "")
  1395. {
  1396. KillTimer( 0);
  1397. return;
  1398. }
  1399. m_pwndToolTip = new CToolTipWnd;
  1400. m_pwndToolTip->m_strText = achrToolTip;
  1401. m_pwndToolTip->m_bManualControl = FALSE;
  1402. const wchar_t *strWindowClass = AfxRegisterWndClass( CS_OWNDC|CS_NOCLOSE);
  1403. if( !m_pwndToolTip->CreateEx( WS_EX_TOPMOST, strWindowClass, L"Tool tip",
  1404. WS_BORDER|WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, m_hWnd, 0))
  1405. {
  1406. // program must never reach this point
  1407. ASSERTALWAYS( "World Editor was unable to open tool tip window");
  1408. }
  1409. }
  1410. KillTimer( 0);
  1411. }
  1412. CMDIFrameWnd::OnTimer(nIDEvent);
  1413. }
  1414. LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  1415. {
  1416. if( message==WM_SYSCOMMAND)
  1417. {
  1418. switch( wParam & ~0x0F)
  1419. {
  1420. case SC_SCREENSAVE:
  1421. case SC_MONITORPOWER:
  1422. return 0;
  1423. }
  1424. }
  1425. return CMDIFrameWnd::DefWindowProc(message, wParam, lParam);
  1426. }
  1427. void CMainFrame::OnHelpFinder()
  1428. {
  1429. CWorldEditorDoc *pDoc = theApp.GetDocument();
  1430. // must not be null
  1431. if( pDoc != NULL)
  1432. {
  1433. // if entity mode
  1434. if( pDoc->m_iMode == ENTITY_MODE)
  1435. {
  1436. // if only one entity selected
  1437. if( pDoc->m_selEntitySelection.Count() == 1)
  1438. {
  1439. CEntity *pen = pDoc->m_selEntitySelection.GetFirstInSelection();
  1440. CTFileName fnecl = pen->GetClass()->GetName();
  1441. theApp.DisplayHelp(fnecl, HH_DISPLAY_TOPIC, NULL);
  1442. return;
  1443. }
  1444. }
  1445. }
  1446. theApp.DisplayHelp(CTFILENAME("Help\\SeriousEditorDefault.hlk"), HH_DISPLAY_TOPIC, NULL);
  1447. }
  1448. void CMainFrame::SetStatusBarMessage( CTString strMessage, INDEX iPane, FLOAT fTime)
  1449. {
  1450. // obtain stop time
  1451. m_wndStatusBar.SetPaneText( iPane, CString(strMessage), TRUE);
  1452. FLOAT tmNow = _pTimer->GetHighPrecisionTimer().GetSeconds();
  1453. theApp.m_tmStartStatusLineInfo=tmNow + fTime;
  1454. }