]> icculus.org git repositories - divverent/netradiant.git/blob - contrib/camera/listener.cpp
256 surfaceparms
[divverent/netradiant.git] / contrib / camera / listener.cpp
1 /*
2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 /*
23 Camera plugin for GtkRadiant
24 Copyright (C) 2002 Splash Damage Ltd.
25 */
26
27 #include "camera.h"
28
29 CListener::CListener()
30 {
31         refCount = 1;
32
33         m_bHooked = FALSE;
34
35   m_bLeftMBPressed = m_bRightMBPressed = m_bMiddleMBPressed = false;
36
37   oldValid = false;
38
39   Register();
40 }
41
42 CListener::~CListener()
43 {
44         UnRegister();
45 }
46
47 void CListener::Register()
48 {
49         g_UITable.m_pfnHookWindow( this );
50   g_pXYWndWrapper = g_UITable.m_pfnGetXYWndWrapper();
51         m_bHooked = TRUE;
52 }
53
54 void CListener::UnRegister()
55 {
56         if(m_bHooked)
57         {
58                 g_UITable.m_pfnUnHookWindow( this );
59     g_pXYWndWrapper= NULL;
60                 m_bHooked = FALSE;
61         }
62 }
63
64 bool CListener::OnMouseMove( unsigned int nFlags, double x, double y )
65 {
66   SetViewType( g_pXYWndWrapper->GetViewType() );
67
68   if( m_bLeftMBPressed && oldValid && g_iEditMode == 0 ) {
69     vec3_t click, delta;
70
71     g_pXYWndWrapper->SnapToGrid( (int)x, (int)y, click );
72
73     switch( m_vt ) {
74     case XY:
75       VectorSet( delta, click[0] - old_x, click[1] - old_y, 0 );
76       old_x = click[0]; old_y = click[1];
77       break;
78     case XZ:
79       VectorSet( delta, click[0] - old_x, 0, click[2] - old_y );
80       old_x = click[0]; old_y = click[2];
81       break;
82     case YZ:
83       VectorSet( delta, 0, click[1] - old_x, click[2] - old_y );
84       old_x = click[1]; old_y = click[2];
85       break;
86     }
87
88     if( g_iActiveTarget < 0 )
89       GetCurrentCam()->GetCam()->getPositionObj()->updateSelection( delta[0], delta[1], delta[2] );
90     else
91       GetCurrentCam()->GetCam()->getActiveTarget(g_iActiveTarget)->updateSelection( delta[0], delta[1], delta[2] );
92
93                 GetCurrentCam()->HasBeenModified();
94
95     g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
96
97     return true;
98   }
99
100   return false;
101 }
102
103 bool CListener::OnLButtonDown( unsigned int nFlags, double x, double y )
104 {
105   SetViewType( g_pXYWndWrapper->GetViewType() );
106
107   m_bLeftMBPressed = true;
108   oldValid = true;
109
110   vec3_t org, delta;
111
112   g_pXYWndWrapper->SnapToGrid( (int)x, (int)y, org );
113
114   switch( m_vt ) {
115   case XY:
116     old_x = org[0]; old_y = org[1]; org[2] = 64*1024;
117     VectorSet( delta, 0, 0, -1 );
118     break;
119   case XZ:
120     old_x = org[0]; old_y = org[2]; org[1] = 64*1024;
121     VectorSet( delta, 0, -1, 0 );
122     break;
123   case YZ:
124     old_x = org[1]; old_y = org[2]; org[0] = 64*1024;
125     VectorSet( delta, -1, 0, 0 );
126     break;
127   }
128
129         if( g_iEditMode == 0 ) {
130                 if( g_iActiveTarget < 0 )
131                         GetCurrentCam()->GetCam()->getPositionObj()->selectPointByRay( org[0], org[1], org[2], delta[0], delta[1], delta[2], true );
132                 else
133                         GetCurrentCam()->GetCam()->getActiveTarget(g_iActiveTarget)->selectPointByRay( org[0], org[1], org[2], delta[0], delta[1], delta[2], true );
134         } else if( g_iEditMode == 1 ) {
135                 idVec3 *lastcoord;
136                 idCameraPosition *camera;
137
138     if( g_iActiveTarget < 0 ) {
139                         camera = GetCurrentCam()->GetCam()->getPositionObj();
140                 } else {
141                         camera = GetCurrentCam()->GetCam()->getActiveTarget(g_iActiveTarget);
142                 }
143
144                 if( camera->numPoints() ) {
145                         lastcoord = camera->getPoint( camera->numPoints() -1 );
146                         switch( m_vt ) {
147                         case XY:
148                                 camera->addPoint( org[0], org[1], lastcoord->z );
149                                 break;
150                         case XZ:
151                                 camera->addPoint( org[0], lastcoord->y, org[2] );
152                                 break;
153                         case YZ:
154                                 camera->addPoint( lastcoord->x, org[1], org[2] );
155                                 break;
156                         }
157                 }       else {
158                         switch( m_vt ) {
159                         case XY:
160                                 camera->addPoint( org[0], org[1], 0 );
161                                 break;
162                         case XZ:
163                                 camera->addPoint( org[0], 0, org[2] );
164                                 break;
165                         case YZ:
166                                 camera->addPoint( 0, org[1], org[2] );
167                                 break;
168                         }
169                 }
170
171                 GetCurrentCam()->HasBeenModified();
172         }
173
174   g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
175
176   return true;
177
178         //return false;
179 }
180
181 bool CListener::OnLButtonUp( unsigned int nFlags, double x, double y )
182 {
183   SetViewType( g_pXYWndWrapper->GetViewType() );
184
185   m_bLeftMBPressed = false;
186   oldValid = false;
187
188         if( g_iEditMode == 0 ) {
189                 if( g_iActiveTarget < 0 )
190                         GetCurrentCam()->GetCam()->getPositionObj()->deselectAll();
191                 else
192                         GetCurrentCam()->GetCam()->getActiveTarget(g_iActiveTarget)->deselectAll();
193
194           g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
195         }
196
197         return false;
198 }
199
200 bool CListener::OnRButtonDown( unsigned int nFlags, double x, double y )
201 {
202   SetViewType( g_pXYWndWrapper->GetViewType() );
203
204   m_bRightMBPressed = true;
205
206         return false;
207 }
208
209 bool CListener::OnRButtonUp( unsigned int nFlags, double x, double y )
210 {
211   SetViewType( g_pXYWndWrapper->GetViewType() );
212
213   m_bRightMBPressed = false;
214
215         return false;
216 }
217
218 bool CListener::OnMButtonDown( unsigned int nFlags, double x, double y )
219 {
220   SetViewType( g_pXYWndWrapper->GetViewType() );
221
222   m_bMiddleMBPressed = true;
223
224         return false;
225 }
226
227 bool CListener::OnMButtonUp( unsigned int nFlags, double x, double y )
228 {
229   SetViewType( g_pXYWndWrapper->GetViewType() );
230
231   m_bMiddleMBPressed = false;
232
233         return false;
234 }