Exemple #1
0
void BuildModeDialog::OnChangeChild( int direction )
{
	Assert( direction == 1 || direction == -1 );
	if ( !m_pBuildGroup )
		return;

	Panel *current = m_pCurrentPanel;
	Panel *context = m_pBuildGroup->GetContextPanel();

	if ( !current || current == context )
	{
		current = NULL;
		if ( context->GetChildCount() > 0 )
		{
			current = context->GetChild( 0 );
		}
	}
	else
	{
		int i;
		// Move in direction requested
		int children = context->GetChildCount();
		for ( i = 0; i < children; ++i )
		{
			Panel *child = context->GetChild( i );
			if ( child == current )
			{
				break;
			}
		}

		if ( i < children )
		{
			for ( int offset = 1; offset < children; ++offset )
			{
				int test = ( i + ( direction * offset ) ) % children;
				if ( test < 0 )
					test += children;
				if ( test == i )
					continue;

				Panel *check = context->GetChild( test );
				BuildModeDialog *bm = dynamic_cast< BuildModeDialog * >( check );
				if ( bm )
					continue;

				current = check;
				break;
			}
		}
	}

	if ( !current )
	{
		return;
	}

	SetActiveControl( current );
}
Exemple #2
0
//-----------------------------------------------------------------------------
// Purpose: Find the correct radio button to move to.
// Input  : direction - the direction we are moving, up or down. 
//-----------------------------------------------------------------------------
RadioButton *RadioButton::FindBestRadioButton(int direction)
{
	RadioButton *bestRadio = NULL;
	int highestRadio = 0;
	Panel *pr = GetParent();
	if (pr)
	{
		// find the radio button to go to next
		for (int i = 0; i < pr->GetChildCount(); i++)
		{
			RadioButton *child = dynamic_cast<RadioButton *>(pr->GetChild(i));
			if (child && child->GetRadioTabPosition() == _oldTabPosition)
			{
				if (child->GetSubTabPosition() == _subTabPosition + direction)
				{
					bestRadio = child;
					break;
				}
				if ( (child->GetSubTabPosition() == 0)  && (direction == DOWN) )
				{
					bestRadio = child;
					continue;
				}
				else if ( (child->GetSubTabPosition() > highestRadio) && (direction == UP) )
				{
					bestRadio = child;
					highestRadio = bestRadio->GetSubTabPosition();
					continue;
				}
				if (!bestRadio)
				{
					bestRadio = child;
				}
			}
		}
		
		if (bestRadio)
		{
			bestRadio->RequestFocus();
		}
		
		InvalidateLayout();
		Repaint();
	}

	return bestRadio;
}