2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
23 Camera plugin for GtkRadiant
24 Copyright (C) 2002 Splash Damage Ltd.
29 CListener::CListener()
35 m_bLeftMBPressed = m_bRightMBPressed = m_bMiddleMBPressed = false;
42 CListener::~CListener()
47 void CListener::Register()
49 g_UITable.m_pfnHookWindow( this );
50 g_pXYWndWrapper = g_UITable.m_pfnGetXYWndWrapper();
54 void CListener::UnRegister()
58 g_UITable.m_pfnUnHookWindow( this );
59 g_pXYWndWrapper= NULL;
64 bool CListener::OnMouseMove( unsigned int nFlags, double x, double y )
66 SetViewType( g_pXYWndWrapper->GetViewType() );
68 if( m_bLeftMBPressed && oldValid && g_iEditMode == 0 ) {
71 g_pXYWndWrapper->SnapToGrid( (int)x, (int)y, click );
75 VectorSet( delta, click[0] - old_x, click[1] - old_y, 0 );
76 old_x = click[0]; old_y = click[1];
79 VectorSet( delta, click[0] - old_x, 0, click[2] - old_y );
80 old_x = click[0]; old_y = click[2];
83 VectorSet( delta, 0, click[1] - old_x, click[2] - old_y );
84 old_x = click[1]; old_y = click[2];
88 if( g_iActiveTarget < 0 )
89 GetCurrentCam()->GetCam()->getPositionObj()->updateSelection( delta[0], delta[1], delta[2] );
91 GetCurrentCam()->GetCam()->getActiveTarget(g_iActiveTarget)->updateSelection( delta[0], delta[1], delta[2] );
93 GetCurrentCam()->HasBeenModified();
95 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
103 bool CListener::OnLButtonDown( unsigned int nFlags, double x, double y )
105 SetViewType( g_pXYWndWrapper->GetViewType() );
107 m_bLeftMBPressed = true;
112 g_pXYWndWrapper->SnapToGrid( (int)x, (int)y, org );
116 old_x = org[0]; old_y = org[1]; org[2] = 64*1024;
117 VectorSet( delta, 0, 0, -1 );
120 old_x = org[0]; old_y = org[2]; org[1] = 64*1024;
121 VectorSet( delta, 0, -1, 0 );
124 old_x = org[1]; old_y = org[2]; org[0] = 64*1024;
125 VectorSet( delta, -1, 0, 0 );
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 );
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 ) {
136 idCameraPosition *camera;
138 if( g_iActiveTarget < 0 ) {
139 camera = GetCurrentCam()->GetCam()->getPositionObj();
141 camera = GetCurrentCam()->GetCam()->getActiveTarget(g_iActiveTarget);
144 if( camera->numPoints() ) {
145 lastcoord = camera->getPoint( camera->numPoints() -1 );
148 camera->addPoint( org[0], org[1], lastcoord->z );
151 camera->addPoint( org[0], lastcoord->y, org[2] );
154 camera->addPoint( lastcoord->x, org[1], org[2] );
160 camera->addPoint( org[0], org[1], 0 );
163 camera->addPoint( org[0], 0, org[2] );
166 camera->addPoint( 0, org[1], org[2] );
171 GetCurrentCam()->HasBeenModified();
174 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
181 bool CListener::OnLButtonUp( unsigned int nFlags, double x, double y )
183 SetViewType( g_pXYWndWrapper->GetViewType() );
185 m_bLeftMBPressed = false;
188 if( g_iEditMode == 0 ) {
189 if( g_iActiveTarget < 0 )
190 GetCurrentCam()->GetCam()->getPositionObj()->deselectAll();
192 GetCurrentCam()->GetCam()->getActiveTarget(g_iActiveTarget)->deselectAll();
194 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
200 bool CListener::OnRButtonDown( unsigned int nFlags, double x, double y )
202 SetViewType( g_pXYWndWrapper->GetViewType() );
204 m_bRightMBPressed = true;
209 bool CListener::OnRButtonUp( unsigned int nFlags, double x, double y )
211 SetViewType( g_pXYWndWrapper->GetViewType() );
213 m_bRightMBPressed = false;
218 bool CListener::OnMButtonDown( unsigned int nFlags, double x, double y )
220 SetViewType( g_pXYWndWrapper->GetViewType() );
222 m_bMiddleMBPressed = true;
227 bool CListener::OnMButtonUp( unsigned int nFlags, double x, double y )
229 SetViewType( g_pXYWndWrapper->GetViewType() );
231 m_bMiddleMBPressed = false;