EditWindow.cpp 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: EditWindow.cpp ///////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: EditWindow.cpp
  36. //
  37. // Created: Colin Day, July 2001
  38. //
  39. // Desc: Main edit window for the GUI editing tool
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. // USER INCLUDES //////////////////////////////////////////////////////////////
  47. #include "Common/Debug.h"
  48. #include "GameClient/Display.h"
  49. #include "GameClient/GameWindowManager.h"
  50. #include "W3DDevice/GameClient/W3DFileSystem.h"
  51. #include "Resource.h"
  52. #include "EditWindow.h"
  53. #include "GUIEdit.h"
  54. #include "WinMain.h"
  55. #include "HierarchyView.h"
  56. #include "Properties.h"
  57. #include "WW3D2/WW3D.h"
  58. #include "WW3D2/Render2D.h"
  59. // DEFINES ////////////////////////////////////////////////////////////////////
  60. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  61. ///////////////////////////////////////////////////////////////////////////////
  62. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  63. ///////////////////////////////////////////////////////////////////////////////
  64. Bool EditWindow::m_classRegistered = FALSE; ///< class registered flag
  65. char *EditWindow::m_className = "EditWindowClass"; ///< edit window class name
  66. ///////////////////////////////////////////////////////////////////////////////
  67. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  68. ///////////////////////////////////////////////////////////////////////////////
  69. EditWindow *TheEditWindow = NULL; ///< edit window singleton
  70. ///////////////////////////////////////////////////////////////////////////////
  71. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  72. ///////////////////////////////////////////////////////////////////////////////
  73. ///////////////////////////////////////////////////////////////////////////////
  74. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  75. ///////////////////////////////////////////////////////////////////////////////
  76. // editProc ===================================================================
  77. /** Window procedure for the edit window */
  78. //=============================================================================
  79. LRESULT CALLBACK EditWindow::editProc( HWND hWnd, UINT message,
  80. WPARAM wParam, LPARAM lParam )
  81. {
  82. switch( message )
  83. {
  84. // ------------------------------------------------------------------------
  85. case WM_TIMER:
  86. {
  87. Int timerID = wParam;
  88. if( TheEditWindow )
  89. {
  90. if( timerID == TIMER_EDIT_WINDOW_PULSE )
  91. TheEditWindow->updatePulse();
  92. } // end if
  93. return 0;
  94. } // end timer
  95. //-------------------------------------------------------------------------
  96. case WM_MOUSEMOVE:
  97. case WM_LBUTTONDOWN:
  98. case WM_LBUTTONUP:
  99. case WM_MBUTTONDOWN:
  100. case WM_MBUTTONUP:
  101. case WM_RBUTTONDOWN:
  102. case WM_RBUTTONUP:
  103. {
  104. TheEditWindow->mouseEvent( message, wParam, lParam );
  105. return 0;
  106. } // end mouse events
  107. // ------------------------------------------------------------------------
  108. case WM_COMMAND:
  109. {
  110. Int controlID = LOWORD( wParam );
  111. // Int nofifyCode = HIWORD( wParam );
  112. // HWND hWndControl = (HWND)lParam;
  113. switch( controlID )
  114. {
  115. // --------------------------------------------------------------------
  116. case POPUP_MENU_NEW_WINDOW:
  117. case POPUP_MENU_NEW_PUSH_BUTTON:
  118. case POPUP_MENU_NEW_RADIO_BUTTON:
  119. case POPUP_MENU_NEW_TAB_CONTROL:
  120. case POPUP_MENU_NEW_CHECK_BOX:
  121. case POPUP_MENU_NEW_LISTBOX:
  122. case POPUP_MENU_NEW_COMBO_BOX:
  123. case POPUP_MENU_NEW_HORIZONTAL_SLIDER:
  124. case POPUP_MENU_NEW_VERTICAL_SLIDER:
  125. case POPUP_MENU_NEW_PROGRESS_BAR:
  126. case POPUP_MENU_NEW_TEXT_ENTRY:
  127. case POPUP_MENU_NEW_STATIC_TEXT:
  128. case POPUP_MENU_PROPERTIES:
  129. case POPUP_MENU_DELETE:
  130. case POPUP_MENU_BRING_TO_TOP:
  131. {
  132. ICoord2D pos;
  133. GameWindow *window;
  134. // get position the menu was initiated at
  135. TheEditWindow->getPopupMenuClickPos( &pos );
  136. //
  137. // if the position the user clicked at was on another window,
  138. // that window will become the parent of the new one
  139. //
  140. window = TheEditor->getWindowAtPos( pos.x, pos.y );
  141. // create new window at that location
  142. switch( controlID )
  143. {
  144. // ----------------------------------------------------------------
  145. case POPUP_MENU_NEW_WINDOW:
  146. TheEditor->newWindow( GWS_USER_WINDOW,
  147. window, pos.x, pos.y,
  148. 15 * TheEditor->getGridResolution(),
  149. 15 * TheEditor->getGridResolution() );
  150. break;
  151. // ----------------------------------------------------------------
  152. case POPUP_MENU_NEW_PUSH_BUTTON:
  153. TheEditor->newWindow( GWS_PUSH_BUTTON,
  154. window, pos.x, pos.y,
  155. 15 * TheEditor->getGridResolution(),
  156. 3 * TheEditor->getGridResolution() );
  157. break;
  158. // ----------------------------------------------------------------
  159. case POPUP_MENU_NEW_CHECK_BOX:
  160. TheEditor->newWindow( GWS_CHECK_BOX,
  161. window, pos.x, pos.y,
  162. 15 * TheEditor->getGridResolution(),
  163. 3 * TheEditor->getGridResolution() );
  164. break;
  165. // ----------------------------------------------------------------
  166. case POPUP_MENU_NEW_RADIO_BUTTON:
  167. TheEditor->newWindow( GWS_RADIO_BUTTON,
  168. window, pos.x, pos.y,
  169. 15 * TheEditor->getGridResolution(),
  170. 3 * TheEditor->getGridResolution() );
  171. break;
  172. // ----------------------------------------------------------------
  173. case POPUP_MENU_NEW_TAB_CONTROL:
  174. TheEditor->newWindow( GWS_TAB_CONTROL,
  175. window, pos.x, pos.y,
  176. 45 * TheEditor->getGridResolution(),
  177. 30 * TheEditor->getGridResolution() );
  178. break;
  179. // ----------------------------------------------------------------
  180. case POPUP_MENU_NEW_LISTBOX:
  181. TheEditor->newWindow( GWS_SCROLL_LISTBOX,
  182. window, pos.x, pos.y,
  183. 20 * TheEditor->getGridResolution(),
  184. 20 * TheEditor->getGridResolution() );
  185. break;
  186. // ----------------------------------------------------------------
  187. case POPUP_MENU_NEW_COMBO_BOX:
  188. TheEditor->newWindow( GWS_COMBO_BOX,
  189. window, pos.x, pos.y,
  190. 15 * TheEditor->getGridResolution(),
  191. 3 * TheEditor->getGridResolution() );
  192. break;
  193. // ----------------------------------------------------------------
  194. case POPUP_MENU_NEW_HORIZONTAL_SLIDER:
  195. TheEditor->newWindow( GWS_HORZ_SLIDER,
  196. window, pos.x, pos.y,
  197. 20 * TheEditor->getGridResolution(),
  198. GADGET_SIZE );
  199. break;
  200. // ----------------------------------------------------------------
  201. case POPUP_MENU_NEW_VERTICAL_SLIDER:
  202. TheEditor->newWindow( GWS_VERT_SLIDER,
  203. window, pos.x, pos.y,
  204. GADGET_SIZE,
  205. 20 * TheEditor->getGridResolution() );
  206. break;
  207. // ----------------------------------------------------------------
  208. case POPUP_MENU_NEW_PROGRESS_BAR:
  209. TheEditor->newWindow( GWS_PROGRESS_BAR,
  210. window, pos.x, pos.y,
  211. 40 * TheEditor->getGridResolution(),
  212. GADGET_SIZE );
  213. break;
  214. // ----------------------------------------------------------------
  215. case POPUP_MENU_NEW_TEXT_ENTRY:
  216. TheEditor->newWindow( GWS_ENTRY_FIELD,
  217. window, pos.x, pos.y,
  218. 20 * TheEditor->getGridResolution(),
  219. 25 );
  220. break;
  221. // ----------------------------------------------------------------
  222. case POPUP_MENU_NEW_STATIC_TEXT:
  223. TheEditor->newWindow( GWS_STATIC_TEXT,
  224. window, pos.x, pos.y,
  225. 15 * TheEditor->getGridResolution(),
  226. 15 * TheEditor->getGridResolution() );
  227. break;
  228. // ----------------------------------------------------------------
  229. case POPUP_MENU_DELETE:
  230. TheEditor->deleteSelected();
  231. break;
  232. // ----------------------------------------------------------------
  233. case POPUP_MENU_BRING_TO_TOP:
  234. TheEditor->bringSelectedToTop();
  235. break;
  236. // ----------------------------------------------------------------
  237. case POPUP_MENU_PROPERTIES:
  238. if( window )
  239. InitPropertiesDialog( window, pos.x, pos.y );
  240. break;
  241. } // end switch
  242. break;
  243. } // end new window
  244. } // end switch on control id
  245. return 0;
  246. } // end command
  247. // ------------------------------------------------------------------------
  248. default:
  249. {
  250. break;
  251. } // end default
  252. } // end switch( message )
  253. return DefWindowProc( hWnd, message, wParam, lParam );
  254. } // end editProc
  255. // EditWindow::registerEditWindowClass ========================================
  256. /** Register a class with the windows OS for an edit window */
  257. //=============================================================================
  258. void EditWindow::registerEditWindowClass( void )
  259. {
  260. WNDCLASSEX wcex;
  261. ATOM atom;
  262. HINSTANCE hInst = TheEditor->getInstance();
  263. wcex.cbSize = sizeof( WNDCLASSEX );
  264. wcex.style = CS_HREDRAW | CS_VREDRAW;
  265. wcex.lpfnWndProc = (WNDPROC)editProc;
  266. wcex.cbClsExtra = 0;
  267. wcex.cbWndExtra = 0;
  268. wcex.hInstance = hInst;
  269. wcex.hIcon = LoadIcon( hInst, (LPCTSTR)IDI_GUIEDIT );
  270. wcex.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW);
  271. wcex.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
  272. wcex.lpszMenuName = NULL;
  273. wcex.lpszClassName = m_className;
  274. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  275. atom = RegisterClassEx( &wcex );
  276. // if successfully registered we don't ever need to do this again
  277. if( atom != 0 )
  278. m_classRegistered = TRUE;
  279. } // end registerEditWindowClass
  280. ///////////////////////////////////////////////////////////////////////////////
  281. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  282. ///////////////////////////////////////////////////////////////////////////////
  283. // EditWindow::EditWindow =====================================================
  284. /** */
  285. //=============================================================================
  286. EditWindow::EditWindow( void )
  287. {
  288. m_pulse = 0;
  289. m_size.x = 0;
  290. m_size.y = 0;
  291. m_bitDepth = 32;
  292. m_editWindowHWnd = NULL;
  293. m_assetManager = NULL;
  294. m_2DRender = NULL;
  295. m_w3dInitialized = FALSE;
  296. m_popupMenuClickPos.x = 0;
  297. m_popupMenuClickPos.y = 0;
  298. m_pickedWindow = NULL;
  299. m_dragMoveOrigin.x = 0;
  300. m_dragMoveOrigin.y = 0;
  301. m_dragMoveDest.x = 0;
  302. m_dragMoveDest.y = 0;
  303. m_dragSelecting = FALSE;
  304. m_selectRegion.lo.x = 0;
  305. m_selectRegion.lo.y = 0;
  306. m_selectRegion.hi.x = 0;
  307. m_selectRegion.hi.y = 0;
  308. m_resizingWindow = FALSE;
  309. m_windowToResize = NULL;
  310. m_resizeOrigin.x = 0;
  311. m_resizeOrigin.y = 0;
  312. m_resizeDest.x = 0;
  313. m_resizeDest.y = 0;
  314. m_backgroundColor.red = 0.0f;
  315. m_backgroundColor.green = 0.3f;
  316. m_backgroundColor.blue = 0.3f;
  317. m_backgroundColor.alpha = 1.0f;
  318. m_clipRegion.lo.x = 0;
  319. m_clipRegion.lo.y = 0;
  320. m_clipRegion.hi.x = 0;
  321. m_clipRegion.hi.y = 0;
  322. m_isClippedEnabled = FALSE;
  323. } // end EditWindow
  324. // EditWindow::~EditWindow ====================================================
  325. /** */
  326. //=============================================================================
  327. EditWindow::~EditWindow( void )
  328. {
  329. // call the shutdown
  330. shutdown();
  331. } // end ~EditWindow
  332. // EditWindow::init ===========================================================
  333. /** Initialize the edit window */
  334. //=============================================================================
  335. void EditWindow::init( UnsignedInt clientWidth, UnsignedInt clientHeight )
  336. {
  337. UnsignedInt windowStyle = WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_BORDER | WS_CAPTION;
  338. UnsignedInt extendedWindowStyle = 0;
  339. ICoord2D size;
  340. // register an edit window class with windows if not already done
  341. if( m_classRegistered == FALSE )
  342. registerEditWindowClass();
  343. // create 2D renderer
  344. m_2DRender = new Render2DClass;
  345. // save width and height
  346. size.x = clientWidth;
  347. size.y = clientHeight;
  348. setSize( &size );
  349. //
  350. // we want a client area the specified width and height, figure out how
  351. // big our window rectangle needs to be in order to have a client are
  352. // of that size
  353. //
  354. RECT clientRect;
  355. clientRect.left = 0;
  356. clientRect.top = 0;
  357. clientRect.right = m_size.x;
  358. clientRect.bottom = m_size.y;
  359. AdjustWindowRect( &clientRect, windowStyle, FALSE );
  360. // create the window
  361. m_editWindowHWnd = CreateWindowEx( extendedWindowStyle, // extended window style
  362. m_className, // class name
  363. "Edit Window", // window name
  364. windowStyle, // style bits
  365. 0, // x location
  366. 0, // y location
  367. clientRect.right - clientRect.left, // width
  368. clientRect.bottom - clientRect.top, // height,
  369. TheEditor->getWindowHandle(), // parent
  370. NULL, // menu
  371. TheEditor->getInstance(), // instance
  372. NULL ); // creation parameters
  373. // display the window
  374. ShowWindow( m_editWindowHWnd, SW_SHOW );
  375. // create the file system for our asset file locations
  376. TheW3DFileSystem = new W3DFileSystem; // our own file system for asset locations
  377. // initialize W3D
  378. WWMath::Init();
  379. WW3D::Init( m_editWindowHWnd );
  380. WW3D::Set_Screen_UV_Bias( TRUE ); ///< this makes text look good :)
  381. if( WW3D::Set_Render_Device( 0,
  382. m_size.x,
  383. m_size.y,
  384. m_bitDepth,
  385. TRUE ) != WW3D_ERROR_OK )
  386. {
  387. assert( 0 );
  388. shutdown();
  389. return;
  390. } // end if
  391. // create asset manager
  392. m_assetManager = new WW3DAssetManager;
  393. assert( m_assetManager );
  394. m_assetManager->Set_WW3D_Load_On_Demand( true );
  395. // W3D is now initialized
  396. m_w3dInitialized = TRUE;
  397. // set a timer for updating visual pulse drawing
  398. SetTimer( m_editWindowHWnd, TIMER_EDIT_WINDOW_PULSE, 5, NULL );
  399. } // end init
  400. // EditWindow::shutdown =======================================================
  401. /** Shutdown edit window */
  402. //=============================================================================
  403. void EditWindow::shutdown( void )
  404. {
  405. // delete 2d renderer
  406. delete m_2DRender;
  407. m_2DRender = NULL;
  408. // delete asset manager
  409. m_assetManager->Free_Assets();
  410. delete m_assetManager;
  411. // shutdown WW3D
  412. WW3D::Shutdown();
  413. WWMath::Shutdown();
  414. // delete the w3d file system
  415. delete TheW3DFileSystem;
  416. TheW3DFileSystem = NULL;
  417. // destroy the edit window
  418. if( m_editWindowHWnd )
  419. DestroyWindow( m_editWindowHWnd );
  420. m_editWindowHWnd = NULL;
  421. // unregister our edit window class
  422. UnregisterClass( m_className, TheEditor->getInstance() );
  423. m_classRegistered = FALSE;
  424. } // EditWindowShutdown
  425. // EditWindow::updatePulse ====================================================
  426. /** Update pulse from timer message */
  427. //=============================================================================
  428. void EditWindow::updatePulse( void )
  429. {
  430. static Bool dir = 1;
  431. static Int stepSize = 4;
  432. static Int pulseMax = 175,
  433. pulseMin = 75;
  434. // this is used for drawing pusling lines for moving stuff
  435. if( dir == 1 )
  436. {
  437. m_pulse += stepSize;
  438. if( m_pulse >= pulseMax )
  439. dir = 0;
  440. } // end if
  441. else
  442. {
  443. m_pulse -= stepSize;
  444. if( m_pulse <= pulseMin )
  445. dir = 1;
  446. } // end else
  447. } // end updatePulse
  448. // EditWindow::mouseEvent =====================================================
  449. /** A mouse event has occurred from our window procedure */
  450. //=============================================================================
  451. void EditWindow::mouseEvent( UnsignedInt windowsMessage,
  452. WPARAM wParam, LPARAM lParam )
  453. {
  454. Int x = LOWORD( lParam );
  455. Int y = HIWORD( lParam );
  456. Bool controlDown = BitTest( GetKeyState( VK_CONTROL ), 0x1000 );
  457. ICoord2D mouse;
  458. // setup mouse in nice struct
  459. mouse.x = x;
  460. mouse.y = y;
  461. // for mouse move messges always update the status bar
  462. if( windowsMessage == WM_MOUSEMOVE )
  463. {
  464. char buffer[ 64 ];
  465. ICoord2D mousePrint;
  466. // only print mouse positions in the edit window
  467. mousePrint.x = x;
  468. mousePrint.y = y;
  469. if( mousePrint.x < 0 )
  470. mousePrint.x = 0;
  471. if( mousePrint.x > m_size.x )
  472. mousePrint.x = m_size.x;
  473. if( mousePrint.y < 0 )
  474. mousePrint.y = 0;
  475. if( mousePrint.y > m_size.y )
  476. mousePrint.y = m_size.y;
  477. sprintf( buffer, "Mouse Location (X = %d, Y = %d)",
  478. mousePrint.x, mousePrint.y );
  479. TheEditor->statusMessage( STATUS_MOUSE_COORDS, buffer );
  480. // keep focus in our app
  481. if( GetFocus() != TheEditor->getWindowHandle() )
  482. SetFocus( TheEditor->getWindowHandle() );
  483. } // end if
  484. //
  485. // if we're in test mode just pump all input through to the
  486. // window system so we can see how everything acts
  487. //
  488. if( TheEditor->getMode() == MODE_TEST_RUN )
  489. {
  490. if( TheWin32Mouse )
  491. TheWin32Mouse->addWin32Event( windowsMessage, wParam, lParam, NO_TIME_FROM_WINDOWS);
  492. return;
  493. } // end if
  494. //
  495. // If we're in the keyboard move, ignore the mouse
  496. //
  497. if (TheEditor->getMode() == MODE_KEYBOARD_MOVE)
  498. return;
  499. // do logic for each of the mouse messages
  500. switch( windowsMessage )
  501. {
  502. // ------------------------------------------------------------------------
  503. case WM_MOUSEMOVE:
  504. {
  505. //
  506. // this is really stupid, but the tree controls just don't
  507. // give enough hooks into all the events we need ... it's possible
  508. // to be in drag and drop mode due to menus opening up and the
  509. // user clicking on blank area etc. So if the mouse is in the
  510. // the edit window just make sure all our drag and drop stuff is
  511. // clear in the hierarchy
  512. //
  513. TheHierarchyView->setDragWindow( NULL );
  514. TheHierarchyView->setDragTarget( NULL );
  515. TheHierarchyView->setPopupTarget( NULL );
  516. if( TheEditor->getMode() == MODE_DRAG_MOVE )
  517. {
  518. // update destination for drag move
  519. m_dragMoveDest = mouse;
  520. } // end if
  521. else if( m_dragSelecting )
  522. {
  523. // update drag selection region
  524. m_selectRegion.hi.x = x;
  525. m_selectRegion.hi.y = y;
  526. } // end else if
  527. else if( m_resizingWindow )
  528. {
  529. // save the position of our mouse for resizing
  530. m_resizeDest = mouse;
  531. } // end else if
  532. else
  533. {
  534. //
  535. // if we have ONE window selected and are close to an anchor corner
  536. // to resize it change the cursor to resize cursor
  537. //
  538. TheEditWindow->handleResizeAvailable( x, y );
  539. } // end else
  540. break;
  541. } // end mouse move
  542. // ------------------------------------------------------------------------
  543. case WM_LBUTTONDOWN:
  544. {
  545. //
  546. // if we're in drag move mode ignore this command ... usually this
  547. // doesn't happen cause you usually get into drag move mode by pressing
  548. // down, holding down, and dragging ... but it's possible to move
  549. // windows via the hierarchy view for those hard to reach windows
  550. //
  551. if( TheEditor->getMode() == MODE_DRAG_MOVE &&
  552. TheEditor->selectionCount() == 1 &&
  553. TheHierarchyView->getPopupTarget() != NULL )
  554. break;
  555. //
  556. // if we are in one of the resize modes then this click will
  557. // resize the window selected
  558. //
  559. if( TheEditor->getMode() == MODE_RESIZE_TOP_LEFT ||
  560. TheEditor->getMode() == MODE_RESIZE_BOTTOM_RIGHT ||
  561. TheEditor->getMode() == MODE_RESIZE_TOP_RIGHT ||
  562. TheEditor->getMode() == MODE_RESIZE_BOTTOM_LEFT ||
  563. TheEditor->getMode() == MODE_RESIZE_TOP ||
  564. TheEditor->getMode() == MODE_RESIZE_BOTTOM ||
  565. TheEditor->getMode() == MODE_RESIZE_RIGHT ||
  566. TheEditor->getMode() == MODE_RESIZE_LEFT )
  567. {
  568. // mouse movements will now resize the window in the selection list
  569. m_windowToResize = TheEditor->getFirstSelected();
  570. if( m_windowToResize )
  571. m_resizingWindow = TRUE;
  572. // save our mouse position for the resizing process
  573. m_resizeOrigin = mouse;
  574. m_resizeDest = mouse;
  575. } // end if
  576. else
  577. {
  578. GameWindow *window = TheEditor->getWindowAtPos( x, y );
  579. if( window )
  580. {
  581. //
  582. // if this window is not selected, then this window will become
  583. // the selected window instead of anything else that is selected.
  584. //
  585. if( TheEditor->isWindowSelected( window ) == FALSE )
  586. {
  587. //
  588. // if control key is not down we clear selections, otherwise
  589. // we will add this one to the select list
  590. //
  591. if( controlDown == FALSE )
  592. TheEditor->clearSelections();
  593. // select this window
  594. TheEditor->selectWindow( window );
  595. } // end if
  596. else
  597. {
  598. //
  599. // this window is selected, if control is down we will
  600. // unselect this window
  601. //
  602. if( controlDown == TRUE )
  603. {
  604. TheEditor->unSelectWindow( window );
  605. }
  606. // only proceed into drag mode if we have something selected
  607. else if( TheEditor->isWindowSelected( window ) )
  608. {
  609. // set move locations
  610. m_dragMoveOrigin = mouse;
  611. m_dragMoveDest = mouse;
  612. // capture the mouse
  613. SetCapture( m_editWindowHWnd );
  614. // change to drag move mode and switch cursor
  615. TheEditor->setMode( MODE_DRAG_MOVE );
  616. } // end if
  617. } // end else
  618. } // end if
  619. else
  620. {
  621. // start a drag selection box
  622. m_dragSelecting = TRUE;
  623. m_selectRegion.lo.x = x;
  624. m_selectRegion.lo.y = y;
  625. m_selectRegion.hi.x = x;
  626. m_selectRegion.hi.y = y;
  627. } // end else
  628. } // end if
  629. break;
  630. } // end left button down
  631. // ------------------------------------------------------------------------
  632. case WM_LBUTTONUP:
  633. {
  634. // exit drag move mode
  635. if( TheEditor->getMode() == MODE_DRAG_MOVE )
  636. {
  637. // move the windows
  638. if ((m_dragMoveOrigin.x != m_dragMoveDest.x) || (m_dragMoveOrigin.y != m_dragMoveDest.y)) {
  639. TheEditor->dragMoveSelectedWindows( &m_dragMoveOrigin, &m_dragMoveDest );
  640. }
  641. // release capture
  642. SetCapture( NULL );
  643. // go back to normal mode
  644. TheEditor->setMode( MODE_EDIT );
  645. } // end if
  646. else if( m_dragSelecting )
  647. {
  648. // select the windows in the region
  649. TheEditor->selectWindowsInRegion( &m_selectRegion );
  650. // stop a drag selection if in progress
  651. m_dragSelecting = FALSE;
  652. } // end else
  653. else if( m_resizingWindow )
  654. {
  655. GameWindow *window = TheEditor->getFirstSelected();
  656. DEBUG_ASSERTCRASH(window, ("No window selected for resize!"));
  657. if (window)
  658. {
  659. ICoord2D resultLoc, resultSize;
  660. ICoord2D dest = m_resizeDest;
  661. // adjust resize dest by the grid if it's on
  662. if( TheEditor->isGridSnapOn() )
  663. TheEditor->gridSnapLocation( &dest, &dest );
  664. // compute the location to resize it at
  665. TheEditor->computeResizeLocation( TheEditor->getMode(),
  666. window,
  667. &m_resizeOrigin, &dest,
  668. &resultLoc, &resultSize );
  669. // move the window
  670. TheEditor->moveWindowTo( window, resultLoc.x, resultLoc.y );
  671. // resize the window
  672. window->winSetSize( resultSize.x, resultSize.y );
  673. }
  674. // go back to normal
  675. m_resizingWindow = FALSE;
  676. TheEditor->setMode( MODE_EDIT );
  677. } // end resizing window
  678. break;
  679. } // end left button up
  680. // ------------------------------------------------------------------------
  681. case WM_MBUTTONDOWN:
  682. {
  683. break;
  684. } // end middle button down
  685. // ------------------------------------------------------------------------
  686. case WM_MBUTTONUP:
  687. {
  688. break;
  689. } // end middle button up
  690. // ------------------------------------------------------------------------
  691. case WM_RBUTTONDOWN:
  692. {
  693. ICoord2D clickPos = mouse;
  694. GameWindow *window;
  695. // adjust the mouse pos if we're on a grid
  696. if( TheEditor->isGridSnapOn() )
  697. TheEditor->gridSnapLocation( &mouse, &clickPos );
  698. // get the window at the click pos
  699. window = TheEditor->getWindowAtPos( clickPos.x, clickPos.y );
  700. //
  701. // if there is a window here and it is not part of the selection
  702. // list, everything else is unselected
  703. //
  704. if( window )
  705. {
  706. if( TheEditor->isWindowSelected( window ) == FALSE )
  707. TheEditor->clearSelections();
  708. // select this window
  709. TheEditor->selectWindow( window );
  710. } // end if
  711. else
  712. {
  713. // no window here, clear selections anyway
  714. TheEditor->clearSelections();
  715. } // end else
  716. // open right click menu
  717. TheEditWindow->openPopupMenu( clickPos.x, clickPos.y );
  718. break;
  719. } // end right button down
  720. // ------------------------------------------------------------------------
  721. case WM_RBUTTONUP:
  722. {
  723. break;
  724. } // end right button up
  725. // ------------------------------------------------------------------------
  726. default:
  727. {
  728. break;
  729. } // end default
  730. } // end switch on widnows message
  731. } // end mouseEvent
  732. // EditWindow::inCornerTolerance ==============================================
  733. /** If the 'dest' point is within 'tolerance' distance to the 'source'
  734. * point this returns TRUE */
  735. //=============================================================================
  736. Bool EditWindow::inCornerTolerance( ICoord2D *dest, ICoord2D *source,
  737. Int tolerance )
  738. {
  739. IRegion2D region;
  740. // sanity
  741. if( dest == NULL || source == NULL )
  742. return FALSE;
  743. /// @todo we should write PointInRegion() stuff again like it was in Nox
  744. // build the region around the source point
  745. region.lo.x = source->x - tolerance;
  746. region.lo.y = source->y - tolerance;
  747. region.hi.x = source->x + tolerance;
  748. region.hi.y = source->y + tolerance;
  749. // check if in region
  750. if( dest->x >= region.lo.x &&
  751. dest->x <= region.hi.x &&
  752. dest->y >= region.lo.y &&
  753. dest->y <= region.hi.y )
  754. return TRUE;
  755. return FALSE;
  756. } // end inCornerTolerance
  757. // EditWindow::inLineTolerance ================================================
  758. /** If the 'dest' point is within the region defined around the
  759. * line with th specified tolerance return TRUE */
  760. //=============================================================================
  761. Bool EditWindow::inLineTolerance( ICoord2D *dest,
  762. ICoord2D *lineStart, ICoord2D *lineEnd,
  763. Int tolerance )
  764. {
  765. IRegion2D region;
  766. // sanity
  767. if( dest == NULL || lineStart == NULL || lineEnd == NULL )
  768. return FALSE;
  769. // setup region
  770. region.lo.x = lineStart->x - tolerance;
  771. region.lo.y = lineStart->y - tolerance;
  772. region.hi.x = lineEnd->x + tolerance;
  773. region.hi.y = lineEnd->y + tolerance;
  774. // check if in region
  775. if( dest->x >= region.lo.x &&
  776. dest->x <= region.hi.x &&
  777. dest->y >= region.lo.y &&
  778. dest->y <= region.hi.y )
  779. return TRUE;
  780. return FALSE;
  781. } // end inLineTolerance
  782. // EditWindow::handleResizeAvailable ==========================================
  783. /** Given the mouse position, if it is close enough to a corner of a
  784. * SINGLE selected window then we change the icon to the appropriate
  785. * resize icon. If the mouse is not moved from this position then
  786. * the next left click will allow for a resize of the window */
  787. //=============================================================================
  788. void EditWindow::handleResizeAvailable( Int mouseX, Int mouseY )
  789. {
  790. GameWindow *window;
  791. ICoord2D origin, size, mouse, point;
  792. const Int tol = 5;
  793. // if there is zero or more than 1 window selected we can't resize
  794. if( TheEditor->selectionCount() != 1 )
  795. return;
  796. // get mouse data in a nice coord 2d
  797. mouse.x = mouseX;
  798. mouse.y = mouseY;
  799. // get the selected window data
  800. window = TheEditor->getFirstSelected();
  801. window->winGetScreenPosition( &origin.x, &origin.y );
  802. window->winGetSize( &size.x, &size.y );
  803. // check for around top left corner
  804. point = origin;
  805. if( inCornerTolerance( &mouse, &point, tol ) == TRUE )
  806. {
  807. TheEditor->setMode( MODE_RESIZE_TOP_LEFT );
  808. return;
  809. } // end if
  810. // check for around bottom right corner
  811. point.x = origin.x + size.x;
  812. point.y = origin.y + size.y;
  813. if( inCornerTolerance( &mouse, &point, tol ) == TRUE )
  814. {
  815. TheEditor->setMode( MODE_RESIZE_BOTTOM_RIGHT );
  816. return;
  817. } // end if
  818. // check for around top right corner
  819. point.x = origin.x + size.x;
  820. point.y = origin.y;
  821. if( inCornerTolerance( &mouse, &point, tol ) == TRUE )
  822. {
  823. TheEditor->setMode( MODE_RESIZE_TOP_RIGHT );
  824. return;
  825. } // end if
  826. // check for around bottom left corner
  827. point.x = origin.x;
  828. point.y = origin.y + size.y;
  829. if( inCornerTolerance( &mouse, &point, tol ) == TRUE )
  830. {
  831. TheEditor->setMode( MODE_RESIZE_BOTTOM_LEFT );
  832. return;
  833. } // end if
  834. ICoord2D lineStart, lineEnd;
  835. // check for along top edge
  836. lineStart = origin;
  837. lineEnd.x = origin.x + size.x;
  838. lineEnd.y = origin.y;
  839. if( inLineTolerance( &mouse, &lineStart, &lineEnd, tol ) == TRUE )
  840. {
  841. TheEditor->setMode( MODE_RESIZE_TOP );
  842. return;
  843. } // end if
  844. // check for along bottom edge
  845. lineStart.x = origin.x;
  846. lineStart.y = origin.y + size.y;
  847. lineEnd.x = origin.x + size.x;
  848. lineEnd.y = origin.y + size.y;
  849. if( inLineTolerance( &mouse, &lineStart, &lineEnd, tol ) == TRUE )
  850. {
  851. TheEditor->setMode( MODE_RESIZE_BOTTOM );
  852. return;
  853. } // end if
  854. // check for along left edge
  855. lineStart = origin;
  856. lineEnd.x = origin.x;
  857. lineEnd.y = origin.y + size.y;
  858. if( inLineTolerance( &mouse, &lineStart, &lineEnd, tol ) == TRUE )
  859. {
  860. TheEditor->setMode( MODE_RESIZE_LEFT );
  861. return;
  862. } // end if
  863. // check for along right edge
  864. lineStart.x = origin.x + size.x;
  865. lineStart.y = origin.y;
  866. lineEnd.x = origin.x + size.x;
  867. lineEnd.y = origin.y + size.y;
  868. if( inLineTolerance( &mouse, &lineStart, &lineEnd, tol ) == TRUE )
  869. {
  870. TheEditor->setMode( MODE_RESIZE_RIGHT );
  871. return;
  872. } // end if
  873. // we are not resizing anything at all, set us to normal mode
  874. TheEditor->setMode( MODE_EDIT );
  875. } // end handleResizeAvailable
  876. // EditWindow::drawSeeThruOutlines ============================================
  877. /** Draw an outline for a window that is see thru so we can still work
  878. * with it in the editor */
  879. //=============================================================================
  880. void EditWindow::drawSeeThruOutlines( GameWindow *windowList, Color c )
  881. {
  882. // end recursion
  883. if( windowList == NULL )
  884. return;
  885. // draw outline for this window
  886. if( BitTest( windowList->winGetStatus(), WIN_STATUS_SEE_THRU ) )
  887. {
  888. ICoord2D pos;
  889. ICoord2D size;
  890. // get position and size
  891. windowList->winGetScreenPosition( &pos.x, &pos.y );
  892. windowList->winGetSize( &size.x, &size.y );
  893. // draw a box on the window
  894. drawOpenRect( pos.x, pos.y, size.x, size.y, 1, c );
  895. } // end if
  896. // check window children
  897. GameWindow *child;
  898. for( child = windowList->winGetChild(); child; child = child->winGetNext() )
  899. drawSeeThruOutlines( child, c );
  900. // go to siblings
  901. drawSeeThruOutlines( windowList->winGetNext(), c );
  902. } // end drawSeeThruOutlines
  903. // EditWindow::drawHiddenOutlines =============================================
  904. /** Draw an outline for a window that is hidden so we can still work
  905. * with it in the editor */
  906. //=============================================================================
  907. void EditWindow::drawHiddenOutlines( GameWindow *windowList, Color c )
  908. {
  909. // end recursion
  910. if( windowList == NULL )
  911. return;
  912. //
  913. // draw outline for this window, we are hidden if we have the hidden
  914. // status or any of our parents are hidden
  915. //
  916. Bool hidden = FALSE;
  917. GameWindow *parent= windowList->winGetParent();
  918. while( parent )
  919. {
  920. if( BitTest( parent->winGetStatus(), WIN_STATUS_HIDDEN ) )
  921. hidden = TRUE;
  922. parent = parent->winGetParent();
  923. } // end while
  924. if( BitTest( windowList->winGetStatus(), WIN_STATUS_HIDDEN ) )
  925. hidden = TRUE;
  926. if( hidden )
  927. {
  928. ICoord2D pos;
  929. ICoord2D size;
  930. // get position and size
  931. windowList->winGetScreenPosition( &pos.x, &pos.y );
  932. windowList->winGetSize( &size.x, &size.y );
  933. // draw a box on the window
  934. drawOpenRect( pos.x, pos.y, size.x, size.y, 2, c );
  935. } // end if
  936. // check window children
  937. GameWindow *child;
  938. for( child = windowList->winGetChild(); child; child = child->winGetNext() )
  939. drawHiddenOutlines( child, c );
  940. // go to siblings
  941. drawHiddenOutlines( windowList->winGetNext(), c );
  942. } // end drawHiddenOutlines
  943. // EditWindow::drawUIback =====================================================
  944. /** Draw any visual feedback to the user about selection boxes or windows
  945. * that are selected, draggin windows etc */
  946. //=============================================================================
  947. void EditWindow::drawUIFeedback( void )
  948. {
  949. WindowSelectionEntry *select;
  950. Int color = m_pulse * 2;
  951. if( color > 255 )
  952. color = 255;
  953. // draw hidden window outlines if requested
  954. if( TheEditor->getShowHiddenOutlines() )
  955. drawHiddenOutlines( TheWindowManager->winGetWindowList(),
  956. GameMakeColor( color, 64, 64, 255 ) );
  957. // draw see-thru window outlines if requested
  958. if( TheEditor->getShowSeeThruOutlines() )
  959. drawSeeThruOutlines( TheWindowManager->winGetWindowList(),
  960. GameMakeColor( 64, 64, color, 255 ) );
  961. // if the grid is visible draw it on top of everything
  962. if( TheEditor->isGridVisible() == TRUE )
  963. drawGrid();
  964. // draw drag selection box
  965. if( m_dragSelecting )
  966. {
  967. Int width, height;
  968. Real selectBoxWidth = 2.0f;
  969. Color selectBoxColor = GameMakeColor( 0, 255, 0, 255 );
  970. width = m_selectRegion.hi.x - m_selectRegion.lo.x;
  971. height = m_selectRegion.hi.y - m_selectRegion.lo.y;
  972. drawOpenRect( m_selectRegion.lo.x, m_selectRegion.lo.y,
  973. width, height, selectBoxWidth, selectBoxColor );
  974. } // end if
  975. // draw select lines on selected windows
  976. select = TheEditor->getSelectList();
  977. while( select )
  978. {
  979. ICoord2D origin, size;
  980. GameWindow *window;
  981. Real windowSelectWidth = 2.0f;
  982. Color windowSelectColor;
  983. windowSelectColor = GameMakeColor( 0, color, 0, 255 );
  984. // get window properties
  985. window = select->window;
  986. window->winGetScreenPosition( &origin.x, &origin.y );
  987. window->winGetSize( &size.x, &size.y );
  988. // draw a box on the window
  989. drawOpenRect( origin.x, origin.y, size.x, size.y,
  990. windowSelectWidth, windowSelectColor );
  991. // go to next selection
  992. select = select->next;
  993. } // end while
  994. //
  995. // if we're drag moving, draw outlines of all the windows in the
  996. // select list offset by the start to end of the drag move
  997. //
  998. if( TheEditor->getMode() == MODE_DRAG_MOVE || TheEditor->getMode() == MODE_KEYBOARD_MOVE )
  999. {
  1000. ICoord2D origin, size;
  1001. ICoord2D moveLoc, safeLoc;
  1002. GameWindow *window, *parent;
  1003. Real outlineWidth = 1.0f;
  1004. Color outlineColor;
  1005. // determine outline using pulse counter
  1006. outlineColor = GameMakeColor( m_pulse, m_pulse, m_pulse + 25, 255 );
  1007. // traverse selection list
  1008. select = TheEditor->getSelectList();
  1009. while( select )
  1010. {
  1011. // get window data
  1012. window = select->window;
  1013. window->winGetScreenPosition( &origin.x, &origin.y );
  1014. window->winGetSize( &size.x, &size.y );
  1015. // figure out the destination of the window from this move
  1016. ICoord2D change;
  1017. change.x = (m_dragMoveDest.x - m_dragMoveOrigin.x);
  1018. change.y = (m_dragMoveDest.y - m_dragMoveOrigin.y);
  1019. // [SKB: Jun 02 2003 @ 2:7pm] :
  1020. // Don't move the object unless we have moved the mouse,
  1021. // this is to avoid the irritating movement of a window when just
  1022. // clicking on a window.
  1023. if (change.x || change.y)
  1024. {
  1025. moveLoc.x = origin.x + change.x;
  1026. moveLoc.y = origin.y + change.y;
  1027. // snap move location to grid if on
  1028. if( (TheEditor->getMode() == MODE_DRAG_MOVE) && TheEditor->isGridSnapOn() )
  1029. TheEditor->gridSnapLocation( &moveLoc, &moveLoc );
  1030. // keep location legal
  1031. TheEditor->computeSafeLocation( window, moveLoc.x, moveLoc.y,
  1032. &safeLoc.x, &safeLoc.y );
  1033. // adjust location by parent location if present
  1034. parent = window->winGetParent();
  1035. if( parent )
  1036. {
  1037. ICoord2D parentOrigin;
  1038. parent->winGetScreenPosition( &parentOrigin.x, &parentOrigin.y );
  1039. safeLoc.x += parentOrigin.x;
  1040. safeLoc.y += parentOrigin.y;
  1041. } // end if
  1042. // draw outline of window at what would be the drag move destination
  1043. drawOpenRect( safeLoc.x, safeLoc.y, size.x, size.y,
  1044. outlineWidth, outlineColor );
  1045. }
  1046. // go to next selection
  1047. select = select->next;
  1048. } // end while
  1049. } // end if
  1050. // if resizing a window draw that resize representation
  1051. if( m_resizingWindow )
  1052. {
  1053. GameWindow *window = m_windowToResize;
  1054. ICoord2D loc, size;
  1055. Color outlineColor;
  1056. Real outlineWidth = 1.0f;
  1057. GameWindow *parent;
  1058. ICoord2D dest = m_resizeDest;
  1059. // adjust resize dest by the grid if it's on
  1060. if( TheEditor->isGridSnapOn() )
  1061. TheEditor->gridSnapLocation( &dest, &dest );
  1062. //
  1063. // given the location that we started dragging at and the destination
  1064. // drag location along with the mode of resizing compute what the
  1065. // new location and the new size of the selected window to resize
  1066. //
  1067. TheEditor->computeResizeLocation( TheEditor->getMode(),
  1068. window,
  1069. &m_resizeOrigin, &dest,
  1070. &loc, &size );
  1071. // adjust location by parent location if present
  1072. parent = window->winGetParent();
  1073. if( parent )
  1074. {
  1075. ICoord2D parentOrigin;
  1076. parent->winGetScreenPosition( &parentOrigin.x, &parentOrigin.y );
  1077. loc.x += parentOrigin.x;
  1078. loc.y += parentOrigin.y;
  1079. } // end if
  1080. // draw a box for the window at its new location
  1081. outlineColor = GameMakeColor( m_pulse, m_pulse, m_pulse, 255 );
  1082. drawOpenRect( loc.x, loc.y, size.x, size.y, outlineWidth, outlineColor );
  1083. } // end if
  1084. // draw lines around any drag source and drag targets in the hierarchy view
  1085. GameWindow *dragSource = TheHierarchyView->getDragWindow();
  1086. Color dragColor = GameMakeColor( color, 0, color, 255 );
  1087. if( dragSource )
  1088. {
  1089. ICoord2D origin, size;
  1090. // get size and position
  1091. dragSource->winGetScreenPosition( &origin.x, &origin.y );
  1092. dragSource->winGetSize( &size.x, &size.y );
  1093. // draw box
  1094. drawOpenRect( origin.x, origin.y, size.x, size.y, 2, dragColor );
  1095. } // end if
  1096. // drag target
  1097. GameWindow *dragTarget = TheHierarchyView->getDragTarget();
  1098. if( dragTarget )
  1099. {
  1100. ICoord2D origin, size;
  1101. // get size and position
  1102. dragTarget->winGetScreenPosition( &origin.x, &origin.y );
  1103. dragTarget->winGetSize( &size.x, &size.y );
  1104. // draw box
  1105. drawOpenRect( origin.x, origin.y, size.x, size.y, 2, dragColor );
  1106. } // end if
  1107. } // end drawUIFeedback
  1108. // EditWindow::drawGrid =======================================================
  1109. /** Draw the grid */
  1110. //=============================================================================
  1111. void EditWindow::drawGrid( void )
  1112. {
  1113. // HDC hdc = GetDC( getWindowHandle() );
  1114. Int res = TheEditor->getGridResolution();
  1115. Int x, y;
  1116. RGBColorInt *gridColor = TheEditor->getGridColor();
  1117. Color color = GameMakeColor( gridColor->red, gridColor->green,
  1118. gridColor->blue, gridColor->alpha );
  1119. // set us to invert where we draw
  1120. // SetROP2( hdc, R2_NOT );
  1121. // SelectObject( hdc, (HPEN)GetStockObject( WHITE_PEN ) );
  1122. for( y = 0; y < m_size.y; y += res )
  1123. {
  1124. TheDisplay->drawLine( 0, y, m_size.x, y, 1, color );
  1125. // MoveToEx( hdc, 0, y, NULL );
  1126. // LineTo( hdc, m_size.x, y );
  1127. }
  1128. for( x = 0; x < m_size.x; x += res )
  1129. {
  1130. TheDisplay->drawLine( x, 0, x, m_size.y, 1, color );
  1131. // MoveToEx( hdc, x, 0, NULL );
  1132. // LineTo( hdc, x, m_size.y );
  1133. }
  1134. /*
  1135. for( y = 0; y < m_size.y; y += res )
  1136. {
  1137. for( x = 0; x < m_size.x; x += res )
  1138. {
  1139. MoveToEx( hdc, x, y, NULL );
  1140. LineTo( hdc, x + 1, y + 1 );
  1141. // TheDisplay->drawLine( x, y, x + 1, y + 1, 1, 0xFFFFFFFF );
  1142. } // end for x
  1143. } // end for y
  1144. */
  1145. // release the dc
  1146. // ReleaseDC( getWindowHandle(), hdc );
  1147. } // end drawGrid
  1148. // EditWindow::draw ===========================================================
  1149. /** Draw the edit window */
  1150. //=============================================================================
  1151. void EditWindow::draw( void )
  1152. {
  1153. static UnsignedInt syncTime = 0;
  1154. // allow W3D to update its internals
  1155. WW3D::Sync( syncTime );
  1156. // for now, use constant time steps to avoid animations running independent of framerate
  1157. syncTime += 50;
  1158. // start render block
  1159. WW3D::Begin_Render( true, true, Vector3( m_backgroundColor.red,
  1160. m_backgroundColor.green,
  1161. m_backgroundColor.blue ) );
  1162. // draw the windows
  1163. TheWindowManager->winRepaint();
  1164. // draw selected drag box and any window selection boxes
  1165. if( TheEditor->getMode() != MODE_TEST_RUN )
  1166. drawUIFeedback();
  1167. // render is all done!
  1168. WW3D::End_Render();
  1169. } // end draw
  1170. // EditWindow::setSize ========================================================
  1171. /** The edit window should now be logically consider this size */
  1172. //=============================================================================
  1173. void EditWindow::setSize( ICoord2D *size )
  1174. {
  1175. // save the size
  1176. m_size = *size;
  1177. // the display should reflect the new size as well
  1178. if( TheDisplay )
  1179. {
  1180. TheDisplay->setWidth( m_size.x );
  1181. TheDisplay->setHeight( m_size.y );
  1182. } // end if
  1183. // set the extents for our 2D renderer
  1184. if( m_2DRender )
  1185. m_2DRender->Set_Coordinate_Range( RectClass( 0,
  1186. 0,
  1187. m_size.x,
  1188. m_size.y ) );
  1189. } // end setSize
  1190. // EditWindow::openPopupMenu ==================================================
  1191. /** Open the new control menu that comes up when the user right clicks
  1192. * in the workspace to create new controls */
  1193. //=============================================================================
  1194. void EditWindow::openPopupMenu( Int x, Int y )
  1195. {
  1196. HMENU menu, subMenu;
  1197. POINT screen;
  1198. Int selectCount = TheEditor->selectionCount();
  1199. // get the menu with the new control items
  1200. menu = LoadMenu( TheEditor->getInstance(), (LPCTSTR)POPUP_MENU );
  1201. subMenu = GetSubMenu( menu, 0 );
  1202. // enable/disable menu items
  1203. if( selectCount == 0 )
  1204. {
  1205. EnableMenuItem( subMenu, POPUP_MENU_DELETE, MF_GRAYED );
  1206. EnableMenuItem( subMenu, POPUP_MENU_PROPERTIES, MF_GRAYED );
  1207. EnableMenuItem( subMenu, POPUP_MENU_BRING_TO_TOP, MF_GRAYED );
  1208. } // end if
  1209. else
  1210. {
  1211. EnableMenuItem( subMenu, POPUP_MENU_DELETE, MF_ENABLED );
  1212. EnableMenuItem( subMenu, POPUP_MENU_PROPERTIES, MF_ENABLED );
  1213. EnableMenuItem( subMenu, POPUP_MENU_BRING_TO_TOP, MF_ENABLED );
  1214. } // end else
  1215. //
  1216. // open up right mouse track menu, note that we have to translate the
  1217. // x,y of this mouse click which is local to this window into
  1218. // screen coordinates
  1219. //
  1220. screen.x = x;
  1221. screen.y = y;
  1222. ClientToScreen( m_editWindowHWnd, &screen );
  1223. TrackPopupMenuEx( subMenu, 0, screen.x, screen.y, m_editWindowHWnd, NULL );
  1224. // save the location click for the creation of the popup menu
  1225. m_popupMenuClickPos.x = x;
  1226. m_popupMenuClickPos.y = y;
  1227. } // end openPopupMenu
  1228. // EditWindow::drawLine =======================================================
  1229. /** draw a line on the display in pixel coordinates with the specified color */
  1230. //=============================================================================
  1231. void EditWindow::drawLine( Int startX, Int startY,
  1232. Int endX, Int endY,
  1233. Real lineWidth, UnsignedInt lineColor )
  1234. {
  1235. m_2DRender->Reset();
  1236. m_2DRender->Enable_Texturing( FALSE );
  1237. m_2DRender->Add_Line( Vector2( startX, startY ), Vector2( endX, endY ),
  1238. lineWidth, lineColor );
  1239. m_2DRender->Render();
  1240. } // end drawLIne
  1241. // EditWindow::drawOpenRect ===================================================
  1242. /** draw a rect border on the display in pixel coordinates with the
  1243. * specified color */
  1244. //=============================================================================
  1245. void EditWindow::drawOpenRect( Int startX, Int startY,
  1246. Int width, Int height,
  1247. Real lineWidth, UnsignedInt lineColor )
  1248. {
  1249. m_2DRender->Reset();
  1250. m_2DRender->Enable_Texturing( FALSE );
  1251. m_2DRender->Add_Outline( RectClass( startX, startY,
  1252. startX + width, startY + height ),
  1253. lineWidth, lineColor );
  1254. // render it now!
  1255. m_2DRender->Render();
  1256. } // end drawOpenRect
  1257. // EditWindow::drawFillRect ===================================================
  1258. /** draw a filled rect on the display in pixel coords with the
  1259. * specified color */
  1260. //=============================================================================
  1261. void EditWindow::drawFillRect( Int startX, Int startY,
  1262. Int width, Int height,
  1263. UnsignedInt color )
  1264. {
  1265. m_2DRender->Reset();
  1266. m_2DRender->Enable_Texturing( FALSE );
  1267. m_2DRender->Add_Rect( RectClass( startX, startY,
  1268. startX + width, startY + height ),
  1269. 0, 0, color );
  1270. // render it now!
  1271. m_2DRender->Render();
  1272. } // end drawFillRect
  1273. // EditWindow::drawImage ======================================================
  1274. /** draw an image fit within the screen coordinates */
  1275. //=============================================================================
  1276. void EditWindow::drawImage( const Image *image,
  1277. Int startX, Int startY,
  1278. Int endX, Int endY,
  1279. Color color )
  1280. {
  1281. // sanity
  1282. if( image == NULL )
  1283. return;
  1284. const Region2D *uv = image->getUV();
  1285. m_2DRender->Reset();
  1286. m_2DRender->Enable_Texturing( TRUE );
  1287. m_2DRender->Set_Texture( image->getFilename().str() );
  1288. RectClass screen_rect(startX,startY,endX,endY);
  1289. RectClass uv_rect(uv->lo.x,uv->lo.y,uv->hi.x,uv->hi.y);
  1290. if (m_isClippedEnabled)
  1291. { //need to clip this quad to clip rectangle
  1292. //
  1293. // Check for completely clipped
  1294. //
  1295. if ( endX <= m_clipRegion.lo.x ||
  1296. endY <= m_clipRegion.lo.y)
  1297. {
  1298. return; //nothing to render
  1299. } else {
  1300. //
  1301. // Clip the polygons to the specified area
  1302. //
  1303. RectClass clipped_rect;
  1304. clipped_rect.Left = __max (screen_rect.Left, m_clipRegion.lo.x);
  1305. clipped_rect.Right = __min (screen_rect.Right, m_clipRegion.hi.x);
  1306. clipped_rect.Top = __max (screen_rect.Top, m_clipRegion.lo.y);
  1307. clipped_rect.Bottom = __min (screen_rect.Bottom, m_clipRegion.hi.y);
  1308. //
  1309. // Clip the texture to the specified area
  1310. //
  1311. RectClass clipped_uv_rect;
  1312. float percent = ((clipped_rect.Left - screen_rect.Left) / screen_rect.Width ());
  1313. clipped_uv_rect.Left = uv_rect.Left + (uv_rect.Width () * percent);
  1314. percent = ((clipped_rect.Right - screen_rect.Left) / screen_rect.Width ());
  1315. clipped_uv_rect.Right = uv_rect.Left + (uv_rect.Width () * percent);
  1316. percent = ((clipped_rect.Top - screen_rect.Top) / screen_rect.Height ());
  1317. clipped_uv_rect.Top = uv_rect.Top + (uv_rect.Height () * percent);
  1318. percent = ((clipped_rect.Bottom - screen_rect.Top) / screen_rect.Height ());
  1319. clipped_uv_rect.Bottom = uv_rect.Top + (uv_rect.Height () * percent);
  1320. //
  1321. // Use the clipped rectangles to render
  1322. //
  1323. screen_rect = clipped_rect;
  1324. uv_rect = clipped_uv_rect;
  1325. }
  1326. }
  1327. // if rotated 90 degrees clockwise we have to adjust the uv coords
  1328. if( BitTest( image->getStatus(), IMAGE_STATUS_ROTATED_90_CLOCKWISE ) )
  1329. {
  1330. m_2DRender->Add_Tri( Vector2( screen_rect.Left, screen_rect.Top ),
  1331. Vector2( screen_rect.Left, screen_rect.Bottom ),
  1332. Vector2( screen_rect.Right, screen_rect.Top ),
  1333. Vector2( uv_rect.Right, uv_rect.Top),
  1334. Vector2( uv_rect.Left, uv_rect.Top),
  1335. Vector2( uv_rect.Right, uv_rect.Bottom ),
  1336. color );
  1337. m_2DRender->Add_Tri( Vector2( screen_rect.Right, screen_rect.Bottom ),
  1338. Vector2( screen_rect.Right, screen_rect.Top ),
  1339. Vector2( screen_rect.Left, screen_rect.Bottom ),
  1340. Vector2( uv_rect.Left, uv_rect.Bottom ),
  1341. Vector2( uv_rect.Right, uv_rect.Bottom ),
  1342. Vector2( uv_rect.Left, uv_rect.Top ),
  1343. color );
  1344. } // end if
  1345. else
  1346. {
  1347. // just draw as normal
  1348. m_2DRender->Add_Quad( screen_rect, uv_rect, color );
  1349. } // end else
  1350. m_2DRender->Render();
  1351. } // end drawImage
  1352. // EditWindow::getBackgroundColor =============================================
  1353. /** Get the background color for the edit window */
  1354. //=============================================================================
  1355. RGBColorReal EditWindow::getBackgroundColor( void )
  1356. {
  1357. return m_backgroundColor;
  1358. } // end getBackgroundColor
  1359. // EditWindow::setBackgroundColor =============================================
  1360. /** Set the background color for the edit window */
  1361. //=============================================================================
  1362. void EditWindow::setBackgroundColor( RGBColorReal color )
  1363. {
  1364. m_backgroundColor = color;
  1365. } // end setBackgroundColor
  1366. // EditWindow::notifyWindowDeleted ============================================
  1367. /** A window has been deleted from the editor and the editor is now
  1368. * notifying the edit window about it in case anything must be
  1369. * cleaned up */
  1370. //=============================================================================
  1371. void EditWindow::notifyWindowDeleted( GameWindow *window )
  1372. {
  1373. // sanity
  1374. if( window == NULL )
  1375. return;
  1376. // check to see if the resizing window was deleted
  1377. if( m_windowToResize == window )
  1378. {
  1379. // get back to normal mode and clean up
  1380. m_windowToResize = NULL;
  1381. m_resizingWindow = FALSE;
  1382. TheEditor->setMode( MODE_EDIT );
  1383. } // end if
  1384. // null out picked window if needed
  1385. if( m_pickedWindow == window )
  1386. m_pickedWindow = NULL;
  1387. //
  1388. // go back to edit mode, this keeps us from staying in a resize mode
  1389. // after deleting the window under the cursor
  1390. //
  1391. TheEditor->setMode( MODE_EDIT );
  1392. } // end notifyWindowDeleted