[nostalgia,studio] Update for new ImGui's Mac awareness
All checks were successful
Build / build (push) Successful in 2m39s

This commit is contained in:
Gary Talent 2024-05-31 22:04:31 -05:00
parent 976550ef6f
commit 430cae1622
3 changed files with 46 additions and 56 deletions

View File

@ -202,7 +202,7 @@ 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::IsKeyDown(ImGuiKey_ModCtrl)) {
if (ImGui::IsKeyPressed(ImGuiKey_A)) {
auto const&img = m_model.activeSubSheet();
m_model.setSelection({{}, {img.columns * TileWidth, img.rows * TileHeight}});
@ -408,19 +408,17 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
ImVec2(1, 0));
// handle input, this must come after drawing
auto const&io = ImGui::GetIO();
auto const mousePos = ox::Vec2(io.MousePos);
auto const mousePos = ox::Vec2(ImGui::GetMousePos());
if (ImGui::IsItemHovered()) {
auto const wheel = io.MouseWheel;
auto const wheelh = io.MouseWheelH;
if (wheel != 0) {
const auto zoomMod = ox::defines::OS == ox::OS::Darwin ?
io.KeySuper : turbine::buttonDown(m_tctx, turbine::Key::Mod_Ctrl);
m_view.scrollV(fbSize, wheel, zoomMod);
m_view.scrollV(fbSize, wheel, ImGui::IsKeyDown(ImGuiKey_ModCtrl));
}
if (wheelh != 0) {
m_view.scrollH(fbSize, wheelh);
}
if (io.MouseDown[0] && m_prevMouseDownPos != mousePos) {
if (ImGui::IsMouseDown(0) && m_prevMouseDownPos != mousePos) {
m_prevMouseDownPos = mousePos;
switch (m_tool) {
case TileSheetTool::Draw:

View File

@ -83,7 +83,6 @@ void StudioUI::update() noexcept {
}
void StudioUI::handleKeyEvent(turbine::Key key, bool down) noexcept {
auto const ctrlDown = turbine::buttonDown(m_ctx, turbine::Key::Mod_Ctrl);
for (auto p : m_popups) {
if (p->isOpen()) {
if (key == turbine::Key::Escape) {
@ -92,55 +91,7 @@ void StudioUI::handleKeyEvent(turbine::Key key, bool down) noexcept {
return;
}
}
if (down && ctrlDown) {
switch (key) {
case turbine::Key::Num_1:
toggleProjectExplorer();
break;
case turbine::Key::Alpha_C:
if (m_activeEditor && m_activeEditor->copyEnabled()) {
m_activeEditor->copy();
}
break;
case turbine::Key::Alpha_N:
if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Shift)) {
m_newProject.open();
} else {
m_newMenu.open();
}
break;
case turbine::Key::Alpha_O:
m_taskRunner.add(*ox::make<FileDialogManager>(this, &StudioUI::openProjectPath));
break;
case turbine::Key::Alpha_Q:
turbine::requestShutdown(m_ctx);
break;
case turbine::Key::Alpha_S:
save();
break;
case turbine::Key::Alpha_V:
if (m_activeEditor && m_activeEditor->pasteEnabled()) {
m_activeEditor->paste();
}
break;
case turbine::Key::Alpha_X:
if (m_activeEditor && m_activeEditor->cutEnabled()) {
m_activeEditor->cut();
}
break;
case turbine::Key::Alpha_Y:
redo();
break;
case turbine::Key::Alpha_Z:
undo();
break;
default:
if (m_activeEditor) {
m_activeEditor->keyStateChanged(key, down);
}
break;
}
} else if (m_activeEditor && !ctrlDown) {
if (m_activeEditor && !ImGui::IsKeyDown(ImGuiKey_ModCtrl)) {
m_activeEditor->keyStateChanged(key, down);
}
}
@ -172,6 +123,7 @@ void StudioUI::draw() noexcept {
}
}
ImGui::End();
handleKeyInput();
}
void StudioUI::drawMenu() noexcept {
@ -332,6 +284,44 @@ void StudioUI::save() noexcept {
}
}
void StudioUI::handleKeyInput() noexcept {
if (ImGui::IsKeyDown(ImGuiKey_ModCtrl)) {
if (ImGui::IsKeyPressed(ImGuiKey_C)) {
if (m_activeEditor && m_activeEditor->copyEnabled()) {
m_activeEditor->copy();
}
} else if (ImGui::IsKeyPressed(ImGuiKey_N)) {
if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Shift)) {
m_newProject.open();
} else {
m_newMenu.open();
}
} else if (ImGui::IsKeyPressed(ImGuiKey_O)) {
m_taskRunner.add(*ox::make<FileDialogManager>(this, &StudioUI::openProjectPath));
} else if (ImGui::IsKeyPressed(ImGuiKey_S)) {
save();
} else if (ImGui::IsKeyPressed(ImGuiKey_Q)) {
turbine::requestShutdown(m_ctx);
} else if (ImGui::IsKeyPressed(ImGuiKey_V)) {
if (m_activeEditor && m_activeEditor->pasteEnabled()) {
m_activeEditor->paste();
}
} else if (ImGui::IsKeyPressed(ImGuiKey_X)) {
if (m_activeEditor && m_activeEditor->cutEnabled()) {
m_activeEditor->cut();
}
} else if (ImGui::IsKeyPressed(ImGuiKey_Y)) {
auto const undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
if (undoStack) { oxLogError(undoStack->redo()); }
} else if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
auto const undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
if (undoStack) { oxLogError(undoStack->undo()); }
} else if (ImGui::IsKeyPressed(ImGuiKey_1)) {
toggleProjectExplorer();
}
}
}
ox::Error StudioUI::createOpenProject(ox::CRStringView path) noexcept {
std::error_code ec;
std::filesystem::create_directories(toStdStringView(path), ec);

View File

@ -83,6 +83,8 @@ class StudioUI: public ox::SignalHandler {
void save() noexcept;
void handleKeyInput() noexcept;
ox::Error createOpenProject(ox::CRStringView path) noexcept;
ox::Error openProjectPath(ox::CRStringView path) noexcept;