From 4e6bb67e014b4f4d9316f8c4bafff1d58afe133f Mon Sep 17 00:00:00 2001 From: Crementif <26669564+Crementif@users.noreply.github.com> Date: Mon, 7 Jul 2025 23:05:41 +0200 Subject: [PATCH] UI: fix DoScroll for wxTextCtrl --- src/gui/wxgui/components/TextList.cpp | 44 ++++++++++++++++++--------- src/gui/wxgui/components/TextList.h | 8 +---- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/gui/wxgui/components/TextList.cpp b/src/gui/wxgui/components/TextList.cpp index 800872f2..f5e3f133 100644 --- a/src/gui/wxgui/components/TextList.cpp +++ b/src/gui/wxgui/components/TextList.cpp @@ -1,5 +1,8 @@ #include "wxgui/wxgui.h" #include "TextList.h" + +#include "debugger/DisasmCtrl.h" + #include #include @@ -18,13 +21,14 @@ TextList::~TextList() this->Unbind(wxEVT_ERASE_BACKGROUND, &TextList::OnEraseBackground, this); } -TextList::TextList(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : wxScrolled(parent, id, pos, size, style) +TextList::TextList(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) + : wxControl(parent, id, pos, size, style), wxScrollHelper(this) { m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); this->wxWindowBase::SetBackgroundStyle(wxBG_STYLE_PAINT); wxInfoDC dc(this); - this->wxScrolled::DoPrepareReadOnlyDC(dc); + this->DoPrepareReadOnlyDC(dc); dc.SetFont(m_font); m_line_height = dc.GetCharHeight(); m_char_width = dc.GetCharWidth(); @@ -280,25 +284,37 @@ void TextList::OnPaintEvent(wxPaintEvent& event) { wxAutoBufferedPaintDC dc(m_targetWindow); + // get window position + auto position = GetPosition(); + + // get current real position + wxRect rect_update = GetUpdateRegion().GetBox(); + const auto count = (uint32)std::ceil((float)rect_update.GetHeight() / m_line_height); + + position.y = (rect_update.y / m_line_height) * m_line_height; + + // paint background dc.SetFont(m_font); + const wxColour window_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); dc.SetBrush(GetBackgroundColour()); dc.SetPen(*wxTRANSPARENT_PEN); - dc.DrawRectangle(GetUpdateRegion().GetBox()); + dc.DrawRectangle(rect_update); - // calculate the number of elements visible in the current view - auto rect_update = GetClientRect(); - sint32 start = GetViewStart().y; - m_elements_visible = std::min(rect_update.height + m_line_height - 1, (sint32)m_element_count - start); + //// paint selection + //if (!m_selected_text.eof()) + //{ + // dc.SetBrush(*wxBLUE_BRUSH); + // dc.SetPen(*wxBLUE_PEN); + // dc.DrawRectangle(m_selection); + //} - // add constraints - if (m_elements_visible < 0) - m_elements_visible = 0; - else if (m_elements_visible > m_element_count - start) - m_elements_visible = m_element_count - start; + sint32 start; + CalcUnscrolledPosition(rect_update.x, rect_update.y, nullptr, &start); - m_scrolled_to_end = (start + m_elements_visible >= m_element_count); + start /= m_line_height; + m_scrolled_to_end = (start + count) >= m_element_count; - OnDraw(dc, GetViewStart().y, m_elements_visible, wxPoint(rect_update.x, rect_update.y)); + OnDraw(dc, start, count, position); // removed Update() here since all text is white } \ No newline at end of file diff --git a/src/gui/wxgui/components/TextList.h b/src/gui/wxgui/components/TextList.h index a27a3c4e..9a722a21 100644 --- a/src/gui/wxgui/components/TextList.h +++ b/src/gui/wxgui/components/TextList.h @@ -5,14 +5,8 @@ #include #include -#define COLOR_BLACK 0xFF000000 -#define COLOR_GREY 0xFFA0A0A0 -#define COLOR_LIGHT_GREY 0xFFE0E0E0 -#define COLOR_WHITE 0xFFFFFFFF -#define COLOR_RED 0xFF0000FF - -class TextList : public wxScrolled +class TextList : public wxControl, public wxScrollHelper { public: virtual ~TextList();