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

📄 displayer.cpp

📁 The application wizard has created this SoccerDoctor application for you. This application not onl
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		case CmdBallDetail:
			return _Settings.m_bBallDetail;
		case CmdPassCourse:
			return _Settings.m_bControlCourse;
		case CmdSelectNone:
			return m_nDebug >= 0 && m_nDebug <= MAX_PLAYER * 2;
			break;
		default:
			break;
	}
	return false;
}
void CDisplayer::OnMouseMove(UINT nFlags, CPoint point)
{
	CString strHint;
	// strHint.Format("(%.2f,%.2f)",ScreenX2FieldX(point.x),ScreenY2FieldY(point.y));
	bool bShowHint = false;
	SetCursor(LoadCursor(NULL,IDC_ARROW));
	if( _pCycleInfo != NULL && !_pCycleInfo->bSight ){
		player_t* pPlayer;
		CRect rect;
		UINT x,y,r;
		for(UINT iPlayer=0 ; iPlayer < MAX_PLAYER * 2; iPlayer++) {
			pPlayer = (player_t*)&(_pCycleInfo->show.pos[iPlayer]);
			if( pPlayer->mode == DISABLE ) {
				continue;
			}
			x = FieldX2ScreenX((double)(long)ntohl(pPlayer->x)/ SHOWINFO_SCALE2);
			y = FieldY2ScreenY((double)(long)ntohl(pPlayer->y)/ SHOWINFO_SCALE2);
			r = CoordX(PlayerSize(ntohs(pPlayer->type)));
			rect.SetRect(x - r,y - r,x + r,y + r);
			if(rect.PtInRect(point)){
				SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(32649)/* IDC_HAND */));
				if( iPlayer<MAX_PLAYER ){ // Left Team
					strHint.Format("[Left %d]",iPlayer+1);
				}else{ // Right Team
					strHint.Format("[Right %d]",iPlayer-MAX_PLAYER+1);
				}
				bShowHint = true;
                break;
			}
		}
	}	
	for( VOIterator i=_VisualObjects.begin(); i != _VisualObjects.end(); ++i ){
		if( (*i)->OnMouseMove(nFlags,point) ) {
			SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(32649)/* IDC_HAND */));
			strHint = (*i)->ToString();
			bShowHint = true;
			break;
		}
	}	
	CDialog::OnMouseMove(nFlags, point);
	if( bShowHint){
		getHintWindow()->ShowHint(point,strHint);
	}
}


void CDisplayer::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	bool bSelected = false; // 看是否有东西被拾取
	if(_pCycleInfo != NULL){ // 场上队员优先被拾取
		player_t* pPlayer;
		CRect rect;
		UINT x,y,r;
		for( UINT iPlayer=0 ; iPlayer < MAX_PLAYER * 2; iPlayer++ ) {
			pPlayer = (player_t*)&(_pCycleInfo->show.pos[iPlayer]);
			if( pPlayer->mode == DISABLE ) {
				continue;
			}
			x = FieldX2ScreenX((double)(long)ntohl(pPlayer->x)/ SHOWINFO_SCALE2);
			y = FieldY2ScreenY((double)(long)ntohl(pPlayer->y)/ SHOWINFO_SCALE2);
			r = CoordX(PlayerSize(ntohs(pPlayer->type)));
			rect.SetRect(x - r,y - r,x + r,y + r);
			if(rect.PtInRect(point)){
				m_nDebug = iPlayer;
				bSelected = true;
				Invalidate();
				break;
			}
		}
	}
	if( !bSelected ){ // VisualObjects
		for( VOIterator i=_VisualObjects.begin(); i != _VisualObjects.end(); ++i){
			(*i)->OnLButtonDown(nFlags,point);
			if( (*i)->Selected() ){
				bSelected = true;
			}
		}
	}
	if( !bSelected ){ // 看是否需要画新VisualObject
		switch( getDrawingBox()->getDrawType() ){
		case CDrawingBox::DRAWNONE:
			break;
		case CDrawingBox::DRAWLINE:
			_VisualObjects.push_back(new CVisualLine(this,point));
			Invalidate();
			break;
		case CDrawingBox::DRAWPOINT:
			_VisualObjects.push_back(new CVisualPoint(this,point));
			Invalidate();
			break;
		case CDrawingBox::DRAWRECTANGLE:
			_VisualObjects.push_back(new CVisualRect(this,point));
			Invalidate();
			break;
		case CDrawingBox::DRAWCIRCLE:
			_VisualObjects.push_back(new CVisualCircle(this,point));
			Invalidate();
			break;
		default:
			break;
		}
	}else{
		Invalidate();
	}
	CDialog::OnLButtonDown(nFlags, point);
	if( !bSelected ){
		CString strHint;
		strHint.Format("(%.2f,%.2f)",ScreenX2FieldX(point.x),ScreenY2FieldY(point.y));
		getHintWindow()->ShowHint(point,strHint);
	}
}

bool CDisplayer::DeliverMessage(MSG* pMsg)
{
	if( pMsg->message == WM_KEYDOWN || pMsg->message == WM_CHAR || pMsg->message == WM_DROPFILES ){
		_pMainFrame->PostMessage(pMsg->message,pMsg->wParam,pMsg->lParam);
		return true;
	}
	return false;
}

BOOL CDisplayer::PreTranslateMessage(MSG* pMsg)
{
	if( DeliverMessage(pMsg) )
		return TRUE;
	return CDialog::PreTranslateMessage(pMsg);
}

void CDisplayer::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
	CMenu menu;
	if( m_bShowLogplay ) {
		menu.LoadMenu(IDR_LOGPLAYERPOPUP);
	}else {
		menu.LoadMenu(IDR_MONITORPOPUP);
	}
	
	CMenu *pPopUp = menu.GetSubMenu(0);
    pPopUp->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,AfxGetMainWnd()) ;
	ScreenToClient(&point);
	_selectedPoint.x = long(ScreenX2FieldX(point.x) * SHOWINFO_SCALE);
	_selectedPoint.y = long(ScreenY2FieldY(point.y) * SHOWINFO_SCALE);
}

void CDisplayer::SelectObject(int value)
{
	if( value >= 0 && value <= MAX_PLAYER * 2){
		m_nDebug = value;
	}else{
		m_nDebug = MAX_PLAYER * 2 + 1;
	}
	Invalidate();
}

void CDisplayer::OnObjectDetails()
{
	if( getObjectDetailDialog()->GetStyle() & WS_VISIBLE ){ // Visible
		getObjectDetailDialog()->ShowWindow(SW_HIDE);
	}else {
		getObjectDetailDialog()->ShowWindow(SW_SHOW);
	}
}

CObjectDetailDialog* CDisplayer::getObjectDetailDialog()
{
	while( _pObjectDetailDialog == NULL ){
		_pObjectDetailDialog = new CObjectDetailDialog(this,this);
		_pObjectDetailDialog->Create(IDD_OBJECTDETAIL,this);
	}
	return _pObjectDetailDialog;
}

CDrawingBox* CDisplayer::getDrawingBox()
{
	while( _pDrawingBox == NULL ){
		_pDrawingBox = new CDrawingBox(this,this);
		_pDrawingBox->Create(IDD_DRAWINGDIALOG,this);
	}
	return _pDrawingBox;
}
CPresentDialog* CDisplayer::getPresentDialog()
{
	while( _pPresentDlg == NULL ){
		_pPresentDlg = new CPresentDialog(this,this);
		_pPresentDlg->Create(IDD_PRESENTDIALOG,this);
	}
	return _pPresentDlg;
}
UINT CDisplayer::FieldX2ScreenX(double x)
{
	return CoordX(x) + CoordX(PITCH_MARGIN + PITCH_LENGTH / 2.0);
}

UINT CDisplayer::FieldY2ScreenY(double y)
{
	return CoordY(y) + CoordY(TOP_MARGIN + PITCH_MARGIN + PITCH_WIDTH / 2.0);
}

double CDisplayer::ScreenX2FieldX(long x)
{
	return (x - CoordX(PITCH_MARGIN + PITCH_LENGTH / 2.0))/m_dScale;
}

double CDisplayer::ScreenY2FieldY(long y)
{
	return (y - CoordY(TOP_MARGIN + PITCH_MARGIN + PITCH_WIDTH / 2.0))/m_dScale;
}

void CDisplayer::OnDrawingTools()
{
	if( getDrawingBox()->GetStyle() & WS_VISIBLE ){
		getDrawingBox()->ShowWindow(SW_HIDE);
	}else{
		getDrawingBox()->ShowWindow(SW_SHOW);
	}
}

int CDisplayer::getSelectedSide() const 
{ 
	if( m_nDebug == MAX_PLAYER*2 )
		return NEUTRAL;
	return m_nDebug < MAX_PLAYER ? LEFT : RIGHT;	
}

UINT CDisplayer::getSelectedNum() const 
{ 
	if( m_nDebug == MAX_PLAYER*2 )
		return 0;
	return m_nDebug < MAX_PLAYER ? m_nDebug + 1 : m_nDebug + 1 - MAX_PLAYER; 
}

void CDisplayer::OnDeleteVisualObject()
{	// 删除所有被选中的对象
	bool bNeedRedraw = false;
	std::vector<VOIterator> tmp;
	for( VOIterator i=_VisualObjects.begin(); i != _VisualObjects.end(); ++i ){
		if( (*i)->Selected() ){
			tmp.push_back(i);
			bNeedRedraw = true;
		}
	}
	for( std::vector<VOIterator>::iterator i=tmp.begin(); i< tmp.end(); ++i){
		delete (*(*i)); // 清除此对象
		_VisualObjects.erase(*i); // 列表中去掉此对象的指针
	}

	if( bNeedRedraw ){
		Invalidate();
	}
}

void CDisplayer::DrawVisualObjects(CDC *pDC)
{
	for( VOIterator i=_VisualObjects.begin(); i != _VisualObjects.end(); ++i ){
		(*i)->Draw(pDC);
	}
}
void CDisplayer::DrawPresent(CDC *pDC)
{
	CPresentDialog::PresentType PresentType = getPresentDialog()->getPresentType();
	if(  PresentType == CPresentDialog::PRESENT_POS ){
		const vector<PointFrameT>& vPos = _pMainFrame->getAnalyzer()->getPlayerPositionPointer();
		for( int i=0; i<vPos.size(); i++){
			if( m_nDebug == MAX_PLAYER*2){ // ball
				pDC->SetPixel(FieldX2ScreenX(vPos[i].ball.x),FieldY2ScreenY(vPos[i].ball.y),COLOR_YELLOW);
			}else if( m_nDebug >= 0 && m_nDebug < MAX_PLAYER*2){
				pDC->SetPixel(FieldX2ScreenX(vPos[i].pFrame[m_nDebug].x),FieldY2ScreenY(vPos[i].pFrame[m_nDebug].y),COLOR_YELLOW);
			}
		}
	}else if( PresentType != CPresentDialog::PRESENT_NONE && m_nDebug >= 0 && m_nDebug < MAX_PLAYER*2){
		const vector<BasicBehaviorEvent>& vEvent = _pMainFrame->getAnalyzer()->getBasicEventPointer();
		pDC->SelectObject(getPinkPen());
		for( int i=0; i<vEvent.size(); i++){
			if( vEvent[i].player == m_nDebug ){ // only draw select player's event
				if( (PresentType == CPresentDialog::PRESENT_SHOT && vEvent[i].type == BB_SHOOT) ||
					(PresentType == CPresentDialog::PRESENT_DRIBBLE && vEvent[i].type == BB_DRIBBLE) ||
					(PresentType == CPresentDialog::PRESENT_PASS && vEvent[i].type == BB_PASS) ||
					(PresentType == CPresentDialog::PRESENT_INTERCEPT && vEvent[i].type == BB_INTERCEPT) ){
						pDC->MoveTo(FieldX2ScreenX(vEvent[i].pt.x),FieldY2ScreenY(vEvent[i].pt.y));
						pDC->LineTo(FieldX2ScreenX(vEvent[i].obj.pt.x),FieldY2ScreenY(vEvent[i].obj.pt.y));
						pDC->Ellipse(FieldX2ScreenX(vEvent[i].pt.x)-2,FieldY2ScreenY(vEvent[i].pt.y)-2,FieldX2ScreenX(vEvent[i].pt.x)+2,FieldY2ScreenY(vEvent[i].pt.y)+2);
					}
			}
		}
	}
}
void CDisplayer::OnToolboxPresent()
{
	if( getPresentDialog()->GetStyle() & WS_VISIBLE ){
		getPresentDialog()->ShowWindow(SW_HIDE);
	}else{
		getPresentDialog()->ShowWindow(SW_SHOW);
	}
}

void CDisplayer::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	CDialog::OnLButtonDblClk(nFlags, point);
	doFullScreen();
}
void CDisplayer::doFullScreen()
{
	if( GetStyle() & WS_MAXIMIZE ){
		ModifyStyle(0,WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU);
		ShowWindow(SW_RESTORE);
	}else{
		ModifyStyle(WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU,0);
		ShowWindow(SW_MAXIMIZE);
	}
}
CHintWindow* CDisplayer::getHintWindow()
{
	while( _pHintWindow == NULL ){
		_pHintWindow = new CHintWindow;
		_pHintWindow->CreateHintWindow(this);
	}
	return _pHintWindow;
}

void CDisplayer::DrawOffsideLine(CDC *pDC)
{
	if( _pCycleInfo==NULL || _pCycleInfo->bSight){ // 现在只能画serverlog中的数据
		return;
	}
	// left offside line
	double left_offside_line = min(_CurrentShowInfo.ball.x,0),min_x(0),min_x2(0);
	for(int i=0;i<MAX_PLAYER;i++){
		if( _CurrentShowInfo.pos[i].mode == DISABLE ){ // 此队员不存在
			continue;
		}
		if( _CurrentShowInfo.pos[i].x < min_x ){
			min_x2 = min_x;
			min_x = _CurrentShowInfo.pos[i].x;
		}else if( _CurrentShowInfo.pos[i].x < min_x2 ){
			min_x2 = _CurrentShowInfo.pos[i].x;
		}
	}
	left_offside_line = min(left_offside_line,min_x2);
	double right_offside_line = max(_CurrentShowInfo.ball.x,0),max_x(0),max_x2(0);
	bool right_team_offside(false);
	for(int i=MAX_PLAYER; i<MAX_PLAYER*2; ++i){
		if( _CurrentShowInfo.pos[i].mode == DISABLE ){ // 此队员不存在
			continue;
		}
		if( _CurrentShowInfo.pos[i].x < left_offside_line ){
			right_team_offside = true;
		}
		if( _CurrentShowInfo.pos[i].x > max_x ){
			max_x2 = max_x;
			max_x = _CurrentShowInfo.pos[i].x;
		}else if( _CurrentShowInfo.pos[i].x > max_x2 ){
			max_x2 = _CurrentShowInfo.pos[i].x;
		}
	}
	if( right_team_offside ){
		pDC->SelectObject(getRedPen());
	}else{
		pDC->SelectObject(getPinkPen());
	}
	pDC->MoveTo(FieldX2ScreenX(left_offside_line),FieldY2ScreenY(-PITCH_WIDTH/2));
	pDC->LineTo(FieldX2ScreenX(left_offside_line),FieldY2ScreenY(PITCH_WIDTH/2));
	
	// right offside line
	right_offside_line = max(right_offside_line,max_x2);
	bool left_team_offside(false);
	for(int i=0;i<MAX_PLAYER;i++){
		if( _CurrentShowInfo.pos[i].mode == DISABLE ){ // 此队员不存在
			continue;
		}
		if( _CurrentShowInfo.pos[i].x > right_offside_line ){
			left_team_offside = true;
		}
	}
	if( left_team_offside ){
		pDC->SelectObject(getRedPen());
	}else{
		pDC->SelectObject(getPinkPen());
	}
	pDC->MoveTo(FieldX2ScreenX(right_offside_line),FieldY2ScreenY(-PITCH_WIDTH/2));
	pDC->LineTo(FieldX2ScreenX(right_offside_line),FieldY2ScreenY(PITCH_WIDTH/2));
}

void CDisplayer::DrawControlCourse(CDC *pDC)
{
	BasicBehaviorEvent Event;
	for( int side=LEFT; ; side=RIGHT){
		for( int uum=1; uum<=MAX_PLAYER; ++uum ){
			Event = (_pMainFrame->getAnalyzer())->getPlayerBehavior(GameTime(),side,uum);
			if( Event.type == BB_DRIBBLE || Event.type == BB_PASS || Event.type == BB_SHOOT || Event.type == BB_CLEARBALL || Event.type == BB_ADJUST){
				if( _CurrentControlSide != side ){
					_ControlEvents.clear();
					_CurrentControlSide = side;
				}
				_ControlEvents.push_back(Event);
			}
		}
		if( RIGHT == side){
			break;
		}
	}
	for( CEIterator i=_ControlEvents.begin(); i<_ControlEvents.end(); ++i){
		switch( i->type ){
		case BB_DRIBBLE:
		case BB_ADJUST:
			pDC->SelectObject(getPinkPen());
			break;
		case BB_SHOOT:
			pDC->SelectObject(getRedPen());
			break;
		case BB_PASS:
		case BB_CLEARBALL:
			pDC->SelectObject(getWhitePen());
			break;
		default:
			break;
		}
		pDC->MoveTo(FieldX2ScreenX(i->pt.x),FieldY2ScreenY(i->pt.y));
		pDC->LineTo(FieldX2ScreenX(i->obj.pt.x),FieldY2ScreenY(i->obj.pt.y));
	}
}

⌨️ 快捷键说明

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