Fix command registrations and mouse pick polling when using transform gizmo
This commit is contained in:
parent
23b8b66297
commit
26eb4ad18c
|
@ -1,54 +0,0 @@
|
||||||
[Window][MainStatusBar]
|
|
||||||
Pos=0,1060
|
|
||||||
Size=1920,20
|
|
||||||
Collapsed=0
|
|
||||||
|
|
||||||
[Window][SHEditorMenuBar]
|
|
||||||
Pos=0,48
|
|
||||||
Size=1920,1012
|
|
||||||
Collapsed=0
|
|
||||||
|
|
||||||
[Window][Hierarchy Panel]
|
|
||||||
Pos=0,142
|
|
||||||
Size=387,918
|
|
||||||
Collapsed=0
|
|
||||||
DockId=0x00000004,0
|
|
||||||
|
|
||||||
[Window][Debug##Default]
|
|
||||||
Pos=60,60
|
|
||||||
Size=400,400
|
|
||||||
Collapsed=0
|
|
||||||
|
|
||||||
[Window][Inspector]
|
|
||||||
Pos=1649,48
|
|
||||||
Size=271,1012
|
|
||||||
Collapsed=0
|
|
||||||
DockId=0x00000006,0
|
|
||||||
|
|
||||||
[Window][Profiler]
|
|
||||||
Pos=0,48
|
|
||||||
Size=387,92
|
|
||||||
Collapsed=0
|
|
||||||
DockId=0x00000003,0
|
|
||||||
|
|
||||||
[Window][Viewport]
|
|
||||||
Pos=648,48
|
|
||||||
Size=2519,1319
|
|
||||||
Collapsed=0
|
|
||||||
DockId=0x00000002,0
|
|
||||||
|
|
||||||
[Window][ Viewport]
|
|
||||||
Pos=389,48
|
|
||||||
Size=1258,1012
|
|
||||||
Collapsed=0
|
|
||||||
DockId=0x00000002,0
|
|
||||||
|
|
||||||
[Docking][Data]
|
|
||||||
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=1920,1012 Split=X
|
|
||||||
DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1992,1036 Split=X
|
|
||||||
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=387,1036 Split=Y Selected=0x1E6EB881
|
|
||||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881
|
|
||||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,940 Selected=0xE096E5AE
|
|
||||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1258,1036 CentralNode=1 Selected=0xB41284E7
|
|
||||||
DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=271,1036 Selected=0xE7039252
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ namespace Sandbox
|
||||||
SHSceneManager::SceneUpdate(0.016f);
|
SHSceneManager::SceneUpdate(0.016f);
|
||||||
#endif
|
#endif
|
||||||
SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, 0.016f);
|
SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, 0.016f);
|
||||||
//editor->PollPicking();
|
editor->PollPicking();
|
||||||
}
|
}
|
||||||
// Finish all graphics jobs first
|
// Finish all graphics jobs first
|
||||||
graphicsSystem->AwaitGraphicsExecution();
|
graphicsSystem->AwaitGraphicsExecution();
|
||||||
|
|
|
@ -94,7 +94,7 @@ namespace SHADE
|
||||||
if (ImGui::BeginMenuBar())
|
if (ImGui::BeginMenuBar())
|
||||||
{
|
{
|
||||||
|
|
||||||
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 35.0f);
|
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 40.0f);
|
||||||
if(ImGui::SmallButton(ICON_MD_DESELECT))
|
if(ImGui::SmallButton(ICON_MD_DESELECT))
|
||||||
{
|
{
|
||||||
auto editor = SHSystemManager::GetSystem<SHEditor>();
|
auto editor = SHSystemManager::GetSystem<SHEditor>();
|
||||||
|
|
|
@ -39,6 +39,10 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
SHComponentManager::RemoveComponent<T>(component->GetEID());
|
SHComponentManager::RemoveComponent<T>(component->GetEID());
|
||||||
}
|
}
|
||||||
|
if (ImGui::Selectable(std::format("{} Reset {}", ICON_MD_RESTART_ALT, componentName.data()).data()))
|
||||||
|
{
|
||||||
|
*component = T();
|
||||||
|
}
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace SHADE
|
||||||
void SHEditorViewport::Init()
|
void SHEditorViewport::Init()
|
||||||
{
|
{
|
||||||
SHEditorWindow::Init();
|
SHEditorWindow::Init();
|
||||||
|
transformGizmo.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHEditorViewport::Update()
|
void SHEditorViewport::Update()
|
||||||
|
|
|
@ -13,6 +13,12 @@
|
||||||
#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h"
|
#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h"
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
void SHTransformGizmo::Init()
|
||||||
|
{
|
||||||
|
auto& style = ImGuizmo::GetStyle();
|
||||||
|
style.RotationLineThickness = 2.5f;
|
||||||
|
}
|
||||||
|
|
||||||
void SHTransformGizmo::Draw()
|
void SHTransformGizmo::Draw()
|
||||||
{
|
{
|
||||||
bool justChangedTfm = false;
|
bool justChangedTfm = false;
|
||||||
|
@ -26,9 +32,12 @@ namespace SHADE
|
||||||
|
|
||||||
SHMatrix view = SHMatrix::Transpose(editorCamera->GetViewMatrix());
|
SHMatrix view = SHMatrix::Transpose(editorCamera->GetViewMatrix());
|
||||||
SHMatrix proj = SHMatrix::Transpose(editorCamera->GetProjMatrix());
|
SHMatrix proj = SHMatrix::Transpose(editorCamera->GetProjMatrix());
|
||||||
|
|
||||||
|
//Invert projection y-axis
|
||||||
proj(1, 1) *= -1;
|
proj(1, 1) *= -1;
|
||||||
|
|
||||||
static SHMatrix gridMat = SHMatrix::Translate(0, -0.5f, 0.f) * SHMatrix::Identity;
|
static SHMatrix gridMat = SHMatrix::Translate(0, -0.5f, 0.f) * SHMatrix::Identity;
|
||||||
//ImGuizmo::DrawGrid(&view._11, &proj._11, &gridMat._11, 100.f);
|
|
||||||
if (selectedEntityTransformComponent == nullptr)
|
if (selectedEntityTransformComponent == nullptr)
|
||||||
{
|
{
|
||||||
SHEditor* editor = SHSystemManager::GetSystem<SHEditor>();
|
SHEditor* editor = SHSystemManager::GetSystem<SHEditor>();
|
||||||
|
@ -55,11 +64,23 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SHMatrix mat = selectedEntityTransformComponent->GetTRS();
|
SHMatrix mat = selectedEntityTransformComponent->GetTRS();
|
||||||
isManipulating = ImGuizmo::Manipulate(&view._11, &proj._11, static_cast<ImGuizmo::OPERATION>(operation), ImGuizmo::MODE::WORLD, &mat._11);
|
useSnap = ImGui::IsKeyDown(ImGuiKey_LeftCtrl);
|
||||||
if (!justChangedTfm)
|
if(useSnap)
|
||||||
{
|
{
|
||||||
if (ImGui::IsItemClicked())
|
switch (operation)
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHMatrix>>(selectedEntityTransformComponent->GetTRS(), mat, [tfm = std::move(selectedEntityTransformComponent)](SHMatrix const& mtx)
|
{
|
||||||
|
case Operation::TRANSLATE: snap = &translationSnap.x; break;
|
||||||
|
case Operation::ROTATE: snap = &rotationSnap; break;
|
||||||
|
case Operation::SCALE: snap = &scaleSnap; break;
|
||||||
|
default: snap = &translationSnap.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGuizmo::Manipulate(&view._11, &proj._11, static_cast<ImGuizmo::OPERATION>(operation), ImGuizmo::MODE::WORLD, &mat._11, nullptr, useSnap ? snap : nullptr);
|
||||||
|
static bool startRecording = false;
|
||||||
|
if (!justChangedTfm && ImGuizmo::IsUsing())
|
||||||
|
{
|
||||||
|
|
||||||
|
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHMatrix>>(selectedEntityTransformComponent->GetTRS(), mat, [tfm = (selectedEntityTransformComponent)](SHMatrix const& mtx)
|
||||||
{
|
{
|
||||||
if (!tfm)
|
if (!tfm)
|
||||||
return;
|
return;
|
||||||
|
@ -68,18 +89,12 @@ namespace SHADE
|
||||||
tfm->SetWorldPosition(translate);
|
tfm->SetWorldPosition(translate);
|
||||||
tfm->SetWorldRotation(rotate);
|
tfm->SetWorldRotation(rotate);
|
||||||
tfm->SetWorldScale(scale);
|
tfm->SetWorldScale(scale);
|
||||||
})));
|
})), startRecording);
|
||||||
else if (ImGui::IsItemHovered(ImGuiMouseButton_Left) && ImGui::IsMouseDown(ImGuiMouseButton_Left) && isManipulating)
|
if(!startRecording)
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHMatrix>>(selectedEntityTransformComponent->GetTRS(), mat, [tfm = std::move(selectedEntityTransformComponent)](SHMatrix const& mtx)
|
startRecording = true;
|
||||||
{
|
}
|
||||||
if (!tfm)
|
isManipulating = ImGuizmo::IsUsing() || startRecording;
|
||||||
return;
|
if(startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||||
SHVec3 translate{}, rotate{}, scale{};
|
startRecording = false;
|
||||||
mtx.Decompose(translate, rotate, scale);
|
|
||||||
tfm->SetWorldPosition(translate);
|
|
||||||
tfm->SetWorldRotation(rotate);
|
|
||||||
tfm->SetWorldScale(scale);
|
|
||||||
})), true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,17 @@ namespace SHADE
|
||||||
UNIVERSAL = TRANSLATE | ROTATE | SCALEU
|
UNIVERSAL = TRANSLATE | ROTATE | SCALEU
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void Init();
|
||||||
void Draw();
|
void Draw();
|
||||||
bool isManipulating = false;
|
bool isManipulating = false;
|
||||||
|
bool useSnap = false;
|
||||||
Mode mode = Mode::WORLD;
|
Mode mode = Mode::WORLD;
|
||||||
Operation operation = Operation::TRANSLATE;
|
Operation operation = Operation::TRANSLATE;
|
||||||
private:
|
private:
|
||||||
|
float scaleSnap = 0.25f;
|
||||||
|
float rotationSnap = 1.0f;
|
||||||
|
SHVec3 translationSnap = SHVec3(0.25f, 0.25f, 0.25f);
|
||||||
|
float* snap = nullptr;
|
||||||
SHTransformComponent* selectedEntityTransformComponent{nullptr};
|
SHTransformComponent* selectedEntityTransformComponent{nullptr};
|
||||||
SHCameraComponent* editorCamera{nullptr};
|
SHCameraComponent* editorCamera{nullptr};
|
||||||
};
|
};
|
||||||
|
|
|
@ -134,7 +134,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PollPicking();
|
//PollPicking();
|
||||||
|
|
||||||
if(ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_Z))
|
if(ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_Z))
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,6 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
|
|
||||||
auto cursorPos = ImGui::GetCursorScreenPos();
|
|
||||||
auto itemSpacing = ImGui::GetStyle().ItemSpacing;
|
auto itemSpacing = ImGui::GetStyle().ItemSpacing;
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
|
||||||
|
@ -208,21 +207,16 @@ namespace SHADE
|
||||||
ImGuiSliderFlags flags = 0)
|
ImGuiSliderFlags flags = 0)
|
||||||
{
|
{
|
||||||
SHVec2 values = get();
|
SHVec2 values = get();
|
||||||
bool changed = false;
|
bool const changed = DragN<float, 2>(fieldLabel, componentLabels, { &values.x, &values.y }, speed, displayFormat, valueMin, valueMax, flags);
|
||||||
if (DragN<float, 2>(fieldLabel, componentLabels, { &values.x, &values.y }, speed, displayFormat, valueMin, valueMax, flags))
|
static bool startRecording = false;
|
||||||
{
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec2>>(get(), values, set)), startRecording);
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec2>>(get(), values, set)), false);
|
if (!startRecording)
|
||||||
else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
startRecording = true;
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec2>>(get(), values, set)), true);
|
|
||||||
else if (ImGui::IsItemDeactivatedAfterEdit())
|
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec2>>(get(), values, set)), false);
|
|
||||||
}
|
}
|
||||||
|
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||||
|
startRecording = false;
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
@ -232,20 +226,20 @@ namespace SHADE
|
||||||
ImGuiSliderFlags flags = 0)
|
ImGuiSliderFlags flags = 0)
|
||||||
{
|
{
|
||||||
SHVec3 values = get();
|
SHVec3 values = get();
|
||||||
bool changed = false;
|
bool const changed = DragN<float, 3>(fieldLabel, componentLabels, { &values.x, &values.y, &values.z }, speed, displayFormat, valueMin, valueMax, flags);
|
||||||
if (DragN<float, 3>(fieldLabel, componentLabels, { &values.x, &values.y, &values.z }, speed, displayFormat, valueMin, valueMax, flags))
|
|
||||||
{
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
static bool startRecording = false;
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
if (ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left, -0.2f))
|
SHVec3 old = get();
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec3>>(get(), values, set)), false);
|
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec3>>(old, values, set)), startRecording);
|
||||||
else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
if (!startRecording)
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec3>>(get(), values, set)), true);
|
startRecording = true;
|
||||||
else if (ImGui::IsItemDeactivatedAfterEdit())
|
}
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec3>>(get(), values, set)), false);
|
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||||
|
{
|
||||||
|
startRecording = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
|
@ -256,20 +250,17 @@ namespace SHADE
|
||||||
ImGuiSliderFlags flags = 0)
|
ImGuiSliderFlags flags = 0)
|
||||||
{
|
{
|
||||||
SHVec4 values = get();
|
SHVec4 values = get();
|
||||||
bool changed = false;
|
bool const changed = DragN<float, 4>(fieldLabel, componentLabels, { &values.x, &values.y, &values.z, &values.w }, speed, displayFormat, valueMin, valueMax, flags);
|
||||||
if (DragN<float, 4>(fieldLabel, componentLabels, { &values.x, &values.y, &values.z, &values.w }, speed, displayFormat, valueMin, valueMax, flags))
|
static bool startRecording = false;
|
||||||
{
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
if (ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left, -0.2f))
|
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec4>>(get(), values, set)), startRecording);
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec4>>(get(), values, set)), false);
|
if (!startRecording)
|
||||||
else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
startRecording = true;
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec4>>(get(), values, set)), true);
|
}
|
||||||
else if (ImGui::IsItemDeactivatedAfterEdit())
|
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec4>>(get(), values, set)), false);
|
{
|
||||||
|
startRecording = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
|
@ -325,112 +316,116 @@ namespace SHADE
|
||||||
float speed = 1.0f, T p_min = T(), T p_max = T(), const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
float speed = 1.0f, T p_min = T(), T p_max = T(), const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
||||||
{
|
{
|
||||||
T value = get();
|
T value = get();
|
||||||
std::cout << value << " \n";
|
const bool hasChange = ImGui::DragScalar(fieldLabel.c_str(), data_type, &value, speed, &p_min, &p_max, displayFormat, flags);
|
||||||
//bool hasChange = ImGui::DragScalar(fieldLabel.c_str(), data_type, &value, speed, &p_min, &p_max, displayFormat, flags);
|
static bool startRecording = false;
|
||||||
|
if (hasChange)
|
||||||
if (ImGui::DragScalar(fieldLabel.c_str(), data_type, &value, speed, &p_min, &p_max, displayFormat, flags))
|
|
||||||
{
|
{
|
||||||
if (ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), startRecording);
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), false);
|
if (!startRecording)
|
||||||
else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
startRecording = true;
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), true);
|
|
||||||
else if (ImGui::IsItemDeactivatedAfterEdit())
|
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), false);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||||
|
{
|
||||||
|
startRecording = false;
|
||||||
|
}
|
||||||
|
return hasChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool DragFloat(const std::string& fieldLabel, std::function<float(void)> get, std::function<void(float const&)> set,
|
static bool DragFloat(const std::string& fieldLabel, std::function<float(void)> get, std::function<void(float const&)> set,
|
||||||
float speed = 0.1f, float p_min = float(), float p_max = float(), const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
float speed = 0.1f, float p_min = float(), float p_max = float(), const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
||||||
{
|
{
|
||||||
float value = get();
|
float value = get();
|
||||||
//bool hasChange = ImGui::DragFloat(fieldLabel.c_str(), &value, speed, p_min, p_max, displayFormat, flags);
|
const bool hasChange = ImGui::DragFloat(fieldLabel.c_str(), &value, speed, p_min, p_max, displayFormat, flags);
|
||||||
if (ImGui::DragFloat(fieldLabel.c_str(), &value, speed, p_min, p_max, displayFormat, flags))
|
static bool startRecording = false;
|
||||||
|
if (hasChange)
|
||||||
{
|
{
|
||||||
if (ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<float>>(get(), value, set)), startRecording);
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<float>>(get(), value, set)), false);
|
if (!startRecording)
|
||||||
else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
startRecording = true;
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<float>>(get(), value, set)), true);
|
|
||||||
else if (ImGui::IsItemDeactivatedAfterEdit())
|
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<float>>(get(), value, set)), false);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||||
return false;
|
{
|
||||||
|
startRecording = false;
|
||||||
|
}
|
||||||
|
return hasChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool DragInt(const std::string& fieldLabel, std::function<int(void)> get, std::function<void(int const&)> set,
|
static bool DragInt(const std::string& fieldLabel, std::function<int(void)> get, std::function<void(int const&)> set,
|
||||||
float speed = 1.0f, int p_min = int(), int p_max = int(), const char* displayFormat = "%d", ImGuiSliderFlags flags = 0)
|
float speed = 1.0f, int p_min = int(), int p_max = int(), const char* displayFormat = "%d", ImGuiSliderFlags flags = 0)
|
||||||
{
|
{
|
||||||
int value = get();
|
int value = get();
|
||||||
//bool hasChange = ImGui::DragFloat(fieldLabel.c_str(), &value, speed, p_min, p_max, displayFormat, flags);
|
const bool hasChange = ImGui::DragInt(fieldLabel.c_str(), &value, speed, p_min, p_max, displayFormat, flags);
|
||||||
if (ImGui::DragInt(fieldLabel.c_str(), &value, speed, p_min, p_max, displayFormat, flags))
|
static bool startRecording = false;
|
||||||
|
if (hasChange)
|
||||||
{
|
{
|
||||||
if (ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<int>>(get(), value, set)), startRecording);
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<int>>(get(), value, set)), false);
|
if (!startRecording)
|
||||||
else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
startRecording = true;
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<int>>(get(), value, set)), true);
|
|
||||||
else if (ImGui::IsItemDeactivatedAfterEdit())
|
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<int>>(get(), value, set)), false);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||||
return false;
|
{
|
||||||
|
startRecording = false;
|
||||||
|
}
|
||||||
|
return hasChange;
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static bool SliderScalar(const std::string& fieldLabel, ImGuiDataType data_type, T min, T max, std::function<T(void)> get, std::function<void(T const&)> set,
|
static bool SliderScalar(const std::string& fieldLabel, ImGuiDataType data_type, T min, T max, std::function<T(void)> get, std::function<void(T const&)> set,
|
||||||
const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
||||||
{
|
{
|
||||||
T value = get();
|
T value = get();
|
||||||
if (ImGui::SliderScalar(fieldLabel.c_str(), data_type, &value, &min, &max, displayFormat, flags))
|
bool const changed = ImGui::SliderScalar(fieldLabel.c_str(), data_type, &value, &min, &max, displayFormat, flags);
|
||||||
|
static bool startRecording = false;
|
||||||
|
if (changed)
|
||||||
{
|
{
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left, false) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left, -0.2f))
|
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), startRecording);
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), false);
|
if (!startRecording)
|
||||||
else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
startRecording = true;
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||||
return false;
|
{
|
||||||
|
startRecording = false;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SliderFloat(const std::string& fieldLabel, float min, float max, std::function<float(void)> get, std::function<void(float const&)> set,
|
static bool SliderFloat(const std::string& fieldLabel, float min, float max, std::function<float(void)> get, std::function<void(float const&)> set,
|
||||||
const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
||||||
{
|
{
|
||||||
float value = get();
|
float value = get();
|
||||||
if (ImGui::SliderFloat(fieldLabel.c_str(), &value, min, max, displayFormat, flags))
|
bool const changed = ImGui::SliderFloat(fieldLabel.c_str(), &value, min, max, displayFormat, flags);
|
||||||
|
static bool startRecording = false;
|
||||||
|
if (changed)
|
||||||
{
|
{
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left, false) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left, -0.2f))
|
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<float>>(get(), value, set)), startRecording);
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<float>>(get(), value, set)), false);
|
if (!startRecording)
|
||||||
else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
startRecording = true;
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<float>>(get(), value, set)), true);
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||||
return false;
|
{
|
||||||
|
startRecording = false;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SliderInt(const std::string& fieldLabel, int min, int max, std::function<int(void)> get, std::function<void(int const&)> set,
|
static bool SliderInt(const std::string& fieldLabel, int min, int max, std::function<int(void)> get, std::function<void(int const&)> set,
|
||||||
const char* displayFormat = "%d", ImGuiSliderFlags flags = 0)
|
const char* displayFormat = "%d", ImGuiSliderFlags flags = 0)
|
||||||
{
|
{
|
||||||
int value = get();
|
int value = get();
|
||||||
if (ImGui::SliderInt(fieldLabel.c_str(), &value, min, max, displayFormat, flags))
|
bool const changed = ImGui::SliderInt(fieldLabel.c_str(), &value, min, max, displayFormat, flags);
|
||||||
|
static bool startRecording = false;
|
||||||
|
if (changed)
|
||||||
{
|
{
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left, false) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left, -0.2f))
|
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<int>>(get(), value, set)), false);
|
|
||||||
else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
|
||||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<int>>(get(), value, set)), true);
|
|
||||||
|
|
||||||
return true;
|
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<int>>(get(), value, set)), startRecording);
|
||||||
|
if (!startRecording)
|
||||||
|
startRecording = true;
|
||||||
|
}
|
||||||
|
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||||
|
{
|
||||||
|
startRecording = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue