doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GETransformer.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 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.
23 
24 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.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "../../sys/win32/rc/guied_resource.h"
33 
34 #include "GEApp.h"
35 #include "../common/MaskEdit.h"
36 
37 HHOOK gTransHook = NULL;
38 HWND gTransDlg = NULL;
39 
41 {
42  mWnd = NULL;
43  mWorkspace = NULL;
44 }
45 
46 bool rvGETransformer::Create ( HWND parent, bool visible )
47 {
48  WNDCLASSEX wndClass;
49  memset ( &wndClass, 0, sizeof(wndClass) );
50  wndClass.cbSize = sizeof(WNDCLASSEX);
51  wndClass.lpszClassName = "GUIEDITOR_TRANSFORMER_CLASS";
52  wndClass.lpfnWndProc = rvGETransformer::WndProc;
53  wndClass.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH );;
54  wndClass.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
55  wndClass.lpszMenuName = NULL;
56  wndClass.hInstance = win32.hInstance;
57  RegisterClassEx ( &wndClass );
58 
59  mWnd = CreateWindowEx ( WS_EX_TOOLWINDOW,
60  "GUIEDITOR_TRANSFORMER_CLASS",
61  "Transformer",
62  WS_SYSMENU|WS_CAPTION|WS_POPUP|WS_OVERLAPPED|WS_BORDER|WS_CLIPSIBLINGS|WS_CHILD,
63  0, 0, 200,100,
64  parent,
65  NULL,
67  this );
68 
69  if ( !mWnd )
70  {
71  return false;
72  }
73 
74  if ( !gApp.GetOptions().GetWindowPlacement ( "transformer", mWnd ) )
75  {
76  RECT rParent;
77  RECT rTrans;
78 
79  GetWindowRect ( parent, &rParent );
80  GetWindowRect ( mWnd, &rTrans );
81  SetWindowPos ( mWnd, NULL,
82  rParent.right - 10 - (rTrans.right-rTrans.left),
83  rParent.bottom - 10 - (rTrans.bottom-rTrans.top),
84  0,0,
85  SWP_NOZORDER|SWP_NOSIZE );
86  }
87 
88  Show ( visible );
89 
90  return true;
91 }
92 
93 LRESULT CALLBACK rvGETransformer::WndProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
94 {
95  rvGETransformer* trans = (rvGETransformer*) GetWindowLong ( hWnd, GWL_USERDATA );
96 
97  switch ( msg )
98  {
99  case WM_NCACTIVATE:
100  return gApp.ToolWindowActivate ( hWnd, msg, wParam, lParam );
101 
102  case WM_ACTIVATE:
103  common->ActivateTool( LOWORD( wParam ) != WA_INACTIVE );
104  break;
105 
106  case WM_DESTROY:
107  gApp.GetOptions().SetWindowPlacement ( "transformer", hWnd );
108  break;
109 
110  case WM_ERASEBKGND:
111  return TRUE;
112 
113  case WM_CREATE:
114  {
115  LPCREATESTRUCT cs;
116 
117  // Attach the class to the window first
118  cs = (LPCREATESTRUCT) lParam;
119  trans = (rvGETransformer*) cs->lpCreateParams;
120  SetWindowLong ( hWnd, GWL_USERDATA, (LONG)trans );
121 
122  trans->mWnd = hWnd;
123  trans->mDlg = CreateDialogParam ( gApp.GetInstance(), MAKEINTRESOURCE(IDD_GUIED_TRANSFORMER),
124  hWnd, DlgProc, (LPARAM)trans );
125 
126  RECT rDlg;
127  RECT rWindow;
128  RECT rClient;
129 
130  GetWindowRect ( trans->mWnd, &rWindow );
131  GetClientRect ( trans->mWnd, &rClient );
132  GetWindowRect ( trans->mDlg, &rDlg );
133 
134  SetWindowPos ( trans->mWnd, NULL, 0, 0,
135  (rWindow.right-rWindow.left)-(rClient.right-rClient.left) + (rDlg.right-rDlg.left),
136  (rWindow.bottom-rWindow.top)-(rClient.bottom-rClient.top) + (rDlg.bottom-rDlg.top),
137  SWP_NOZORDER );
138 
139  ShowWindow ( trans->mDlg, SW_SHOW );
140  UpdateWindow ( trans->mDlg );
141 
142  break;
143  }
144  }
145 
146  return DefWindowProc ( hWnd, msg, wParam, lParam );
147 }
148 
149 INT_PTR CALLBACK rvGETransformer::DlgProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
150 {
151  rvGETransformer* trans = (rvGETransformer*) GetWindowLong ( hWnd, GWL_USERDATA );
152 
153  switch ( msg )
154  {
155  case WM_DESTROY:
156  if ( gTransHook )
157  {
158  UnhookWindowsHookEx( gTransHook );
159  }
160  gTransDlg = NULL;
161  break;
162 
163  case WM_INITDIALOG:
164  trans = (rvGETransformer*) lParam;
165  trans->mDlg = hWnd;
166  SetWindowLong ( hWnd, GWL_USERDATA, lParam );
167  NumberEdit_Attach ( GetDlgItem ( hWnd, IDC_GUIED_ITEMRECTX ) );
168  NumberEdit_Attach ( GetDlgItem ( hWnd, IDC_GUIED_ITEMRECTY ) );
169  NumberEdit_Attach ( GetDlgItem ( hWnd, IDC_GUIED_ITEMRECTW ) );
170  NumberEdit_Attach ( GetDlgItem ( hWnd, IDC_GUIED_ITEMRECTH ) );
171  gTransDlg = hWnd;
172  gTransHook = SetWindowsHookEx( WH_GETMESSAGE, GetMsgProc, NULL, GetCurrentThreadId() );
173  break;
174 
175  case WM_COMMAND:
176  if ( LOWORD ( wParam ) == IDOK )
177  {
178  SendMessage ( hWnd, WM_NEXTDLGCTL, 0, 0 );
179  }
180  else if ( HIWORD ( wParam ) == EN_KILLFOCUS && trans && trans->mWorkspace )
181  {
182  char temp[64];
183  int value;
184  GetWindowText ( GetDlgItem ( hWnd, LOWORD(wParam) ), temp, 64 );
185  value = atoi ( temp );
186 
187  idRectangle rect = trans->mWorkspace->GetSelectionMgr().GetRect ( );
188  trans->mWorkspace->WindowToWorkspace ( rect );
189 
190  // The transformer coords are relative to the botto most selected window's parent so
191  // adjust the rect accordingly
192  if ( trans->mRelative )
193  {
195  rect.x -= screenRect.x;
196  rect.y -= screenRect.y;
197  }
198 
199  switch ( LOWORD ( wParam ) )
200  {
201  case IDC_GUIED_ITEMRECTX:
202  if ( value - rect[0] )
203  {
204  trans->mWorkspace->AddModifierMove ( "Transform Move", value - rect[0], 0, false );
205  }
206  break;
207 
208  case IDC_GUIED_ITEMRECTY:
209  if ( value - rect[1] )
210  {
211  trans->mWorkspace->AddModifierMove ( "Transform Move", 0, value - rect[1], false );
212  }
213  break;
214 
215  case IDC_GUIED_ITEMRECTW:
216  if ( value - rect[2] )
217  {
218  trans->mWorkspace->AddModifierSize ( "Transform Size", 0, 0, value - rect[2], 0, false );
219  }
220  break;
221 
222  case IDC_GUIED_ITEMRECTH:
223  if ( value - rect[3] )
224  {
225  trans->mWorkspace->AddModifierSize ( "Transform Size", 0, 0, 0, value - rect[3], false );
226  }
227  break;
228  }
229  }
230  break;
231  }
232 
233  return FALSE;
234 }
235 
236 /*
237 ================
238 rvGETransformer::Show
239 
240 Shows and hides the transformer window
241 ================
242 */
243 void rvGETransformer::Show ( bool visible )
244 {
245  gApp.GetOptions().SetTransformerVisible ( visible );
246  ShowWindow ( mWnd, visible?SW_SHOW:SW_HIDE );
247  Update ( );
248 }
249 
250 /*
251 ================
252 rvGETransformer::SetWorkspace
253 
254 Sets a new workspace for the transformer window
255 ================
256 */
258 {
259  mWorkspace = workspace;
260 
261  Update ( );
262 }
263 
264 /*
265 ================
266 rvGETransformer::Update
267 
268 Update the enabled/disabled states based on the selections and update
269 the rectangle coordinates
270 ================
271 */
273 {
274  bool state = false;
275 
276  mRelative = NULL;
277 
278  if ( mWorkspace && mWorkspace->GetSelectionMgr ( ).Num ( ) )
279  {
280  state = true;
283 
285  mWorkspace->WindowToWorkspace ( rect );
286 
287  // Make the rectangle relative to the given parent
288  if ( mRelative )
289  {
291  rect.x -= screenRect.x;
292  rect.y -= screenRect.y;
293  }
294 
295  SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTX ), va("%d",(int)rect[0]) );
296  SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTY ), va("%d",(int)rect[1]) );
297  SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTW ), va("%d",(int)rect[2]) );
298  SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTH ), va("%d",(int)rect[3]) );
299  }
300 
301  if ( !state )
302  {
303  SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTX ), "" );
304  SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTY ), "" );
305  SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTW ), "" );
306  SetWindowText ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTH ), "" );
307  }
308 
309  EnableWindow ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTX ), state );
310  EnableWindow ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTY ), state );
311  EnableWindow ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTW ), state );
312  EnableWindow ( GetDlgItem ( mDlg, IDC_GUIED_ITEMRECTH ), state );
313 }
314 
315 /*
316 ================
317 rvGETransformer::GetMsgProc
318 
319 Ensures normal dialog functions work in the transformer dialog
320 ================
321 */
322 LRESULT FAR PASCAL rvGETransformer::GetMsgProc ( int nCode, WPARAM wParam, LPARAM lParam )
323 {
324  LPMSG lpMsg = (LPMSG) lParam;
325 
326  if ( nCode >= 0 && PM_REMOVE == wParam )
327  {
328  // Don't translate non-input events.
329  if ( lpMsg->message != WM_SYSCHAR && (lpMsg->message >= WM_KEYFIRST && lpMsg->message <= WM_KEYLAST) )
330  {
331  if ( IsDialogMessage( gTransDlg, lpMsg) )
332  {
333  // The value returned from this hookproc is ignored,
334  // and it cannot be used to tell Windows the message has been handled.
335  // To avoid further processing, convert the message to WM_NULL
336  // before returning.
337  lpMsg->message = WM_NULL;
338  lpMsg->lParam = 0;
339  lpMsg->wParam = 0;
340  }
341  }
342  }
343 
344  return CallNextHookEx(gTransHook, nCode, wParam, lParam);
345 }
#define IDD_GUIED_TRANSFORMER
GLsizei const GLfloat * value
Definition: glext.h:3614
CPropTreeItem LPARAM
Definition: PropTree.h:70
void SetTransformerVisible(bool vis)
Definition: GEOptions.h:202
static INT_PTR CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
idWindow * mRelative
Definition: GETransformer.h:51
idWindow * GetBottomMost(void)
void SetWindowPlacement(const char *name, HWND hwnd)
Definition: GEOptions.h:288
HHOOK gTransHook
bool GetWindowPlacement(const char *name, HWND hwnd)
Definition: GEOptions.h:293
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
rvGEWorkspace * mWorkspace
Definition: GETransformer.h:50
HINSTANCE GetInstance(void)
Definition: GEApp.h:168
rvGEApp gApp
Definition: guied.cpp:41
void Show(bool show)
rvGEOptions & GetOptions(void)
Definition: GEApp.h:163
void SetWorkspace(rvGEWorkspace *workspace)
float y
Definition: Rectangle.h:37
idCommon * common
Definition: Common.cpp:206
#define NULL
Definition: Lib.h:88
idRectangle & GetScreenRect(void)
#define IDC_GUIED_ITEMRECTW
#define FAR
Definition: jmorecfg.h:205
HWND gTransDlg
#define IDC_GUIED_ITEMRECTH
rvGESelectionMgr & GetSelectionMgr(void)
Definition: GEWorkspace.h:293
#define IDC_GUIED_ITEMRECTX
float x
Definition: Rectangle.h:36
idRectangle & GetRect(void)
int ToolWindowActivate(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: GEApp.cpp:1335
long LONG
static rvGEWindowWrapper * GetWrapper(idWindow *window)
void AddModifierSize(const char *modName, float l, float t, float r, float b, bool snap)
bool Create(HWND parent, bool visible)
idVec2 & WindowToWorkspace(idVec2 &point)
void NumberEdit_Attach(HWND hWnd)
Definition: MaskEdit.cpp:93
#define FALSE
Definition: mprintf.c:70
void AddModifierMove(const char *modName, float x, float y, bool snap)
#define TRUE
Definition: mprintf.c:69
HINSTANCE hInstance
Definition: win_local.h:102
char * va(const char *fmt,...)
Definition: Str.cpp:1568
Win32Vars_t win32
Definition: win_main.cpp:65
virtual void ActivateTool(bool active)=0
static LRESULT FAR PASCAL GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
idWindow * GetParent()
Definition: Window.h:224
#define IDC_GUIED_ITEMRECTY