#include <direct.h>

#include "stdafx.h"
#include "acp_base.h"
#include "geo.h"
#include "gli.h"
#include "ITF.h"
#include "caminter.hpp"
#include "camresrc.h"


//Keyboard constants
enum{	KA_RotateX = 1,
		KA_RotateY,
		KA_RotateZ,
		KA_InvRotateX,
		KA_InvRotateY,
		KA_InvRotateZ,
		KA_MoveX,
		KA_MoveY,
		KA_MoveZ,
		KA_InvMoveX,
		KA_InvMoveY,
		KA_InvMoveZ,
		KA_IncreaseTStep,
		KA_DecreaseTStep,
		KA_FrontView,
		KA_BackView,
		KA_RightView,
		KA_LeftView,
		KA_TopView,
		KA_BottomView,
		KA_ToggleTargetSO,
		KA_ToggleTargetPoint,
		KA_TargetSO,
//CPA2 Corneliu Babiuc 15-05-98
		KA_ZoomSO,
		KA_CenterSO,
		KA_EasyPointTarget,
		KA_NotTargeted,
		KA_AutoTarget,
		KA_AutoZoom,
		KA_PutCameraInEmptySlot,
		KA_GetSlot1,
		KA_GetSlot2,
		KA_GetSlot3,
		KA_GetSlot4,
		KA_GetSlot5,
		KA_GetSlot6,
		KA_GetSlot7,
		KA_GetSlot8,
		KA_GetSlot9
//END CPA2 Corneliu Babiuc 15-05-98
	};


static tdstKeyboardActionDef gs_a_stCameraKeys[] =
{
	{"Turn right (Y axis)",					KA_InvRotateY},
	{"Turn left (Y axis)",					KA_RotateY},
	{"Look up (X axis)",					KA_InvRotateX},
	{"Look down (X axis)",					KA_RotateX},
	{"Twist clockwise (Z axis)",			KA_RotateZ},
	{"Twist counter-clockwise (Z axis)",	KA_InvRotateZ},
	{"Move left (X+)",						KA_MoveX},
	{"Move right (X-)",						KA_InvMoveX},
	{"Move up (Y+)",						KA_MoveY},
	{"Move down (Y-)",						KA_InvMoveY},
	{"Move forward (Z+)",					KA_MoveZ},
	{"Move backward (Z-)",					KA_InvMoveZ},
	{"Increase Translation Step",			KA_IncreaseTStep},
	{"Decrease Translation Step",			KA_DecreaseTStep},
	{"Front View",							KA_FrontView},
	{"Back View",							KA_BackView},
	{"Left View",							KA_LeftView},
	{"Right View",							KA_RightView},
	{"Top View",							KA_TopView},
	{"Bottom View",							KA_BottomView},
	{"Toggle SuperObject Targeted",			KA_ToggleTargetSO},
	{"Toggle Point Targeted",				KA_ToggleTargetPoint},
	{"Target Selected Object",				KA_TargetSO},
	{"Center Selected Object",				KA_CenterSO},
	{"Zoom Selected Object",				KA_ZoomSO},
	{"Easy Point Target",					KA_EasyPointTarget},
	{"Camera Not Targeted",					KA_NotTargeted},
	{"AutoTarget",							KA_AutoTarget},
	{"AutoZoom",							KA_AutoZoom},
	{"Put Camera in empty slot ",			KA_PutCameraInEmptySlot},
	{"Get Slot 1",							KA_GetSlot1},
	{"Get Slot 2",							KA_GetSlot2},
	{"Get Slot 3",							KA_GetSlot3},
	{"Get Slot 4",							KA_GetSlot4},
	{"Get Slot 5",							KA_GetSlot5},
	{"Get Slot 6",							KA_GetSlot6},
	{"Get Slot 7",							KA_GetSlot7},
	{"Get Slot 8",							KA_GetSlot8},
	{"Get Slot 9",							KA_GetSlot9},
	{NULL, 0}
};


//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
void Camera_Interface::InitKeyboard()
{
    m_p_oKeyConfiguration = new CPA_KeyActionConfiguration("camera\\camera.ini", gs_a_stCameraKeys);
    m_p_oKeyConfiguration->mfn_vSetObjectName("Camera Editor");
}



//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
BOOL Camera_Interface::SendKeyDownToCamera (CPA_BaseObject *p_oCamera, UINT nChar, UINT nRepCnt, UINT nFlags)
{
	ASSERT(p_oCamera != NULL);
	ASSERT(p_oCamera->fn_bIsOfType(C_szCameraObjectTypeName));

	// Camera Rotation.
	if (KeyRotateCamera((Camera*)p_oCamera,nChar,(nRepCnt != 1)))
	{
		GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
		if (GetInterface()->GetStatusBarMode() == E_sb_CameraInfo)
			((Camera*)p_oCamera)->GetViewport()->fn_vUpdateStatusBarMessage();
		return TRUE;
	}
	
	// Camera Move.
	if (KeyMoveCamera((Camera*)p_oCamera,nChar,(nRepCnt != 1)))
	{
		GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
		if (GetInterface()->GetStatusBarMode() == E_sb_CameraInfo)
			((Camera*)p_oCamera)->GetViewport()->fn_vUpdateStatusBarMessage();
		return TRUE;
	}

	// Camera Move.
	if (KeyViewCamera((Camera*)p_oCamera,nChar))
	{
		GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
		if (GetInterface()->GetStatusBarMode() == E_sb_CameraInfo)
			((Camera*)p_oCamera)->GetViewport()->fn_vUpdateStatusBarMessage();
		return TRUE;
	}

	// Camera Move.
	if (KeyOtherActions((Camera*)p_oCamera,nChar))
	{
		GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
		if (GetInterface()->GetStatusBarMode() == E_sb_CameraInfo)
			((Camera*)p_oCamera)->GetViewport()->fn_vUpdateStatusBarMessage();
		return TRUE;
	}

	return FALSE;
}




//==================================================================================================
//==================================================================================================
//==================================================================================================
//==================================================================================================
//================ P R I V A T E ===================================================================
//==================================================================================================
//==================================================================================================
BOOL Camera_Interface::KeyRotateCamera(Camera *p_oCamera, UINT nChar, BOOL bRepeat)
{
	switch (m_p_oKeyConfiguration->mfn_uwKeyToAction(nChar))
	{
	case KA_RotateX :
			p_oCamera->Rotate(X_Custom, m_fRotationStep);
		return TRUE;
		break;
		
	case KA_InvRotateX :
			p_oCamera->Rotate(X_Custom, -m_fRotationStep);
		return TRUE;
		break;
		
	case KA_RotateY :
		p_oCamera->Rotate(Y_Custom, m_fRotationStep);
		return TRUE;
		break;
		
	case KA_InvRotateY :
		p_oCamera->Rotate(Y_Custom, -m_fRotationStep);
		return TRUE;
		break;
		
	case KA_RotateZ :
		p_oCamera->Rotate(Z_Custom, m_fRotationStep);
		return TRUE;
		break;
		
	case KA_InvRotateZ :
		p_oCamera->Rotate(Z_Custom, -m_fRotationStep);
		return TRUE;
		break;
	}
	return FALSE;
}

		

//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
BOOL Camera_Interface::KeyMoveCamera(Camera *p_oCamera, UINT nChar, BOOL bRepeat)
{
	CPA_CameraCoords oCoords;

	switch (m_p_oKeyConfiguration->mfn_uwKeyToAction(nChar))
	{
	case KA_MoveX :
		if (p_oCamera->GetTargetType() != tNone && p_oCamera->GetTranslationAxisSystem() != WorldCoordinates)
		{
			//we have a target, so we rotate
			p_oCamera->Rotate(Y_Custom, m_fRotationStep);
		}
		else
		{
			oCoords.SetXYZ(m_fTranslationStep,0,0);
			p_oCamera->Translate(&oCoords,TRUE);
		}
		return TRUE;
		break;
		
	case KA_InvMoveX :
		if (p_oCamera->GetTargetType() != tNone && p_oCamera->GetTranslationAxisSystem() != WorldCoordinates)
		{
			//we have a target, so we rotate
			p_oCamera->Rotate(Y_Custom, -m_fRotationStep);
		}
		else
		{
			oCoords.SetXYZ(-m_fTranslationStep,0,0);
			p_oCamera->Translate(&oCoords,TRUE);
		}
		return TRUE;
		break;
		
	case KA_MoveY :
		if (p_oCamera->GetTargetType() != tNone && p_oCamera->GetTranslationAxisSystem() != WorldCoordinates)
		{
			//we have a target, so we rotate
			p_oCamera->Rotate(X_Custom, m_fRotationStep);
		}
		else
		{
			oCoords.SetXYZ(0,m_fTranslationStep,0);
			p_oCamera->Translate(&oCoords,TRUE);
		}
		return TRUE;
		break;
		
	case KA_InvMoveY :
		if (p_oCamera->GetTargetType() != tNone && p_oCamera->GetTranslationAxisSystem() != WorldCoordinates)
		{
			//we have a target, so we rotate
			p_oCamera->Rotate(X_Custom, -m_fRotationStep);
		}
		else
		{
			oCoords.SetXYZ(0,-m_fTranslationStep,0);
			p_oCamera->Translate(&oCoords,TRUE);
		}
		return TRUE;
		break;
		
	case KA_MoveZ :
		oCoords.SetXYZ(0,0,m_fTranslationStep);
		p_oCamera->Translate(&oCoords,TRUE);
		return TRUE;
		break;
		
	case KA_InvMoveZ :
		oCoords.SetXYZ(0,0,-m_fTranslationStep);
		p_oCamera->Translate(&oCoords,TRUE);
		return TRUE;
		break;
	}
	return FALSE;
}



//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
BOOL Camera_Interface::KeyOtherActions(Camera *p_oCamera, UINT nChar)
{
	CPA_SuperObject *p_oSelection;

	switch (m_p_oKeyConfiguration->mfn_uwKeyToAction(nChar))
	{

	case KA_IncreaseTStep :
		m_fTranslationStep = m_fTranslationStep * 10.0;
		if (m_fTranslationStep == 0)
			m_fTranslationStep = 0.001;
		if (m_fTranslationStep > 10000)
			m_fTranslationStep = 10000;
		return TRUE;
	case KA_DecreaseTStep :
		m_fTranslationStep = m_fTranslationStep / 10.0;
		if (m_fTranslationStep < 0.001)
			m_fTranslationStep = 0.001;
		return TRUE;
	case KA_TargetSO :
		// get the selected superobject
		p_oSelection = GetInterface()->GetCurrentWorld()->GetSingleSelection();
		if (p_oSelection == NULL)
		{
			M_GetMainWnd()->UpdateStatus("there is no valid selection to target",C_STATUSPANE_INFOS,C_STATUS_WARNING);
			return TRUE;
		}
		p_oCamera->SetTargetSuperObject(p_oSelection);
		p_oCamera->SetTargetType(tSuperObject);
		p_oCamera->Update();
		return TRUE;
		break;

	case KA_ToggleTargetSO :
		if (p_oCamera->GetTargetType() != tSuperObject)
		{
			BOOL bResult;
			bResult = p_oCamera->SetTargetType(tSuperObject);
			if (!bResult)
			{
				M_GetMainWnd()->UpdateStatus("there is no valid target in this camera",C_STATUSPANE_INFOS,C_STATUS_WARNING);
			}
			else
			{
				p_oCamera->Update();
			}
			return TRUE;
		}
		p_oCamera->SetTargetType(tNone);
		return TRUE;
		break;

	case KA_ToggleTargetPoint :
		if (p_oCamera->GetTargetType() != tPoint)
		{
			p_oCamera->SetTargetType(tPoint);
			return TRUE;
		}
		p_oCamera->SetTargetType(tNone);
		return TRUE;
		break;

//CPA2 Corneliu Babiuc 15-05-98
	// center camera on object
	case KA_CenterSO:
		p_oSelection = GetInterface()->GetCurrentWorld()->GetSingleSelection();
		if (p_oSelection != NULL)
		{
			p_oCamera->SetTargetSuperObject(p_oSelection);
			p_oCamera->SetTargetType(tSuperObject);
			p_oCamera->Update();
			p_oCamera->SetTargetType(tNone);
			GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
		}
		return TRUE;

	case KA_ZoomSO:
		p_oSelection = GetInterface()->GetCurrentWorld()->GetSingleSelection();
		if (p_oSelection != NULL)
		{
			p_oCamera->ZoomOnTarget(p_oSelection);
			GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
		}
		else if (p_oCamera->GetTargetType() == tSuperObject)
		{
			p_oCamera->ZoomOnTarget();
			GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
		}
		return TRUE;

	case KA_EasyPointTarget:
		ChangeCameraTarget();
		return TRUE;
	
	case KA_NotTargeted:
		p_oCamera->SetTargetType(tNone);
		return TRUE;

	
	case KA_AutoTarget:
		GetInterface()->SetAutoTarget(!GetInterface()->fn_bAutoTarget());
		return TRUE;
	case KA_AutoZoom:
		GetInterface()->SetAutoZoom(!GetInterface()->fn_bAutoZoom());
		return TRUE;
	
	
	case KA_PutCameraInEmptySlot:
		{
//Stefan Dumitrean 22-06-98 ( slots )
			CPA_CameraSlots * p_oCameraSlot = GetMainWorld()->GetWorld()->GetCameraSlots();
			//save camera in empty slot
			long lSlotNum = p_oCameraSlot->SaveCameraInSlot(-1,"",p_oCamera,MakeACopy);

			// normal slot : save the camera position in the current slot
			if (!p_oCameraSlot->IsSpecialSlot( p_oCameraSlot->GetCurrentSlot()))
				p_oCameraSlot->SaveCameraInSlot(p_oCameraSlot->GetCurrentSlot(),"",p_oCamera,MakeACopy);
			// special slot : save in empty slot
			else
			{	
				if (AfxMessageBox("The current slot is the default one. \n Do you want to save it in a new slot ?",
									MB_ICONWARNING|MB_OKCANCEL) == IDOK)
				{
					Camera_NewSlot	oDialog;
					CString			csName;
					long			lNewSlot = p_oCameraSlot->FindFirstEmptySlot();

					csName.Format("Default Slot %i", lNewSlot);

					// call dialog to find new name
					if (oDialog.fn_iDoDialog(csName, TRUE) == IDOK)
					{
						if( lNewSlot >= 0 )
							p_oCameraSlot->SaveCameraInSlot(lNewSlot,oDialog.GetName(),p_oCamera,MakeACopy);
						else
							p_oCameraSlot->SaveCameraInSlot(-1,oDialog.GetName(),p_oCamera,MakeACopy);
						
						// set new current slot
						p_oCameraSlot->SetCurrentSlot(lNewSlot);				
					}
				}
			}
			if (p_oCameraSlot->IsSpecialSlot(lSlotNum)  || !p_oCameraSlot->IsSlotReserved(lSlotNum))
				p_oCameraSlot->SetCurrentSlot(lSlotNum);				

//End Stefan Dumitrean 22-06-98 ( slots )

		//save slots positions in .ECA file
			SaveSlotsPositions();
			return TRUE;
		}
	case KA_GetSlot1:
	case KA_GetSlot2:
	case KA_GetSlot3:
	case KA_GetSlot4:
	case KA_GetSlot5:
	case KA_GetSlot6:
	case KA_GetSlot7:
	case KA_GetSlot9:
		//get camera slots
		CPA_CameraSlots * p_oCameraSlot = GetMainWorld()->GetWorld()->GetCameraSlots();
		//get the number of slot
		long lSlotNumber = m_p_oKeyConfiguration->mfn_uwKeyToAction(nChar) - KA_PutCameraInEmptySlot;
		//if the slot is not empty restore camera
		if (! p_oCameraSlot->IsEmpty(lSlotNumber) )
		{
			(Camera *) p_oCamera = (Camera*)p_oCameraSlot->GetCameraFromSlot(lSlotNumber,MakeACopy);
			//and set this new camera in the focus viewport
			// the old camera (if any) is totally destroyed
			if (p_oCamera != NULL)
			{
				CPA_SuperObject *p_oCameraSO,*p_oOldCameraSO;

				//get or build a superobject for this camera
//Stefan Dumitrean 29-06-98 ( slots )
				DEV_ViewPort3D * p_oViewPort = (DEV_ViewPort3D*)(M_GetMainDeviceNum(0)->GetViewPort());

				if( p_oCameraSlot->IsSpecialSlot( lSlotNumber ) )
					p_oOldCameraSO = p_oViewPort->GetCameraSO();
				else
				{
					p_oCameraSO = AssociateSuperObject(p_oCamera);
					p_oOldCameraSO = p_oViewPort->ChangeCamera(p_oCameraSO);
				}
//End Stefan Dumitrean 29-06-98 ( slots )

//Stefan Dumitrean 22-06-98 ( slots )
				// normal slot : save the camera position in the current slot
				if (!p_oCameraSlot->IsSpecialSlot( p_oCameraSlot->GetCurrentSlot()))
					p_oCameraSlot->SaveCameraInSlot(p_oCameraSlot->GetCurrentSlot(),"",p_oOldCameraSO->GetObject(),MakeACopy);
				// special slot : save in empty slot
				else
				{	
					if (AfxMessageBox("The current slot is the default one. \n Do you want to save it in a new slot ?",
										MB_ICONWARNING|MB_OKCANCEL) == IDOK)
					{
						Camera_NewSlot	oDialog;
						CString			csName;
						long			lNewSlot = p_oCameraSlot->FindFirstEmptySlot();

						csName.Format("Default Slot %i", lNewSlot);

						// call dialog to find new name
						if (oDialog.fn_iDoDialog(csName, TRUE) == IDOK)
						{
							if( lNewSlot >= 0 )
								p_oCameraSlot->SaveCameraInSlot(lNewSlot,oDialog.GetName(),p_oOldCameraSO->GetObject(),MakeACopy);
							else
								p_oCameraSlot->SaveCameraInSlot(-1,oDialog.GetName(),p_oOldCameraSO->GetObject(),MakeACopy);
							
							// set new current slot
							p_oCameraSlot->SetCurrentSlot(lNewSlot);				
						}
					}
				}
				SaveSlotsPositions();
				if (p_oCameraSlot->IsSpecialSlot(lSlotNumber) || !p_oCameraSlot->IsSlotReserved(lSlotNumber))
					p_oCameraSlot->SetCurrentSlot(lSlotNumber);				
//End Stefan Dumitrean 22-06-98 ( slots )

//Stefan Dumitrean 29-06-98 ( slots )
				if (!p_oCameraSlot->IsSpecialSlot(lSlotNumber))
				{
					// remove the old camera from the hierarchy, and destroy it
					DestroyCamera(p_oOldCameraSO);
					// and put the new camera in the hierarchy
					InsertCameraInHierarchy(p_oCameraSO);
//restore the editor and selection saved with the slot 2-07-98
					if (!p_oCameraSlot->IsSlotReserved(lSlotNumber))
					{
						p_oCameraSlot->SetCurrentEditorForSlotNr( lSlotNumber );
						p_oCameraSlot->SetCurrentSelectionForSlotNr( lSlotNumber );
					}

					p_oCamera->GetMainWorld()->GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
				}
//End Stefan Dumitrean 29-06-98 ( slots )
			}

		}
		return TRUE;
//END CPA2 Corneliu Babiuc 21-05-98
	}
	return FALSE;
}



//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
BOOL Camera_Interface::KeyViewCamera(Camera *p_oCamera, UINT nChar)
{
	switch (m_p_oKeyConfiguration->mfn_uwKeyToAction(nChar))
	{
	case KA_FrontView:
		p_oCamera->FrontView();
		return TRUE;
		break;

	case KA_BackView:
		p_oCamera->BackView();
		return TRUE;
		break;

	case KA_LeftView:
		p_oCamera->LeftView();
		return TRUE;
		break;

	case KA_RightView:
		p_oCamera->RightView();
		return TRUE;
		break;

	case KA_TopView:
		p_oCamera->TopView();
		return TRUE;
		break;

	case KA_BottomView:
		p_oCamera->BottomView();
		return TRUE;
		break;
	}

	return FALSE;
}

//**********************************************************************************
// CPA_Ed_1 MP BEGIN
//**********************************************************************************
#define R_SENSITIVITY 64
#define T_SENSITIVITY 128
	void Camera_Interface::UpdatePosition( Camera *p_oCamera, tdstMousePos *p_stPos )
	{
		DEV_ViewPort3D *vp=p_oCamera->GetViewport();
		CRect rect;
		vp->GetClientRect( &rect );
		CPoint point;
		point=p_stPos->stPos;
		vp->ScreenToClient( &point );
		if( !rect.PtInRect( point ) )
		{
			if( point.x<rect.left )
				point.x+=rect.Width();
			else
			if( point.x>=rect.right )
				point.x-=rect.Width();

			if( point.y<rect.top )
				point.y+=rect.Height();
			else
			if( point.y>=rect.bottom )
				point.y-=rect.Height();

			vp->ClientToScreen( &point );

			SetCursorPos( point.x, point.y );

			p_stPos->stPos=point;
		}
		m_stMousePos=*p_stPos;
	}

	BOOL Camera_Interface::MouseRotateCamera( Camera *p_oCamera, tdstMousePos *p_stPos )
	{
		BOOL retval=FALSE;
		
		int dx=p_stPos->stPos.x-m_stMousePos.stPos.x;
		int dy=p_stPos->stPos.y-m_stMousePos.stPos.y;
		UpdatePosition( p_oCamera, p_stPos );
		m_stMousePos=*p_stPos;

		if( dx!=0 )
		{	
//ANNECY Shaitan correction 19/02/98
			p_oCamera->Rotate(Y_Custom, /*-*/dx*m_fRotationStep/R_SENSITIVITY);
//ENDANNECY Shaitan correction
			retval=TRUE;
		}
		
		if( dy!=0 )
		{	p_oCamera->Rotate(X_Custom, dy*m_fRotationStep/R_SENSITIVITY);
			retval=TRUE;
		}
	
		return retval;
	}
	
	BOOL Camera_Interface::MouseMoveCamera( Camera *p_oCamera, tdstMousePos *p_stPos )
	{

		CPA_CameraCoords oCoords;
		BOOL retval=FALSE;

		int dx=p_stPos->stPos.x-m_stMousePos.stPos.x;
		int dy=p_stPos->stPos.y-m_stMousePos.stPos.y;
		UpdatePosition( p_oCamera, p_stPos );
		m_stMousePos=*p_stPos;
		
		if( dx!=0 )
		{	//if (p_oCamera->GetTargetType() != tNone && p_oCamera->GetTranslationAxisSystem() != WorldCoordinates)
			//{
			//	//we have a target, so we rotate
			//	p_oCamera->Rotate(Y_Custom, dx*m_fRotationStep/SENSITIVITY);
			//}
			//else
			{
//ANNECY Shaitan correction 19/02/98
				oCoords.SetXYZ(/*-*/dx*m_fTranslationStep/T_SENSITIVITY,0,0);
				p_oCamera->Translate(&oCoords,TRUE);
//ENDANNECY Shaitan correction
			}
			retval=TRUE;
		}
		
		if( dy!=0 )
		{	//if (p_oCamera->GetTargetType() != tNone && p_oCamera->GetTranslationAxisSystem() != WorldCoordinates)
			//{
			//	//we have a target, so we rotate
			//	p_oCamera->Rotate(X_Custom, dy*m_fRotationStep/SENSITIVITY);
			//}
			//else
			{
				oCoords.SetXYZ(0,dy*m_fTranslationStep/T_SENSITIVITY,0);
				p_oCamera->Translate(&oCoords,TRUE);
			}
			retval=TRUE;
		}
		
		return retval;
	}

	static HCURSOR oldcursor=NULL;

	BOOL Camera_Interface::SendMouseMoveToCamera(CPA_BaseObject *p_oCamera, UINT nFlags, tdstMousePos *p_stPos, MTH3D_tdstVector *p_stVect)
	{
		
		if( !GetInterface()->fn_bMoveCamera() )
			return FALSE;
		
		if( nFlags & MK_RBUTTON )
			m_bRotateOn=TRUE;
		else
			m_bRotateOn=FALSE;

				
		if( !m_bIsMoving )
			return FALSE;
	
		Camera *pCamera=(Camera *)p_oCamera;

		if( m_bRotateOn )
		{
			if( MouseRotateCamera( pCamera, p_stPos ))
			{		GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
					return TRUE;
			}
		}
		else
		{	
			if( MouseMoveCamera( pCamera, p_stPos ))
			{		GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
					return TRUE;
			}
		}
	
		m_stMousePos=*p_stPos;
		
		return TRUE;
	}
	
	BOOL Camera_Interface::SendLButtonDownToCamera(CPA_BaseObject *p_oCamera, UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo)
	{
		if( !GetInterface()->fn_bMoveCamera() )
			return FALSE;
		
		
		m_stMousePos=*p_stPos;
		m_bIsMoving=TRUE;

		oldcursor=::SetCursor( hcursorM );

		return TRUE;
	}
	
	BOOL Camera_Interface::SendRButtonDownToCamera(CPA_BaseObject *p_oCamera, UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo)
	{
		if( !GetInterface()->fn_bMoveCamera() )
			return FALSE;

		if( !m_bIsMoving )
		{
			GetInterface()->GetFrameBase()->m_oGeneralDialogBar.SetMoveCamera( 0 ); 
			return TRUE;
		}

		m_bRotateOn=TRUE;

		::SetCursor( hcursorR );
		return TRUE;
	}
	
	BOOL Camera_Interface::SendLButtonUpToCamera(CPA_BaseObject *p_oCamera, UINT nFlags, tdstMousePos *p_stPos)
	{
		if( !GetInterface()->fn_bMoveCamera() )
			return FALSE;
		if( !m_bIsMoving )
			return FALSE;
		
		Camera *pCamera=(Camera *)p_oCamera;

		m_bIsMoving=FALSE;

		::SetCursor( oldcursor );
		
		if( m_bRotateOn )
		{	if( MouseRotateCamera( pCamera, p_stPos ))
			{		GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
					return TRUE;
			}
		}
		else
		{	if( MouseMoveCamera( pCamera, p_stPos ))
			{		GetInterface()->fn_vUpdateAll(E_mc_JustDraw);
					return TRUE;
			}
		}
		return FALSE;
	}
	
	BOOL Camera_Interface::SendRButtonUpToCamera(CPA_BaseObject *p_oCamera, UINT nFlags, tdstMousePos *p_stPos)
	{
		if( !GetInterface()->fn_bMoveCamera() )
			return FALSE;

		m_bRotateOn=FALSE;
		if( m_bIsMoving )
			::SetCursor( hcursorM );
		else
			::SetCursor( oldcursor );
		return TRUE;
	}

//**********************************************************************************
// CPA_Ed_1 MP END
// *********************************************************************************
