Squashed 'deps/nostalgia/' changes from dd5d1bfb..976550ef
976550ef [nostalgia/sample_project] Add missing type descriptors 1fb0a866 [nostalgia/core] Fix CompactPalette TypeName and TypeVersion eb46aeeb [nfde] Fix compiler warnings on Gtk build 9244b735 [nostalgia] Fix non-Linux non-Apple systems not to build GLFW for Wayland 3fba36b4 [nfde] Make only option BUILD_SHARED_LIBS if not already set 6ddb6b42 Merge commit '5461f6700dac79e9e71e3966f8a1270706c385ba' 5461f670 Squashed 'deps/nfde/' changes from 28ade5a5c..5786fabce 1ecc7aa7 Merge commit '26c8cc348eacea01237cd64e1a68d0df8141e848' 26c8cc34 Squashed 'deps/glfw/' changes from 7d5a16ce7..7b6aead9f fc25c12d Merge commit 'ae51a422787bc3b720ff1748c0219c8f33363427' ae51a422 Squashed 'deps/imgui/' changes from f33737806..2db79d086 6c71e1e2 [nostalgia/core/studio,studio] Give TileSheetEditor Ctrl-A and Ctrl-G for selection 2ede01e7 [nostalgia/core/studio] Fix build deacd4ab [nostalgia/core/studio] Fix PaletteEditor add/remove color commands git-subtree-dir: deps/nostalgia git-subtree-split: 976550ef6fa269cf1e367e880f148b0ad7b1b163
This commit is contained in:
		@@ -58,8 +58,8 @@ using Palette = PaletteV3;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct CompactPaletteV1 {
 | 
			
		||||
	static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.Palette";
 | 
			
		||||
	static constexpr auto TypeVersion = 2;
 | 
			
		||||
	static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.CompactPalette";
 | 
			
		||||
	static constexpr auto TypeVersion = 1;
 | 
			
		||||
	static constexpr auto Preloadable = true;
 | 
			
		||||
	ox::Vector<ox::Vector<Color16>> pages{};
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -293,7 +293,7 @@ ox::Vector<uint8_t> pixels(TileSheet &ts) noexcept;
 | 
			
		||||
 | 
			
		||||
using TileSheetV4 = TileSheet;
 | 
			
		||||
 | 
			
		||||
struct CompactTileSheet {
 | 
			
		||||
struct CompactTileSheetV1 {
 | 
			
		||||
	static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.CompactTileSheet";
 | 
			
		||||
	static constexpr auto TypeVersion = 1;
 | 
			
		||||
	int8_t bpp = 0;
 | 
			
		||||
@@ -301,6 +301,8 @@ struct CompactTileSheet {
 | 
			
		||||
	ox::Vector<uint8_t> pixels = {};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
using CompactTileSheet = CompactTileSheetV1;
 | 
			
		||||
 | 
			
		||||
oxModelBegin(TileSheetV1)
 | 
			
		||||
	oxModelField(bpp)
 | 
			
		||||
	oxModelField(rows)
 | 
			
		||||
@@ -355,7 +357,7 @@ oxModelBegin(TileSheetV4)
 | 
			
		||||
	oxModelField(subsheet)
 | 
			
		||||
oxModelEnd()
 | 
			
		||||
 | 
			
		||||
oxModelBegin(CompactTileSheet)
 | 
			
		||||
oxModelBegin(CompactTileSheetV1)
 | 
			
		||||
	oxModelField(bpp)
 | 
			
		||||
	oxModelField(defaultPalette)
 | 
			
		||||
	oxModelField(pixels)
 | 
			
		||||
 
 | 
			
		||||
@@ -38,9 +38,10 @@ static class: public keel::Module {
 | 
			
		||||
				keel::generateTypeDesc<TileSheetV2>,
 | 
			
		||||
				keel::generateTypeDesc<TileSheetV3>,
 | 
			
		||||
				keel::generateTypeDesc<TileSheetV4>,
 | 
			
		||||
				keel::generateTypeDesc<CompactTileSheet>,
 | 
			
		||||
				keel::generateTypeDesc<CompactTileSheetV1>,
 | 
			
		||||
				keel::generateTypeDesc<PaletteV1>,
 | 
			
		||||
				keel::generateTypeDesc<PaletteV2>,
 | 
			
		||||
				keel::generateTypeDesc<CompactPaletteV1>,
 | 
			
		||||
			};
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -68,7 +68,7 @@ ox::Error DuplicatePageCommand::redo() noexcept {
 | 
			
		||||
 | 
			
		||||
ox::Error DuplicatePageCommand::undo() noexcept {
 | 
			
		||||
	m_page = std::move(m_pal.pages[m_dstIdx]);
 | 
			
		||||
	return m_pal.pages.erase(static_cast<std::size_t>(m_dstIdx)).error;
 | 
			
		||||
	return m_pal.pages.erase(m_dstIdx).error;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
size_t DuplicatePageCommand::insertIdx() const noexcept {
 | 
			
		||||
@@ -86,7 +86,7 @@ int RemovePageCommand::commandId() const noexcept {
 | 
			
		||||
 | 
			
		||||
ox::Error RemovePageCommand::redo() noexcept {
 | 
			
		||||
	m_page = std::move(colors(m_pal, m_idx));
 | 
			
		||||
	return m_pal.pages.erase(static_cast<std::size_t>(m_idx)).error;
 | 
			
		||||
	return m_pal.pages.erase(m_idx).error;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ox::Error RemovePageCommand::undo() noexcept {
 | 
			
		||||
@@ -105,15 +105,17 @@ int AddColorCommand::commandId() const noexcept {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ox::Error AddColorCommand::redo() noexcept {
 | 
			
		||||
	m_pal.colorInfo.emplace(m_idx, ox::sfmt("Color {}", m_pal.colorInfo.size() + 1));
 | 
			
		||||
	for (auto &page : m_pal.pages) {
 | 
			
		||||
		page.emplace(static_cast<size_t>(m_idx), m_color);
 | 
			
		||||
		page.emplace(m_idx, m_color);
 | 
			
		||||
	}
 | 
			
		||||
	return {};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ox::Error AddColorCommand::undo() noexcept {
 | 
			
		||||
	oxReturnError(m_pal.colorInfo.erase(m_idx));
 | 
			
		||||
	for (auto &page : m_pal.pages) {
 | 
			
		||||
		oxReturnError(page.erase(static_cast<std::size_t>(m_idx)));
 | 
			
		||||
		oxReturnError(page.erase(m_idx));
 | 
			
		||||
	}
 | 
			
		||||
	return {};
 | 
			
		||||
}
 | 
			
		||||
@@ -136,6 +138,8 @@ int RemoveColorCommand::commandId() const noexcept {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ox::Error RemoveColorCommand::redo() noexcept {
 | 
			
		||||
	m_colorInfo = std::move(m_pal.colorInfo[m_idx]);
 | 
			
		||||
	oxReturnError(m_pal.colorInfo.erase(m_idx));
 | 
			
		||||
	for (auto &page : m_pal.pages) {
 | 
			
		||||
		oxReturnError(page.erase(m_idx));
 | 
			
		||||
	}
 | 
			
		||||
@@ -143,6 +147,7 @@ ox::Error RemoveColorCommand::redo() noexcept {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ox::Error RemoveColorCommand::undo() noexcept {
 | 
			
		||||
	m_pal.colorInfo.emplace(m_idx, std::move(m_colorInfo));
 | 
			
		||||
	for (size_t p = 0; auto &page : m_pal.pages) {
 | 
			
		||||
		page.emplace(m_idx, m_colors[p]);
 | 
			
		||||
		++p;
 | 
			
		||||
 
 | 
			
		||||
@@ -111,6 +111,7 @@ class RemoveColorCommand: public studio::UndoCommand {
 | 
			
		||||
	private:
 | 
			
		||||
		Palette &m_pal;
 | 
			
		||||
		size_t const m_idx = 0;
 | 
			
		||||
		Palette::ColorInfo m_colorInfo;
 | 
			
		||||
		ox::Vector<Color16> const m_colors;
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
 
 | 
			
		||||
@@ -154,7 +154,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
 | 
			
		||||
		m_subsheetEditor.close();
 | 
			
		||||
		m_exportMenu.close();
 | 
			
		||||
	}
 | 
			
		||||
	auto const popupOpen = m_subsheetEditor.isOpen() && m_exportMenu.isOpen();
 | 
			
		||||
	auto const popupOpen = m_subsheetEditor.isOpen() || m_exportMenu.isOpen();
 | 
			
		||||
	auto const pal = m_model.pal();
 | 
			
		||||
	if (!popupOpen) {
 | 
			
		||||
		auto const colorCnt = core::colorCnt(pal, m_model.palettePage());
 | 
			
		||||
@@ -200,6 +200,17 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
 | 
			
		||||
	auto const popupOpen = m_subsheetEditor.isOpen() || m_exportMenu.isOpen();
 | 
			
		||||
	if (!popupOpen && m_tool == TileSheetTool::Select) {
 | 
			
		||||
		if (ImGui::IsKeyPressed(ImGuiKey_ModCtrl)) {
 | 
			
		||||
			if (ImGui::IsKeyPressed(ImGuiKey_A)) {
 | 
			
		||||
				auto const&img = m_model.activeSubSheet();
 | 
			
		||||
				m_model.setSelection({{}, {img.columns * TileWidth, img.rows * TileHeight}});
 | 
			
		||||
			} else if (ImGui::IsKeyPressed(ImGuiKey_G)) {
 | 
			
		||||
				m_model.clearSelection();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	auto const paneSize = ImGui::GetContentRegionAvail();
 | 
			
		||||
	auto const tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y);
 | 
			
		||||
	auto const fbSize = ox::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16);
 | 
			
		||||
@@ -209,10 +220,10 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
 | 
			
		||||
	}
 | 
			
		||||
	ImGui::EndChild();
 | 
			
		||||
	ImGui::SameLine();
 | 
			
		||||
	ImGui::BeginChild("Controls", ImVec2(m_palViewWidth - 8, paneSize.y), true);
 | 
			
		||||
	ImGui::BeginChild("Controls", {m_palViewWidth - 8, paneSize.y}, true);
 | 
			
		||||
	{
 | 
			
		||||
		auto const controlsSize = ImGui::GetContentRegionAvail();
 | 
			
		||||
		ImGui::BeginChild("ToolBox", ImVec2(m_palViewWidth - 24, 30), true);
 | 
			
		||||
		ImGui::BeginChild("ToolBox", {m_palViewWidth - 24, 30}, true);
 | 
			
		||||
		{
 | 
			
		||||
			auto const btnSz = ImVec2(45, 14);
 | 
			
		||||
			if (ImGui::Selectable("Select", m_tool == TileSheetTool::Select, 0, btnSz)) {
 | 
			
		||||
@@ -232,15 +243,15 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
 | 
			
		||||
		ImGui::EndChild();
 | 
			
		||||
		auto const ySize = controlsSize.y - 38;
 | 
			
		||||
		// draw palette/color picker
 | 
			
		||||
		ImGui::BeginChild("Palette", ImVec2(m_palViewWidth - 24, ySize / 2.f), true);
 | 
			
		||||
		ImGui::BeginChild("Palette", {m_palViewWidth - 24, ySize / 2.f}, true);
 | 
			
		||||
		{
 | 
			
		||||
			drawPaletteSelector();
 | 
			
		||||
		}
 | 
			
		||||
		ImGui::EndChild();
 | 
			
		||||
		ImGui::BeginChild("SubSheets", ImVec2(m_palViewWidth - 24, ySize / 2.f), true);
 | 
			
		||||
		ImGui::BeginChild("SubSheets", {m_palViewWidth - 24, ySize / 2.f}, true);
 | 
			
		||||
		{
 | 
			
		||||
			static constexpr auto btnHeight = ig::BtnSz.y;
 | 
			
		||||
			auto const btnSize = ImVec2(btnHeight, btnHeight);
 | 
			
		||||
			auto const btnSize = ImVec2{btnHeight, btnHeight};
 | 
			
		||||
			if (ig::PushButton("+", btnSize)) {
 | 
			
		||||
				auto insertOnIdx = m_model.activeSubSheetIdx();
 | 
			
		||||
				auto const&parent = m_model.activeSubSheet();
 | 
			
		||||
 
 | 
			
		||||
@@ -214,10 +214,14 @@ void TileSheetEditorModel::fill(ox::Point const&pt, int palIdx) noexcept {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TileSheetEditorModel::setSelection(studio::Selection const&sel) noexcept {
 | 
			
		||||
	m_selection.emplace(sel);
 | 
			
		||||
	m_updated = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TileSheetEditorModel::select(ox::Point const&pt) noexcept {
 | 
			
		||||
	if (m_selTracker.updateCursorPoint(pt)) {
 | 
			
		||||
		m_selection.emplace(m_selTracker.selection());
 | 
			
		||||
		m_updated = true;
 | 
			
		||||
		setSelection(m_selTracker.selection());
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -234,6 +238,7 @@ void TileSheetEditorModel::completeSelection() noexcept {
 | 
			
		||||
 | 
			
		||||
void TileSheetEditorModel::clearSelection() noexcept {
 | 
			
		||||
	m_updated = true;
 | 
			
		||||
	m_selTracker.reset();
 | 
			
		||||
	m_selection.reset();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -103,6 +103,8 @@ class TileSheetEditorModel: public ox::SignalHandler {
 | 
			
		||||
 | 
			
		||||
		void fill(ox::Point const&pt, int palIdx) noexcept;
 | 
			
		||||
 | 
			
		||||
		void setSelection(studio::Selection const&sel) noexcept;
 | 
			
		||||
 | 
			
		||||
		void select(ox::Point const&pt) noexcept;
 | 
			
		||||
 | 
			
		||||
		void completeSelection() noexcept;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user