From c3e41809d9d43e3c251ac6bb6e5bb21fcc1e7442 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Aug 2014 14:59:02 -0400 Subject: [PATCH] DolphinWX: Move the CodeView debugger view over to wxGraphicsContext This is a more advanced drawing 'backend' over the previous one and allows us to control things like transparency and anti-aliasing, etc. --- Source/Core/DolphinWX/Debugger/CodeView.cpp | 105 ++++++++++---------- Source/Core/DolphinWX/Debugger/CodeView.h | 4 +- 2 files changed, 58 insertions(+), 51 deletions(-) diff --git a/Source/Core/DolphinWX/Debugger/CodeView.cpp b/Source/Core/DolphinWX/Debugger/CodeView.cpp index d723d9aa6b..961c74fc17 100644 --- a/Source/Core/DolphinWX/Debugger/CodeView.cpp +++ b/Source/Core/DolphinWX/Debugger/CodeView.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -393,21 +395,21 @@ void CCodeView::OnErase(wxEraseEvent& event) void CCodeView::OnPaint(wxPaintEvent& event) { - // -------------------------------------------------------------------- + // ------------------------- // General settings // ------------------------- - wxPaintDC dc(this); + std::unique_ptr ctx(wxGraphicsContext::Create(wxPaintDC(this))); wxRect rc = GetClientRect(); - dc.SetFont(DebuggerFont); + ctx->SetFont(DebuggerFont, *wxBLACK); - wxCoord w,h; - dc.GetTextExtent("0WJyq", &w, &h); + wxDouble w,h; + ctx->GetTextExtent("0WJyq", &w, &h); if (h > m_rowHeight) m_rowHeight = h; - dc.GetTextExtent("W", &w, &h); + ctx->GetTextExtent("W", &w, &h); int charWidth = w; struct branch @@ -422,10 +424,10 @@ void CCodeView::OnPaint(wxPaintEvent& event) int numRows = (rc.height / m_rowHeight) / 2 + 2; // ------------ - // -------------------------------------------------------------------- + // ------------------------- // Colors and brushes // ------------------------- - dc.SetBackgroundMode(wxTRANSPARENT); // the text background + const wxColour bgColor = *wxWHITE; wxPen nullPen(bgColor); wxPen currentPen(*wxBLACK_PEN); @@ -440,15 +442,15 @@ void CCodeView::OnPaint(wxPaintEvent& event) wxBrush nullBrush(bgColor); nullBrush.SetStyle(wxTRANSPARENT); - dc.SetPen(nullPen); - dc.SetBrush(bgBrush); - dc.DrawRectangle(0, 0, 16, rc.height); - dc.DrawRectangle(0, 0, rc.width, 5); + ctx->SetPen(nullPen); + ctx->SetBrush(bgBrush); + ctx->DrawRectangle(0, 0, 16, rc.height); + ctx->DrawRectangle(0, 0, rc.width, 5); // ------------ - // -------------------------------------------------------------------- + // ----------------------------- // Walk through all visible rows - // ------------------------- + // ----------------------------- for (int i = -numRows; i <= numRows; i++) { unsigned int address = m_curAddress + i * m_align; @@ -459,27 +461,28 @@ void CCodeView::OnPaint(wxPaintEvent& event) wxString temp = wxString::Format("%08x", address); u32 col = m_debugger->GetColor(address); wxBrush rowBrush(wxColour(col >> 16, col >> 8, col)); - dc.SetBrush(nullBrush); - dc.SetPen(nullPen); - dc.DrawRectangle(0, rowY1, 16, rowY2 - rowY1 + 2); + ctx->SetBrush(nullBrush); + ctx->SetPen(nullPen); + ctx->DrawRectangle(0, rowY1, 16, rowY2 - rowY1 + 2); if (m_selecting && (address == m_selection)) - dc.SetPen(selPen); + ctx->SetPen(selPen); else - dc.SetPen(i == 0 ? currentPen : nullPen); + ctx->SetPen(i == 0 ? currentPen : nullPen); if (address == m_debugger->GetPC()) - dc.SetBrush(pcBrush); + ctx->SetBrush(pcBrush); else - dc.SetBrush(rowBrush); + ctx->SetBrush(rowBrush); - dc.DrawRectangle(16, rowY1, width, rowY2 - rowY1 + 1); - dc.SetBrush(currentBrush); + ctx->DrawRectangle(16, rowY1, width, rowY2 - rowY1 + 1); + ctx->SetBrush(currentBrush); if (!m_plain) { - dc.SetTextForeground("#600000"); // the address text is dark red - dc.DrawText(temp, 17, rowY1); - dc.SetTextForeground(*wxBLACK); + // the address text is dark red + ctx->SetFont(DebuggerFont, wxColour("#600000")); + ctx->DrawText(temp, 17, rowY1); + ctx->SetFont(DebuggerFont, *wxBLACK); } // If running @@ -510,23 +513,23 @@ void CCodeView::OnPaint(wxPaintEvent& event) branches[numBranches].srcAddr = address / m_align; branches[numBranches++].dst = (int)(rowY1 + ((s64)(u32)offs - (s64)(u32)address) * m_rowHeight / m_align + m_rowHeight / 2); desc = StringFromFormat("-->%s", m_debugger->GetDescription(offs).c_str()); - dc.SetTextForeground(wxTheColourDatabase->Find("PURPLE")); // the -> arrow illustrations are purple + ctx->SetFont(DebuggerFont, wxTheColourDatabase->Find("PURPLE")); // the -> arrow illustrations are purple } else { - dc.SetTextForeground(*wxBLACK); + ctx->SetFont(DebuggerFont, *wxBLACK); } - dc.DrawText(StrToWxStr(operands), 17 + 17*charWidth, rowY1); + ctx->DrawText(StrToWxStr(operands), 17 + 17*charWidth, rowY1); // ------------ // Show blr as its' own color if (opcode == "blr") - dc.SetTextForeground(wxTheColourDatabase->Find("DARK GREEN")); + ctx->SetFont(DebuggerFont, wxTheColourDatabase->Find("DARK GREEN")); else - dc.SetTextForeground(wxTheColourDatabase->Find("VIOLET")); + ctx->SetFont(DebuggerFont, wxTheColourDatabase->Find("VIOLET")); - dc.DrawText(StrToWxStr(opcode), 17 + (m_plain ? 1*charWidth : 9*charWidth), rowY1); + ctx->DrawText(StrToWxStr(opcode), 17 + (m_plain ? 1*charWidth : 9*charWidth), rowY1); if (desc.empty()) { @@ -535,30 +538,30 @@ void CCodeView::OnPaint(wxPaintEvent& event) if (!m_plain) { - dc.SetTextForeground(*wxBLUE); + ctx->SetFont(DebuggerFont, *wxBLUE); //char temp[256]; //UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE); if (!desc.empty()) { - dc.DrawText(StrToWxStr(desc), 17 + 35 * charWidth, rowY1); + ctx->DrawText(StrToWxStr(desc), 17 + 35 * charWidth, rowY1); } } // Show red breakpoint dot if (m_debugger->IsBreakpoint(address)) { - dc.SetBrush(bpBrush); - dc.DrawRectangle(2, rowY1 + 1, 11, 11); + ctx->SetBrush(bpBrush); + ctx->DrawRectangle(2, rowY1 + 1, 11, 11); } } } // end of for // ------------ - // -------------------------------------------------------------------- + // ------------------------- // Colors and brushes // ------------------------- - dc.SetPen(currentPen); + ctx->SetPen(currentPen); for (int i = 0; i < numBranches; i++) { @@ -567,34 +570,36 @@ void CCodeView::OnPaint(wxPaintEvent& event) if (branches[i].dst < rc.height + 400 && branches[i].dst > -400) { - LineTo(dc, x+2, branches[i].src); - LineTo(dc, x+2, branches[i].dst); - LineTo(dc, x-4, branches[i].dst); + LineTo(ctx, x+2, branches[i].src); + LineTo(ctx, x+2, branches[i].dst); + LineTo(ctx, x-4, branches[i].dst); MoveTo(x, branches[i].dst - 4); - LineTo(dc, x-4, branches[i].dst); - LineTo(dc, x+1, branches[i].dst+5); + LineTo(ctx, x-4, branches[i].dst); + LineTo(ctx, x+1, branches[i].dst+5); } //else //{ // This can be re-enabled when there is a scrollbar or // something on the codeview (the lines are too long) - //LineTo(dc, x+4, branches[i].src); + //LineTo(ctx, x+4, branches[i].src); //MoveTo(x+2, branches[i].dst-4); - //LineTo(dc, x+6, branches[i].dst); - //LineTo(dc, x+1, branches[i].dst+5); + //LineTo(ctx, x+6, branches[i].dst); + //LineTo(ctx, x+1, branches[i].dst+5); //} - //LineTo(dc, x, branches[i].dst+4); - //LineTo(dc, x-2, branches[i].dst); + //LineTo(ctx, x, branches[i].dst+4); + //LineTo(ctx, x-2, branches[i].dst); } // ------------ } -void CCodeView::LineTo(wxPaintDC &dc, int x, int y) +void CCodeView::LineTo(std::unique_ptr& ctx, int x, int y) { - dc.DrawLine(m_lx, m_ly, x, y); + std::vector points { wxPoint2DDouble(m_lx, m_ly), wxPoint2DDouble(x, y) }; + + ctx->DrawLines(points.size(), points.data()); m_lx = x; m_ly = y; } diff --git a/Source/Core/DolphinWX/Debugger/CodeView.h b/Source/Core/DolphinWX/Debugger/CodeView.h index b6e643fae6..82b4925527 100644 --- a/Source/Core/DolphinWX/Debugger/CodeView.h +++ b/Source/Core/DolphinWX/Debugger/CodeView.h @@ -7,11 +7,13 @@ #define wxUSE_XPM_IN_MSW 1 #define USE_XPM_BITMAPS 1 +#include #include #include #include #include +#include #include #include "Common/Common.h" @@ -70,7 +72,7 @@ private: m_ly = y; } - void LineTo(wxPaintDC &dc, int x, int y); + void LineTo(std::unique_ptr& dc, int x, int y); struct BlrStruct // for IDM_INSERTBLR {