Debian Codegraph @

contrib/camera/listener.cpp

raw symbols SCIP
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 refCount = 1;
31
32 m_bHooked = FALSE;
33
34 m_bLeftMBPressed = m_bRightMBPressed = m_bMiddleMBPressed = false;
35
36 oldValid = false;
37
38 Register();
39 }
40
41 CListener::~CListener(){
42 UnRegister();
43 }
44
45 void CListener::Register(){
46 g_UITable.m_pfnHookWindow( this );
47 g_pXYWndWrapper = g_UITable.m_pfnGetXYWndWrapper();
48 m_bHooked = TRUE;
49 }
50
51 void CListener::UnRegister(){
52 if ( m_bHooked ) {
53 g_UITable.m_pfnUnHookWindow( this );
54 g_pXYWndWrapper = NULL;
55 m_bHooked = FALSE;
56 }
57 }
58
59 bool CListener::OnMouseMove( unsigned int nFlags, double x, double y ){
60 SetViewType( g_pXYWndWrapper->GetViewType() );
61
62 if ( m_bLeftMBPressed && oldValid && g_iEditMode == 0 ) {
63 vec3_t click, delta;
64
65 g_pXYWndWrapper->SnapToGrid( (int)x, (int)y, click );
66
67 switch ( m_vt ) {
68 case XY:
69 VectorSet( delta, click[0] - old_x, click[1] - old_y, 0 );
70 old_x = click[0]; old_y = click[1];
71 break;
72 case XZ:
73 VectorSet( delta, click[0] - old_x, 0, click[2] - old_y );
74 old_x = click[0]; old_y = click[2];
75 break;
76 case YZ:
77 VectorSet( delta, 0, click[1] - old_x, click[2] - old_y );
78 old_x = click[1]; old_y = click[2];
79 break;
80 }
81
82 if ( g_iActiveTarget < 0 ) {
83 GetCurrentCam()->GetCam()->getPositionObj()->updateSelection( delta[0], delta[1], delta[2] );
84 }
85 else{
86 GetCurrentCam()->GetCam()->getActiveTarget( g_iActiveTarget )->updateSelection( delta[0], delta[1], delta[2] );
87 }
88
89 GetCurrentCam()->HasBeenModified();
90
91 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
92
93 return true;
94 }
95
96 return false;
97 }
98
99 bool CListener::OnLButtonDown( unsigned int nFlags, double x, double y ){
100 SetViewType( g_pXYWndWrapper->GetViewType() );
101
102 m_bLeftMBPressed = true;
103 oldValid = true;
104
105 vec3_t org, delta;
106
107 g_pXYWndWrapper->SnapToGrid( (int)x, (int)y, org );
108
109 switch ( m_vt ) {
110 case XY:
111 old_x = org[0]; old_y = org[1]; org[2] = 64 * 1024;
112 VectorSet( delta, 0, 0, -1 );
113 break;
114 case XZ:
115 old_x = org[0]; old_y = org[2]; org[1] = 64 * 1024;
116 VectorSet( delta, 0, -1, 0 );
117 break;
118 case YZ:
119 old_x = org[1]; old_y = org[2]; org[0] = 64 * 1024;
120 VectorSet( delta, -1, 0, 0 );
121 break;
122 }
123
124 if ( g_iEditMode == 0 ) {
125 if ( g_iActiveTarget < 0 ) {
126 GetCurrentCam()->GetCam()->getPositionObj()->selectPointByRay( org[0], org[1], org[2], delta[0], delta[1], delta[2], true );
127 }
128 else{
129 GetCurrentCam()->GetCam()->getActiveTarget( g_iActiveTarget )->selectPointByRay( org[0], org[1], org[2], delta[0], delta[1], delta[2], true );
130 }
131 }
132 else if ( g_iEditMode == 1 ) {
133 idVec3 *lastcoord;
134 idCameraPosition *camera;
135
136 if ( g_iActiveTarget < 0 ) {
137 camera = GetCurrentCam()->GetCam()->getPositionObj();
138 }
139 else {
140 camera = GetCurrentCam()->GetCam()->getActiveTarget( g_iActiveTarget );
141 }
142
143 if ( camera->numPoints() ) {
144 lastcoord = camera->getPoint( camera->numPoints() - 1 );
145 switch ( m_vt ) {
146 case XY:
147 camera->addPoint( org[0], org[1], lastcoord->z );
148 break;
149 case XZ:
150 camera->addPoint( org[0], lastcoord->y, org[2] );
151 break;
152 case YZ:
153 camera->addPoint( lastcoord->x, org[1], org[2] );
154 break;
155 }
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 SetViewType( g_pXYWndWrapper->GetViewType() );
183
184 m_bLeftMBPressed = false;
185 oldValid = false;
186
187 if ( g_iEditMode == 0 ) {
188 if ( g_iActiveTarget < 0 ) {
189 GetCurrentCam()->GetCam()->getPositionObj()->deselectAll();
190 }
191 else{
192 GetCurrentCam()->GetCam()->getActiveTarget( g_iActiveTarget )->deselectAll();
193 }
194
195 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
196 }
197
198 return false;
199 }
200
201 bool CListener::OnRButtonDown( unsigned int nFlags, double x, double y ){
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 SetViewType( g_pXYWndWrapper->GetViewType() );
211
212 m_bRightMBPressed = false;
213
214 return false;
215 }
216
217 bool CListener::OnMButtonDown( unsigned int nFlags, double x, double y ){
218 SetViewType( g_pXYWndWrapper->GetViewType() );
219
220 m_bMiddleMBPressed = true;
221
222 return false;
223 }
224
225 bool CListener::OnMButtonUp( unsigned int nFlags, double x, double y ){
226 SetViewType( g_pXYWndWrapper->GetViewType() );
227
228 m_bMiddleMBPressed = false;
229
230 return false;
231 }