EditWindow.cpp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. /*
  2. ** Command & Conquer Generals(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. TheEditor->unSelectWindow( window );
  604. } // end else
  605. // only proceed into drag mode if we have something selected
  606. if( TheEditor->isWindowSelected( window ) )
  607. {
  608. // set move locations
  609. m_dragMoveOrigin = mouse;
  610. m_dragMoveDest = mouse;
  611. // capture the mouse
  612. SetCapture( m_editWindowHWnd );
  613. // change to drag move mode and switch cursor
  614. TheEditor->setMode( MODE_DRAG_MOVE );
  615. } // end if
  616. } // end if
  617. else
  618. {
  619. // start a drag selection box
  620. m_dragSelecting = TRUE;
  621. m_selectRegion.lo.x = x;
  622. m_selectRegion.lo.y = y;
  623. m_selectRegion.hi.x = x;
  624. m_selectRegion.hi.y = y;
  625. } // end else
  626. } // end if
  627. break;
  628. } // end left button down
  629. // ------------------------------------------------------------------------
  630. case WM_LBUTTONUP:
  631. {
  632. // exit drag move mode
  633. if( TheEditor->getMode() == MODE_DRAG_MOVE )
  634. {
  635. // move the windows
  636. TheEditor->dragMoveSelectedWindows( &m_dragMoveOrigin, &m_dragMoveDest );
  637. // release capture
  638. SetCapture( NULL );
  639. // go back to normal mode
  640. TheEditor->setMode( MODE_EDIT );
  641. } // end if
  642. else if( m_dragSelecting )
  643. {
  644. // select the windows in the region
  645. TheEditor->selectWindowsInRegion( &m_selectRegion );
  646. // stop a drag selection if in progress
  647. m_dragSelecting = FALSE;
  648. } // end else
  649. else if( m_resizingWindow )
  650. {
  651. GameWindow *window = TheEditor->getFirstSelected();
  652. DEBUG_ASSERTCRASH(window, ("No window selected for resize!"));
  653. if (window)
  654. {
  655. ICoord2D resultLoc, resultSize;
  656. ICoord2D dest = m_resizeDest;
  657. // adjust resize dest by the grid if it's on
  658. if( TheEditor->isGridSnapOn() )
  659. TheEditor->gridSnapLocation( &dest, &dest );
  660. // compute the location to resize it at
  661. TheEditor->computeResizeLocation( TheEditor->getMode(),
  662. window,
  663. &m_resizeOrigin, &dest,
  664. &resultLoc, &resultSize );
  665. // move the window
  666. TheEditor->moveWindowTo( window, resultLoc.x, resultLoc.y );
  667. // resize the window
  668. window->winSetSize( resultSize.x, resultSize.y );
  669. }
  670. // go back to normal
  671. m_resizingWindow = FALSE;
  672. TheEditor->setMode( MODE_EDIT );
  673. } // end resizing window
  674. break;
  675. } // end left button up
  676. // ------------------------------------------------------------------------
  677. case WM_MBUTTONDOWN:
  678. {
  679. break;
  680. } // end middle button down
  681. // ------------------------------------------------------------------------
  682. case WM_MBUTTONUP:
  683. {
  684. break;
  685. } // end middle button up
  686. // ------------------------------------------------------------------------
  687. case WM_RBUTTONDOWN:
  688. {
  689. ICoord2D clickPos = mouse;
  690. GameWindow *window;
  691. // adjust the mouse pos if we're on a grid
  692. if( TheEditor->isGridSnapOn() )
  693. TheEditor->gridSnapLocation( &mouse, &clickPos );
  694. // get the window at the click pos
  695. window = TheEditor->getWindowAtPos( clickPos.x, clickPos.y );
  696. //
  697. // if there is a window here and it is not part of the selection
  698. // list, everything else is unselected
  699. //
  700. if( window )
  701. {
  702. if( TheEditor->isWindowSelected( window ) == FALSE )
  703. TheEditor->clearSelections();
  704. // select this window
  705. TheEditor->selectWindow( window );
  706. } // end if
  707. else
  708. {
  709. // no window here, clear selections anyway
  710. TheEditor->clearSelections();
  711. } // end else
  712. // open right click menu
  713. TheEditWindow->openPopupMenu( clickPos.x, clickPos.y );
  714. break;
  715. } // end right button down
  716. // ------------------------------------------------------------------------
  717. case WM_RBUTTONUP:
  718. {
  719. break;
  720. } // end right button up
  721. // ------------------------------------------------------------------------
  722. default:
  723. {
  724. break;
  725. } // end default
  726. } // end switch on widnows message
  727. } // end mouseEvent
  728. // EditWindow::inCornerTolerance ==============================================
  729. /** If the 'dest' point is within 'tolerance' distance to the 'source'
  730. * point this returns TRUE */
  731. //=============================================================================
  732. Bool EditWindow::inCornerTolerance( ICoord2D *dest, ICoord2D *source,
  733. Int tolerance )
  734. {
  735. IRegion2D region;
  736. // sanity
  737. if( dest == NULL || source == NULL )
  738. return FALSE;
  739. /// @todo we should write PointInRegion() stuff again like it was in Nox
  740. // build the region around the source point
  741. region.lo.x = source->x - tolerance;
  742. region.lo.y = source->y - tolerance;
  743. region.hi.x = source->x + tolerance;
  744. region.hi.y = source->y + tolerance;
  745. // check if in region
  746. if( dest->x >= region.lo.x &&
  747. dest->x <= region.hi.x &&
  748. dest->y >= region.lo.y &&
  749. dest->y <= region.hi.y )
  750. return TRUE;
  751. return FALSE;
  752. } // end inCornerTolerance
  753. // EditWindow::inLineTolerance ================================================
  754. /** If the 'dest' point is within the region defined around the
  755. * line with th specified tolerance return TRUE */
  756. //=============================================================================
  757. Bool EditWindow::inLineTolerance( ICoord2D *dest,
  758. ICoord2D *lineStart, ICoord2D *lineEnd,
  759. Int tolerance )
  760. {
  761. IRegion2D region;
  762. // sanity
  763. if( dest == NULL || lineStart == NULL || lineEnd == NULL )
  764. return FALSE;
  765. // setup region
  766. region.lo.x = lineStart->x - tolerance;
  767. region.lo.y = lineStart->y - tolerance;
  768. region.hi.x = lineEnd->x + tolerance;
  769. region.hi.y = lineEnd->y + tolerance;
  770. // check if in region
  771. if( dest->x >= region.lo.x &&
  772. dest->x <= region.hi.x &&
  773. dest->y >= region.lo.y &&
  774. dest->y <= region.hi.y )
  775. return TRUE;
  776. return FALSE;
  777. } // end inLineTolerance
  778. // EditWindow::handleResizeAvailable ==========================================
  779. /** Given the mouse position, if it is close enough to a corner of a
  780. * SINGLE selected window then we change the icon to the appropriate
  781. * resize icon. If the mouse is not moved from this position then
  782. * the next left click will allow for a resize of the window */
  783. //=============================================================================
  784. void EditWindow::handleResizeAvailable( Int mouseX, Int mouseY )
  785. {
  786. GameWindow *window;
  787. ICoord2D origin, size, mouse, point;
  788. const Int tol = 5;
  789. // if there is zero or more than 1 window selected we can't resize
  790. if( TheEditor->selectionCount() != 1 )
  791. return;
  792. // get mouse data in a nice coord 2d
  793. mouse.x = mouseX;
  794. mouse.y = mouseY;
  795. // get the selected window data
  796. window = TheEditor->getFirstSelected();
  797. window->winGetScreenPosition( &origin.x, &origin.y );
  798. window->winGetSize( &size.x, &size.y );
  799. // check for around top left corner
  800. point = origin;
  801. if( inCornerTolerance( &mouse, &point, tol ) == TRUE )
  802. {
  803. TheEditor->setMode( MODE_RESIZE_TOP_LEFT );
  804. return;
  805. } // end if
  806. // check for around bottom right corner
  807. point.x = origin.x + size.x;
  808. point.y = origin.y + size.y;
  809. if( inCornerTolerance( &mouse, &point, tol ) == TRUE )
  810. {
  811. TheEditor->setMode( MODE_RESIZE_BOTTOM_RIGHT );
  812. return;
  813. } // end if
  814. // check for around top right corner
  815. point.x = origin.x + size.x;
  816. point.y = origin.y;
  817. if( inCornerTolerance( &mouse, &point, tol ) == TRUE )
  818. {
  819. TheEditor->setMode( MODE_RESIZE_TOP_RIGHT );
  820. return;
  821. } // end if
  822. // check for around bottom left corner
  823. point.x = origin.x;
  824. point.y = origin.y + size.y;
  825. if( inCornerTolerance( &mouse, &point, tol ) == TRUE )
  826. {
  827. TheEditor->setMode( MODE_RESIZE_BOTTOM_LEFT );
  828. return;
  829. } // end if
  830. ICoord2D lineStart, lineEnd;
  831. // check for along top edge
  832. lineStart = origin;
  833. lineEnd.x = origin.x + size.x;
  834. lineEnd.y = origin.y;
  835. if( inLineTolerance( &mouse, &lineStart, &lineEnd, tol ) == TRUE )
  836. {
  837. TheEditor->setMode( MODE_RESIZE_TOP );
  838. return;
  839. } // end if
  840. // check for along bottom edge
  841. lineStart.x = origin.x;
  842. lineStart.y = origin.y + size.y;
  843. lineEnd.x = origin.x + size.x;
  844. lineEnd.y = origin.y + size.y;
  845. if( inLineTolerance( &mouse, &lineStart, &lineEnd, tol ) == TRUE )
  846. {
  847. TheEditor->setMode( MODE_RESIZE_BOTTOM );
  848. return;
  849. } // end if
  850. // check for along left edge
  851. lineStart = origin;
  852. lineEnd.x = origin.x;
  853. lineEnd.y = origin.y + size.y;
  854. if( inLineTolerance( &mouse, &lineStart, &lineEnd, tol ) == TRUE )
  855. {
  856. TheEditor->setMode( MODE_RESIZE_LEFT );
  857. return;
  858. } // end if
  859. // check for along right edge
  860. lineStart.x = origin.x + size.x;
  861. lineStart.y = origin.y;
  862. lineEnd.x = origin.x + size.x;
  863. lineEnd.y = origin.y + size.y;
  864. if( inLineTolerance( &mouse, &lineStart, &lineEnd, tol ) == TRUE )
  865. {
  866. TheEditor->setMode( MODE_RESIZE_RIGHT );
  867. return;
  868. } // end if
  869. // we are not resizing anything at all, set us to normal mode
  870. TheEditor->setMode( MODE_EDIT );
  871. } // end handleResizeAvailable
  872. // EditWindow::drawSeeThruOutlines ============================================
  873. /** Draw an outline for a window that is see thru so we can still work
  874. * with it in the editor */
  875. //=============================================================================
  876. void EditWindow::drawSeeThruOutlines( GameWindow *windowList, Color c )
  877. {
  878. // end recursion
  879. if( windowList == NULL )
  880. return;
  881. // draw outline for this window
  882. if( BitTest( windowList->winGetStatus(), WIN_STATUS_SEE_THRU ) )
  883. {
  884. ICoord2D pos;
  885. ICoord2D size;
  886. // get position and size
  887. windowList->winGetScreenPosition( &pos.x, &pos.y );
  888. windowList->winGetSize( &size.x, &size.y );
  889. // draw a box on the window
  890. drawOpenRect( pos.x, pos.y, size.x, size.y, 1, c );
  891. } // end if
  892. // check window children
  893. GameWindow *child;
  894. for( child = windowList->winGetChild(); child; child = child->winGetNext() )
  895. drawSeeThruOutlines( child, c );
  896. // go to siblings
  897. drawSeeThruOutlines( windowList->winGetNext(), c );
  898. } // end drawSeeThruOutlines
  899. // EditWindow::drawHiddenOutlines =============================================
  900. /** Draw an outline for a window that is hidden so we can still work
  901. * with it in the editor */
  902. //=============================================================================
  903. void EditWindow::drawHiddenOutlines( GameWindow *windowList, Color c )
  904. {
  905. // end recursion
  906. if( windowList == NULL )
  907. return;
  908. //
  909. // draw outline for this window, we are hidden if we have the hidden
  910. // status or any of our parents are hidden
  911. //
  912. Bool hidden = FALSE;
  913. GameWindow *parent= windowList->winGetParent();
  914. while( parent )
  915. {
  916. if( BitTest( parent->winGetStatus(), WIN_STATUS_HIDDEN ) )
  917. hidden = TRUE;
  918. parent = parent->winGetParent();
  919. } // end while
  920. if( BitTest( windowList->winGetStatus(), WIN_STATUS_HIDDEN ) )
  921. hidden = TRUE;
  922. if( hidden )
  923. {
  924. ICoord2D pos;
  925. ICoord2D size;
  926. // get position and size
  927. windowList->winGetScreenPosition( &pos.x, &pos.y );
  928. windowList->winGetSize( &size.x, &size.y );
  929. // draw a box on the window
  930. drawOpenRect( pos.x, pos.y, size.x, size.y, 2, c );
  931. } // end if
  932. // check window children
  933. GameWindow *child;
  934. for( child = windowList->winGetChild(); child; child = child->winGetNext() )
  935. drawHiddenOutlines( child, c );
  936. // go to siblings
  937. drawHiddenOutlines( windowList->winGetNext(), c );
  938. } // end drawHiddenOutlines
  939. // EditWindow::drawUIback =====================================================
  940. /** Draw any visual feedback to the user about selection boxes or windows
  941. * that are selected, draggin windows etc */
  942. //=============================================================================
  943. void EditWindow::drawUIFeedback( void )
  944. {
  945. WindowSelectionEntry *select;
  946. Int color = m_pulse * 2;
  947. if( color > 255 )
  948. color = 255;
  949. // draw hidden window outlines if requested
  950. if( TheEditor->getShowHiddenOutlines() )
  951. drawHiddenOutlines( TheWindowManager->winGetWindowList(),
  952. GameMakeColor( color, 64, 64, 255 ) );
  953. // draw see-thru window outlines if requested
  954. if( TheEditor->getShowSeeThruOutlines() )
  955. drawSeeThruOutlines( TheWindowManager->winGetWindowList(),
  956. GameMakeColor( 64, 64, color, 255 ) );
  957. // if the grid is visible draw it on top of everything
  958. if( TheEditor->isGridVisible() == TRUE )
  959. drawGrid();
  960. // draw drag selection box
  961. if( m_dragSelecting )
  962. {
  963. Int width, height;
  964. Real selectBoxWidth = 2.0f;
  965. Color selectBoxColor = GameMakeColor( 0, 255, 0, 255 );
  966. width = m_selectRegion.hi.x - m_selectRegion.lo.x;
  967. height = m_selectRegion.hi.y - m_selectRegion.lo.y;
  968. drawOpenRect( m_selectRegion.lo.x, m_selectRegion.lo.y,
  969. width, height, selectBoxWidth, selectBoxColor );
  970. } // end if
  971. // draw select lines on selected windows
  972. select = TheEditor->getSelectList();
  973. while( select )
  974. {
  975. ICoord2D origin, size;
  976. GameWindow *window;
  977. Real windowSelectWidth = 2.0f;
  978. Color windowSelectColor;
  979. windowSelectColor = GameMakeColor( 0, color, 0, 255 );
  980. // get window properties
  981. window = select->window;
  982. window->winGetScreenPosition( &origin.x, &origin.y );
  983. window->winGetSize( &size.x, &size.y );
  984. // draw a box on the window
  985. drawOpenRect( origin.x, origin.y, size.x, size.y,
  986. windowSelectWidth, windowSelectColor );
  987. // go to next selection
  988. select = select->next;
  989. } // end while
  990. //
  991. // if we're drag moving, draw outlines of all the windows in the
  992. // select list offset by the start to end of the drag move
  993. //
  994. if( TheEditor->getMode() == MODE_DRAG_MOVE || TheEditor->getMode() == MODE_KEYBOARD_MOVE )
  995. {
  996. ICoord2D origin, size;
  997. ICoord2D moveLoc, safeLoc;
  998. GameWindow *window, *parent;
  999. Real outlineWidth = 1.0f;
  1000. Color outlineColor;
  1001. // determine outline using pulse counter
  1002. outlineColor = GameMakeColor( m_pulse, m_pulse, m_pulse + 25, 255 );
  1003. // traverse selection list
  1004. select = TheEditor->getSelectList();
  1005. while( select )
  1006. {
  1007. // get window data
  1008. window = select->window;
  1009. window->winGetScreenPosition( &origin.x, &origin.y );
  1010. window->winGetSize( &size.x, &size.y );
  1011. // figure out the destination of the window from this move
  1012. moveLoc.x = origin.x + (m_dragMoveDest.x - m_dragMoveOrigin.x);
  1013. moveLoc.y = origin.y + (m_dragMoveDest.y - m_dragMoveOrigin.y);
  1014. // snap move location to grid if on
  1015. if( (TheEditor->getMode() == MODE_DRAG_MOVE) && TheEditor->isGridSnapOn() )
  1016. TheEditor->gridSnapLocation( &moveLoc, &moveLoc );
  1017. // keep location legal
  1018. TheEditor->computeSafeLocation( window, moveLoc.x, moveLoc.y,
  1019. &safeLoc.x, &safeLoc.y );
  1020. // adjust location by parent location if present
  1021. parent = window->winGetParent();
  1022. if( parent )
  1023. {
  1024. ICoord2D parentOrigin;
  1025. parent->winGetScreenPosition( &parentOrigin.x, &parentOrigin.y );
  1026. safeLoc.x += parentOrigin.x;
  1027. safeLoc.y += parentOrigin.y;
  1028. } // end if
  1029. // draw outline of window at what would be the drag move destination
  1030. drawOpenRect( safeLoc.x, safeLoc.y, size.x, size.y,
  1031. outlineWidth, outlineColor );
  1032. // go to next selection
  1033. select = select->next;
  1034. } // end while
  1035. } // end if
  1036. // if resizing a window draw that resize representation
  1037. if( m_resizingWindow )
  1038. {
  1039. GameWindow *window = m_windowToResize;
  1040. ICoord2D loc, size;
  1041. Color outlineColor;
  1042. Real outlineWidth = 1.0f;
  1043. GameWindow *parent;
  1044. ICoord2D dest = m_resizeDest;
  1045. // adjust resize dest by the grid if it's on
  1046. if( TheEditor->isGridSnapOn() )
  1047. TheEditor->gridSnapLocation( &dest, &dest );
  1048. //
  1049. // given the location that we started dragging at and the destination
  1050. // drag location along with the mode of resizing compute what the
  1051. // new location and the new size of the selected window to resize
  1052. //
  1053. TheEditor->computeResizeLocation( TheEditor->getMode(),
  1054. window,
  1055. &m_resizeOrigin, &dest,
  1056. &loc, &size );
  1057. // adjust location by parent location if present
  1058. parent = window->winGetParent();
  1059. if( parent )
  1060. {
  1061. ICoord2D parentOrigin;
  1062. parent->winGetScreenPosition( &parentOrigin.x, &parentOrigin.y );
  1063. loc.x += parentOrigin.x;
  1064. loc.y += parentOrigin.y;
  1065. } // end if
  1066. // draw a box for the window at its new location
  1067. outlineColor = GameMakeColor( m_pulse, m_pulse, m_pulse, 255 );
  1068. drawOpenRect( loc.x, loc.y, size.x, size.y, outlineWidth, outlineColor );
  1069. } // end if
  1070. // draw lines around any drag source and drag targets in the hierarchy view
  1071. GameWindow *dragSource = TheHierarchyView->getDragWindow();
  1072. Color dragColor = GameMakeColor( color, 0, color, 255 );
  1073. if( dragSource )
  1074. {
  1075. ICoord2D origin, size;
  1076. // get size and position
  1077. dragSource->winGetScreenPosition( &origin.x, &origin.y );
  1078. dragSource->winGetSize( &size.x, &size.y );
  1079. // draw box
  1080. drawOpenRect( origin.x, origin.y, size.x, size.y, 2, dragColor );
  1081. } // end if
  1082. // drag target
  1083. GameWindow *dragTarget = TheHierarchyView->getDragTarget();
  1084. if( dragTarget )
  1085. {
  1086. ICoord2D origin, size;
  1087. // get size and position
  1088. dragTarget->winGetScreenPosition( &origin.x, &origin.y );
  1089. dragTarget->winGetSize( &size.x, &size.y );
  1090. // draw box
  1091. drawOpenRect( origin.x, origin.y, size.x, size.y, 2, dragColor );
  1092. } // end if
  1093. } // end drawUIFeedback
  1094. // EditWindow::drawGrid =======================================================
  1095. /** Draw the grid */
  1096. //=============================================================================
  1097. void EditWindow::drawGrid( void )
  1098. {
  1099. // HDC hdc = GetDC( getWindowHandle() );
  1100. Int res = TheEditor->getGridResolution();
  1101. Int x, y;
  1102. RGBColorInt *gridColor = TheEditor->getGridColor();
  1103. Color color = GameMakeColor( gridColor->red, gridColor->green,
  1104. gridColor->blue, gridColor->alpha );
  1105. // set us to invert where we draw
  1106. // SetROP2( hdc, R2_NOT );
  1107. // SelectObject( hdc, (HPEN)GetStockObject( WHITE_PEN ) );
  1108. for( y = 0; y < m_size.y; y += res )
  1109. {
  1110. TheDisplay->drawLine( 0, y, m_size.x, y, 1, color );
  1111. // MoveToEx( hdc, 0, y, NULL );
  1112. // LineTo( hdc, m_size.x, y );
  1113. }
  1114. for( x = 0; x < m_size.x; x += res )
  1115. {
  1116. TheDisplay->drawLine( x, 0, x, m_size.y, 1, color );
  1117. // MoveToEx( hdc, x, 0, NULL );
  1118. // LineTo( hdc, x, m_size.y );
  1119. }
  1120. /*
  1121. for( y = 0; y < m_size.y; y += res )
  1122. {
  1123. for( x = 0; x < m_size.x; x += res )
  1124. {
  1125. MoveToEx( hdc, x, y, NULL );
  1126. LineTo( hdc, x + 1, y + 1 );
  1127. // TheDisplay->drawLine( x, y, x + 1, y + 1, 1, 0xFFFFFFFF );
  1128. } // end for x
  1129. } // end for y
  1130. */
  1131. // release the dc
  1132. // ReleaseDC( getWindowHandle(), hdc );
  1133. } // end drawGrid
  1134. // EditWindow::draw ===========================================================
  1135. /** Draw the edit window */
  1136. //=============================================================================
  1137. void EditWindow::draw( void )
  1138. {
  1139. static UnsignedInt syncTime = 0;
  1140. // allow W3D to update its internals
  1141. WW3D::Sync( syncTime );
  1142. // for now, use constant time steps to avoid animations running independent of framerate
  1143. syncTime += 50;
  1144. // start render block
  1145. WW3D::Begin_Render( true, true, Vector3( m_backgroundColor.red,
  1146. m_backgroundColor.green,
  1147. m_backgroundColor.blue ) );
  1148. // draw the windows
  1149. TheWindowManager->winRepaint();
  1150. // draw selected drag box and any window selection boxes
  1151. if( TheEditor->getMode() != MODE_TEST_RUN )
  1152. drawUIFeedback();
  1153. // render is all done!
  1154. WW3D::End_Render();
  1155. } // end draw
  1156. // EditWindow::setSize ========================================================
  1157. /** The edit window should now be logically consider this size */
  1158. //=============================================================================
  1159. void EditWindow::setSize( ICoord2D *size )
  1160. {
  1161. // save the size
  1162. m_size = *size;
  1163. // the display should reflect the new size as well
  1164. if( TheDisplay )
  1165. {
  1166. TheDisplay->setWidth( m_size.x );
  1167. TheDisplay->setHeight( m_size.y );
  1168. } // end if
  1169. // set the extents for our 2D renderer
  1170. if( m_2DRender )
  1171. m_2DRender->Set_Coordinate_Range( RectClass( 0,
  1172. 0,
  1173. m_size.x,
  1174. m_size.y ) );
  1175. } // end setSize
  1176. // EditWindow::openPopupMenu ==================================================
  1177. /** Open the new control menu that comes up when the user right clicks
  1178. * in the workspace to create new controls */
  1179. //=============================================================================
  1180. void EditWindow::openPopupMenu( Int x, Int y )
  1181. {
  1182. HMENU menu, subMenu;
  1183. POINT screen;
  1184. Int selectCount = TheEditor->selectionCount();
  1185. // get the menu with the new control items
  1186. menu = LoadMenu( TheEditor->getInstance(), (LPCTSTR)POPUP_MENU );
  1187. subMenu = GetSubMenu( menu, 0 );
  1188. // enable/disable menu items
  1189. if( selectCount == 0 )
  1190. {
  1191. EnableMenuItem( subMenu, POPUP_MENU_DELETE, MF_GRAYED );
  1192. EnableMenuItem( subMenu, POPUP_MENU_PROPERTIES, MF_GRAYED );
  1193. EnableMenuItem( subMenu, POPUP_MENU_BRING_TO_TOP, MF_GRAYED );
  1194. } // end if
  1195. else
  1196. {
  1197. EnableMenuItem( subMenu, POPUP_MENU_DELETE, MF_ENABLED );
  1198. EnableMenuItem( subMenu, POPUP_MENU_PROPERTIES, MF_ENABLED );
  1199. EnableMenuItem( subMenu, POPUP_MENU_BRING_TO_TOP, MF_ENABLED );
  1200. } // end else
  1201. //
  1202. // open up right mouse track menu, note that we have to translate the
  1203. // x,y of this mouse click which is local to this window into
  1204. // screen coordinates
  1205. //
  1206. screen.x = x;
  1207. screen.y = y;
  1208. ClientToScreen( m_editWindowHWnd, &screen );
  1209. TrackPopupMenuEx( subMenu, 0, screen.x, screen.y, m_editWindowHWnd, NULL );
  1210. // save the location click for the creation of the popup menu
  1211. m_popupMenuClickPos.x = x;
  1212. m_popupMenuClickPos.y = y;
  1213. } // end openPopupMenu
  1214. // EditWindow::drawLine =======================================================
  1215. /** draw a line on the display in pixel coordinates with the specified color */
  1216. //=============================================================================
  1217. void EditWindow::drawLine( Int startX, Int startY,
  1218. Int endX, Int endY,
  1219. Real lineWidth, UnsignedInt lineColor )
  1220. {
  1221. m_2DRender->Reset();
  1222. m_2DRender->Enable_Texturing( FALSE );
  1223. m_2DRender->Add_Line( Vector2( startX, startY ), Vector2( endX, endY ),
  1224. lineWidth, lineColor );
  1225. m_2DRender->Render();
  1226. } // end drawLIne
  1227. // EditWindow::drawOpenRect ===================================================
  1228. /** draw a rect border on the display in pixel coordinates with the
  1229. * specified color */
  1230. //=============================================================================
  1231. void EditWindow::drawOpenRect( Int startX, Int startY,
  1232. Int width, Int height,
  1233. Real lineWidth, UnsignedInt lineColor )
  1234. {
  1235. m_2DRender->Reset();
  1236. m_2DRender->Enable_Texturing( FALSE );
  1237. m_2DRender->Add_Outline( RectClass( startX, startY,
  1238. startX + width, startY + height ),
  1239. lineWidth, lineColor );
  1240. // render it now!
  1241. m_2DRender->Render();
  1242. } // end drawOpenRect
  1243. // EditWindow::drawFillRect ===================================================
  1244. /** draw a filled rect on the display in pixel coords with the
  1245. * specified color */
  1246. //=============================================================================
  1247. void EditWindow::drawFillRect( Int startX, Int startY,
  1248. Int width, Int height,
  1249. UnsignedInt color )
  1250. {
  1251. m_2DRender->Reset();
  1252. m_2DRender->Enable_Texturing( FALSE );
  1253. m_2DRender->Add_Rect( RectClass( startX, startY,
  1254. startX + width, startY + height ),
  1255. 0, 0, color );
  1256. // render it now!
  1257. m_2DRender->Render();
  1258. } // end drawFillRect
  1259. // EditWindow::drawImage ======================================================
  1260. /** draw an image fit within the screen coordinates */
  1261. //=============================================================================
  1262. void EditWindow::drawImage( const Image *image,
  1263. Int startX, Int startY,
  1264. Int endX, Int endY,
  1265. Color color )
  1266. {
  1267. // sanity
  1268. if( image == NULL )
  1269. return;
  1270. const Region2D *uv = image->getUV();
  1271. m_2DRender->Reset();
  1272. m_2DRender->Enable_Texturing( TRUE );
  1273. m_2DRender->Set_Texture( image->getFilename().str() );
  1274. RectClass screen_rect(startX,startY,endX,endY);
  1275. RectClass uv_rect(uv->lo.x,uv->lo.y,uv->hi.x,uv->hi.y);
  1276. if (m_isClippedEnabled)
  1277. { //need to clip this quad to clip rectangle
  1278. //
  1279. // Check for completely clipped
  1280. //
  1281. if ( endX <= m_clipRegion.lo.x ||
  1282. endY <= m_clipRegion.lo.y)
  1283. {
  1284. return; //nothing to render
  1285. } else {
  1286. //
  1287. // Clip the polygons to the specified area
  1288. //
  1289. RectClass clipped_rect;
  1290. clipped_rect.Left = __max (screen_rect.Left, m_clipRegion.lo.x);
  1291. clipped_rect.Right = __min (screen_rect.Right, m_clipRegion.hi.x);
  1292. clipped_rect.Top = __max (screen_rect.Top, m_clipRegion.lo.y);
  1293. clipped_rect.Bottom = __min (screen_rect.Bottom, m_clipRegion.hi.y);
  1294. //
  1295. // Clip the texture to the specified area
  1296. //
  1297. RectClass clipped_uv_rect;
  1298. float percent = ((clipped_rect.Left - screen_rect.Left) / screen_rect.Width ());
  1299. clipped_uv_rect.Left = uv_rect.Left + (uv_rect.Width () * percent);
  1300. percent = ((clipped_rect.Right - screen_rect.Left) / screen_rect.Width ());
  1301. clipped_uv_rect.Right = uv_rect.Left + (uv_rect.Width () * percent);
  1302. percent = ((clipped_rect.Top - screen_rect.Top) / screen_rect.Height ());
  1303. clipped_uv_rect.Top = uv_rect.Top + (uv_rect.Height () * percent);
  1304. percent = ((clipped_rect.Bottom - screen_rect.Top) / screen_rect.Height ());
  1305. clipped_uv_rect.Bottom = uv_rect.Top + (uv_rect.Height () * percent);
  1306. //
  1307. // Use the clipped rectangles to render
  1308. //
  1309. screen_rect = clipped_rect;
  1310. uv_rect = clipped_uv_rect;
  1311. }
  1312. }
  1313. // if rotated 90 degrees clockwise we have to adjust the uv coords
  1314. if( BitTest( image->getStatus(), IMAGE_STATUS_ROTATED_90_CLOCKWISE ) )
  1315. {
  1316. m_2DRender->Add_Tri( Vector2( screen_rect.Left, screen_rect.Top ),
  1317. Vector2( screen_rect.Left, screen_rect.Bottom ),
  1318. Vector2( screen_rect.Right, screen_rect.Top ),
  1319. Vector2( uv_rect.Right, uv_rect.Top),
  1320. Vector2( uv_rect.Left, uv_rect.Top),
  1321. Vector2( uv_rect.Right, uv_rect.Bottom ),
  1322. color );
  1323. m_2DRender->Add_Tri( Vector2( screen_rect.Right, screen_rect.Bottom ),
  1324. Vector2( screen_rect.Right, screen_rect.Top ),
  1325. Vector2( screen_rect.Left, screen_rect.Bottom ),
  1326. Vector2( uv_rect.Left, uv_rect.Bottom ),
  1327. Vector2( uv_rect.Right, uv_rect.Bottom ),
  1328. Vector2( uv_rect.Left, uv_rect.Top ),
  1329. color );
  1330. } // end if
  1331. else
  1332. {
  1333. // just draw as normal
  1334. m_2DRender->Add_Quad( screen_rect, uv_rect, color );
  1335. } // end else
  1336. m_2DRender->Render();
  1337. } // end drawImage
  1338. // EditWindow::getBackgroundColor =============================================
  1339. /** Get the background color for the edit window */
  1340. //=============================================================================
  1341. RGBColorReal EditWindow::getBackgroundColor( void )
  1342. {
  1343. return m_backgroundColor;
  1344. } // end getBackgroundColor
  1345. // EditWindow::setBackgroundColor =============================================
  1346. /** Set the background color for the edit window */
  1347. //=============================================================================
  1348. void EditWindow::setBackgroundColor( RGBColorReal color )
  1349. {
  1350. m_backgroundColor = color;
  1351. } // end setBackgroundColor
  1352. // EditWindow::notifyWindowDeleted ============================================
  1353. /** A window has been deleted from the editor and the editor is now
  1354. * notifying the edit window about it in case anything must be
  1355. * cleaned up */
  1356. //=============================================================================
  1357. void EditWindow::notifyWindowDeleted( GameWindow *window )
  1358. {
  1359. // sanity
  1360. if( window == NULL )
  1361. return;
  1362. // check to see if the resizing window was deleted
  1363. if( m_windowToResize == window )
  1364. {
  1365. // get back to normal mode and clean up
  1366. m_windowToResize = NULL;
  1367. m_resizingWindow = FALSE;
  1368. TheEditor->setMode( MODE_EDIT );
  1369. } // end if
  1370. // null out picked window if needed
  1371. if( m_pickedWindow == window )
  1372. m_pickedWindow = NULL;
  1373. //
  1374. // go back to edit mode, this keeps us from staying in a resize mode
  1375. // after deleting the window under the cursor
  1376. //
  1377. TheEditor->setMode( MODE_EDIT );
  1378. } // end notifyWindowDeleted