engine: sync editor rendering and ui changes
This commit is contained in:
@@ -99,7 +99,9 @@ struct BuiltInIconState {
|
||||
BuiltInTexture gameObject;
|
||||
BuiltInTexture scene;
|
||||
BuiltInTexture cameraGizmo;
|
||||
BuiltInTexture mainLightGizmo;
|
||||
BuiltInTexture directionalLightGizmo;
|
||||
BuiltInTexture pointLightGizmo;
|
||||
BuiltInTexture spotLightGizmo;
|
||||
struct CachedAssetPreview {
|
||||
BuiltInTexture texture;
|
||||
std::unique_ptr<LoadedTexturePixels> decodedPixels;
|
||||
@@ -157,9 +159,19 @@ std::filesystem::path ResolveCameraGizmoIconPath() {
|
||||
return (exeDir / ".." / ".." / "resources" / "Icons" / "camera_gizmo.png").lexically_normal();
|
||||
}
|
||||
|
||||
std::filesystem::path ResolveMainLightGizmoIconPath() {
|
||||
std::filesystem::path ResolveDirectionalLightGizmoIconPath() {
|
||||
const std::filesystem::path exeDir(Platform::GetExecutableDirectoryUtf8());
|
||||
return (exeDir / ".." / ".." / "resources" / "Icons" / "main_light_gizmo.png").lexically_normal();
|
||||
return (exeDir / ".." / ".." / "resources" / "Icons" / "directional_light_gizmo.png").lexically_normal();
|
||||
}
|
||||
|
||||
std::filesystem::path ResolvePointLightGizmoIconPath() {
|
||||
const std::filesystem::path exeDir(Platform::GetExecutableDirectoryUtf8());
|
||||
return (exeDir / ".." / ".." / "resources" / "Icons" / "point_light_gizmo.png").lexically_normal();
|
||||
}
|
||||
|
||||
std::filesystem::path ResolveSpotLightGizmoIconPath() {
|
||||
const std::filesystem::path exeDir(Platform::GetExecutableDirectoryUtf8());
|
||||
return (exeDir / ".." / ".." / "resources" / "Icons" / "spot_light_gizmo.png").lexically_normal();
|
||||
}
|
||||
|
||||
std::string NormalizePathKey(const std::filesystem::path& path) {
|
||||
@@ -975,8 +987,12 @@ BuiltInTexture* ResolveEditorTexture(EditorTextureIconKind kind) {
|
||||
switch (kind) {
|
||||
case EditorTextureIconKind::CameraGizmo:
|
||||
return &g_icons.cameraGizmo;
|
||||
case EditorTextureIconKind::MainLightGizmo:
|
||||
return &g_icons.mainLightGizmo;
|
||||
case EditorTextureIconKind::DirectionalLightGizmo:
|
||||
return &g_icons.directionalLightGizmo;
|
||||
case EditorTextureIconKind::PointLightGizmo:
|
||||
return &g_icons.pointLightGizmo;
|
||||
case EditorTextureIconKind::SpotLightGizmo:
|
||||
return &g_icons.spotLightGizmo;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1025,8 +1041,30 @@ void InitializeBuiltInIcons(
|
||||
backend,
|
||||
device,
|
||||
commandQueue,
|
||||
ResolveMainLightGizmoIconPath(),
|
||||
g_icons.mainLightGizmo,
|
||||
ResolveDirectionalLightGizmoIconPath(),
|
||||
g_icons.directionalLightGizmo,
|
||||
pendingUpload)) {
|
||||
g_icons.pendingIconUploads.push_back(std::move(pendingUpload));
|
||||
}
|
||||
|
||||
pendingUpload.reset();
|
||||
if (LoadTextureFromFile(
|
||||
backend,
|
||||
device,
|
||||
commandQueue,
|
||||
ResolvePointLightGizmoIconPath(),
|
||||
g_icons.pointLightGizmo,
|
||||
pendingUpload)) {
|
||||
g_icons.pendingIconUploads.push_back(std::move(pendingUpload));
|
||||
}
|
||||
|
||||
pendingUpload.reset();
|
||||
if (LoadTextureFromFile(
|
||||
backend,
|
||||
device,
|
||||
commandQueue,
|
||||
ResolveSpotLightGizmoIconPath(),
|
||||
g_icons.spotLightGizmo,
|
||||
pendingUpload)) {
|
||||
g_icons.pendingIconUploads.push_back(std::move(pendingUpload));
|
||||
}
|
||||
@@ -1043,7 +1081,9 @@ void ShutdownBuiltInIcons() {
|
||||
ResetTexture(g_icons.gameObject);
|
||||
ResetTexture(g_icons.scene);
|
||||
ResetTexture(g_icons.cameraGizmo);
|
||||
ResetTexture(g_icons.mainLightGizmo);
|
||||
ResetTexture(g_icons.directionalLightGizmo);
|
||||
ResetTexture(g_icons.pointLightGizmo);
|
||||
ResetTexture(g_icons.spotLightGizmo);
|
||||
g_icons.backend = nullptr;
|
||||
g_icons.device = nullptr;
|
||||
g_icons.commandQueue = nullptr;
|
||||
|
||||
@@ -21,7 +21,10 @@ enum class AssetIconKind {
|
||||
|
||||
enum class EditorTextureIconKind {
|
||||
CameraGizmo,
|
||||
MainLightGizmo
|
||||
DirectionalLightGizmo,
|
||||
PointLightGizmo,
|
||||
SpotLightGizmo,
|
||||
MainLightGizmo = DirectionalLightGizmo
|
||||
};
|
||||
|
||||
void InitializeBuiltInIcons(
|
||||
|
||||
@@ -14,8 +14,17 @@ namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace UI {
|
||||
|
||||
inline bool ShouldTracePopupSubmenuLabel(const char* label) {
|
||||
if (!label) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string text(label);
|
||||
return text == "Create" || text == "3D Object";
|
||||
}
|
||||
|
||||
inline void TracePopupSubmenuIfNeeded(const char* label, const std::string& message) {
|
||||
if (!label || std::string(label) != "Create") {
|
||||
if (!ShouldTracePopupSubmenuLabel(label)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,7 +101,7 @@ inline bool DrawMenuScope(const char* label, DrawContentFn&& drawContent) {
|
||||
}
|
||||
|
||||
template <typename DrawContentFn>
|
||||
inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent) {
|
||||
inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent, bool enabled = true) {
|
||||
if (!label || label[0] == '\0') {
|
||||
return false;
|
||||
}
|
||||
@@ -103,18 +112,24 @@ inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent
|
||||
const ImVec2 rowPos = ImGui::GetCursorScreenPos();
|
||||
const float rowHeight = labelSize.y;
|
||||
const float rowWidth = ImMax(ImGui::GetContentRegionAvail().x, 1.0f);
|
||||
const bool popupOpen = ImGui::IsPopupOpen(popupId);
|
||||
const bool popupOpen = enabled && ImGui::IsPopupOpen(popupId);
|
||||
ImGuiSelectableFlags selectableFlags = ImGuiSelectableFlags_NoAutoClosePopups;
|
||||
if (!enabled) {
|
||||
selectableFlags |= ImGuiSelectableFlags_Disabled;
|
||||
}
|
||||
|
||||
if (ImGui::Selectable(
|
||||
"##PopupSubmenuRow",
|
||||
popupOpen,
|
||||
ImGuiSelectableFlags_NoAutoClosePopups,
|
||||
selectableFlags,
|
||||
ImVec2(rowWidth, rowHeight))) {
|
||||
TracePopupSubmenuIfNeeded(label, "Hierarchy create submenu selectable clicked -> OpenPopup");
|
||||
ImGui::OpenPopup(popupId);
|
||||
if (enabled) {
|
||||
TracePopupSubmenuIfNeeded(label, "Hierarchy create submenu selectable clicked -> OpenPopup");
|
||||
ImGui::OpenPopup(popupId);
|
||||
}
|
||||
}
|
||||
|
||||
const bool hovered = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);
|
||||
const bool hovered = enabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);
|
||||
if (hovered && !popupOpen) {
|
||||
TracePopupSubmenuIfNeeded(label, "Hierarchy create submenu hovered -> OpenPopup");
|
||||
ImGui::OpenPopup(popupId);
|
||||
@@ -127,9 +142,10 @@ inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent
|
||||
const float parentWindowRight = parentWindowPos.x + parentWindowSize.x;
|
||||
const float itemHeight = itemMax.y - itemMin.y;
|
||||
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
||||
const ImU32 textColor = ImGui::GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled);
|
||||
drawList->AddText(
|
||||
ImVec2(itemMin.x + ImGui::GetStyle().FramePadding.x, itemMin.y + (itemHeight - labelSize.y) * 0.5f),
|
||||
ImGui::GetColorU32(ImGuiCol_Text),
|
||||
textColor,
|
||||
label);
|
||||
|
||||
const float arrowExtent = PopupSubmenuArrowExtent();
|
||||
@@ -139,7 +155,12 @@ inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent
|
||||
ImVec2(arrowCenterX - arrowExtent * 0.30f, arrowCenterY - arrowExtent * 0.50f),
|
||||
ImVec2(arrowCenterX - arrowExtent * 0.30f, arrowCenterY + arrowExtent * 0.50f),
|
||||
ImVec2(arrowCenterX + arrowExtent * 0.50f, arrowCenterY),
|
||||
ImGui::GetColorU32(ImGuiCol_Text));
|
||||
textColor);
|
||||
|
||||
if (!enabled) {
|
||||
ImGui::PopID();
|
||||
return false;
|
||||
}
|
||||
|
||||
ImGui::SetNextWindowPos(
|
||||
ImVec2(parentWindowRight + PopupSubmenuOpenOffsetX(), rowPos.y - PopupWindowPadding().y),
|
||||
@@ -149,7 +170,7 @@ inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent
|
||||
ImGuiWindowFlags_NoMove |
|
||||
ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoSavedSettings);
|
||||
if (std::string(label) == "Create") {
|
||||
if (ShouldTracePopupSubmenuLabel(label)) {
|
||||
static bool s_lastCreateOpen = false;
|
||||
if (open != s_lastCreateOpen) {
|
||||
TracePopupSubmenuIfNeeded(
|
||||
|
||||
Reference in New Issue
Block a user