DolphinWX: Get rid of some magic numbers in MemoryView and MemoryWindow

This commit is contained in:
Lioncash 2015-07-09 07:47:51 -04:00
parent 638b108f44
commit 81878d7b56
3 changed files with 22 additions and 13 deletions

View File

@ -43,7 +43,6 @@ enum
CMemoryView::CMemoryView(DebugInterface* debuginterface, wxWindow* parent) CMemoryView::CMemoryView(DebugInterface* debuginterface, wxWindow* parent)
: wxControl(parent, wxID_ANY) : wxControl(parent, wxID_ANY)
, curAddress(debuginterface->GetPC())
, debugger(debuginterface) , debugger(debuginterface)
, align(debuginterface->GetInstructionSize(0)) , align(debuginterface->GetInstructionSize(0))
, rowHeight(13) , rowHeight(13)
@ -51,6 +50,8 @@ CMemoryView::CMemoryView(DebugInterface* debuginterface, wxWindow* parent)
, oldSelection(0) , oldSelection(0)
, selecting(false) , selecting(false)
, memory(0) , memory(0)
, curAddress(debuginterface->GetPC())
, dataType(MemoryDataType::U8)
, viewAsType(VIEWAS_FP) , viewAsType(VIEWAS_FP)
{ {
Bind(wxEVT_PAINT, &CMemoryView::OnPaint, this); Bind(wxEVT_PAINT, &CMemoryView::OnPaint, this);
@ -364,21 +365,21 @@ void CMemoryView::OnPaint(wxPaintEvent& event)
{ {
switch (dataType) switch (dataType)
{ {
case 0: case MemoryDataType::U8:
dis += StringFromFormat(" %02X %02X %02X %02X", dis += StringFromFormat(" %02X %02X %02X %02X",
((word & 0xff000000) >> 24) & 0xFF, ((word & 0xff000000) >> 24) & 0xFF,
((word & 0xff0000) >> 16) & 0xFF, ((word & 0xff0000) >> 16) & 0xFF,
((word & 0xff00) >> 8) & 0xFF, ((word & 0xff00) >> 8) & 0xFF,
word & 0xff); word & 0xff);
break; break;
case 1: case MemoryDataType::U16:
dis += StringFromFormat(" %02X%02X %02X%02X", dis += StringFromFormat(" %02X%02X %02X%02X",
((word & 0xff000000) >> 24) & 0xFF, ((word & 0xff000000) >> 24) & 0xFF,
((word & 0xff0000) >> 16) & 0xFF, ((word & 0xff0000) >> 16) & 0xFF,
((word & 0xff00) >> 8) & 0xFF, ((word & 0xff00) >> 8) & 0xFF,
word & 0xff); word & 0xff);
break; break;
case 2: case MemoryDataType::U32:
dis += StringFromFormat(" %02X%02X%02X%02X", dis += StringFromFormat(" %02X%02X%02X%02X",
((word & 0xff000000) >> 24) & 0xFF, ((word & 0xff000000) >> 24) & 0xFF,
((word & 0xff0000) >> 16) & 0xFF, ((word & 0xff0000) >> 16) & 0xFF,

View File

@ -9,6 +9,11 @@
class DebugInterface; class DebugInterface;
enum class MemoryDataType
{
U8, U16, U32
};
class CMemoryView : public wxControl class CMemoryView : public wxControl
{ {
public: public:
@ -22,8 +27,12 @@ public:
curAddress = addr; curAddress = addr;
Refresh(); Refresh();
} }
int dataType; // u8,u16,u32
int curAddress; // Will be accessed by parent void SetDataType(MemoryDataType data_type)
{
dataType = data_type;
Refresh();
}
private: private:
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
@ -47,6 +56,8 @@ private:
bool selecting; bool selecting;
int memory; int memory;
int curAddress;
MemoryDataType dataType;
enum EViewAsType enum EViewAsType
{ {

View File

@ -79,7 +79,7 @@ CMemoryWindow::CMemoryWindow(wxWindow* parent, wxWindowID id,
// wxSize(20, 100), 0, nullptr, wxLB_SORT); // wxSize(20, 100), 0, nullptr, wxLB_SORT);
//sizerLeft->Add(symbols, 1, wxEXPAND); //sizerLeft->Add(symbols, 1, wxEXPAND);
memview = new CMemoryView(di, this); memview = new CMemoryView(di, this);
memview->dataType = 0;
//sizerBig->Add(sizerLeft, 1, wxEXPAND); //sizerBig->Add(sizerLeft, 1, wxEXPAND);
sizerBig->Add(memview, 20, wxEXPAND); sizerBig->Add(memview, 20, wxEXPAND);
sizerBig->Add(sizerRight, 0, wxEXPAND | wxALL, 3); sizerBig->Add(sizerRight, 0, wxEXPAND | wxALL, 3);
@ -281,24 +281,21 @@ void CMemoryWindow::U8(wxCommandEvent& event)
{ {
chk16->SetValue(0); chk16->SetValue(0);
chk32->SetValue(0); chk32->SetValue(0);
memview->dataType = 0; memview->SetDataType(MemoryDataType::U8);
memview->Refresh();
} }
void CMemoryWindow::U16(wxCommandEvent& event) void CMemoryWindow::U16(wxCommandEvent& event)
{ {
chk8->SetValue(0); chk8->SetValue(0);
chk32->SetValue(0); chk32->SetValue(0);
memview->dataType = 1; memview->SetDataType(MemoryDataType::U16);
memview->Refresh();
} }
void CMemoryWindow::U32(wxCommandEvent& event) void CMemoryWindow::U32(wxCommandEvent& event)
{ {
chk16->SetValue(0); chk16->SetValue(0);
chk8->SetValue(0); chk8->SetValue(0);
memview->dataType = 2; memview->SetDataType(MemoryDataType::U32);
memview->Refresh();
} }
void CMemoryWindow::onSearch(wxCommandEvent& event) void CMemoryWindow::onSearch(wxCommandEvent& event)