[nostalgia,olympic] Further reduce use of applicationData

This commit is contained in:
Gary Talent 2024-03-23 16:07:49 -05:00
parent a4f0c7cdb5
commit 27f1df8f33
20 changed files with 62 additions and 60 deletions

View File

@ -42,7 +42,7 @@ void PaletteEditorImGui::keyStateChanged(turbine::Key key, bool down) {
}
void PaletteEditorImGui::draw(turbine::Context&) noexcept {
void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
auto const paneSize = ImGui::GetContentRegionAvail();
{
ImGui::BeginChild("Pages", ImVec2(250, paneSize.y), true);

View File

@ -25,7 +25,7 @@ class PaletteEditorImGui: public studio::Editor {
void keyStateChanged(turbine::Key key, bool down) override;
void draw(turbine::Context&) noexcept final;
void draw(studio::StudioContext&) noexcept final;
protected:
ox::Error saveItem() noexcept final;

View File

@ -157,7 +157,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
}
}
void TileSheetEditorImGui::draw(turbine::Context&) noexcept {
void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
auto const paneSize = ImGui::GetContentRegionAvail();
auto const tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y);
auto const fbSize = ox::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16);
@ -237,7 +237,7 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept {
}
ImGui::EndChild();
m_subsheetEditor.draw(m_tctx);
m_exportMenu.draw(m_tctx);
m_exportMenu.draw(m_sctx);
}
void TileSheetEditorImGui::drawSubsheetSelector(
@ -481,7 +481,7 @@ ox::Error TileSheetEditorImGui::markUnsavedChanges(studio::UndoCommand const*) n
return {};
}
void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &ctx) noexcept {
void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &sctx) noexcept {
constexpr auto popupName = "Edit Subsheet";
if (!m_show) {
return;
@ -490,7 +490,7 @@ void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &ctx) noexcept
auto constexpr popupWidth = 235.f;
auto const popupHeight = modSize ? 130.f : 85.f;
auto const popupSz = ImVec2(popupWidth, popupHeight);
if (ig::BeginPopup(ctx, popupName, m_show, popupSz)) {
if (ig::BeginPopup(sctx, popupName, m_show, popupSz)) {
ImGui::InputText("Name", m_name.data(), m_name.cap());
if (modSize) {
ImGui::InputInt("Columns", &m_cols);
@ -507,7 +507,7 @@ void TileSheetEditorImGui::SubSheetEditor::close() noexcept {
m_show = false;
}
void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &ctx) noexcept {
void TileSheetEditorImGui::ExportMenu::draw(studio::StudioContext &sctx) noexcept {
constexpr auto popupName = "Export Tile Sheet";
if (!m_show) {
return;
@ -515,7 +515,7 @@ void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &ctx) noexcept {
constexpr auto popupWidth = 235.f;
constexpr auto popupHeight = 85.f;
constexpr auto popupSz = ImVec2(popupWidth, popupHeight);
if (ig::BeginPopup(ctx, popupName, m_show, popupSz)) {
if (ig::BeginPopup(sctx.tctx, popupName, m_show, popupSz)) {
ImGui::InputInt("Scale", &m_scale);
m_scale = ox::clamp(m_scale, 1, 50);
if (ig::PopupControlsOkCancel(popupWidth, m_show) == ig::PopupResponse::OK) {

View File

@ -40,7 +40,7 @@ class TileSheetEditorImGui: public studio::Editor {
m_cols = cols;
m_rows = rows;
}
void draw(turbine::Context &ctx) noexcept;
void draw(turbine::Context &sctx) noexcept;
void close() noexcept;
[[nodiscard]]
inline bool isOpen() const noexcept { return m_show; }
@ -55,7 +55,7 @@ class TileSheetEditorImGui: public studio::Editor {
m_show = true;
m_scale = 5;
}
void draw(turbine::Context &ctx) noexcept;
void draw(studio::StudioContext &sctx) noexcept;
void close() noexcept;
[[nodiscard]]
inline bool isOpen() const noexcept { return m_show; }
@ -88,7 +88,7 @@ class TileSheetEditorImGui: public studio::Editor {
void keyStateChanged(turbine::Key key, bool down) override;
void draw(turbine::Context&) noexcept override;
void draw(studio::StudioContext&) noexcept override;
void drawSubsheetSelector(TileSheet::SubSheet&, TileSheet::SubSheetIdx &path);

View File

@ -18,7 +18,7 @@ SceneEditorImGui::SceneEditorImGui(studio::StudioContext &ctx, ox::StringView pa
setRequiresConstantRefresh(false);
}
void SceneEditorImGui::draw(turbine::Context&) noexcept {
void SceneEditorImGui::draw(studio::StudioContext&) noexcept {
auto const paneSize = ImGui::GetContentRegionAvail();
m_view.draw(ox::Size{static_cast<int>(paneSize.x), static_cast<int>(paneSize.y)});
auto &fb = m_view.framebuffer();

View File

@ -23,7 +23,7 @@ class SceneEditorImGui: public studio::Editor {
public:
SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path);
void draw(turbine::Context&) noexcept final;
void draw(studio::StudioContext&) noexcept final;
void onActivated() noexcept override;

View File

@ -29,7 +29,7 @@ bool AboutPopup::isOpen() const noexcept {
return m_stage == Stage::Open;
}
void AboutPopup::draw(turbine::Context &ctx) noexcept {
void AboutPopup::draw(studio::StudioContext &sctx) noexcept {
switch (m_stage) {
case Stage::Closed:
break;
@ -41,7 +41,7 @@ void AboutPopup::draw(turbine::Context &ctx) noexcept {
constexpr auto modalFlags =
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
ImGui::SetNextWindowSize(ImVec2(215, 90));
studio::ig::centerNextWindow(ctx);
studio::ig::centerNextWindow(sctx.tctx);
auto open = true;
if (ImGui::BeginPopupModal("About", &open, modalFlags)) {
ImGui::Text("%s", m_text.c_str());

View File

@ -35,7 +35,7 @@ class AboutPopup: public studio::Popup {
[[nodiscard]]
bool isOpen() const noexcept override;
void draw(turbine::Context &ctx) noexcept override;
void draw(studio::StudioContext &sctx) noexcept override;
};

View File

@ -13,7 +13,7 @@ ClawEditor::ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept:
m_obj(std::move(obj)) {
}
void ClawEditor::draw(turbine::Context&) noexcept {
void ClawEditor::draw(studio::StudioContext&) noexcept {
ImGui::BeginChild("PaletteEditor");
static constexpr auto flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody;
if (ImGui::BeginTable("ObjTree", 3, flags)) {

View File

@ -18,7 +18,7 @@ class ClawEditor: public studio::Editor {
public:
ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept;
void draw(turbine::Context&) noexcept final;
void draw(studio::StudioContext&) noexcept final;
private:
static void drawRow(ox::ModelValue const&value) noexcept;

View File

@ -33,7 +33,7 @@ bool NewMenu::isOpen() const noexcept {
return m_open;
}
void NewMenu::draw(turbine::Context &ctx) noexcept {
void NewMenu::draw(studio::StudioContext &sctx) noexcept {
switch (m_stage) {
case Stage::Opening:
ImGui::OpenPopup(title().c_str());
@ -41,10 +41,10 @@ void NewMenu::draw(turbine::Context &ctx) noexcept {
m_open = true;
[[fallthrough]];
case Stage::NewItemType:
drawNewItemType(ctx);
drawNewItemType(sctx);
break;
case Stage::NewItemName:
drawNewItemName(ctx);
drawNewItemName(sctx);
break;
case Stage::Closed:
m_open = false;
@ -61,8 +61,8 @@ void NewMenu::addItemMaker(ox::UniquePtr<studio::ItemMaker> &&im) noexcept {
});
}
void NewMenu::drawNewItemType(turbine::Context &ctx) noexcept {
drawWindow(ctx, &m_open, [this] {
void NewMenu::drawNewItemType(studio::StudioContext &sctx) noexcept {
drawWindow(sctx.tctx, &m_open, [this] {
auto items = ox_malloca(m_types.size() * sizeof(char const*), char const*, nullptr);
for (auto i = 0u; auto const&im : m_types) {
items.get()[i] = im->typeName.c_str();
@ -73,13 +73,13 @@ void NewMenu::drawNewItemType(turbine::Context &ctx) noexcept {
});
}
void NewMenu::drawNewItemName(turbine::Context &ctx) noexcept {
drawWindow(ctx, &m_open, [this, &ctx] {
void NewMenu::drawNewItemName(studio::StudioContext &sctx) noexcept {
drawWindow(sctx.tctx, &m_open, [this, &sctx] {
auto const typeIdx = static_cast<std::size_t>(m_selectedType);
if (typeIdx < m_types.size()) {
ImGui::InputText("Name", m_itemName.data(), m_itemName.cap());
}
drawLastPageButtons(ctx);
drawLastPageButtons(sctx);
});
}
@ -97,7 +97,7 @@ void NewMenu::drawFirstPageButtons() noexcept {
}
}
void NewMenu::drawLastPageButtons(turbine::Context &ctx) noexcept {
void NewMenu::drawLastPageButtons(studio::StudioContext &sctx) noexcept {
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 138);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
if (ImGui::Button("Back")) {
@ -105,7 +105,7 @@ void NewMenu::drawLastPageButtons(turbine::Context &ctx) noexcept {
}
ImGui::SameLine();
if (ImGui::Button("Finish")) {
finish(ctx);
finish(sctx);
}
ImGui::SameLine();
if (ImGui::Button("Quit")) {
@ -114,17 +114,16 @@ void NewMenu::drawLastPageButtons(turbine::Context &ctx) noexcept {
}
}
void NewMenu::finish(turbine::Context &ctx) noexcept {
void NewMenu::finish(studio::StudioContext &sctx) noexcept {
if (m_itemName.len() == 0) {
return;
}
auto const sctx = turbine::applicationData<studio::StudioContext>(ctx);
auto const&typeMaker = *m_types[static_cast<std::size_t>(m_selectedType)];
if (sctx->project->exists(typeMaker.itemPath(m_itemName))) {
if (sctx.project->exists(typeMaker.itemPath(m_itemName))) {
oxLogError(OxError(1, "New file error: File already exists"));
return;
}
auto const [path, err] = typeMaker.write(ctx, m_itemName);
auto const [path, err] = typeMaker.write(sctx, m_itemName);
if (err) {
oxLogError(err);
return;

View File

@ -43,7 +43,7 @@ class NewMenu: public studio::Popup {
[[nodiscard]]
bool isOpen() const noexcept override;
void draw(turbine::Context &ctx) noexcept override;
void draw(studio::StudioContext &sctx) noexcept override;
template<typename T>
void addItemType(ox::String name, ox::String parentDir, ox::String fileExt, T itemTempl, ox::ClawFormat pFmt = ox::ClawFormat::Metal) noexcept;
@ -54,15 +54,15 @@ class NewMenu: public studio::Popup {
void addItemMaker(ox::UniquePtr<studio::ItemMaker> &&im) noexcept;
private:
void drawNewItemType(turbine::Context &ctx) noexcept;
void drawNewItemType(studio::StudioContext &sctx) noexcept;
void drawNewItemName(turbine::Context &ctx) noexcept;
void drawNewItemName(studio::StudioContext &sctx) noexcept;
void drawFirstPageButtons() noexcept;
void drawLastPageButtons(turbine::Context &ctx) noexcept;
void drawLastPageButtons(studio::StudioContext &sctx) noexcept;
void finish(turbine::Context &ctx) noexcept;
void finish(studio::StudioContext &sctx) noexcept;
};

View File

@ -32,7 +32,7 @@ bool NewProject::isOpen() const noexcept {
return m_open;
}
void NewProject::draw(turbine::Context &ctx) noexcept {
void NewProject::draw(studio::StudioContext &ctx) noexcept {
switch (m_stage) {
case Stage::Opening:
ImGui::OpenPopup(title().c_str());
@ -48,14 +48,14 @@ void NewProject::draw(turbine::Context &ctx) noexcept {
}
}
void NewProject::drawNewProjectName(turbine::Context &ctx) noexcept {
drawWindow(ctx, &m_open, [this, &ctx] {
void NewProject::drawNewProjectName(studio::StudioContext &sctx) noexcept {
drawWindow(sctx.tctx, &m_open, [this, &sctx] {
ImGui::InputText("Name", m_projectName.data(), m_projectName.cap());
ImGui::Text("Path: %s", m_projectPath.c_str());
if (ImGui::Button("Browse")) {
oxLogError(studio::chooseDirectory().moveTo(m_projectPath));
}
drawLastPageButtons(ctx);
drawLastPageButtons(sctx);
});
}
@ -73,7 +73,7 @@ void NewProject::drawFirstPageButtons() noexcept {
}
}
void NewProject::drawLastPageButtons(turbine::Context&) noexcept {
void NewProject::drawLastPageButtons(studio::StudioContext&) noexcept {
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 95);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
if (ImGui::Button("Finish")) {

View File

@ -42,14 +42,14 @@ class NewProject: public studio::Popup {
[[nodiscard]]
bool isOpen() const noexcept override;
void draw(turbine::Context &ctx) noexcept override;
void draw(studio::StudioContext &ctx) noexcept override;
private:
void drawNewProjectName(turbine::Context &ctx) noexcept;
void drawNewProjectName(studio::StudioContext &ctx) noexcept;
void drawFirstPageButtons() noexcept;
void drawLastPageButtons(turbine::Context &ctx) noexcept;
void drawLastPageButtons(studio::StudioContext &ctx) noexcept;
void finish() noexcept;

View File

@ -37,12 +37,12 @@ static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
ProjectExplorer::ProjectExplorer(turbine::Context &ctx) noexcept: m_ctx(ctx) {
}
void ProjectExplorer::draw(turbine::Context &ctx) noexcept {
void ProjectExplorer::draw(studio::StudioContext &ctx) noexcept {
auto const viewport = ImGui::GetContentRegionAvail();
ImGui::BeginChild("ProjectExplorer", ImVec2(300, viewport.y), true);
ImGui::SetNextItemOpen(true);
if (m_treeModel) {
m_treeModel->draw(ctx);
m_treeModel->draw(ctx.tctx);
}
ImGui::EndChild();
}

View File

@ -19,7 +19,7 @@ class ProjectExplorer: public studio::Widget {
public:
explicit ProjectExplorer(turbine::Context &ctx) noexcept;
void draw(turbine::Context &ctx) noexcept override;
void draw(studio::StudioContext &ctx) noexcept override;
void setModel(ox::UPtr<ProjectTreeModel> &&model) noexcept;

View File

@ -159,15 +159,15 @@ void StudioUI::draw() noexcept {
ImGui::Begin("MainWindow##Studio", nullptr, windowFlags);
{
if (m_showProjectExplorer) {
m_projectExplorer.draw(m_ctx);
m_projectExplorer.draw(m_sctx);
ImGui::SameLine();
}
drawTabBar();
for (auto &w: m_widgets) {
w->draw(m_ctx);
w->draw(m_sctx);
}
for (auto p: m_popups) {
p->draw(m_ctx);
p->draw(m_sctx);
}
}
ImGui::End();
@ -261,7 +261,7 @@ void StudioUI::drawTabs() noexcept {
m_activeEditor->onActivated();
turbine::setConstantRefresh(m_ctx, m_activeEditor->requiresConstantRefresh());
}
e->draw(m_ctx);
e->draw(m_sctx);
m_activeEditorOnLastDraw = e.get();
ImGui::EndTabItem();
}

View File

@ -18,7 +18,8 @@ class ItemMaker {
ox::String const typeName;
ox::String const parentDir;
ox::String const fileExt;
constexpr explicit ItemMaker(ox::StringView pName, ox::StringView pParentDir, ox::CRStringView pFileExt) noexcept:
constexpr explicit ItemMaker(
ox::StringView pName, ox::StringView pParentDir, ox::CRStringView pFileExt) noexcept:
typeName(pName),
parentDir(pParentDir),
fileExt(pFileExt) {
@ -36,7 +37,8 @@ class ItemMaker {
* @param pName
* @return path of file or error in Result
*/
virtual ox::Result<ox::String> write(turbine::Context &ctx, ox::CRStringView pName) const noexcept = 0;
virtual ox::Result<ox::String> write(
studio::StudioContext &ctx, ox::CRStringView pName) const noexcept = 0;
};
template<typename T>
@ -73,11 +75,10 @@ class ItemMakerT: public ItemMaker {
m_item(std::move(pItem)),
m_fmt(pFmt) {
}
ox::Result<ox::String> write(turbine::Context &ctx, ox::CRStringView pName) const noexcept override {
ox::Result<ox::String> write(studio::StudioContext &sctx, ox::CRStringView pName) const noexcept override {
auto const path = itemPath(pName);
auto const sctx = turbine::applicationData<studio::StudioContext>(ctx);
keel::createUuidMapping(keelCtx(ctx), path, ox::UUID::generate().unwrap());
oxReturnError(sctx->project->writeObj(path, m_item, m_fmt));
keel::createUuidMapping(keelCtx(sctx.tctx), path, ox::UUID::generate().unwrap());
oxReturnError(sctx.project->writeObj(path, m_item, m_fmt));
return path;
}
};

View File

@ -32,7 +32,7 @@ class Popup {
[[nodiscard]]
virtual bool isOpen() const noexcept = 0;
virtual void draw(turbine::Context &ctx) noexcept = 0;
virtual void draw(studio::StudioContext &ctx) noexcept = 0;
protected:
constexpr void setSize(ox::Size sz) noexcept {

View File

@ -8,12 +8,14 @@
#include <turbine/context.hpp>
#include "context.hpp"
namespace studio {
class Widget: public ox::SignalHandler {
public:
~Widget() noexcept override = default;
virtual void draw(turbine::Context&) noexcept = 0;
virtual void draw(studio::StudioContext&) noexcept = 0;
};
}