Exemplo n.º 1
0
const FVector2D UKUIInterfaceElement::CalculateAlignLocation( const FVector2D& v2Origin, const FVector2D& v2Extent, const FVector2D& v2Size, const FVector2D& v2Default )
{
	FVector2D v2AlignLocation;
	const FVector2D v2MarginSize = GetMarginSize(); // X+Z, Y+W

	if ( bDebug )
		KUILogUO( "(%f,%f) (%f,%f) (%f,%f) (%f,%f)", ExpandV2( v2Origin ), ExpandV2( v2Extent ), ExpandV2( v2Size ), ExpandV2( v2Default ) );

	switch ( GetHorizontalAlignment() )
	{
		case EKUIInterfaceHAlign::HA_Left: 
			v2AlignLocation.X = v2Origin.X;
			break;

		case EKUIInterfaceHAlign::HA_Centre: 
			v2AlignLocation.X = v2Origin.X + ( v2Extent.X / 2.f ) - ( v2Size.X / 2.f ); 
			break;

		case EKUIInterfaceHAlign::HA_Right:
			v2AlignLocation.X = v2Origin.X + v2Extent.X - v2Size.X;
			break;

		case EKUIInterfaceHAlign::HA_Left_Outer:
			v2AlignLocation.X = v2Origin.X - v2Size.X;
			break;

		case EKUIInterfaceHAlign::HA_Right_Outer:
			v2AlignLocation.X = v2Origin.X + v2Extent.X;
			break;

		case EKUIInterfaceHAlign::HA_Fill:
			SetSize( v2Extent.X - v2MarginSize.X, GetSize().Y );
			v2AlignLocation.X = v2Origin.X;
			break;

		case EKUIInterfaceHAlign::HA_None:
		default:
			v2AlignLocation.X = v2Default.X;
			break;
	}

	switch ( GetVerticalAlignment() )
	{
		case EKUIInterfaceVAlign::VA_Top: 
			v2AlignLocation.Y = v2Origin.Y; 
			break;

		case EKUIInterfaceVAlign::VA_Centre: 
			v2AlignLocation.Y = v2Origin.Y + ( v2Extent.Y / 2.f ) - ( v2Size.Y / 2.f ); 
			break;

		case EKUIInterfaceVAlign::VA_Bottom:
			v2AlignLocation.Y = v2Origin.Y + v2Extent.Y - v2Size.Y;
			break;

		case EKUIInterfaceVAlign::VA_Top_Outer:
			v2AlignLocation.Y = v2Origin.Y - v2Size.Y;
			break;

		case EKUIInterfaceVAlign::VA_Bottom_Outer:
			v2AlignLocation.Y = v2Origin.Y + v2Extent.Y;
			break;

		case EKUIInterfaceVAlign::VA_Fill:
			SetSize( GetSize().X, v2Extent.Y - v2MarginSize.Y );
			v2AlignLocation.Y = v2Origin.Y;
			break;

		case EKUIInterfaceVAlign::VA_None:
		default:
			v2AlignLocation.Y = v2Default.Y;
			break;
	}

	v2AlignLocation += GetMarginOffset();

	if ( bDebug )
		KUILogUO( "%f,%f", ExpandV2( v2AlignLocation ) );

	return v2AlignLocation;
}
Exemplo n.º 2
0
void AKUIInterface::Render( UCanvas* oCanvas )
{
	if ( !bShowHUD )
		return;

	if ( GEngine != NULL && GEngine->GameViewport != NULL )
	{	
		// Update the screen res.
		FVector2D v2ScreenResolution = FVector2D::ZeroVector;
		GEngine->GameViewport->GetViewportSize( v2ScreenResolution );

		if ( !this->v2ScreenResolution.Equals( v2ScreenResolution, 0.5f ) )
			OnScreenResolutionChange( this->v2ScreenResolution, v2ScreenResolution );

		this->v2ScreenResolution = v2ScreenResolution;

		if ( this->v2CursorLocation.X == KUI_INTERFACE_FIRST_CURSOR_UPDATE )
			this->v2CursorLocation = FVector2D( floor( this->v2ScreenResolution.X / 2.f ), floor( this->v2ScreenResolution.Y / 2.f ) );
	}
	
	if ( !IsTemplate() )
		OnRenderBP( Canvas );

#if KUI_INTERFACE_MOUSEOVER_DEBUG
	cmDebugMouseOver = NULL;
	v2DebugMouseOverLocation = FVector2D::ZeroVector;
	v2DebugMouseOverSize = FVector2D::ZeroVector;
#endif // KUI_INTERFACE_MOUSEOVER_DEBUG

	if ( IsVisible() )
	{
		for ( int32 i = 0; i < ctRootContainers.Num(); ++i )
		{
			if ( ctRootContainers[ i ] == NULL )
				continue;

			if ( i == EKUIInterfaceRoot::R_Cursor )
				continue;

#if KUI_INTERFACE_MOUSEOVER_DEBUG
			bDebugMouseOver = arDebugMouseOver[ i ];
#endif // KUI_INTERFACE_MOUSEOVER_DEBUG
			ctRootContainers[ i ]->Render( this, oCanvas, FVector2D::ZeroVector );
		}
	}

	if ( IsCursorVisible() )
	{
#if KUI_INTERFACE_MOUSEOVER_DEBUG
		bDebugMouseOver = arDebugMouseOver[ EKUIInterfaceRoot::R_Cursor ];
#endif // KUI_INTERFACE_MOUSEOVER_DEBUG
		ctRootContainers[ EKUIInterfaceRoot::R_Cursor ]->Render( this, oCanvas, v2CursorLocation );
	}

#if KUI_INTERFACE_MOUSEOVER_DEBUG
	bDebugMouseOver = false;

	if ( cmDebugMouseOver.IsValid() )
	{
		cmDebugMouseOverTestBox->SetLocationStruct( v2DebugMouseOverLocation + FVector2D( 1.f, 1.f ) );
		cmDebugMouseOverTestBox->SetSizeStruct( v2DebugMouseOverSize - FVector2D( 1.f, 1.f ) );
		cmDebugMouseOverTestBox->Render( this, oCanvas, FVector2D::ZeroVector, NULL );
	}

	if ( cmDebugMouseOver.Get() != cmDebugMouseOverLastTick.Get() )
	{
		KUILogUO( 
			"UI Mouse Over: %s: %s -> %s: %s (%f,%f) -> (%f,%f)", 
			*( cmDebugMouseOverLastTick.Get() ? ( cmDebugMouseOverLastTick.Get()->GetOuter() ? cmDebugMouseOverLastTick.Get()->GetOuter()->GetName() : "NULL" ) : "NULL" ),
			*( cmDebugMouseOverLastTick.Get() ? cmDebugMouseOverLastTick->GetName() : FString( "NULL" ) ), 
			*( cmDebugMouseOver.Get() ? ( cmDebugMouseOver.Get()->GetOuter() ? cmDebugMouseOver.Get()->GetOuter()->GetName() : "NULL" ) : "NULL" ),
			*( cmDebugMouseOver.Get() ? cmDebugMouseOver->GetName() : FString( "NULL" ) ), 
			ExpandV2( v2DebugMouseOverLocation ),
			ExpandV2( v2DebugMouseOverSize )
		);
	}

	cmDebugMouseOverLastTick = cmDebugMouseOver.Get();
#endif // KUI_INTERFACE_MOUSEOVER_DEBUG
}