From 81146a87537cd7bc38b79b4b9dc8fe36b5ea7ba8 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Wed, 17 Sep 2014 12:03:17 +0200 Subject: [PATCH] Implemented inverse keys Closes #98 --- ogl_editor/src/Editor.c | 67 ++++++++++++++++++++++++++++++++++- ogl_editor/src/Menu.c | 1 + ogl_editor/src/Menu.h | 1 + ogl_editor/src/windows/RocketWindow.c | 1 + 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/ogl_editor/src/Editor.c b/ogl_editor/src/Editor.c index af8b560..9eb2e59 100644 --- a/ogl_editor/src/Editor.c +++ b/ogl_editor/src/Editor.c @@ -1190,6 +1190,66 @@ static void onInterpolation() updateNeedsSaving(); } +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +static void onInvertSelection() +{ + int track, row, rowCount; + TrackViewInfo* viewInfo = getTrackViewInfo(); + struct sync_track** tracks = getTracks(); + const int selectLeft = mini(viewInfo->selectStartTrack, viewInfo->selectStopTrack); + const int selectRight = maxi(viewInfo->selectStartTrack, viewInfo->selectStopTrack); + const int selectTop = mini(viewInfo->selectStartRow, viewInfo->selectStopRow); + const int selectBottom = maxi(viewInfo->selectStartRow, viewInfo->selectStopRow); + + if (selectLeft == selectRight && selectTop == selectBottom) + return; + + rowCount = (selectBottom - selectTop) + 1; + CopyEntry* entries = malloc(rowCount * sizeof(CopyEntry)); + + Commands_beginMulti("invertSelection"); + + for (track = selectLeft; track <= selectRight; ++track) + { + int i = 0; + memset(entries, 0, rowCount * sizeof(CopyEntry)); + + struct sync_track* t = tracks[track]; + + // Take a copy of the data and delete the keys + + for (i = 0, row = selectTop; row <= selectBottom; ++row, ++i) + { + int idx = sync_find_key(t, row); + if (idx < 0) + continue; + + entries[i].track = 1; // just to mark that we should use it + entries[i].keyFrame = t->keys[idx]; + + Commands_deleteKey(track, row); + } + + // Add back the keys but in inverted order + + for (i = 0, row = selectBottom; row >= selectTop; --row, ++i) + { + CopyEntry* entry = &entries[i]; + + if (!entry->track) + continue; + + entry->keyFrame.row = row; + Commands_addOrUpdateKey(track, &entry->keyFrame); + } + } + + free(entries); + + Commands_endMulti(); + updateNeedsSaving(); +} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1246,10 +1306,14 @@ static void onEnterCurrentValue() if (!tracks) return; + Commands_beginMulti("enterCurrentValues"); + enterCurrentValue(tracks[activeTrack], activeTrack, rowPos); - + for (i = selectLeft; i < selectRight; ++i) enterCurrentValue(tracks[i], i, rowPos); + + Commands_endMulti(); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1615,6 +1679,7 @@ void Editor_menuEvent(int menuItem) case EDITOR_MENU_SCALE_001: scaleSelection(0.01f); break; case EDITOR_MENU_INTERPOLATION : onInterpolation(); break; + case EDITOR_MENU_INVERT_SELECTION: onInvertSelection(); break; case EDITOR_MENU_ENTER_CURRENT_V : onEnterCurrentValue(); break; // View diff --git a/ogl_editor/src/Menu.c b/ogl_editor/src/Menu.c index af9db86..c34882c 100644 --- a/ogl_editor/src/Menu.c +++ b/ogl_editor/src/Menu.c @@ -56,6 +56,7 @@ MenuDescriptor g_editMenu[] = { _T("Scale 0.01"), EDITOR_MENU_SCALE_001, 'h', EMGUI_KEY_SHIFT, EMGUI_KEY_SHIFT }, { _T(""), EDITOR_MENU_SEPARATOR, 0, 0, 0 }, { _T("Interpolation"), EDITOR_MENU_INTERPOLATION, 'i', 0, 0 }, + { _T("Invert Selection"), EDITOR_MENU_INVERT_SELECTION, 'i', EMGUI_KEY_COMMAND, EMGUI_KEY_CTRL }, { _T("Insert current value"), EDITOR_MENU_ENTER_CURRENT_V,EMGUI_KEY_ENTER,0, 0 }, { 0 }, }; diff --git a/ogl_editor/src/Menu.h b/ogl_editor/src/Menu.h index 638745c..0edc9fa 100644 --- a/ogl_editor/src/Menu.h +++ b/ogl_editor/src/Menu.h @@ -64,6 +64,7 @@ enum EDITOR_MENU_SCALE_001, EDITOR_MENU_INTERPOLATION, + EDITOR_MENU_INVERT_SELECTION, EDITOR_MENU_ENTER_CURRENT_V, // View diff --git a/ogl_editor/src/windows/RocketWindow.c b/ogl_editor/src/windows/RocketWindow.c index 866c595..f6d2116 100644 --- a/ogl_editor/src/windows/RocketWindow.c +++ b/ogl_editor/src/windows/RocketWindow.c @@ -542,6 +542,7 @@ LRESULT CALLBACK WndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam case EDITOR_MENU_SCALE_05: case EDITOR_MENU_SCALE_01: case EDITOR_MENU_INTERPOLATION: + case EDITOR_MENU_INVERT_SELECTION: case EDITOR_MENU_ENTER_CURRENT_V: case EDITOR_MENU_TAB: case EDITOR_MENU_PLAY: