Merge commit 'ce53be92716b0f5201882d6959c398b61c6cc93c'
This commit is contained in:
@@ -238,7 +238,7 @@ uint_t spriteCount(Context &ctx) noexcept;
|
||||
|
||||
ox::Error initConsole(Context &ctx) noexcept;
|
||||
|
||||
void puts(Context &ctx, int column, int row, ox::StringViewCR str) noexcept;
|
||||
void consoleWrite(Context &ctx, int column, int row, ox::StringViewCR str) noexcept;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -36,13 +36,13 @@ OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
setBgStatus(*ctx, 0, true);
|
||||
clearBg(*ctx, 0);
|
||||
auto const serr = ox::sfmt<ox::IString<23>>("Error code: {}", static_cast<int64_t>(err));
|
||||
puts(*ctx, 32 + 1, 1, "SADNESS...");
|
||||
puts(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||
puts(*ctx, 32 + 2, 6, panicMsg);
|
||||
consoleWrite(*ctx, 32 + 1, 1, "SADNESS...");
|
||||
consoleWrite(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||
consoleWrite(*ctx, 32 + 2, 6, panicMsg);
|
||||
if (err) {
|
||||
puts(*ctx, 32 + 2, 8, serr);
|
||||
consoleWrite(*ctx, 32 + 2, 8, serr);
|
||||
}
|
||||
puts(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||
consoleWrite(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||
// print to terminal if in mGBA
|
||||
oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg);
|
||||
if (err.msg) {
|
||||
|
||||
@@ -251,7 +251,7 @@ ox::Error initConsole(Context &ctx) noexcept {
|
||||
return loadBgPalette(ctx, 0, PaletteAddr);
|
||||
}
|
||||
|
||||
void puts(
|
||||
void consoleWrite(
|
||||
Context &ctx,
|
||||
int const column,
|
||||
int const row,
|
||||
|
||||
@@ -50,22 +50,25 @@ void PaletteEditorImGui::PageRenameDialog::draw(turbine::Context &tctx) noexcept
|
||||
return;
|
||||
}
|
||||
if (ig::BeginPopup(tctx, "Rename Page", m_show)) {
|
||||
if (ImGui::IsWindowAppearing()) {
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
}
|
||||
ig::InputText("Name", m_name);
|
||||
switch (ig::PopupControlsOkCancel(m_show)) {
|
||||
case ig::PopupResponse::OK:
|
||||
inputSubmitted.emit(m_name);
|
||||
[[fallthrough]];
|
||||
case ig::PopupResponse::Cancel:
|
||||
close();
|
||||
default:
|
||||
break;
|
||||
auto const nameInputFocused = ImGui::IsItemFocused();
|
||||
auto const resp = ig::PopupControlsOkCancel(m_show);
|
||||
if ((nameInputFocused && ImGui::IsKeyPressed(ImGuiKey_Enter))
|
||||
|| resp == ig::PopupResponse::OK) {
|
||||
inputSubmitted.emit(m_name);
|
||||
close();
|
||||
} else if (resp == ig::PopupResponse::Cancel) {
|
||||
close();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
|
||||
PaletteEditorImGui::PaletteEditorImGui(studio::Context &sctx, ox::StringParam path):
|
||||
Editor(sctx, std::move(path)),
|
||||
m_sctx(sctx),
|
||||
m_tctx(sctx.tctx),
|
||||
@@ -74,7 +77,7 @@ PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringPa
|
||||
m_pageRenameDlg.inputSubmitted.connect(this, &PaletteEditorImGui::renamePage);
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
void PaletteEditorImGui::draw(studio::Context&) noexcept {
|
||||
auto const paneSize = ImGui::GetContentRegionAvail();
|
||||
{
|
||||
ImGui::BeginChild("Pages", {280, paneSize.y}, true);
|
||||
@@ -102,13 +105,13 @@ void PaletteEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
|
||||
auto const &color = args[0];
|
||||
auto const &page = args[1];
|
||||
{
|
||||
auto const [c, err] = atoi(color);
|
||||
auto const [c, err] = strToInt(color);
|
||||
if (!err && static_cast<size_t>(c) < colorCnt(m_pal)) {
|
||||
m_selectedColorRow = static_cast<size_t>(c);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto const [pg, err] = atoi(page);
|
||||
auto const [pg, err] = strToInt(page);
|
||||
if (!err && static_cast<size_t>(pg) < m_pal.pages.size()) {
|
||||
m_page = static_cast<size_t>(pg);
|
||||
}
|
||||
@@ -131,7 +134,7 @@ void PaletteEditorImGui::numShortcuts(size_t &val, size_t const sizeRange) noexc
|
||||
auto const lastElem = sizeRange - 1;
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_0)) {
|
||||
val = ox::min<size_t>(9, lastElem);
|
||||
} else for (auto i = 9u; i < 10; --i) {
|
||||
} else for (auto i = 8u; i < 9; --i) {
|
||||
auto const key = static_cast<ImGuiKey>(ImGuiKey_1 + i);
|
||||
if (ImGui::IsKeyPressed(key)) {
|
||||
val = ox::min<size_t>(i, lastElem);
|
||||
|
||||
@@ -31,16 +31,16 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
constexpr bool isOpen() const noexcept { return m_show; }
|
||||
void draw(turbine::Context &tctx) noexcept;
|
||||
} m_pageRenameDlg;
|
||||
studio::StudioContext &m_sctx;
|
||||
studio::Context &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
Palette m_pal;
|
||||
size_t m_selectedColorRow = 0;
|
||||
size_t m_page = 0;
|
||||
|
||||
public:
|
||||
PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path);
|
||||
PaletteEditorImGui(studio::Context &sctx, ox::StringParam path);
|
||||
|
||||
void draw(studio::StudioContext&) noexcept final;
|
||||
void draw(studio::Context&) noexcept final;
|
||||
|
||||
protected:
|
||||
ox::Error saveItem() noexcept final;
|
||||
@@ -53,7 +53,7 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
static void drawColumn(ox::CStringView txt) noexcept;
|
||||
|
||||
static void drawColumn(ox::Integer_c auto i) noexcept {
|
||||
drawColumn(ox::itoa(i));
|
||||
drawColumn(ox::intToStr(i));
|
||||
}
|
||||
|
||||
static void numShortcuts(size_t &val, size_t sizeRange) noexcept;
|
||||
|
||||
@@ -12,15 +12,15 @@
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
static class: public studio::Module {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::StudioContext &ctx) const noexcept final {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::Context &ctx) const noexcept final {
|
||||
return {
|
||||
studio::editorMaker<TileSheetEditorImGui>(ctx, {FileExt_ng, FileExt_nts}),
|
||||
studio::editorMaker<PaletteEditorImGui>(ctx, FileExt_npal),
|
||||
};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::StudioContext&) const noexcept final {
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::Context&) const noexcept final {
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<TileSheet>>("Tile Sheet", "TileSheets", FileExt_nts));
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<Palette>>("Palette", "Palettes", FileExt_npal, Palette{
|
||||
.colorNames = {},
|
||||
|
||||
@@ -35,8 +35,10 @@ ox::Error gfx::DeleteTilesCommand::redo() noexcept {
|
||||
auto const src = &p[srcPos];
|
||||
auto const dst1 = &p[m_deletePos];
|
||||
auto const dst2 = &p[(p.size() - m_deleteSz)];
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memmove(dst1, src, p.size() - srcPos);
|
||||
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -47,8 +49,10 @@ ox::Error DeleteTilesCommand::undo() noexcept {
|
||||
auto const dst1 = &p[m_deletePos + m_deleteSz];
|
||||
auto const dst2 = src;
|
||||
auto const sz = p.size() - m_deletePos - m_deleteSz;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memmove(dst1, src, sz);
|
||||
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ InsertTilesCommand::InsertTilesCommand(
|
||||
}
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
ox::Error InsertTilesCommand::redo() noexcept {
|
||||
auto &s = getSubSheet(m_img, m_idx);
|
||||
auto &p = s.pixels;
|
||||
@@ -55,6 +57,8 @@ ox::Error InsertTilesCommand::undo() noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
int InsertTilesCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::InsertTile);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ static ox::Error toPngFile(
|
||||
8)));
|
||||
}
|
||||
|
||||
TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path):
|
||||
TileSheetEditorImGui::TileSheetEditorImGui(studio::Context &sctx, ox::StringParam path):
|
||||
Editor(sctx, std::move(path)),
|
||||
m_sctx{sctx},
|
||||
m_tctx{m_sctx.tctx},
|
||||
@@ -129,7 +129,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const do
|
||||
if (!down) {
|
||||
return;
|
||||
}
|
||||
if (key == turbine::Key::Escape) {
|
||||
if (ig::mainWinHasFocus() && key == turbine::Key::Escape) {
|
||||
m_subsheetEditor.close();
|
||||
m_exportMenu.close();
|
||||
m_palPicker.close();
|
||||
@@ -188,7 +188,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key const key, bool const do
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
void TileSheetEditorImGui::draw(studio::Context&) noexcept {
|
||||
if (ig::mainWinHasFocus() && m_tool == TileSheetTool::Select) {
|
||||
if (ImGui::IsKeyDown(ImGuiKey_ModCtrl) && !m_palPathFocused) {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_A)) {
|
||||
@@ -549,7 +549,7 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
|
||||
ImGui::PushID(static_cast<int>(i));
|
||||
// Column: color idx
|
||||
ImGui::TableNextColumn();
|
||||
auto const label = ox::itoa(i + 1);
|
||||
auto const label = ox::intToStr(i + 1);
|
||||
auto const rowSelected = i == m_view.palIdx();
|
||||
if (ImGui::Selectable(
|
||||
label.c_str(), rowSelected, ImGuiSelectableFlags_SpanAllColumns)) {
|
||||
|
||||
@@ -45,7 +45,7 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
constexpr bool isOpen() const noexcept { return m_show; }
|
||||
};
|
||||
static constexpr float s_palViewWidth = 335;
|
||||
studio::StudioContext &m_sctx;
|
||||
studio::Context &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
ox::Vector<ox::String> m_paletteList;
|
||||
SubSheetEditor m_subsheetEditor;
|
||||
@@ -60,7 +60,7 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
ox::Vector<ox::UPtr<studio::UndoCommand>, 1> m_deferredCmds;
|
||||
|
||||
public:
|
||||
TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path);
|
||||
TileSheetEditorImGui(studio::Context &sctx, ox::StringParam path);
|
||||
|
||||
~TileSheetEditorImGui() override = default;
|
||||
|
||||
@@ -77,7 +77,7 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
|
||||
void keyStateChanged(turbine::Key key, bool down) override;
|
||||
|
||||
void draw(studio::StudioContext&) noexcept override;
|
||||
void draw(studio::Context&) noexcept override;
|
||||
|
||||
void drawSubsheetSelector(TileSheet::SubSheet&, TileSheet::SubSheetIdx &path);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ Palette const TileSheetEditorModel::s_defaultPalette = {
|
||||
};
|
||||
|
||||
TileSheetEditorModel::TileSheetEditorModel(
|
||||
studio::StudioContext &sctx, ox::StringParam path, studio::UndoStack &undoStack):
|
||||
studio::Context &sctx, ox::StringParam path, studio::UndoStack &undoStack):
|
||||
m_sctx(sctx),
|
||||
m_tctx(m_sctx.tctx),
|
||||
m_path(std::move(path)),
|
||||
|
||||
@@ -22,7 +22,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
|
||||
private:
|
||||
static Palette const s_defaultPalette;
|
||||
studio::StudioContext &m_sctx;
|
||||
studio::Context &m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
ox::String m_path;
|
||||
ox::String m_palPath;
|
||||
@@ -39,7 +39,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
bool m_updated = false;
|
||||
|
||||
public:
|
||||
TileSheetEditorModel(studio::StudioContext &sctx, ox::StringParam path, studio::UndoStack &undoStack);
|
||||
TileSheetEditorModel(studio::Context &sctx, ox::StringParam path, studio::UndoStack &undoStack);
|
||||
|
||||
~TileSheetEditorModel() override = default;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
TileSheetEditorView::TileSheetEditorView(
|
||||
studio::StudioContext &sctx, ox::StringViewCR path, studio::UndoStack &undoStack):
|
||||
studio::Context &sctx, ox::StringViewCR path, studio::UndoStack &undoStack):
|
||||
m_model(sctx, path, undoStack),
|
||||
m_pixelsDrawer(m_model) {
|
||||
glBindVertexArray(0);
|
||||
|
||||
@@ -56,7 +56,7 @@ class TileSheetEditorView: public ox::SignalHandler {
|
||||
std::size_t m_palIdx = 0;
|
||||
|
||||
public:
|
||||
TileSheetEditorView(studio::StudioContext &sctx, ox::StringViewCR path, studio::UndoStack &undoStack);
|
||||
TileSheetEditorView(studio::Context &sctx, ox::StringViewCR path, studio::UndoStack &undoStack);
|
||||
|
||||
~TileSheetEditorView() override = default;
|
||||
|
||||
|
||||
@@ -5,12 +5,13 @@
|
||||
#include <ox/claw/write.hpp>
|
||||
|
||||
#include <nostalgia/gfx/consts.hpp>
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
#include "tilesheetpixelgrid.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
void TileSheetGrid::setPixelSizeMod(float sm) noexcept {
|
||||
void TileSheetGrid::setPixelSizeMod(float const sm) noexcept {
|
||||
m_pixelSizeMod = sm;
|
||||
}
|
||||
|
||||
@@ -18,10 +19,11 @@ ox::Error TileSheetGrid::buildShader() noexcept {
|
||||
auto const pixelLineVshad = ox::sfmt(VShad, gl::GlslVersion);
|
||||
auto const pixelLineFshad = ox::sfmt(FShad, gl::GlslVersion);
|
||||
auto const pixelLineGshad = ox::sfmt(GShad, gl::GlslVersion);
|
||||
return glutils::buildShaderProgram(pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader);
|
||||
return glutils::buildShaderProgram(
|
||||
pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader);
|
||||
}
|
||||
|
||||
void TileSheetGrid::draw(bool update, ox::Vec2 const&scroll) noexcept {
|
||||
void TileSheetGrid::draw(bool const update, ox::Vec2 const&scroll) noexcept {
|
||||
// the lines just show up bigger on Windows for some reason
|
||||
if constexpr(ox::defines::OS == ox::OS::Windows) {
|
||||
glLineWidth(3 * m_pixelSizeMod * 0.25f);
|
||||
@@ -51,7 +53,8 @@ void TileSheetGrid::initBufferSet(ox::Vec2 const&paneSize, TileSheet::SubSheet c
|
||||
// vbo layout
|
||||
auto const pt1Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt1"));
|
||||
glEnableVertexAttribArray(pt1Attr);
|
||||
glVertexAttribPointer(pt1Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), nullptr);
|
||||
glVertexAttribPointer(
|
||||
pt1Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), nullptr);
|
||||
auto const pt2Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt2"));
|
||||
glEnableVertexAttribArray(pt2Attr);
|
||||
glVertexAttribPointer(pt2Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float),
|
||||
@@ -70,18 +73,18 @@ void TileSheetGrid::update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&su
|
||||
}
|
||||
|
||||
void TileSheetGrid::setBufferObject(
|
||||
ox::Point pt1,
|
||||
ox::Point pt2,
|
||||
Color32 c,
|
||||
float *vbo,
|
||||
ox::Point const pt1,
|
||||
ox::Point const pt2,
|
||||
Color32 const c,
|
||||
ox::Span<float> const vbo,
|
||||
ox::Vec2 const&pixSize) noexcept {
|
||||
auto const x1 = static_cast<float>(pt1.x) * pixSize.x - 1.f;
|
||||
auto const y1 = 1.f - static_cast<float>(pt1.y) * pixSize.y;
|
||||
auto const x2 = static_cast<float>(pt2.x) * pixSize.x - 1.f;
|
||||
auto const y2 = 1.f - static_cast<float>(pt2.y) * pixSize.y;
|
||||
// don't worry, this memcpy gets optimized to something much more ideal
|
||||
// don't worry, this gets optimized to something much more ideal
|
||||
ox::Array<float, VertexVboLength> const vertices = {x1, y1, x2, y2, redf(c), greenf(c), bluef(c)};
|
||||
memcpy(vbo, vertices.data(), sizeof(vertices));
|
||||
ox::spancpy(vbo, ox::SpanView<float>{vertices});
|
||||
}
|
||||
|
||||
void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept {
|
||||
@@ -92,7 +95,8 @@ void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubShee
|
||||
}
|
||||
auto const pixSize = pixelSize(paneSize);
|
||||
auto const set = [&](std::size_t i, ox::Point pt1, ox::Point pt2, Color32 c) {
|
||||
auto const vbo = &m_bufferSet.vertices[i * VertexVboLength];
|
||||
auto const idx = i * VertexVboLength;
|
||||
auto const vbo = ox::Span{m_bufferSet.vertices} + idx;
|
||||
setBufferObject(pt1, pt2, c, vbo, pixSize);
|
||||
};
|
||||
// set buffer length
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <glutils/glutils.hpp>
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
#include <nostalgia/gfx/tilesheet.hpp>
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
@@ -74,7 +73,7 @@ class TileSheetGrid {
|
||||
void update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;
|
||||
|
||||
private:
|
||||
static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, float *vbo, ox::Vec2 const&pixSize) noexcept;
|
||||
static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, ox::Span<float> vbo, ox::Vec2 const&pixSize) noexcept;
|
||||
|
||||
void setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <nostalgia/gfx/consts.hpp>
|
||||
#include <nostalgia/gfx/ptidxconv.hpp>
|
||||
#include "tilesheeteditormodel.hpp"
|
||||
#include "tilesheetpixels.hpp"
|
||||
|
||||
@@ -88,11 +86,11 @@ ox::Vec2 TileSheetPixels::pixelSize(ox::Vec2 const&paneSize) const noexcept {
|
||||
|
||||
void TileSheetPixels::setPixelBufferObject(
|
||||
ox::Vec2 const&paneSize,
|
||||
unsigned vertexRow,
|
||||
unsigned const vertexRow,
|
||||
float x, float y,
|
||||
Color16 color,
|
||||
float *vbo,
|
||||
GLuint *ebo) const noexcept {
|
||||
Color16 const color,
|
||||
ox::Span<float> const vbo,
|
||||
ox::Span<GLuint> const ebo) const noexcept {
|
||||
auto const [xmod, ymod] = pixelSize(paneSize);
|
||||
x *= xmod;
|
||||
y *= -ymod;
|
||||
@@ -106,12 +104,12 @@ void TileSheetPixels::setPixelBufferObject(
|
||||
x + xmod, y + ymod, r, g, b, // top right
|
||||
x, y + ymod, r, g, b, // top left
|
||||
};
|
||||
memcpy(vbo, vertices.data(), sizeof(vertices));
|
||||
ox::spancpy(vbo, ox::SpanView<float>{vertices});
|
||||
std::array const elms = {
|
||||
vertexRow + 0, vertexRow + 1, vertexRow + 2,
|
||||
vertexRow + 2, vertexRow + 3, vertexRow + 0,
|
||||
};
|
||||
memcpy(ebo, elms.data(), sizeof(elms));
|
||||
ox::spancpy(ebo, ox::SpanView<GLuint>{elms});
|
||||
}
|
||||
|
||||
void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
|
||||
@@ -137,8 +135,8 @@ void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
|
||||
auto const pt = idxToPt(static_cast<int>(i), subSheet.columns);
|
||||
auto const fx = static_cast<float>(pt.x);
|
||||
auto const fy = static_cast<float>(pt.y);
|
||||
auto const vbo = &m_bufferSet.vertices[i * vboLen];
|
||||
auto const ebo = &m_bufferSet.elements[i * VertexEboLength];
|
||||
auto const vbo = ox::Span{m_bufferSet.vertices} + i * vboLen;
|
||||
auto const ebo = ox::Span{m_bufferSet.elements} + i * VertexEboLength;
|
||||
if (i * vboLen + vboLen > m_bufferSet.vertices.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,11 +6,9 @@
|
||||
|
||||
#include <ox/std/vec.hpp>
|
||||
|
||||
#include <glutils/glutils.hpp>
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/gfx/color.hpp>
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
#include <glutils/glutils.hpp>
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
@@ -44,15 +42,15 @@ class TileSheetPixels {
|
||||
|
||||
private:
|
||||
void setPixelBufferObject(
|
||||
ox::Vec2 const&paneS,
|
||||
ox::Vec2 const&paneSize,
|
||||
unsigned vertexRow,
|
||||
float x,
|
||||
float y,
|
||||
Color16 color,
|
||||
float *vbo,
|
||||
GLuint *ebo) const noexcept;
|
||||
ox::Span<float> vbo,
|
||||
ox::Span<GLuint> ebo) const noexcept;
|
||||
|
||||
void setBufferObjects(ox::Vec2 const&paneS) noexcept;
|
||||
void setBufferObjects(ox::Vec2 const&paneSize) noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
namespace nostalgia::sound {
|
||||
|
||||
static class: public studio::Module {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::StudioContext&) const noexcept final {
|
||||
ox::Vector<studio::EditorMaker> editors(studio::Context&) const noexcept final {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::StudioContext&) const noexcept final {
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> out;
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(studio::Context&) const noexcept final {
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
|
||||
return out;
|
||||
}
|
||||
} const mod;
|
||||
|
||||
2
deps/nostalgia/src/nostalgia/player/app.cpp
vendored
2
deps/nostalgia/src/nostalgia/player/app.cpp
vendored
@@ -69,7 +69,7 @@ static ox::Error runTest(turbine::Context &tctx) {
|
||||
OX_RETURN_ERROR(gfx::loadSpriteTileSheet(*cctx, "/TileSheets/Charset.nts"));
|
||||
OX_RETURN_ERROR(gfx::loadSpritePalette(*cctx, "/Palettes/Chester.npal"));
|
||||
OX_RETURN_ERROR(gfx::initConsole(*cctx));
|
||||
gfx::puts(*cctx, 10, 9, "DOPENESS!!!");
|
||||
gfx::consoleWrite(*cctx, 10, 9, "DOPENESS!!!");
|
||||
turbine::setUpdateHandler(tctx, testUpdateHandler);
|
||||
turbine::setKeyEventHandler(tctx, testKeyEventHandler);
|
||||
return turbine::run(tctx);
|
||||
|
||||
16
deps/nostalgia/src/nostalgia/studio/icondata.cpp
vendored
16
deps/nostalgia/src/nostalgia/studio/icondata.cpp
vendored
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
static constexpr ox::Array<uint8_t, 134> WindowIcon16Data {
|
||||
static const ox::Array<uint8_t, 134> WindowIcon16Data {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10,
|
||||
0x00, 0x00, 0x00, 0x10, 0x02, 0x03, 0x00, 0x00, 0x00, 0x62,
|
||||
@@ -24,7 +24,7 @@ static constexpr ox::Array<uint8_t, 134> WindowIcon16Data {
|
||||
|
||||
ox::SpanView<uint8_t> WindowIcon16() noexcept { return WindowIcon16Data; }
|
||||
|
||||
static constexpr ox::Array<uint8_t, 149> WindowIcon24Data {
|
||||
static const ox::Array<uint8_t, 149> WindowIcon24Data {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x18,
|
||||
0x00, 0x00, 0x00, 0x18, 0x02, 0x03, 0x00, 0x00, 0x00, 0x9d,
|
||||
@@ -44,7 +44,7 @@ static constexpr ox::Array<uint8_t, 149> WindowIcon24Data {
|
||||
|
||||
ox::SpanView<uint8_t> WindowIcon24() noexcept { return WindowIcon24Data; }
|
||||
|
||||
static constexpr ox::Array<uint8_t, 4249> WindowIcon32Data {
|
||||
static const ox::Array<uint8_t, 4249> WindowIcon32Data {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20,
|
||||
0x00, 0x00, 0x00, 0x20, 0x02, 0x03, 0x00, 0x00, 0x00, 0x0e,
|
||||
@@ -474,7 +474,7 @@ static constexpr ox::Array<uint8_t, 4249> WindowIcon32Data {
|
||||
|
||||
ox::SpanView<uint8_t> WindowIcon32() noexcept { return WindowIcon32Data; }
|
||||
|
||||
static constexpr ox::Array<uint8_t, 334> WindowIcon40Data {
|
||||
static const ox::Array<uint8_t, 334> WindowIcon40Data {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x28,
|
||||
0x00, 0x00, 0x00, 0x28, 0x08, 0x03, 0x00, 0x00, 0x00, 0xbb,
|
||||
@@ -513,7 +513,7 @@ static constexpr ox::Array<uint8_t, 334> WindowIcon40Data {
|
||||
|
||||
ox::SpanView<uint8_t> WindowIcon40() noexcept { return WindowIcon40Data; }
|
||||
|
||||
static constexpr ox::Array<uint8_t, 163> WindowIcon48Data {
|
||||
static const ox::Array<uint8_t, 163> WindowIcon48Data {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x30,
|
||||
0x00, 0x00, 0x00, 0x30, 0x02, 0x03, 0x00, 0x00, 0x00, 0x2a,
|
||||
@@ -535,7 +535,7 @@ static constexpr ox::Array<uint8_t, 163> WindowIcon48Data {
|
||||
|
||||
ox::SpanView<uint8_t> WindowIcon48() noexcept { return WindowIcon48Data; }
|
||||
|
||||
static constexpr ox::Array<uint8_t, 8148> WindowIcon128Data {
|
||||
static const ox::Array<uint8_t, 8148> WindowIcon128Data {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x80,
|
||||
0x00, 0x00, 0x00, 0x80, 0x02, 0x03, 0x00, 0x00, 0x00, 0xbe,
|
||||
@@ -1355,7 +1355,7 @@ static constexpr ox::Array<uint8_t, 8148> WindowIcon128Data {
|
||||
|
||||
ox::SpanView<uint8_t> WindowIcon128() noexcept { return WindowIcon128Data; }
|
||||
|
||||
static constexpr ox::Array<uint8_t, 275> WindowIcon264Data {
|
||||
static const ox::Array<uint8_t, 275> WindowIcon264Data {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x01, 0x08,
|
||||
0x00, 0x00, 0x01, 0x08, 0x02, 0x03, 0x00, 0x00, 0x00, 0xde,
|
||||
@@ -1388,7 +1388,7 @@ static constexpr ox::Array<uint8_t, 275> WindowIcon264Data {
|
||||
|
||||
ox::SpanView<uint8_t> WindowIcon264() noexcept { return WindowIcon264Data; }
|
||||
|
||||
static constexpr ox::Array<uint8_t, 851> WindowIcon1080Data {
|
||||
static const ox::Array<uint8_t, 851> WindowIcon1080Data {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x03, 0x48,
|
||||
0x00, 0x00, 0x03, 0x48, 0x02, 0x03, 0x00, 0x00, 0x00, 0x80,
|
||||
|
||||
@@ -15,7 +15,18 @@
|
||||
namespace keel {
|
||||
|
||||
ox::Error init(
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName,
|
||||
DuplicateSet &duplicateSet) noexcept;
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName,
|
||||
DuplicateSet &duplicateSet) noexcept;
|
||||
|
||||
ox::Error init(
|
||||
Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName) noexcept;
|
||||
|
||||
|
||||
@@ -29,13 +29,14 @@ OX_MODEL_BEGIN(PreloadPtr)
|
||||
OX_MODEL_FIELD(preloadAddr)
|
||||
OX_MODEL_END()
|
||||
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const&addr) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::StringViewCR path) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(Context &ctx, ox::FileAddress const&addr) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(Context &ctx, ox::StringViewCR path) noexcept;
|
||||
|
||||
|
||||
void createUuidMapping(Context &ctx, ox::StringViewCR filePath, ox::UUID const&uuid) noexcept;
|
||||
|
||||
ox::Error buildUuidMap(Context &ctx) noexcept;
|
||||
// map of UUIDs to paths
|
||||
using DuplicateSet = ox::HashMap<ox::UUID, ox::Vector<ox::String>>;
|
||||
|
||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept;
|
||||
|
||||
@@ -87,8 +88,8 @@ constexpr auto makeLoader(Context &ctx) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObjFile(
|
||||
keel::Context &ctx,
|
||||
ox::Result<AssetRef<T>> readObjFile(
|
||||
Context &ctx,
|
||||
ox::StringViewCR assetId,
|
||||
bool const forceLoad) noexcept {
|
||||
static constexpr auto load = [](
|
||||
@@ -135,11 +136,11 @@ ox::Result<keel::AssetRef<T>> readObjNoCache(
|
||||
|
||||
#endif
|
||||
|
||||
ox::Error reloadAsset(keel::Context &ctx, ox::StringViewCR assetId) noexcept;
|
||||
ox::Error reloadAsset(Context &ctx, ox::StringViewCR assetId) noexcept;
|
||||
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObj(
|
||||
keel::Context &ctx,
|
||||
ox::Result<AssetRef<T>> readObj(
|
||||
Context &ctx,
|
||||
ox::StringViewCR assetId,
|
||||
[[maybe_unused]] bool forceLoad = false) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
@@ -150,8 +151,8 @@ ox::Result<keel::AssetRef<T>> readObj(
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObj(
|
||||
keel::Context &ctx,
|
||||
ox::Result<AssetRef<T>> readObj(
|
||||
Context &ctx,
|
||||
ox::FileAddress const&file,
|
||||
[[maybe_unused]] bool forceLoad = false) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
@@ -169,7 +170,7 @@ ox::Result<keel::AssetRef<T>> readObj(
|
||||
|
||||
template<typename T>
|
||||
ox::Error writeObj(
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::FileAddress const&file,
|
||||
T const&obj,
|
||||
ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept {
|
||||
@@ -177,6 +178,8 @@ ox::Error writeObj(
|
||||
return ctx.rom->write(file, objBuff.data(), objBuff.size());
|
||||
}
|
||||
|
||||
ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs, DuplicateSet &duplicateSet) noexcept;
|
||||
|
||||
ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept;
|
||||
|
||||
ox::Result<ox::UPtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept;
|
||||
|
||||
@@ -32,6 +32,7 @@ class WrapT: public Wrap {
|
||||
[[nodiscard]]
|
||||
virtual constexpr T &obj() noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::UAnyPtr moveToCopy() noexcept final {
|
||||
return new T{std::move(obj())};
|
||||
}
|
||||
@@ -46,14 +47,17 @@ class WrapRef final: public WrapT<T> {
|
||||
public:
|
||||
constexpr explicit WrapRef(T &obj): m_obj{obj} {}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::CStringView typeName() const noexcept override {
|
||||
return ox::ModelTypeName_v<T>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int typeVersion() const noexcept override {
|
||||
return ox::ModelTypeVersion_v<T>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &obj() noexcept override {
|
||||
return m_obj;
|
||||
}
|
||||
@@ -72,14 +76,17 @@ class WrapInline final: public WrapT<T> {
|
||||
constexpr explicit WrapInline(Args &&...args): m_obj(ox::forward<Args>(args)...) {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::CStringView typeName() const noexcept override {
|
||||
return ox::ModelTypeName_v<T>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int typeVersion() const noexcept override {
|
||||
return ox::ModelTypeVersion_v<T>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &obj() noexcept override {
|
||||
return m_obj;
|
||||
}
|
||||
@@ -197,22 +204,17 @@ class ConverterFunc final: public BaseConverter {
|
||||
class Converter {
|
||||
private:
|
||||
ox::AllocAlias<BaseConverter> m_buff{};
|
||||
BaseConverter *m_conv{};
|
||||
public:
|
||||
template<auto Func>
|
||||
static Converter make() noexcept {
|
||||
Converter out;
|
||||
static_assert(sizeof(ConverterFunc<Func>) <= sizeof(out.m_buff));
|
||||
out.m_conv = new (out.m_buff.data()) ConverterFunc<Func>{};
|
||||
new (out.m_buff.data()) ConverterFunc<Func>{};
|
||||
return out;
|
||||
}
|
||||
constexpr Converter() {}
|
||||
Converter(Converter const &other) noexcept:
|
||||
m_buff{other.m_buff},
|
||||
m_conv{m_buff.data()} {}
|
||||
[[nodiscard]]
|
||||
BaseConverter const *converter() const noexcept {
|
||||
return m_conv;
|
||||
BaseConverter const &converter() const noexcept {
|
||||
return *m_buff.data();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) no
|
||||
return ox::readClaw(ts, buff);
|
||||
}
|
||||
|
||||
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView buff) noexcept {
|
||||
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const buff) noexcept {
|
||||
const auto err = readUuidHeader(buff).error;
|
||||
const auto offset = err ? 0u : K1HdrSz;
|
||||
if (offset >= buff.size()) [[unlikely]] {
|
||||
|
||||
39
deps/nostalgia/src/olympic/keel/src/keel.cpp
vendored
39
deps/nostalgia/src/olympic/keel/src/keel.cpp
vendored
@@ -6,21 +6,24 @@
|
||||
|
||||
namespace keel {
|
||||
|
||||
ox::Error init(
|
||||
keel::Context &ctx,
|
||||
static ox::Error init(
|
||||
Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName) noexcept {
|
||||
ox::StringViewCR appName,
|
||||
DuplicateSet *duplicateSet) noexcept {
|
||||
ctx.appName = appName;
|
||||
std::ignore = setRomFs(ctx, std::move(fs));
|
||||
std::ignore = duplicateSet ?
|
||||
setRomFs(ctx, std::move(fs), *duplicateSet) :
|
||||
setRomFs(ctx, std::move(fs));
|
||||
#ifndef OX_BARE_METAL
|
||||
auto const&mods = modules();
|
||||
for (auto &mod : mods) {
|
||||
// register type converters
|
||||
for (auto c : mod->converters()) {
|
||||
for (auto const c : mod->converters()) {
|
||||
ctx.converters.emplace_back(c);
|
||||
}
|
||||
// register pack transforms
|
||||
for (auto c : mod->packTransforms()) {
|
||||
for (auto const c : mod->packTransforms()) {
|
||||
ctx.packTransforms.emplace_back(c);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +31,30 @@ ox::Error init(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error init(
|
||||
Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName,
|
||||
DuplicateSet &duplicateSet) noexcept {
|
||||
return init(ctx, std::move(fs), appName, &duplicateSet);
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName,
|
||||
DuplicateSet &duplicateSet) noexcept {
|
||||
auto ctx = ox::make_unique<Context>();
|
||||
OX_RETURN_ERROR(keel::init(*ctx, std::move(fs), appName, &duplicateSet));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
ox::Error init(
|
||||
Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::StringViewCR appName) noexcept {
|
||||
return init(ctx, std::move(fs), appName, nullptr);
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
|
||||
auto ctx = ox::make_unique<Context>();
|
||||
OX_RETURN_ERROR(keel::init(*ctx, std::move(fs), appName));
|
||||
|
||||
31
deps/nostalgia/src/olympic/keel/src/media.cpp
vendored
31
deps/nostalgia/src/olympic/keel/src/media.cpp
vendored
@@ -47,7 +47,7 @@ void createUuidMapping(Context &ctx, ox::StringViewCR filePath, ox::UUID const&u
|
||||
ctx.uuidToPath[uuid.toString()] = filePath;
|
||||
}
|
||||
|
||||
static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path, DuplicateSet *duplicates) noexcept {
|
||||
OX_REQUIRE(files, ctx.rom->ls(path));
|
||||
for (auto const&f : files) {
|
||||
OX_REQUIRE_M(filePath, ox::join("/", ox::Array<ox::StringView, 2>{path, f}));
|
||||
@@ -58,22 +58,31 @@ static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
ctx.rom->read(filePath, 0, buff.size(), buff));
|
||||
auto const [uuid, err] = readUuidHeader(buff);
|
||||
if (!err) {
|
||||
createUuidMapping(ctx, filePath, uuid);
|
||||
// check for duplication
|
||||
if (duplicates && ctx.uuidToPath[uuid.toString()].len()) {
|
||||
auto &dl = (*duplicates)[uuid];
|
||||
if (dl.empty()) {
|
||||
dl.emplace_back(ctx.uuidToPath[uuid.toString()]);
|
||||
}
|
||||
dl.emplace_back(filePath);
|
||||
} else {
|
||||
createUuidMapping(ctx, filePath, uuid);
|
||||
}
|
||||
}
|
||||
} else if (stat.fileType == ox::FileType::Directory) {
|
||||
if (!beginsWith(f, ".")) {
|
||||
OX_RETURN_ERROR(buildUuidMap(ctx, filePath));
|
||||
OX_RETURN_ERROR(buildUuidMap(ctx, filePath, duplicates));
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error buildUuidMap(Context &ctx) noexcept {
|
||||
static ox::Error buildUuidMap(Context &ctx, DuplicateSet *duplicates) noexcept {
|
||||
if (!ctx.rom) {
|
||||
return ox::Error(1, "No ROM FS");
|
||||
return ox::Error{1, "No ROM FS"};
|
||||
}
|
||||
return buildUuidMap(ctx, "");
|
||||
return buildUuidMap(ctx, "", duplicates);
|
||||
}
|
||||
|
||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
@@ -199,7 +208,7 @@ namespace keel {
|
||||
static void clearUuidMap(Context&) noexcept {
|
||||
}
|
||||
|
||||
ox::Error buildUuidMap(Context&) noexcept {
|
||||
static ox::Error buildUuidMap(Context&, DuplicateSet*) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -249,10 +258,16 @@ ox::Error reloadAsset(keel::Context&, ox::StringView) noexcept {
|
||||
|
||||
namespace keel {
|
||||
|
||||
ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs, DuplicateSet &duplicateSet) noexcept {
|
||||
ctx.rom = std::move(fs);
|
||||
clearUuidMap(ctx);
|
||||
return buildUuidMap(ctx, &duplicateSet);
|
||||
}
|
||||
|
||||
ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept {
|
||||
ctx.rom = std::move(fs);
|
||||
clearUuidMap(ctx);
|
||||
return buildUuidMap(ctx);
|
||||
return buildUuidMap(ctx, nullptr);
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept {
|
||||
|
||||
@@ -6,13 +6,11 @@
|
||||
|
||||
#include <ox/clargs/clargs.hpp>
|
||||
#include <ox/fs/fs.hpp>
|
||||
#include <ox/logconn/def.hpp>
|
||||
#include <ox/logconn/logconn.hpp>
|
||||
#include <ox/oc/write.hpp>
|
||||
|
||||
#include <keel/keel.hpp>
|
||||
|
||||
static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) noexcept {
|
||||
static ox::Error writeFileBuff(ox::StringViewCR path, ox::BufferView const &buff) noexcept {
|
||||
try {
|
||||
std::ofstream f(std::string(toStdStringView(path)), std::ios::binary);
|
||||
f.write(buff.data(), static_cast<intptr_t>(buff.size()));
|
||||
@@ -22,7 +20,7 @@ static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) n
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
|
||||
static ox::Result<ox::Buffer> readFileBuff(ox::StringViewCR path) noexcept {
|
||||
std::ifstream file(std::string(toStdStringView(path)), std::ios::binary | std::ios::ate);
|
||||
if (!file.good()) {
|
||||
oxErrorf("Could not find OxFS file: {}", path);
|
||||
@@ -42,7 +40,7 @@ static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
|
||||
|
||||
static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
|
||||
for (auto const mod : keel::modules()) {
|
||||
for (auto gen : mod->types()) {
|
||||
for (auto const gen : mod->types()) {
|
||||
OX_RETURN_ERROR(gen(ts));
|
||||
}
|
||||
}
|
||||
@@ -50,14 +48,27 @@ static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
|
||||
}
|
||||
|
||||
static ox::Error pack(
|
||||
ox::StringView argSrc,
|
||||
ox::StringView argRomBin,
|
||||
ox::StringView argManifest,
|
||||
ox::StringView projectDataDir) noexcept {
|
||||
ox::StringViewCR argSrc,
|
||||
ox::StringViewCR argRomBin,
|
||||
ox::StringViewCR argManifest,
|
||||
ox::StringViewCR projectDataDir) noexcept {
|
||||
ox::Buffer dstBuff(32 * ox::units::MB);
|
||||
OX_RETURN_ERROR(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
||||
ox::FileSystem32 dst(dstBuff);
|
||||
OX_REQUIRE(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack"));
|
||||
keel::DuplicateSet duplicateSet;
|
||||
OX_REQUIRE(ctx, keel::init(
|
||||
ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack", duplicateSet));
|
||||
if (duplicateSet.size()) {
|
||||
oxErr("Multiple files have the same UUID:\n");
|
||||
for (auto const &k : duplicateSet.keys()) {
|
||||
oxErrf("\n\t{}:\n", k.toString());
|
||||
for (auto const &v : duplicateSet[k]) {
|
||||
oxErrf("\t\t{}\n", v);
|
||||
}
|
||||
}
|
||||
oxErr("\n");
|
||||
std::exit(1);
|
||||
}
|
||||
keel::TypeStore ts(*ctx->rom, ox::sfmt("{}/type_descriptors", projectDataDir));
|
||||
OX_RETURN_ERROR(generateTypes(ts));
|
||||
keel::Manifest manifest;
|
||||
@@ -82,10 +93,10 @@ static ox::Error pack(
|
||||
}
|
||||
|
||||
ox::Error run(
|
||||
[[maybe_unused]] ox::StringView project,
|
||||
[[maybe_unused]] ox::StringView appName,
|
||||
ox::StringView projectDataDir,
|
||||
ox::SpanView<ox::CString> argv) noexcept {
|
||||
[[maybe_unused]] ox::StringView const project,
|
||||
[[maybe_unused]] ox::StringView const appName,
|
||||
ox::StringView const projectDataDir,
|
||||
ox::SpanView<ox::CString> const argv) noexcept {
|
||||
ox::ClArgs const args(argv);
|
||||
auto const argSrc = args.getString("src", "");
|
||||
auto const argRomBin = args.getString("rom-bin", "");
|
||||
|
||||
37
deps/nostalgia/src/olympic/keel/src/pack.cpp
vendored
37
deps/nostalgia/src/olympic/keel/src/pack.cpp
vendored
@@ -11,13 +11,12 @@
|
||||
namespace keel {
|
||||
|
||||
static ox::Error pathToInode(
|
||||
keel::Context &ctx,
|
||||
ox::FileSystem &dest,
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelObject &obj) noexcept {
|
||||
auto &o = obj;
|
||||
OX_REQUIRE(typeVal, o.at("type"));
|
||||
OX_REQUIRE(typeVal, obj.at("type"));
|
||||
auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>());
|
||||
OX_REQUIRE(dataVal, o.at("data"));
|
||||
OX_REQUIRE(dataVal, obj.at("data"));
|
||||
auto &data = dataVal->get<ox::ModelUnion>();
|
||||
ox::String path;
|
||||
switch (type) {
|
||||
@@ -47,13 +46,17 @@ static ox::Error pathToInode(
|
||||
}
|
||||
|
||||
static ox::Error transformFileAddressesObj(
|
||||
keel::Context &ctx, ox::FileSystem &dest, ox::ModelObject &obj) noexcept;
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelObject &obj) noexcept;
|
||||
static ox::Error transformFileAddressesVec(
|
||||
keel::Context &ctx, ox::FileSystem &dest, ox::ModelValueVector &v) noexcept;
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelValueVector &v) noexcept;
|
||||
|
||||
static ox::Error transformFileAddresses(
|
||||
keel::Context &ctx,
|
||||
ox::FileSystem &dest,
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelValue &v) noexcept {
|
||||
if (v.type() == ox::ModelValue::Type::Object) {
|
||||
auto &obj = v.get<ox::ModelObject>();
|
||||
@@ -66,8 +69,8 @@ static ox::Error transformFileAddresses(
|
||||
}
|
||||
|
||||
static ox::Error transformFileAddressesVec(
|
||||
keel::Context &ctx,
|
||||
ox::FileSystem &dest,
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelValueVector &v) noexcept {
|
||||
for (auto &f : v) {
|
||||
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, f));
|
||||
@@ -80,13 +83,13 @@ static ox::Error transformFileAddressesVec(
|
||||
* @return error
|
||||
*/
|
||||
static ox::Error transformFileAddressesObj(
|
||||
keel::Context &ctx,
|
||||
ox::FileSystem &dest,
|
||||
Context &ctx,
|
||||
ox::FileSystem const &dest,
|
||||
ox::ModelObject &obj) noexcept {
|
||||
if (obj.typeName() == "net.drinkingtea.ox.FileAddress" && obj.typeVersion() == 1) {
|
||||
return pathToInode(ctx, dest, obj);
|
||||
}
|
||||
for (auto &f : obj) {
|
||||
for (auto const &f : obj) {
|
||||
auto &v = f->value;
|
||||
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, v));
|
||||
}
|
||||
@@ -111,7 +114,7 @@ static ox::Error performPackTransforms(
|
||||
|
||||
static ox::Error doTransformations(
|
||||
Manifest &manifest,
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &dest,
|
||||
ox::StringViewCR filePath) noexcept {
|
||||
@@ -134,7 +137,7 @@ static ox::Error doTransformations(
|
||||
// transformations need to be done after the copy to the new FS is complete
|
||||
static ox::Error transformClaw(
|
||||
Manifest &manifest,
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &dest,
|
||||
ox::StringViewCR path) noexcept {
|
||||
@@ -200,7 +203,7 @@ static ox::Error copy(
|
||||
|
||||
ox::Error pack(
|
||||
Manifest &manifest,
|
||||
keel::Context &ctx,
|
||||
Context &ctx,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &dest) noexcept {
|
||||
OX_RETURN_ERROR(copy(manifest, *ctx.rom, dest, "/"));
|
||||
|
||||
10
deps/nostalgia/src/olympic/keel/src/typeconv.cpp
vendored
10
deps/nostalgia/src/olympic/keel/src/typeconv.cpp
vendored
@@ -15,8 +15,8 @@ static ox::Result<BaseConverter const*> findConverter(
|
||||
ox::StringViewCR dstTypeName,
|
||||
int const dstTypeVersion) noexcept {
|
||||
for (auto const&c : converters) {
|
||||
if (c.converter()->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
|
||||
return c.converter();
|
||||
if (c.converter().matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
|
||||
return &c.converter();
|
||||
}
|
||||
}
|
||||
return ox::Error{1, "Could not find converter"};
|
||||
@@ -46,14 +46,14 @@ static ox::Result<ox::UPtr<Wrap>> convert(
|
||||
}
|
||||
// try to chain multiple converters
|
||||
for (auto const&subConverter : converters) {
|
||||
if (!subConverter.converter()->dstMatches(dstTypeName, dstTypeVersion)) {
|
||||
if (!subConverter.converter().dstMatches(dstTypeName, dstTypeVersion)) {
|
||||
continue;
|
||||
}
|
||||
const auto [intermediate, chainErr] =
|
||||
convert(ctx, converters, src, srcTypeName, srcTypeVersion,
|
||||
subConverter.converter()->srcTypeName(), subConverter.converter()->srcTypeVersion());
|
||||
subConverter.converter().srcTypeName(), subConverter.converter().srcTypeVersion());
|
||||
if (!chainErr) {
|
||||
return subConverter.converter()->convertPtrToPtr(ctx, *intermediate);
|
||||
return subConverter.converter().convertPtrToPtr(ctx, *intermediate);
|
||||
}
|
||||
}
|
||||
return ox::Error{1, "Could not convert between types"};
|
||||
|
||||
@@ -5,6 +5,7 @@ add_library(
|
||||
clawviewer.cpp
|
||||
deleteconfirmation.cpp
|
||||
filedialogmanager.cpp
|
||||
font.cpp
|
||||
makecopypopup.cpp
|
||||
newdir.cpp
|
||||
newmenu.cpp
|
||||
|
||||
BIN
deps/nostalgia/src/olympic/studio/applib/src/Roboto-Medium.ttf
vendored
Normal file
BIN
deps/nostalgia/src/olympic/studio/applib/src/Roboto-Medium.ttf
vendored
Normal file
Binary file not shown.
@@ -29,7 +29,11 @@ bool AboutPopup::isOpen() const noexcept {
|
||||
return m_stage == Stage::Open;
|
||||
}
|
||||
|
||||
void AboutPopup::draw(StudioContext &sctx) noexcept {
|
||||
void AboutPopup::draw(Context &sctx) noexcept {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
|
||||
@@ -35,7 +35,7 @@ class AboutPopup: public studio::Popup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept override;
|
||||
|
||||
void draw(studio::StudioContext &sctx) noexcept override;
|
||||
void draw(studio::Context &sctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class StudioUIDrawer: public turbine::gl::Drawer {
|
||||
};
|
||||
|
||||
static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down) noexcept {
|
||||
auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
|
||||
auto sctx = turbine::applicationData<studio::Context>(ctx);
|
||||
sctx->ui.handleKeyEvent(key, down);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
ClawEditor::ClawEditor(StudioContext &sctx, ox::StringParam path):
|
||||
ClawEditor::ClawEditor(Context &sctx, ox::StringParam path):
|
||||
Editor(sctx, std::move(path)),
|
||||
m_obj(sctx.project->loadObj<ox::ModelObject>(itemPath()).unwrapThrow()) {
|
||||
}
|
||||
|
||||
void ClawEditor::draw(StudioContext&) noexcept {
|
||||
void ClawEditor::draw(Context&) noexcept {
|
||||
ImGui::BeginChild("PaletteEditor");
|
||||
static constexpr auto flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody;
|
||||
if (ImGui::BeginTable("ObjTree", 3, flags)) {
|
||||
|
||||
@@ -16,9 +16,9 @@ class ClawEditor: public Editor {
|
||||
using ObjPath = ox::Vector<ox::StringView, 8>;
|
||||
ox::ModelObject m_obj;
|
||||
public:
|
||||
ClawEditor(StudioContext &sctx, ox::StringParam path);
|
||||
ClawEditor(Context &sctx, ox::StringParam path);
|
||||
|
||||
void draw(StudioContext&) noexcept final;
|
||||
void draw(Context&) noexcept final;
|
||||
|
||||
private:
|
||||
static void drawRow(ox::ModelValue const&value) noexcept;
|
||||
|
||||
@@ -31,7 +31,11 @@ bool DeleteConfirmation::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void DeleteConfirmation::draw(StudioContext &ctx) noexcept {
|
||||
void DeleteConfirmation::draw(Context &ctx) noexcept {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
|
||||
@@ -36,7 +36,7 @@ class DeleteConfirmation final: public Popup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept override;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
void draw(Context &ctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
16272
deps/nostalgia/src/olympic/studio/applib/src/font.cpp
vendored
Normal file
16272
deps/nostalgia/src/olympic/studio/applib/src/font.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10
deps/nostalgia/src/olympic/studio/applib/src/font.hpp
vendored
Normal file
10
deps/nostalgia/src/olympic/studio/applib/src/font.hpp
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// Generated
|
||||
|
||||
#include <ox/std/span.hpp>
|
||||
|
||||
namespace studio::files {
|
||||
|
||||
[[nodiscard]]
|
||||
ox::SpanView<uint8_t> RobotoMedium_ttf() noexcept;
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <studio/imguiutil.hpp>
|
||||
|
||||
#include "makecopypopup.hpp"
|
||||
|
||||
namespace studio {
|
||||
@@ -26,7 +28,7 @@ bool MakeCopyPopup::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void MakeCopyPopup::draw(StudioContext const &ctx) noexcept {
|
||||
void MakeCopyPopup::draw(Context &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
@@ -68,7 +70,7 @@ void MakeCopyPopup::draw(StudioContext const &ctx) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void MakeCopyPopup::accept(StudioContext const &ctx) noexcept {
|
||||
void MakeCopyPopup::accept(Context const &ctx) noexcept {
|
||||
auto const p = sfmt("{}{}", m_dirPath, m_fileName);
|
||||
if (!ctx.project->exists(p)) {
|
||||
makeCopy.emit(m_srcPath, p);
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
#include <ox/std/string.hpp>
|
||||
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/imguiutil.hpp>
|
||||
|
||||
#include <studio/widget.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
class MakeCopyPopup {
|
||||
class MakeCopyPopup: public Widget {
|
||||
private:
|
||||
enum class Stage {
|
||||
Closed,
|
||||
@@ -36,10 +37,10 @@ class MakeCopyPopup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept;
|
||||
|
||||
void draw(StudioContext const &ctx) noexcept;
|
||||
void draw(Context &ctx) noexcept override;
|
||||
|
||||
private:
|
||||
void accept(StudioContext const &ctx) noexcept;
|
||||
void accept(Context const &ctx) noexcept;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,11 @@ bool NewDir::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void NewDir::draw(StudioContext &ctx) noexcept {
|
||||
void NewDir::draw(Context &ctx) noexcept {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
|
||||
@@ -37,7 +37,7 @@ class NewDir final: public Popup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept override;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
void draw(Context &ctx) noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::CStringView value() const noexcept {
|
||||
|
||||
@@ -44,7 +44,11 @@ bool NewMenu::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void NewMenu::draw(StudioContext &sctx) noexcept {
|
||||
void NewMenu::draw(Context &sctx) noexcept {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
switch (m_stage) {
|
||||
case Stage::Opening:
|
||||
ImGui::OpenPopup(title().c_str());
|
||||
@@ -84,7 +88,7 @@ void NewMenu::installItemTemplate(ox::UPtr<ItemTemplate> &tmplt) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void NewMenu::drawNewItemType(StudioContext const&sctx) noexcept {
|
||||
void NewMenu::drawNewItemType(Context const&sctx) noexcept {
|
||||
setSize({280, 180});
|
||||
drawWindow(sctx.tctx, m_open, [this] {
|
||||
ig::ListBox("Item Type", [&](size_t const i) -> ox::CStringView {
|
||||
@@ -101,7 +105,7 @@ void NewMenu::drawNewItemType(StudioContext const&sctx) noexcept {
|
||||
});
|
||||
}
|
||||
|
||||
void NewMenu::drawNewItemTemplate(StudioContext const&sctx) noexcept {
|
||||
void NewMenu::drawNewItemTemplate(Context const&sctx) noexcept {
|
||||
setSize({280, 180});
|
||||
drawWindow(sctx.tctx, m_open, [this] {
|
||||
auto const&templates =
|
||||
@@ -113,7 +117,7 @@ void NewMenu::drawNewItemTemplate(StudioContext const&sctx) noexcept {
|
||||
});
|
||||
}
|
||||
|
||||
void NewMenu::drawNewItemPath(StudioContext &sctx) noexcept {
|
||||
void NewMenu::drawNewItemPath(Context &sctx) noexcept {
|
||||
setSize({380, 340});
|
||||
drawWindow(sctx.tctx, m_open, [this, &sctx] {
|
||||
if (m_stage == Stage::NewItemTransitioningToPath) [[unlikely]] {
|
||||
@@ -166,7 +170,7 @@ void NewMenu::drawFirstPageButtons(Stage const next) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void NewMenu::drawLastPageButtons(StudioContext &sctx) noexcept {
|
||||
void NewMenu::drawLastPageButtons(Context &sctx) noexcept {
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 198);
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
|
||||
constexpr ImVec2 btnSz{60, 20};
|
||||
@@ -187,7 +191,7 @@ void NewMenu::drawLastPageButtons(StudioContext &sctx) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void NewMenu::finish(StudioContext &sctx) noexcept {
|
||||
void NewMenu::finish(Context &sctx) noexcept {
|
||||
if (m_itemName.len() == 0) {
|
||||
oxLogError(ox::Error{1, "New file error: no file name"});
|
||||
return;
|
||||
|
||||
@@ -53,7 +53,7 @@ class NewMenu final: public Popup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept override;
|
||||
|
||||
void draw(StudioContext &sctx) noexcept override;
|
||||
void draw(Context &sctx) noexcept override;
|
||||
|
||||
template<typename T>
|
||||
void addItemType(
|
||||
@@ -75,19 +75,19 @@ class NewMenu final: public Popup {
|
||||
void installItemTemplate(ox::UPtr<ItemTemplate> &tmplt) noexcept;
|
||||
|
||||
private:
|
||||
void drawNewItemType(StudioContext const&sctx) noexcept;
|
||||
void drawNewItemType(Context const&sctx) noexcept;
|
||||
|
||||
void drawNewItemPath(StudioContext &sctx) noexcept;
|
||||
void drawNewItemPath(Context &sctx) noexcept;
|
||||
|
||||
void drawNewItemTemplate(StudioContext const &sctx) noexcept;
|
||||
void drawNewItemTemplate(Context const &sctx) noexcept;
|
||||
|
||||
void drawButtons(Stage next) noexcept;
|
||||
|
||||
void drawFirstPageButtons(Stage next) noexcept;
|
||||
|
||||
void drawLastPageButtons(StudioContext &sctx) noexcept;
|
||||
void drawLastPageButtons(Context &sctx) noexcept;
|
||||
|
||||
void finish(StudioContext &sctx) noexcept;
|
||||
void finish(Context &sctx) noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
NewProject::NewProject(ox::StringParam projectDatadir) noexcept: m_projectDataDir(std::move(projectDatadir)) {
|
||||
NewProject::NewProject(ox::StringParam projectDatadir) noexcept:
|
||||
m_projectDataDir{std::move(projectDatadir)} {
|
||||
setTitle("New Project");
|
||||
setSize({230, 140});
|
||||
}
|
||||
@@ -32,7 +33,11 @@ bool NewProject::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void NewProject::draw(studio::StudioContext &ctx) noexcept {
|
||||
void NewProject::draw(Context &ctx) noexcept {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
switch (m_stage) {
|
||||
case Stage::Opening:
|
||||
ImGui::OpenPopup(title().c_str());
|
||||
@@ -48,39 +53,25 @@ void NewProject::draw(studio::StudioContext &ctx) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void NewProject::drawNewProjectName(studio::StudioContext &sctx) noexcept {
|
||||
void NewProject::drawNewProjectName(Context &sctx) noexcept {
|
||||
drawWindow(sctx.tctx, m_open, [this, &sctx] {
|
||||
ig::InputText("Name", m_projectName);
|
||||
ImGui::Text("Path: %s", m_projectPath.c_str());
|
||||
if (ImGui::Button("Browse")) {
|
||||
if (ig::PushButton("Browse")) {
|
||||
oxLogError(studio::chooseDirectory().moveTo(m_projectPath));
|
||||
}
|
||||
drawLastPageButtons(sctx);
|
||||
});
|
||||
}
|
||||
|
||||
void NewProject::drawFirstPageButtons() noexcept {
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 130);
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
|
||||
auto const btnSz = ImVec2(60, 20);
|
||||
if (ImGui::Button("Next", btnSz)) {
|
||||
m_stage = Stage::NewItemName;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Cancel", btnSz)) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
m_stage = Stage::Closed;
|
||||
}
|
||||
}
|
||||
|
||||
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")) {
|
||||
void NewProject::drawLastPageButtons(Context&) noexcept {
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 110);
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 22);
|
||||
if (ig::PushButton("Finish")) {
|
||||
finish();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Quit")) {
|
||||
if (ig::PushButton("Quit")) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
m_stage = Stage::Closed;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class NewProject: public studio::Popup {
|
||||
ox::String const m_projectDataDir;
|
||||
ox::String m_projectPath;
|
||||
ox::IString<255> m_projectName;
|
||||
ox::Vector<ox::UniquePtr<studio::ItemMaker>> m_types;
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> m_types;
|
||||
bool m_open = false;
|
||||
|
||||
public:
|
||||
@@ -42,14 +42,12 @@ class NewProject: public studio::Popup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept override;
|
||||
|
||||
void draw(studio::StudioContext &ctx) noexcept override;
|
||||
void draw(studio::Context &ctx) noexcept override;
|
||||
|
||||
private:
|
||||
void drawNewProjectName(studio::StudioContext &ctx) noexcept;
|
||||
void drawNewProjectName(studio::Context &ctx) noexcept;
|
||||
|
||||
void drawFirstPageButtons() noexcept;
|
||||
|
||||
void drawLastPageButtons(studio::StudioContext &ctx) noexcept;
|
||||
void drawLastPageButtons(studio::Context &ctx) noexcept;
|
||||
|
||||
void finish() noexcept;
|
||||
|
||||
|
||||
@@ -34,7 +34,11 @@ bool RenameFile::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void RenameFile::draw(StudioContext &ctx) noexcept {
|
||||
void RenameFile::draw(Context &ctx) noexcept {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
|
||||
@@ -38,7 +38,7 @@ class RenameFile: public Popup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept override;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
void draw(Context &ctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
11
deps/nostalgia/src/olympic/studio/applib/src/rsrc.json
vendored
Normal file
11
deps/nostalgia/src/olympic/studio/applib/src/rsrc.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"cpp": "font.cpp",
|
||||
"hpp": "font.hpp",
|
||||
"namespace": "studio::files",
|
||||
"files": [
|
||||
{
|
||||
"path": "Roboto-Medium.ttf",
|
||||
"cpp_name": "RobotoMedium_ttf"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -14,11 +14,23 @@
|
||||
#include <studio/configio.hpp>
|
||||
#include "clawviewer.hpp"
|
||||
#include "filedialogmanager.hpp"
|
||||
#include "font.hpp"
|
||||
#include "studioui.hpp"
|
||||
|
||||
#ifdef OX_OS_Darwin
|
||||
#define STUDIO_CTRL "Cmd"
|
||||
#else
|
||||
#define STUDIO_CTRL "Ctrl"
|
||||
#endif
|
||||
|
||||
namespace studio {
|
||||
|
||||
void navigateTo(StudioContext &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept {
|
||||
static bool shutdownHandler(turbine::Context &ctx) {
|
||||
auto sctx = turbine::applicationData<Context>(ctx);
|
||||
return sctx->ui.handleShutdown();
|
||||
}
|
||||
|
||||
void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept {
|
||||
ctx.ui.navigateTo(std::move(filePath), std::move(navArgs));
|
||||
}
|
||||
|
||||
@@ -57,7 +69,21 @@ StudioUI::StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexce
|
||||
m_projectExplorer{keelCtx(m_tctx)},
|
||||
m_newProject{m_projectDataDir},
|
||||
m_aboutPopup{m_tctx} {
|
||||
{
|
||||
ImFontConfig fontCfg;
|
||||
fontCfg.FontDataOwnedByAtlas = false;
|
||||
auto const &io = ImGui::GetIO();
|
||||
auto const font = files::RobotoMedium_ttf();
|
||||
// const_cast is needed because this data is definitely const,
|
||||
// but AddFontFromMemoryTTF requires a mutable buffer.
|
||||
// However, setting fontCfg.FontDataOwnedByAtlas ensures
|
||||
// that it will still be treated as const.
|
||||
// ImGui documentation recognize that this is a bad design,
|
||||
// and hopefully it will change at some point.
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<uint8_t*>(font.data()), static_cast<int>(font.size()), 13, &fontCfg);
|
||||
}
|
||||
turbine::setApplicationData(m_tctx, &m_sctx);
|
||||
turbine::setShutdownHandler(m_tctx, shutdownHandler);
|
||||
m_projectExplorer.fileChosen.connect(this, &StudioUI::openFile);
|
||||
m_projectExplorer.addDir.connect(this, &StudioUI::addDir);
|
||||
m_projectExplorer.addItem.connect(this, &StudioUI::addFile);
|
||||
@@ -69,6 +95,7 @@ StudioUI::StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexce
|
||||
m_renameFile.moveFile.connect(this, &StudioUI::queueFileMove);
|
||||
m_newProject.finished.connect(this, &StudioUI::createOpenProject);
|
||||
m_newMenu.finished.connect(this, &StudioUI::openFile);
|
||||
m_closeAppConfirm.response.connect(this, &StudioUI::handleCloseAppResponse);
|
||||
m_closeFileConfirm.response.connect(this, &StudioUI::handleCloseFileResponse);
|
||||
loadModules();
|
||||
// open project and files
|
||||
@@ -98,14 +125,6 @@ StudioUI::StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexce
|
||||
}
|
||||
|
||||
void StudioUI::handleKeyEvent(turbine::Key const key, bool const down) noexcept {
|
||||
for (auto const p : m_popups) {
|
||||
if (p->isOpen()) {
|
||||
if (key == turbine::Key::Escape) {
|
||||
p->close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (m_activeEditor && !ImGui::IsKeyDown(ImGuiKey_ModCtrl)) {
|
||||
m_activeEditor->keyStateChanged(key, down);
|
||||
}
|
||||
@@ -138,14 +157,9 @@ void StudioUI::draw() noexcept {
|
||||
ImGui::SameLine();
|
||||
}
|
||||
drawTabBar();
|
||||
for (auto const&w : m_widgets) {
|
||||
for (auto const w : m_widgets) {
|
||||
w->draw(m_sctx);
|
||||
}
|
||||
for (auto const p : m_popups) {
|
||||
p->draw(m_sctx);
|
||||
}
|
||||
m_closeFileConfirm.draw(m_sctx);
|
||||
m_copyFilePopup.draw(m_sctx);
|
||||
}
|
||||
ImGui::End();
|
||||
handleKeyInput();
|
||||
@@ -153,48 +167,77 @@ void StudioUI::draw() noexcept {
|
||||
procFileMoves();
|
||||
}
|
||||
|
||||
bool StudioUI::handleShutdown() noexcept {
|
||||
auto const out = ox::all_of(m_editors.begin(), m_editors.end(), [](ox::UPtr<BaseEditor> const &e) {
|
||||
return !e->unsavedChanges();
|
||||
});
|
||||
if (!out) {
|
||||
m_closeAppConfirm.open();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void StudioUI::drawMenu() noexcept {
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("New...", "Ctrl+N", false, m_project)) {
|
||||
if (ImGui::MenuItem("New...", STUDIO_CTRL "+N", false, m_project)) {
|
||||
m_newMenu.open();
|
||||
}
|
||||
if (ImGui::MenuItem("New Project...", "Ctrl+Shift+N")) {
|
||||
if (ImGui::MenuItem("New Project...", STUDIO_CTRL "+Shift+N")) {
|
||||
m_newProject.open();
|
||||
}
|
||||
if (ImGui::MenuItem("Open Project...", "Ctrl+O")) {
|
||||
if (ImGui::MenuItem("Open Project...", STUDIO_CTRL "+O")) {
|
||||
m_taskRunner.add(*ox::make<FileDialogManager>(this, &StudioUI::openProjectPath));
|
||||
}
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S", false, m_activeEditor && m_activeEditor->unsavedChanges())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Save",
|
||||
STUDIO_CTRL "+S",
|
||||
false,
|
||||
m_activeEditor && m_activeEditor->unsavedChanges())) {
|
||||
m_activeEditor->save();
|
||||
}
|
||||
if (ImGui::MenuItem("Quit", "Ctrl+Q")) {
|
||||
if (ImGui::MenuItem("Quit", STUDIO_CTRL "+Q")) {
|
||||
turbine::requestShutdown(m_tctx);
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("Edit")) {
|
||||
auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
|
||||
if (ImGui::MenuItem("Undo", "Ctrl+Z", false, undoStack && undoStack->canUndo())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Undo", STUDIO_CTRL "+Z", false, undoStack && undoStack->canUndo())) {
|
||||
oxLogError(undoStack->undo());
|
||||
}
|
||||
if (ImGui::MenuItem("Redo", "Ctrl+Y", false, undoStack && undoStack->canRedo())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Redo", STUDIO_CTRL "+Y", false, undoStack && undoStack->canRedo())) {
|
||||
oxLogError(undoStack->redo());
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Copy", "Ctrl+C", false, m_activeEditor && m_activeEditor->copyEnabled())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Copy",
|
||||
STUDIO_CTRL "+C",
|
||||
false,
|
||||
m_activeEditor && m_activeEditor->copyEnabled())) {
|
||||
m_activeEditor->copy();
|
||||
}
|
||||
if (ImGui::MenuItem("Cut", "Ctrl+X", false, m_activeEditor && m_activeEditor->cutEnabled())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Cut",
|
||||
STUDIO_CTRL "+X",
|
||||
false,
|
||||
m_activeEditor && m_activeEditor->cutEnabled())) {
|
||||
m_activeEditor->cut();
|
||||
}
|
||||
if (ImGui::MenuItem("Paste", "Ctrl+V", false, m_activeEditor && m_activeEditor->pasteEnabled())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Paste",
|
||||
STUDIO_CTRL "+V",
|
||||
false,
|
||||
m_activeEditor && m_activeEditor->pasteEnabled())) {
|
||||
m_activeEditor->paste();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("View")) {
|
||||
if (ImGui::MenuItem("Project Explorer", "Ctrl+Shift+1", m_showProjectExplorer)) {
|
||||
if (ImGui::MenuItem(
|
||||
"Project Explorer", STUDIO_CTRL "+Shift+1", m_showProjectExplorer)) {
|
||||
toggleProjectExplorer();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
@@ -260,12 +303,8 @@ void StudioUI::drawTabs() noexcept {
|
||||
if (m_activeEditor == (*it).get()) {
|
||||
m_activeEditor = nullptr;
|
||||
}
|
||||
try {
|
||||
OX_THROW_ERROR(m_editors.erase(it).moveTo(it));
|
||||
} catch (ox::Exception const&ex) {
|
||||
oxErrf("Editor tab deletion failed: {} ({}:{})\n", ex.what(), ex.src.file_name(), ex.src.line());
|
||||
} catch (std::exception const&ex) {
|
||||
oxErrf("Editor tab deletion failed: {}\n", ex.what());
|
||||
if (auto const err = m_editors.erase(it).moveTo(it)) {
|
||||
oxErrf("Editor tab deletion failed: {} ({}:{})\n", toStr(err), err.src.file_name(), err.src.line());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -460,12 +499,25 @@ ox::Error StudioUI::createOpenProject(ox::StringViewCR path) noexcept {
|
||||
|
||||
ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
|
||||
OX_REQUIRE_M(fs, keel::loadRomFs(path.view()));
|
||||
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_tctx), std::move(fs)));
|
||||
keel::DuplicateSet ds;
|
||||
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_tctx), std::move(fs), ds));
|
||||
if (ds.size()) {
|
||||
ox::String msg;
|
||||
msg += "Multiple files have the same UUID:\n";
|
||||
for (auto const &k : ds.keys()) {
|
||||
msg += ox::sfmt("\n\t{}:\n", k.toString());
|
||||
for (auto const &v : ds[k]) {
|
||||
msg += ox::sfmt("\t\t - {}\n", v);
|
||||
}
|
||||
}
|
||||
m_messagePopup.show(msg);
|
||||
}
|
||||
OX_RETURN_ERROR(
|
||||
ox::make_unique_catch<Project>(keelCtx(m_tctx), std::move(path), m_projectDataDir)
|
||||
.moveTo(m_project));
|
||||
m_sctx.project = m_project.get();
|
||||
turbine::setWindowTitle(m_tctx, ox::sfmt("{} - {}", keelCtx(m_tctx).appName, m_project->projectPath()));
|
||||
turbine::setWindowTitle(
|
||||
m_tctx, ox::sfmt("{} - {}", keelCtx(m_tctx).appName, m_project->projectPath()));
|
||||
m_deleteConfirmation.deleteFile.connect(m_sctx.project, &Project::deleteItem);
|
||||
m_copyFilePopup.makeCopy.connect(m_sctx.project, &Project::copyItem);
|
||||
m_newDirDialog.newDir.connect(m_sctx.project, &Project::mkdir);
|
||||
@@ -534,6 +586,13 @@ ox::Error StudioUI::makeCopyDlg(ox::StringViewCR path) noexcept {
|
||||
return m_copyFilePopup.open(path);
|
||||
}
|
||||
|
||||
ox::Error StudioUI::handleCloseAppResponse(ig::PopupResponse const response) noexcept {
|
||||
if (response == ig::PopupResponse::OK && m_activeEditor) {
|
||||
turbine::requestShutdown(m_tctx, true);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error StudioUI::handleCloseFileResponse(ig::PopupResponse const response) noexcept {
|
||||
if (response == ig::PopupResponse::OK && m_activeEditor) {
|
||||
return closeCurrentFile();
|
||||
|
||||
@@ -29,13 +29,12 @@ class StudioUI: public ox::SignalHandler {
|
||||
friend class StudioUIDrawer;
|
||||
|
||||
private:
|
||||
StudioContext m_sctx;
|
||||
Context m_sctx;
|
||||
turbine::Context &m_tctx;
|
||||
ox::String m_projectDataDir;
|
||||
ox::UPtr<Project> m_project;
|
||||
TaskRunner m_taskRunner;
|
||||
ox::Vector<ox::UPtr<BaseEditor>> m_editors;
|
||||
ox::Vector<ox::UPtr<Widget>> m_widgets;
|
||||
ox::HashMap<ox::String, EditorMaker::Func> m_editorMakers;
|
||||
ProjectExplorer m_projectExplorer;
|
||||
ox::Vector<ox::String> m_openFiles;
|
||||
@@ -49,17 +48,26 @@ class StudioUI: public ox::SignalHandler {
|
||||
DeleteConfirmation m_deleteConfirmation;
|
||||
NewDir m_newDirDialog;
|
||||
ig::QuestionPopup m_closeFileConfirm{"Close File?", "This file has unsaved changes. Close?"};
|
||||
ig::QuestionPopup m_closeAppConfirm{
|
||||
"Close Application?",
|
||||
"There are files with unsaved changes. Close?"
|
||||
};
|
||||
ig::MessagePopup m_messagePopup{"Message", ""};
|
||||
MakeCopyPopup m_copyFilePopup;
|
||||
RenameFile m_renameFile;
|
||||
NewProject m_newProject;
|
||||
AboutPopup m_aboutPopup;
|
||||
ox::Array<Popup*, 6> const m_popups = {
|
||||
ox::Array<Widget*, 10> const m_widgets {
|
||||
&m_closeFileConfirm,
|
||||
&m_closeAppConfirm,
|
||||
&m_copyFilePopup,
|
||||
&m_newMenu,
|
||||
&m_newProject,
|
||||
&m_aboutPopup,
|
||||
&m_deleteConfirmation,
|
||||
&m_newDirDialog,
|
||||
&m_renameFile,
|
||||
&m_messagePopup,
|
||||
};
|
||||
bool m_showProjectExplorer = true;
|
||||
struct NavAction {
|
||||
@@ -80,6 +88,8 @@ class StudioUI: public ox::SignalHandler {
|
||||
return m_project.get();
|
||||
}
|
||||
|
||||
bool handleShutdown() noexcept;
|
||||
|
||||
protected:
|
||||
void draw() noexcept;
|
||||
|
||||
@@ -128,6 +138,8 @@ class StudioUI: public ox::SignalHandler {
|
||||
|
||||
ox::Error makeCopyDlg(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error handleCloseAppResponse(ig::PopupResponse response) noexcept;
|
||||
|
||||
ox::Error handleCloseFileResponse(ig::PopupResponse response) noexcept;
|
||||
|
||||
ox::Error closeCurrentFile() noexcept;
|
||||
|
||||
@@ -14,19 +14,19 @@ namespace studio {
|
||||
|
||||
class StudioUI;
|
||||
|
||||
struct StudioContext {
|
||||
struct Context {
|
||||
StudioUI &ui;
|
||||
Project *project = nullptr;
|
||||
turbine::Context &tctx;
|
||||
StudioContext(StudioUI &pUi, turbine::Context &pTctx) noexcept:
|
||||
Context(StudioUI &pUi, turbine::Context &pTctx) noexcept:
|
||||
ui(pUi), tctx(pTctx) {}
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
inline keel::Context &keelCtx(StudioContext &ctx) noexcept {
|
||||
inline keel::Context &keelCtx(Context &ctx) noexcept {
|
||||
return keelCtx(ctx.tctx);
|
||||
}
|
||||
|
||||
void navigateTo(StudioContext &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept;
|
||||
void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept;
|
||||
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ class Editor: public studio::BaseEditor {
|
||||
ox::String m_itemName;
|
||||
|
||||
public:
|
||||
Editor(StudioContext &ctx, ox::StringParam itemPath) noexcept;
|
||||
Editor(Context &ctx, ox::StringParam itemPath) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::CStringView itemPath() const noexcept final;
|
||||
|
||||
@@ -31,7 +31,7 @@ class FilePickerPopup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept;
|
||||
|
||||
ox::Optional<ox::String> draw(StudioContext &ctx) noexcept;
|
||||
ox::Optional<ox::String> draw(Context &ctx) noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class FileExplorer: public ox::SignalHandler {
|
||||
m_kctx{kctx},
|
||||
m_fileDraggable{fileDraggable} {}
|
||||
|
||||
void draw(StudioContext &ctx, ImVec2 const &sz) const noexcept;
|
||||
void draw(Context &ctx, ImVec2 const &sz) const noexcept;
|
||||
|
||||
void setModel(ox::UPtr<FileTreeModel> &&model, bool selectRoot = false) noexcept;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/widget.hpp>
|
||||
|
||||
namespace studio::ig {
|
||||
|
||||
@@ -168,7 +169,9 @@ TextInput<ox::IString<MaxChars>> InputText(
|
||||
out.changed = ImGui::InputText(
|
||||
label.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data);
|
||||
if (out.changed) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str()));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -185,7 +188,9 @@ TextInput<ox::IString<MaxChars>> InputTextWithHint(
|
||||
out.changed = ImGui::InputTextWithHint(
|
||||
label.c_str(), hint.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data);
|
||||
if (out.changed) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str()));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -200,7 +205,9 @@ bool InputText(
|
||||
auto const out = ImGui::InputText(
|
||||
label.c_str(), text.data(), StrCap + 1, flags, callback, user_data);
|
||||
if (out) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = text.unsafeResize(ox::strlen(text.c_str()));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -222,6 +229,10 @@ PopupResponse PopupControlsOkCancel(
|
||||
ox::CStringViewCR ok = "OK",
|
||||
ox::CStringViewCR cancel = "Cancel");
|
||||
|
||||
PopupResponse PopupControlsOk(
|
||||
bool &popupOpen,
|
||||
ox::CStringViewCR ok);
|
||||
|
||||
[[nodiscard]]
|
||||
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz = {285, 0});
|
||||
|
||||
@@ -249,7 +260,7 @@ bool ComboBox(ox::CStringView lbl, ox::Span<const ox::String> list, size_t &sele
|
||||
/**
|
||||
*
|
||||
* @param lbl
|
||||
* @param callback
|
||||
* @param f callback function
|
||||
* @param selectedIdx
|
||||
* @return true if new value selected, false otherwise
|
||||
*/
|
||||
@@ -261,7 +272,7 @@ bool ComboBox(
|
||||
|
||||
bool FileComboBox(
|
||||
ox::CStringViewCR lbl,
|
||||
StudioContext &sctx,
|
||||
Context &sctx,
|
||||
ox::StringViewCR fileExt,
|
||||
size_t &selectedIdx) noexcept;
|
||||
|
||||
@@ -284,7 +295,7 @@ bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::String> const&list, size_t
|
||||
class FilePicker {
|
||||
private:
|
||||
bool m_show{};
|
||||
studio::StudioContext &m_sctx;
|
||||
Context &m_sctx;
|
||||
ox::String const m_title;
|
||||
ox::String const m_fileExt;
|
||||
ImVec2 const m_size;
|
||||
@@ -292,7 +303,7 @@ class FilePicker {
|
||||
ox::Signal<ox::Error(ox::StringView)> filePicked;
|
||||
|
||||
FilePicker(
|
||||
studio::StudioContext &sctx,
|
||||
studio::Context &sctx,
|
||||
ox::StringParam title,
|
||||
ox::StringParam fileExt,
|
||||
ImVec2 const&size = {}) noexcept;
|
||||
@@ -303,8 +314,8 @@ class FilePicker {
|
||||
|
||||
};
|
||||
|
||||
class QuestionPopup {
|
||||
private:
|
||||
class Popup: public Widget {
|
||||
protected:
|
||||
enum class Stage {
|
||||
Closed,
|
||||
Opening,
|
||||
@@ -313,12 +324,11 @@ class QuestionPopup {
|
||||
Stage m_stage = Stage::Closed;
|
||||
bool m_open{};
|
||||
ox::String m_title;
|
||||
ox::String m_question;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(ig::PopupResponse)> response;
|
||||
ox::Signal<ox::Error(PopupResponse)> response;
|
||||
|
||||
QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept;
|
||||
explicit Popup(ox::StringParam title) noexcept;
|
||||
|
||||
void open() noexcept;
|
||||
|
||||
@@ -327,7 +337,33 @@ class QuestionPopup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept;
|
||||
|
||||
void draw(StudioContext &ctx, ImVec2 const &sz = {}) noexcept;
|
||||
};
|
||||
|
||||
class QuestionPopup: public Popup {
|
||||
private:
|
||||
ox::String m_question;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(PopupResponse)> response;
|
||||
|
||||
QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept;
|
||||
|
||||
void draw(Context &ctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
class MessagePopup: public Popup {
|
||||
private:
|
||||
ox::String m_msg;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(PopupResponse)> response;
|
||||
|
||||
MessagePopup(ox::StringParam title, ox::StringParam msg) noexcept;
|
||||
|
||||
void show(ox::StringParam msg) noexcept;
|
||||
|
||||
void draw(Context &ctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ class ItemMaker {
|
||||
* @return path of file or error in Result
|
||||
*/
|
||||
ox::Error write(
|
||||
StudioContext &ctx,
|
||||
Context &ctx,
|
||||
ox::StringViewCR pPath,
|
||||
size_t pTemplateIdx) const noexcept {
|
||||
return writeItem(ctx, pPath, pTemplateIdx);
|
||||
@@ -177,7 +177,7 @@ class ItemMaker {
|
||||
* @return path of file or error in Result
|
||||
*/
|
||||
ox::Error write(
|
||||
StudioContext &ctx,
|
||||
Context &ctx,
|
||||
ox::StringViewCR pPath,
|
||||
ox::StringViewCR pName,
|
||||
size_t pTemplateIdx) const noexcept {
|
||||
@@ -187,7 +187,7 @@ class ItemMaker {
|
||||
|
||||
protected:
|
||||
virtual ox::Error writeItem(
|
||||
StudioContext &ctx,
|
||||
Context &ctx,
|
||||
ox::StringViewCR pPath,
|
||||
size_t pTemplateIdx) const noexcept = 0;
|
||||
|
||||
@@ -249,7 +249,7 @@ class ItemMakerT final: public ItemMaker {
|
||||
}
|
||||
|
||||
ox::Error writeItem(
|
||||
StudioContext &ctx,
|
||||
Context &ctx,
|
||||
ox::StringViewCR pPath,
|
||||
size_t const pTemplateIdx) const noexcept override {
|
||||
createUuidMapping(keelCtx(ctx.tctx), pPath, ox::UUID::generate().unwrap());
|
||||
|
||||
@@ -27,17 +27,17 @@ class Module {
|
||||
public:
|
||||
virtual ~Module() noexcept = default;
|
||||
|
||||
virtual ox::Vector<EditorMaker> editors(studio::StudioContext &ctx) const;
|
||||
virtual ox::Vector<EditorMaker> editors(studio::Context &ctx) const;
|
||||
|
||||
virtual ox::Vector<ox::UPtr<ItemMaker>> itemMakers(studio::StudioContext&) const;
|
||||
virtual ox::Vector<ox::UPtr<ItemMaker>> itemMakers(studio::Context&) const;
|
||||
|
||||
virtual ox::Vector<ox::UPtr<ItemTemplate>> itemTemplates(studio::StudioContext&) const;
|
||||
virtual ox::Vector<ox::UPtr<ItemTemplate>> itemTemplates(studio::Context&) const;
|
||||
|
||||
};
|
||||
|
||||
template<typename Editor>
|
||||
[[nodiscard]]
|
||||
EditorMaker editorMaker(StudioContext &ctx, ox::StringParam ext) noexcept {
|
||||
EditorMaker editorMaker(Context &ctx, ox::StringParam ext) noexcept {
|
||||
return {
|
||||
{std::move(ext)},
|
||||
[&ctx](ox::StringViewCR path) -> ox::Result<BaseEditor*> {
|
||||
@@ -48,7 +48,7 @@ EditorMaker editorMaker(StudioContext &ctx, ox::StringParam ext) noexcept {
|
||||
|
||||
template<typename Editor>
|
||||
[[nodiscard]]
|
||||
EditorMaker editorMaker(StudioContext &ctx, std::initializer_list<ox::StringView> exts) noexcept {
|
||||
EditorMaker editorMaker(Context &ctx, std::initializer_list<ox::StringView> exts) noexcept {
|
||||
return {
|
||||
[&exts] {
|
||||
ox::Vector<ox::String> fileTypes;
|
||||
|
||||
@@ -12,10 +12,12 @@
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
|
||||
#include "widget.hpp"
|
||||
|
||||
namespace studio {
|
||||
|
||||
|
||||
class Popup {
|
||||
class Popup: public Widget {
|
||||
private:
|
||||
ox::Vec2 m_size;
|
||||
ox::String m_title;
|
||||
@@ -23,7 +25,7 @@ class Popup {
|
||||
// emits path parameter
|
||||
ox::Signal<ox::Error(ox::String const&)> finished;
|
||||
|
||||
virtual ~Popup() noexcept = default;
|
||||
~Popup() noexcept override = default;
|
||||
|
||||
virtual void open() noexcept = 0;
|
||||
|
||||
@@ -32,8 +34,6 @@ class Popup {
|
||||
[[nodiscard]]
|
||||
virtual bool isOpen() const noexcept = 0;
|
||||
|
||||
virtual void draw(studio::StudioContext &ctx) noexcept = 0;
|
||||
|
||||
protected:
|
||||
constexpr void setSize(ox::Size sz) noexcept {
|
||||
m_size = {static_cast<float>(sz.width), static_cast<float>(sz.height)};
|
||||
|
||||
@@ -24,7 +24,7 @@ class Task: public ox::SignalHandler {
|
||||
|
||||
class TaskRunner {
|
||||
private:
|
||||
ox::Vector<ox::UniquePtr<studio::Task>> m_tasks;
|
||||
ox::Vector<ox::UPtr<studio::Task>> m_tasks;
|
||||
public:
|
||||
void update(turbine::Context &ctx) noexcept;
|
||||
void add(Task &task) noexcept;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace studio {
|
||||
class Widget: public ox::SignalHandler {
|
||||
public:
|
||||
~Widget() noexcept override = default;
|
||||
virtual void draw(studio::StudioContext&) noexcept = 0;
|
||||
virtual void draw(Context&) noexcept = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ UndoStack *BaseEditor::undoStack() noexcept {
|
||||
void BaseEditor::navigateTo(ox::StringViewCR) noexcept {}
|
||||
|
||||
|
||||
Editor::Editor(StudioContext &ctx, ox::StringParam itemPath) noexcept:
|
||||
Editor::Editor(Context &ctx, ox::StringParam itemPath) noexcept:
|
||||
m_itemPath(std::move(itemPath)),
|
||||
m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)) {
|
||||
m_undoStack.changeTriggered.connect(this, &Editor::markUnsavedChanges);
|
||||
|
||||
@@ -12,10 +12,12 @@
|
||||
namespace studio {
|
||||
|
||||
FDFilterItem::FDFilterItem(ox::StringViewCR pName, ox::StringViewCR pSpec) noexcept {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
name.resize(pName.len() + 1);
|
||||
ox::strncpy(name.data(), pName.data(), pName.len());
|
||||
spec.resize(pSpec.len() + 1);
|
||||
ox::strncpy(spec.data(), pSpec.data(), pSpec.len());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
|
||||
static ox::Result<ox::String> toResult(nfdresult_t r, NFD::UniquePathN const&path) noexcept {
|
||||
|
||||
@@ -52,7 +52,7 @@ bool FilePickerPopup::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
ox::Optional<ox::String> FilePickerPopup::draw(StudioContext &ctx) noexcept {
|
||||
ox::Optional<ox::String> FilePickerPopup::draw(Context &ctx) noexcept {
|
||||
ox::Optional<ox::String> out;
|
||||
if (!m_open) {
|
||||
return out;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
void FileExplorer::draw(StudioContext &ctx, ImVec2 const &sz) const noexcept {
|
||||
void FileExplorer::draw(Context &ctx, ImVec2 const &sz) const noexcept {
|
||||
ImGui::BeginChild("ProjectExplorer", sz, true);
|
||||
ImGui::SetNextItemOpen(true);
|
||||
if (m_treeModel) {
|
||||
|
||||
@@ -82,6 +82,25 @@ PopupResponse PopupControlsOkCancel(
|
||||
return PopupControlsOkCancel(ImGui::GetContentRegionAvail().x + 17, popupOpen, ok, cancel);
|
||||
}
|
||||
|
||||
PopupResponse PopupControlsOk(
|
||||
bool &popupOpen,
|
||||
ox::CStringViewCR ok) {
|
||||
auto out = PopupResponse::None;
|
||||
constexpr auto btnSz = ImVec2{50, BtnSz.y};
|
||||
ImGui::Separator();
|
||||
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 42);
|
||||
if (ImGui::Button(ok.c_str(), btnSz)) {
|
||||
popupOpen = false;
|
||||
out = PopupResponse::OK;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::IsKeyDown(ImGuiKey_Escape)) {
|
||||
popupOpen = false;
|
||||
out = PopupResponse::Cancel;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz) {
|
||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||
centerNextWindow(ctx);
|
||||
@@ -150,7 +169,7 @@ bool ComboBox(
|
||||
|
||||
bool FileComboBox(
|
||||
ox::CStringViewCR lbl,
|
||||
StudioContext &sctx,
|
||||
Context &sctx,
|
||||
ox::StringViewCR fileExt,
|
||||
size_t &selectedIdx) noexcept {
|
||||
auto const&list = sctx.project->fileList(fileExt);
|
||||
@@ -194,7 +213,7 @@ bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::CStringView> const&list, s
|
||||
|
||||
|
||||
FilePicker::FilePicker(
|
||||
StudioContext &sctx,
|
||||
Context &sctx,
|
||||
ox::StringParam title,
|
||||
ox::StringParam fileExt,
|
||||
ImVec2 const&size) noexcept:
|
||||
@@ -226,25 +245,29 @@ void FilePicker::show() noexcept {
|
||||
}
|
||||
|
||||
|
||||
QuestionPopup::QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept:
|
||||
m_title{std::move(title)},
|
||||
m_question{std::move(question)} {
|
||||
Popup::Popup(ox::StringParam title) noexcept: m_title{std::move(title)} {
|
||||
}
|
||||
|
||||
void QuestionPopup::open() noexcept {
|
||||
void Popup::open() noexcept {
|
||||
m_stage = Stage::Opening;
|
||||
}
|
||||
|
||||
void QuestionPopup::close() noexcept {
|
||||
void Popup::close() noexcept {
|
||||
m_stage = Stage::Closed;
|
||||
m_open = false;
|
||||
}
|
||||
|
||||
bool QuestionPopup::isOpen() const noexcept {
|
||||
bool Popup::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void QuestionPopup::draw(StudioContext &ctx, ImVec2 const &sz) noexcept {
|
||||
|
||||
QuestionPopup::QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept:
|
||||
Popup{std::move(title)},
|
||||
m_question{std::move(question)} {
|
||||
}
|
||||
|
||||
void QuestionPopup::draw(Context &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
@@ -255,7 +278,7 @@ void QuestionPopup::draw(StudioContext &ctx, ImVec2 const &sz) noexcept {
|
||||
[[fallthrough]];
|
||||
case Stage::Open:
|
||||
centerNextWindow(ctx.tctx);
|
||||
ImGui::SetNextWindowSize(static_cast<ImVec2>(sz));
|
||||
ImGui::SetNextWindowSize({});
|
||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
|
||||
ImGui::Text("%s", m_question.c_str());
|
||||
@@ -279,6 +302,49 @@ void QuestionPopup::draw(StudioContext &ctx, ImVec2 const &sz) noexcept {
|
||||
}
|
||||
|
||||
|
||||
MessagePopup::MessagePopup(ox::StringParam title, ox::StringParam msg) noexcept:
|
||||
Popup{std::move(title)},
|
||||
m_msg{std::move(msg)} {
|
||||
}
|
||||
|
||||
void MessagePopup::show(ox::StringParam msg) noexcept {
|
||||
m_msg = std::move(msg);
|
||||
open();
|
||||
}
|
||||
|
||||
void MessagePopup::draw(Context &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
case Stage::Opening:
|
||||
ImGui::OpenPopup(m_title.c_str());
|
||||
m_stage = Stage::Open;
|
||||
m_open = true;
|
||||
[[fallthrough]];
|
||||
case Stage::Open:
|
||||
centerNextWindow(ctx.tctx);
|
||||
ImGui::SetNextWindowSize({});
|
||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
|
||||
ImGui::Text("%s", m_msg.c_str());
|
||||
auto const r = PopupControlsOk(m_open, "OK");
|
||||
switch (r) {
|
||||
case PopupResponse::None:
|
||||
break;
|
||||
case PopupResponse::OK:
|
||||
response.emit(r);
|
||||
close();
|
||||
break;
|
||||
case PopupResponse::Cancel:
|
||||
break;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool s_mainWinHasFocus{};
|
||||
bool mainWinHasFocus() noexcept {
|
||||
return s_mainWinHasFocus;
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
ox::Vector<EditorMaker> Module::editors(StudioContext&) const {
|
||||
ox::Vector<EditorMaker> Module::editors(Context&) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UPtr<ItemMaker>> Module::itemMakers(StudioContext&) const {
|
||||
ox::Vector<ox::UPtr<ItemMaker>> Module::itemMakers(Context&) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Vector<ox::UPtr<ItemTemplate>> Module::itemTemplates(StudioContext&) const {
|
||||
ox::Vector<ox::UPtr<ItemTemplate>> Module::itemTemplates(Context&) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ class Context;
|
||||
|
||||
void safeDelete(Context *p);
|
||||
|
||||
void shutdown(Context &ctx) noexcept;
|
||||
|
||||
keel::Context const&keelCtx(Context const&ctx) noexcept;
|
||||
|
||||
keel::Context &keelCtx(Context &ctx) noexcept;
|
||||
|
||||
@@ -27,6 +27,10 @@ ox::Error run(Context &ctx) noexcept;
|
||||
[[nodiscard]]
|
||||
TimeMs ticksMs(Context const&ctx) noexcept;
|
||||
|
||||
void requestShutdown(Context &ctx) noexcept;
|
||||
void requestShutdown(Context &ctx, bool force = false) noexcept;
|
||||
|
||||
using ShutdownHandler = bool (*)(Context&);
|
||||
|
||||
void setShutdownHandler(Context &ctx, ShutdownHandler handler) noexcept;
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace turbine {
|
||||
|
||||
class Context {
|
||||
class Context final {
|
||||
public:
|
||||
UpdateHandler updateHandler = [](Context&) -> int {return 0;};
|
||||
keel::Context keelCtx;
|
||||
@@ -27,10 +27,6 @@ class Context {
|
||||
Context(Context const&other) noexcept = delete;
|
||||
Context(Context const&&other) noexcept = delete;
|
||||
|
||||
virtual inline ~Context() noexcept {
|
||||
shutdown(*this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -44,10 +44,10 @@ static ox::Result<std::size_t> findPreloadSection() noexcept {
|
||||
// media section
|
||||
constexpr auto headerP2 = "DER_____________";
|
||||
constexpr auto headerP1 = "KEEL_PRELOAD_HEA";
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
constexpr auto headerP1Len = ox::strlen(headerP2);
|
||||
constexpr auto headerP2Len = ox::strlen(headerP1);
|
||||
constexpr auto headerLen = headerP1Len + headerP2Len;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
for (auto current = MEM_ROM; current < reinterpret_cast<char*>(0x0a000000); current += headerLen) {
|
||||
if (memcmp(current, headerP1, headerP1Len) == 0 &&
|
||||
memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) {
|
||||
@@ -82,8 +82,11 @@ bool buttonDown(Context const&, Key k) noexcept {
|
||||
return k <= Key::GamePad_L && !(REG_GAMEPAD & (1 << static_cast<int>(k)));
|
||||
}
|
||||
|
||||
void requestShutdown(Context &ctx) noexcept {
|
||||
void requestShutdown(Context &ctx, bool) noexcept {
|
||||
ctx.running = false;
|
||||
}
|
||||
|
||||
void setShutdownHandler(Context&, ShutdownHandler) noexcept {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ ox::String getClipboardText(Context &ctx) noexcept {
|
||||
|
||||
void setClipboardText(Context &ctx, ox::StringViewCR text) noexcept {
|
||||
auto cstr = ox_malloca(text.bytes() + 1, char);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::strncpy(cstr.get(), text.data(), text.bytes());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
glfwSetClipboardString(ctx.window, cstr.get());
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ class Context {
|
||||
uint64_t keysDown = 0;
|
||||
uint64_t prevFpsCheckTime = 0;
|
||||
uint64_t draws = 0;
|
||||
bool running{};
|
||||
ShutdownHandler shutdownHandler{};
|
||||
|
||||
Context() noexcept = default;
|
||||
|
||||
|
||||
@@ -93,6 +93,14 @@ static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int
|
||||
}
|
||||
}
|
||||
|
||||
static void handleGlfwWindowCloseEvent(GLFWwindow *window) noexcept {
|
||||
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
|
||||
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
|
||||
ctx.running = ctx.shutdownHandler ? !ctx.shutdownHandler(ctx) : false;
|
||||
glfwSetWindowShouldClose(window, !ctx.running);
|
||||
glfwPostEmptyEvent();
|
||||
}
|
||||
|
||||
#if TURBINE_USE_IMGUI
|
||||
static void themeImgui() noexcept {
|
||||
// Dark Ruda style by Raikiri from ImThemes
|
||||
@@ -210,6 +218,7 @@ ox::Error initGfx(Context &ctx) noexcept {
|
||||
glfwSetCursorPosCallback(ctx.window, handleGlfwCursorPosEvent);
|
||||
glfwSetMouseButtonCallback(ctx.window, handleGlfwMouseButtonEvent);
|
||||
glfwSetKeyCallback(ctx.window, handleGlfwKeyEvent);
|
||||
glfwSetWindowCloseCallback(ctx.window, handleGlfwWindowCloseEvent);
|
||||
glfwSetWindowUserPointer(ctx.window, &ctx);
|
||||
glfwMakeContextCurrent(ctx.window);
|
||||
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress))) {
|
||||
@@ -235,6 +244,7 @@ struct IconData {
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
[[maybe_unused]]
|
||||
static ox::Result<IconData> toGlfwImgPixels(ox::SpanView<uint8_t> const &iconPng) noexcept {
|
||||
ox::Result<IconData> out;
|
||||
unsigned w{}, h{};
|
||||
@@ -247,24 +257,28 @@ static ox::Result<IconData> toGlfwImgPixels(ox::SpanView<uint8_t> const &iconPng
|
||||
}
|
||||
|
||||
ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept {
|
||||
ox::Vector<IconData, 8> src;
|
||||
ox::Vector<GLFWimage, 8> imgs;
|
||||
for (auto const &iconPng : iconPngs) {
|
||||
OX_RETURN_ERROR(toGlfwImgPixels(iconPng).moveTo(src.emplace_back()));
|
||||
auto &icon = *src.back().unwrap();
|
||||
imgs.emplace_back(GLFWimage{
|
||||
.width = icon.w,
|
||||
.height = icon.h,
|
||||
.pixels = icon.pixels.data(),
|
||||
});
|
||||
if constexpr(ox::defines::OS != ox::OS::Darwin) {
|
||||
ox::Vector<IconData, 8> src;
|
||||
ox::Vector<GLFWimage, 8> imgs;
|
||||
for (auto const &iconPng : iconPngs) {
|
||||
OX_RETURN_ERROR(toGlfwImgPixels(iconPng).moveTo(src.emplace_back()));
|
||||
auto &icon = *src.back().unwrap();
|
||||
imgs.emplace_back(GLFWimage{
|
||||
.width = icon.w,
|
||||
.height = icon.h,
|
||||
.pixels = icon.pixels.data(),
|
||||
});
|
||||
}
|
||||
glfwSetWindowIcon(ctx.window, static_cast<int>(imgs.size()), imgs.data());
|
||||
}
|
||||
glfwSetWindowIcon(ctx.window, static_cast<int>(imgs.size()), imgs.data());
|
||||
return {};
|
||||
}
|
||||
|
||||
void setWindowTitle(Context &ctx, ox::StringViewCR title) noexcept {
|
||||
auto cstr = ox_malloca(title.bytes() + 1, char);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::strncpy(cstr.get(), title.data(), title.bytes());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
glfwSetWindowTitle(ctx.window, cstr.get());
|
||||
}
|
||||
|
||||
|
||||
@@ -68,9 +68,21 @@ static void tickFps(Context &ctx, uint64_t const nowMs) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
static void shutdown(Context &ctx) noexcept {
|
||||
if (ctx.window) {
|
||||
#if TURBINE_USE_IMGUI
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
#endif
|
||||
glfwDestroyWindow(ctx.window);
|
||||
ctx.window = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error run(Context &ctx) noexcept {
|
||||
uint64_t sleepTime = 0;
|
||||
while (!glfwWindowShouldClose(ctx.window)) {
|
||||
ctx.running = true;
|
||||
while (ctx.running) {
|
||||
ctx.refreshWithinMs = 10 * 1000; // refresh within 10 seconds
|
||||
glfwPollEvents();
|
||||
auto const ticks = ticksMs(ctx);
|
||||
@@ -80,7 +92,7 @@ ox::Error run(Context &ctx) noexcept {
|
||||
ctx.wakeupTime = ticks + static_cast<unsigned>(st);
|
||||
sleepTime = static_cast<uint64_t>(st);
|
||||
} else {
|
||||
ctx.wakeupTime = ~uint64_t(0);
|
||||
ctx.wakeupTime = ~uint64_t{0};
|
||||
sleepTime = ctx.wakeupTime - ticks;
|
||||
}
|
||||
} else {
|
||||
@@ -97,17 +109,6 @@ ox::Error run(Context &ctx) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
void shutdown(Context &ctx) noexcept {
|
||||
if (ctx.window) {
|
||||
#if TURBINE_USE_IMGUI
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
#endif
|
||||
glfwDestroyWindow(ctx.window);
|
||||
ctx.window = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
TimeMs ticksMs(Context const&ctx) noexcept {
|
||||
using namespace std::chrono;
|
||||
auto const now = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
|
||||
@@ -118,8 +119,17 @@ bool buttonDown(Context const&ctx, Key const key) noexcept {
|
||||
return (ctx.keysDown >> static_cast<int>(key)) & 1;
|
||||
}
|
||||
|
||||
void requestShutdown(Context &ctx) noexcept {
|
||||
void requestShutdown(Context &ctx, bool const force) noexcept {
|
||||
glfwSetWindowShouldClose(ctx.window, true);
|
||||
if (force) {
|
||||
ctx.running = false;
|
||||
} else {
|
||||
ctx.running = ctx.shutdownHandler ? !ctx.shutdownHandler(ctx) : false;
|
||||
}
|
||||
}
|
||||
|
||||
void setShutdownHandler(Context &ctx, ShutdownHandler const handler) noexcept {
|
||||
ctx.shutdownHandler = handler;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user