diff --git a/src/tests/kits/interface/flatten_picture/PictureTestWindow.cpp b/src/tests/kits/interface/flatten_picture/PictureTestWindow.cpp index 772bbc3bcd..350026952d 100644 --- a/src/tests/kits/interface/flatten_picture/PictureTestWindow.cpp +++ b/src/tests/kits/interface/flatten_picture/PictureTestWindow.cpp @@ -21,6 +21,7 @@ #include "PictureTestWindow.h" #include "TestResultItem.h" + PictureTestWindow::PictureTestWindow() : Inherited(BRect(10, 30, 630, 470), "Bitmap Drawing Tests", B_DOCUMENT_WINDOW, 0) , fFailedTests(0) @@ -61,7 +62,7 @@ void PictureTestWindow::BuildGUI() BRect b = Bounds(); b.top = mb->Bounds().bottom + 1; - + fHeader = new BStringView(b, "header", "X", B_FOLLOW_LEFT | B_FOLLOW_RIGHT | B_FOLLOW_TOP); float width, height; @@ -69,7 +70,7 @@ void PictureTestWindow::BuildGUI() fHeader->ResizeTo(b.Width(), height); backdrop->AddChild(fHeader); b.top = fHeader->Frame().bottom + 1; - + b.right -= B_V_SCROLL_BAR_WIDTH; b.bottom -= B_H_SCROLL_BAR_HEIGHT; fListView = new BListView(b, "Results", B_SINGLE_SELECTION_LIST, @@ -83,8 +84,8 @@ void PictureTestWindow::BuildGUI() void PictureTestWindow::UpdateHeader() { - BString text("Direct Drawing, Picture Drawing, Restored Picture Drawing, Test Name, Error Message"); - text << " (failures = " << fFailedTests << ", tests =" << fNumberOfTests << ")"; + BString text; + text << "failures = " << fFailedTests << ", tests =" << fNumberOfTests; fHeader->SetText(text.String()); } @@ -144,7 +145,7 @@ PictureTestWindow::RunTests(color_space *colorSpaces, int32 n) fListView->AddItem(new BStringItem(text.String())); RunTests(testIndex, colorSpaces, n); } - + UpdateHeader(); } @@ -179,6 +180,10 @@ PictureTestWindow::RunTests(int32 testIndex, color_space *colorSpaces, int32 n) text += csText; fListView->AddItem(new BStringItem(text.String())); + BRect frame(0, 0, 100, 30); + fListView->AddItem(new HeaderListItem("Direct Drawing", "Picture Drawing", + "Restored Picture", "", "Test Name", "Error Message", frame)); + RunTests(testIndex, colorSpace); } } diff --git a/src/tests/kits/interface/flatten_picture/TestResultItem.cpp b/src/tests/kits/interface/flatten_picture/TestResultItem.cpp index de12cb65f1..539bacb91f 100644 --- a/src/tests/kits/interface/flatten_picture/TestResultItem.cpp +++ b/src/tests/kits/interface/flatten_picture/TestResultItem.cpp @@ -8,7 +8,7 @@ #include "TestResultItem.h" -const float distance = 5; +const float kDistance = 5; TestResultItem::TestResultItem(const char* name, BRect bitmapSize) : fName(name) @@ -39,12 +39,10 @@ TestResultItem::DrawItem(BView *owner, BRect itemRect, bool drawEverthing) if (IsSelected()) { rgb_color lowColor = owner->LowColor(); owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT)); - } - else if (fOk) { + } else if (fOk) { // green background color on success owner->SetHighColor(200, 255, 200); - } - else { + } else { // red background color on failure owner->SetHighColor(255, 200, 200); } @@ -57,23 +55,23 @@ TestResultItem::DrawItem(BView *owner, BRect itemRect, bool drawEverthing) if (fDirectBitmap != NULL) { owner->DrawBitmap(fDirectBitmap); } - owner->MovePenBy(fBitmapSize.Width() + distance, 0); + owner->MovePenBy(fBitmapSize.Width() + kDistance, 0); if (fOriginalBitmap != NULL) { owner->DrawBitmap(fOriginalBitmap); } - owner->MovePenBy(fBitmapSize.Width() + distance, 0); + owner->MovePenBy(fBitmapSize.Width() + kDistance, 0); if (fArchivedBitmap != NULL) { owner->DrawBitmap(fArchivedBitmap); } - owner->MovePenBy(fBitmapSize.Width() + distance, 0); + owner->MovePenBy(fBitmapSize.Width() + kDistance, 0); owner->DrawBitmap(fDirectBitmap); owner->SetDrawingMode(B_OP_SUBTRACT); owner->DrawBitmap(fOriginalBitmap); - owner->MovePenBy(fBitmapSize.Width() + distance, 0); + owner->MovePenBy(fBitmapSize.Width() + kDistance, 0); owner->SetDrawingMode(B_OP_OVER); BFont font; @@ -90,11 +88,12 @@ TestResultItem::DrawItem(BView *owner, BRect itemRect, bool drawEverthing) font.SetFace(B_ITALIC_FACE); owner->SetFont(&font); owner->SetHighColor(255, 0, 0); - owner->MovePenBy(distance, 0); + owner->MovePenBy(kDistance, 0); owner->DrawString(fErrorMessage.String()); owner->PopState(); } + void TestResultItem::Update(BView *owner, const BFont *font) { @@ -103,18 +102,18 @@ TestResultItem::Update(BView *owner, const BFont *font) float height = 0.0; width += font->StringWidth(fName.String()); - width += distance; + width += kDistance; width += font->StringWidth(fErrorMessage.String()); - - width += 3 * distance; + + width += 3 * kDistance; width += 3 * fBitmapSize.Width(); height = fBitmapSize.Height(); - + // border of two pixels width += 4; height += 4; - + if (width > Width()) SetWidth(width); @@ -122,3 +121,78 @@ TestResultItem::Update(BView *owner, const BFont *font) SetHeight(height); } + +// HeaderListItem +HeaderListItem::HeaderListItem(const char* label1, const char* label2, + const char* label3, const char* label4, const char* label5, + const char* label6, BRect rect) + : + fRect(rect) +{ + fLabels[0] = label1; + fLabels[1] = label2; + fLabels[2] = label3; + fLabels[3] = label4; + fLabels[4] = label5; + fLabels[5] = label6; +} + + +/* virtual */ +void +HeaderListItem::DrawItem(BView *owner, BRect itemRect, bool drawEverthing) +{ + owner->SetDrawingMode(B_OP_COPY); + + owner->PushState(); + if (IsSelected()) { + rgb_color lowColor = owner->LowColor(); + owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT)); + owner->FillRect(itemRect); + } + + owner->PopState(); + + itemRect.InsetBy(0, 1); + owner->StrokeRect(itemRect); + + itemRect.InsetBy(1, 0); + + owner->SetDrawingMode(B_OP_OVER); + + BFont font; + owner->GetFont(&font); + float baseLine = itemRect.top + (itemRect.IntegerHeight() / 2 + font.Size() / 2); + + for (int32 c = 0; c < sizeof(fLabels) / sizeof(fLabels[0]); c++) { + owner->MovePenTo(itemRect.left + 1 + (fRect.Width() + kDistance) * c, baseLine); + owner->DrawString(fLabels[c]); + } +} + + +/* virtual */ +void +HeaderListItem::Update(BView *owner, const BFont *font) +{ + BListItem::Update(owner, font); + float width = 0.0; + float height = 0.0; + + for (int32 c = 0; c < sizeof(fLabels) / sizeof(fLabels[0]); c++) { + width += font->StringWidth(fLabels[c].String()); + } + + width += kDistance * (sizeof(fLabels) / sizeof(fLabels[0]) - 1); + + height = fRect.Height(); + + // border of two pixels + width += 4; + height += 4; + + if (width > Width()) + SetWidth(width); + if (height > Height()) + SetHeight(height); +} diff --git a/src/tests/kits/interface/flatten_picture/TestResultItem.h b/src/tests/kits/interface/flatten_picture/TestResultItem.h index 1da029323d..6561febcaf 100644 --- a/src/tests/kits/interface/flatten_picture/TestResultItem.h +++ b/src/tests/kits/interface/flatten_picture/TestResultItem.h @@ -39,4 +39,19 @@ private: BBitmap *fArchivedBitmap; }; + +class HeaderListItem : public BListItem { +public: + HeaderListItem(const char* label1, const char* label2, + const char* label3, const char* label4, const char* label5, + const char* label6, BRect rect); + virtual void DrawItem(BView *owner, BRect itemRect, bool drawEverthing); + virtual void Update(BView *owner, const BFont *font); + +private: + BString fLabels[6]; + BRect fRect; +}; + + #endif