[nostalgia/core/studio,studio] Give TileSheetEditor Ctrl-A and Ctrl-G for selection

This commit is contained in:
Gary Talent 2024-05-31 00:40:48 -05:00
parent 2ede01e7e2
commit 6c71e1e24c
4 changed files with 30 additions and 8 deletions

View File

@ -154,7 +154,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) {
m_subsheetEditor.close(); m_subsheetEditor.close();
m_exportMenu.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(); auto const pal = m_model.pal();
if (!popupOpen) { if (!popupOpen) {
auto const colorCnt = core::colorCnt(pal, m_model.palettePage()); 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 { 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 paneSize = ImGui::GetContentRegionAvail();
auto const tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y); auto const tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y);
auto const fbSize = ox::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16); auto const fbSize = ox::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16);
@ -209,10 +220,10 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
} }
ImGui::EndChild(); ImGui::EndChild();
ImGui::SameLine(); 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(); 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); auto const btnSz = ImVec2(45, 14);
if (ImGui::Selectable("Select", m_tool == TileSheetTool::Select, 0, btnSz)) { if (ImGui::Selectable("Select", m_tool == TileSheetTool::Select, 0, btnSz)) {
@ -232,15 +243,15 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
ImGui::EndChild(); ImGui::EndChild();
auto const ySize = controlsSize.y - 38; auto const ySize = controlsSize.y - 38;
// draw palette/color picker // 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(); drawPaletteSelector();
} }
ImGui::EndChild(); 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; static constexpr auto btnHeight = ig::BtnSz.y;
auto const btnSize = ImVec2(btnHeight, btnHeight); auto const btnSize = ImVec2{btnHeight, btnHeight};
if (ig::PushButton("+", btnSize)) { if (ig::PushButton("+", btnSize)) {
auto insertOnIdx = m_model.activeSubSheetIdx(); auto insertOnIdx = m_model.activeSubSheetIdx();
auto const&parent = m_model.activeSubSheet(); auto const&parent = m_model.activeSubSheet();

View File

@ -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 { void TileSheetEditorModel::select(ox::Point const&pt) noexcept {
if (m_selTracker.updateCursorPoint(pt)) { if (m_selTracker.updateCursorPoint(pt)) {
m_selection.emplace(m_selTracker.selection()); setSelection(m_selTracker.selection());
m_updated = true;
} }
} }
@ -234,6 +238,7 @@ void TileSheetEditorModel::completeSelection() noexcept {
void TileSheetEditorModel::clearSelection() noexcept { void TileSheetEditorModel::clearSelection() noexcept {
m_updated = true; m_updated = true;
m_selTracker.reset();
m_selection.reset(); m_selection.reset();
} }

View File

@ -103,6 +103,8 @@ class TileSheetEditorModel: public ox::SignalHandler {
void fill(ox::Point const&pt, int palIdx) noexcept; void fill(ox::Point const&pt, int palIdx) noexcept;
void setSelection(studio::Selection const&sel) noexcept;
void select(ox::Point const&pt) noexcept; void select(ox::Point const&pt) noexcept;
void completeSelection() noexcept; void completeSelection() noexcept;

View File

@ -111,6 +111,10 @@ class SelectionTracker {
allowStart); allowStart);
} }
constexpr void reset() noexcept {
m_selectionOngoing = {};
}
constexpr void finishSelection() noexcept { constexpr void finishSelection() noexcept {
m_selectionOngoing = {}; m_selectionOngoing = {};
} }