Permalink
Browse files

Implement drawing of offset scale

-Add function to draw offset

-Add checkbox to allow toggling of offset writing

-Set writeOffsets default value to Off

-Ensure the drawing and user input is not affected by the offset
  • Loading branch information...
dl471 committed Oct 21, 2018
1 parent c11cfe3 commit b25adc7ba88d69e49c34f4be869902b834138e45
@@ -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 (writeOffsets) {
drawOffsetScale(hdc);
}
// draw one extra row that may be partially visible
for (int i = 0; i < visibleRows+1; i++)
{
@@ -205,7 +211,7 @@ void CtrlMemView::onPaint(WPARAM wParam, LPARAM lParam)
int rowY = rowHeight*i;
if (writeOffsets)
rowY += rowHeight * 2; // skip the first two rows to make space for the offets
rowY += rowHeight * offsetSpace; // skip the first X rows to make space for the offsets
sprintf(temp,"%08X",address);
@@ -281,7 +287,7 @@ void CtrlMemView::onPaint(WPARAM wParam, LPARAM lParam)
SelectObject(hdc,oldBrush);
// copy bitmap to the actual hdc
BitBlt(actualHdc, 0, 0, rect.right, rect.bottom, hdc, 0, 0, SRCCOPY);
BitBlt(actualHdc,0,0,rect.right,rect.bottom,hdc,0,0,SRCCOPY);
DeleteObject(hBM);
DeleteDC(hdc);
@@ -414,7 +420,7 @@ void CtrlMemView::redraw()
visibleRows = (rect.bottom/rowHeight);
if (writeOffsets) {
visibleRows -= 2; // visibleRows is calculated based on the size of the control, but 2 of the rows have already been used for the offsets and are not longer usable
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);
@@ -525,9 +531,16 @@ void CtrlMemView::gotoPoint(int x, int y)
int line = y/rowHeight;
int lineAddress = windowStart+line*rowSize;
if (writeOffsets)
lineAddress -= (rowSize * 2); // since each row has been written 2 rows down from where the window expected it to be written the target of the clicks must be adjusted
if (writeOffsets)
{
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)
{
@@ -720,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)
writeOffsets = true;
else if (toggle == Off)
writeOffsets = false;
updateStatusBarText();
redraw();
}
@@ -19,6 +19,16 @@
#include "../../Core/Debugger/DebugInterface.h"
enum OffsetSpacing {
offsetSpace = 3,
offsetLine = 1,
};
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,7 +49,7 @@ class CtrlMemView
bool asciiSelected;
int selectedNibble;
bool writeOffsets = true;
bool writeOffsets = false;
int visibleRows;
@@ -81,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 b25adc7

Please sign in to comment.