Squashed 'deps/nostalgia/' changes from c2e34b64..5d1f680a
5d1f680a [nostalgia/core] Cleanup TileSheetEditor with new ImGui util functions git-subtree-dir: deps/nostalgia git-subtree-split: 5d1f680a513788d9cedac5b711d68eb085d780a6
This commit is contained in:
		@@ -12,6 +12,8 @@
 | 
			
		||||
 | 
			
		||||
namespace nostalgia::core {
 | 
			
		||||
 | 
			
		||||
namespace ig = studio::ig;
 | 
			
		||||
 | 
			
		||||
static ox::Vector<uint32_t> normalizePixelSizes(
 | 
			
		||||
		ox::Vector<uint8_t> const&inPixels,
 | 
			
		||||
		int const bpp) noexcept {
 | 
			
		||||
@@ -194,9 +196,9 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept {
 | 
			
		||||
		ImGui::EndChild();
 | 
			
		||||
		ImGui::BeginChild("SubSheets", ImVec2(m_palViewWidth - 24, ySize / 2.f), true);
 | 
			
		||||
		{
 | 
			
		||||
			static constexpr auto btnHeight = 18;
 | 
			
		||||
			auto const btnSize = ImVec2(18, btnHeight);
 | 
			
		||||
			if (ImGui::Button("+", btnSize)) {
 | 
			
		||||
			static constexpr auto btnHeight = ig::BtnSz.y;
 | 
			
		||||
			auto const btnSize = ImVec2(btnHeight, btnHeight);
 | 
			
		||||
			if (ig::PushButton("+", btnSize)) {
 | 
			
		||||
				auto insertOnIdx = m_model.activeSubSheetIdx();
 | 
			
		||||
				auto const&parent = m_model.activeSubSheet();
 | 
			
		||||
				m_model.addSubsheet(insertOnIdx);
 | 
			
		||||
@@ -204,18 +206,18 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept {
 | 
			
		||||
				m_model.setActiveSubsheet(insertOnIdx);
 | 
			
		||||
			}
 | 
			
		||||
			ImGui::SameLine();
 | 
			
		||||
			if (ImGui::Button("-", btnSize)) {
 | 
			
		||||
			if (ig::PushButton("-", btnSize)) {
 | 
			
		||||
				auto const&activeSubsheetIdx = m_model.activeSubSheetIdx();
 | 
			
		||||
				if (!activeSubsheetIdx.empty()) {
 | 
			
		||||
					m_model.rmSubsheet(activeSubsheetIdx);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			ImGui::SameLine();
 | 
			
		||||
			if (ImGui::Button("Edit", ImVec2(51, btnHeight))) {
 | 
			
		||||
			if (ig::PushButton("Edit")) {
 | 
			
		||||
				showSubsheetEditor();
 | 
			
		||||
			}
 | 
			
		||||
			ImGui::SameLine();
 | 
			
		||||
			if (ImGui::Button("Export", ImVec2(51, btnHeight))) {
 | 
			
		||||
			if (ig::PushButton("Export")) {
 | 
			
		||||
				m_exportMenu.show();
 | 
			
		||||
			}
 | 
			
		||||
			TileSheet::SubSheetIdx path;
 | 
			
		||||
@@ -233,11 +235,12 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept {
 | 
			
		||||
		ImGui::EndChild();
 | 
			
		||||
	}
 | 
			
		||||
	ImGui::EndChild();
 | 
			
		||||
	m_subsheetEditor.draw();
 | 
			
		||||
	m_exportMenu.draw();
 | 
			
		||||
	m_subsheetEditor.draw(m_ctx);
 | 
			
		||||
	m_exportMenu.draw(m_ctx);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TileSheetEditorImGui::drawSubsheetSelector(TileSheet::SubSheet &subsheet, TileSheet::SubSheetIdx &path) {
 | 
			
		||||
void TileSheetEditorImGui::drawSubsheetSelector(
 | 
			
		||||
		TileSheet::SubSheet &subsheet, TileSheet::SubSheetIdx &path) {
 | 
			
		||||
	constexpr auto indentReduce = 14;
 | 
			
		||||
	ImGui::TableNextRow(0, 5);
 | 
			
		||||
	using Str = ox::BasicString<100>;
 | 
			
		||||
@@ -398,22 +401,10 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
 | 
			
		||||
void TileSheetEditorImGui::drawPaletteSelector() noexcept {
 | 
			
		||||
	auto &sctx = *applicationData<studio::StudioContext>(m_ctx);
 | 
			
		||||
	auto const&files = sctx.project->fileList(core::FileExt_npal);
 | 
			
		||||
	auto const first = m_selectedPaletteIdx < files.size() ?
 | 
			
		||||
		files[m_selectedPaletteIdx].c_str() : "";
 | 
			
		||||
	auto const comboWidthSub = 62;
 | 
			
		||||
	ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub);
 | 
			
		||||
	if (ImGui::BeginCombo("Palette", first, 0)) {
 | 
			
		||||
		for (auto n = 0u; n < files.size(); ++n) {
 | 
			
		||||
			const auto selected = (m_selectedPaletteIdx == n);
 | 
			
		||||
			if (ImGui::Selectable(files[n].c_str(), selected) && m_selectedPaletteIdx != n) {
 | 
			
		||||
				m_selectedPaletteIdx = n;
 | 
			
		||||
				oxLogError(m_model.setPalette(files[n]));
 | 
			
		||||
			}
 | 
			
		||||
			if (selected) {
 | 
			
		||||
				ImGui::SetItemDefaultFocus();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		ImGui::EndCombo();
 | 
			
		||||
	if (ig::ComboBox("Palette", files, m_selectedPaletteIdx)) {
 | 
			
		||||
		oxLogError(m_model.setPalette(files[m_selectedPaletteIdx]));
 | 
			
		||||
	}
 | 
			
		||||
	auto const pages = m_model.pal().pages.size();
 | 
			
		||||
	if (pages > 1) {
 | 
			
		||||
@@ -491,34 +482,24 @@ ox::Error TileSheetEditorImGui::markUnsavedChanges(studio::UndoCommand const*) n
 | 
			
		||||
	return {};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TileSheetEditorImGui::SubSheetEditor::draw() noexcept {
 | 
			
		||||
	constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
 | 
			
		||||
void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &ctx) noexcept {
 | 
			
		||||
	constexpr auto popupName = "Edit Subsheet";
 | 
			
		||||
	if (!m_show) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	ImGui::OpenPopup(popupName);
 | 
			
		||||
	auto const modSize = m_cols > 0;
 | 
			
		||||
	auto const popupWidth = 235.f;
 | 
			
		||||
	auto const popupHeight = modSize ? 125.f : 80.f;
 | 
			
		||||
	ImGui::SetNextWindowSize(ImVec2(popupWidth, popupHeight));
 | 
			
		||||
	if (ImGui::BeginPopupModal(popupName, &m_show, modalFlags)) {
 | 
			
		||||
	auto constexpr popupWidth = 235.f;
 | 
			
		||||
	auto const popupHeight = modSize ? 130.f : 85.f;
 | 
			
		||||
	auto const popupSz = ImVec2(popupWidth, popupHeight);
 | 
			
		||||
	if (ig::BeginPopup(ctx, popupName, m_show, popupSz)) {
 | 
			
		||||
		ImGui::InputText("Name", m_name.data(), m_name.cap());
 | 
			
		||||
		if (modSize) {
 | 
			
		||||
			ImGui::InputInt("Columns", &m_cols);
 | 
			
		||||
			ImGui::InputInt("Rows", &m_rows);
 | 
			
		||||
		}
 | 
			
		||||
		ImGui::SetCursorPosX(popupWidth - 116);
 | 
			
		||||
		if (ImGui::Button("OK", ImVec2{50, 20})) {
 | 
			
		||||
			ImGui::CloseCurrentPopup();
 | 
			
		||||
			m_show = false;
 | 
			
		||||
		if (ig::PopupControlsOkCancel(popupWidth, m_show) == ig::PopupResponse::OK) {
 | 
			
		||||
			inputSubmitted.emit(m_name, m_cols, m_rows);
 | 
			
		||||
		}
 | 
			
		||||
		ImGui::SameLine();
 | 
			
		||||
		if (ImGui::Button("Cancel", ImVec2{50, 20})) {
 | 
			
		||||
			ImGui::CloseCurrentPopup();
 | 
			
		||||
			m_show = false;
 | 
			
		||||
		}
 | 
			
		||||
		ImGui::EndPopup();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -527,28 +508,20 @@ void TileSheetEditorImGui::SubSheetEditor::close() noexcept {
 | 
			
		||||
	m_show = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TileSheetEditorImGui::ExportMenu::draw() noexcept {
 | 
			
		||||
	constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
 | 
			
		||||
void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &ctx) noexcept {
 | 
			
		||||
	constexpr auto popupName = "Export Tile Sheet";
 | 
			
		||||
	if (!m_show) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	ImGui::OpenPopup(popupName);
 | 
			
		||||
	constexpr auto popupHeight = 80.f;
 | 
			
		||||
	ImGui::SetNextWindowSize(ImVec2(235, popupHeight));
 | 
			
		||||
	if (ImGui::BeginPopupModal(popupName, &m_show, modalFlags)) {
 | 
			
		||||
	constexpr auto popupWidth = 235.f;
 | 
			
		||||
	constexpr auto popupHeight = 85.f;
 | 
			
		||||
	constexpr auto popupSz = ImVec2(popupWidth, popupHeight);
 | 
			
		||||
	if (ig::BeginPopup(ctx, popupName, m_show, popupSz)) {
 | 
			
		||||
		ImGui::InputInt("Scale", &m_scale);
 | 
			
		||||
		m_scale = ox::clamp(m_scale, 1, 50);
 | 
			
		||||
		if (ImGui::Button("OK", ImVec2{50, 20})) {
 | 
			
		||||
			ImGui::CloseCurrentPopup();
 | 
			
		||||
			m_show = false;
 | 
			
		||||
		if (ig::PopupControlsOkCancel(popupWidth, m_show) == ig::PopupResponse::OK) {
 | 
			
		||||
			inputSubmitted.emit(m_scale);
 | 
			
		||||
		}
 | 
			
		||||
		ImGui::SameLine();
 | 
			
		||||
		if (ImGui::Button("Cancel", ImVec2{50, 20})) {
 | 
			
		||||
			ImGui::CloseCurrentPopup();
 | 
			
		||||
			m_show = false;
 | 
			
		||||
		}
 | 
			
		||||
		ImGui::EndPopup();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,7 @@ class TileSheetEditorImGui: public studio::Editor {
 | 
			
		||||
					m_cols = cols;
 | 
			
		||||
					m_rows = rows;
 | 
			
		||||
				}
 | 
			
		||||
				void draw() noexcept;
 | 
			
		||||
				void draw(turbine::Context &ctx) noexcept;
 | 
			
		||||
				void close() noexcept;
 | 
			
		||||
				[[nodiscard]]
 | 
			
		||||
				inline bool isOpen() const noexcept { return m_show; }
 | 
			
		||||
@@ -55,7 +55,7 @@ class TileSheetEditorImGui: public studio::Editor {
 | 
			
		||||
					m_show = true;
 | 
			
		||||
					m_scale = 5;
 | 
			
		||||
				}
 | 
			
		||||
				void draw() noexcept;
 | 
			
		||||
				void draw(turbine::Context &ctx) noexcept;
 | 
			
		||||
				void close() noexcept;
 | 
			
		||||
				[[nodiscard]]
 | 
			
		||||
				inline bool isOpen() const noexcept { return m_show; }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user