instrument editor undo: don't check delta if no user input has come in that could potentially have dirtied the editor

This commit is contained in:
Adam Lederer 2024-08-19 00:02:42 -07:00 committed by tildearrow
parent ea02a913b2
commit ad53b33d7c
5 changed files with 54 additions and 22 deletions

View file

@ -7740,31 +7740,44 @@ void FurnaceGUI::drawInsEdit() {
ImGui::EndPopup();
}
if (ins) {
bool insChanged=ins!=cachedCurInsPtr;
bool delayDiff=ImGui::IsMouseDown(ImGuiMouseButton_Left) || ImGui::IsMouseDown(ImGuiMouseButton_Right) || ImGui::GetIO().WantCaptureKeyboard;
// check against the last cached to see if diff -- note that modifications to instruments happen outside
// drawInsEdit (e.g. cursor inputs are processed and can directly modify macro data)
if (!insChanged && !delayDiff) {
ins->recordUndoStepIfChanged(e->processTime, &cachedCurIns);
}
if (insChanged || !delayDiff) {
cachedCurIns=*ins;
}
cachedCurInsPtr=ins;
} else {
cachedCurInsPtr=NULL;
}
}
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_INS_EDIT;
ImGui::End();
}
void FurnaceGUI::checkRecordInstrumentUndoStep() {
if (curIns>=0 && curIns<(int)e->song.ins.size()) {
DivInstrument* ins=e->song.ins[curIns];
// invalidate cachedCurIns/any possible changes if the cachedCurIns was referencing a different
// instrument altgoether
bool insChanged=ins!=cachedCurInsPtr;
if (insChanged) {
insEditMayBeDirty=false;
cachedCurInsPtr=ins;
cachedCurIns=*ins;
}
cachedCurInsPtr=ins;
// check against the last cached to see if diff -- note that modifications to instruments
// happen outside drawInsEdit (e.g. cursor inputs are processed and can directly modify
// macro data). but don't check until we think the user input is complete.
bool delayDiff=ImGui::IsMouseDown(ImGuiMouseButton_Left) || ImGui::IsMouseDown(ImGuiMouseButton_Right) || ImGui::GetIO().WantCaptureKeyboard;
if (!delayDiff && insEditMayBeDirty) {
bool hasChange=ins->recordUndoStepIfChanged(e->processTime, &cachedCurIns);
if (hasChange) {
cachedCurIns=*ins;
}
insEditMayBeDirty=false;
}
} else {
cachedCurInsPtr=NULL;
insEditMayBeDirty=false;
}
}
void FurnaceGUI::doUndoInstrument() {
if (!insEditOpen) return;
if (curIns<0 || curIns>=(int)e->song.ins.size()) return;