Files
nostalgia/src/nostalgia/scene/studio/sceneeditor-imgui.cpp

60 lines
1.5 KiB
C++

/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <imgui.h>
#include <keel/media.hpp>
#include <nostalgia/core/gfx.hpp>
#include "sceneeditor-imgui.hpp"
namespace nostalgia::scene {
SceneEditorImGui::SceneEditorImGui(turbine::Context *ctx, ox::CRStringView path):
m_editor(ctx, path),
m_view(ctx, m_editor.scene()) {
m_ctx = ctx;
m_itemPath = path;
const auto lastSlash = std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset();
m_itemName = m_itemPath.substr(lastSlash + 1);
setRequiresConstantRefresh(false);
}
ox::CRString SceneEditorImGui::itemName() const noexcept {
return m_itemPath;
}
ox::CRString SceneEditorImGui::itemDisplayName() const noexcept {
return m_itemName;
}
void SceneEditorImGui::draw(turbine::Context*) noexcept {
const auto paneSize = ImGui::GetContentRegionAvail();
const ox::Size fbSize{
static_cast<int>(paneSize.x),
static_cast<int>(paneSize.y)};
m_view.draw(fbSize.width, fbSize.height);
auto &fb = m_view.framebuffer();
const uintptr_t buffId = fb.color.id;
ImGui::Image(
reinterpret_cast<void*>(buffId),
paneSize,
ImVec2(0, 1),
ImVec2(1, 0));
}
void SceneEditorImGui::onActivated() noexcept {
oxLogError(m_view.setupScene());
}
ox::Error SceneEditorImGui::saveItem() noexcept {
const auto sctx = applicationData<studio::StudioContext>(*m_ctx);
oxReturnError(sctx->project->writeObj(m_itemPath, &m_editor.scene()));
oxReturnError(m_ctx->assetManager.setAsset(m_itemPath, m_editor.scene()));
return {};
}
}