GETransformer.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "../../sys/win32/rc/guied_resource.h"
  23. #include "GEApp.h"
  24. #include "../common/MaskEdit.h"
  25. HHOOK gTransHook = NULL;
  26. HWND gTransDlg = NULL;
  27. rvGETransformer::rvGETransformer ( )
  28. {
  29. mWnd = NULL;
  30. mWorkspace = NULL;
  31. }
  32. bool rvGETransformer::Create ( HWND parent, bool visible )
  33. {
  34. WNDCLASSEX wndClass;
  35. memset ( &wndClass, 0, sizeof(wndClass) );
  36. wndClass.cbSize = sizeof(WNDCLASSEX);
  37. wndClass.lpszClassName = "GUIEDITOR_TRANSFORMER_CLASS";
  38. wndClass.lpfnWndProc = rvGETransformer::WndProc;
  39. wndClass.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH );;
  40. wndClass.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
  41. wndClass.lpszMenuName = NULL;
  42. wndClass.hInstance = win32.hInstance;
  43. RegisterClassEx ( &wndClass );
  44. mWnd = CreateWindowEx ( WS_EX_TOOLWINDOW,
  45. "GUIEDITOR_TRANSFORMER_CLASS",
  46. "Transformer",
  47. WS_SYSMENU|WS_CAPTION|WS_POPUP|WS_OVERLAPPED|WS_BORDER|WS_CLIPSIBLINGS|WS_CHILD,
  48. 0, 0, 200,100,
  49. parent,
  50. NULL,
  51. win32.hInstance,
  52. this );
  53. if ( !mWnd )
  54. {
  55. return false;
  56. }
  57. if ( !gApp.GetOptions().GetWindowPlacement ( "transformer", mWnd ) )
  58. {
  59. RECT rParent;
  60. RECT rTrans;
  61. GetWindowRect ( parent, &rParent );
  62. GetWindowRect ( mWnd, &rTrans );
  63. SetWindowPos ( mWnd, NULL,
  64. rParent.right - 10 - (rTrans.right-rTrans.left),
  65. rParent.bottom - 10 - (rTrans.bottom-rTrans.top),
  66. 0,0,
  67. SWP_NOZORDER|SWP_NOSIZE );
  68. }
  69. Show ( visible );
  70. return true;
  71. }
  72. LRESULT CALLBACK rvGETransformer::WndProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  73. {
  74. rvGETransformer* trans = (rvGETransformer*) GetWindowLong ( hWnd, GWL_USERDATA );
  75. switch ( msg )
  76. {
  77. case WM_NCACTIVATE:
  78. return gApp.ToolWindowActivate ( hWnd, msg, wParam, lParam );
  79. case WM_ACTIVATE:
  80. common->ActivateTool( LOWORD( wParam ) != WA_INACTIVE );
  81. break;
  82. case WM_DESTROY:
  83. gApp.GetOptions().SetWindowPlacement ( "transformer", hWnd );
  84. break;
  85. case WM_ERASEBKGND:
  86. return TRUE;
  87. case WM_CREATE:
  88. {
  89. LPCREATESTRUCT cs;
  90. // Attach the class to the window first
  91. cs = (LPCREATESTRUCT) lParam;
  92. trans = (rvGETransformer*) cs->lpCreateParams;
  93. SetWindowLong ( hWnd, GWL_USERDATA, (LONG)trans );
  94. trans->mWnd = hWnd;
  95. trans->mDlg = CreateDialogParam ( gApp.GetInstance(), MAKEINTRESOURCE(IDD_GUIED_TRANSFORMER),
  96. hWnd, DlgProc, (LPARAM)trans );
  97. RECT rDlg;
  98. RECT rWindow;
  99. RECT rClient;
  100. GetWindowRect ( trans->mWnd, &rWindow );
  101. GetClientRect ( trans->mWnd, &rClient );
  102. GetWindowRect ( trans->mDlg, &rDlg );
  103. SetWindowPos ( trans->mWnd, NULL, 0, 0,
  104. (rWindow.right-rWindow.left)-(rClient.right-rClient.left) + (rDlg.right-rDlg.left),
  105. (rWindow.bottom-rWindow.top)-(rClient.bottom-rClient.top) + (rDlg.bottom-rDlg.top),
  106. SWP_NOZORDER );
  107. ShowWindow ( trans->mDlg, SW_SHOW );
  108. UpdateWindow ( trans->mDlg );
  109. break;
  110. }
  111. }
  112. return DefWindowProc ( hWnd, msg, wParam, lParam );
  113. }
  114. INT_PTR CALLBACK rvGETransformer::DlgProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  115. {
  116. rvGETransformer* trans = (rvGETransformer*) GetWindowLong ( hWnd, GWL_USERDATA );
  117. switch ( msg )
  118. {
  119. case WM_DESTROY:
  120. if ( gTransHook )
  121. {
  122. UnhookWindowsHookEx( gTransHook );
  123. }
  124. gTransDlg = NULL;
  125. break;
  126. case WM_INITDIALOG:
  127. trans = (rvGETransformer*) lParam;
  128. trans->mDlg = hWnd;
  129. SetWindowLong ( hWnd, GWL_USERDATA, lParam );
  130. NumberEdit_Attach ( GetDlgItem ( hWnd, IDC_GUIED_ITEMRECTX ) );
  131. NumberEdit_Attach ( GetDlgItem ( hWnd, IDC_GUIED_ITEMRECTY ) );
  132. NumberEdit_Attach ( GetDlgItem ( hWnd, IDC_GUIED_ITEMRECTW ) );
  133. NumberEdit_Attach ( GetDlgItem ( hWnd, IDC_GUIED_ITEMRECTH ) );
  134. gTransDlg = hWnd;
  135. gTransHook = SetWindowsHookEx( WH_GETMESSAGE, GetMsgProc, NULL, GetCurrentThreadId() );
  136. break;
  137. case WM_COMMAND:
  138. if ( LOWORD ( wParam ) == IDOK )
  139. {
  140. SendMessage ( hWnd, WM_NEXTDLGCTL, 0, 0 );
  141. }
  142. else if ( HIWORD ( wParam ) == EN_KILLFOCUS && trans && trans->mWorkspace )
  143. {
  144. char temp[64];
  145. int value;
  146. GetWindowText ( GetDlgItem ( hWnd, LOWORD(wParam) ), temp, 64 );
  147. value = atoi ( temp );
  148. idRectangle rect = trans->mWorkspace->GetSelectionMgr().GetRect ( );
  149. trans->mWorkspace->WindowToWorkspace ( rect );
  150. // The transformer coords are relative to the botto most selected window's parent so
  151. // adjust the rect accordingly
  152. if ( trans->mRelative )
  153. {
  154. idRectangle& screenRect = rvGEWindowWrapper::GetWrapper ( trans->mRelative )->GetScreenRect ( );
  155. rect.x -= screenRect.x;
  156. rect.y -= screenRect.y;
  157. }
  158. switch ( LOWORD ( wParam ) )
  159. {
  160. case IDC_GUIED_ITEMRECTX:
  161. if ( value - rect[0] )
  162. {
  163. trans->mWorkspace->AddModifierMove ( "Transform Move", value - rect[0], 0, false );
  164. }
  165. break;
  166. case IDC_GUIED_ITEMRECTY:
  167. if ( value - rect[1] )
  168. {
  169. trans->mWorkspace->AddModifierMove ( "Transform Move", 0, value - rect[1], false );
  170. }
  171. break;
  172. case IDC_GUIED_ITEMRECTW:
  173. if ( value - rect[2] )
  174. {
  175. trans->mWorkspace->AddModifierSize ( "Transform Size", 0, 0, value - rect[2], 0, false );
  176. }
  177. break;
  178. case IDC_GUIED_ITEMRECTH:
  179. if ( value - rect[3] )
  180. {
  181. trans->mWorkspace->AddModifierSize ( "Transform Size", 0, 0, 0, value - rect[3], false );
  182. }
  183. break;
  184. }
  185. }
  186. break;
  187. }
  188. return FALSE;
  189. }
  190. /*
  191. ================
  192. rvGETransformer::Show
  193. Shows and hides the transformer window
  194. ================
  195. */
  196. void rvGETransformer::Show ( bool visible )
  197. {
  198. gApp.GetOptions().SetTransformerVisible ( visible );
  199. ShowWindow ( mWnd, visible?SW_SHOW:SW_HIDE );
  200. Update ( );
  201. }
  202. /*
  203. ================
  204. rvGETransformer::SetWorkspace
  205. Sets a new workspace for the transformer window
  206. ================
  207. */
  208. void rvGETransformer::SetWorkspace ( rvGEWorkspace* workspace )
  209. {
  210. mWorkspace = workspace;
  211. Update ( );
  212. }
  213. /*
  214. ================
  215. rvGETransformer::Update
  216. Update the enabled/disabled states based on the selections and update
  217. the rectangle coordinates
  218. ================
  219. */
  220. void rvGETransformer::Update ( void )
  221. {
  222. bool state = false;
  223. mRelative = NULL;
  224. if ( mWorkspace && mWorkspace->GetSelectionMgr ( ).Num ( ) )
  225. {
  226. state = true;
  227. mRelative = mWorkspace->GetSelectionMgr().GetBottomMost ( );
  228. mRelative = mRelative->GetParent ( );
  229. idRectangle rect = mWorkspace->GetSelectionMgr ( ).GetRect ( );
  230. mWorkspace->WindowToWorkspace ( rect );
  231. // Make the rectangle relative to the given parent
  232. if ( mRelative )
  233. {
  234. idRectangle& screenRect = rvGEWindowWrapper::GetWrapper ( mRelative )->GetScreenRect ( );
  235. rect.x -= screenRect.x;
  236. rect.y -= screenRect.y;
  237. }
  238. SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTX ), va("%d",(int)rect[0]) );
  239. SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTY ), va("%d",(int)rect[1]) );
  240. SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTW ), va("%d",(int)rect[2]) );
  241. SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTH ), va("%d",(int)rect[3]) );
  242. }
  243. if ( !state )
  244. {
  245. SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTX ), "" );
  246. SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTY ), "" );
  247. SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTW ), "" );
  248. SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTH ), "" );
  249. }
  250. EnableWindow ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTX ), state );
  251. EnableWindow ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTY ), state );
  252. EnableWindow ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTW ), state );
  253. EnableWindow ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTH ), state );
  254. }
  255. /*
  256. ================
  257. rvGETransformer::GetMsgProc
  258. Ensures normal dialog functions work in the transformer dialog
  259. ================
  260. */
  261. LRESULT FAR PASCAL rvGETransformer::GetMsgProc ( int nCode, WPARAM wParam, LPARAM lParam )
  262. {
  263. LPMSG lpMsg = (LPMSG) lParam;
  264. if ( nCode >= 0 && PM_REMOVE == wParam )
  265. {
  266. // Don't translate non-input events.
  267. if ( lpMsg->message != WM_SYSCHAR && (lpMsg->message >= WM_KEYFIRST && lpMsg->message <= WM_KEYLAST) )
  268. {
  269. if ( IsDialogMessage( gTransDlg, lpMsg) )
  270. {
  271. // The value returned from this hookproc is ignored,
  272. // and it cannot be used to tell Windows the message has been handled.
  273. // To avoid further processing, convert the message to WM_NULL
  274. // before returning.
  275. lpMsg->message = WM_NULL;
  276. lpMsg->lParam = 0;
  277. lpMsg->wParam = 0;
  278. }
  279. }
  280. }
  281. return CallNextHookEx(gTransHook, nCode, wParam, lParam);
  282. }