[nostalgia/core/studio] Cleanup context types

This commit is contained in:
Gary Talent 2024-04-21 10:24:29 -05:00
parent 189ba4c545
commit 453f2750dd
6 changed files with 30 additions and 27 deletions

View File

@ -75,10 +75,11 @@ static ox::Error toPngFile(
8))); 8)));
} }
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path): TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path):
Editor(path), Editor(path),
m_ctx(ctx.tctx), m_sctx(sctx),
m_view(m_ctx, path, *undoStack()), m_tctx(sctx.tctx),
m_view(m_sctx, path, *undoStack()),
m_model(m_view.model()) { m_model(m_view.model()) {
oxIgnoreError(setPaletteSelection()); oxIgnoreError(setPaletteSelection());
// connect signal/slots // connect signal/slots
@ -134,7 +135,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
setPasteEnabled(false); setPasteEnabled(false);
m_model.clearSelection(); m_model.clearSelection();
} else if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) { } 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<std::size_t>( auto const idx = ox::min<std::size_t>(
static_cast<uint32_t>(key - turbine::Key::Num_1), m_model.pal().pages.size() - 1); static_cast<uint32_t>(key - turbine::Key::Num_1), m_model.pal().pages.size() - 1);
m_model.setPalettePage(idx); m_model.setPalettePage(idx);
@ -143,7 +144,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
m_view.setPalIdx(idx); m_view.setPalIdx(idx);
} }
} else if (key == turbine::Key::Num_0) { } 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<std::size_t>( auto const idx = ox::min<std::size_t>(
static_cast<uint32_t>(key - turbine::Key::Num_1 + 9), m_model.pal().pages.size() - 1); static_cast<uint32_t>(key - turbine::Key::Num_1 + 9), m_model.pal().pages.size() - 1);
m_model.setPalettePage(idx); m_model.setPalettePage(idx);
@ -235,8 +236,8 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept {
ImGui::EndChild(); ImGui::EndChild();
} }
ImGui::EndChild(); ImGui::EndChild();
m_subsheetEditor.draw(m_ctx); m_subsheetEditor.draw(m_tctx);
m_exportMenu.draw(m_ctx); m_exportMenu.draw(m_tctx);
} }
void TileSheetEditorImGui::drawSubsheetSelector( void TileSheetEditorImGui::drawSubsheetSelector(
@ -341,13 +342,14 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
} else if (m_view.updated()) { } else if (m_view.updated()) {
m_view.ackUpdate(); m_view.ackUpdate();
} }
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer); {
glutils::FrameBufferBind const frameBufferBind(m_framebuffer);
// clear screen and draw // clear screen and draw
glViewport(0, 0, fbSizei.width, fbSizei.height); glViewport(0, 0, fbSizei.width, fbSizei.height);
m_view.draw(); m_view.draw();
glBindFramebuffer(GL_FRAMEBUFFER, 0); }
ImGui::Image( ImGui::Image(
std::bit_cast<ImTextureID>(uintptr_t{m_framebuffer.color.id}), ig::toImTextureID(m_framebuffer.color.id),
static_cast<ImVec2>(fbSize), static_cast<ImVec2>(fbSize),
ImVec2(0, 1), ImVec2(0, 1),
ImVec2(1, 0)); ImVec2(1, 0));
@ -359,7 +361,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
auto const wheelh = io.MouseWheelH; auto const wheelh = io.MouseWheelH;
if (wheel != 0) { if (wheel != 0) {
const auto zoomMod = ox::defines::OS == ox::OS::Darwin ? 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); m_view.scrollV(fbSize, wheel, zoomMod);
} }
if (wheelh != 0) { if (wheelh != 0) {
@ -399,8 +401,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
} }
void TileSheetEditorImGui::drawPaletteSelector() noexcept { void TileSheetEditorImGui::drawPaletteSelector() noexcept {
auto &sctx = *applicationData<studio::StudioContext>(m_ctx); auto const&files = m_sctx.project->fileList(core::FileExt_npal);
auto const&files = sctx.project->fileList(core::FileExt_npal);
auto const comboWidthSub = 62; auto const comboWidthSub = 62;
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub);
if (ig::ComboBox("Palette", files, m_selectedPaletteIdx)) { if (ig::ComboBox("Palette", files, m_selectedPaletteIdx)) {
@ -465,8 +466,7 @@ ox::Error TileSheetEditorImGui::updateActiveSubsheet(ox::StringView const&name,
ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept { ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept {
auto const&palPath = m_model.palPath(); auto const&palPath = m_model.palPath();
auto &sctx = *applicationData<studio::StudioContext>(m_ctx); auto const&palList = m_sctx.project->fileList(core::FileExt_npal);
auto const&palList = sctx.project->fileList(core::FileExt_npal);
for (std::size_t i = 0; auto const&pal : palList) { for (std::size_t i = 0; auto const&pal : palList) {
if (palPath == pal) { if (palPath == pal) {
m_selectedPaletteIdx = i; m_selectedPaletteIdx = i;

View File

@ -61,7 +61,8 @@ class TileSheetEditorImGui: public studio::Editor {
inline bool isOpen() const noexcept { return m_show; } inline bool isOpen() const noexcept { return m_show; }
}; };
std::size_t m_selectedPaletteIdx = 0; std::size_t m_selectedPaletteIdx = 0;
turbine::Context &m_ctx; studio::StudioContext &m_sctx;
turbine::Context &m_tctx;
ox::Vector<ox::String> m_paletteList; ox::Vector<ox::String> m_paletteList;
SubSheetEditor m_subsheetEditor; SubSheetEditor m_subsheetEditor;
ExportMenu m_exportMenu; ExportMenu m_exportMenu;
@ -73,7 +74,7 @@ class TileSheetEditorImGui: public studio::Editor {
Tool m_tool = Tool::Draw; Tool m_tool = Tool::Draw;
public: public:
TileSheetEditorImGui(studio::StudioContext &ctx, ox::CRStringView path); TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path);
~TileSheetEditorImGui() override = default; ~TileSheetEditorImGui() override = default;

View File

@ -41,8 +41,9 @@ static void normalizeSubsheets(TileSheet::SubSheet &ss) noexcept {
} }
} }
TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack): TileSheetEditorModel::TileSheetEditorModel(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack):
m_ctx(ctx), m_sctx(sctx),
m_ctx(m_sctx.tctx),
m_path(path), m_path(path),
m_img(*readObj<TileSheet>(keelCtx(m_ctx), m_path).unwrapThrow()), m_img(*readObj<TileSheet>(keelCtx(m_ctx), m_path).unwrapThrow()),
// ignore failure to load palette // ignore failure to load palette
@ -261,8 +262,7 @@ void TileSheetEditorModel::ackUpdate() noexcept {
} }
ox::Error TileSheetEditorModel::saveFile() noexcept { ox::Error TileSheetEditorModel::saveFile() noexcept {
const auto sctx = applicationData<studio::StudioContext>(m_ctx); return m_sctx.project->writeObj(m_path, m_img, ox::ClawFormat::Metal);
return sctx->project->writeObj(m_path, m_img, ox::ClawFormat::Metal);
} }
bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept { bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept {

View File

@ -24,6 +24,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
private: private:
static Palette const s_defaultPalette; static Palette const s_defaultPalette;
studio::StudioContext &m_sctx;
turbine::Context &m_ctx; turbine::Context &m_ctx;
ox::String m_path; ox::String m_path;
TileSheet m_img; TileSheet m_img;
@ -38,7 +39,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}}; ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}};
public: public:
TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack); TileSheetEditorModel(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack);
~TileSheetEditorModel() override = default; ~TileSheetEditorModel() override = default;

View File

@ -11,9 +11,10 @@
namespace nostalgia::core { 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_model(ctx, path, undoStack),
m_pixelsDrawer(m_model) { m_pixelsDrawer(m_model) {
glBindVertexArray(0);
// build shaders // build shaders
oxThrowError(m_pixelsDrawer.buildShader()); oxThrowError(m_pixelsDrawer.buildShader());
oxThrowError(m_pixelGridDrawer.buildShader()); oxThrowError(m_pixelGridDrawer.buildShader());

View File

@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler {
std::size_t m_palIdx = 0; std::size_t m_palIdx = 0;
public: public:
TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack); TileSheetEditorView(studio::StudioContext &ctx, ox::StringView path, studio::UndoStack &undoStack);
~TileSheetEditorView() override = default; ~TileSheetEditorView() override = default;