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

📄 settingcolor.cpp

📁 FIRA 3对3 机器人足球PC端控制程序。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		SetDlgItemInt(IDC_GMIN_SCROLLBAR, idcolor[0][2], FALSE);		 	                   	
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_GMAX_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[0][3], TRUE); 	                        
		SetDlgItemInt(IDC_GMAX_SCROLLBAR, idcolor[0][3], FALSE);		 	                   		
	 	pScroll	= (CScrollBar *)GetDlgItem(IDC_BMIN_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[0][4], TRUE); 	                   
		SetDlgItemInt(IDC_BMIN_SCROLLBAR, idcolor[0][4], FALSE);		 	                   			
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_BMAX_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[0][5], TRUE); 	                                
		SetDlgItemInt(IDC_BMAX_SCROLLBAR, idcolor[0][5], FALSE);
	}    
	UpdateData(FALSE);
}


void CSettingColor::OnId2Color() 
{
/////////////////////////////////////////////////
// Choi.W.H  2000.02.18 
	// TODO: Add your control notification handler code here
	char tmp[10];
	CScrollBar *pScroll;	
	
	UpdateData(TRUE);
	if(bSetColor == FALSE){
		sprintf(tmp, "%u", idcolor[1][0]); 
		m_sRmin = tmp; 
		sprintf(tmp, "%u", idcolor[1][1]); 
		m_sRmax = tmp;
		sprintf(tmp, "%u", idcolor[1][2]); 
		m_sGmin = tmp;
		sprintf(tmp, "%u", idcolor[1][3]); 
		m_sGmax = tmp;
		sprintf(tmp, "%u", idcolor[1][4]); 
		m_sBmin = tmp;
		sprintf(tmp, "%u", idcolor[1][5]); 
		m_sBmax = tmp;

	 	pScroll	= (CScrollBar *)GetDlgItem(IDC_RMIN_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[1][0], TRUE); 	                   
		SetDlgItemInt(IDC_RMIN_SCROLLBAR, idcolor[1][0], FALSE);	
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_RMAX_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[1][1], TRUE);
		SetDlgItemInt(IDC_RMAX_SCROLLBAR, idcolor[1][1], FALSE);		 	                   
	 	pScroll	= (CScrollBar *)GetDlgItem(IDC_GMIN_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[1][2], TRUE); 	                       
		SetDlgItemInt(IDC_GMIN_SCROLLBAR, idcolor[1][2], FALSE);		 	                   	
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_GMAX_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[1][3], TRUE); 	                        
		SetDlgItemInt(IDC_GMAX_SCROLLBAR, idcolor[1][3], FALSE);		 	                   		
	 	pScroll	= (CScrollBar *)GetDlgItem(IDC_BMIN_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[1][4], TRUE); 	                   
		SetDlgItemInt(IDC_BMIN_SCROLLBAR, idcolor[1][4], FALSE);		 	                   			
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_BMAX_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[1][5], TRUE); 	                                
		SetDlgItemInt(IDC_BMAX_SCROLLBAR, idcolor[1][5], FALSE);
	}    
	UpdateData(FALSE);
// Choi.W.H  2000.02.18
// //////////////////////////////////////////////
}


void CSettingColor::OnId3Color() 
{
/////////////////////////////////////////////////
// Choi.W.H  2000.02.18 
	// TODO: Add your control notification handler code here
	char tmp[10];
	CScrollBar *pScroll;	
	
	UpdateData(TRUE);
	if(bSetColor == FALSE){
		sprintf(tmp, "%u", idcolor[2][0]); 
		m_sRmin = tmp; 
		sprintf(tmp, "%u", idcolor[2][1]); 
		m_sRmax = tmp;
		sprintf(tmp, "%u", idcolor[2][2]); 
		m_sGmin = tmp;
		sprintf(tmp, "%u", idcolor[2][3]); 
		m_sGmax = tmp;
		sprintf(tmp, "%u", idcolor[2][4]); 
		m_sBmin = tmp;
		sprintf(tmp, "%u", idcolor[2][5]); 
		m_sBmax = tmp;

	 	pScroll	= (CScrollBar *)GetDlgItem(IDC_RMIN_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[2][0], TRUE); 	                   
		SetDlgItemInt(IDC_RMIN_SCROLLBAR, idcolor[2][0], FALSE);	
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_RMAX_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[2][1], TRUE);
		SetDlgItemInt(IDC_RMAX_SCROLLBAR, idcolor[2][1], FALSE);		 	                   
	 	pScroll	= (CScrollBar *)GetDlgItem(IDC_GMIN_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[2][2], TRUE); 	                       
		SetDlgItemInt(IDC_GMIN_SCROLLBAR, idcolor[2][2], FALSE);		 	                   	
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_GMAX_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[2][3], TRUE); 	                        
		SetDlgItemInt(IDC_GMAX_SCROLLBAR, idcolor[2][3], FALSE);		 	                   		
	 	pScroll	= (CScrollBar *)GetDlgItem(IDC_BMIN_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[2][4], TRUE); 	                   
		SetDlgItemInt(IDC_BMIN_SCROLLBAR, idcolor[2][4], FALSE);		 	                   			
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_BMAX_SCROLLBAR);
		pScroll->SetScrollPos(idcolor[2][5], TRUE); 	                                
		SetDlgItemInt(IDC_BMAX_SCROLLBAR, idcolor[2][5], FALSE);
	}    
	UpdateData(FALSE);
// Choi.W.H  2000.02.18
// //////////////////////////////////////////////
}


void CSettingColor::OnOpponentColor() 
{
	// TODO: Add your control notification handler code here
	char tmp[10];
	CScrollBar *pScroll;	
	
	UpdateData(TRUE);
	if(bSetColor == FALSE){
		sprintf(tmp, "%u", opponentcolor[0]); 
		m_sRmin = tmp; 
		sprintf(tmp, "%u", opponentcolor[1]); 
		m_sRmax = tmp;
		sprintf(tmp, "%u", opponentcolor[2]); 
		m_sGmin = tmp;
		sprintf(tmp, "%u", opponentcolor[3]); 
		m_sGmax = tmp;
		sprintf(tmp, "%u", opponentcolor[4]); 
		m_sBmin = tmp;
		sprintf(tmp, "%u", opponentcolor[5]); 
		m_sBmax = tmp;

	 	pScroll	= (CScrollBar *)GetDlgItem(IDC_RMIN_SCROLLBAR);
		pScroll->SetScrollPos(opponentcolor[0], TRUE); 	                   
		SetDlgItemInt(IDC_RMIN_SCROLLBAR, opponentcolor[0], FALSE);	
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_RMAX_SCROLLBAR);
		pScroll->SetScrollPos(opponentcolor[1], TRUE);
		SetDlgItemInt(IDC_RMAX_SCROLLBAR, opponentcolor[1], FALSE);		 	                   
	 	pScroll	= (CScrollBar *)GetDlgItem(IDC_GMIN_SCROLLBAR);
		pScroll->SetScrollPos(opponentcolor[2], TRUE); 	                       
		SetDlgItemInt(IDC_GMIN_SCROLLBAR, opponentcolor[2], FALSE);		 	                   	
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_GMAX_SCROLLBAR);
		pScroll->SetScrollPos(opponentcolor[3], TRUE); 	                        
		SetDlgItemInt(IDC_GMAX_SCROLLBAR, opponentcolor[3], FALSE);		 	                   		
	 	pScroll	= (CScrollBar *)GetDlgItem(IDC_BMIN_SCROLLBAR);
		pScroll->SetScrollPos(opponentcolor[4], TRUE); 	                   
		SetDlgItemInt(IDC_BMIN_SCROLLBAR, opponentcolor[4], FALSE);		 	                   			
 		pScroll	= (CScrollBar *)GetDlgItem(IDC_BMAX_SCROLLBAR);
		pScroll->SetScrollPos(opponentcolor[5], TRUE); 	                                
		SetDlgItemInt(IDC_BMAX_SCROLLBAR, opponentcolor[5], FALSE);		 	                   				
	}    
	UpdateData(FALSE);
}


void CSettingColor::CreateOverlayImage()
{
	/* Prepare overlay buffer. */
	/* Disable overlay display while preparing the data. */
	MdispControl(MilDisplayId, M_WINDOW_OVR_SHOW, M_DISABLE);
	/* Enable writing Overlay graphics on top of display buffer. */
	MdispControl(MilDisplayId, M_WINDOW_OVR_WRITE, M_ENABLE);
	/* Inquire the Overlay buffer associated with the displayed buffer. */
	MdispInquire(MilDisplayId, M_WINDOW_OVR_BUF_ID, &MilOverlayImage);
	/* Inquire the current keying color. */
	MdispInquire(MilDisplayId, M_KEY_COLOR, &TransparentColor);
	/* Clear the overlay buffer with the keying color. */
	MbufClear(MilOverlayImage, TransparentColor); 
	/* Enable the overlay display. */
	MdispControl(MilDisplayId, M_WINDOW_OVR_SHOW, M_ENABLE);
	/* Inquire MilOverlayImage size x and y. */
	ImageWidth  = MbufInquire(MilOverlayImage,M_SIZE_X,M_NULL);
	ImageHeight = MbufInquire(MilOverlayImage,M_SIZE_Y,M_NULL);
	/* Set graphic text to transparent background. */
//	MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT);

	/* Create a child buffer on the green component for drawing. */
	MbufChildColor(MilOverlayImage, M_GREEN , &MilOverlayImageGreen);
    /* Set drawing color to maximum intensity for green. */
	MgraColor(M_DEFAULT, 255);
	/* Print a string in the green component overlay image buffer. */
	MgraFont(M_DEFAULT, M_FONT_DEFAULT_LARGE);
    MgraText(M_DEFAULT, MilOverlayImageGreen, ImageWidth/2-150, ImageHeight/2-5, "Adjust the Range of Color");
	MgraFont(M_DEFAULT, M_FONT_DEFAULT);
    
}

void CSettingColor::DestroyOverlayImage()
{
	// Free the child buffer.
	MbufFree(MilOverlayImageGreen);
	// Disable the overlay display. 
	MdispControl(MilDisplayId, M_WINDOW_OVR_SHOW, M_DISABLE);
	// Disable writing Overlay graphics on top of display buffer.
	MdispControl(MilDisplayId, M_WINDOW_OVR_WRITE, M_DISABLE);

}


void CSettingColor::OnBlackBackgroundCheck() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

}


BOOL CSettingColor::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class

	KillTimer(2);

	DestroyOverlayImage();

	MdigGrabContinuous(MilDigitizerId, MilImageBufferId);
	
	return CDialog::DestroyWindow();
}

void CSettingColor::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	
	switch(nIDEvent) {
	case 1 :
		KillTimer(1);
		SetTimer(2, 1000, NULL);
	case 2 :
		BYTE *ptrBuf;
		int NumPixel;
		int y, u, v;

		MdigGrab(MilDigitizerId, MilImageBufferId);
		MbufGetColor(MilImageBufferId, M_RGB32 + M_PACKED, M_ALL_BAND, pImageBuffer);

		if(m_bBlackBackground)
			MbufClear(MilOverlayImage, 0x00);
		else
			MbufClear(MilOverlayImage, TransparentColor);
			
		color[0] = atoi((const char *)(m_sRmin));
		color[1] = atoi((const char *)(m_sRmax));
		color[2] = atoi((const char *)(m_sGmin));
		color[3] = atoi((const char *)(m_sGmax));
		color[4] = atoi((const char *)(m_sBmin));
		color[5] = atoi((const char *)(m_sBmax));
		
		// Create a device context to draw in the overlay buffer with GDI. 
		MbufControl(MilOverlayImage, M_WINDOW_DC_ALLOC, M_DEFAULT);
		// Attach the device context.
		CDC NewDC;
		CPen pen, *pOldPen;
		NewDC.Attach((HDC)MbufInquire(MilOverlayImage, M_WINDOW_DC, M_NULL));
		pen.CreatePen(PS_SOLID, 1, RGB(0,255,0));
		pOldPen = NewDC.SelectObject(&pen);
		
		ptrBuf = pImageBuffer;
		NumPixel = 0;

		if(m_bBlackBackground) {
			for(h = 0;h < DispSizeY;h++){
				for(w = 0;w < DispSizeX;w++){
					r = *ptrBuf;
					g = *(ptrBuf+1);
					b = *(ptrBuf+2);

					y = (int)(299*r + 587*g + 114*b);
					y = min(255000,max(y,0));
					u = (int)(565*(1000*b-y) + 128000000)/1000000;
					u = min(255000,max(u,0));
					v = (int)(713*(1000*r-y) + 128000000)/1000000;
					v = min(255,max(v,0));
					y /= 1000;
					if( y >= color[0] && y <= color[1] &&
						u >= color[2] && u <= color[3] &&
						v >= color[4] && v <= color[5] ) {
							NewDC.SetPixelV(w, h, RGB(r, g, b));
							NumPixel++;
					} 
				
					ptrBuf += 4;
				}
			}
		}
		else {
			for(h = 0;h < DispSizeY;h++){
				for(w = 0;w < DispSizeX;w++){
					r = *ptrBuf;
					g = *(ptrBuf+1);
					b = *(ptrBuf+2);

					y = (int)(299*r + 587*g + 114*b);
					y = min(255000,max(y,0));
					u = (int)(565*(1000*b-y) + 128000000)/1000000;
					u = min(255000,max(u,0));
					v = (int)(713*(1000*r-y) + 128000000)/1000000;
					v = min(255,max(v,0));
					y /= 1000;
				
					if( y >= color[0] && y <= color[1] &&
						u >= color[2] && u <= color[3] &&
						v >= color[4] && v <= color[5] ) {
							NewDC.SetPixelV(w, h, RGB(0,255,0));
							NumPixel++;
					} 

					ptrBuf += 4;
				}
			}
		}

		NewDC.SelectObject(pOldPen);                         
		pen.DeleteObject();   
		NewDC.Detach();

		char tmp[30];
		sprintf(tmp, "Number of Pixel = %d", NumPixel);
		MgraText(M_DEFAULT, MilOverlayImageGreen, 10, 5, tmp);
		
        // Delete created device context. 
        MbufControl(MilOverlayImage, M_WINDOW_DC_FREE, M_DEFAULT);

		MdigGrab(MilDigitizerId, MilImageBufferId);
				
		break;
	}

	CDialog::OnTimer(nIDEvent);
}



⌨️ 快捷键说明

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