diff --git a/Source/DasherVR/Private/Dasher3DWidget.cpp b/Source/DasherVR/Private/Dasher3DWidget.cpp index f0c6dbb59746d0b4ce900d75446a5fdd4cffe008..765f5c4011d20a73ade86541754185b58f4b3427 100644 --- a/Source/DasherVR/Private/Dasher3DWidget.cpp +++ b/Source/DasherVR/Private/Dasher3DWidget.cpp @@ -96,13 +96,13 @@ void ADasher3DWidget::DrawCube(float posX, float posY, float sizeX, float sizeY, if (sizeX == 0 || sizeY == 0) return; - const float currentNodeDepth = ExtrusionLevelToHeight(nodeDepth.extrusionLevel) + nodeDepth.groupRecursionDepth*0.001; - const float parentNodeDepth = ExtrusionLevelToHeight(parentDepth.extrusionLevel) + parentDepth.groupRecursionDepth*0.001; + const float currentNodeDepth = ExtrusionLevelToHeight(nodeDepth.extrusionLevel) + nodeDepth.groupRecursionDepth*GroupDepthScale; + const float parentNodeDepth = ExtrusionLevelToHeight(parentDepth.extrusionLevel) + parentDepth.groupRecursionDepth*GroupDepthScale; const FVector Scale = FVector(FVector2D(sizeX, sizeY) / DrawingSize, FMath::Max(currentNodeDepth - parentNodeDepth, 0.001f)); // Min Depth 1mm const FVector2D Translation = FVector2D(posX, posY) / DrawingSize - FVector2D(0.5f, 0.5f); - const FLinearColor RectColor = FLinearColor(color.Red / 255.0, color.Green / 255.0, color.Blue / 255.0, color.Alpha / 255.0); + const FLinearColor RectColor = FLinearColor(color.Red / 255.0 * Brightness, color.Green / 255.0 * Brightness, color.Blue / 255.0 * Brightness, color.Alpha / 255.0 * Brightness); BackBuffer->first.Add(FTransform(FQuat::Identity, FVector(Translation, parentNodeDepth) * WorldToMeters, Scale)); BackBuffer->second.Add(RectColor.R); @@ -158,7 +158,7 @@ void ADasher3DWidget::Draw3DLabel(Label* label, Dasher::screenint x, Dasher::scr const FVector CharTranslation = FVector( ((x + x_offset) / DrawingSize.X + CharScale.X * 0.5f) * WorldToMeters + CharacterOffset, ((y + y_offset + ((orientation != Dasher::Options::BottomToTop) ? CharacterVerticalOffset : 0.1f)) / DrawingSize.Y) * WorldToMeters, //0.1px offset for not running into Z-fighting - (FMath::Max(ExtrusionLevelToHeight(extrusionLevel), 0.001f) + groupRecursionDepth*0.001) * WorldToMeters + z_offset + (FMath::Max(ExtrusionLevelToHeight(extrusionLevel), 0.001f) + groupRecursionDepth*GroupDepthScale) * WorldToMeters + z_offset ) - FVector(0.5f, 0.5f, 0) * WorldToMeters; // Move to upper left corner of parent @@ -321,6 +321,68 @@ void ADasher3DWidget::SimulateClick(FKey Key, bool pressed) } } +void ADasher3DWidget::SetBoolParamter(FString ParameterName, bool Value) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + DasherMainInterface->SetBoolParameter(param->first, Value); + return; + } +} + +void ADasher3DWidget::SetLongParamter(FString ParameterName, int64 Value) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + DasherMainInterface->SetLongParameter(param->first, Value); + return; + } +} + +void ADasher3DWidget::SetStringParamter(FString ParameterName, FString Value) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + DasherMainInterface->SetStringParameter(param->first, TCHAR_TO_UTF8(*Value)); + return; + } +} + +bool ADasher3DWidget::GetBoolParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + { + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return DasherMainInterface->GetBoolParameter(param->first); + } + } + return false; +} + +int64 ADasher3DWidget::GetLongParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return DasherMainInterface->GetLongParameter(param->first); + } + return -1; +} + +FString ADasher3DWidget::GetStringParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return UTF8_TO_TCHAR(DasherMainInterface->GetStringParameter(param->first).c_str()); + } + return ""; +} + void ADasher3DWidget::InitializeTextureArray() { TextureArray = NewObject<UTexture2DArray>(); diff --git a/Source/DasherVR/Private/SDasherWidget.cpp b/Source/DasherVR/Private/SDasherWidget.cpp index fd326d18042f7b1b64d825173899cc4e0ac89e74..8316a7cfb29e5f903b546b57f7bbb202ba9a81ba 100644 --- a/Source/DasherVR/Private/SDasherWidget.cpp +++ b/Source/DasherVR/Private/SDasherWidget.cpp @@ -310,6 +310,38 @@ void SDasherWidget::SetParameter(FString ParameterName, FString Value) } } +bool SDasherWidget::GetBoolParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + { + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return DasherMainInterface->GetBoolParameter(param->first); + } + } + return false; +} + +int64 SDasherWidget::GetLongParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return DasherMainInterface->GetLongParameter(param->first); + } + return -1; +} + +FString SDasherWidget::GetStringParamter(FString ParameterName) +{ + for (auto param = Dasher::Settings::parameter_defaults.begin(); param != Dasher::Settings::parameter_defaults.end(); ++param) + if (param->second.name == TCHAR_TO_UTF8(*ParameterName)) + { + return UTF8_TO_TCHAR(DasherMainInterface->GetStringParameter(param->first).c_str()); + } + return ""; +} + //paints our stuff, then lets compoundwidget (super::) draw its stuff //This draws from bottom to top rectangles->lines->labels, this is enough for our use, but for more complex scenarios a proper layering system might have to be implemented int32 SDasherWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const @@ -416,7 +448,7 @@ void SDasherWidget::DrawRectangle(Dasher::screenint x1, Dasher::screenint y1, Da if(color != Dasher::ColorPalette::noColor && !color.isFullyTransparent()) { - BackBuffer->Add(MakeUnique<FFilledRect>(FVector2D(x1 + iThickness, y1 + iThickness), FVector2D(x2 - iThickness, y2 - iThickness), FLinearColor(color.Red / 255.0f, color.Green / 255.0f, color.Blue / 255.0f, color.Alpha / 255.0f))); + BackBuffer->Add(MakeUnique<FFilledRect>(FVector2D(x1 + iThickness, y1 + iThickness), FVector2D(x2 - iThickness, y2 - iThickness), FLinearColor(color.Red / 255.0f * brightness, color.Green / 255.0f * brightness, color.Blue / 255.0f * brightness, color.Alpha / 255.0f))); } if (iThickness && outlineColor != Dasher::ColorPalette::noColor && !outlineColor.isFullyTransparent()) diff --git a/Source/DasherVR/Private/UDasherWidget.cpp b/Source/DasherVR/Private/UDasherWidget.cpp index 9b1207756cc7c43c52238b958f93f08439baf56b..0160bf76975cba88b59a61c1e814be93cfe39409 100644 --- a/Source/DasherVR/Private/UDasherWidget.cpp +++ b/Source/DasherVR/Private/UDasherWidget.cpp @@ -85,6 +85,24 @@ void UDasherWidget::SetStringParamter(FString ParameterName, FString Value) DasherScreen->SetParameter(ParameterName, Value); } +bool UDasherWidget::GetBoolParamter(FString ParameterName) +{ + if(!DasherScreen) return false; + return DasherScreen->GetBoolParamter(ParameterName); +} + +int64 UDasherWidget::GetLongParamter(FString ParameterName) +{ + if(!DasherScreen) return -1; + return DasherScreen->GetLongParamter(ParameterName); +} + +FString UDasherWidget::GetStringParamter(FString ParameterName) +{ + if(!DasherScreen) return ""; + return DasherScreen->GetStringParamter(ParameterName); +} + void UDasherWidget::InputButton(bool Pressed) { if(!DasherScreen) return; diff --git a/Source/DasherVR/Public/Dasher3DWidget.h b/Source/DasherVR/Public/Dasher3DWidget.h index f68c8b9e7b374f6041f5a84a453668c061fda6b1..2c0b75771c6cb11b44ff823e0a1e17ecfc727072 100644 --- a/Source/DasherVR/Public/Dasher3DWidget.h +++ b/Source/DasherVR/Public/Dasher3DWidget.h @@ -67,13 +67,23 @@ public: UPROPERTY(VisibleAnywhere, Category = "Components") UInstancedStaticMeshComponent* CubeInstances = nullptr; UPROPERTY(VisibleAnywhere, Category = "Components") UInstancedStaticMeshComponent* LetterInstances = nullptr; UPROPERTY(EditAnywhere) UFont* DisplayFont; - UPROPERTY(EditAnywhere) float DepthScale = 0.1; + UPROPERTY(EditAnywhere, BlueprintReadWrite) float DepthScale = 0.1; + UPROPERTY(EditAnywhere, BlueprintReadWrite) float GroupDepthScale = 0.001; + UPROPERTY(EditAnywhere, BlueprintReadWrite) float Brightness = 1; UPROPERTY(EditAnywhere, BlueprintReadOnly) FVector Origin = {0,0,0}; UPROPERTY(EditAnywhere, BlueprintReadOnly) FVector MousePos = {0,0,0}; UPROPERTY(EditAnywhere, BlueprintReadWrite) FString settingsFile = "Settings3D.xml"; UFUNCTION(BlueprintCallable) void SetMouseLocation(FVector WorldLocation); UFUNCTION(BlueprintCallable) void SimulateClick(FKey Key, bool pressed); + + UFUNCTION(BlueprintCallable) void SetBoolParamter(FString ParameterName, bool Value); + UFUNCTION(BlueprintCallable) void SetLongParamter(FString ParameterName, int64 Value); + UFUNCTION(BlueprintCallable) void SetStringParamter(FString ParameterName, FString Value); + UFUNCTION(BlueprintPure) bool GetBoolParamter(FString ParameterName); + UFUNCTION(BlueprintPure) int64 GetLongParamter(FString ParameterName); + UFUNCTION(BlueprintPure) FString GetStringParamter(FString ParameterName); + virtual void PostInitializeComponents() override; public: @@ -97,7 +107,7 @@ private: private: FVector2D CursorPosition; float WorldToMeters; // normally 100 - FVector2D DrawingSize = {1000,1000}; // Rendering Resolution + FVector2D DrawingSize = {1920,1080}; // Rendering Resolution TSharedPtr<Dasher::DasherInterface> DasherMainInterface; UPROPERTY() UMaterialInstanceDynamic* CubeMaterialInstanceDynamic; UPROPERTY() UMaterialInstanceDynamic* LetterMaterialInstanceDynamic; diff --git a/Source/DasherVR/Public/SDasherWidget.h b/Source/DasherVR/Public/SDasherWidget.h index 9a17c05ac9c871ab42de8cbae82f1b0ef7149b14..09540b0cd3a8b70ebab5610982b64f7dafcfaea0 100644 --- a/Source/DasherVR/Public/SDasherWidget.h +++ b/Source/DasherVR/Public/SDasherWidget.h @@ -94,6 +94,9 @@ public: void SetParameter(FString ParameterName, bool Value); void SetParameter(FString ParameterName, int64 Value); void SetParameter(FString ParameterName, FString Value); + bool GetBoolParamter(FString ParameterName); + int64 GetLongParamter(FString ParameterName); + FString GetStringParamter(FString ParameterName); virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; diff --git a/Source/DasherVR/Public/UDasherWidget.h b/Source/DasherVR/Public/UDasherWidget.h index be1822f098e1bc372a1cd07204e19c9c7f1da2bf..f7f06a664b7b154ba2efe5b27fae3edf134f83b8 100644 --- a/Source/DasherVR/Public/UDasherWidget.h +++ b/Source/DasherVR/Public/UDasherWidget.h @@ -38,6 +38,10 @@ public: UFUNCTION(BlueprintCallable) void SetLongParamter(FString ParameterName, int64 Value); UFUNCTION(BlueprintCallable) void SetStringParamter(FString ParameterName, FString Value); + UFUNCTION(BlueprintPure) bool GetBoolParamter(FString ParameterName); + UFUNCTION(BlueprintPure) int64 GetLongParamter(FString ParameterName); + UFUNCTION(BlueprintPure) FString GetStringParamter(FString ParameterName); + UFUNCTION(BlueprintCallable) void InputButton(bool Pressed); UFUNCTION(BlueprintCallable) void InputVector(FVector2D InputVector); @@ -59,8 +63,10 @@ public: //Only for testing UFUNCTION(BlueprintCallable) void SetTransparency(float transparency){DasherScreen->transparency = 255*transparency;} UFUNCTION(BlueprintCallable) void SetBrightness(float brightness){DasherScreen->brightness = brightness;} + UFUNCTION(BlueprintCallable, BlueprintPure) float GetBrightness(){return DasherScreen->brightness;} public: + // UWidget interface virtual void SynchronizeProperties() override; // End of UWidget interface