// MenuImageAdjust.cpp : 实现文件
//

#include "stdafx.h"
#include "CombineSubjectDrawTest.h"
#include "MenuImageAdjust.h"
#include "afxdialogex.h"


// CMenuImageAdjust 对话框

IMPLEMENT_DYNAMIC(CMenuImageAdjust, CDialogEx)

CMenuImageAdjust::CMenuImageAdjust(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_DIALOG_ADJUST, pParent)
	, m_nDirectType(0)
{

}

CMenuImageAdjust::~CMenuImageAdjust()
{
}

void CMenuImageAdjust::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_SLIDER_LIGHT, m_just_light);
	DDX_Control(pDX, IDC_SLIDER_GAMMA, m_just_gam);
	DDX_Control(pDX, IDC_SLIDER_CON, m_just_con);
	DDX_Radio(pDX, IDC_RADIO_RAD, m_nDirectType);
}


BEGIN_MESSAGE_MAP(CMenuImageAdjust, CDialogEx)
	ON_BN_CLICKED(IDCANCEL, &CMenuImageAdjust::OnBnClickedCancel)
	ON_BN_CLICKED(IDC_BUTTON_DEFAULT, &CMenuImageAdjust::OnBnClickedButtonDefault)
	ON_WM_HSCROLL()
	ON_BN_CLICKED(IDC_RADIO_RAD, &CMenuImageAdjust::OnBnClickedRadioRad)
	ON_BN_CLICKED(IDC_RADIO4, &CMenuImageAdjust::OnBnClickedRadio4)
	ON_BN_CLICKED(IDC_RADIO5, &CMenuImageAdjust::OnBnClickedRadio5)
	ON_BN_CLICKED(IDC_RADIO6, &CMenuImageAdjust::OnBnClickedRadio6)
END_MESSAGE_MAP()


// CMenuImageAdjust 消息处理程序


void CMenuImageAdjust::OnBnClickedCancel()
{
	// TODO: 在此添加控件通知处理程序代码
	CDialogEx::OnCancel();
}


BOOL CMenuImageAdjust::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	m_just_light.SetRange(-100, 100, TRUE);
	m_just_con.SetRange(-100, 100, TRUE);
	m_just_gam.SetRange(0, 300, TRUE);

	int nB = 0;
	int nC = 0;
	int nG = 0;
	m_pControl->GetBrightness(nB);
	m_pControl->GetContrast(nC);
	m_pControl->GetDefinition(nG);

	m_just_light.SetPos(nB);
	m_just_gam.SetPos(nG);
	m_just_con.SetPos(nC);

	CString strValue;
	strValue.Format(_T("%d"), nB);
	GetDlgItem(IDC_STATIC_B)->SetWindowText(strValue);
	strValue.Format(_T("%d"), nC);
	GetDlgItem(IDC_STATIC_C)->SetWindowText(strValue);
	strValue.Format(_T("%.2f"), nG/100.0);
	GetDlgItem(IDC_STATIC_G)->SetWindowText(strValue);


	emImageDirection  _dir;
	m_pControl->GetImageDirection(_dir);
	switch (_dir)
	{
	case DIRECTION_0:
		m_nDirectType = 0;
		break;
	case DIRECTION_90:
		m_nDirectType = 1;
		break;
	case DIRECTION_180:
		m_nDirectType = 2;
		break;
	case DIRECTION_270:
		m_nDirectType = 3;
		break;
	}

	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CMenuImageAdjust::OnBnClickedButtonDefault()
{
	m_just_light.SetPos(0);
	m_just_gam.SetPos(100);
	m_just_con.SetPos(0);
 
	GetDlgItem(IDC_STATIC_B)->SetWindowText(_T("100"));

	GetDlgItem(IDC_STATIC_C)->SetWindowText(_T("100"));

	GetDlgItem(IDC_STATIC_G)->SetWindowText(_T("1.00"));


	int nPos = m_just_light.GetPos();
	m_pControl->AdjustBrightness(nPos);


	nPos = m_just_con.GetPos();
	m_pControl->AdjustContrast(nPos);


	nPos = m_just_gam.GetPos();
	m_pControl->AdjustDefinition(nPos);
}


void CMenuImageAdjust::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (pScrollBar == GetDlgItem(IDC_SLIDER_LIGHT))
	{
		int nPos = m_just_light.GetPos();
		CString strText;
		strText.Format(_T("%d"), nPos);
		GetDlgItem(IDC_STATIC_B)->SetWindowText(strText);

		m_pControl->AdjustBrightness(nPos);

 
		return;
	}
	if (pScrollBar == GetDlgItem(IDC_SLIDER_CON))
	{
		int nPos = m_just_con.GetPos();
		CString strText;
		strText.Format(_T("%d"), nPos);
		GetDlgItem(IDC_STATIC_C)->SetWindowText(strText);
		m_pControl->AdjustContrast(nPos);
		return;
	}
	if (pScrollBar == GetDlgItem(IDC_SLIDER_GAMMA))
	{
		int nPos = m_just_gam.GetPos();
		CString strText;
		double dbValue = (double)nPos;
		strText.Format(_T("%.2f"), dbValue / 100);
		GetDlgItem(IDC_STATIC_G)->SetWindowText(strText);
		m_pControl->AdjustDefinition(nPos);
		return;
	}

	CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}


void CMenuImageAdjust::OnBnClickedRadioRad()
{
	m_pControl->SetImageDirection(DIRECTION_0);
}


void CMenuImageAdjust::OnBnClickedRadio4()
{
	m_pControl->SetImageDirection(DIRECTION_90);
}


void CMenuImageAdjust::OnBnClickedRadio5()
{
	m_pControl->SetImageDirection(DIRECTION_180);
}


void CMenuImageAdjust::OnBnClickedRadio6()
{
	m_pControl->SetImageDirection(DIRECTION_270);
}
 