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(){
34 m_bLeftMBPressed = m_bRightMBPressed = m_bMiddleMBPressed = false;
41 CListener::~CListener(){
45 void CListener::Register(){
46 g_UITable.m_pfnHookWindow( this );
47 g_pXYWndWrapper = g_UITable.m_pfnGetXYWndWrapper();
51 void CListener::UnRegister(){
53 g_UITable.m_pfnUnHookWindow( this );
54 g_pXYWndWrapper = NULL;
59 bool CListener::OnMouseMove( unsigned int nFlags, double x, double y ){
60 SetViewType( g_pXYWndWrapper->GetViewType() );
62 if ( m_bLeftMBPressed && oldValid && g_iEditMode == 0 ) {
65 g_pXYWndWrapper->SnapToGrid( (int)x, (int)y, click );
69 VectorSet( delta, click[0] - old_x, click[1] - old_y, 0 );
70 old_x = click[0]; old_y = click[1];
73 VectorSet( delta, click[0] - old_x, 0, click[2] - old_y );
74 old_x = click[0]; old_y = click[2];
77 VectorSet( delta, 0, click[1] - old_x, click[2] - old_y );
78 old_x = click[1]; old_y = click[2];
82 if ( g_iActiveTarget < 0 ) {
83 GetCurrentCam()->GetCam()->getPositionObj()->updateSelection( delta[0], delta[1], delta[2] );
86 GetCurrentCam()->GetCam()->getActiveTarget( g_iActiveTarget )->updateSelection( delta[0], delta[1], delta[2] );
89 GetCurrentCam()->HasBeenModified();
91 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
99 bool CListener::OnLButtonDown( unsigned int nFlags, double x, double y ){
100 SetViewType( g_pXYWndWrapper->GetViewType() );
102 m_bLeftMBPressed = true;
107 g_pXYWndWrapper->SnapToGrid( (int)x, (int)y, org );
111 old_x = org[0]; old_y = org[1]; org[2] = 64 * 1024;
112 VectorSet( delta, 0, 0, -1 );
115 old_x = org[0]; old_y = org[2]; org[1] = 64 * 1024;
116 VectorSet( delta, 0, -1, 0 );
119 old_x = org[1]; old_y = org[2]; org[0] = 64 * 1024;
120 VectorSet( delta, -1, 0, 0 );
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 );
129 GetCurrentCam()->GetCam()->getActiveTarget( g_iActiveTarget )->selectPointByRay( org[0], org[1], org[2], delta[0], delta[1], delta[2], true );
132 else if ( g_iEditMode == 1 ) {
134 idCameraPosition *camera;
136 if ( g_iActiveTarget < 0 ) {
137 camera = GetCurrentCam()->GetCam()->getPositionObj();
140 camera = GetCurrentCam()->GetCam()->getActiveTarget( g_iActiveTarget );
143 if ( camera->numPoints() ) {
144 lastcoord = camera->getPoint( camera->numPoints() - 1 );
147 camera->addPoint( org[0], org[1], lastcoord->z );
150 camera->addPoint( org[0], lastcoord->y, org[2] );
153 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 ){
182 SetViewType( g_pXYWndWrapper->GetViewType() );
184 m_bLeftMBPressed = false;
187 if ( g_iEditMode == 0 ) {
188 if ( g_iActiveTarget < 0 ) {
189 GetCurrentCam()->GetCam()->getPositionObj()->deselectAll();
192 GetCurrentCam()->GetCam()->getActiveTarget( g_iActiveTarget )->deselectAll();
195 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
201 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 ){
210 SetViewType( g_pXYWndWrapper->GetViewType() );
212 m_bRightMBPressed = false;
217 bool CListener::OnMButtonDown( unsigned int nFlags, double x, double y ){
218 SetViewType( g_pXYWndWrapper->GetViewType() );
220 m_bMiddleMBPressed = true;
225 bool CListener::OnMButtonUp( unsigned int nFlags, double x, double y ){
226 SetViewType( g_pXYWndWrapper->GetViewType() );
228 m_bMiddleMBPressed = false;