Changed the ConvertLine() method to produce almost exactly the same

output as the original DiskProbe.
fFontSize and fAscent are now automatically maintained when the font
size is changed. Rendering improved (spacing and location).
The maximum window size is now set to contain the whole data view.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6569 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-02-12 04:21:33 +00:00
parent bc005359f2
commit 90828ad15d
5 changed files with 80 additions and 11 deletions
+51 -8
View File
@@ -11,16 +11,19 @@
static const uint32 kBlockSize = 16;
static const uint32 kHorizontalSpace = 8;
static const uint32 kVerticalSpace = 4;
DataView::DataView(BRect rect, DataEditor &editor)
: BView(rect, "dataView", B_FOLLOW_NONE, B_WILL_DRAW),
: BView(rect, "dataView", B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS),
fEditor(editor)
{
fPositionLength = 4;
fDataSize = fEditor.ViewSize();
fData = (uint8 *)malloc(fDataSize);
fFontHeight = 15;
SetFontSize(12.0);
UpdateFromEditor();
@@ -94,14 +97,11 @@ DataView::ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size
line += sprintf(line, "%0*Lx: ", (int)fPositionLength, offset);
for (uint32 i = 0; i < kBlockSize; i++) {
if (!(i % 4))
*line++ = ' ';
if (i >= size) {
strcpy(line, " ");
line += 2;
} else
line += sprintf(line, "%02x", *(unsigned char *)(buffer + i));
line += sprintf(line, "%02x ", *(unsigned char *)(buffer + i));
}
strcpy(line, " ");
@@ -111,7 +111,7 @@ DataView::ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size
if (i < size) {
char c = buffer[i];
if (c < 30)
if (c < ' ' || c == 0x7f)
*line++ = '.';
else
*line++ = c;
@@ -132,7 +132,7 @@ DataView::Draw(BRect updateRect)
// ToDo: take "updateRect" into account!
char line[255];
BPoint location(8, fFontHeight);
BPoint location(kHorizontalSpace, kVerticalSpace + fAscent);
for (uint32 i = 0; i < fDataSize; i += kBlockSize) {
ConvertLine(line, fOffset + i, fData + i, fDataSize - i);
@@ -143,3 +143,46 @@ DataView::Draw(BRect updateRect)
// ToDo: clear unused space!
}
void
DataView::SetFont(const BFont *font, uint32 properties)
{
if (!font->IsFixed())
return;
BView::SetFont(font, properties);
font_height fontHeight;
font->GetHeight(&fontHeight);
fFontHeight = int32(fontHeight.ascent + fontHeight.descent + fontHeight.leading);
fAscent = fontHeight.ascent;
}
void
DataView::SetFontSize(float point)
{
BFont font = be_fixed_font;
font.SetSize(point);
SetFont(&font);
}
void
DataView::GetPreferredSize(float *_width, float *_height)
{
if (_width) {
BFont font;
GetFont(&font);
*_width = font.StringWidth("w") * (kBlockSize * 4 + fPositionLength + 6)
+ 2 * kHorizontalSpace;
}
if (_height) {
*_height = fFontHeight * ((fDataSize + kBlockSize - 1) / kBlockSize)
+ 2 * kVerticalSpace;
}
}
+7 -1
View File
@@ -24,6 +24,11 @@ class DataView : public BView {
virtual void MessageReceived(BMessage *message);
virtual void Draw(BRect updateRect);
virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL);
virtual void GetPreferredSize(float *_width, float *_height);
void SetFontSize(float point);
private:
void UpdateFromEditor(BMessage *message = NULL);
void ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size);
@@ -33,7 +38,8 @@ class DataView : public BView {
uint8 *fData;
uint32 fDataSize;
off_t fOffset;
float fFontHeight;
float fAscent;
int32 fFontHeight;
};
#endif /* DATA_VIEW_H */
+16 -2
View File
@@ -361,9 +361,9 @@ ProbeView::ProbeView(BRect rect, entry_ref *ref, const char *attribute)
rect.top = rect.bottom + 3;
rect.bottom = Bounds().bottom - B_H_SCROLL_BAR_HEIGHT;
rect.right -= B_V_SCROLL_BAR_WIDTH;
BView *view = new DataView(rect, fEditor);
fDataView = new DataView(rect, fEditor);
fScrollView = new BScrollView("scroller", view, B_FOLLOW_ALL, B_WILL_DRAW, true, true);
fScrollView = new BScrollView("scroller", fDataView, B_FOLLOW_ALL, B_WILL_DRAW, true, true);
AddChild(fScrollView);
}
@@ -373,6 +373,20 @@ ProbeView::~ProbeView()
}
void
ProbeView::UpdateSizeLimits()
{
if (Window() == NULL)
return;
float width, height;
fDataView->GetPreferredSize(&width, &height);
Window()->SetSizeLimits(200, width + B_V_SCROLL_BAR_WIDTH,
200, height + fHeaderView->Frame().bottom + 1 + B_H_SCROLL_BAR_HEIGHT + Frame().top);
}
void
ProbeView::DetachedFromWindow()
{
+4
View File
@@ -16,6 +16,7 @@
class BScrollView;
class HeaderView;
class DataView;
class ProbeView : public BView {
@@ -29,9 +30,12 @@ class ProbeView : public BView {
void AddFileMenuItems(BMenu *menu, int32 index);
void UpdateSizeLimits();
private:
DataEditor fEditor;
HeaderView *fHeaderView;
DataView *fDataView;
BScrollView *fScrollView;
};
+2
View File
@@ -70,6 +70,8 @@ ProbeWindow::ProbeWindow(BRect rect, entry_ref *ref, const char *attribute)
ProbeView *probeView = new ProbeView(rect, ref, attribute);
probeView->AddFileMenuItems(menu, menu->CountItems() - 4);
AddChild(probeView);
probeView->UpdateSizeLimits();
}