109 lines
3.3 KiB
C++
109 lines
3.3 KiB
C++
#pragma once
|
|
|
|
#include "XCUIBackend/XCUIHostedPreviewPresenter.h"
|
|
|
|
#include <XCEngine/UI/DrawData.h>
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string_view>
|
|
|
|
namespace XCEngine {
|
|
namespace Editor {
|
|
namespace XCUIBackend {
|
|
|
|
enum class XCUIPanelCanvasHostBackend : std::uint8_t {
|
|
Null = 0,
|
|
ImGui
|
|
};
|
|
|
|
struct XCUIPanelCanvasHostCapabilities {
|
|
bool supportsPointerHitTesting = false;
|
|
bool supportsHostedSurfaceImages = false;
|
|
bool supportsPrimitiveOverlays = false;
|
|
};
|
|
|
|
struct XCUIPanelCanvasRequest {
|
|
const char* childId = nullptr;
|
|
float height = 0.0f;
|
|
float topInset = 0.0f;
|
|
bool bordered = true;
|
|
bool showSurfaceImage = false;
|
|
bool drawPreviewFrame = true;
|
|
const char* placeholderTitle = nullptr;
|
|
const char* placeholderSubtitle = nullptr;
|
|
const char* badgeTitle = nullptr;
|
|
const char* badgeSubtitle = nullptr;
|
|
XCUIHostedPreviewSurfaceImage surfaceImage = {};
|
|
};
|
|
|
|
struct XCUIPanelCanvasSession {
|
|
::XCEngine::UI::UIRect hostRect = {};
|
|
::XCEngine::UI::UIRect canvasRect = {};
|
|
::XCEngine::UI::UIPoint pointerPosition = {};
|
|
bool validCanvas = false;
|
|
bool hovered = false;
|
|
bool windowFocused = false;
|
|
};
|
|
|
|
inline const char* ResolveXCUIPanelCanvasChildId(
|
|
const XCUIPanelCanvasRequest& request,
|
|
const char* fallback = "XCUIPanelCanvasHost") {
|
|
if (request.childId != nullptr && request.childId[0] != '\0') {
|
|
return request.childId;
|
|
}
|
|
|
|
return fallback != nullptr ? fallback : "XCUIPanelCanvasHost";
|
|
}
|
|
|
|
inline XCUIPanelCanvasSession BuildPassiveXCUIPanelCanvasSession(
|
|
const XCUIPanelCanvasRequest& request) {
|
|
const float hostHeight = request.height > 0.0f ? request.height : 0.0f;
|
|
const float topInset = request.topInset > 0.0f ? request.topInset : 0.0f;
|
|
const float clampedTopInset = topInset < hostHeight ? topInset : hostHeight;
|
|
|
|
XCUIPanelCanvasSession session = {};
|
|
session.hostRect = ::XCEngine::UI::UIRect(0.0f, 0.0f, 0.0f, hostHeight);
|
|
session.canvasRect = ::XCEngine::UI::UIRect(
|
|
0.0f,
|
|
clampedTopInset,
|
|
0.0f,
|
|
hostHeight - clampedTopInset);
|
|
session.pointerPosition = {};
|
|
session.validCanvas = false;
|
|
session.hovered = false;
|
|
session.windowFocused = false;
|
|
return session;
|
|
}
|
|
|
|
class IXCUIPanelCanvasHost {
|
|
public:
|
|
virtual ~IXCUIPanelCanvasHost() = default;
|
|
|
|
virtual const char* GetDebugName() const = 0;
|
|
virtual XCUIPanelCanvasHostBackend GetBackend() const = 0;
|
|
virtual XCUIPanelCanvasHostCapabilities GetCapabilities() const = 0;
|
|
virtual XCUIPanelCanvasSession BeginCanvas(const XCUIPanelCanvasRequest& request) = 0;
|
|
virtual void DrawFilledRect(
|
|
const ::XCEngine::UI::UIRect& rect,
|
|
const ::XCEngine::UI::UIColor& color,
|
|
float rounding = 0.0f) = 0;
|
|
virtual void DrawOutlineRect(
|
|
const ::XCEngine::UI::UIRect& rect,
|
|
const ::XCEngine::UI::UIColor& color,
|
|
float thickness = 1.0f,
|
|
float rounding = 0.0f) = 0;
|
|
virtual void DrawText(
|
|
const ::XCEngine::UI::UIPoint& position,
|
|
std::string_view text,
|
|
const ::XCEngine::UI::UIColor& color,
|
|
float fontSize = 0.0f) = 0;
|
|
virtual void EndCanvas() = 0;
|
|
};
|
|
|
|
std::unique_ptr<IXCUIPanelCanvasHost> CreateNullXCUIPanelCanvasHost();
|
|
|
|
} // namespace XCUIBackend
|
|
} // namespace Editor
|
|
} // namespace XCEngine
|