Example #1
0
void FEdMode::Tick(FEditorViewportClient* ViewportClient,float DeltaTime)
{
    if( GetCurrentTool() )
    {
        GetCurrentTool()->Tick(ViewportClient,DeltaTime);
    }
}
Example #2
0
void FEdMode::SelectNone()
{
    if( GetCurrentTool() )
    {
        GetCurrentTool()->SelectNone();
    }
}
Example #3
0
bool FEdMode::EndTracking(FEditorViewportClient* InViewportClient, FViewport* InViewport)
{
    bool bResult = false;
    if( GetCurrentTool() )
    {
        bResult = GetCurrentTool()->EndModify();
    }
    return bResult;
}
Example #4
0
/**
 * Lets each mode/tool handle frustum selection in its own way.
 *
 * @param	InFrustum	The selection frustum to use, in worldspace coordinates.
 * @return	true if something was selected/deselected, false otherwise.
 */
bool FEdMode::FrustumSelect( const FConvexVolume& InFrustum, bool InSelect )
{
    bool bResult = false;
    if( GetCurrentTool() )
    {
        bResult = GetCurrentTool()->FrustumSelect( InFrustum, InSelect );
    }
    return bResult;
}
Example #5
0
bool FEdMode::UsesTransformWidget() const
{
    if( GetCurrentTool() )
    {
        return GetCurrentTool()->UseWidget();
    }

    return 1;
}
Example #6
0
/**
 * Lets each mode/tool handle box selection in its own way.
 *
 * @param	InBox	The selection box to use, in worldspace coordinates.
 * @return		true if something was selected/deselected, false otherwise.
 */
bool FEdMode::BoxSelect( FBox& InBox, bool InSelect )
{
    bool bResult = false;
    if( GetCurrentTool() )
    {
        bResult = GetCurrentTool()->BoxSelect( InBox, InSelect );
    }
    return bResult;
}
Example #7
0
bool FEdMode::CapturedMouseMove( FEditorViewportClient* InViewportClient, FViewport* InViewport, int32 InMouseX, int32 InMouseY )
{
    if( GetCurrentTool() )
    {
        return GetCurrentTool()->CapturedMouseMove( InViewportClient, InViewport, InMouseX, InMouseY );
    }

    return false;
}
Example #8
0
bool FEdMode::LostFocus(FEditorViewportClient* ViewportClient,FViewport* Viewport)
{
    if( GetCurrentTool() )
    {
        return GetCurrentTool()->LostFocus( ViewportClient, Viewport );
    }

    return false;
}
Example #9
0
bool FEdMode::MouseMove(FEditorViewportClient* ViewportClient,FViewport* Viewport,int32 x, int32 y)
{
    if( GetCurrentTool() )
    {
        return GetCurrentTool()->MouseMove( ViewportClient, Viewport, x, y );
    }

    return false;
}
Example #10
0
bool FEdMode::MouseLeave( FEditorViewportClient* ViewportClient,FViewport* Viewport )
{
    if( GetCurrentTool() )
    {
        return GetCurrentTool()->MouseLeave( ViewportClient, Viewport );
    }

    return false;
}
Example #11
0
bool FEdMode::InputAxis(FEditorViewportClient* InViewportClient, FViewport* Viewport, int32 ControllerId, FKey Key, float Delta, float DeltaTime)
{
    FModeTool* Tool = GetCurrentTool();
    if (Tool)
    {
        return Tool->InputAxis(InViewportClient, Viewport, ControllerId, Key, Delta, DeltaTime);
    }

    return false;
}
Example #12
0
bool FEdMode::InputKey(FEditorViewportClient* ViewportClient, FViewport* Viewport, FKey Key, EInputEvent Event)
{
    if( GetCurrentTool() && GetCurrentTool()->InputKey( ViewportClient, Viewport, Key, Event ) )
    {
        return true;
    }
    else
    {
        // Pass input up to selected actors if not in a tool mode
        TArray<AActor*> SelectedActors;
        Owner->GetSelectedActors()->GetSelectedObjects<AActor>(SelectedActors);

        for( TArray<AActor*>::TIterator it(SelectedActors); it; ++it )
        {
            // Tell the object we've had a key press
            (*it)->EditorKeyPressed(Key, Event);
        }
    }

    return 0;
}
Example #13
0
void RepRap::DeleteTool(Tool* tool)
{
	// Must have a valid tool...
	if (tool == nullptr)
	{
		return;
	}

	// Deselect it if necessary
	if (GetCurrentTool() == tool)
	{
		SelectTool(-1);
	}

	// Switch off any associated heater
	for (size_t i = 0; i < tool->HeaterCount(); i++)
	{
		reprap.GetHeat()->SwitchOff(tool->Heater(i));
	}

	// Purge any references to this tool
	for (Tool **t = &toolList; *t != nullptr; t = &((*t)->next))
	{
		if (*t == tool)
		{
			*t = tool->next;
			break;
		}
	}

	// Delete it
	Tool::Delete(tool);

	// Update the number of active heaters and extruder drives
	activeExtruders = activeToolHeaters = 0;
	for (Tool *t = toolList; t != nullptr; t = t->Next())
	{
		t->UpdateExtruderAndHeaterCount(activeExtruders, activeToolHeaters);
	}
	platform->UpdateConfiguredHeaters();
}
Example #14
0
void FEdMode::DrawHUD(FEditorViewportClient* ViewportClient,FViewport* Viewport,const FSceneView* View,FCanvas* Canvas)
{
    // Render the drag tool.
    ViewportClient->RenderDragTool( View, Canvas );

    // Let the current mode tool draw a HUD if it wants to
    FModeTool* tool = GetCurrentTool();
    if( tool )
    {
        tool->DrawHUD( ViewportClient, Viewport, View, Canvas );
    }

    if (ViewportClient->IsPerspective() && GetDefault<ULevelEditorViewportSettings>()->bHighlightWithBrackets)
    {
        DrawBrackets( ViewportClient, Viewport, View, Canvas );
    }

    // If this viewport doesn't show mode widgets or the mode itself doesn't want them, leave.
    if( !(ViewportClient->EngineShowFlags.ModeWidgets) || !ShowModeWidgets() )
    {
        return;
    }

    // Clear Hit proxies
    const bool bIsHitTesting = Canvas->IsHitTesting();
    if ( !bIsHitTesting )
    {
        Canvas->SetHitProxy(NULL);
    }

    // Draw vertices for selected BSP brushes and static meshes if the large vertices show flag is set.
    if ( !ViewportClient->bDrawVertices )
    {
        return;
    }

    const bool bLargeVertices		= View->Family->EngineShowFlags.LargeVertices;
    const bool bShowBrushes			= View->Family->EngineShowFlags.Brushes;
    const bool bShowBSP				= View->Family->EngineShowFlags.BSP;
    const bool bShowBuilderBrush	= View->Family->EngineShowFlags.BuilderBrush != 0;

    UTexture2D* VertexTexture = GetVertexTexture();
    const float TextureSizeX		= VertexTexture->GetSizeX() * ( bLargeVertices ? 1.0f : 0.5f );
    const float TextureSizeY		= VertexTexture->GetSizeY() * ( bLargeVertices ? 1.0f : 0.5f );

    // Temporaries.
    TArray<FVector> Vertices;

    for ( FSelectionIterator It( *Owner->GetSelectedActors() ) ; It ; ++It )
    {
        AActor* SelectedActor = static_cast<AActor*>( *It );
        checkSlow( SelectedActor->IsA(AActor::StaticClass()) );

        if( bLargeVertices )
        {
            FCanvasItemTestbed::bTestState = !FCanvasItemTestbed::bTestState;

            // Static mesh vertices
            AStaticMeshActor* Actor = Cast<AStaticMeshActor>( SelectedActor );
            if( Actor && Actor->GetStaticMeshComponent() && Actor->GetStaticMeshComponent()->StaticMesh
                    && Actor->GetStaticMeshComponent()->StaticMesh->RenderData )
            {
                FTransform ActorToWorld = Actor->ActorToWorld();
                Vertices.Empty();
                const FPositionVertexBuffer& VertexBuffer = Actor->GetStaticMeshComponent()->StaticMesh->RenderData->LODResources[0].PositionVertexBuffer;
                for( uint32 i = 0 ; i < VertexBuffer.GetNumVertices() ; i++ )
                {
                    Vertices.AddUnique( ActorToWorld.TransformPosition( VertexBuffer.VertexPosition(i) ) );
                }

                FCanvasTileItem TileItem( FVector2D( 0.0f, 0.0f ), FVector2D( 0.0f, 0.0f ), FLinearColor::White );
                TileItem.BlendMode = SE_BLEND_Translucent;
                for( int32 VertexIndex = 0 ; VertexIndex < Vertices.Num() ; ++VertexIndex )
                {
                    const FVector& Vertex = Vertices[VertexIndex];
                    FVector2D PixelLocation;
                    if(View->ScreenToPixel(View->WorldToScreen(Vertex),PixelLocation))
                    {
                        const bool bOutside =
                            PixelLocation.X < 0.0f || PixelLocation.X > View->ViewRect.Width() ||
                            PixelLocation.Y < 0.0f || PixelLocation.Y > View->ViewRect.Height();
                        if( !bOutside )
                        {
                            const float X = PixelLocation.X - (TextureSizeX/2);
                            const float Y = PixelLocation.Y - (TextureSizeY/2);
                            if( bIsHitTesting )
                            {
                                Canvas->SetHitProxy( new HStaticMeshVert(Actor,Vertex) );
                            }
                            TileItem.Texture = VertexTexture->Resource;

                            TileItem.Size = FVector2D( TextureSizeX, TextureSizeY );
                            Canvas->DrawItem( TileItem, FVector2D( X, Y ) );
                            if( bIsHitTesting )
                            {
                                Canvas->SetHitProxy( NULL );
                            }
                        }
                    }
                }
            }
        }
    }

    if(UsesPropertyWidgets())
    {
        AActor* SelectedActor = GetFirstSelectedActorInstance();
        if (SelectedActor != NULL)
        {
            FEditorScriptExecutionGuard ScriptGuard;

            const int32 HalfX = 0.5f * Viewport->GetSizeXY().X;
            const int32 HalfY = 0.5f * Viewport->GetSizeXY().Y;

            UClass* Class = SelectedActor->GetClass();
            TArray<FPropertyWidgetInfo> WidgetInfos;
            GetPropertyWidgetInfos(Class, SelectedActor, WidgetInfos);
            for(int32 i=0; i<WidgetInfos.Num(); i++)
            {
                FString WidgetName = WidgetInfos[i].PropertyName;
                FName WidgetValidator = WidgetInfos[i].PropertyValidationName;
                int32 WidgetIndex = WidgetInfos[i].PropertyIndex;
                bool bIsTransform = WidgetInfos[i].bIsTransform;

                FVector LocalPos = FVector::ZeroVector;
                if(bIsTransform)
                {
                    FTransform LocalTM = GetPropertyValueByName<FTransform>(SelectedActor, WidgetName, WidgetIndex);
                    LocalPos = LocalTM.GetLocation();
                }
                else
                {
                    LocalPos = GetPropertyValueByName<FVector>(SelectedActor, WidgetName, WidgetIndex);
                }

                FTransform ActorToWorld = SelectedActor->ActorToWorld();
                FVector WorldPos = ActorToWorld.TransformPosition(LocalPos);

                UFunction* ValidateFunc = NULL;
                FString FinalString;
                if(WidgetValidator != NAME_None &&
                        (ValidateFunc = SelectedActor->FindFunction(WidgetValidator)) != NULL)
                {
                    SelectedActor->ProcessEvent(ValidateFunc, &FinalString);
                }

                const FPlane Proj = View->Project( WorldPos );

                //do some string fixing
                const uint32 VectorIndex = WidgetInfos[i].PropertyIndex;
                const FString WidgetDisplayName = WidgetInfos[i].DisplayName + ((VectorIndex != INDEX_NONE) ? FString::Printf(TEXT("[%d]"), VectorIndex) : TEXT(""));
                FinalString = FinalString.IsEmpty() ? WidgetDisplayName : FinalString;

                if(Proj.W > 0.f)
                {
                    const int32 XPos = HalfX + ( HalfX * Proj.X );
                    const int32 YPos = HalfY + ( HalfY * (Proj.Y * -1.f) );
                    FCanvasTextItem TextItem( FVector2D( XPos + 5, YPos), FText::FromString( FinalString ), GEngine->GetSmallFont(), FLinearColor::White );
                    Canvas->DrawItem( TextItem );
                }
            }
        }
    }
}
Example #15
0
void FEdMode::Render(const FSceneView* View,FViewport* Viewport,FPrimitiveDrawInterface* PDI)
{
    // Let the current mode tool render if it wants to
    FModeTool* tool = GetCurrentTool();
    if( tool )
    {
        tool->Render( View, Viewport, PDI );
    }

    if(UsesPropertyWidgets())
    {
        bool bHitTesting = PDI->IsHitTesting();
        AActor* SelectedActor = GetFirstSelectedActorInstance();
        if (SelectedActor != NULL)
        {
            UClass* Class = SelectedActor->GetClass();
            TArray<FPropertyWidgetInfo> WidgetInfos;
            GetPropertyWidgetInfos(Class, SelectedActor, WidgetInfos);
            FEditorScriptExecutionGuard ScriptGuard;
            for(int32 i=0; i<WidgetInfos.Num(); i++)
            {
                FString WidgetName = WidgetInfos[i].PropertyName;
                FName WidgetValidator = WidgetInfos[i].PropertyValidationName;
                int32 WidgetIndex = WidgetInfos[i].PropertyIndex;
                bool bIsTransform = WidgetInfos[i].bIsTransform;

                bool bSelected = (WidgetName == EditedPropertyName) && (WidgetIndex == EditedPropertyIndex);
                FColor WidgetColor = bSelected ? FColor::White : FColor(128, 128, 255);

                FVector LocalPos = FVector::ZeroVector;
                if(bIsTransform)
                {
                    FTransform LocalTM = GetPropertyValueByName<FTransform>(SelectedActor, WidgetName, WidgetIndex);
                    LocalPos = LocalTM.GetLocation();
                }
                else
                {
                    LocalPos = GetPropertyValueByName<FVector>(SelectedActor, WidgetName, WidgetIndex);
                }

                FTransform ActorToWorld = SelectedActor->ActorToWorld();
                FVector WorldPos = ActorToWorld.TransformPosition(LocalPos);

                UFunction* ValidateFunc= NULL;
                if(WidgetValidator != NAME_None &&
                        (ValidateFunc = SelectedActor->FindFunction(WidgetValidator)) != NULL)
                {
                    FString ReturnText;
                    SelectedActor->ProcessEvent(ValidateFunc, &ReturnText);

                    //if we have a negative result, the widget color is red.
                    WidgetColor = ReturnText.IsEmpty() ? WidgetColor : FColor::Red;
                }

                FTranslationMatrix WidgetTM(WorldPos);

                const float WidgetSize = 0.035f;
                const float ZoomFactor = FMath::Min<float>(View->ViewMatrices.ProjMatrix.M[0][0], View->ViewMatrices.ProjMatrix.M[1][1]);
                const float WidgetRadius = View->Project(WorldPos).W * (WidgetSize / ZoomFactor);

                if(bHitTesting) PDI->SetHitProxy( new HPropertyWidgetProxy(WidgetName, WidgetIndex, bIsTransform) );
                DrawWireDiamond(PDI, WidgetTM, WidgetRadius, WidgetColor, SDPG_Foreground );
                if(bHitTesting) PDI->SetHitProxy( NULL );
            }
        }
    }
}
Example #16
0
bool FEdMode::InputDelta(FEditorViewportClient* InViewportClient, FViewport* InViewport, FVector& InDrag, FRotator& InRot, FVector& InScale)
{
    if(UsesPropertyWidgets())
    {
        AActor* SelectedActor = GetFirstSelectedActorInstance();
        if(SelectedActor != NULL && InViewportClient->GetCurrentWidgetAxis() != EAxisList::None)
        {
            GEditor->NoteActorMovement();

            if (EditedPropertyName != TEXT(""))
            {
                FTransform LocalTM = FTransform::Identity;

                if(bEditedPropertyIsTransform)
                {
                    LocalTM = GetPropertyValueByName<FTransform>(SelectedActor, EditedPropertyName, EditedPropertyIndex);
                }
                else
                {
                    FVector LocalPos = GetPropertyValueByName<FVector>(SelectedActor, EditedPropertyName, EditedPropertyIndex);
                    LocalTM = FTransform(LocalPos);
                }

                // Get actor transform (actor to world)
                FTransform ActorTM = SelectedActor->ActorToWorld();
                // Calculate world transform
                FTransform WorldTM = LocalTM * ActorTM;
                // Calc delta specified by drag
                //FTransform DeltaTM(InRot.Quaternion(), InDrag);
                // Apply delta in world space
                WorldTM.SetTranslation(WorldTM.GetTranslation() + InDrag);
                WorldTM.SetRotation(InRot.Quaternion() * WorldTM.GetRotation());
                // Convert new world transform back into local space
                LocalTM = WorldTM.GetRelativeTransform(ActorTM);
                // Apply delta scale
                LocalTM.SetScale3D(LocalTM.GetScale3D() + InScale);

                SelectedActor->PreEditChange(NULL);

                if(bEditedPropertyIsTransform)
                {
                    SetPropertyValueByName<FTransform>(SelectedActor, EditedPropertyName, EditedPropertyIndex, LocalTM);
                }
                else
                {
                    SetPropertyValueByName<FVector>(SelectedActor, EditedPropertyName, EditedPropertyIndex, LocalTM.GetLocation());
                }

                SelectedActor->PostEditChange();

                return true;
            }
        }
    }

    if( GetCurrentTool() )
    {
        return GetCurrentTool()->InputDelta(InViewportClient,InViewport,InDrag,InRot,InScale);
    }

    return 0;
}