Refactor material inspector state IO
This commit is contained in:
103
tests/editor/test_viewport_panel_content.cpp
Normal file
103
tests/editor/test_viewport_panel_content.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "panels/ViewportPanelContent.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace {
|
||||
|
||||
class ImGuiContextScope {
|
||||
public:
|
||||
ImGuiContextScope() {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
}
|
||||
|
||||
~ImGuiContextScope() {
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
};
|
||||
|
||||
void BeginTestFrame() {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.DisplaySize = ImVec2(640.0f, 480.0f);
|
||||
io.DeltaTime = 1.0f / 60.0f;
|
||||
unsigned char* fontPixels = nullptr;
|
||||
int fontWidth = 0;
|
||||
int fontHeight = 0;
|
||||
io.Fonts->GetTexDataAsRGBA32(&fontPixels, &fontWidth, &fontHeight);
|
||||
io.Fonts->SetTexID(static_cast<ImTextureID>(1));
|
||||
ImGui::GetStyle().WindowPadding = ImVec2(0.0f, 0.0f);
|
||||
|
||||
ImGui::NewFrame();
|
||||
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
|
||||
ImGui::SetNextWindowSize(ImVec2(320.0f, 240.0f));
|
||||
ASSERT_TRUE(ImGui::Begin(
|
||||
"ViewportPanelContentTestWindow",
|
||||
nullptr,
|
||||
ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoMove |
|
||||
ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoCollapse |
|
||||
ImGuiWindowFlags_NoSavedSettings));
|
||||
}
|
||||
|
||||
void EndTestFrame() {
|
||||
ImGui::End();
|
||||
ImGui::EndFrame();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(ViewportPanelContentTest, AllowOverlapDefaultItemClickMissesMiddleClickOnFirstFrame) {
|
||||
ImGuiContextScope contextScope;
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
BeginTestFrame();
|
||||
EndTestFrame();
|
||||
|
||||
io.MousePos = ImVec2(32.0f, 32.0f);
|
||||
io.MouseDown[ImGuiMouseButton_Middle] = true;
|
||||
BeginTestFrame();
|
||||
|
||||
ImGui::SetCursorScreenPos(ImVec2(16.0f, 16.0f));
|
||||
|
||||
ImGui::SetNextItemAllowOverlap();
|
||||
ImGui::InvisibleButton(
|
||||
"##ViewportOverlapProbe",
|
||||
ImVec2(120.0f, 90.0f),
|
||||
ImGuiButtonFlags_MouseButtonMiddle);
|
||||
|
||||
EXPECT_FALSE(ImGui::IsItemHovered());
|
||||
EXPECT_FALSE(ImGui::IsItemClicked(ImGuiMouseButton_Middle));
|
||||
EXPECT_TRUE(ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlappedByItem));
|
||||
|
||||
EndTestFrame();
|
||||
}
|
||||
|
||||
TEST(ViewportPanelContentTest, InteractionSurfaceCapturesMiddleClickOnFirstHoveredFrame) {
|
||||
ImGuiContextScope contextScope;
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
BeginTestFrame();
|
||||
EndTestFrame();
|
||||
|
||||
io.MousePos = ImVec2(32.0f, 32.0f);
|
||||
io.MouseDown[ImGuiMouseButton_Middle] = true;
|
||||
BeginTestFrame();
|
||||
|
||||
ImGui::SetCursorScreenPos(ImVec2(16.0f, 16.0f));
|
||||
|
||||
XCEngine::Editor::ViewportPanelContentResult result = {};
|
||||
XCEngine::Editor::RenderViewportInteractionSurface(
|
||||
result,
|
||||
XCEngine::Editor::EditorViewportKind::Scene,
|
||||
ImVec2(120.0f, 90.0f));
|
||||
|
||||
EXPECT_TRUE(result.hovered);
|
||||
EXPECT_TRUE(result.clickedMiddle);
|
||||
EXPECT_FALSE(result.clickedLeft);
|
||||
EXPECT_FALSE(result.clickedRight);
|
||||
|
||||
EndTestFrame();
|
||||
}
|
||||
Reference in New Issue
Block a user