MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / DoPaint

Method DoPaint

WinArk/HexControl.cpp:4–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include "HexControl.h"
3
4void CHexControl::DoPaint(CDCHandle dc, RECT& rect) {
5 auto back = m_ReadOnly ? RGB(192, 192, 192) : m_Colors.Background;
6 dc.FillSolidRect(&rect, back);
7 if (!m_Buffer)
8 return;
9
10 SCROLLINFO si;
11 si.cbSize = sizeof(si);
12 si.fMask = SIF_POS;
13 GetScrollInfo(SB_HORZ, &si);
14 int xstart = -si.nPos * m_CharWidth;
15
16 dc.SelectFont(m_Font);
17 dc.SetBkMode(OPAQUE);
18 dc.SetBkColor(back);
19
20 WCHAR str[20];
21 int i = 0;
22 uint8_t data[512];
23 POLYTEXT poly[128] = { 0 };
24
25 int addrLenth = m_AddressDigits;
26 const std::wstring addrFormat = L"%0" + std::to_wstring(addrLenth) + L"X";
27 int x = (addrLenth + 1) * m_CharWidth;
28
29 // data
30 m_Text.clear();
31 int lines = 1;
32 std::wstring format(L"%0" + std::to_wstring(m_DataSize * 2) + L"llX ");
33 int factor = m_CharWidth * (m_DataSize * 2 + 1);
34 for (int y = 0;; y++) {
35 auto offset = m_StartOffset + i;
36 int count = m_Buffer->GetData(offset, data, m_BytesPerLine);
37 if (count == 0)
38 break;
39 if (m_EditDigits > 0 && m_CaretOffset >= offset && m_CaretOffset < offset + m_BytesPerLine) {
40 // change data
41 memcpy(data + m_CaretOffset - offset, &m_CurrentInput, m_DataSize);
42 }
43 int jcount = std::min<int>(m_BytesPerLine / m_DataSize, count);
44 for (int j = 0; j < jcount; j++) {
45 if (offset + j * m_DataSize >= m_EndOffset)
46 break;
47 auto ds = int(m_EndOffset - offset - j * m_DataSize);
48 ATLASSERT(ds >= 1);
49 if (ds > m_DataSize)
50 ds = m_DataSize;
51 if (ds & (ds - 1))
52 ds = m_DataSize >> 1;
53
54 switch (ds)
55 {
56 case 1: ::StringCchPrintf(str, _countof(str), L"%02X", data[j * m_DataSize]); break;
57 case 2: ::StringCchPrintf(str, _countof(str), L"%04X", *(WORD*)&data[j * m_DataSize]); break;
58 case 4: ::StringCchPrintf(str, _countof(str), L"%08X", *(DWORD*)&data[j * m_DataSize]); break;
59 case 8: ::StringCchPrintf(str, _countof(str), L"%0llX", *(DWORD64*)&data[j * m_DataSize]); break;
60 }
61 bool selected = m_Selection.IsSelected(offset + j);

Callers

nothing calls this directly

Calls 7

clearMethod · 0.80
IsSelectedMethod · 0.80
SetTextColorMethod · 0.80
push_backMethod · 0.80
emptyMethod · 0.80
GetDataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected