Permalink
Browse files

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

Windows: Option to show offset scale in memory view
  • Loading branch information...
hrydgard committed Nov 2, 2018
2 parents f8e946d + f68fed7 commit e7ac302384376c77fc4a7cc56ff24343932804b6
@@ -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,13 +198,21 @@ 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++)
{
char temp[32];
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();
}
@@ -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 @@ class CtrlMemView
void gotoAddr(unsigned int addr);
void scrollWindow(int lines);
void scrollCursor(int bytes);
void drawOffsetScale(HDC hdc);
void toggleOffsetScale(OffsetToggles toggle);
};
@@ -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;
@@ -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
@@ -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

0 comments on commit e7ac302

Please sign in to comment.