//ROMTEAM WorldEditor
////////////////////////////////////////////////////////////////////////////////////////
// File        : CDlgITBox.cpp: implementation of the CDlgITBox class.
// Author      : Ionut Grozea
// Date        : 97.11
// Description :
////////////////////////////////////////////////////////////////////////////////////////

#include "DlgITBox.h"
#include "stdafx.h"
#include "ACP_Base.h"
#include "ITF.h"
#include "incGAM.h"
#include "GLI.h"
#include "DPT.h"

#undef CPA_WANTS_IMPORT
#undef CPA_EXPORT
#define CPA_WANTS_EXPORT
    #include "OGD.h"
#undef CPA_WANTS_EXPORT
#define CPA_WANTS_IMPORT

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
class ITBox3D;
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method : CDlgITBox::CDlgITBox
// Date   : 97.11
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : constructor to create a new dialog
// Author      : Ionut Grozea
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date         :
// By           :
//////////////////////////////////////////////////////////////////////////////////////////////////////

CDlgITBox::CDlgITBox(float m_Nx , float m_Ny , float m_Nz , ITBox3D*pBox , CWnd* pParent /*= NULL*/)   // standard constructor
	: CDialog(CDlgITBox::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgITBox)
	m_fScaleY = 0.0f;
	m_fScaleX = 0.0f;
	m_fScaleZ = 0.0f;
	//}}AFX_DATA_INIT
	m_fScaleXOld = m_Nx;
	m_fScaleYOld = m_Ny;
	m_fScaleZOld = m_Nz;


	m_poBox = pBox;
}


void CDlgITBox::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgITBox)
	DDX_Control(pDX, IDC_SLIDER5, m_SliderZ);
	DDX_Control(pDX, IDC_SLIDER3, m_SliderY);
	DDX_Control(pDX, IDC_SLIDER2, m_SliderX);
 	DDX_Text(pDX, IDC_EDIT3, m_fScaleY);
	DDV_MinMaxFloat(pDX, m_fScaleY, 0.f, 10.f);
	DDX_Text(pDX, IDC_EDIT2, m_fScaleX);
	DDV_MinMaxFloat(pDX, m_fScaleX, 0.f, 10.f);
	DDX_Text(pDX, IDC_EDIT4, m_fScaleZ);
	DDV_MinMaxFloat(pDX, m_fScaleZ, 0.f, 10.f);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgITBox, CDialog)
	//{{AFX_MSG_MAP(CDlgITBox)
	ON_WM_HSCROLL()
 	ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
	ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
	ON_EN_CHANGE(IDC_EDIT4, OnChangeEdit4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgITBox message handlers


int CDlgITBox::mfn_iGetIntPos(float fVal)
{
	return (int) ( fVal* 10);
}

float CDlgITBox::mfn_fSliderInt2Float(int sliderVal)
{
	return sliderVal/10.0f;
}

void CDlgITBox::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
 
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);

	CWnd  *m_Slider3  , *m_Slider2 ,  *m_Slider5;
	m_Slider2 = GetDlgItem(IDC_SLIDER2);
	m_Slider3 = GetDlgItem(IDC_SLIDER3);
	m_Slider5 = GetDlgItem(IDC_SLIDER5);
 	
	if (m_Slider2  == pScrollBar)
	{
		m_fScaleX=mfn_fSliderInt2Float(m_SliderX.GetPos());
		UpdateData(FALSE);
		m_poBox->SetScaleX(m_fScaleX);
	}
	if (m_Slider3  == pScrollBar)
	{
		m_fScaleY=mfn_fSliderInt2Float(m_SliderY.GetPos());
		UpdateData(FALSE);
		m_poBox->SetScaleY(m_fScaleY);
	}

	if (m_Slider5  == pScrollBar)
	{
		m_fScaleZ=mfn_fSliderInt2Float(m_SliderZ.GetPos());
		UpdateData(FALSE);
		m_poBox->SetScaleZ(m_fScaleZ);
	}

		(((DEV_MultiDevice*)g_oFrameGest.ma_p_oWinArray[2][2]->GetActiveView())->DrawObject());

	
}

BOOL CDlgITBox::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_fScaleX = m_poBox->m_fX;
	m_fScaleY = m_poBox->m_fY;
	m_fScaleZ = m_poBox->m_fZ;
	m_SliderX.SetPos(mfn_iGetIntPos(m_poBox->m_fX));  
	m_SliderY.SetPos(mfn_iGetIntPos(m_poBox->m_fY));  
	m_SliderZ.SetPos(mfn_iGetIntPos(m_poBox->m_fZ));  
 	UpdateData(FALSE);
	return TRUE;   
}

void CDlgITBox::OnChangeEdit2() 
{
	UpdateData();
	m_SliderX.SetPos(mfn_iGetIntPos(m_fScaleX));
	m_poBox->SetScaleX(m_fScaleX);
	(((DEV_MultiDevice*)g_oFrameGest.ma_p_oWinArray[2][2]->GetActiveView())->DrawObject());	 
  
}

void CDlgITBox::OnChangeEdit3() 
{
	 
	UpdateData();
	m_SliderY.SetPos(mfn_iGetIntPos(m_fScaleY));
	m_poBox->SetScaleY(m_fScaleY);
	(((DEV_MultiDevice*)g_oFrameGest.ma_p_oWinArray[2][2]->GetActiveView())->DrawObject());	 
 
	
}

void CDlgITBox::OnChangeEdit4() 
{
 
	UpdateData();
	m_SliderZ.SetPos(mfn_iGetIntPos(m_fScaleZ));
	m_poBox->SetScaleZ(m_fScaleZ);
	(((DEV_MultiDevice*)g_oFrameGest.ma_p_oWinArray[2][2]->GetActiveView())->DrawObject());	 
 
}


void CDlgITBox::OnCancel()
{
	m_fScaleX=m_fScaleXOld;
	m_fScaleY=m_fScaleYOld;
	m_fScaleZ=m_fScaleZOld;
	m_poBox->SetScaleX(m_fScaleX);
	m_poBox->SetScaleY(m_fScaleY);
	m_poBox->SetScaleZ(m_fScaleZ);
	CDialog::OnCancel();
}
