Compare commits

..

1 Commits

Author SHA1 Message Date
gary 59dbfe0db1 [studio] Cleanup
Build / build (push) Successful in 1m11s
2026-05-17 15:05:44 -05:00
63 changed files with 280 additions and 494 deletions
-1
View File
@@ -1,2 +1 @@
type summary add --summary-string "${var.m_buff.m_items}" ox::String
type summary add --summary-string "${var.m_value.m_buff.m_items}" ox::StringParam
+2 -2
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.25)
cmake_minimum_required(VERSION 3.19)
set(CMAKE_POLICY_DEFAULT_CMP0110 NEW) # requires CMake 3.19
if(BUILDCORE_TARGET STREQUAL "gba")
@@ -52,7 +52,7 @@ if(NOT BUILDCORE_TARGET STREQUAL "gba")
set(GLFW_BUILD_TESTS OFF)
set(GLFW_BUILD_DOCS OFF)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(GLFW_BUILD_WAYLAND ON)
set(GLFW_BUILD_WAYLAND OFF)
endif()
add_subdirectory(deps/glfw)
add_subdirectory(deps/glutils)
+7 -2
View File
@@ -27,8 +27,8 @@ git-push-ox:
git subtree push --prefix=deps/oxlib ox-master master
.PHONY: pkg-gba
pkg-gba: build-studio build-gba-player
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-gba.py ${PROJECT_STUDIO} sample_project ${BC_VAR_PROJECT_NAME_CAP}
pkg-gba: build-pack build-gba-player
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-gba.py sample_project ${BC_VAR_PROJECT_NAME_CAP}
.PHONY: pkg-mac
pkg-mac: install
@@ -47,6 +47,11 @@ build-gba-player:
build-player:
${BC_CMD_CMAKE_BUILD} ${BC_VAR_BUILD_PATH} ${BC_VAR_PROJECT_NAME_CAP}
.PHONY: build-pack
build-pack:
cmake --build ./build/${BC_VAR_CURRENT_BUILD} --target ${BC_VAR_PROJECT_NAME}-pack
.PHONY: run
run: build-player
${PROJECT_PLAYER} sample_project
+2 -1
View File
@@ -129,7 +129,8 @@ Error writeClaw(
if (fmt == ClawFormat::Metal) {
OX_RETURN_ERROR(writeMC(writer, obj));
} else if (fmt == ClawFormat::Organic) {
OX_RETURN_ERROR(writeOC(writer, obj));
OX_REQUIRE(data, writeOC(obj));
OX_RETURN_ERROR(writer.write(data.data(), data.size()));
}
#else
if (fmt != ClawFormat::Metal) {
+1 -3
View File
@@ -28,10 +28,8 @@ String PassThroughFS::basePath() const noexcept {
}
Error PassThroughFS::mkdir(StringViewCR path, bool recursive) noexcept {
auto const cleanPath =
endsWith(path, '/') ? substr(path, 0, path.size() - 1) : path;
bool success = false;
auto p = cleanPath.size() ? m_path / stripSlash(cleanPath) : m_path;
const auto p = m_path / stripSlash(path);
const auto u8p = p.u8string();
oxTrace("ox.fs.PassThroughFS.mkdir", std::bit_cast<const char*>(u8p.c_str()));
if (recursive) {
+1 -1
View File
@@ -282,7 +282,7 @@ Error readOC(BufferView const buff, auto &val) noexcept {
try {
Json::Value doc;
Json::CharReaderBuilder parserBuilder;
auto const parser = UPtr<Json::CharReader>(parserBuilder.newCharReader());
auto parser = UPtr<Json::CharReader>(parserBuilder.newCharReader());
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
if (!parser->parse(buff.data(), buff.data() + buff.size(), &doc, nullptr)) {
OX_ALLOW_UNSAFE_BUFFERS_END
+2 -13
View File
@@ -28,7 +28,6 @@ namespace ox {
class OrganicClawWriter {
friend Error writeOC(Writer_c auto &writer, auto const &val) noexcept;
friend Result<Buffer> writeOC(const auto &val) noexcept;
friend Result<String> writeOCString(const auto &val) noexcept;
@@ -255,19 +254,9 @@ Error OrganicClawWriter::field(CString key, UnionView<U, force> val) noexcept {
return {};
}
Error writeOC(Writer_c auto &writer, auto const &val) noexcept {
OrganicClawWriter ocWriter;
ModelHandlerInterface handler(ocWriter);
OX_RETURN_ERROR(model(&handler, &val));
Json::StreamWriterBuilder const jsonBuilder;
auto const str = Json::writeString(jsonBuilder, ocWriter.m_json);
OX_RETURN_ERROR(writer.write(str.data(), str.size()));
return writer.put('\0');
}
Result<Buffer> writeOC(auto const &val) noexcept {
OrganicClawWriter writer;
ModelHandlerInterface handler(writer);
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(writer);
OX_RETURN_ERROR(model(&handler, &val));
Json::StreamWriterBuilder const jsonBuilder;
auto const str = Json::writeString(jsonBuilder, writer.m_json);
@@ -281,7 +270,7 @@ Result<Buffer> writeOC(auto const &val) noexcept {
Result<String> writeOCString(auto const &val) noexcept {
OrganicClawWriter writer;
ModelHandlerInterface handler(writer);
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(writer);
OX_RETURN_ERROR(model(&handler, &val));
Json::StreamWriterBuilder const jsonBuilder;
auto const str = Json::writeString(jsonBuilder, writer.m_json);
+3 -3
View File
@@ -348,15 +348,15 @@ struct [[nodiscard]] Result {
constexpr Result reoriginate(
ErrorCode const pErrCode,
CString const pMsg = nullptr,
std::source_location const &pSrc = std::source_location::current()) && noexcept {
std::source_location const &pSrc = std::source_location::current()) const && noexcept {
if (error) {
return {std::move(value), Error{pErrCode, pMsg, pSrc}};
}
return {std::move(value)};
return Error{};
}
constexpr Result reoriginate(
std::source_location const &pSrc = std::source_location::current()) && noexcept {
std::source_location const &pSrc = std::source_location::current()) const && noexcept {
return {std::move(value), Error{error.errCode, error.msg, pSrc}};
}
+2 -2
View File
@@ -38,11 +38,11 @@ constexpr StringView substr(StringViewCR str, std::size_t const start, std::size
[[nodiscard]]
constexpr char toUpper(char const c) noexcept {
return c & static_cast<char>(0b1101'1111);
return c & 0b1101'1111;
}
[[nodiscard]]
constexpr int caseInsensitiveStrCmp(StringViewCR a, StringViewCR b) noexcept {
constexpr int caseInsensitiveEquals(ox::StringViewCR a, ox::StringViewCR b) noexcept {
auto const sz = ox::min(a.size(), b.size());
for (size_t i{}; i < sz; ++i) {
auto const ac = toUpper(a[i]);
-14
View File
@@ -54,21 +54,10 @@ struct VectorAllocator {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later
if (!std::is_constant_evaluated()) {
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow="
#endif
if (cap <= m_data.size() && count <= m_data.size()) {
for (auto i = 0u; i < count; ++i) {
auto const srcItem = std::launder(reinterpret_cast<T*>(&src->m_data[i]));
#if defined(__GNUC__) && __GNUC__ >= 12
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow="
#endif
new (&m_data[i]) T(std::move(*srcItem));
#if defined(__GNUC__) && __GNUC__ >= 12
#pragma GCC diagnostic pop
#endif
}
if (count) {
*items = std::launder(reinterpret_cast<T*>(m_data.data()));
@@ -76,9 +65,6 @@ struct VectorAllocator {
*items = reinterpret_cast<T*>(m_data.data());
}
}
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
}
}
+1 -4
View File
@@ -1,9 +1,6 @@
# d2026.05.0
# NEXT
* Add HiDPI support
* Add Get Info file dialog option in project explorer
* Fix Navigate Back to not require a double Forward when going all the way back
* Fix issue with config data not being saved correctly on first run
# d2025.07.0
+1
View File
@@ -41,6 +41,7 @@ if(${NOSTALGIA_BUILD_PLAYER})
endif()
if(NOT BUILDCORE_TARGET STREQUAL "gba")
add_subdirectory(tools)
if(${NOSTALGIA_BUILD_STUDIO_APP})
add_subdirectory(studio)
endif()
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -4,7 +4,7 @@
#pragma once
#include <studio/undocommand.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/palette.hpp>
@@ -45,11 +45,11 @@ OX_MODEL_BEGIN(PageDragDrop)
OX_MODEL_FIELD(page)
OX_MODEL_END()
void PaletteEditorImGui::PageRenameDialog::draw() noexcept {
void PaletteEditorImGui::PageRenameDialog::draw(turbine::Context &tctx) noexcept {
if (!m_show) {
return;
}
if (ig::BeginPopup("Rename Page", m_show)) {
if (ig::BeginPopup(tctx, "Rename Page", m_show)) {
if (ImGui::IsWindowAppearing()) {
ImGui::SetKeyboardFocusHere();
}
@@ -71,26 +71,26 @@ void PaletteEditorImGui::PageRenameDialog::draw() noexcept {
PaletteEditorImGui::PaletteEditorImGui(studio::Context &sctx, ox::StringParam path):
Editor(sctx, std::move(path)),
m_sctx(sctx),
m_tctx(sctx.tctx),
m_pal(m_sctx.project->loadObj<Palette>(itemPath()).unwrapThrow()) {
undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand);
m_pageRenameDlg.inputSubmitted.connect(this, &PaletteEditorImGui::renamePage);
}
void PaletteEditorImGui::draw(studio::Context&) noexcept {
auto const scale = ig::dpiScale();
auto const paneSize = ImGui::GetContentRegionAvail();
{
ImGui::BeginChild("Pages", {scale * 280, paneSize.y}, true);
ImGui::BeginChild("Pages", {280, paneSize.y}, true);
drawPagesEditor();
ImGui::EndChild();
}
ImGui::SameLine();
{
ImGui::BeginChild("Colors", {scale * -1, paneSize.y}, true);
ImGui::BeginChild("Colors", {-1, paneSize.y}, true);
drawColorsEditor();
ImGui::EndChild();
}
m_pageRenameDlg.draw();
m_pageRenameDlg.draw(m_tctx);
}
ox::Error PaletteEditorImGui::saveItem() noexcept {
@@ -165,7 +165,7 @@ void PaletteEditorImGui::drawColorsEditor() noexcept {
static constexpr auto toolbarHeight = 40;
{
auto constexpr sz = ImVec2{70, 24};
if (ig::PushButton("Add", sz)) {
if (ImGui::Button("Add", sz)) {
auto const colorSz = colorCnt(m_pal, m_page);
constexpr Color16 c = 0;
std::ignore = pushCommand<AddColorCommand>(m_pal, c, colorSz);
@@ -173,7 +173,7 @@ void PaletteEditorImGui::drawColorsEditor() noexcept {
ImGui::SameLine();
ImGui::BeginDisabled(m_selectedColorRow >= colorCnt(m_pal, m_page));
{
if (ig::PushButton("Remove", sz)) {
if (ImGui::Button("Remove", sz)) {
std::ignore = pushCommand<RemoveColorCommand>(m_pal, m_selectedColorRow);
m_selectedColorRow = ox::min(colorCnt(m_pal, m_page) - 1, m_selectedColorRow);
colorEditor = m_selectedColorRow < colorCnt(m_pal, m_page);
@@ -183,18 +183,17 @@ void PaletteEditorImGui::drawColorsEditor() noexcept {
}
auto const tblWidth = (colorsSz.x - static_cast<float>(colorEditorWidth) - 8.f)
* static_cast<float>(colorEditor);
auto const scale = ig::dpiScale();
ImGui::BeginTable(
"Colors",
6,
tableFlags,
{tblWidth * scale, colorsSz.y - (toolbarHeight + 5) * scale});
{tblWidth, colorsSz.y - (toolbarHeight + 5)});
{
ImGui::TableSetupColumn("Idx", ImGuiTableColumnFlags_WidthFixed, 25 * scale);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 100 * scale);
ImGui::TableSetupColumn("Red", ImGuiTableColumnFlags_WidthFixed, 40 * scale);
ImGui::TableSetupColumn("Green", ImGuiTableColumnFlags_WidthFixed, 40 * scale);
ImGui::TableSetupColumn("Blue", ImGuiTableColumnFlags_WidthFixed, 40 * scale);
ImGui::TableSetupColumn("Idx", ImGuiTableColumnFlags_WidthFixed, 25);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 100);
ImGui::TableSetupColumn("Red", ImGuiTableColumnFlags_WidthFixed, 40);
ImGui::TableSetupColumn("Green", ImGuiTableColumnFlags_WidthFixed, 40);
ImGui::TableSetupColumn("Blue", ImGuiTableColumnFlags_WidthFixed, 40);
ImGui::TableSetupColumn("Preview", ImGuiTableColumnFlags_NoHide);
ImGui::TableHeadersRow();
if (m_page < m_pal.pages.size()) {
@@ -237,11 +236,10 @@ void PaletteEditorImGui::drawColorsEditor() noexcept {
}
void PaletteEditorImGui::drawPagesEditor() noexcept {
auto const scale = ig::dpiScale();
constexpr auto tableFlags = ImGuiTableFlags_RowBg;
auto const paneSz = ImGui::GetContentRegionAvail();
constexpr auto toolbarHeight = 40;
auto const btnSz = ImVec2{paneSz.x / 4 - 5.5f * scale, 24 * scale};
auto const btnSz = ImVec2{paneSz.x / 4 - 5.5f, 24};
if (ImGui::Button("Add", btnSz)) {
if (m_pal.pages.empty()) {
std::ignore = pushCommand<AddPageCommand>(m_pal);
@@ -267,7 +265,7 @@ void PaletteEditorImGui::drawPagesEditor() noexcept {
"PageSelect",
2,
tableFlags,
{paneSz.x, paneSz.y - (toolbarHeight + 5) * scale});
{paneSz.x, paneSz.y - (toolbarHeight + 5)});
{
ImGui::TableSetupColumn("Page", ImGuiTableColumnFlags_WidthFixed, 60);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 200);
@@ -29,9 +29,10 @@ class PaletteEditorImGui: public studio::Editor {
}
[[nodiscard]]
constexpr bool isOpen() const noexcept { return m_show; }
void draw() noexcept;
void draw(turbine::Context &tctx) noexcept;
} m_pageRenameDlg;
studio::Context &m_sctx;
turbine::Context &m_tctx;
Palette m_pal;
size_t m_selectedColorRow = 0;
size_t m_page = 0;
@@ -23,7 +23,7 @@ struct SubSheetRef {
TileSheet::SubSheetIdx subsheet{};
};
static OX_MODEL_BEGIN(SubSheetRef)
OX_MODEL_BEGIN(SubSheetRef)
OX_MODEL_FIELD(subsheet)
OX_MODEL_END()
@@ -33,7 +33,7 @@ struct TileSheetEditorConfig {
TileSheet::SubSheetIdx activeSubsheet{};
};
static OX_MODEL_BEGIN(TileSheetEditorConfig)
OX_MODEL_BEGIN(TileSheetEditorConfig)
OX_MODEL_FIELD_RENAME(activeSubsheet, active_subsheet)
OX_MODEL_END()
@@ -149,30 +149,27 @@ void TileSheetEditorImGui::draw(studio::Context&) noexcept {
if (ImGui::IsKeyDown(ImGuiKey_ModCtrl) && !m_palPathFocused) {
if (ImGui::IsKeyPressed(ImGuiKey_A)) {
auto const &img = m_model.activeSubSheet();
m_model.setSelection({
{},
{img.columns * TileWidth - 1, img.rows * TileHeight - 1}});
m_model.setSelection({{}, {img.columns * TileWidth - 1, img.rows * TileHeight - 1}});
} else if (ImGui::IsKeyPressed(ImGuiKey_G)) {
m_model.clearSelection();
}
}
}
auto const scale = ig::dpiScale();
auto const paneSize = ImGui::GetContentRegionAvail();
auto const tileSheetParentSize = ImVec2{paneSize.x - s_palViewWidth * scale, paneSize.y};
auto const fbSize = ox::Vec2{tileSheetParentSize.x - 16 * scale, tileSheetParentSize.y - 16 * scale};
auto const tileSheetParentSize = ImVec2{paneSize.x - s_palViewWidth, paneSize.y};
auto const fbSize = ox::Vec2{tileSheetParentSize.x - 16, tileSheetParentSize.y - 16};
ImGui::BeginChild("TileSheetView", tileSheetParentSize, true);
{
drawTileSheet(fbSize);
}
ImGui::EndChild();
ImGui::SameLine();
ImGui::BeginChild("Controls", {(s_palViewWidth - 8) * scale, paneSize.y}, true);
ImGui::BeginChild("Controls", {s_palViewWidth - 8, paneSize.y}, true);
{
auto const controlsSize = ImGui::GetContentRegionAvail();
ImGui::BeginChild("ToolBox", {0, 32 * scale}, true);
ImGui::BeginChild("ToolBox", {0, 32}, true);
{
auto const btnSz = ImVec2{45 * scale, 14 * scale};
auto const btnSz = ImVec2{45, 14};
if (ImGui::Selectable("Select", m_tool == TileSheetTool::Select, 0, btnSz)) {
m_tool = TileSheetTool::Select;
}
@@ -196,7 +193,7 @@ void TileSheetEditorImGui::draw(studio::Context&) noexcept {
//ig::ComboBox("##Operations", ox::Array<ox::CStringView, 1>{"Operations"}, i);
}
ImGui::EndChild();
ImGui::BeginChild("OperationsBox", {0, 35 * scale}, ImGuiWindowFlags_NoTitleBar);
ImGui::BeginChild("OperationsBox", {0, 35}, ImGuiWindowFlags_NoTitleBar);
{
if (ImGui::BeginCombo("##Operations", "Operations", 0)) {
if (ImGui::Selectable("Flip X", false)) {
@@ -217,17 +214,17 @@ void TileSheetEditorImGui::draw(studio::Context&) noexcept {
}
}
ImGui::EndChild();
auto const ySize = controlsSize.y - (38 + ig::BtnSz.y + 21) * scale;
auto const ySize = controlsSize.y - (38 + ig::BtnSz.y + 21);
// draw palette/color picker
ImGui::BeginChild("Palette", {(s_palViewWidth - 24) * scale, ySize / 2.f}, true);
ImGui::BeginChild("Palette", {s_palViewWidth - 24, ySize / 2.f}, true);
{
drawPaletteMenu();
}
ImGui::EndChild();
ImGui::BeginChild("SubSheets", {(s_palViewWidth - 24) * scale, ySize / 2.f}, true);
ImGui::BeginChild("SubSheets", {s_palViewWidth - 24, ySize / 2.f}, true);
{
auto constexpr btnHeight = ig::BtnSz.y;
auto const btnSize = ImVec2{btnHeight, btnHeight};
static constexpr auto btnHeight = ig::BtnSz.y;
auto constexpr btnSize = ImVec2{btnHeight, btnHeight};
if (ig::PushButton("+", btnSize)) {
auto insertOnIdx = m_model.activeSubSheetIdx();
auto const &parent = m_model.activeSubSheet();
@@ -250,16 +247,16 @@ void TileSheetEditorImGui::draw(studio::Context&) noexcept {
if (ig::PushButton("Export")) {
m_exportMenu.show();
}
TileSheet::SubSheetIdx path;
static constexpr auto flags =
ImGuiTableFlags_RowBg |
ImGuiTableFlags_NoBordersInBody |
ImGuiTableFlags_ScrollY;
if (ImGui::BeginTable("Subsheets", 4, flags)) {
TileSheet::SubSheetIdx path;
ImGui::TableSetupColumn("Subsheet", ImGuiTableColumnFlags_NoHide);
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed, 25 * scale);
ImGui::TableSetupColumn("Columns", ImGuiTableColumnFlags_WidthFixed, 50 * scale);
ImGui::TableSetupColumn("Rows", ImGuiTableColumnFlags_WidthFixed, 50 * scale);
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed, 25);
ImGui::TableSetupColumn("Columns", ImGuiTableColumnFlags_WidthFixed, 50);
ImGui::TableSetupColumn("Rows", ImGuiTableColumnFlags_WidthFixed, 50);
ImGui::TableHeadersRow();
drawSubsheetSelector(m_view.img().subsheet, path);
ImGui::EndTable();
@@ -268,8 +265,8 @@ void TileSheetEditorImGui::draw(studio::Context&) noexcept {
ImGui::EndChild();
}
ImGui::EndChild();
m_subsheetEditor.draw();
m_exportMenu.draw();
m_subsheetEditor.draw(m_tctx);
m_exportMenu.draw(m_tctx);
if (auto pal = m_palPicker.draw(m_sctx)) {
if (*pal != m_model.palPath()) {
oxLogError(m_model.setPalette(*pal));
@@ -448,11 +445,10 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const &fbSize) noexcept {
void TileSheetEditorImGui::drawPaletteMenu() noexcept {
ig::IDStackItem const idStackItem{"PaletteMenu"};
auto const scale = ig::dpiScale();
auto const comboWidthSub = 62 * scale;
auto constexpr comboWidthSub = 62;
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub);
auto constexpr palFlags = ImGuiInputTextFlags_ReadOnly;
if (ig::InputTextWithHint("##Palette", "Path to Palette", m_model.palPath(), palFlags)) {
auto constexpr palTags = ImGuiInputTextFlags_ReadOnly;
if (ig::InputTextWithHint("##Palette", "Path to Palette", m_model.palPath(), palTags)) {
oxLogError(m_model.setPalette(m_model.palPath()));
}
m_palPathFocused = ImGui::IsItemFocused();
@@ -560,7 +556,7 @@ void TileSheetEditorImGui::SubSheetEditor::show(ox::StringViewCR name, int const
m_rows = rows;
}
void TileSheetEditorImGui::SubSheetEditor::draw() noexcept {
void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &tctx) noexcept {
constexpr auto popupName = "Edit Subsheet";
if (!m_show) {
return;
@@ -569,13 +565,13 @@ void TileSheetEditorImGui::SubSheetEditor::draw() noexcept {
auto constexpr popupWidth = 235.f;
auto const popupHeight = modSize ? 130.f : 85.f;
auto const popupSz = ImVec2{popupWidth, popupHeight};
if (ig::BeginPopup(popupName, m_show, popupSz)) {
if (ig::BeginPopup(tctx, popupName, m_show, popupSz)) {
ig::InputText("Name", m_name);
if (modSize) {
ImGui::InputInt("Columns", &m_cols);
ImGui::InputInt("Rows", &m_rows);
}
if (ig::PopupControlsOkCancel(m_show) == ig::PopupResponse::OK) {
if (ig::PopupControlsOkCancel(popupWidth, m_show) == ig::PopupResponse::OK) {
inputSubmitted.emit(m_name, m_cols, m_rows);
}
ImGui::EndPopup();
@@ -592,18 +588,18 @@ void TileSheetEditorImGui::ExportMenu::show() noexcept {
m_scale = 5;
}
void TileSheetEditorImGui::ExportMenu::draw() noexcept {
void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &tctx) noexcept {
constexpr auto popupName = "Export Tile Sheet";
if (!m_show) {
return;
}
auto constexpr popupWidth = 235.f;
auto constexpr popupHeight = 85.f;
auto constexpr popupSz = ImVec2{popupWidth, popupHeight};
if (ig::BeginPopup(popupName, m_show, popupSz)) {
constexpr auto popupWidth = 235.f;
constexpr auto popupHeight = 85.f;
constexpr auto popupSz = ImVec2{popupWidth, popupHeight};
if (ig::BeginPopup(tctx, popupName, m_show, popupSz)) {
ImGui::InputInt("Scale", &m_scale);
m_scale = ox::clamp(m_scale, 1, 135);
if (ig::PopupControlsOkCancel(m_show) == ig::PopupResponse::OK) {
if (ig::PopupControlsOkCancel(popupWidth, m_show) == ig::PopupResponse::OK) {
inputSubmitted.emit(m_scale);
}
ImGui::EndPopup();
@@ -27,7 +27,7 @@ class TileSheetEditorImGui: public studio::Editor {
public:
ox::Signal<ox::Error(ox::StringViewCR name, int cols, int rows)> inputSubmitted;
void show(ox::StringViewCR name, int cols, int rows) noexcept;
void draw() noexcept;
void draw(turbine::Context &tctx) noexcept;
void close() noexcept;
[[nodiscard]]
constexpr bool isOpen() const noexcept { return m_show; }
@@ -39,7 +39,7 @@ class TileSheetEditorImGui: public studio::Editor {
public:
ox::Signal<ox::Error(int scale)> inputSubmitted;
void show() noexcept;
void draw() noexcept;
void draw(turbine::Context &tctx) noexcept;
void close() noexcept;
[[nodiscard]]
constexpr bool isOpen() const noexcept { return m_show; }
+1 -2
View File
@@ -15,8 +15,7 @@ target_link_libraries(
target_compile_definitions(
NostalgiaStudio PUBLIC
OLYMPIC_APP_VERSION="d2026.05.0"
OLYMPIC_APP_ID="net.drinkingtea.nostalgia.NostalgiaStudio"
OLYMPIC_APP_VERSION="dev build"
)
install(
+1 -1
View File
@@ -18,7 +18,7 @@
<string>APPL</string>
<key>CFBundleVersion</key>
<string>d2026.05.0</string>
<string>dev build</string>
<key>LSMinimumSystemVersion</key>
<string>12.0.0</string>
+21
View File
@@ -0,0 +1,21 @@
add_executable(nostalgia-pack)
target_link_libraries(
nostalgia-pack
KeelPack-AppLib
NostalgiaKeelModules
NostalgiaProfile
OlympicApplib
)
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT WIN32)
# enable LTO
set_property(TARGET nostalgia-pack PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
install(
TARGETS
nostalgia-pack
RUNTIME DESTINATION
bin
)
+2 -8
View File
@@ -9,10 +9,6 @@
#define OLYMPIC_PROJECT_NAME "OlympicProject"
#endif
#ifndef OLYMPIC_APP_ID
#define OLYMPIC_APP_ID "AppID"
#endif
#ifndef OLYMPIC_APP_NAME
#define OLYMPIC_APP_NAME "App"
#endif
@@ -42,9 +38,7 @@
#endif
namespace olympic {
ox::StringLiteral appVersion{OLYMPIC_APP_VERSION};
ox::StringLiteral appId{OLYMPIC_APP_ID};
ox::StringLiteral projectName{OLYMPIC_PROJECT_NAME};
ox::String appVersion{OLYMPIC_APP_VERSION};
}
ox::Error run(
@@ -78,7 +72,7 @@ int main(int const argc, char const **argv) {
OLYMPIC_PROJECT_DATADIR,
{argv, static_cast<size_t>(argc)});
oxAssert(err, "Something went wrong...");
if (ox::defines::Debug && err) {
if (err) {
oxErrf("Failure: {}\n", toStr(err));
}
return static_cast<int>(err);
@@ -1,18 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/std/error.hpp>
#include <ox/std/span.hpp>
#include <ox/std/stringview.hpp>
namespace keel {
ox::Error pack(
ox::StringViewCR projectDir,
ox::StringViewCR projectDataDir,
ox::SpanView<ox::CString> argv) noexcept;
}
+10 -5
View File
@@ -41,15 +41,20 @@ install(
if(TURBINE_BUILD_TYPE STREQUAL "Native")
add_library(
KeelPack-PackLib
pack-packlib.cpp
KeelPack-AppLib
pack-applib.cpp
)
target_include_directories(
KeelPack-PackLib PUBLIC
KeelPack-AppLib PUBLIC
../include
)
target_compile_definitions(
KeelPack-AppLib PUBLIC
OLYMPIC_LOAD_KEEL_MODULES=1
OLYMPIC_APP_NAME="Keel Pack"
)
target_link_libraries(
KeelPack-PackLib
KeelPack-AppLib
Keel
OxClArgs
OxClaw
@@ -57,7 +62,7 @@ if(TURBINE_BUILD_TYPE STREQUAL "Native")
)
install(
TARGETS
KeelPack-PackLib
KeelPack-AppLib
DESTINATION
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
@@ -92,20 +92,22 @@ static ox::Error pack(
return {};
}
namespace keel {
ox::Error pack(
ox::StringViewCR projectDir,
ox::StringViewCR projectDataDir,
ox::Error run(
[[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", "");
auto const argManifest = args.getString("manifest", "");
if (argSrc == "") {
oxErr("\033[31;1;1merror:\033[0m must specify a source directory\n");
return ox::Error(1, "must specify a source directory");
}
if (argRomBin == "") {
oxErr("\033[31;1;1merror:\033[0m must specify a path for ROM file\n");
return ox::Error(1, "must specify a path for preload file");
}
return ::pack(projectDir, argRomBin, argManifest, projectDataDir);
return pack(argSrc, argRomBin, argManifest, projectDataDir);
}
}
+12 -34
View File
@@ -15,16 +15,10 @@
#include <studioapp/studioapp.hpp>
#include "subcommands/change-format/change-format.hpp"
#include "subcommands/pack/pack.hpp"
#include "configfile.hpp"
#include "font.hpp"
#include "studioui.hpp"
namespace olympic {
extern ox::StringLiteral appId;
}
namespace studio {
static ox::Error convertStudioConfigV1ToStudioConfigV2(
@@ -47,8 +41,10 @@ static struct: Module {
ox::Vector<Command> commands() const final {
return {
{ "change-format", cmdChangeFormat, },
{ "pack", cmdPack, },
{
"change-format",
cmdChangeFormat,
}
};
}
} constexpr mod;
@@ -73,10 +69,6 @@ class StudioUIDrawer: public turbine::gl::Drawer {
explicit StudioUIDrawer(StudioUI &ui) noexcept: m_ui(ui) {
}
void preDraw(turbine::Context&) noexcept final {
m_ui.preDraw();
}
void draw(turbine::Context&) noexcept final {
m_ui.draw();
}
@@ -99,9 +91,7 @@ static ox::Error runStudio(
ox::StringViewCR appName,
ox::StringViewCR projectDataDir,
ox::UPtr<ox::FileSystem> &&fs) noexcept {
OX_REQUIRE_M(
ctx,
turbine::init(std::move(fs), appName, olympic::appId));
OX_REQUIRE_M(ctx, turbine::init(std::move(fs), appName));
oxLogError(turbine::setWindowIcon(*ctx, WindowIcons()));
turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName);
turbine::setKeyEventHandler(*ctx, keyEventHandler);
@@ -115,20 +105,6 @@ static ox::Error runStudio(
return err;
}
static void listCmds() noexcept {
oxOut("Insufficient arguments for sub-command\n\nValid commands:\n\n");
for (auto const m : modules()) {
if (m->commands().empty()) {
continue;
}
oxOutf("\t{}\n", m->id());
for (auto const &c : m->commands()) {
oxOutf("\t\t{}\n", c.name);
}
oxOut("\n");
}
}
static ox::Error run(
ox::StringViewCR appName,
ox::StringViewCR projectDataDir,
@@ -143,8 +119,7 @@ static ox::Error run(
});
if (args.size() > 1 && ox::StringView{args[1]} == "cmd") {
if (args.size() < 5) {
listCmds();
return ox::Error{1};
return ox::Error{1, "insufficient arguments for sub-command"};
}
auto constexpr numCmdArgs = 5;
ox::StringView const projectDir = args[2];
@@ -154,10 +129,13 @@ static ox::Error run(
if (m->id() == moduleId) {
for (auto const &c : m->commands()) {
if (c.name == subCmd) {
OX_REQUIRE(kctx, keel::init(
auto kctx = keel::init(
ox::make_unique<ox::PassThroughFS>(projectDir),
c.name).reoriginate(2, "failed to load project directory"));
Project project{*kctx, projectDir, projectDataDir};
c.name);
if (kctx.error) {
return ox::Error{2, "failed to load project directory"};
}
Project project{*kctx.value, projectDir, projectDataDir};
return c.func(
project,
args.size() > numCmdArgs ?
@@ -4,6 +4,8 @@
#include <imgui.h>
#include <studio/context.hpp>
#include "clawviewer.hpp"
namespace studio {
-2
View File
@@ -1,7 +1,5 @@
// Generated
#pragma once
#include <ox/std/span.hpp>
namespace studio::files {
@@ -8,7 +8,7 @@
#include "about.hpp"
namespace olympic {
extern ox::StringLiteral appVersion;
extern ox::String appVersion;
}
namespace studio {
@@ -22,7 +22,7 @@ AboutPopup::AboutPopup(turbine::Context &ctx) noexcept:
#endif
}
void AboutPopup::draw(Context&) noexcept {
void AboutPopup::draw(Context &sctx) noexcept {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
close();
return;
@@ -37,12 +37,12 @@ void AboutPopup::draw(Context&) noexcept {
case Stage::Open: {
constexpr auto modalFlags =
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
ig::centerNextWindow();
ig::centerNextWindow(sctx.tctx);
auto open = true;
if (ImGui::BeginPopupModal("About", &open, modalFlags)) {
ImGui::Text("%s\n\nBuild date: %s", m_text.c_str(), __DATE__);
ImGui::NewLine();
ig::Dummy({148.0f, 0.0f});
ImGui::Dummy({148.0f, 0.0f});
ImGui::SameLine();
if (ig::PushButton("Close")) {
ImGui::CloseCurrentPopup();
@@ -37,7 +37,7 @@ ox::Error FileInfo::open(ox::StringParam filePath) noexcept {
return {};
}
void FileInfo::draw(Context&) noexcept {
void FileInfo::draw(Context &sctx) noexcept {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
close();
return;
@@ -52,7 +52,7 @@ void FileInfo::draw(Context&) noexcept {
case Stage::Open: {
constexpr auto modalFlags =
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
ig::centerNextWindow();
ig::centerNextWindow(sctx.tctx);
auto open = true;
if (ImGui::BeginPopupModal(m_title.c_str(), &open, modalFlags)) {
drawTable();
@@ -79,14 +79,13 @@ void FileInfo::draw(Context&) noexcept {
}
void FileInfo::drawTable() const noexcept {
auto const scale = ig::dpiScale();
ig::IDStackItem const idStackItem{"FileInfo"};
ImGui::Text("%s", m_filePath.c_str());
if (m_fileInfo && ImGui::BeginTable(
"Table", 2,
ImGuiTableFlags_Borders |
ImGuiTableFlags_RowBg)) {
ImGui::TableSetupColumn("Field", ImGuiTableColumnFlags_WidthFixed, 70 * scale);
ImGui::TableSetupColumn("Field", ImGuiTableColumnFlags_WidthFixed, 70);
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_NoHide);
// asset id
ImGui::TableNextRow();
@@ -37,10 +37,9 @@ void MakeCopyPopup::draw(Context &ctx) noexcept {
m_stage = Stage::Open;
m_open = true;
[[fallthrough]];
case Stage::Open: {
auto const scale = ig::dpiScale();
ig::centerNextWindow();
ImGui::SetNextWindowSize({250 * scale, 0});
case Stage::Open:
ig::centerNextWindow(ctx.tctx);
ImGui::SetNextWindowSize({250, 0});
constexpr auto modalFlags =
ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove |
@@ -68,7 +67,6 @@ void MakeCopyPopup::draw(Context &ctx) noexcept {
ImGui::EndPopup();
}
break;
}
}
}
@@ -134,10 +134,9 @@ void NewMenu::drawNewItemPath(Context &sctx) noexcept {
}
void NewMenu::drawButtons(Stage const next) noexcept {
auto const scale = ig::dpiScale();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 198 * scale);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 22 * scale);
ImVec2 const btnSz{60 * scale, ig::BtnSz.y * scale};
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 198);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
constexpr ImVec2 btnSz{60, 20};
if (ImGui::Button("Back", btnSz)) {
if (auto const p = m_prev.back(); p.ok()) {
m_stage = *p.value;
@@ -157,10 +156,9 @@ void NewMenu::drawButtons(Stage const next) noexcept {
}
void NewMenu::drawFirstPageButtons(Stage const next) noexcept {
auto const scale = ig::dpiScale();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 130 * scale);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 22 * scale);
ImVec2 const btnSz{60 * scale, ig::BtnSz.y * scale};
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 130);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
constexpr ImVec2 btnSz{60, 20};
if (ImGui::Button("Next", btnSz)) {
m_prev.emplace_back(m_stage);
m_stage = next;
@@ -173,10 +171,9 @@ void NewMenu::drawFirstPageButtons(Stage const next) noexcept {
}
void NewMenu::drawLastPageButtons(Context &sctx) noexcept {
auto const scale = ig::dpiScale();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 198 * scale);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 22 * scale);
ImVec2 const btnSz{60 * scale, ig::BtnSz.y * scale};
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 198);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20);
constexpr ImVec2 btnSz{60, 20};
if (ImGui::Button("Back", btnSz)) {
if (auto const p = m_prev.back(); p.ok()) {
m_stage = *p.value;
@@ -65,9 +65,8 @@ void NewProject::drawNewProjectName(Context &sctx) noexcept {
}
void NewProject::drawLastPageButtons(Context&) noexcept {
auto const scale = ig::dpiScale();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 110 * scale);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 22 * scale);
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 110);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 22);
if (ig::PushButton("Finish")) {
finish();
}
+23 -50
View File
@@ -43,7 +43,7 @@ ox::Vector<Module const*> const &modules() noexcept {
return g_modules;
}
void registerModule(Module const *mod) noexcept {
void registerModule(Module const*mod) noexcept {
if (mod) {
g_modules.emplace_back(mod);
}
@@ -121,6 +121,19 @@ using StudioConfig = StudioConfigV2;
StudioUI::StudioUI(turbine::Context &tctx, ox::StringParam projectDataDir) noexcept:
m_sctx{*this, tctx},
m_projectDataDir{std::move(projectDataDir)} {
{
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 recognizes 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);
}
auto &kctx = keelCtx(m_tctx);
kctx.converters.emplace_back(keel::Converter::make<convertStudioConfigV1ToStudioConfigV2>());
oxLogError(headerizeConfigFile<StudioConfigV1>(kctx));
@@ -183,16 +196,7 @@ void StudioUI::handleNavigationChange(ox::StringParam path, ox::StringParam navA
m_navAction.emplace(std::move(path), std::move(navArgs));
}
void StudioUI::preDraw() noexcept {
loadFont();
}
void StudioUI::draw() noexcept {
if (turbine::isWayland() || ox::defines::OS == ox::OS::Darwin) {
ig::setDpiScale(1.f);
} else {
ig::setDpiScale(ImGui::GetWindowDpiScale());
}
glutils::clearScreen();
drawMenu();
auto const &viewport = *ImGui::GetMainViewport();
@@ -211,7 +215,7 @@ void StudioUI::draw() noexcept {
ImGuiFocusedFlags_RootAndChildWindows | ImGuiFocusedFlags_NoPopupHierarchy);
if (m_showProjectExplorer) {
auto const v = ImGui::GetContentRegionAvail();
m_projectExplorer.draw(m_sctx, {300 * ig::dpiScale(), v.y});
m_projectExplorer.draw(m_sctx, {300, v.y});
ImGui::SameLine();
}
drawTabBar();
@@ -225,29 +229,6 @@ void StudioUI::draw() noexcept {
procFileMoves();
}
void StudioUI::loadFont() noexcept {
auto const scale = turbine::isWayland() || ox::defines::OS == ox::OS::Darwin ?
1.f : turbine::scale(m_tctx);
if (m_fontScale != scale) {
m_fontScale = scale;
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 recognizes 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 * scale,
&fontCfg);
}
}
bool StudioUI::handleShutdown() noexcept {
auto const out = ox::all_of(m_editors.begin(), m_editors.end(), [](ox::UPtr<BaseEditor> const &e) {
return !e->unsavedChanges();
@@ -341,14 +322,12 @@ void StudioUI::drawMenu() noexcept {
if (ImGui::BeginMenu("Navigate")) {
constexpr auto backShortcut = ox::defines::OS == ox::OS::Darwin ? "Cmd+[" : "Alt+Left Arrow";
constexpr auto fwdShortcut = ox::defines::OS == ox::OS::Darwin ? "Cmd+]" : "Alt+Right Arrow";
if (ImGui::MenuItem(
"Back", backShortcut, false,
m_sctx.navIdx && *m_sctx.navIdx > 1)) {
if (ImGui::MenuItem("Back", backShortcut, false, m_sctx.navIdx > 1)) {
navigateBack(m_sctx);
}
if (ImGui::MenuItem(
"Forward", fwdShortcut, false,
m_sctx.navIdx && *m_sctx.navIdx < m_sctx.navStack.size())) {
m_sctx.navIdx < m_sctx.navStack.size())) {
navigateForward(m_sctx);
}
ImGui::EndMenu();
@@ -379,7 +358,7 @@ void StudioUI::drawTabs() noexcept {
auto const &e = *it;
auto open = true;
auto const unsavedChanges = e->unsavedChanges() ? ImGuiTabItemFlags_UnsavedDocument : 0;
auto const selected = m_activeEditorUpdatePending == e.get() ? ImGuiTabItemFlags_SetSelected : 0;
auto const selected = m_activeEditorUpdatePending == e.get() ? ImGuiTabItemFlags_SetSelected : 0;
auto const flags = unsavedChanges | selected | ImGuiTabItemFlags_NoAssumedClosure;
if (ImGui::BeginTabItem(e->itemDisplayName().c_str(), &open, flags)) {
if (m_activeEditor != e.get()) [[unlikely]] {
@@ -397,17 +376,11 @@ void StudioUI::drawTabs() noexcept {
if (m_activeEditorOnLastDraw != e.get()) [[unlikely]] {
m_activeEditor->onActivated();
if (!m_sctx.navIdx ||
*m_sctx.navIdx == m_sctx.navStack.size() ||
(*m_sctx.navIdx < m_sctx.navStack.size() &&
m_sctx.navStack[*m_sctx.navIdx].filePath != m_activeEditor->itemPath())) {
auto constexpr defaultVal =
ox::MaxValue<ox::remove_reference_t<decltype(*m_sctx.navIdx)>>;
auto &navIdx = m_sctx.navIdx.emplace(m_sctx.navIdx.or_value(defaultVal));
++navIdx;
m_sctx.navStack.resize(navIdx);
m_sctx.navStack.emplace_back(
ox::String{m_activeEditor->itemPath()},
ox::String{});
(m_sctx.navIdx <= m_sctx.navStack.size() &&
m_sctx.navStack[m_sctx.navIdx - 1].filePath != m_activeEditor->itemPath())) {
m_sctx.navStack.resize(m_sctx.navIdx);
++m_sctx.navIdx;
m_sctx.navStack.emplace_back(ox::String{m_activeEditor->itemPath()}, ox::String{""});
}
}
if (m_closeActiveTab) [[unlikely]] {
@@ -84,7 +84,6 @@ class StudioUI final: public ox::SignalHandler {
ox::String args;
};
ox::Optional<NavAction> m_navAction;
float m_fontScale{};
public:
explicit StudioUI(turbine::Context &tctx, ox::StringParam projectDataDir) noexcept;
@@ -103,13 +102,9 @@ class StudioUI final: public ox::SignalHandler {
bool handleShutdown() noexcept;
protected:
void preDraw() noexcept;
void draw() noexcept;
private:
void loadFont() noexcept;
void drawMenu() noexcept;
void drawTabBar() noexcept;
@@ -2,11 +2,9 @@
target_sources(
StudioAppLib PRIVATE
change-format/change-format.cpp
pack/pack.cpp
)
target_link_libraries(
StudioAppLib PUBLIC
OxClArgs
KeelPack-PackLib
)
@@ -20,12 +20,13 @@ static ox::Error convertFile(
OX_REQUIRE(uuid, keel::readUuidHeader(buff));
OX_REQUIRE(obj, keel::readAsset(ts, buff).reoriginate(1, "unable to parse file"));
buff.clear();
ox::BufferWriter writer{&buff};
OX_RETURN_ERROR(keel::writeUuidHeader(writer, uuid));
OX_RETURN_ERROR(ox::writeClaw(obj, writer, fmt));
ox::BufferWriter wrtr{&buff};
OX_RETURN_ERROR(keel::writeUuidHeader(wrtr, uuid));
OX_RETURN_ERROR(ox::writeClaw(obj, wrtr, fmt));
if (fmt == ox::ClawFormat::Organic) {
*buff.back().value = '\n';
}
OX_RETURN_ERROR(wrtr.write(buff.data(), buff.size()));
OX_RETURN_ERROR(fs.write(path, buff).reoriginate(1, "unable to write file"));
return {};
}
@@ -36,9 +37,9 @@ static void printUsage() noexcept {
[[nodiscard]]
static constexpr ox::Result<ox::ClawFormat> getFmt(ox::StringViewCR fmtStr) noexcept {
if (caseInsensitiveStrCmp(fmtStr, "mc") == 0) {
if (caseInsensitiveEquals(fmtStr, "mc") == 0) {
return ox::ClawFormat::Metal;
} else if (caseInsensitiveStrCmp(fmtStr, "oc") == 0) {
} else if (caseInsensitiveEquals(fmtStr, "oc") == 0) {
return ox::ClawFormat::Organic;
}
return ox::Error{1, "invalid format"};
@@ -4,8 +4,6 @@
#pragma once
#include <studio/project.hpp>
namespace studio {
ox::Error cmdChangeFormat(Project &project, ox::SpanView<ox::CString> args) noexcept;
@@ -1,19 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <keel/pack-packlib.hpp>
#include "pack.hpp"
namespace olympic {
extern ox::StringLiteral projectName;
}
namespace studio {
ox::Error cmdPack(Project &project, ox::SpanView<ox::CString> args) noexcept {
return keel::pack(project.projectPath(), olympic::projectName, args);
}
}
@@ -1,13 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <studio/project.hpp>
namespace studio {
ox::Error cmdPack(Project &project, ox::SpanView<ox::CString> args) noexcept;
}
@@ -28,7 +28,7 @@ struct Context {
ox::String filePath;
ox::String navArgs;
};
ox::Optional<size_t> navIdx{};
size_t navIdx{};
ox::Vector<NavPath> navStack;
std::function<void(ox::StringParam filePath, ox::StringParam navArgs)> navCallback;
Context(StudioUI &pUi, turbine::Context &pTctx) noexcept:
@@ -27,10 +27,6 @@ namespace studio::ig {
inline constexpr auto BtnSz = ImVec2{52, 22};
void setDpiScale(float scale) noexcept;
[[nodiscard]]
float dpiScale() noexcept;
constexpr ImTextureID toImTextureID(ox::Unsigned_c auto id) noexcept
requires(sizeof(id) <= sizeof(ox::Uint<sizeof(ImTextureID)*8>)) {
@@ -137,7 +133,7 @@ auto dragDropTarget(auto const &cb) noexcept {
class ChildStackItem {
public:
explicit ChildStackItem(ox::CStringViewCR id, ImVec2 sz = {}) noexcept;
explicit ChildStackItem(ox::CStringViewCR id, ImVec2 const &sz = {}) noexcept;
~ChildStackItem() noexcept;
};
@@ -157,12 +153,7 @@ class IndentStackItem {
~IndentStackItem() noexcept;
};
void centerNextWindow() noexcept;
inline void Dummy(ImVec2 const &sz) noexcept {
auto const scale = dpiScale();
ImGui::Dummy({sz.x * scale, sz.y * scale});
}
void centerNextWindow(turbine::Context &ctx) noexcept;
bool PushButton(ox::CStringViewCR lbl, ImVec2 const &btnSz = BtnSz) noexcept;
@@ -182,10 +173,10 @@ TextInput<ox::IString<MaxChars>> InputText(
ox::StringViewCR currentText,
ImGuiInputTextFlags const flags = 0,
ImGuiInputTextCallback const callback = nullptr,
void *const userData = nullptr) noexcept {
void *user_data = nullptr) noexcept {
TextInput<ox::IString<MaxChars>> out = {.text = currentText};
out.changed = ImGui::InputText(
label.c_str(), out.text.data(), MaxChars + 1, flags, callback, userData);
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()));
@@ -201,10 +192,10 @@ TextInput<ox::IString<MaxChars>> InputTextWithHint(
ox::StringViewCR currentText,
ImGuiInputTextFlags const flags = 0,
ImGuiInputTextCallback const callback = nullptr,
void *userData = nullptr) noexcept {
void *user_data = nullptr) noexcept {
TextInput<ox::IString<MaxChars>> out = {.text = currentText};
out.changed = ImGui::InputTextWithHint(
label.c_str(), hint.c_str(), out.text.data(), MaxChars + 1, flags, callback, userData);
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()));
@@ -219,9 +210,9 @@ bool InputText(
ox::IString<StrCap> &text,
ImGuiInputTextFlags const flags = 0,
ImGuiInputTextCallback const callback = nullptr,
void *userData = nullptr) noexcept {
void *user_data = nullptr) noexcept {
auto const out = ImGui::InputText(
label.c_str(), text.data(), StrCap + 1, flags, callback, userData);
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()));
@@ -252,7 +243,7 @@ PopupResponse PopupControlsOk(
ox::CStringViewCR ok);
[[nodiscard]]
bool BeginPopup(ox::CStringViewCR popupName, bool &show, ImVec2 sz = {285, 0});
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const &sz = {285, 0});
/**
*
@@ -299,7 +290,7 @@ bool ListBox(
std::function<ox::CStringView(size_t)> const &f,
size_t strCnt,
size_t &selIdx,
ImVec2 sz = {0, 0}) noexcept;
ImVec2 const &sz = {0, 0}) noexcept;
/**
*
+18 -24
View File
@@ -15,9 +15,12 @@ void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs)
}
path = p;
}
auto constexpr defaultVal =
ox::MaxValue<ox::remove_reference_t<decltype(*ctx.navIdx)>>;
ctx.navStack.resize(ctx.navIdx.or_value(defaultVal) + 1);
//if (
// auto const [np, err] = ctx.navStack.back();
// !err && np->filePath == path && np->navArgs == navArgs.view()) {
// return;
//}
ctx.navStack.resize(ctx.navIdx + 1);
ctx.navStack.emplace_back(ox::String{path}, ox::String{navArgs.view()});
try {
ctx.navCallback(std::move(path), std::move(navArgs));
@@ -31,20 +34,15 @@ void navigateBack(Context &ctx) noexcept {
if (!ctx.navIdx) {
return;
}
auto &navIdx = *ctx.navIdx;
while (navIdx && navIdx < ctx.navStack.size()) {
--navIdx;
auto const &n = ctx.navStack[navIdx];
// check for invalid entry
--ctx.navIdx;
while (ctx.navIdx < ctx.navStack.size() && ctx.navIdx) {
auto const i = ctx.navIdx - 1;
auto const &n = ctx.navStack[i];
if (!ctx.project->exists(n.filePath)) {
// remove the invalid entry, then reset and retry
auto const err = ctx.navStack.erase(navIdx);
if (err.error) {
return;
}
std::ignore = ctx.navStack.erase(i);
--ctx.navIdx;
continue;
}
// entry is valid, do the navigation
try {
ctx.navCallback(n.filePath, n.navArgs);
} catch (std::exception const &e) {
@@ -56,24 +54,20 @@ void navigateBack(Context &ctx) noexcept {
}
void navigateForward(Context &ctx) noexcept {
if (!ctx.navIdx) {
ctx.navIdx.emplace(0u);
}
auto &navIdx = *ctx.navIdx;
auto const nextIdx = navIdx + 1;
auto const nextIdx = ctx.navIdx + 1;
while (nextIdx < ctx.navStack.size()) {
auto const &n = ctx.navStack[nextIdx];
if (!ctx.project->exists(n.filePath)) {
std::ignore = ctx.navStack.erase(nextIdx);
continue;
}
try {
ctx.navCallback(n.filePath, n.navArgs);
} catch (std::exception const &e) {
oxAssert(ctx.navCallback != nullptr, "navCallback is null");
oxErrf("navigateForward failed: {}", e.what());
}
++navIdx;
if (!ctx.project->exists(n.filePath)) {
std::ignore = ctx.navStack.erase(nextIdx);
continue;
}
++ctx.navIdx;
break;
}
}
@@ -2,8 +2,6 @@
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <turbine/turbine.hpp>
#include <studio/imguiutil.hpp>
#include <studio/filepickerpopup.hpp>
@@ -85,10 +83,9 @@ ox::Optional<ox::String> FilePickerPopup::draw(Context &ctx) noexcept {
if (!m_open) {
return out;
}
auto const scale = turbine::scale(ctx.tctx);
if (ig::BeginPopup(m_name, m_open, {380, 340})) {
if (ig::BeginPopup(ctx.tctx, m_name, m_open, {380, 340})) {
auto const vp = ImGui::GetContentRegionAvail();
m_explorer.draw(ctx, {vp.x, vp.y - 30 * scale});
m_explorer.draw(ctx, {vp.x, vp.y - 30});
if (ig::PopupControlsOkCancel(m_open) == ig::PopupResponse::OK || m_explorer.opened) {
out = handlePick();
}
+29 -55
View File
@@ -10,25 +10,7 @@
namespace studio::ig {
inline void scaleSz(ImVec2 &sz) noexcept {
auto const scale = dpiScale();
sz.x *= scale;
sz.y *= scale;
}
static thread_local float g_dpiScale = 1.f;
void setDpiScale(float const scale) noexcept {
g_dpiScale = scale;
}
[[nodiscard]]
float dpiScale() noexcept {
return g_dpiScale;
}
ChildStackItem::ChildStackItem(ox::CStringViewCR id, ImVec2 sz) noexcept {
scaleSz(sz);
ChildStackItem::ChildStackItem(ox::CStringViewCR id, ImVec2 const &sz) noexcept {
ImGui::BeginChild(id.c_str(), sz);
}
@@ -51,7 +33,7 @@ IDStackItem::~IDStackItem() noexcept {
}
IndentStackItem::IndentStackItem(float id) noexcept: m_indent(id) {
IndentStackItem::IndentStackItem(float indent) noexcept: m_indent(indent) {
ImGui::Indent(m_indent);
}
@@ -60,18 +42,16 @@ IndentStackItem::~IndentStackItem() noexcept {
}
void centerNextWindow() noexcept {
auto const &io = ImGui::GetIO();
auto const sz = io.DisplaySize;
ImGui::SetNextWindowPos(
{sz.x * 0.5f, sz.y * 0.5f},
ImGuiCond_Always,
{0.5f, 0.5f});
void centerNextWindow(turbine::Context &ctx) noexcept {
auto const sz = turbine::getScreenSize(ctx);
auto const screenW = static_cast<float>(sz.width);
auto const screenH = static_cast<float>(sz.height);
auto const mod = ImGui::GetWindowDpiScale() * 2;
ImGui::SetNextWindowPos(ImVec2(screenW / mod, screenH / mod), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
}
bool PushButton(ox::CStringViewCR lbl, ImVec2 const &btnSz) noexcept {
auto const scale = dpiScale();
return ImGui::Button(lbl.c_str(), {btnSz.x * scale, btnSz.y * scale});
return ImGui::Button(lbl.c_str(), btnSz);
}
PopupResponse PopupControlsOkCancel(
@@ -80,10 +60,9 @@ PopupResponse PopupControlsOkCancel(
ox::CStringViewCR ok,
ox::CStringViewCR cancel) {
auto out = PopupResponse::None;
auto const scale = dpiScale();
auto const btnSz = ImVec2{50 * scale, BtnSz.y * scale};
constexpr auto btnSz = ImVec2{50, BtnSz.y};
ImGui::Separator();
ImGui::SetCursorPosX(popupWidth - 118 * scale);
ImGui::SetCursorPosX(popupWidth - 118);
if (ImGui::Button(ok.c_str(), btnSz)) {
popupOpen = false;
out = PopupResponse::OK;
@@ -100,18 +79,16 @@ PopupResponse PopupControlsOkCancel(
bool &popupOpen,
ox::CStringViewCR ok,
ox::CStringViewCR cancel) {
auto const scale = dpiScale();
return PopupControlsOkCancel(ImGui::GetContentRegionAvail().x + 17 * scale, popupOpen, ok, cancel);
return PopupControlsOkCancel(ImGui::GetContentRegionAvail().x + 17, popupOpen, ok, cancel);
}
PopupResponse PopupControlsOk(
bool &popupOpen,
ox::CStringViewCR ok) {
auto const scale = dpiScale();
auto out = PopupResponse::None;
auto const btnSz = ImVec2{50 * scale, BtnSz.y * scale};
constexpr auto btnSz = ImVec2{50, BtnSz.y};
ImGui::Separator();
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 42 * scale);
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 42);
if (ImGui::Button(ok.c_str(), btnSz)) {
popupOpen = false;
out = PopupResponse::OK;
@@ -124,24 +101,23 @@ PopupResponse PopupControlsOk(
return out;
}
bool BeginPopup(ox::CStringViewCR popupName, bool &show, ImVec2 sz) {
scaleSz(sz);
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const &sz) {
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
centerNextWindow();
centerNextWindow(ctx);
ImGui::OpenPopup(popupName.c_str());
ImGui::SetNextWindowSize(sz);
return ImGui::BeginPopupModal(popupName.c_str(), &show, modalFlags);
}
bool ComboBox(
ox::CStringViewCR lbl,
ox::CStringView const &lbl,
ox::SpanView<ox::CStringView> const list,
size_t &selectedIdx) noexcept {
bool out{};
auto const first = selectedIdx < list.size() ? list[selectedIdx].c_str() : "";
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
for (auto i = 0u; i < list.size(); ++i) {
auto const selected = selectedIdx == i;
auto const selected = (selectedIdx == i);
if (ImGui::Selectable(list[i].c_str(), selected) && selectedIdx != i) {
selectedIdx = i;
out = true;
@@ -153,14 +129,14 @@ bool ComboBox(
}
bool ComboBox(
ox::CStringViewCR lbl,
ox::CStringView const &lbl,
ox::Span<ox::String const> const list,
size_t &selectedIdx) noexcept {
bool out{};
auto const first = selectedIdx < list.size() ? list[selectedIdx].c_str() : "";
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
for (auto i = 0u; i < list.size(); ++i) {
auto const selected = selectedIdx == i;
auto const selected = (selectedIdx == i);
if (ImGui::Selectable(list[i].c_str(), selected) && selectedIdx != i) {
selectedIdx = i;
out = true;
@@ -205,14 +181,12 @@ bool ListBox(
std::function<ox::CStringView(size_t)> const &f,
size_t const strCnt,
size_t &selIdx,
ImVec2 sz) noexcept {
auto const scale = dpiScale();
sz = {sz.x * scale, sz.y * scale};
ImVec2 const &sz) noexcept {
auto out = false;
if (ImGui::BeginListBox(name.c_str(), sz)) {
for (size_t i = 0; i < strCnt; ++i) {
auto const str = f(i);
IDStackItem const idStackItem2(static_cast<int>(i));
auto str = f(i);
ig::IDStackItem const idStackItem2(static_cast<int>(i));
if (ImGui::Selectable(str.c_str(), selIdx == i)) {
if (i != selIdx) {
selIdx = i;
@@ -226,13 +200,13 @@ bool ListBox(
}
bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::String> const &list, size_t &selIdx) noexcept {
return ListBox(name, [list](size_t const i) -> ox::CStringView {
return ListBox(name, [list](size_t i) -> ox::CStringView {
return list[i];
}, list.size(), selIdx);
}
bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::CStringView> const &list, size_t &selIdx) noexcept {
return ListBox(name, [list](size_t const i) -> ox::CStringView {
return ListBox(name, [list](size_t i) -> ox::CStringView {
return list[i];
}, list.size(), selIdx);
}
@@ -255,7 +229,7 @@ void FilePicker::draw() noexcept {
}
auto constexpr popupSz = ImVec2{450.f, 0};
IDStackItem const idStackItem(m_title);
if (BeginPopup(m_title, m_show, popupSz)) {
if (BeginPopup(m_sctx.tctx, m_title, m_show, popupSz)) {
auto const &list = m_sctx.project->fileList(m_fileExt);
size_t selIdx{};
ComboBox(m_title, list, selIdx);
@@ -310,7 +284,7 @@ void QuestionPopup::draw(Context &ctx) noexcept {
turbine::requireRefreshFor(ctx.tctx, 1000);
[[fallthrough]];
case Stage::Open:
centerNextWindow();
centerNextWindow(ctx.tctx);
ImGui::SetNextWindowSize({});
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
@@ -345,7 +319,7 @@ void MessagePopup::show(ox::StringParam msg) noexcept {
open();
}
void MessagePopup::draw(Context&) noexcept {
void MessagePopup::draw(Context &ctx) noexcept {
switch (m_stage) {
case Stage::Closed:
break;
@@ -355,7 +329,7 @@ void MessagePopup::draw(Context&) noexcept {
m_open = true;
[[fallthrough]];
case Stage::Open:
centerNextWindow();
centerNextWindow(ctx.tctx);
ImGui::SetNextWindowSize({});
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
+3 -3
View File
@@ -7,9 +7,9 @@
namespace studio {
void Popup::drawWindow(turbine::Context&, bool &open, std::function<void()> const &drawContents) {
ig::centerNextWindow();
ImGui::SetNextWindowSize(static_cast<ImVec2>(m_size * ig::dpiScale()));
void Popup::drawWindow(turbine::Context &ctx, bool &open, std::function<void()> const &drawContents) {
ig::centerNextWindow(ctx);
ImGui::SetNextWindowSize(static_cast<ImVec2>(m_size));
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
if (ImGui::BeginPopupModal(m_title.c_str(), &open, modalFlags)) {
drawContents();
@@ -18,7 +18,6 @@ namespace gl {
class Drawer {
public:
virtual ~Drawer() = default;
virtual void preDraw(Context&) noexcept {}
virtual void draw(Context&) noexcept = 0;
};
void addDrawer(Context &ctx, Drawer *cd) noexcept;
@@ -11,6 +11,7 @@
#include "gfx.hpp"
namespace turbine {
class Context;
using TimeMs = uint64_t;
@@ -90,15 +91,9 @@ KeyEventHandler keyEventHandler(Context const &ctx) noexcept;
[[nodiscard]]
bool buttonDown(Context const &ctx, Key) noexcept;
ox::Result<ox::UPtr<Context>> init(
ox::UPtr<ox::FileSystem> &&fs,
ox::StringViewCR appName,
ox::StringViewCR appId = {}) noexcept;
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept;
ox::Result<ox::UPtr<Context>> init(
ox::StringViewCR fsPath,
ox::StringViewCR appName,
ox::StringViewCR appId = {}) noexcept;
ox::Result<ox::UPtr<Context>> init(ox::StringViewCR fsPath, ox::StringViewCR appName) noexcept;
ox::Error run(Context &ctx) noexcept;
@@ -117,10 +112,4 @@ void setShutdownHandler(Context &ctx, ShutdownHandler handler) noexcept;
// sleep time is a minimum of ~16 milliseconds.
void setUpdateHandler(Context &ctx, UpdateHandler) noexcept;
[[nodiscard]]
float scale(Context const &ctx) noexcept;
[[nodiscard]]
bool isWayland() noexcept;
}
+1 -9
View File
@@ -95,7 +95,7 @@ ox::Error setWindowBounds(Context&, ox::Bounds const&) noexcept {
}
ox::Result<ox::UPtr<Context>> init(
ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName, ox::StringViewCR) noexcept {
ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
auto ctx = ox::make_unique<Context>();
OX_RETURN_ERROR(keel::init(ctx->keelCtx, std::move(fs), appName));
#ifdef OX_BARE_METAL
@@ -139,12 +139,4 @@ KeyEventHandler keyEventHandler(Context const &ctx) noexcept {
return ctx.keyEventHandler;
}
float scale(Context const&) noexcept {
return 1;
}
bool isWayland() noexcept {
return false;
}
}
-1
View File
@@ -32,7 +32,6 @@ class Context {
uint64_t draws = 0;
bool running{};
ShutdownHandler shutdownHandler{};
float scale{};
Context() noexcept = default;
+2 -32
View File
@@ -235,15 +235,12 @@ void requireRefreshFor(Context &ctx, int ms) noexcept {
static void draw(Context &ctx) noexcept {
// draw start
for (auto const d : ctx.drawers) {
d->preDraw(ctx);
}
#if TURBINE_USE_IMGUI
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
#endif
for (auto const d : ctx.drawers) {
for (auto d : ctx.drawers) {
d->draw(ctx);
}
#if TURBINE_USE_IMGUI
@@ -333,9 +330,7 @@ static void handleGlfwWindowCloseEvent(GLFWwindow *window) noexcept {
}
ox::Result<ox::UPtr<Context>> init(
ox::UPtr<ox::FileSystem> &&fs,
ox::StringViewCR appName,
ox::StringViewCR appId) noexcept {
ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
auto ctx = ox::make_unique<Context>();
OX_RETURN_ERROR(keel::init(ctx->keelCtx, std::move(fs), appName));
using namespace std::chrono;
@@ -344,20 +339,12 @@ ox::Result<ox::UPtr<Context>> init(
setMandatoryRefreshPeriod(*ctx, ticksMs(*ctx) + config::MandatoryRefreshPeriod);
// init GLFW context
glfwInit();
glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
glfwSetErrorCallback(handleGlfwError);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
{
auto appIdCstr = ox_malloca(appId.bytes() + 1, char);
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::strncpy(appIdCstr.get(), appId.data(), appId.bytes());
OX_ALLOW_UNSAFE_BUFFERS_END
glfwWindowHintString(GLFW_WAYLAND_APP_ID, appIdCstr.get());
}
constexpr auto Scale = 5;
ctx->window = glfwCreateWindow(
240 * Scale, 160 * Scale, ctx->keelCtx.appName.c_str(), nullptr, nullptr);
@@ -386,13 +373,6 @@ ox::Result<ox::UPtr<Context>> init(
ImGui_ImplOpenGL3_Init();
io.IniFilename = nullptr;
themeImgui();
float xscale{}, yscale{};
glfwGetWindowContentScale(ctx->window, &xscale, &yscale);
ctx->scale = isWayland() || ox::defines::OS == ox::OS::Darwin ?
1.f : ox::max(xscale, yscale);
io.DisplayFramebufferScale = ImVec2{ctx->scale, ctx->scale};
auto &style = ImGui::GetStyle();
style.ScaleAllSizes(ctx->scale);
#endif
return ctx;
}
@@ -491,14 +471,4 @@ KeyEventHandler keyEventHandler(Context const &ctx) noexcept {
return ctx.keyEventHandler;
}
float scale(Context const &ctx) noexcept {
float x{}, y{};
glfwGetWindowContentScale(ctx.window, &x, &y);
return y;
}
bool isWayland() noexcept {
return glfwGetPlatform() == GLFW_PLATFORM_WAYLAND;
}
}
+2 -5
View File
@@ -8,12 +8,9 @@
namespace turbine {
ox::Result<ox::UPtr<Context>> init(
ox::StringViewCR fsPath,
ox::StringViewCR appName,
ox::StringViewCR appId) noexcept {
ox::Result<ox::UPtr<Context>> init(ox::StringViewCR fsPath, ox::StringViewCR appName) noexcept {
OX_REQUIRE_M(fs, keel::loadRomFs(fsPath));
return init(std::move(fs), appName, appId);
return init(std::move(fs), appName);
}
}
+1 -1
View File
@@ -64,7 +64,7 @@ def proc_rsrc_file(rsrc_path: str):# Open and read the JSON file
pop_ns = ''
cpp = '// Generated\n\n#include <ox/std/array.hpp>\n'
cpp += '#include <ox/std/span.hpp>\n\n'
hpp = '// Generated\n\n#pragma once\n\n#include <ox/std/span.hpp>\n\n'
hpp = '// Generated\n\n#include <ox/std/span.hpp>\n\n'
cpp += push_ns
hpp += push_ns
all_files_func_decl = ''
+14 -8
View File
@@ -8,30 +8,36 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import platform
import shutil
import subprocess
import sys
os = platform.system().lower()
arch = platform.machine()
host_env = f'{os}-{arch}'
def run(args: list[str]):
if subprocess.run(args).returncode != 0:
sys.exit(1)
# get the current build type
with open(".current_build", "r") as f:
current_build = f.readlines()[0]
if current_build[-1] == '\n':
current_build = current_build[:-1]
studio_path = sys.argv[1]
project_dir = sys.argv[2]
project_name = sys.argv[3]
project_dir = sys.argv[1]
project_name = sys.argv[2]
bin = f'./build/{host_env}-{current_build}/bin/'
project_bin = f'build/gba-release/bin/{project_name}.bin'
project_gba = f'{project_name}.gba'
project_manifest = f'{project_name.lower()}-manifest.json'
shutil.copyfile(project_bin, project_gba)
run([
studio_path,
'cmd',
project_dir,
'net.drinkingtea.studio',
'pack',
f'{bin}/{project_name.lower()}-pack',
'-src', project_dir,
'-rom-bin', project_gba,
'-manifest', project_manifest])
run(['gbafix', project_gba])