diff --git a/Windows/Debugger/CtrlDisAsmView.cpp b/Windows/Debugger/CtrlDisAsmView.cpp index 15493687c6..d36ebca896 100644 --- a/Windows/Debugger/CtrlDisAsmView.cpp +++ b/Windows/Debugger/CtrlDisAsmView.cpp @@ -31,6 +31,9 @@ TCHAR CtrlDisAsmView::szClassName[] = _T("CtrlDisAsmView"); +static constexpr UINT_PTR IDT_REDRAW = 0xC0DE0001; +static constexpr UINT REDRAW_DELAY = 1000 / 60; + void CtrlDisAsmView::init() { WNDCLASSEX wc; @@ -138,6 +141,16 @@ LRESULT CALLBACK CtrlDisAsmView::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPA } } return DLGC_WANTCHARS|DLGC_WANTARROWS; + + case WM_TIMER: + if (wParam == IDT_REDRAW) { + InvalidateRect(hwnd, nullptr, FALSE); + UpdateWindow(hwnd); + ccp->redrawScheduled_ = false; + KillTimer(hwnd, wParam); + } + break; + default: break; } @@ -835,8 +848,10 @@ void CtrlDisAsmView::redraw() GetClientRect(wnd, &rect); visibleRows = rect.bottom/rowHeight; - InvalidateRect(wnd, NULL, FALSE); - UpdateWindow(wnd); + if (!redrawScheduled_) { + SetTimer(wnd, IDT_REDRAW, REDRAW_DELAY, nullptr); + redrawScheduled_ = true; + } } void CtrlDisAsmView::toggleBreakpoint(bool toggleEnabled) @@ -1071,7 +1086,6 @@ void CtrlDisAsmView::onMouseMove(WPARAM wParam, LPARAM lParam, int button) { int y = HIWORD(lParam); setCurAddress(yToAddress(y), KeyDownAsync(VK_SHIFT)); - // TODO: Perhaps don't do this every time, but on a timer? redraw(); } } diff --git a/Windows/Debugger/CtrlDisAsmView.h b/Windows/Debugger/CtrlDisAsmView.h index 7b06b3a517..1ca3c3143e 100644 --- a/Windows/Debugger/CtrlDisAsmView.h +++ b/Windows/Debugger/CtrlDisAsmView.h @@ -173,4 +173,7 @@ public: selectRangeEnd = extend ? std::max(selectRangeEnd, after) : after; updateStatusBarText(); } -}; \ No newline at end of file + +private: + bool redrawScheduled_ = false; +}; diff --git a/Windows/Debugger/CtrlMemView.cpp b/Windows/Debugger/CtrlMemView.cpp index eeb7ad2d3e..83f160d56f 100644 --- a/Windows/Debugger/CtrlMemView.cpp +++ b/Windows/Debugger/CtrlMemView.cpp @@ -20,6 +20,12 @@ wchar_t CtrlMemView::szClassName[] = L"CtrlMemView"; +static constexpr UINT_PTR IDT_REDRAW_DELAYED = 0xC0DE0001; +static constexpr UINT REDRAW_DELAY = 1000 / 60; +// We also redraw regularly, since data changes during runtime. +static constexpr UINT_PTR IDT_REDRAW_AUTO = 0xC0DE0002; +static constexpr UINT REDRAW_INTERVAL = 1000; + CtrlMemView::CtrlMemView(HWND _wnd) { wnd=_wnd; @@ -56,7 +62,7 @@ CtrlMemView::CtrlMemView(HWND _wnd) asciiStart = hexStart + (rowSize*3+1)*charWidth; // set redraw timer - SetTimer(wnd,1,1000,0); + SetTimer(wnd, IDT_REDRAW_AUTO, REDRAW_INTERVAL, nullptr); } CtrlMemView::~CtrlMemView() @@ -157,8 +163,16 @@ LRESULT CALLBACK CtrlMemView::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM return DLGC_WANTARROWS|DLGC_WANTCHARS|DLGC_WANTTAB; break; case WM_TIMER: - if (wParam == 1 && IsWindowVisible(ccp->wnd)) + // This is actually delayed too, using another timer. That way we won't update twice. + if (wParam == IDT_REDRAW_AUTO && IsWindowVisible(ccp->wnd)) ccp->redraw(); + + if (wParam == IDT_REDRAW_DELAYED) { + InvalidateRect(hwnd, nullptr, FALSE); + UpdateWindow(hwnd); + ccp->redrawScheduled_ = false; + KillTimer(hwnd, wParam); + } break; default: break; @@ -459,8 +473,10 @@ void CtrlMemView::redraw() visibleRows -= offsetSpace; // visibleRows is calculated based on the size of the control, but X rows have already been used for the offsets and are no longer usable } - InvalidateRect(wnd, NULL, FALSE); - UpdateWindow(wnd); + if (!redrawScheduled_) { + SetTimer(wnd, IDT_REDRAW_DELAYED, REDRAW_DELAY, nullptr); + redrawScheduled_ = true; + } } void CtrlMemView::onMouseDown(WPARAM wParam, LPARAM lParam, int button) diff --git a/Windows/Debugger/CtrlMemView.h b/Windows/Debugger/CtrlMemView.h index 563f589be2..45bbcb3275 100644 --- a/Windows/Debugger/CtrlMemView.h +++ b/Windows/Debugger/CtrlMemView.h @@ -106,4 +106,7 @@ public: void toggleOffsetScale(CommonToggles toggle); void toggleStringSearch(CommonToggles toggle); void setHighlightType(MemBlockFlags flags); + +private: + bool redrawScheduled_ = false; }; diff --git a/Windows/Debugger/CtrlRegisterList.cpp b/Windows/Debugger/CtrlRegisterList.cpp index 3de9f87221..aac5864f6c 100644 --- a/Windows/Debugger/CtrlRegisterList.cpp +++ b/Windows/Debugger/CtrlRegisterList.cpp @@ -24,6 +24,9 @@ enum { REGISTER_PC = 32, REGISTER_HI, REGISTER_LO, REGISTERS_END }; TCHAR CtrlRegisterList::szClassName[] = _T("CtrlRegisterList"); +static constexpr UINT_PTR IDT_REDRAW = 0xC0DE0001; +static constexpr UINT REDRAW_DELAY = 1000 / 60; + void CtrlRegisterList::init() { WNDCLASSEX wc; @@ -103,6 +106,16 @@ LRESULT CALLBACK CtrlRegisterList::wndProc(HWND hwnd, UINT msg, WPARAM wParam, L break; case WM_GETDLGCODE: // want chars so that we can return 0 on key press and supress the beeping sound return DLGC_WANTARROWS|DLGC_WANTCHARS; + + case WM_TIMER: + if (wParam == IDT_REDRAW) { + InvalidateRect(hwnd, nullptr, FALSE); + UpdateWindow(hwnd); + ccp->redrawScheduled_ = false; + KillTimer(hwnd, wParam); + } + break; + default: break; } @@ -342,10 +355,11 @@ void CtrlRegisterList::onKeyDown(WPARAM wParam, LPARAM lParam) } -void CtrlRegisterList::redraw() -{ - InvalidateRect(wnd, NULL, FALSE); - UpdateWindow(wnd); +void CtrlRegisterList::redraw() { + if (!redrawScheduled_) { + SetTimer(wnd, IDT_REDRAW, REDRAW_DELAY, nullptr); + redrawScheduled_ = true; + } } u32 CtrlRegisterList::getSelectedRegValue(char *out, size_t size) diff --git a/Windows/Debugger/CtrlRegisterList.h b/Windows/Debugger/CtrlRegisterList.h index 398e6803d0..46d9a13f68 100644 --- a/Windows/Debugger/CtrlRegisterList.h +++ b/Windows/Debugger/CtrlRegisterList.h @@ -76,4 +76,7 @@ public: { return cpu; } + +private: + bool redrawScheduled_ = false; }; diff --git a/Windows/Debugger/Debugger_Disasm.cpp b/Windows/Debugger/Debugger_Disasm.cpp index 63857ae6d2..9a31bd173b 100644 --- a/Windows/Debugger/Debugger_Disasm.cpp +++ b/Windows/Debugger/Debugger_Disasm.cpp @@ -909,6 +909,6 @@ void CDisasm::UpdateDialog(bool _bComplete) // repaint windows at the bottom. only the memory view needs to be forced to // redraw. all others are updated manually - InvalidateRect (GetDlgItem(m_hDlg, IDC_DEBUGMEMVIEW), NULL, TRUE); - UpdateWindow (GetDlgItem(m_hDlg, IDC_DEBUGMEMVIEW)); + CtrlMemView *memview = CtrlMemView::getFrom(GetDlgItem(m_hDlg, IDC_DEBUGMEMVIEW)); + memview->redraw(); }