[olympic/studio] Make StudioContext::ui a ref instead of ptr
This commit is contained in:
		@@ -30,13 +30,13 @@ class StudioUIDrawer: public turbine::gl::Drawer {
 | 
			
		||||
 | 
			
		||||
static int updateHandler(turbine::Context &ctx) noexcept {
 | 
			
		||||
	auto sctx = turbine::applicationData<studio::StudioContext>(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<studio::StudioContext>(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);
 | 
			
		||||
 
 | 
			
		||||
@@ -10,8 +10,11 @@
 | 
			
		||||
 | 
			
		||||
namespace studio {
 | 
			
		||||
 | 
			
		||||
static ox::Result<ox::UniquePtr<ProjectTreeModel>>
 | 
			
		||||
buildProjectTreeModel(ProjectExplorer &explorer, ox::StringView name, ox::CRStringView path, ProjectTreeModel *parent) noexcept {
 | 
			
		||||
static ox::Result<ox::UniquePtr<ProjectTreeModel>> 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<ProjectTreeModel>(explorer, ox::String(name), parent);
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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<studio::Project> 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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user