diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp index 1abaec74..9d2f4ee2 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -75,10 +75,11 @@ static ox::Error toPngFile( 8))); } -TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path): +TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path): Editor(path), - m_ctx(ctx.tctx), - m_view(m_ctx, path, *undoStack()), + m_sctx(sctx), + m_tctx(sctx.tctx), + m_view(m_sctx, path, *undoStack()), m_model(m_view.model()) { oxIgnoreError(setPaletteSelection()); // connect signal/slots @@ -134,7 +135,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) { setPasteEnabled(false); m_model.clearSelection(); } else if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) { - if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { + if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) { auto const idx = ox::min( static_cast(key - turbine::Key::Num_1), m_model.pal().pages.size() - 1); m_model.setPalettePage(idx); @@ -143,7 +144,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) { m_view.setPalIdx(idx); } } else if (key == turbine::Key::Num_0) { - if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { + if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) { auto const idx = ox::min( static_cast(key - turbine::Key::Num_1 + 9), m_model.pal().pages.size() - 1); m_model.setPalettePage(idx); @@ -235,8 +236,8 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept { ImGui::EndChild(); } ImGui::EndChild(); - m_subsheetEditor.draw(m_ctx); - m_exportMenu.draw(m_ctx); + m_subsheetEditor.draw(m_tctx); + m_exportMenu.draw(m_tctx); } void TileSheetEditorImGui::drawSubsheetSelector( @@ -341,13 +342,14 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept { } else if (m_view.updated()) { m_view.ackUpdate(); } - glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer); - // clear screen and draw - glViewport(0, 0, fbSizei.width, fbSizei.height); - m_view.draw(); - glBindFramebuffer(GL_FRAMEBUFFER, 0); + { + glutils::FrameBufferBind const frameBufferBind(m_framebuffer); + // clear screen and draw + glViewport(0, 0, fbSizei.width, fbSizei.height); + m_view.draw(); + } ImGui::Image( - std::bit_cast(uintptr_t{m_framebuffer.color.id}), + ig::toImTextureID(m_framebuffer.color.id), static_cast(fbSize), ImVec2(0, 1), ImVec2(1, 0)); @@ -359,7 +361,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept { auto const wheelh = io.MouseWheelH; if (wheel != 0) { const auto zoomMod = ox::defines::OS == ox::OS::Darwin ? - io.KeySuper : turbine::buttonDown(m_ctx, turbine::Key::Mod_Ctrl); + io.KeySuper : turbine::buttonDown(m_tctx, turbine::Key::Mod_Ctrl); m_view.scrollV(fbSize, wheel, zoomMod); } if (wheelh != 0) { @@ -399,8 +401,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept { } void TileSheetEditorImGui::drawPaletteSelector() noexcept { - auto &sctx = *applicationData(m_ctx); - auto const&files = sctx.project->fileList(core::FileExt_npal); + auto const&files = m_sctx.project->fileList(core::FileExt_npal); auto const comboWidthSub = 62; ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub); if (ig::ComboBox("Palette", files, m_selectedPaletteIdx)) { @@ -465,8 +466,7 @@ ox::Error TileSheetEditorImGui::updateActiveSubsheet(ox::StringView const&name, ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept { auto const&palPath = m_model.palPath(); - auto &sctx = *applicationData(m_ctx); - auto const&palList = sctx.project->fileList(core::FileExt_npal); + auto const&palList = m_sctx.project->fileList(core::FileExt_npal); for (std::size_t i = 0; auto const&pal : palList) { if (palPath == pal) { m_selectedPaletteIdx = i; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp index 26d0c4df..529bba9a 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp @@ -61,7 +61,8 @@ class TileSheetEditorImGui: public studio::Editor { inline bool isOpen() const noexcept { return m_show; } }; std::size_t m_selectedPaletteIdx = 0; - turbine::Context &m_ctx; + studio::StudioContext &m_sctx; + turbine::Context &m_tctx; ox::Vector m_paletteList; SubSheetEditor m_subsheetEditor; ExportMenu m_exportMenu; @@ -73,7 +74,7 @@ class TileSheetEditorImGui: public studio::Editor { Tool m_tool = Tool::Draw; public: - TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path); + TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path); ~TileSheetEditorImGui() override = default; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index 7694efa9..b3013cde 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -41,8 +41,9 @@ static void normalizeSubsheets(TileSheet::SubSheet &ss) noexcept { } } -TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack): - m_ctx(ctx), +TileSheetEditorModel::TileSheetEditorModel(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack): + m_sctx(sctx), + m_ctx(m_sctx.tctx), m_path(path), m_img(*readObj(keelCtx(m_ctx), m_path).unwrapThrow()), // ignore failure to load palette @@ -261,8 +262,7 @@ void TileSheetEditorModel::ackUpdate() noexcept { } ox::Error TileSheetEditorModel::saveFile() noexcept { - const auto sctx = applicationData(m_ctx); - return sctx->project->writeObj(m_path, m_img, ox::ClawFormat::Metal); + return m_sctx.project->writeObj(m_path, m_img, ox::ClawFormat::Metal); } bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept { diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp index 361d2006..fcee5a9e 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp @@ -24,6 +24,7 @@ class TileSheetEditorModel: public ox::SignalHandler { private: static Palette const s_defaultPalette; + studio::StudioContext &m_sctx; turbine::Context &m_ctx; ox::String m_path; TileSheet m_img; @@ -38,7 +39,7 @@ class TileSheetEditorModel: public ox::SignalHandler { ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}}; public: - TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack); + TileSheetEditorModel(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack); ~TileSheetEditorModel() override = default; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp index b9f4ec8e..a42c6cc6 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp @@ -11,9 +11,10 @@ namespace nostalgia::core { -TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack): +TileSheetEditorView::TileSheetEditorView(studio::StudioContext &ctx, ox::StringView path, studio::UndoStack &undoStack): m_model(ctx, path, undoStack), m_pixelsDrawer(m_model) { + glBindVertexArray(0); // build shaders oxThrowError(m_pixelsDrawer.buildShader()); oxThrowError(m_pixelGridDrawer.buildShader()); diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp index 52ef3028..0e9f8a9e 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp @@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler { std::size_t m_palIdx = 0; public: - TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack); + TileSheetEditorView(studio::StudioContext &ctx, ox::StringView path, studio::UndoStack &undoStack); ~TileSheetEditorView() override = default;