From 2d911b4c68df221053a67ad1aeb65ac2f30be8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Thu, 2 Nov 2023 08:25:45 +0100 Subject: [PATCH] editor: transform component elements resetting buttons --- Editor/GeneralWindow.cpp | 24 +++++++++++++++++ Editor/TransformWindow.cpp | 54 +++++++++++++++++++++++++++++++++++--- Editor/TransformWindow.h | 4 +++ 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/Editor/GeneralWindow.cpp b/Editor/GeneralWindow.cpp index 98e137451..8b3a1e23b 100644 --- a/Editor/GeneralWindow.cpp +++ b/Editor/GeneralWindow.cpp @@ -552,6 +552,30 @@ void GeneralWindow::Create(EditorComponent* _editor) } } + editor->componentsWnd.transformWnd.resetTranslationButton.SetColor(wi::Color::Error(), wi::gui::WIDGETSTATE::FOCUS); + for (auto& sprite : editor->componentsWnd.transformWnd.resetTranslationButton.sprites) + { + sprite.params.enableCornerRounding(); + sprite.params.corners_rounding[1].radius = 10; + sprite.params.corners_rounding[3].radius = 10; + } + + editor->componentsWnd.transformWnd.resetScaleButton.SetColor(wi::Color::Error(), wi::gui::WIDGETSTATE::FOCUS); + for (auto& sprite : editor->componentsWnd.transformWnd.resetScaleButton.sprites) + { + sprite.params.enableCornerRounding(); + sprite.params.corners_rounding[1].radius = 10; + sprite.params.corners_rounding[3].radius = 10; + } + + editor->componentsWnd.transformWnd.resetRotationButton.SetColor(wi::Color::Error(), wi::gui::WIDGETSTATE::FOCUS); + for (auto& sprite : editor->componentsWnd.transformWnd.resetRotationButton.sprites) + { + sprite.params.enableCornerRounding(); + sprite.params.corners_rounding[1].radius = 10; + sprite.params.corners_rounding[3].radius = 10; + } + if ((Theme)args.userdata == Theme::Bright) { editor->inactiveEntityColor = theme_color_focus; diff --git a/Editor/TransformWindow.cpp b/Editor/TransformWindow.cpp index 9e20850cb..f982dfafd 100644 --- a/Editor/TransformWindow.cpp +++ b/Editor/TransformWindow.cpp @@ -313,6 +313,48 @@ void TransformWindow::Create(EditorComponent* _editor) }); AddWidget(&snapTranslateInput); + resetTranslationButton.Create("ResetTranslation"); + resetTranslationButton.SetText("X"); + resetTranslationButton.SetTooltip("Reset translation"); + resetTranslationButton.SetSize(XMFLOAT2(hei, hei)); + resetTranslationButton.OnClick([=](wi::gui::EventArgs args) { + TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity); + if (transform != nullptr) + { + transform->translation_local = XMFLOAT3(0, 0, 0); + transform->SetDirty(); + } + }); + AddWidget(&resetTranslationButton); + + resetScaleButton.Create("ResetScale"); + resetScaleButton.SetText("X"); + resetScaleButton.SetTooltip("Reset scale"); + resetScaleButton.SetSize(XMFLOAT2(hei, hei)); + resetScaleButton.OnClick([=](wi::gui::EventArgs args) { + TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity); + if (transform != nullptr) + { + transform->scale_local = XMFLOAT3(1, 1, 1); + transform->SetDirty(); + } + }); + AddWidget(&resetScaleButton); + + resetRotationButton.Create("ResetRotation"); + resetRotationButton.SetText("X"); + resetRotationButton.SetTooltip("Reset rotation"); + resetRotationButton.SetSize(XMFLOAT2(hei, hei)); + resetRotationButton.OnClick([=](wi::gui::EventArgs args) { + TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity); + if (transform != nullptr) + { + transform->rotation_local = XMFLOAT4(0, 0, 0, 1); + transform->SetDirty(); + } + }); + AddWidget(&resetRotationButton); + SetMinimized(true); SetVisible(false); @@ -395,7 +437,7 @@ void TransformWindow::ResizeLayout() add_fullwidth(clearButton); - float safe_width = width - 100; + float safe_width = width - 100 - 20 - padding; txInput.SetSize(XMFLOAT2(safe_width / 3.0f - padding, txInput.GetSize().y)); tyInput.SetSize(XMFLOAT2(safe_width / 3.0f - padding, txInput.GetSize().y)); tzInput.SetSize(XMFLOAT2(safe_width / 3.0f - padding, txInput.GetSize().y)); @@ -408,18 +450,22 @@ void TransformWindow::ResizeLayout() pitchInput.SetSize(XMFLOAT2(safe_width / 3.0f - padding, txInput.GetSize().y)); yawInput.SetSize(XMFLOAT2(safe_width / 3.0f - padding, txInput.GetSize().y)); + safe_width = width - 100; rxInput.SetSize(XMFLOAT2(safe_width / 4.0f - padding, txInput.GetSize().y)); ryInput.SetSize(XMFLOAT2(safe_width / 4.0f - padding, txInput.GetSize().y)); rzInput.SetSize(XMFLOAT2(safe_width / 4.0f - padding, txInput.GetSize().y)); rwInput.SetSize(XMFLOAT2(safe_width / 4.0f - padding, txInput.GetSize().y)); - add_right(tzInput); + add_right(resetTranslationButton); + tzInput.SetPos(XMFLOAT2(resetTranslationButton.GetPos().x - tzInput.GetSize().x - padding, resetTranslationButton.GetPos().y)); tyInput.SetPos(XMFLOAT2(tzInput.GetPos().x - tyInput.GetSize().x - padding, tzInput.GetPos().y)); txInput.SetPos(XMFLOAT2(tyInput.GetPos().x - txInput.GetSize().x - padding, tyInput.GetPos().y)); - add_right(szInput); + add_right(resetScaleButton); + szInput.SetPos(XMFLOAT2(resetScaleButton.GetPos().x - szInput.GetSize().x - padding, resetScaleButton.GetPos().y)); syInput.SetPos(XMFLOAT2(szInput.GetPos().x - syInput.GetSize().x - padding, szInput.GetPos().y)); sxInput.SetPos(XMFLOAT2(syInput.GetPos().x - sxInput.GetSize().x - padding, syInput.GetPos().y)); - add_right(yawInput); + add_right(resetRotationButton); + yawInput.SetPos(XMFLOAT2(resetRotationButton.GetPos().x - yawInput.GetSize().x - padding, resetRotationButton.GetPos().y)); pitchInput.SetPos(XMFLOAT2(yawInput.GetPos().x - pitchInput.GetSize().x - padding, yawInput.GetPos().y)); rollInput.SetPos(XMFLOAT2(pitchInput.GetPos().x - rollInput.GetSize().x - padding, pitchInput.GetPos().y)); add_right(rwInput); diff --git a/Editor/TransformWindow.h b/Editor/TransformWindow.h index 71007d452..c8848ae3a 100644 --- a/Editor/TransformWindow.h +++ b/Editor/TransformWindow.h @@ -33,6 +33,10 @@ public: wi::gui::TextInputField snapRotateInput; wi::gui::TextInputField snapTranslateInput; + wi::gui::Button resetTranslationButton; + wi::gui::Button resetScaleButton; + wi::gui::Button resetRotationButton; + void ResizeLayout() override; };