[olympic/studio] Make StudioContext::ui a ref instead of ptr

This commit is contained in:
Gary Talent 2024-03-14 23:31:01 -05:00
parent b015fe88b7
commit dade484d87
5 changed files with 19 additions and 15 deletions

View File

@ -30,13 +30,13 @@ class StudioUIDrawer: public turbine::gl::Drawer {
static int updateHandler(turbine::Context &ctx) noexcept { static int updateHandler(turbine::Context &ctx) noexcept {
auto sctx = turbine::applicationData<studio::StudioContext>(ctx); auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
sctx->ui->update(); sctx->ui.update();
return 16; return 16;
} }
static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down) noexcept { static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down) noexcept {
auto sctx = turbine::applicationData<studio::StudioContext>(ctx); auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
sctx->ui->handleKeyEvent(key, down); sctx->ui.handleKeyEvent(key, down);
} }
static ox::Error runApp( static ox::Error runApp(
@ -48,10 +48,7 @@ static ox::Error runApp(
turbine::setUpdateHandler(*ctx, updateHandler); turbine::setUpdateHandler(*ctx, updateHandler);
turbine::setKeyEventHandler(*ctx, keyEventHandler); turbine::setKeyEventHandler(*ctx, keyEventHandler);
turbine::setConstantRefresh(*ctx, false); turbine::setConstantRefresh(*ctx, false);
studio::StudioContext studioCtx(*ctx); StudioUI ui(*ctx, projectDataDir);
turbine::setApplicationData(*ctx, &studioCtx);
StudioUI ui(studioCtx, projectDataDir);
studioCtx.ui = &ui;
StudioUIDrawer drawer(ui); StudioUIDrawer drawer(ui);
turbine::gl::addDrawer(*ctx, &drawer); turbine::gl::addDrawer(*ctx, &drawer);
auto const err = turbine::run(*ctx); auto const err = turbine::run(*ctx);

View File

@ -10,8 +10,11 @@
namespace studio { namespace studio {
static ox::Result<ox::UniquePtr<ProjectTreeModel>> static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
buildProjectTreeModel(ProjectExplorer &explorer, ox::StringView name, ox::CRStringView path, ProjectTreeModel *parent) noexcept { ProjectExplorer &explorer,
ox::StringView name,
ox::StringView path,
ProjectTreeModel *parent) noexcept {
auto const fs = explorer.romFs(); auto const fs = explorer.romFs();
oxRequire(stat, fs->stat(path)); oxRequire(stat, fs->stat(path));
auto out = ox::make_unique<ProjectTreeModel>(explorer, ox::String(name), parent); auto out = ox::make_unique<ProjectTreeModel>(explorer, ox::String(name), parent);

View File

@ -40,13 +40,14 @@ oxModelBegin(StudioConfig)
oxModelFieldRename(showProjectExplorer, show_project_explorer) oxModelFieldRename(showProjectExplorer, show_project_explorer)
oxModelEnd() oxModelEnd()
StudioUI::StudioUI(studio::StudioContext &ctx, ox::StringView projectDataDir) noexcept: StudioUI::StudioUI(turbine::Context &ctx, ox::StringView projectDataDir) noexcept:
m_sctx(ctx), m_sctx(*this, ctx),
m_ctx(ctx.tctx), m_ctx(ctx),
m_projectDataDir(projectDataDir), m_projectDataDir(projectDataDir),
m_projectExplorer(m_ctx), m_projectExplorer(m_ctx),
m_newProject(ox::String(projectDataDir)), m_newProject(ox::String(projectDataDir)),
m_aboutPopup(m_ctx) { m_aboutPopup(m_ctx) {
turbine::setApplicationData(m_ctx, &m_sctx);
m_projectExplorer.fileChosen.connect(this, &StudioUI::openFile); m_projectExplorer.fileChosen.connect(this, &StudioUI::openFile);
m_newProject.finished.connect(this, &StudioUI::createOpenProject); m_newProject.finished.connect(this, &StudioUI::createOpenProject);
m_newMenu.finished.connect(this, &StudioUI::openFile); m_newMenu.finished.connect(this, &StudioUI::openFile);

View File

@ -24,7 +24,7 @@ class StudioUI: public ox::SignalHandler {
friend class StudioUIDrawer; friend class StudioUIDrawer;
private: private:
studio::StudioContext &m_sctx; studio::StudioContext m_sctx;
turbine::Context &m_ctx; turbine::Context &m_ctx;
ox::String m_projectDataDir; ox::String m_projectDataDir;
ox::UPtr<studio::Project> m_project; ox::UPtr<studio::Project> m_project;
@ -48,7 +48,7 @@ class StudioUI: public ox::SignalHandler {
bool m_showProjectExplorer = true; bool m_showProjectExplorer = true;
public: public:
explicit StudioUI(studio::StudioContext &ctx, ox::StringView projectDataDir) noexcept; explicit StudioUI(turbine::Context &ctx, ox::StringView projectDataDir) noexcept;
void update() noexcept; void update() noexcept;

View File

@ -12,11 +12,14 @@
namespace studio { namespace studio {
class StudioUI;
struct StudioContext { struct StudioContext {
class StudioUI *ui = nullptr; StudioUI &ui;
Project *project = nullptr; Project *project = nullptr;
turbine::Context &tctx; turbine::Context &tctx;
inline explicit StudioContext(turbine::Context &pTctx) noexcept: tctx(pTctx) {} inline StudioContext(StudioUI &pUi, turbine::Context &pTctx) noexcept:
ui(pUi), tctx(pTctx) {}
}; };
} }