Exemple #1
0
void CMemoryView::OnPaint(wxPaintEvent& event)
{
	wxPaintDC dc(this);
	wxRect rc = GetClientRect();
	wxFont hFont("Courier");
	hFont.SetFamily(wxFONTFAMILY_TELETYPE);

	wxCoord w,h;
	dc.GetTextExtent("0WJyq", &w, &h, nullptr, nullptr, &hFont);
	if (h > rowHeight)
		rowHeight = h;
	dc.GetTextExtent("0WJyq", &w, &h, nullptr, nullptr, &DebuggerFont);
	if (h > rowHeight)
		rowHeight = h;

	if (viewAsType==VIEWAS_HEX)
		dc.SetFont(hFont);
	else
		dc.SetFont(DebuggerFont);

	dc.GetTextExtent("W", &w, &h);
	int fontSize = w;
	int textPlacement = 17 + 9 * fontSize;

	// TODO: Add any drawing code here...
	int width   = rc.width;
	int numRows = (rc.height / rowHeight) / 2 + 2;
	dc.SetBackgroundMode(wxTRANSPARENT);
	const wxColour bgColor = *wxWHITE;
	wxPen nullPen(bgColor);
	wxPen currentPen(*wxBLACK_PEN);
	wxPen selPen(*wxGREY_PEN);
	nullPen.SetStyle(wxTRANSPARENT);

	wxBrush currentBrush(*wxLIGHT_GREY_BRUSH);
	wxBrush pcBrush(*wxGREEN_BRUSH);
	wxBrush mcBrush(*wxBLUE_BRUSH);
	wxBrush bgBrush(bgColor);
	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+8);

	// TODO - clean up this freaking mess!!!!!
	for (int row = -numRows; row <= numRows; row++)
	{
		unsigned int address = curAddress + row * align;

		int rowY1 = rc.height / 2 + rowHeight * row - rowHeight / 2;
		int rowY2 = rc.height / 2 + rowHeight * row + rowHeight / 2;

		wxString temp = wxString::Format("%08x", address);
		u32 col = debugger->GetColor(address);
		wxBrush rowBrush(wxColour(col >> 16, col >> 8, col));
		dc.SetBrush(nullBrush);
		dc.SetPen(nullPen);
		dc.DrawRectangle(0, rowY1, 16, rowY2);

		if (selecting && (address == selection))
			dc.SetPen(selPen);
		else
			dc.SetPen(row == 0 ? currentPen : nullPen);

		if (address == debugger->GetPC())
			dc.SetBrush(pcBrush);
		else
			dc.SetBrush(rowBrush);

		dc.DrawRectangle(16, rowY1, width, rowY2 - 1);
		dc.SetBrush(currentBrush);
		dc.SetTextForeground("#600000"); // Dark red
		dc.DrawText(temp, 17, rowY1);

		if (viewAsType != VIEWAS_HEX)
		{
			char mem[256];
			debugger->GetRawMemoryString(memory, address, mem, 256);
			dc.SetTextForeground(wxTheColourDatabase->Find("NAVY"));
			dc.DrawText(StrToWxStr(mem), 17+fontSize*(8), rowY1);
			dc.SetTextForeground(*wxBLACK);
		}

		if (!PowerPC::HostIsRAMAddress(address))
			continue;

		if (debugger->IsAlive())
		{
			std::string dis;
			u32 mem_data = debugger->ReadExtraMemory(memory, address);

			if (viewAsType == VIEWAS_FP)
			{
				float flt = *(float *)(&mem_data);
				dis = StringFromFormat("f: %f", flt);
			}
			else if (viewAsType == VIEWAS_ASCII)
			{
				u32 a[4] = {
					(mem_data & 0xff000000) >> 24,
					(mem_data & 0xff0000) >> 16,
					(mem_data & 0xff00) >> 8,
					(mem_data & 0xff)
				};

				for (auto& word : a)
				{
					if (word == '\0')
						word = ' ';
				}

				dis = StringFromFormat("%c%c%c%c", a[0], a[1], a[2], a[3]);
			}
			else if (viewAsType == VIEWAS_HEX)
Exemple #2
0
void CMemoryView::OnPaint(wxPaintEvent& event)
{
	wxPaintDC dc(this);
	wxRect rc = GetClientRect();
	wxFont hFont(_T("Courier"));
	hFont.SetFamily(wxFONTFAMILY_TELETYPE);

	wxCoord w,h;
	dc.GetTextExtent(_T("0WJyq"),&w,&h,nullptr,nullptr,&hFont);
	if (h > rowHeight)
		rowHeight = h;
	dc.GetTextExtent(_T("0WJyq"),&w,&h,nullptr,nullptr,&DebuggerFont);
	if (h > rowHeight)
		rowHeight = h;

	if (viewAsType==VIEWAS_HEX)
		dc.SetFont(hFont);
	else
		dc.SetFont(DebuggerFont);

	dc.GetTextExtent(_T("W"),&w,&h);
	int fontSize = w;
	int textPlacement = 17 + 9 * fontSize;

	// TODO: Add any drawing code here...
	int width   = rc.width;
	int numRows = (rc.height / rowHeight) / 2 + 2;
	dc.SetBackgroundMode(wxTRANSPARENT);
	const wxChar* bgColor = _T("#ffffff");
	wxPen nullPen(bgColor);
	wxPen currentPen(_T("#000000"));
	wxPen selPen(_T("#808080")); // gray
	nullPen.SetStyle(wxTRANSPARENT);

	wxBrush currentBrush(_T("#FFEfE8")); // light gray
	wxBrush pcBrush(_T("#70FF70")); // green
	wxBrush mcBrush(_T("#1133FF")); // blue
	wxBrush bgBrush(bgColor);
	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+8);

	// TODO - clean up this freaking mess!!!!!
	for (int row = -numRows; row <= numRows; row++)
	{
		unsigned int address = curAddress + row * align;

		int rowY1 = rc.height / 2 + rowHeight * row - rowHeight / 2;
		int rowY2 = rc.height / 2 + rowHeight * row + rowHeight / 2;

		wxString temp = wxString::Format(_T("%08x"), address);
		u32 col = debugger->GetColor(address);
		wxBrush rowBrush(wxColor(col >> 16, col >> 8, col));
		dc.SetBrush(nullBrush);
		dc.SetPen(nullPen);
		dc.DrawRectangle(0, rowY1, 16, rowY2);

		if (selecting && (address == selection))
			dc.SetPen(selPen);
		else
			dc.SetPen(row == 0 ? currentPen : nullPen);

		if (address == debugger->GetPC())
			dc.SetBrush(pcBrush);
		else
			dc.SetBrush(rowBrush);

		dc.DrawRectangle(16, rowY1, width, rowY2 - 1);
		dc.SetBrush(currentBrush);
		dc.SetTextForeground(_T("#600000"));
		dc.DrawText(temp, 17, rowY1);

		if (viewAsType != VIEWAS_HEX)
		{
			char mem[256];
			debugger->GetRawMemoryString(memory, address, mem, 256);
			dc.SetTextForeground(_T("#000080"));
			dc.DrawText(StrToWxStr(mem), 17+fontSize*(8), rowY1);
			dc.SetTextForeground(_T("#000000"));
		}

		if (debugger->IsAlive())
		{
			char dis[256] = {0};
			u32 mem_data = debugger->ReadExtraMemory(memory, address);

			if (viewAsType == VIEWAS_FP)
			{
				float flt = *(float *)(&mem_data);
				sprintf(dis, "f: %f", flt);
			}
			else if (viewAsType == VIEWAS_ASCII)
			{
				u32 a[4] = {(mem_data&0xff000000)>>24,
					(mem_data&0xff0000)>>16,
					(mem_data&0xff00)>>8,
					mem_data&0xff};
				for (auto& word : a)
					if (word == '\0')
						word = ' ';
				sprintf(dis, "%c%c%c%c", a[0], a[1], a[2], a[3]);
			}
			else if (viewAsType == VIEWAS_HEX)