diff --git a/src/drivers/win/taseditor/history.cpp b/src/drivers/win/taseditor/history.cpp index 1379a418..9c3a4b6f 100644 --- a/src/drivers/win/taseditor/history.cpp +++ b/src/drivers/win/taseditor/history.cpp @@ -39,9 +39,11 @@ extern TASEDITOR_LUA taseditor_lua; extern int joysticks_per_frame[NUM_SUPPORTED_INPUT_TYPES]; extern int GetInputType(MovieData& md); +extern Window_items_struct window_items[]; + char history_save_id[HISTORY_ID_LEN] = "HISTORY"; char history_skipsave_id[HISTORY_ID_LEN] = "HISTORX"; -char modCaptions[MODTYPES_TOTAL][20] = {" Init", +char modCaptions[MODTYPES_TOTAL][20] = {" Init Project", " Undefined", " Set", " Unset", @@ -124,7 +126,7 @@ void HISTORY::reset() // create initial snapshot SNAPSHOT inp; inp.init(currMovieData, taseditor_config.enable_hot_changes); - strcat(inp.description, modCaptions[0]); + strcat(inp.description, modCaptions[MODTYPE_INIT]); inp.jump_frame = -1; AddSnapshotToHistory(inp); UpdateHistoryList(); @@ -149,6 +151,38 @@ void HISTORY::update() piano_roll.RedrawRow(undo_hint_pos); // not changing Bookmarks List } +void HISTORY::HistorySizeChanged() +{ + int new_history_size = taseditor_config.undo_levels + 1; + std::vector new_snapshots(new_history_size); + int pos = history_cursor_pos, source_pos = history_cursor_pos; + if (pos >= new_history_size) + pos = new_history_size - 1; + int new_history_cursor_pos = pos; + // copy old "undo" snapshots + while (pos >= 0) + { + new_snapshots[pos] = snapshots[(history_start_pos + source_pos) % history_size]; + pos--; + source_pos--; + } + // copy old "redo" snapshots + int num_redo_snapshots = history_total_items - (history_cursor_pos + 1); + int space_available = new_history_size - (new_history_cursor_pos + 1); + int i = (num_redo_snapshots <= space_available) ? num_redo_snapshots : space_available; + int new_history_total_items = new_history_cursor_pos + i + 1; + for (; i > 0; i--) + new_snapshots[new_history_cursor_pos + i] = snapshots[(history_start_pos + history_cursor_pos + i) % history_size]; + // finish + snapshots = new_snapshots; + history_size = new_history_size; + history_start_pos = 0; + history_cursor_pos = new_history_cursor_pos; + history_total_items = new_history_total_items; + UpdateHistoryList(); + RedrawHistoryList(); +} + // returns frame of first input change (for greenzone invalidation) int HISTORY::jump(int new_pos) { @@ -232,7 +266,7 @@ void HISTORY::redo() void HISTORY::AddSnapshotToHistory(SNAPSHOT &inp) { // history uses conveyor of snapshots (vector with fixed size) to aviod resizing which is awfully expensive with such large objects as SNAPSHOT - if (history_cursor_pos+1 >= history_size) + if (history_total_items >= history_size) { // reached the end of available history_size - move history_start_pos (thus deleting oldest snapshot) history_cursor_pos = history_size-1; @@ -583,12 +617,12 @@ int HISTORY::RegisterLuaChanges(const char* name, int start, bool InsertionDelet // fill description: if (name[0]) { - // custom name of operation + // user provided custom name of operation strcat(inp.description, LuaCaptionPrefix); strncat(inp.description, name, LUACHANGES_NAME_MAX_LEN); } else { - // default name + // set default name strcat(inp.description, modCaptions[inp.mod_type]); } inp.jump_frame = first_changes; @@ -799,6 +833,17 @@ int HISTORY::GetUndoHint() else return -1; } +bool HISTORY::CursorOverHistoryList() +{ + POINT p; + if (GetCursorPos(&p)) + { + ScreenToClient(hwndHistoryList, &p); + if (p.x >= 0 && p.y >= 0 && p.x < window_items[HISTORYLIST_IN_WINDOWITEMS].width && p.y < (taseditor_config.wndheight + window_items[HISTORYLIST_IN_WINDOWITEMS].height - window_items[HISTORYLIST_IN_WINDOWITEMS].y)) + return true; + } + return false; +} // --------------------------------------------------------------------------------- LRESULT APIENTRY HistoryListWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -838,10 +883,17 @@ LRESULT APIENTRY HistoryListWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l return 0; case WM_MOUSEWHEEL: { - // Right button/Ctrl/Shift/Alt + wheel -> send the message to Piano Roll - // but if just wheel - use default scrolling here - if (GET_KEYSTATE_WPARAM(wParam) & (MK_RBUTTON|MK_SHIFT|MK_CONTROL) || (GetKeyState(VK_MENU) < 0)) + if (!history.CursorOverHistoryList()) return SendMessage(piano_roll.hwndList, msg, wParam, lParam); + break; + } + case WM_MOUSEWHEEL_RESENT: + { + // this is message from Piano Roll + // it means that cursor is currently over History List, and user scrolls the wheel (although focus may be on some other window) + // ensure that wParam's low-order word is 0 (so fwKeys = 0) + CallWindowProc(hwndHistoryList_oldWndProc, hWnd, WM_MOUSEWHEEL, wParam & ~(LOWORD(-1)), lParam); + return 0; } case WM_MOUSEACTIVATE: if (GetFocus() != hWnd) diff --git a/src/drivers/win/taseditor/history.h b/src/drivers/win/taseditor/history.h index 7e019fb0..7c13d595 100644 --- a/src/drivers/win/taseditor/history.h +++ b/src/drivers/win/taseditor/history.h @@ -54,6 +54,9 @@ enum }; #define HISTORY_NORMAL_COLOR 0x000000 +#define HISTORYLIST_IN_WINDOWITEMS 18 +#define WM_MOUSEWHEEL_RESENT WM_APP+123 + #define HISTORY_ID_LEN 8 class HISTORY @@ -65,6 +68,8 @@ public: void reset(); void update(); // called every frame + void HistorySizeChanged(); + void save(EMUFILE *os, bool really_save = true); bool load(EMUFILE *is); @@ -94,6 +99,8 @@ public: void RedrawHistoryList(); void UpdateHistoryList(); + bool CursorOverHistoryList(); + HWND hwndHistoryList; private: diff --git a/src/drivers/win/taseditor/piano_roll.cpp b/src/drivers/win/taseditor/piano_roll.cpp index 27c520ad..bf4ffb01 100644 --- a/src/drivers/win/taseditor/piano_roll.cpp +++ b/src/drivers/win/taseditor/piano_roll.cpp @@ -1187,6 +1187,9 @@ LRESULT APIENTRY ListWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) bookmarks.RedrawChangedBookmarks(lastCursor); } return 0; + } else if (history.CursorOverHistoryList()) + { + return SendMessage(history.hwndHistoryList, WM_MOUSEWHEEL_RESENT, wParam, lParam); } break; } diff --git a/src/drivers/win/taseditor/piano_roll.h b/src/drivers/win/taseditor/piano_roll.h index 6e5916a7..fcda2150 100644 --- a/src/drivers/win/taseditor/piano_roll.h +++ b/src/drivers/win/taseditor/piano_roll.h @@ -12,12 +12,12 @@ #define HEADER_LIGHT_MAX 10 #define HEADER_LIGHT_HOLD 5 -#define HEADER_LIGHT_MOUSEOVER 2 +#define HEADER_LIGHT_MOUSEOVER 1 #define HEADER_LIGHT_MOUSEOVER_SEL 3 #define HEADER_LIGHT_UPDATE_TICK 40 // 25FPS #define HEADER_DX_FIX 4 -#define BOOST_WHEN_BOTH_RIGHTBUTTON_AND_ALT_PRESSED 2 +#define BOOST_WHEN_BOTH_RIGHTBUTTON_AND_ALT_PRESSED 4 enum { diff --git a/src/drivers/win/taseditor/selection.cpp b/src/drivers/win/taseditor/selection.cpp index 48b87066..4ab1b983 100644 --- a/src/drivers/win/taseditor/selection.cpp +++ b/src/drivers/win/taseditor/selection.cpp @@ -148,6 +148,36 @@ void SELECTION::update() } +void SELECTION::HistorySizeChanged() +{ + int new_history_size = taseditor_config.undo_levels + 1; + std::vector new_selections_history(new_history_size); + int pos = history_cursor_pos, source_pos = history_cursor_pos; + if (pos >= new_history_size) + pos = new_history_size - 1; + int new_history_cursor_pos = pos; + // copy old "undo" snapshots + while (pos >= 0) + { + new_selections_history[pos] = selections_history[(history_start_pos + source_pos) % history_size]; + pos--; + source_pos--; + } + // copy old "redo" snapshots + int num_redo_snapshots = history_total_items - (history_cursor_pos + 1); + int space_available = new_history_size - (new_history_cursor_pos + 1); + int i = (num_redo_snapshots <= space_available) ? num_redo_snapshots : space_available; + int new_history_total_items = new_history_cursor_pos + i + 1; + for (; i > 0; i--) + new_selections_history[new_history_cursor_pos + i] = selections_history[(history_start_pos + history_cursor_pos + i) % history_size]; + // finish + selections_history = new_selections_history; + history_size = new_history_size; + history_start_pos = 0; + history_cursor_pos = new_history_cursor_pos; + history_total_items = new_history_total_items; +} + void SELECTION::RedrawMarker() { // redraw marker num diff --git a/src/drivers/win/taseditor/selection.h b/src/drivers/win/taseditor/selection.h index 58591d54..1479ee9c 100644 --- a/src/drivers/win/taseditor/selection.h +++ b/src/drivers/win/taseditor/selection.h @@ -15,6 +15,8 @@ public: void reset_vars(); void update(); + void HistorySizeChanged(); + void RedrawMarker(); void save(EMUFILE *os, bool really_save = true); diff --git a/src/drivers/win/taseditor/taseditor_window.cpp b/src/drivers/win/taseditor/taseditor_window.cpp index c5f87a07..4b011ec0 100644 --- a/src/drivers/win/taseditor/taseditor_window.cpp +++ b/src/drivers/win/taseditor/taseditor_window.cpp @@ -68,19 +68,7 @@ char patterns_menu_prefix[] = "Pattern: "; char taseditor_help_filename[] = "\\taseditor.chm"; // all items of the window (used for resising) and their default x,y,w,h // actual x,y,w,h are calculated at the beginning from screen -static struct -{ - int id; - int x; - int y; - int width; - int height; - char tooltip_text_base[TOOLTIP_TEXT_MAX_LEN]; - char tooltip_text[TOOLTIP_TEXT_MAX_LEN]; - bool static_rect; - int hotkey_emucmd; - HWND tooltip_hwnd; -} window_items[TASEDITOR_WINDOW_TOTAL_ITEMS] = { +Window_items_struct window_items[TASEDITOR_WINDOW_TOTAL_ITEMS] = { IDC_PROGRESS_BUTTON, -1, 0, 0, 0, "Click here whenever you want to abort seeking", "", false, 0, 0, IDC_BRANCHES_BUTTON, -1, 0, 0, 0, "Click here to switch between Bookmarks List and Branches Tree", "", false, 0, 0, IDC_LIST1, 0, 0, -1, -1, "", "", false, 0, 0, @@ -999,10 +987,8 @@ BOOL CALLBACK WndprocTasEditor(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara if (new_size != taseditor_config.undo_levels) { taseditor_config.undo_levels = new_size; - history.reset(); - selection.reset(); - // hot changes were cleared, so update Piano Roll - piano_roll.RedrawList(); + history.HistorySizeChanged(); + selection.HistorySizeChanged(); } } break; diff --git a/src/drivers/win/taseditor/taseditor_window.h b/src/drivers/win/taseditor/taseditor_window.h index 934e34b5..1c650221 100644 --- a/src/drivers/win/taseditor/taseditor_window.h +++ b/src/drivers/win/taseditor/taseditor_window.h @@ -8,6 +8,20 @@ #define PATTERNS_MAX_VISIBLE_NAME 50 #define PATTERNMENU_MAX_VISIBLE_NAME PATTERNS_MAX_VISIBLE_NAME + 6 // + "Pattern: " +struct Window_items_struct +{ + int id; + int x; + int y; + int width; + int height; + char tooltip_text_base[TOOLTIP_TEXT_MAX_LEN]; + char tooltip_text[TOOLTIP_TEXT_MAX_LEN]; + bool static_rect; + int hotkey_emucmd; + HWND tooltip_hwnd; +}; + enum ECONTEXTMENU { CONTEXTMENU_STRAY = 0, diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 66a23b3f..3517fb73 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -348,6 +348,8 @@ void updateGameDependentMenus(unsigned int enable) { const int menu_ids[]= { MENU_CLOSE_FILE, + ID_FILE_SCREENSHOT, + ID_FILE_SAVESCREENSHOTAS, MENU_RESET, MENU_POWER, MENU_INSERT_COIN,