Contain XCUI ImGui adapters behind explicit host seams
This commit is contained in:
56
new_editor/src/XCUIBackend/ImGuiXCUIInputSource.h
Normal file
56
new_editor/src/XCUIBackend/ImGuiXCUIInputSource.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "XCUIBackend/ImGuiXCUIInputAdapter.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace XCUIBackend {
|
||||
|
||||
class ImGuiXCUIInputSnapshotSource final : public IXCUIInputSnapshotSource {
|
||||
public:
|
||||
explicit ImGuiXCUIInputSnapshotSource(const ImGuiIO* io = nullptr)
|
||||
: m_io(io) {
|
||||
}
|
||||
|
||||
void SetIO(const ImGuiIO* io) {
|
||||
m_io = io;
|
||||
}
|
||||
|
||||
const ImGuiIO* GetIO() const {
|
||||
return ResolveIO();
|
||||
}
|
||||
|
||||
XCUIInputBridgeFrameSnapshot CaptureSnapshot(
|
||||
const XCUIInputBridgeCaptureOptions& options = XCUIInputBridgeCaptureOptions()) const override {
|
||||
const ImGuiIO* io = ResolveIO();
|
||||
return io != nullptr
|
||||
? ImGuiXCUIInputAdapter::CaptureSnapshot(*io, options)
|
||||
: XCUIInputBridgeFrameSnapshot();
|
||||
}
|
||||
|
||||
const ::XCEngine::UI::UIPoint& GetPointerPosition() const override {
|
||||
m_cachedPointerPosition = {};
|
||||
const ImGuiIO* io = ResolveIO();
|
||||
if (io != nullptr) {
|
||||
m_cachedPointerPosition = ::XCEngine::UI::UIPoint(io->MousePos.x, io->MousePos.y);
|
||||
}
|
||||
|
||||
return m_cachedPointerPosition;
|
||||
}
|
||||
|
||||
private:
|
||||
const ImGuiIO* ResolveIO() const {
|
||||
if (m_io != nullptr) {
|
||||
return m_io;
|
||||
}
|
||||
|
||||
return ImGui::GetCurrentContext() != nullptr ? &ImGui::GetIO() : nullptr;
|
||||
}
|
||||
|
||||
const ImGuiIO* m_io = nullptr;
|
||||
mutable ::XCEngine::UI::UIPoint m_cachedPointerPosition = {};
|
||||
};
|
||||
|
||||
} // namespace XCUIBackend
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user