#include "CAniEditorDrawGrid.h"
#include "resource.h"

IMPLEMENT_DYNAMIC(CAniEditorDrawGrid, CDialog)

BEGIN_MESSAGE_MAP(CAniEditorDrawGrid, CDialog)
	ON_BN_CLICKED(IDOK, &CAniEditorDrawGrid::OnBnClickedOk)
END_MESSAGE_MAP()

CAniEditorDrawGrid::CAniEditorDrawGrid(CWnd* pParent)
	: CDialog(IDD_CANIEDITOR_DRAW_GRID, pParent)
{
}

CAniEditorDrawGrid::~CAniEditorDrawGrid()
{
}

void CAniEditorDrawGrid::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_GRID_W, edit_grid_w);
	DDX_Control(pDX, IDC_EDIT_GRID_H, edit_grid_h);
	DDX_Control(pDX, IDC_EDIT_COUNT_W, edit_count_w);
	DDX_Control(pDX, IDC_EDIT_COUNT_H, edit_count_h);
	DDX_Control(pDX, IDC_CHECK_SHOWBK, check_showBk);
	DDX_Control(pDX, IDC_CHECK_SHOWLINE, check_showLine);
	DDX_Control(pDX, IDC_CHECK_SHOWENTITY, check_showEntity);
	DDX_Control(pDX, IDC_RADIO_DARK, radio_dark);
	DDX_Control(pDX, IDC_RADIO_LIGHT, radio_light);
}

BOOL CAniEditorDrawGrid::OnInitDialog()
{
	CDialog::OnInitDialog();
	//设置默认值
	SetDlgItemInt(IDC_EDIT_GRID_W, outGridW);
	SetDlgItemInt(IDC_EDIT_GRID_H, outGridH);
	SetDlgItemInt(IDC_EDIT_COUNT_W, outCountW);
	SetDlgItemInt(IDC_EDIT_COUNT_H, outCountH);
	check_showBk.SetCheck(outShowBk);
	check_showLine.SetCheck(outShowLine);
	check_showEntity.SetCheck(outShowEntity);
	if (outIsDark)
	{
		radio_dark.SetCheck(true);
		radio_light.SetCheck(false);
	}
	else
	{
		radio_dark.SetCheck(false);
		radio_light.SetCheck(true);
	}
	return 0;
}


void CAniEditorDrawGrid::OnBnClickedOk()
{
	//网格宽度
	CString strGrid_w;
	edit_grid_w.GetWindowTextW(strGrid_w);
	if (strGrid_w.GetLength() == 0)
	{
		MessageBox(L"必须填写网格宽度", L"填写属性无效");
		return;
	}
	int grid_w = GetDlgItemInt(IDC_EDIT_GRID_W);
	if (grid_w == 0)
	{
		MessageBox(L"网格宽度至少为1", L"填写属性无效");
		return;
	}
	//网格高度
	CString strGrid_h;
	edit_grid_h.GetWindowTextW(strGrid_h);
	if (strGrid_h.GetLength() == 0)
	{
		MessageBox(L"必须填写网格高度", L"填写属性无效");
		return;
	}
	int grid_h = GetDlgItemInt(IDC_EDIT_GRID_H);
	if (grid_h == 0)
	{
		MessageBox(L"网格高度至少为1", L"填写属性无效");
		return;
	}
	//网格列数
	CString strCount_w;
	edit_count_w.GetWindowTextW(strCount_w);
	if (strCount_w.GetLength() == 0)
	{
		MessageBox(L"必须填写网格列数", L"填写属性无效");
		return;
	}
	int count_w = GetDlgItemInt(IDC_EDIT_COUNT_W);
	if (count_w == 0)
	{
		MessageBox(L"网格列数至少为1", L"填写属性无效");
		return;
	}
	//网格行数
	CString strCount_h;
	edit_count_h.GetWindowTextW(strCount_h);
	if (strCount_h.GetLength() == 0)
	{
		MessageBox(L"必须填写网格行数", L"填写属性无效");
		return;
	}
	int count_h = GetDlgItemInt(IDC_EDIT_COUNT_H);
	if (count_h == 0)
	{
		MessageBox(L"网格行数至少为1", L"填写属性无效");
		return;
	}
	//棋盘网格背景
	bool bShowBk = check_showBk.GetCheck();
	//中心线
	bool bShowLine = check_showLine.GetCheck();
	//实体线框
	bool bShowEntity = check_showEntity.GetCheck();
	//颜色
	bool bIsDark = true;
	if (radio_dark.GetCheck())
		bIsDark = true;
	else if (radio_light.GetCheck())
		bIsDark = false;
	//输出
	outGridW = grid_w;
	outGridH = grid_h;
	outCountW = count_w;
	outCountH = count_h;
	outShowBk = bShowBk;
	outShowLine = bShowLine;
	outShowEntity = bShowEntity;
	outIsDark = bIsDark;
	CDialog::OnOK();
}
