From fc2eb38fcd2753cdcf7658864c515a7a1dae4e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ed=C3=AAnis=20Freindorfer=20Azevedo?= Date: Mon, 19 Aug 2019 17:25:47 -0300 Subject: [PATCH] Fix behaviour of `Tools` > `Memory Viewer` (#486) We fix the wxWidgets error message when trying to open the dialog via menu. The scrollbar behaviour has been enhanced to adjust itself between 200 and 300 rows from GUI (0x6c0 memory to 0xf9ff - GB example). Clicking on top or bottom line of the memory values now moves 1 row position backwards and forward, respectively. Arrow keys also functional for navigation. * Remove clicking on top/bottom behaviour. --- src/wx/viewsupt.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/wx/viewsupt.cpp b/src/wx/viewsupt.cpp index 7015c739..7276175d 100644 --- a/src/wx/viewsupt.cpp +++ b/src/wx/viewsupt.cpp @@ -136,7 +136,7 @@ void DisList::MoveSB() pos = (topaddr - 100) / 10 + 100; else if (topaddr >= maxaddr - 1100) pos = (topaddr - maxaddr + 1100) / 10 + 300; - else + else // FIXME this pos is very likely wrong... but I cannot trigger it pos = 250; sb.SetScrollbar(pos, 20, 500, 20); @@ -553,16 +553,16 @@ void MemView::MoveSB() { int pos; - if (topaddr / 16 <= 100) + if (topaddr / 16 <= 100) // <= 100 pos = topaddr / 16; - else if (topaddr / 16 >= maxaddr / 16 - 100) + else if (topaddr / 16 >= maxaddr / 16 - 100) // >= 400 pos = topaddr / 16 - maxaddr / 16 + 500; - else if (topaddr / 16 < 1100) + else if (topaddr / 16 < 1100) // <= 200 pos = (topaddr / 16 - 100) / 10 + 100; - else if (topaddr / 16 >= maxaddr / 16 - 1100) + else if (topaddr / 16 >= maxaddr / 16 - 1100) // >= 300 pos = (topaddr / 16 - maxaddr / 16 + 1100) / 10 + 300; - else - pos = 250; + else // > 200 && < 300 + pos = ((topaddr / 16) - 1100) / (((maxaddr / 16) - 2200) / 100) + 200; sb.SetScrollbar(pos, 20, 500, 20); } @@ -597,6 +597,13 @@ void MemView::MoveView(wxScrollEvent& ev) MoveSB(); } // ignore THUMBTRACK and CHANGED + // do not interrupt scroll because no event was triggered + else if (pos <= 200) + topaddr = ((pos - 100) * 10 + 100) * 16; + else if (pos >= 300) + topaddr = ((pos - 300) * 10 - 1100) * 16 + maxaddr; + else if (pos > 200 && pos < 300) + topaddr = ((pos - 200) * ((maxaddr / 16 - 2200) / 100) + 1100) * 16; RefillNeeded(); } @@ -649,7 +656,7 @@ void MemView::Refill(wxDC& dc) for (size_t i = 0; i < (size_t)nlines && i < words.size() / 4; i++) { wxString line, word; - line.Printf(maxaddr > 0xffff ? wxT("%08X ") : wxT("%04X "), topaddr + i * 16); + line.Printf(maxaddr > 0xffff ? wxT("%08X ") : wxT("%04X "), topaddr + (int)i * 16); for (int j = 0; j < 4; j++) { uint32_t v = words[i * 4 + j];