diff --git a/src/olympic/studio/applib/src/main.cpp b/src/olympic/studio/applib/src/main.cpp index fd4bb60b..85482205 100644 --- a/src/olympic/studio/applib/src/main.cpp +++ b/src/olympic/studio/applib/src/main.cpp @@ -30,13 +30,13 @@ class StudioUIDrawer: public turbine::gl::Drawer { static int updateHandler(turbine::Context &ctx) noexcept { auto sctx = turbine::applicationData(ctx); - sctx->ui->update(); + sctx->ui.update(); return 16; } static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down) noexcept { auto sctx = turbine::applicationData(ctx); - sctx->ui->handleKeyEvent(key, down); + sctx->ui.handleKeyEvent(key, down); } static ox::Error runApp( @@ -48,10 +48,7 @@ static ox::Error runApp( turbine::setUpdateHandler(*ctx, updateHandler); turbine::setKeyEventHandler(*ctx, keyEventHandler); turbine::setConstantRefresh(*ctx, false); - studio::StudioContext studioCtx(*ctx); - turbine::setApplicationData(*ctx, &studioCtx); - StudioUI ui(studioCtx, projectDataDir); - studioCtx.ui = &ui; + StudioUI ui(*ctx, projectDataDir); StudioUIDrawer drawer(ui); turbine::gl::addDrawer(*ctx, &drawer); auto const err = turbine::run(*ctx); diff --git a/src/olympic/studio/applib/src/projectexplorer.cpp b/src/olympic/studio/applib/src/projectexplorer.cpp index 2ff1a2d4..3cc779e5 100644 --- a/src/olympic/studio/applib/src/projectexplorer.cpp +++ b/src/olympic/studio/applib/src/projectexplorer.cpp @@ -10,8 +10,11 @@ namespace studio { -static ox::Result> -buildProjectTreeModel(ProjectExplorer &explorer, ox::StringView name, ox::CRStringView path, ProjectTreeModel *parent) noexcept { +static ox::Result> buildProjectTreeModel( + ProjectExplorer &explorer, + ox::StringView name, + ox::StringView path, + ProjectTreeModel *parent) noexcept { auto const fs = explorer.romFs(); oxRequire(stat, fs->stat(path)); auto out = ox::make_unique(explorer, ox::String(name), parent); diff --git a/src/olympic/studio/applib/src/studioapp.cpp b/src/olympic/studio/applib/src/studioapp.cpp index 984be43f..790e9944 100644 --- a/src/olympic/studio/applib/src/studioapp.cpp +++ b/src/olympic/studio/applib/src/studioapp.cpp @@ -40,13 +40,14 @@ oxModelBegin(StudioConfig) oxModelFieldRename(showProjectExplorer, show_project_explorer) oxModelEnd() -StudioUI::StudioUI(studio::StudioContext &ctx, ox::StringView projectDataDir) noexcept: - m_sctx(ctx), - m_ctx(ctx.tctx), +StudioUI::StudioUI(turbine::Context &ctx, ox::StringView projectDataDir) noexcept: + m_sctx(*this, ctx), + m_ctx(ctx), m_projectDataDir(projectDataDir), m_projectExplorer(m_ctx), m_newProject(ox::String(projectDataDir)), m_aboutPopup(m_ctx) { + turbine::setApplicationData(m_ctx, &m_sctx); m_projectExplorer.fileChosen.connect(this, &StudioUI::openFile); m_newProject.finished.connect(this, &StudioUI::createOpenProject); m_newMenu.finished.connect(this, &StudioUI::openFile); diff --git a/src/olympic/studio/applib/src/studioapp.hpp b/src/olympic/studio/applib/src/studioapp.hpp index 25d3c740..74e24a7c 100644 --- a/src/olympic/studio/applib/src/studioapp.hpp +++ b/src/olympic/studio/applib/src/studioapp.hpp @@ -24,7 +24,7 @@ class StudioUI: public ox::SignalHandler { friend class StudioUIDrawer; private: - studio::StudioContext &m_sctx; + studio::StudioContext m_sctx; turbine::Context &m_ctx; ox::String m_projectDataDir; ox::UPtr m_project; @@ -48,7 +48,7 @@ class StudioUI: public ox::SignalHandler { bool m_showProjectExplorer = true; public: - explicit StudioUI(studio::StudioContext &ctx, ox::StringView projectDataDir) noexcept; + explicit StudioUI(turbine::Context &ctx, ox::StringView projectDataDir) noexcept; void update() noexcept; diff --git a/src/olympic/studio/modlib/include/studio/context.hpp b/src/olympic/studio/modlib/include/studio/context.hpp index c7101bac..de15c8cd 100644 --- a/src/olympic/studio/modlib/include/studio/context.hpp +++ b/src/olympic/studio/modlib/include/studio/context.hpp @@ -12,11 +12,14 @@ namespace studio { +class StudioUI; + struct StudioContext { - class StudioUI *ui = nullptr; + StudioUI &ui; Project *project = nullptr; turbine::Context &tctx; - inline explicit StudioContext(turbine::Context &pTctx) noexcept: tctx(pTctx) {} + inline StudioContext(StudioUI &pUi, turbine::Context &pTctx) noexcept: + ui(pUi), tctx(pTctx) {} }; }