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.
This commit is contained in:
Lioncash 2014-08-24 14:59:02 -04:00
parent b749a74d33
commit c3e41809d9
2 changed files with 58 additions and 51 deletions

View File

@ -6,6 +6,7 @@
#include <cmath>
#include <cstdio>
#include <cstring>
#include <memory>
#include <string>
#include <vector>
#include <wx/brush.h>
@ -18,6 +19,7 @@
#include <wx/defs.h>
#include <wx/event.h>
#include <wx/gdicmn.h>
#include <wx/graphics.h>
#include <wx/menu.h>
#include <wx/menuitem.h>
#include <wx/pen.h>
@ -393,21 +395,21 @@ void CCodeView::OnErase(wxEraseEvent& event)
void CCodeView::OnPaint(wxPaintEvent& event)
{
// --------------------------------------------------------------------
// -------------------------
// General settings
// -------------------------
wxPaintDC dc(this);
std::unique_ptr<wxGraphicsContext> 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<wxGraphicsContext>& ctx, int x, int y)
{
dc.DrawLine(m_lx, m_ly, x, y);
std::vector<wxPoint2DDouble> points { wxPoint2DDouble(m_lx, m_ly), wxPoint2DDouble(x, y) };
ctx->DrawLines(points.size(), points.data());
m_lx = x;
m_ly = y;
}

View File

@ -7,11 +7,13 @@
#define wxUSE_XPM_IN_MSW 1
#define USE_XPM_BITMAPS 1
#include <memory>
#include <vector>
#include <wx/control.h>
#include <wx/defs.h>
#include <wx/event.h>
#include <wx/graphics.h>
#include <wx/windowid.h>
#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<wxGraphicsContext>& dc, int x, int y);
struct BlrStruct // for IDM_INSERTBLR
{