void UKUIInterfaceElement::RemoveAlignedToThis( UKUIInterfaceElement* oAlignChild ) { // Can't remove a null pointer if ( oAlignChild == NULL ) { KUIErrorUO( "Trying to remove null align child" ); return; } // Check if we're actually in the children array. int32 iIndex = INDEX_NONE; for ( int32 i = 0; i < arAlignedToThis.Num(); ++i ) { if ( arAlignedToThis[ i ] != oAlignChild ) continue; iIndex = i; break; } // It wasn't if ( iIndex == INDEX_NONE ) { KUIErrorDebugUO( "Trying to remove an align child not aligned to this element" ); return; } // Swap out the highest index with this child, to maintain contiguity. int32 iHighestIndex = INDEX_NONE; for ( int32 i = arAlignedToThis.Num() - 1; i > iIndex; --i ) { if ( !arAlignedToThis[ i ].IsValid() ) continue; iHighestIndex = i; break; } // We found a highest child, so swap. Otherwise, we were the highest child and no sort is necessary. if ( iHighestIndex != INDEX_NONE ) arAlignedToThis[ iIndex ] = arAlignedToThis[ iHighestIndex ]; // Reduce the size of the array by 1. arAlignedToThis.SetNum( iIndex ); }
void UKUISubContainerRenderCache::UpdateRenderCache( UKUIInterfaceElement* oElement ) { if ( oElement == NULL ) { KUIErrorUO( "Null element" ); return; } KUILogUO( "Updating Render Cache" ); UKUISubContainer* const ctSub = Cast<UKUISubContainer>( oElement ); const FVector2D v2ElemSize = ctSub->GetTotalSize(); if ( v2ElemSize.X < 1.f || v2ElemSize.Y < 1.f ) { KUIErrorUO( "Element is zero size" ); return; } bool bRebuildTexture = false; if ( GetTexture() == NULL ) bRebuildTexture = true; else if ( v2ElemSize.X != GetTexture()->GetSurfaceWidth() || v2ElemSize.Y != GetTexture()->GetSurfaceHeight() ) bRebuildTexture = true; if ( bRebuildTexture ) CreateRenderCache( v2ElemSize ); if ( GetTexture() == NULL ) { KUIErrorUO( "Texture is null" ); return; } if ( !GetTexture()->IsA<UTextureRenderTarget2D>() ) { KUIErrorUO( "Texture is not a render target" ); return; } UTextureRenderTarget2D* const tRenderTarget = Cast<UTextureRenderTarget2D>( GetTexture() ); tRenderTarget->UpdateResource(); tRenderTarget->UpdateResourceImmediate(); UCanvas* uoCanvas = Cast<UCanvas>( StaticFindObjectFast( UCanvas::StaticClass(), GetTransientPackage(), FName( TEXT( "Sub Container Render Cache Canvas" ) ) ) ); if ( uoCanvas == NULL ) { uoCanvas = NewObject<UCanvas>( GetTransientPackage(), FName( TEXT( "Sub Container Render Cache Canvas" ) ) ); uoCanvas->AddToRoot(); } uoCanvas->Init( floor( v2ElemSize.X ), floor( v2ElemSize.Y ), NULL ); uoCanvas->Update(); ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER( CanvasRenderTargetMakeCurrentCommand, FTextureRenderTarget2DResource*, TextureRenderTarget, static_cast<FTextureRenderTarget2DResource*>( tRenderTarget->GameThread_GetRenderTargetResource() ), { SetRenderTarget( RHICmdList, TextureRenderTarget->GetRenderTargetTexture(), FTexture2DRHIRef() ); RHICmdList.SetViewport( 0, 0, 0.0f, TextureRenderTarget->GetSizeXY().X, TextureRenderTarget->GetSizeXY().Y, 1.0f ); }
void UKUIScrollContainer::UpdateScrollbarMetrics() { if ( !ctScrollArea.IsValid() ) { KUIErrorUO( "Null scroll area" ); return; } FVector2D v2ScrollContainerSize = GetSize(); const FVector2D v2ScrollTotalSize = ctScrollArea->GetTotalSize(); if ( v2ScrollTotalSize.X > v2ScrollContainerSize.X ) v2ScrollContainerSize.X -= v2ScrollBarSize.X; if ( v2ScrollTotalSize.Y > v2ScrollContainerSize.Y ) v2ScrollContainerSize.Y -= v2ScrollBarSize.Y; // Check again to see if the vertical scrollbar means we need to scroll. if ( v2ScrollTotalSize.X > v2ScrollContainerSize.X ) v2ScrollContainerSize.X -= v2ScrollBarSize.X; ctScrollArea->SetSizeStruct( v2ScrollContainerSize ); const FVector2D v2Size = GetSize(); if ( v2ScrollContainerSize.X >= v2Size.X && v2ScrollContainerSize.Y >= v2Size.Y ) { if ( cmHorizontalScrollBar.IsValid() ) cmHorizontalScrollBar->SetVisible( false ); if ( cmVerticalScrollBar.IsValid() ) cmVerticalScrollBar->SetVisible( false ); if ( oCornerComponent.IsValid() ) oCornerComponent->SetVisible( false ); } else if ( v2ScrollContainerSize.Y >= v2Size.Y ) { if ( cmHorizontalScrollBar.IsValid() ) { cmHorizontalScrollBar->SetVisible( true ); cmHorizontalScrollBar->SetSize( v2Size.X, v2ScrollBarSize.Y ); } if ( cmVerticalScrollBar.IsValid() ) cmVerticalScrollBar->SetVisible( false ); if ( oCornerComponent.IsValid() ) oCornerComponent->SetVisible( false ); } else if ( v2ScrollContainerSize.X >= v2Size.X ) { if ( cmHorizontalScrollBar.IsValid() ) cmHorizontalScrollBar->SetVisible( false ); if ( cmVerticalScrollBar.IsValid() ) { cmVerticalScrollBar->SetVisible( true ); cmVerticalScrollBar->SetSize( v2ScrollBarSize.X, v2Size.Y ); } if ( oCornerComponent.IsValid() ) oCornerComponent->SetVisible( false ); } else { if ( cmHorizontalScrollBar.IsValid() ) { cmHorizontalScrollBar->SetVisible( true ); cmHorizontalScrollBar->SetSize( v2Size.X - v2ScrollBarSize.X, v2ScrollBarSize.Y ); } if ( cmVerticalScrollBar.IsValid() ) { cmVerticalScrollBar->SetVisible( true ); cmVerticalScrollBar->SetSize( v2ScrollBarSize.X, v2Size.Y - v2ScrollBarSize.Y ); } if ( oCornerComponent.IsValid() ) { oCornerComponent->SetVisible( true ); oCornerComponent->SetSize( v2Size.X, v2Size.Y ); } } }