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

📄 ddbutton.cpp

📁 网页游戏赤壁
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	  &&(y >= m_nTopEdge )&&(y <= m_nBottomEdge) )
		return TRUE;
	else
		return FALSE;
}
// to show this button
void CDDButton::Show(BOOL flag /*= TRUE*/)	// flag = TRUE --> to place bitmap to back buffer and updata the front butter
										//        FALSE -> only to place bitmap to back buffer
{
	Blit();
	if(flag == TRUE)
		Update();
}
// to blit this button to back buffer
void CDDButton::Blit()
{
	POINT	ptDest;

	ptDest.x = m_dwX;
	ptDest.y = m_dwY;

	if( m_nState != BUTTON_HIDE )
		m_BitmapSurface.BltToBack(ptDest, &m_rCurrent);
}
// to update the area of this button from back buffer to front buffer
void CDDButton::Update()
{
	RECT	ShowRect;

	ShowRect.left = m_dwX,	ShowRect.top = m_dwY;
	ShowRect.right = m_dwX + m_szOneBitmap.cx;
	ShowRect.bottom = m_dwY + m_szOneBitmap.cy;

	DDC_UpdateScreen( &ShowRect );
}
// to send a message to notion that this button is clicked
LRESULT	CDDButton::SendAMessage( int lParam /*=0*/ )
{
	LRESULT	m_result;

	m_result = PostMessage(hwndGame, WM_COMMAND, m_nID, lParam);

	return m_result ;
}
///////////////////////////////////////////////
// to define all CDDButtonUnit member function
///////////////////////////////////////////////
CDDButtonUnit::CDDButtonUnit()
{
	for( int i=0; i<MAX_BUTTONINUNIT; i++ )
	{
		m_pButton[i] = NULL;
	}
}
// to set state of each button that in this command unit
void	CDDButtonUnit::SetMemberState( int state )
{
	for( int i=0; i<MAX_BUTTONINUNIT; i++ )
	{
		if( m_pButton[i] != NULL )
		{
			m_pButton[i]->SetState(state);
		}
	}
}
// to show this button-unit
void	CDDButtonUnit::Show( BOOL flag /*=TRUE*/ )
{
/*	for( int i=0; i<MAX_BUTTONINUNIT; i++ )
	{
		if( m_pButton[i] != NULL )
		{
			m_pButton[i]->Show(flag);
		}	
	}	*/
	Blit();
	if(flag == TRUE)
		Update();
}
// to blit every button of this button unit to back buffer
void CDDButtonUnit::Blit()
{
	for( int i=0; i<MAX_BUTTONINUNIT; i++ )
	{
		if( m_pButton[i] != NULL )
		{
			m_pButton[i]->Blit();
		}	
	}
}
// to update the area of every one button in this button unit from back buffer to front buffer
void CDDButtonUnit::Update()
{
	for( int i=0; i<MAX_BUTTONINUNIT; i++ )
	{
		if( m_pButton[i] != NULL )
		{
			m_pButton[i]->Update();
		}	
	}
}
// to release this button-unit
void	CDDButtonUnit::Release()
{
	for( int i=0; i<MAX_BUTTONINUNIT; i++ )
	{
//		if( FACE_GetCommandState() == COMMAND_STATE_MENU
//		 && m_pButton[i] == pCurrentButton )
		if( m_pButton[i] == pCurrentButton )
		{
			pCurrentButton = NULL ;
			nCurrentButtonState = BUTTON_NONE;
		}
		if( m_pButton[i] != NULL )
		{
			delete m_pButton[i];
			m_pButton[i] = NULL;
		}
	}
}
/////////////////////////////////////////
// to test whether a button is clicked ----WM_LBUTTONDOWN
/////////////////////////////////////////
BOOL	LeftButtonDownOnButton(int xPos, int yPos)
{
	for( int i=0; i<MAX_BUTTON; i++ )
	{
		if( (pAllButton[i] != NULL)&&(pAllButton[i]->GetState() != BUTTON_HIDE)
		  &&(pAllButton[i]->GetState() != BUTTON_DISABLE)
		  &&( pAllButton[i]->OnButton(xPos, yPos) ) )
		{
		// to transfer current button's pointer and state to previous
			pPreviousButton = pCurrentButton;
			nPreviousButtonState = nCurrentButtonState;
			// set the just been clicked button's state
			pAllButton[i]->SetState(BUTTON_DOWN);
			pAllButton[i]->Show();
			// to set the global button's state
			pCurrentButton = pAllButton[i];
			nCurrentButtonState = BUTTON_DOWN;
/*
			char wavfile[_MAX_FNAME];
			extern char GAME_strSetupDirectory[_MAX_PATH];
			strcpy( wavfile, GAME_strSetupDirectory );
			strcat( wavfile, "\\sound\\Click.wav" );
*/
			strcpy( Wave.strFileName, "Effect\\Click.wav" );
			if( Wave.Play(0) == FALSE )
			{
				char wavfile[_MAX_FNAME];
				extern char GAME_strSetupDirectory[_MAX_PATH];
				strcpy( wavfile, GAME_strSetupDirectory );
				strcat( wavfile, "\\sound\\Click.wav" );
				strcpy( Wave.strFileName, wavfile );
				Wave.Play(0);
			}
			return TRUE;
		}
	}
	return	FALSE;
}
//////////////////////////////////////////////////////////////////////
// to test whether cursor is on current button when left button up---WM_LBUTTONUP
///////////////////////////////////////////////////////////////////////
BOOL	LeftButtonUpOnButton( int xPos, int yPos)
{
	if( pCurrentButton==NULL )
		return FALSE ;

	if( nCurrentButtonState == BUTTON_DOWN )
	{
		if( pCurrentButton->OnButton(xPos, yPos) &&
	   	    (pCurrentButton->GetState() != BUTTON_HIDE) &&
			(pCurrentButton->GetState() != BUTTON_DISABLE) )
		{
				// to transfer current button's pointer and state to previous
				pPreviousButton = pCurrentButton;
				nPreviousButtonState = nCurrentButtonState;
				// set the just been clicked button's state
				pCurrentButton->SetState(BUTTON_UP);
				pCurrentButton->Show();
				pCurrentButton->SendAMessage();
				// to erase the prompt string area
				pCurrentButton->ErasePromptRect();
				pCurrentButton = NULL;
				// to set the global button's state
				nCurrentButtonState = BUTTON_UP;

				return TRUE;
		}
	}
	return FALSE;
}
///////////////////////////////////////////////////////////
// to test whether cursor is moved on a button ----- WM_ONMOUSEMOVE
///////////////////////////////////////////////////////////
BOOL	MouseMoveOnButton(int xPos, int yPos)
{
	// to up the button that has press down when mouse leave the button with left button pressed
	if( nCurrentButtonState == BUTTON_DOWN )
	{
		if( pCurrentButton==NULL )
			return FALSE ;

		if( ( ! pCurrentButton->OnButton(xPos, yPos) )&&
	   	    (pCurrentButton->GetState() != BUTTON_HIDE) &&
			(pCurrentButton->GetState() != BUTTON_DISABLE) )
		{
				// to transfer current button's pointer and state to previous
				pPreviousButton = pCurrentButton;
				nPreviousButtonState = nCurrentButtonState;
				// set the just been clicked button's state
				pCurrentButton->SetState(BUTTON_UP);
				pCurrentButton->Show();
				// to erase the prompt string area
				pCurrentButton->ErasePromptRect();
				// to set the global button's state
				pCurrentButton = NULL;
				nCurrentButtonState = BUTTON_NONE;
				return TRUE;
		}
		return TRUE;
	}
	// to restore the state of a hight light button (forcus button) to normal when mouse move out the region of this button
	if( nCurrentButtonState == BUTTON_FOCUS )
	{
		Assert(pCurrentButton !=NULL);
		if( pCurrentButton==NULL )
			return FALSE ;

		if( ! pCurrentButton->OnButton(xPos, yPos) )
		{
			pPreviousButton = pCurrentButton;
			nPreviousButtonState = nCurrentButtonState;
			// set the just been clicked button's state
			if( (pCurrentButton->GetState() != BUTTON_HIDE)
			  &&(pCurrentButton->GetState() != BUTTON_DISABLE) )
			{
				pCurrentButton->SetState(BUTTON_UP);
				pCurrentButton->Show();
			}
			// to erase the prompt string area
			pCurrentButton->ErasePromptRect();
			// to set the global button's state
			pCurrentButton = NULL;
			nCurrentButtonState = BUTTON_NONE;
			return TRUE;
		}

/*		for( int i=0; i<MAX_BUTTON; i++ )		//
		{
			if( (pAllButton[i] != NULL)
			  &&(pAllButton[i]->GetState() == BUTTON_FOCUS)
			  &&( ! pAllButton[i]->OnButton(xPos, yPos) ) )
			{
				// to transfer current button's pointer and state to previous
//				pCurrentButton = pPreviousButton;
//				nCurrentButtonState = nPreviousButtonState;
				// set the just been clicked button's state
				pCurrentButton->SetState(nPreviousButtonState);
				pCurrentButton->Show();
				// to erase the prompt string area
				pCurrentButton->ErasePromptRect();
				// to set the global button's state
				pCurrentButton = NULL;
				nCurrentButtonState = BUTTON_NONE;
				return TRUE;
			}
		}
*/	}
	// to show the button in hight light ( forcus state ) when mouse move on it
	else
	{
		for( int i=0; i<MAX_BUTTON; i++ )		//
		{
			if( (pAllButton[i] != NULL)
			  &&(pAllButton[i]->GetState() != BUTTON_HIDE)
			  &&(pAllButton[i]->GetState() != BUTTON_DISABLE)
			  &&(pAllButton[i]->OnButton(xPos, yPos) ) )
			{
				// to transfer current button's pointer and state to previous
				if(pCurrentButton == NULL)
				{
					pCurrentButton = pAllButton[i];	
					nCurrentButtonState = BUTTON_UP;
				}
				pPreviousButton = pCurrentButton;
				nPreviousButtonState = nCurrentButtonState;
				// set the just been clicked button's state
				pAllButton[i]->SetState(BUTTON_FOCUS);
				pAllButton[i]->Show();
				// to erase the prompt string area
				pCurrentButton->ErasePromptRect();
				// to show prompt string
				pAllButton[i]->ShowPromptString();
				// to set the global button's state
				pCurrentButton = pAllButton[i];
				nCurrentButtonState = BUTTON_FOCUS;
				return TRUE;
			}
		}
	}
	return FALSE;
}
/////////////////////////////////////////
// to set all button's state when change the command state
void FACE_SetAllButtonState(int state)	// let button up or down or ...
{
	for( int i=0; i<MAX_BUTTON; i++ )
	{
		if( pAllButton[i] != NULL )
		{
			pAllButton[i]->SetAllButtonState(state);
		}
	}
}
// to restore all button's state when change the command state
void FACE_RestoreAllButtonState()	// let button up or down or ...
{
	for( int i=0; i<MAX_BUTTON; i++ )
	{
		if( pAllButton[i] != NULL )
		{
			pAllButton[i]->RestoreAllButtonState();
		}
	}
}
///////////////////////////////
//	to set pause button to active when you set
void	FACE_SetPauseButtonActive()
{
	for( int i=0; i<MAX_BUTTON; i++ )
	{
		if( pAllButton[i] != NULL && pAllButton[i]->GetID() == BUTTON_PAUSE)
		{
			pAllButton[i]->SetState(BUTTON_UP);
			pAllButton[i]->SetState(BUTTON_UP);
		}
	}
}
///////////////////////////////
// to delete all button in pAllButton[] array
void	FACE_DeleteAllButton()
{
	for( int i=0; i<MAX_BUTTON; i++ )
	{
		if( pAllButton[i] != NULL )
		{
			pAllButton[i]->Release();
			pAllButton[i] = NULL;
		}
	}
}
////////////// END

⌨️ 快捷键说明

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