Merge pull request #11488 from dl471/memview-show-offsets

Windows: Option to show offset scale in memory view
This commit is contained in:
Henrik Rydgård 2018-11-02 11:30:33 +01:00 committed by GitHub
commit e7ac302384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 0 deletions

View File

@ -28,6 +28,7 @@ CtrlMemView::CtrlMemView(HWND _wnd)
rowHeight = g_Config.iFontHeight;
charWidth = g_Config.iFontWidth;
offsetPositionY = offsetLine*rowHeight;
font =
CreateFont(rowHeight,charWidth,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
@ -93,6 +94,7 @@ LRESULT CALLBACK CtrlMemView::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
{
CtrlMemView *ccp = CtrlMemView::getFrom(hwnd);
static bool lmbDown=false,rmbDown=false;
switch(msg)
{
case WM_NCCREATE:
@ -196,6 +198,10 @@ void CtrlMemView::onPaint(WPARAM wParam, LPARAM lParam)
SelectObject(hdc,standardBrush);
Rectangle(hdc,0,0,rect.right,rect.bottom);
if (displayOffsetScale)
drawOffsetScale(hdc);
// draw one extra row that may be partially visible
for (int i = 0; i < visibleRows+1; i++)
{
@ -203,6 +209,10 @@ void CtrlMemView::onPaint(WPARAM wParam, LPARAM lParam)
unsigned int address=windowStart + i*rowSize;
int rowY = rowHeight*i;
if (displayOffsetScale)
rowY += rowHeight * offsetSpace; // skip the first X rows to make space for the offsets
sprintf(temp,"%08X",address);
SetTextColor(hdc,0x600000);
@ -409,6 +419,10 @@ void CtrlMemView::redraw()
GetClientRect(wnd, &rect);
visibleRows = (rect.bottom/rowHeight);
if (displayOffsetScale) {
visibleRows -= offsetSpace; // visibleRows is calculated based on the size of the control, but X rows have already been used for the offsets and are no longer usable
}
InvalidateRect(wnd, NULL, FALSE);
UpdateWindow(wnd);
}
@ -517,6 +531,17 @@ void CtrlMemView::gotoPoint(int x, int y)
int line = y/rowHeight;
int lineAddress = windowStart+line*rowSize;
if (displayOffsetScale)
{
if (line < offsetSpace) // ignore clicks on the offset space
{
updateStatusBarText();
redraw();
return;
}
lineAddress -= (rowSize * offsetSpace); // since each row has been written X rows down from where the window expected it to be written the target of the clicks must be adjusted
}
if (x >= asciiStart)
{
int col = (x-asciiStart) / (charWidth+2);
@ -708,3 +733,34 @@ void CtrlMemView::search(bool continueSearch)
searching = false;
redraw();
}
void CtrlMemView::drawOffsetScale(HDC hdc)
{
int currentX = addressStart;
SetTextColor(hdc, 0x600000);
TextOutA(hdc, currentX, offsetPositionY, "Offset", 6);
currentX = addressStart + ((8 + 1)*charWidth); // the start offset, the size of the hex addresses and one space
char temp[64];
for (int i = 0; i < 16; i++)
{
sprintf(temp, "%02X", i);
TextOutA(hdc, currentX, offsetPositionY, temp, 2);
currentX += 3 * charWidth; // hex and space
}
}
void CtrlMemView::toggleOffsetScale(OffsetToggles toggle)
{
if (toggle == On)
displayOffsetScale = true;
else if (toggle == Off)
displayOffsetScale = false;
updateStatusBarText();
redraw();
}

View File

@ -19,6 +19,16 @@
#include "../../Core/Debugger/DebugInterface.h"
enum OffsetSpacing {
offsetSpace = 3, // the number of blank lines that should be left to make space for the offsets
offsetLine = 1, // the line on which the offsets should be written
};
enum OffsetToggles {
On,
Off,
};
class CtrlMemView
{
HWND wnd;
@ -30,6 +40,7 @@ class CtrlMemView
unsigned int windowStart;
int rowHeight;
int rowSize;
int offsetPositionY;
int addressStart;
int charWidth;
@ -38,6 +49,8 @@ class CtrlMemView
bool asciiSelected;
int selectedNibble;
bool displayOffsetScale = false;
int visibleRows;
std::string searchQuery;
@ -79,4 +92,7 @@ public:
void gotoAddr(unsigned int addr);
void scrollWindow(int lines);
void scrollCursor(int bytes);
void drawOffsetScale(HDC hdc);
void toggleOffsetScale(OffsetToggles toggle);
};

View File

@ -154,6 +154,17 @@ BOOL CMemoryDlg::DlgProc(UINT message, WPARAM wParam, LPARAM lParam)
break;
};
break;
case IDC_SHOWOFFSETS:
switch (HIWORD(wParam))
{
case BN_CLICKED:
if (SendDlgItemMessage(m_hDlg, IDC_SHOWOFFSETS, BM_GETCHECK, 0, 0))
mv->toggleOffsetScale(On);
else
mv->toggleOffsetScale(Off);
break;
}
break;
}
}
break;

View File

@ -304,6 +304,7 @@ BEGIN
CONTROL "Normal",IDC_MODENORMAL,"Button",BS_AUTORADIOBUTTON | WS_GROUP,248,9,40,9
CONTROL "Symbols",IDC_MODESYMBOLS,"Button",BS_AUTORADIOBUTTON,291,9,43,8
GROUPBOX "Mode",IDC_STATIC,241,0,104,22
AUTOCHECKBOX "Show Offsets",IDC_SHOWOFFSETS,365,9,55,8
COMBOBOX IDC_REGIONS,87,5,88,139,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
END

View File

@ -164,6 +164,7 @@
#define IDC_GEDBG_FORCEOPAQUE 1197
#define IDC_GEDBG_SHOWCLUT 1198
#define IDC_BREAKPOINT_LOG_FORMAT 1199
#define IDC_SHOWOFFSETS 1200
#define ID_SHADERS_BASE 5000