More cleanups. Scrolling draws correctly now.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42170 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent
2011-06-14 03:33:10 +00:00
parent e445dd0ef7
commit 90624579a7
@@ -98,33 +98,36 @@ MemoryView::Draw(BRect rect)
if (fTargetBlock == NULL) if (fTargetBlock == NULL)
return; return;
char buffer[32]; char buffer[16];
int32 startLine = (int32)rect.top / fLineHeight; int32 startLine = rect.top / fLineHeight;
int32 bytesPerLine = fNybblesPerLine / 2; int32 endLine = rect.bottom / fLineHeight + 1;
int32 startByte = bytesPerLine * startLine; int32 startByte = fNybblesPerLine / 2 * startLine;
target_addr_t currentAddress = fTargetBlock->BaseAddress() + startByte; uint16* currentAddress = (uint16*)(fTargetBlock->BaseAddress()
target_addr_t maxAddress = fTargetBlock->BaseAddress() + startByte);
+ fTargetBlock->Size(); uint16* maxAddress = (uint16*)(fTargetBlock->BaseAddress()
BPoint drawPoint(1.0, rect.top); + fTargetBlock->Size());
int32 currentBytesPerLine = bytesPerLine; BPoint drawPoint(1.0, startLine * fLineHeight);
int32 currentWordsPerLine = fNybblesPerLine / 4;
for (int32 i = startLine; drawPoint.y < rect.bottom for (int32 i = startLine; i <= endLine && currentAddress < maxAddress;
&& currentAddress < maxAddress; i++, drawPoint.y += fLineHeight) { i++, drawPoint.y += fLineHeight) {
drawPoint.x = 1.0; drawPoint.x = 1.0;
snprintf(buffer, sizeof(buffer), "%" B_PRIx32 " ", snprintf(buffer, sizeof(buffer), "%" B_PRIx32,
(uint32)currentAddress); (uint32)currentAddress);
DrawString(buffer, drawPoint); DrawString(buffer, drawPoint);
drawPoint.x += fCharWidth * 10; drawPoint.x += fCharWidth * 10;
if (currentAddress + bytesPerLine > maxAddress)
currentBytesPerLine = maxAddress - currentAddress; if (currentAddress + currentWordsPerLine > maxAddress)
for (int32 j = 0; j < currentBytesPerLine; j += 2) { currentWordsPerLine = (maxAddress - currentAddress) / 2;
snprintf(buffer, sizeof(buffer), "%04" B_PRIx16 " ",
*((uint16*)&fTargetBlock->Data()[i * bytesPerLine + j])); for (int32 j = 0; j < currentWordsPerLine; j++) {
snprintf(buffer, sizeof(buffer), "%04" B_PRIx16,
currentAddress[j]);
DrawString(buffer, drawPoint); DrawString(buffer, drawPoint);
drawPoint.x += fCharWidth * 5; drawPoint.x += fCharWidth * 5;
} }
currentAddress += bytesPerLine; currentAddress += currentWordsPerLine;
} }
} }
@@ -176,7 +179,7 @@ MemoryView::_RecalcScrollBars()
// line plus some spacing to separate that from the data // line plus some spacing to separate that from the data
fNybblesPerLine -= 10; fNybblesPerLine -= 10;
// also allocate a space between each 16-bit grouping // also allocate a space between each 16-bit grouping
fNybblesPerLine -= (fNybblesPerLine / 4); fNybblesPerLine -= (fNybblesPerLine / 4) - 1;
fNybblesPerLine &= ~3; fNybblesPerLine &= ~3;
int32 lineCount = ceil(2 * fTargetBlock->Size() / fNybblesPerLine); int32 lineCount = ceil(2 * fTargetBlock->Size() / fNybblesPerLine);
float totalHeight = lineCount * fLineHeight; float totalHeight = lineCount * fLineHeight;