static void GetTextFromCell(tinyxml2::XMLElement* pCell, nString& Text)
{
	Text.Clear();

	tinyxml2::XMLHandle hCell(pCell);
	tinyxml2::XMLText* pText = hCell.FirstChildElement("Data").FirstChild().ToText();
	if (pText) Text = pText->Value();
	else
	{
		// Check for indirect text (hidden in Font-Statements)
		tinyxml2::XMLElement* pData = hCell.FirstChildElement("ss:Data").ToElement();
		if (!pData) return;

		tinyxml2::XMLElement* pFont = pData->FirstChildElement("Font");
		for (; pFont; pFont = pFont->NextSiblingElement("Font"))
		{
			tinyxml2::XMLHandle hFont(pFont);
			tinyxml2::XMLText* pFontText = hFont.FirstChild().ToText();
			if (pFontText) Text.Append(pFontText->Value());
		}
	}
}
Example #2
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)
Example #3
0
DGraphics::FontResourcePtr DGraphics::loadFont(const wchar_t *fontName,
	uint32_t startChar, uint32_t endChar, uint32_t w, uint32_t h)
{
	HRESULT hr = S_OK;

	// Create font
	HFONT htmpFont = ::CreateFont(
		h, 0, 0, 0, 0, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
		OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
		FIXED_PITCH | FF_MODERN, fontName);
	checkWin32Result(htmpFont != nullptr, "CreateFont() failed");
	auto fontDel = [](HFONT hFont) { ::DeleteObject(hFont); };
	std::unique_ptr<std::remove_pointer<HFONT>::type, decltype(fontDel)>
		hFont(htmpFont, fontDel);
	// Get DC
	HDC htmpDC = ::GetDC(nullptr);
	checkWin32Result(htmpDC != nullptr, "GetDC() failed");
	auto dcRel = [](HDC hDC) { ::ReleaseDC(nullptr, hDC); };
	std::unique_ptr<std::remove_pointer<HDC>::type, decltype(dcRel)>
		hDC(htmpDC, dcRel);
	// Select font
	HFONT tmpOldFont = static_cast<HFONT>(::SelectObject(hDC.get(), hFont.get()));
	checkWin32Result(tmpOldFont != nullptr, "SelectObject() failed");
	auto restoreObj = [&hDC](HFONT oldFont) { ::SelectObject(hDC.get(), oldFont); };
	std::unique_ptr<std::remove_pointer<HFONT>::type, decltype(restoreObj)>
		hOldFont(tmpOldFont, restoreObj);

	TEXTMETRIC tm = { 0 };
	checkWin32Result(::GetTextMetrics(hDC.get(), &tm) != FALSE,
		"GetTextMetrics() failed");

	std::vector<FontTexture::TexPtr> texList;
	std::vector<FontTexture::RvPtr> rvList;
	texList.reserve(endChar - startChar + 1);
	rvList.reserve(endChar - startChar + 1);

	for (uint32_t c = startChar; c <= endChar; c++) {
		// Get font bitmap
		GLYPHMETRICS gm = { 0 };
		const MAT2 mat = { { 0, 1 },{ 0, 0 },{ 0, 0 },{ 0, 1 } };
		DWORD bufSize = ::GetGlyphOutline(hDC.get(), c, GGO_GRAY8_BITMAP, &gm, 0, nullptr, &mat);
		checkWin32Result(bufSize != GDI_ERROR, "GetGlyphOutline() failed");
		auto buf = std::make_unique<uint8_t[]>(bufSize);
		DWORD ret = ::GetGlyphOutline(hDC.get(), c, GGO_GRAY8_BITMAP, &gm, bufSize, buf.get(), &mat);
		checkWin32Result(ret != GDI_ERROR, "GetGlyphOutline() failed");
		uint32_t pitch = (gm.gmBlackBoxX + 3) / 4 * 4;
		// Black box pos in while box
		uint32_t destX = gm.gmptGlyphOrigin.x;
		uint32_t destY = tm.tmAscent - gm.gmptGlyphOrigin.y;

		// Create texture
		D3D11_TEXTURE2D_DESC desc = { 0 };
		desc.Width = w;
		desc.Height = h;
		desc.MipLevels = 1;
		desc.ArraySize = 1;
		desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		desc.SampleDesc.Count = 1;
		desc.Usage = D3D11_USAGE_DYNAMIC;
		desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
		desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
		ID3D11Texture2D *ptmpTex = nullptr;
		hr = m_pDevice->CreateTexture2D(&desc, nullptr, &ptmpTex);
		checkDXResult<D3DError>(hr, "ID3D11Device::CreateTexture2D() failed");
		// make unique_ptr and push
		texList.emplace_back(ptmpTex);

		// Write
		D3D11_MAPPED_SUBRESOURCE mapped;
		UINT subres = ::D3D11CalcSubresource(0, 0, 1);
		hr = m_pContext->Map(ptmpTex, subres, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
		checkDXResult<D3DError>(hr, "ID3D11DeviceContext::Map() failed");
		uint8_t *pTexels = static_cast<uint8_t *>(mapped.pData);
		::ZeroMemory(pTexels, w * h * 4);
		for (uint32_t y = 0; y < gm.gmBlackBoxY; y++) {
			for (uint32_t x = 0; x < gm.gmBlackBoxX; x++) {
				if (destX + x >= w || destY + y >= h) {
					continue;
				}
				uint32_t alpha = buf[y * pitch + x] * 255 / 64;
				uint32_t destInd = (((destY + y) * w) + (destX + x)) * 4;
				pTexels[destInd + 0] = 0;
				pTexels[destInd + 1] = 0;
				pTexels[destInd + 2] = 0;
				pTexels[destInd + 3] = alpha;
			}
		}
		m_pContext->Unmap(ptmpTex, subres);

		// Create resource view
		ID3D11ShaderResourceView *ptmpRV = nullptr;
		hr = m_pDevice->CreateShaderResourceView(ptmpTex, nullptr, &ptmpRV);
		checkDXResult<D3DError>(hr, "ID3D11Device::CreateShaderResourceView() failed");
		// make unique_ptr and push
		rvList.emplace_back(ptmpRV);
	}

	// add (id, FontTexture(...))
	auto res = std::make_shared<FontTexture>(
		w, h, startChar, endChar);
	res->pTexList.swap(texList);
	res->pRVList.swap(rvList);
	return res;
}
Example #4
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)