AmazeView.cpp
资源名称:Amaze.rar [点击查看]
上传用户:jygk2008
上传日期:2007-04-06
资源大小:18k
文件大小:4k
源码类别:
系统/网络安全
开发平台:
Visual C++
- // AmazeView.cpp : implementation of the CAmazeView class
- //
- #include "stdafx.h"
- #include "Amaze.h"
- #include "AmazeDoc.h"
- #include "AmazeView.h"
- #include "Setup.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAmazeView
- IMPLEMENT_DYNCREATE(CAmazeView, CScrollView)
- BEGIN_MESSAGE_MAP(CAmazeView, CScrollView)
- //{{AFX_MSG_MAP(CAmazeView)
- ON_COMMAND(IDC_NEW, OnNew)
- ON_COMMAND(IDC_DIS, OnDis)
- ON_UPDATE_COMMAND_UI(IDC_DIS, OnUpdateDis)
- ON_COMMAND(IDC_WIDTH, OnWidth)
- ON_COMMAND(IDC_HEIGHT, OnHeight)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CAmazeView construction/destruction
- CAmazeView::CAmazeView()
- {
- // TODO: add construction code here
- m_bDis = false;
- }
- CAmazeView::~CAmazeView()
- {
- }
- BOOL CAmazeView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CScrollView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAmazeView drawing
- void CAmazeView::OnDraw(CDC* pDC)
- {
- int i, j;
- CAmazeDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- if(!pDoc->HaveAmaze())
- return;
- for( i = 0 ; i <= 2 * pDoc->GetHeight() ; i++ ){
- for( j = 0 ; j <= 2 * pDoc->GetWidth() ; j++ ){
- if( pDoc->AmazeData(j, i) && pDoc->AmazeData(j + 1, i) ){
- pDC->MoveTo((j + 1) * SEPARATE, (i + 1) * SEPARATE);
- pDC->LineTo((j + 2) * SEPARATE, (i + 1) * SEPARATE);
- }
- if( pDoc->AmazeData(j, i) && pDoc->AmazeData(j, i + 1) ){
- pDC->MoveTo((j + 1) * SEPARATE, (i + 1) * SEPARATE);
- pDC->LineTo((j + 1) * SEPARATE, (i + 2) * SEPARATE);
- }
- }
- }
- if(m_bDis){
- CPen *oldpen, pen(PS_SOLID, 1, RGB(255, 0, 0));
- oldpen = pDC->SelectObject(&pen);
- pDC->MoveTo( (*(pDoc->m_pDisData) + 1) * SEPARATE, (*(pDoc->m_pDisData + 1) + 1) * SEPARATE );
- for( i = 1 ; i < pDoc->m_nDisNum ; i++ )
- pDC->LineTo( (*(pDoc->m_pDisData + 2 * i) + 1) * SEPARATE, (*(pDoc->m_pDisData + 2 * i + 1) + 1) * SEPARATE );
- pDC->SelectObject(oldpen);
- }
- }
- void CAmazeView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx = sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAmazeView diagnostics
- #ifdef _DEBUG
- void CAmazeView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CAmazeView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- CAmazeDoc* CAmazeView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAmazeDoc)));
- return (CAmazeDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CAmazeView message handlers
- void CAmazeView::ResetScrollbar()
- {
- CAmazeDoc* pDoc = GetDocument();
- CSize sizeTotal;
- sizeTotal.cx = (pDoc->GetWidth() + 1) * 2 * SEPARATE;
- sizeTotal.cy = (pDoc->GetHeight() + 1) * 2 * SEPARATE;;
- SetScrollSizes(MM_TEXT, sizeTotal);
- }
- void CAmazeView::OnNew()
- {
- // TODO: Add your command handler code here
- GetDocument()->CreateAmaze();//创建迷宫
- ResetScrollbar();//设置滚动条
- Invalidate();//更新显示
- }
- void CAmazeView::OnDis()
- {
- // TODO: Add your command handler code here
- m_bDis = m_bDis ? false : true;
- Invalidate();
- }
- void CAmazeView::OnUpdateDis(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_bDis);
- }
- void CAmazeView::OnWidth()
- {
- // TODO: Add your command handler code here
- CSetup dlg;
- CAmazeDoc* pDoc = GetDocument();
- dlg.m_strPrompt = "迷宫宽度:";
- dlg.m_nValue = pDoc->GetWidth();
- if(dlg.DoModal() == IDOK)
- pDoc->SetWidth(dlg.m_nValue);
- }
- void CAmazeView::OnHeight()
- {
- // TODO: Add your command handler code here
- CSetup dlg;
- CAmazeDoc* pDoc = GetDocument();
- dlg.m_strPrompt = "迷宫高度:";
- dlg.m_nValue = pDoc->GetHeight();
- if(dlg.DoModal() == IDOK)
- pDoc->SetHeight(dlg.m_nValue);
- }