⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 magicscissorsview.cpp

📁 刚上传内容的相关CODEC不能单独上传。于是
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			if( nFlags&MK_SHIFT)
				pDoc->FindLine( m_ptStart, m_ptEnd);
			else
				pDoc->FindEdge( m_ptStart, m_ptEnd );
			Invalidate(FALSE);
		}
		else if( m_nMode == 2 && m_bEdgeStart )
		{
			if( m_ptStart != point )
			{				
				pDoc->AddModify(point);
				m_ptStart = point;
				Invalidate(FALSE);
			}
		}
		else if( m_nMode == 3 )
		{
			CPoint pt = point - m_ptStart;
			m_ptStart = point;
			pDoc->m_pPolygonList->GetSelect()->Move(pt.x, pt.y);
			Invalidate(FALSE);
		}
		else if( m_nMode == 4 && m_bEdgeStart )
		{
			m_ptEnd = point;
			Invalidate(FALSE);
		}

		
		if( m_nMode == 1 )
			SetCursor( LoadCursor( NULL, IDC_CROSS ) );
		else if( m_nMode == 2 )
			SetCursor( LoadCursor( NULL, IDC_CROSS ) );
		else if( m_nMode == 3 )
			SetCursor( LoadCursor( NULL, IDC_SIZEALL ) );
		else if( m_nMode == 4 )
			SetCursor( LoadCursor( NULL, IDC_CROSS ) );
	}

	point = pt;

	CScrollView::OnMouseMove(nFlags, point);
}

void CMagicScissorsView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CMagicScissorsDoc* pDoc = GetDocument();
	
	CPoint pt = point;
	CPoint sc = GetScrollPosition();
	point += sc;
	point.x /= m_nZoom;
	point.y /= m_nZoom;

	if( m_nMode == 1 )
	{
		if( m_bEdgeStart )
		{
			BeginWaitCursor();
			m_bEdgeStart = FALSE;
			m_ptStart = *(pDoc->m_pEdgeList->GetLastPoint());
			m_ptEnd = *(pDoc->m_pEdgeList->GetPoint(0));
			pDoc->FindEdge( m_ptStart, m_ptEnd );
			pDoc->AddEdge();
			pDoc->AddNewObject();			
			Invalidate(FALSE);
			m_nMode = 0;
			EndWaitCursor();
		}
	}
	point = pt;
	CScrollView::OnLButtonDblClk(nFlags, point);
}



void CMagicScissorsView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CMagicScissorsDoc* pDoc = GetDocument();
	CPoint pt = point;
	CPoint sc = GetScrollPosition();
	point += sc;
	point.x /= m_nZoom;
	point.y /= m_nZoom;

	if( m_nMode == 2 && m_bEdgeStart )
	{
		pDoc->ModifyEdge();
		//m_nMode = 0;
		m_bEdgeStart = FALSE;
		Invalidate(FALSE);
	}
	else if( m_nMode == 3 )
		m_nMode = 0;
	else if( m_nMode == 4 )
	{
		//m_nMode = 0;
		m_bEdgeStart = FALSE;
		m_ptEnd = point;
		pDoc->CreateActiveContour( CRect(m_ptStart, m_ptEnd) );
		Invalidate(FALSE);
	}


	point = pt;
	CScrollView::OnLButtonUp(nFlags, point);
}

void CMagicScissorsView::OnUpdateSegment(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if( m_nMode == 1 )
		pCmdUI->SetCheck(1);
	else
		pCmdUI->SetCheck(0);
}

void CMagicScissorsView::OnUpdateModify(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if( m_nMode == 2 )
		pCmdUI->SetCheck(1);
	else
		pCmdUI->SetCheck(0);
}

void CMagicScissorsView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CMagicScissorsDoc* pDoc = GetDocument();
	CPoint pt = point;
	CPoint sc = GetScrollPosition();
	point += sc;
	point.x /= m_nZoom;
	point.y /= m_nZoom;

	if( m_nMode == 1 && m_bEdgeStart )
	{
		pDoc->UndoEdge();
		Invalidate(FALSE);
	}
	if( m_nMode == 0 )
	{
		pDoc->SelectObject(point);
		Invalidate(FALSE);
	}
	point = pt;
	CScrollView::OnRButtonDown(nFlags, point);
}

void CMagicScissorsView::OnDeleteRegion() 
{
	// TODO: Add your command handler code here
	CMagicScissorsDoc* pDoc = GetDocument();
	if( pDoc->DeleteObject() )
		Invalidate(FALSE);

}

void CMagicScissorsView::OnSmooth() 
{
	// TODO: Add your command handler code here
	CMagicScissorsDoc* pDoc = GetDocument();
	if( pDoc->EdgeSmoothing() )
		Invalidate(FALSE);
}

void CMagicScissorsView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	CMagicScissorsDoc* pDoc = GetDocument();
	if( m_nMode == 0 )
	{
		if( nChar == VK_DELETE )
			OnDeleteRegion();
		else if( nChar == 'S' || nChar == 's' )
		{
			pDoc->DataSave();
		}			
		else if( nChar == 'F' || nChar == 'f' )
		{
			if( m_bPlay )
				OnPause();
			else
				OnPlay();
		}
		else if( nChar == VK_LEFT )
			OnPrev();
		else if( nChar == VK_RIGHT )			
			OnNext();
		else if( nChar == 'Z' || nChar == 'z' )
		{
			if( m_nZoom == 1 )
				OnZoomIn();
			else if( m_nZoom == 2 )
				OnZoomOut();
		}	
		else if( nChar == VK_SPACE && m_nZoom > 1 )
			m_bScroll = TRUE;
	}
	CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CMagicScissorsView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	if( nChar == VK_SPACE )
		m_bScroll = FALSE;
	
	CScrollView::OnKeyUp(nChar, nRepCnt, nFlags);
}

void CMagicScissorsView::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// TODO: Add your message handler code here
	CPoint pnt = point;

	ScreenToClient(&pnt);

	//CSize size = GetScrollPosition();

	//int x,y;
	//long lParam;
	//x = pnt.x;
	//y = pnt.y;	
	//lParam = (y << 16) | x;
	//SendMessage(WM_LBUTTONDOWN, 0, lParam);

	//pnt.x = (pnt.x+size.cx)/m_nZoom;
	//pnt.y = (pnt.y+size.cy)/m_nZoom;
	
	CMagicScissorsDoc* pDoc = GetDocument();
	CObjRgn* pObj = pDoc->m_pCurFrame->GetSelected();
	pnt.x /= m_nZoom;
	pnt.y /= m_nZoom;
	if( pObj && pObj->PtInRgn(pnt) )
	{
		CMenu menu;
		if (menu.LoadMenu(IDR_POPUP)) {			
			CMenu* pPopup = menu.GetSubMenu(0);
			ASSERT(pPopup != NULL);			
			pPopup->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN, point.x, point.y, this);
		}
	}	
}

void CMagicScissorsView::OnCopyprev() 
{
	// TODO: Add your command handler code here
	CMagicScissorsDoc* pDoc = GetDocument();
	pDoc->CopyPrev();
	//pDoc->TraceEdge();
	Invalidate(FALSE);
}

void CMagicScissorsView::OnFindedge() 
{
	// TODO: Add your command handler code here
	CMagicScissorsDoc* pDoc = GetDocument();
	BeginWaitCursor();
	pDoc->TraceEdge();
	Invalidate(FALSE);
	EndWaitCursor();
}

void CMagicScissorsView::OnPlayOnly() 
{
	// TODO: Add your command handler code here
	m_nPlayMode = 0;	
}

void CMagicScissorsView::OnUpdatePlayOnly(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if( m_nPlayMode == 0 )
		pCmdUI->SetCheck();
	else
		pCmdUI->SetCheck(0);
}

void CMagicScissorsView::OnPlayTrace() 
{
	// TODO: Add your command handler code here
	m_nPlayMode = 1;
}

void CMagicScissorsView::OnUpdatePlayTrace(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if( m_nPlayMode == 1 )
		pCmdUI->SetCheck();
	else
		pCmdUI->SetCheck(0);
}

void CMagicScissorsView::OnZoomIn() 
{
	// TODO: Add your command handler code here
	CMagicScissorsDoc* pDoc = GetDocument();
	if( m_nZoom < 5 )
	{
		m_nZoom++;
		CSize size;
		size.cx = pDoc->m_ImgSize.cx * m_nZoom;
		size.cy = pDoc->m_ImgSize.cy * m_nZoom;
		SetScrollSizes(MM_TEXT, size);
		Invalidate();
		AfxGetMainWnd()->UpdateWindow();
	}
}

void CMagicScissorsView::OnUpdateZoomIn(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if( m_nZoom < 5 )
		pCmdUI->Enable(1);
	else
		pCmdUI->Enable(0);
}

void CMagicScissorsView::OnZoomOut() 
{
	// TODO: Add your command handler code here
	CMagicScissorsDoc* pDoc = GetDocument();
	if( m_nZoom > 1 )
	{
		m_nZoom--;
		CSize size;
		size.cx = pDoc->m_ImgSize.cx * m_nZoom;
		size.cy = pDoc->m_ImgSize.cy * m_nZoom;
		SetScrollSizes(MM_TEXT, size);
		Invalidate();
		AfxGetMainWnd()->UpdateWindow();
	}
}

void CMagicScissorsView::OnUpdateZoomOut(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if( m_nZoom > 1 )
		pCmdUI->Enable(1);
	else
		pCmdUI->Enable(0);		
}

void CMagicScissorsView::OnFindFrame() 
{
	// TODO: Add your command handler code here
	CMagicScissorsDoc* pDoc = GetDocument();
	CFrameFindDlg dlg;
	if( dlg.DoModal() == IDOK )
	{
		pDoc->FindFrame(dlg.m_nFrame);
		Invalidate(FALSE);
		((CMainFrame*)AfxGetMainWnd())->m_wndVideoControlBar.SetPos(pDoc->m_nCurFrame-1);
	}
}

void CMagicScissorsView::OnChangeSlider(int pos)
{
	CMagicScissorsDoc* pDoc = GetDocument();
	if( m_bPlay )
		KillTimer(IDT_VIDEO_PLAY);

	Sleep(100);
	pDoc->FindFrame(pos);
	Invalidate(FALSE);

	if( m_bPlay )
		SetTimer(IDT_VIDEO_PLAY, 100, NULL);
}

void CMagicScissorsView::OnToFirst() 
{
	// TODO: Add your command handler code here
	CMagicScissorsDoc* pDoc = GetDocument();
	pDoc->FindFrame(0);
	Invalidate(FALSE);
	((CMainFrame*)AfxGetMainWnd())->m_wndVideoControlBar.SetPos(pDoc->m_nCurFrame-1);
}

void CMagicScissorsView::OnToLast() 
{
	// TODO: Add your command handler code here
	CMagicScissorsDoc* pDoc = GetDocument();
	pDoc->FindFrame(pDoc->m_nTotalFrame-1);
	Invalidate(FALSE);
	((CMainFrame*)AfxGetMainWnd())->m_wndVideoControlBar.SetPos(pDoc->m_nCurFrame-1);
	if( m_bPlay )
	{
		KillTimer(IDT_VIDEO_PLAY);
		m_bPlay = FALSE;
	}
}


void CMagicScissorsView::OnUpdatePlay(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if( m_bPlay )
		pCmdUI->SetCheck(1);
	else
		pCmdUI->SetCheck(0);
}

void CMagicScissorsView::OnUpdatePrev(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if( m_bPlay )
		pCmdUI->Enable(FALSE);
	else
		pCmdUI->Enable(TRUE);
}

void CMagicScissorsView::OnUpdateNext(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if( m_bPlay )
		pCmdUI->Enable(FALSE);
	else
		pCmdUI->Enable(TRUE);
}



void CMagicScissorsView::OnDeleteRegions() 
{
	// TODO: Add your command handler code here
	CDelRegionsDlg dlg;
	if( dlg.DoModal() == IDOK )
	{
		BeginWaitCursor();
		CMagicScissorsDoc* pDoc = GetDocument();
		pDoc->DeleteFrameInfo(dlg.m_nStart,dlg.m_nEnd);
		EndWaitCursor();
	}
}

void CMagicScissorsView::OnMakeActivecontour() 
{
	// TODO: Add your command handler code here
	if( m_nMode == 0 )
	{
		m_nMode = 4;
	}
	else if( m_nMode == 4 )
	{
		m_nMode = 0;
	}
}

void CMagicScissorsView::OnActivecontourEvolve() 
{
	// TODO: Add your command handler code here
	CMagicScissorsDoc* pDoc = GetDocument();
	pDoc->EvolveActiveContour();
	Invalidate(FALSE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -