182afdb09SMichael Pfeiffer /* 282afdb09SMichael Pfeiffer * Copyright 2007, Haiku. All rights reserved. 382afdb09SMichael Pfeiffer * Distributed under the terms of the MIT License. 482afdb09SMichael Pfeiffer * 582afdb09SMichael Pfeiffer * Authors: 682afdb09SMichael Pfeiffer * Michael Pfeiffer 782afdb09SMichael Pfeiffer */ 882afdb09SMichael Pfeiffer 982afdb09SMichael Pfeiffer #include "PictureTestCases.h" 1082afdb09SMichael Pfeiffer 1154730332SMichael Pfeiffer static const rgb_color kBlack = {0, 0, 0}; 1254730332SMichael Pfeiffer static const rgb_color kWhite = {255, 255, 255}; 1354730332SMichael Pfeiffer static const rgb_color kRed = {255, 0, 0}; 1454730332SMichael Pfeiffer static const rgb_color kGreen = {0, 255, 0}; 1554730332SMichael Pfeiffer static const rgb_color kBlue = {0, 0, 255}; 1654730332SMichael Pfeiffer 1754730332SMichael Pfeiffer static BPoint centerPoint(BRect rect) 1854730332SMichael Pfeiffer { 1954730332SMichael Pfeiffer int x = (int)(rect.left + rect.IntegerWidth() / 2); 2054730332SMichael Pfeiffer int y = (int)(rect.top + rect.IntegerHeight() / 2); 2154730332SMichael Pfeiffer return BPoint(x, y); 2254730332SMichael Pfeiffer } 2354730332SMichael Pfeiffer 2454730332SMichael Pfeiffer static void testNoOp(BView *view, BRect frame) 2582afdb09SMichael Pfeiffer { 2682afdb09SMichael Pfeiffer // no op 2782afdb09SMichael Pfeiffer } 2882afdb09SMichael Pfeiffer 2954730332SMichael Pfeiffer static void testDrawChar(BView *view, BRect frame) 3054730332SMichael Pfeiffer { 3154730332SMichael Pfeiffer view->MovePenTo(frame.left, frame.bottom - 5); 3254730332SMichael Pfeiffer view->DrawChar('A'); 3354730332SMichael Pfeiffer 3454730332SMichael Pfeiffer view->DrawChar('B', BPoint(frame.left + 20, frame.bottom - 5)); 3554730332SMichael Pfeiffer } 3654730332SMichael Pfeiffer 3754730332SMichael Pfeiffer static void testDrawString(BView *view, BRect frame) 3882afdb09SMichael Pfeiffer { 3982afdb09SMichael Pfeiffer BFont font; 4082afdb09SMichael Pfeiffer view->GetFont(&font); 4182afdb09SMichael Pfeiffer font_height height; 4282afdb09SMichael Pfeiffer font.GetHeight(&height); 4382afdb09SMichael Pfeiffer float baseline = frame.bottom - height.descent; 4482afdb09SMichael Pfeiffer // draw base line 4554730332SMichael Pfeiffer view->SetHighColor(kGreen); 4682afdb09SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1)); 4782afdb09SMichael Pfeiffer 4854730332SMichael Pfeiffer view->SetHighColor(kBlack); 4982afdb09SMichael Pfeiffer view->DrawString("Haiku [ÖÜÄöüä]", BPoint(frame.left, baseline)); 5082afdb09SMichael Pfeiffer } 5182afdb09SMichael Pfeiffer 5254730332SMichael Pfeiffer static void testDrawStringWithLength(BView *view, BRect frame) 5354730332SMichael Pfeiffer { 5454730332SMichael Pfeiffer BFont font; 5554730332SMichael Pfeiffer view->GetFont(&font); 5654730332SMichael Pfeiffer font_height height; 5754730332SMichael Pfeiffer font.GetHeight(&height); 5854730332SMichael Pfeiffer float baseline = frame.bottom - height.descent; 5954730332SMichael Pfeiffer // draw base line 6054730332SMichael Pfeiffer view->SetHighColor(kGreen); 6154730332SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1)); 6254730332SMichael Pfeiffer 6354730332SMichael Pfeiffer view->SetHighColor(kBlack); 6454730332SMichael Pfeiffer view->DrawString("Haiku [ÖÜÄöüä]", 13, BPoint(frame.left, baseline)); 6554730332SMichael Pfeiffer } 6654730332SMichael Pfeiffer 6754730332SMichael Pfeiffer static void testFillArc(BView *view, BRect frame) 6882afdb09SMichael Pfeiffer { 6982afdb09SMichael Pfeiffer frame.InsetBy(2, 2); 7054730332SMichael Pfeiffer view->FillArc(frame, 45, 180); 7154730332SMichael Pfeiffer } 7254730332SMichael Pfeiffer 7354730332SMichael Pfeiffer static void testStrokeArc(BView *view, BRect frame) 7454730332SMichael Pfeiffer { 7554730332SMichael Pfeiffer frame.InsetBy(2, 2); 7654730332SMichael Pfeiffer view->StrokeArc(frame, 45, 180); 7754730332SMichael Pfeiffer } 7854730332SMichael Pfeiffer 7954730332SMichael Pfeiffer static void testFillBezier(BView *view, BRect frame) 8054730332SMichael Pfeiffer { 8154730332SMichael Pfeiffer frame.InsetBy(2, 2); 8254730332SMichael Pfeiffer BPoint points[4]; 8354730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 8454730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 8554730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 8654730332SMichael Pfeiffer points[3] = BPoint(frame.right, frame.top); 8754730332SMichael Pfeiffer view->FillBezier(points); 8854730332SMichael Pfeiffer } 8954730332SMichael Pfeiffer 9054730332SMichael Pfeiffer static void testStrokeBezier(BView *view, BRect frame) 9154730332SMichael Pfeiffer { 9254730332SMichael Pfeiffer frame.InsetBy(2, 2); 9354730332SMichael Pfeiffer BPoint points[4]; 9454730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 9554730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 9654730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 9754730332SMichael Pfeiffer points[3] = BPoint(frame.right, frame.top); 9854730332SMichael Pfeiffer view->StrokeBezier(points); 9954730332SMichael Pfeiffer } 10054730332SMichael Pfeiffer 10154730332SMichael Pfeiffer static void testFillEllipse(BView *view, BRect frame) 10254730332SMichael Pfeiffer { 10354730332SMichael Pfeiffer frame.InsetBy(2, 2); 10454730332SMichael Pfeiffer view->FillEllipse(frame); 10554730332SMichael Pfeiffer 10654730332SMichael Pfeiffer view->SetHighColor(kRed); 10754730332SMichael Pfeiffer float r = frame.Width() / 3; 10854730332SMichael Pfeiffer float s = frame.Height() / 4; 10954730332SMichael Pfeiffer view->FillEllipse(centerPoint(frame), r, s); 11054730332SMichael Pfeiffer } 11154730332SMichael Pfeiffer 11254730332SMichael Pfeiffer static void testStrokeEllipse(BView *view, BRect frame) 11354730332SMichael Pfeiffer { 11454730332SMichael Pfeiffer frame.InsetBy(2, 2); 11554730332SMichael Pfeiffer view->StrokeEllipse(frame); 11654730332SMichael Pfeiffer 11754730332SMichael Pfeiffer view->SetHighColor(kRed); 11854730332SMichael Pfeiffer float r = frame.Width() / 3; 11954730332SMichael Pfeiffer float s = frame.Height() / 4; 12054730332SMichael Pfeiffer view->StrokeEllipse(centerPoint(frame), r, s); 12154730332SMichael Pfeiffer } 12254730332SMichael Pfeiffer 12354730332SMichael Pfeiffer static void testFillPolygon(BView *view, BRect frame) 12454730332SMichael Pfeiffer { 12554730332SMichael Pfeiffer frame.InsetBy(2, 2); 12654730332SMichael Pfeiffer 12754730332SMichael Pfeiffer BPoint points[4]; 12854730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.top); 12954730332SMichael Pfeiffer points[1] = BPoint(frame.right, frame.bottom); 13054730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.top); 13154730332SMichael Pfeiffer points[3] = BPoint(frame.left, frame.bottom); 13254730332SMichael Pfeiffer 13354730332SMichael Pfeiffer view->FillPolygon(points, 4); 13454730332SMichael Pfeiffer } 13554730332SMichael Pfeiffer 13654730332SMichael Pfeiffer static void testStrokePolygon(BView *view, BRect frame) 13754730332SMichael Pfeiffer { 13854730332SMichael Pfeiffer frame.InsetBy(2, 2); 13954730332SMichael Pfeiffer 14054730332SMichael Pfeiffer BPoint points[4]; 14154730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.top); 14254730332SMichael Pfeiffer points[1] = BPoint(frame.right, frame.bottom); 14354730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.top); 14454730332SMichael Pfeiffer points[3] = BPoint(frame.left, frame.bottom); 14554730332SMichael Pfeiffer 14654730332SMichael Pfeiffer view->StrokePolygon(points, 4); 14754730332SMichael Pfeiffer } 14854730332SMichael Pfeiffer 14954730332SMichael Pfeiffer static void testFillRect(BView *view, BRect frame) 15054730332SMichael Pfeiffer { 15154730332SMichael Pfeiffer frame.InsetBy(2, 2); 15282afdb09SMichael Pfeiffer view->FillRect(frame); 15382afdb09SMichael Pfeiffer } 15482afdb09SMichael Pfeiffer 15554730332SMichael Pfeiffer static void testStrokeRect(BView *view, BRect frame) 15682afdb09SMichael Pfeiffer { 15782afdb09SMichael Pfeiffer frame.InsetBy(2, 2); 15882afdb09SMichael Pfeiffer view->StrokeRect(frame); 15982afdb09SMichael Pfeiffer } 16082afdb09SMichael Pfeiffer 16154730332SMichael Pfeiffer static void testFillRegion(BView *view, BRect frame) 16282afdb09SMichael Pfeiffer { 16354730332SMichael Pfeiffer frame.InsetBy(2, 2); 16454730332SMichael Pfeiffer BRegion region(frame); 16554730332SMichael Pfeiffer frame.InsetBy(2, 2); 16654730332SMichael Pfeiffer region.Exclude(frame); 16754730332SMichael Pfeiffer view->FillRegion(®ion); 16854730332SMichael Pfeiffer } 16954730332SMichael Pfeiffer 17054730332SMichael Pfeiffer static void testFillRoundRect(BView *view, BRect frame) 17154730332SMichael Pfeiffer { 17254730332SMichael Pfeiffer frame.InsetBy(2, 2); 17354730332SMichael Pfeiffer view->FillRoundRect(frame, 5, 3); 17454730332SMichael Pfeiffer } 17554730332SMichael Pfeiffer 17654730332SMichael Pfeiffer static void testStrokeRoundRect(BView *view, BRect frame) 17754730332SMichael Pfeiffer { 17854730332SMichael Pfeiffer frame.InsetBy(2, 2); 17954730332SMichael Pfeiffer view->StrokeRoundRect(frame, 5, 3); 18054730332SMichael Pfeiffer } 18154730332SMichael Pfeiffer 18254730332SMichael Pfeiffer static void testFillTriangle(BView *view, BRect frame) 18354730332SMichael Pfeiffer { 18454730332SMichael Pfeiffer frame.InsetBy(2, 2); 18554730332SMichael Pfeiffer BPoint points[3]; 18654730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 18754730332SMichael Pfeiffer points[1] = BPoint(centerPoint(frame).x, frame.top); 18854730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.bottom); 18954730332SMichael Pfeiffer view->FillTriangle(points[0], points[1], points[2]); 19054730332SMichael Pfeiffer } 19154730332SMichael Pfeiffer 19254730332SMichael Pfeiffer static void testStrokeTriangle(BView *view, BRect frame) 19354730332SMichael Pfeiffer { 19454730332SMichael Pfeiffer frame.InsetBy(2, 2); 19554730332SMichael Pfeiffer BPoint points[3]; 19654730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 19754730332SMichael Pfeiffer points[1] = BPoint(centerPoint(frame).x, frame.top); 19854730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.bottom); 19954730332SMichael Pfeiffer view->StrokeTriangle(points[0], points[1], points[2]); 20054730332SMichael Pfeiffer } 20154730332SMichael Pfeiffer 20254730332SMichael Pfeiffer static void testStrokeLine(BView *view, BRect frame) 20354730332SMichael Pfeiffer { 20454730332SMichael Pfeiffer frame.InsetBy(2, 2); 20554730332SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top)); 20654730332SMichael Pfeiffer 20754730332SMichael Pfeiffer frame.top += 2; 20854730332SMichael Pfeiffer frame.bottom -= 2; 20982afdb09SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.bottom)); 21054730332SMichael Pfeiffer 21154730332SMichael Pfeiffer frame.bottom += 2;; 21254730332SMichael Pfeiffer frame.top = frame.bottom; 21354730332SMichael Pfeiffer view->StrokeLine(BPoint(frame.right, frame.top), BPoint(frame.left, frame.top)); 21482afdb09SMichael Pfeiffer } 21582afdb09SMichael Pfeiffer 21654730332SMichael Pfeiffer static void testFillShape(BView *view, BRect frame) 21782afdb09SMichael Pfeiffer { 21854730332SMichael Pfeiffer frame.InsetBy(2, 2); 21954730332SMichael Pfeiffer BShape shape; 22054730332SMichael Pfeiffer shape.MoveTo(BPoint(frame.left, frame.bottom)); 22154730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.top)); 22254730332SMichael Pfeiffer shape.LineTo(BPoint(frame.left, frame.top)); 22354730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.bottom)); 22454730332SMichael Pfeiffer view->FillShape(&shape); 22582afdb09SMichael Pfeiffer } 22682afdb09SMichael Pfeiffer 22754730332SMichael Pfeiffer static void testStrokeShape(BView *view, BRect frame) 22854730332SMichael Pfeiffer { 22954730332SMichael Pfeiffer frame.InsetBy(2, 2); 23054730332SMichael Pfeiffer BShape shape; 23154730332SMichael Pfeiffer shape.MoveTo(BPoint(frame.left, frame.bottom)); 23254730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.top)); 23354730332SMichael Pfeiffer shape.LineTo(BPoint(frame.left, frame.top)); 23454730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.bottom)); 23554730332SMichael Pfeiffer view->StrokeShape(&shape); 23654730332SMichael Pfeiffer } 23754730332SMichael Pfeiffer 23854730332SMichael Pfeiffer static void testRecordPicture(BView *view, BRect frame) 23982afdb09SMichael Pfeiffer { 24082afdb09SMichael Pfeiffer BPicture *picture = new BPicture(); 24182afdb09SMichael Pfeiffer view->BeginPicture(picture); 24282afdb09SMichael Pfeiffer view->FillRect(frame); 24382afdb09SMichael Pfeiffer view->EndPicture(); 24482afdb09SMichael Pfeiffer delete picture; 24582afdb09SMichael Pfeiffer } 24682afdb09SMichael Pfeiffer 24754730332SMichael Pfeiffer static void testRecordAndPlayPicture(BView *view, BRect frame) 24882afdb09SMichael Pfeiffer { 24982afdb09SMichael Pfeiffer BPicture *picture = new BPicture(); 25082afdb09SMichael Pfeiffer view->BeginPicture(picture); 25182afdb09SMichael Pfeiffer frame.InsetBy(2, 2); 25282afdb09SMichael Pfeiffer view->FillRect(frame); 25382afdb09SMichael Pfeiffer view->EndPicture(); 25482afdb09SMichael Pfeiffer view->DrawPicture(picture); 25582afdb09SMichael Pfeiffer delete picture; 25682afdb09SMichael Pfeiffer } 25782afdb09SMichael Pfeiffer 25854730332SMichael Pfeiffer static void testRecordAndPlayPictureWithOffset(BView *view, BRect frame) 25982afdb09SMichael Pfeiffer { 26082afdb09SMichael Pfeiffer BPicture *picture = new BPicture(); 26182afdb09SMichael Pfeiffer view->BeginPicture(picture); 26282afdb09SMichael Pfeiffer frame.InsetBy(frame.Width() / 4, frame.Height() / 4); 26382afdb09SMichael Pfeiffer frame.OffsetTo(0, 0); 26482afdb09SMichael Pfeiffer view->FillRect(frame); 26582afdb09SMichael Pfeiffer view->EndPicture(); 26682afdb09SMichael Pfeiffer 26782afdb09SMichael Pfeiffer view->DrawPicture(picture, BPoint(10, 10)); 26882afdb09SMichael Pfeiffer // color of picture should not change 26954730332SMichael Pfeiffer view->SetLowColor(kGreen); 27054730332SMichael Pfeiffer view->SetLowColor(kRed); 27182afdb09SMichael Pfeiffer view->DrawPicture(picture, BPoint(0, 0)); 27282afdb09SMichael Pfeiffer delete picture; 27382afdb09SMichael Pfeiffer } 27482afdb09SMichael Pfeiffer 27554730332SMichael Pfeiffer static void testAppendToPicture(BView *view, BRect frame) 27654730332SMichael Pfeiffer { 27754730332SMichael Pfeiffer frame.InsetBy(2, 2); 27854730332SMichael Pfeiffer view->BeginPicture(new BPicture()); 27954730332SMichael Pfeiffer view->FillRect(frame); 28054730332SMichael Pfeiffer BPicture* picture = view->EndPicture(); 28154730332SMichael Pfeiffer if (picture == NULL) 28254730332SMichael Pfeiffer return; 28354730332SMichael Pfeiffer 28454730332SMichael Pfeiffer frame.InsetBy(2, 2); 28554730332SMichael Pfeiffer view->AppendToPicture(picture); 28654730332SMichael Pfeiffer view->SetHighColor(kRed); 28754730332SMichael Pfeiffer view->FillRect(frame); 28854730332SMichael Pfeiffer if (view->EndPicture() != picture) 28954730332SMichael Pfeiffer return; 29054730332SMichael Pfeiffer 29154730332SMichael Pfeiffer view->DrawPicture(picture); 29254730332SMichael Pfeiffer delete picture; 29354730332SMichael Pfeiffer } 29454730332SMichael Pfeiffer 29554730332SMichael Pfeiffer static void testLineArray(BView *view, BRect frame) 29654730332SMichael Pfeiffer { 29754730332SMichael Pfeiffer frame.InsetBy(2, 2); 29854730332SMichael Pfeiffer view->BeginLineArray(3); 29954730332SMichael Pfeiffer view->AddLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top), kBlack); 30054730332SMichael Pfeiffer 30154730332SMichael Pfeiffer frame.top += 2; 30254730332SMichael Pfeiffer frame.bottom -= 2; 30354730332SMichael Pfeiffer view->AddLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.bottom), kRed); 30454730332SMichael Pfeiffer 30554730332SMichael Pfeiffer frame.bottom += 2;; 30654730332SMichael Pfeiffer frame.top = frame.bottom; 30754730332SMichael Pfeiffer view->AddLine(BPoint(frame.right, frame.top), BPoint(frame.left, frame.top), kGreen); 30854730332SMichael Pfeiffer 30954730332SMichael Pfeiffer view->EndLineArray(); 31054730332SMichael Pfeiffer } 31154730332SMichael Pfeiffer 31254730332SMichael Pfeiffer static void testInvertRect(BView *view, BRect frame) 31354730332SMichael Pfeiffer { 31454730332SMichael Pfeiffer frame.InsetBy(2, 2); 31554730332SMichael Pfeiffer view->InvertRect(frame); 31654730332SMichael Pfeiffer } 31754730332SMichael Pfeiffer 31854730332SMichael Pfeiffer static void testBitmap(BView *view, BRect frame) { 31982afdb09SMichael Pfeiffer BBitmap bitmap(frame, B_RGBA32); 32082afdb09SMichael Pfeiffer for (int32 y = 0; y < bitmap.Bounds().IntegerHeight(); y ++) { 32182afdb09SMichael Pfeiffer for (int32 x = 0; x < bitmap.Bounds().IntegerWidth(); x ++) { 32282afdb09SMichael Pfeiffer char *pixel = (char*)bitmap.Bits(); 32382afdb09SMichael Pfeiffer pixel += bitmap.BytesPerRow() * y + 4 * x; 32482afdb09SMichael Pfeiffer // fill with blue 32582afdb09SMichael Pfeiffer pixel[0] = 255; 32682afdb09SMichael Pfeiffer pixel[1] = 0; 32782afdb09SMichael Pfeiffer pixel[2] = 0; 32882afdb09SMichael Pfeiffer pixel[3] = 255; 32982afdb09SMichael Pfeiffer } 33082afdb09SMichael Pfeiffer } 33182afdb09SMichael Pfeiffer view->DrawBitmap(&bitmap, BPoint(0, 0)); 33282afdb09SMichael Pfeiffer } 33382afdb09SMichael Pfeiffer 334c43f0163SMichael Pfeiffer static void testConstrainClippingRegion(BView *view, BRect frame) 335c43f0163SMichael Pfeiffer { 336c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 337c43f0163SMichael Pfeiffer // draw background 338c43f0163SMichael Pfeiffer view->SetHighColor(kRed); 339c43f0163SMichael Pfeiffer view->FillRect(frame); 340c43f0163SMichael Pfeiffer 341c43f0163SMichael Pfeiffer frame.InsetBy(1, 1); 342c43f0163SMichael Pfeiffer BRegion region(frame); 343c43f0163SMichael Pfeiffer BRect r(frame); 344c43f0163SMichael Pfeiffer r.InsetBy(r.IntegerWidth() / 4, r.IntegerHeight() / 4); 345c43f0163SMichael Pfeiffer region.Exclude(r); 346c43f0163SMichael Pfeiffer view->ConstrainClippingRegion(®ion); 347c43f0163SMichael Pfeiffer 348c43f0163SMichael Pfeiffer frame.InsetBy(-1, -1); 349c43f0163SMichael Pfeiffer view->SetHighColor(kBlack); 350c43f0163SMichael Pfeiffer view->FillRect(frame); 351c43f0163SMichael Pfeiffer // a filled black rectangle with a red one pixel border 352c43f0163SMichael Pfeiffer // and inside a red rectangle should be drawn. 353c43f0163SMichael Pfeiffer } 354c43f0163SMichael Pfeiffer 355c43f0163SMichael Pfeiffer static void testClipToPicture(BView *view, BRect frame) 356c43f0163SMichael Pfeiffer { 357c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 358c43f0163SMichael Pfeiffer view->BeginPicture(new BPicture()); 359c43f0163SMichael Pfeiffer view->FillEllipse(frame); 360c43f0163SMichael Pfeiffer BPicture *picture = view->EndPicture(); 361c43f0163SMichael Pfeiffer if (picture == NULL) 362c43f0163SMichael Pfeiffer return; 363c43f0163SMichael Pfeiffer 364c43f0163SMichael Pfeiffer view->ClipToPicture(picture); 365c43f0163SMichael Pfeiffer delete picture; 366c43f0163SMichael Pfeiffer 367c43f0163SMichael Pfeiffer view->FillRect(frame); 368c43f0163SMichael Pfeiffer // black ellipse should be drawn 369c43f0163SMichael Pfeiffer } 370c43f0163SMichael Pfeiffer 371c43f0163SMichael Pfeiffer static void testClipToInversePicture(BView *view, BRect frame) 372c43f0163SMichael Pfeiffer { 373c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 374c43f0163SMichael Pfeiffer 375c43f0163SMichael Pfeiffer view->BeginPicture(new BPicture()); 376c43f0163SMichael Pfeiffer view->FillEllipse(frame); 377c43f0163SMichael Pfeiffer BPicture *picture = view->EndPicture(); 378c43f0163SMichael Pfeiffer if (picture == NULL) 379c43f0163SMichael Pfeiffer return; 380c43f0163SMichael Pfeiffer 381c43f0163SMichael Pfeiffer view->ClipToInversePicture(picture); 382c43f0163SMichael Pfeiffer delete picture; 383c43f0163SMichael Pfeiffer 384c43f0163SMichael Pfeiffer view->FillRect(frame); 385c43f0163SMichael Pfeiffer // white ellipse inside a black rectangle 386c43f0163SMichael Pfeiffer } 387c43f0163SMichael Pfeiffer 388c43f0163SMichael Pfeiffer static void testSetPenSize(BView *view, BRect frame) 389c43f0163SMichael Pfeiffer { 390c43f0163SMichael Pfeiffer frame.InsetBy(8, 2); 391c43f0163SMichael Pfeiffer float x = centerPoint(frame).x; 392c43f0163SMichael Pfeiffer 393c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top)); 394c43f0163SMichael Pfeiffer 395c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 396c43f0163SMichael Pfeiffer view->SetPenSize(1); 397c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 398c43f0163SMichael Pfeiffer view->SetPenSize(0); 399c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 400c43f0163SMichael Pfeiffer 401c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 402c43f0163SMichael Pfeiffer view->SetPenSize(1); 403c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 404c43f0163SMichael Pfeiffer view->SetPenSize(2); 405c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 406c43f0163SMichael Pfeiffer 407c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 408c43f0163SMichael Pfeiffer view->SetPenSize(1); 409c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 410c43f0163SMichael Pfeiffer view->SetPenSize(3); 411c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 412c43f0163SMichael Pfeiffer 413c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 414c43f0163SMichael Pfeiffer view->SetPenSize(1); 415c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 416c43f0163SMichael Pfeiffer view->SetPenSize(4); 417c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 418c43f0163SMichael Pfeiffer } 419c43f0163SMichael Pfeiffer 420c43f0163SMichael Pfeiffer static void testSetPenSize2(BView *view, BRect frame) 421c43f0163SMichael Pfeiffer { 422c43f0163SMichael Pfeiffer // test if pen size is scaled too 423c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 424c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 425c43f0163SMichael Pfeiffer view->SetPenSize(4); 426c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top)); 427c43f0163SMichael Pfeiffer view->SetScale(0.5); 428c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left + 2, frame.bottom), BPoint(frame.right + 2, frame.bottom)); 429c43f0163SMichael Pfeiffer 430c43f0163SMichael Pfeiffer // black line from left to right, 4 pixel size 431c43f0163SMichael Pfeiffer // below black line with half the length of the first one 432c43f0163SMichael Pfeiffer // and 2 pixel size 433c43f0163SMichael Pfeiffer } 434c43f0163SMichael Pfeiffer 435c43f0163SMichael Pfeiffer static void testPattern(BView *view, BRect frame) 436c43f0163SMichael Pfeiffer { 437c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 438c43f0163SMichael Pfeiffer int x = frame.IntegerWidth() / 3; 439c43f0163SMichael Pfeiffer frame.right = frame.left + x - 2; 440c43f0163SMichael Pfeiffer // -2 for an empty pixel row between 441c43f0163SMichael Pfeiffer // filled rectangles 442c43f0163SMichael Pfeiffer 443c43f0163SMichael Pfeiffer view->SetLowColor(kGreen); 444c43f0163SMichael Pfeiffer view->SetHighColor(kRed); 445c43f0163SMichael Pfeiffer 446c43f0163SMichael Pfeiffer view->FillRect(frame, B_SOLID_HIGH); 447c43f0163SMichael Pfeiffer 448c43f0163SMichael Pfeiffer frame.OffsetBy(x, 0); 449c43f0163SMichael Pfeiffer view->FillRect(frame, B_MIXED_COLORS); 450c43f0163SMichael Pfeiffer 451c43f0163SMichael Pfeiffer frame.OffsetBy(x, 0); 452c43f0163SMichael Pfeiffer view->FillRect(frame, B_SOLID_LOW); 453c43f0163SMichael Pfeiffer } 454c43f0163SMichael Pfeiffer 455c43f0163SMichael Pfeiffer static void testSetOrigin(BView *view, BRect frame) 456c43f0163SMichael Pfeiffer { 457c43f0163SMichael Pfeiffer BPoint origin = view->Origin(); 458c43f0163SMichael Pfeiffer BPoint center = centerPoint(frame); 459c43f0163SMichael Pfeiffer view->SetOrigin(center); 460c43f0163SMichael Pfeiffer 461c43f0163SMichael Pfeiffer BRect r(0, 0, center.x, center.y); 462c43f0163SMichael Pfeiffer view->SetHighColor(kBlue); 463c43f0163SMichael Pfeiffer view->FillRect(r); 464c43f0163SMichael Pfeiffer 465c43f0163SMichael Pfeiffer view->SetOrigin(origin); 466c43f0163SMichael Pfeiffer view->SetHighColor(kRed); 467c43f0163SMichael Pfeiffer view->FillRect(r); 468c43f0163SMichael Pfeiffer 469c43f0163SMichael Pfeiffer // red rectangle in left, top corner 470c43f0163SMichael Pfeiffer // blue rectangle in right, bottom corner 471c43f0163SMichael Pfeiffer // the red rectangle overwrites the 472c43f0163SMichael Pfeiffer // top, left pixel of the blue rectangle 473c43f0163SMichael Pfeiffer } 474c43f0163SMichael Pfeiffer 475c43f0163SMichael Pfeiffer static void testSetOrigin2(BView *view, BRect frame) 476c43f0163SMichael Pfeiffer { 477c43f0163SMichael Pfeiffer BPoint center = centerPoint(frame); 478c43f0163SMichael Pfeiffer BRect r(0, 0, center.x, center.y); 479c43f0163SMichael Pfeiffer view->SetOrigin(center); 480c43f0163SMichael Pfeiffer view->PushState(); 481c43f0163SMichael Pfeiffer view->SetOrigin(BPoint(-center.x, 0)); 482c43f0163SMichael Pfeiffer view->FillRect(r); 483c43f0163SMichael Pfeiffer view->PopState(); 484c43f0163SMichael Pfeiffer // black rectangle in left, bottom corner 485c43f0163SMichael Pfeiffer } 486c43f0163SMichael Pfeiffer 487c43f0163SMichael Pfeiffer static void testSetScale(BView *view, BRect frame) 488c43f0163SMichael Pfeiffer { 489c43f0163SMichael Pfeiffer view->SetScale(0.5); 490c43f0163SMichael Pfeiffer view->FillRect(frame); 491c43f0163SMichael Pfeiffer // black rectangle in left, top corner 492c43f0163SMichael Pfeiffer } 493c43f0163SMichael Pfeiffer 494c43f0163SMichael Pfeiffer static void testSetScale2(BView *view, BRect frame) 495c43f0163SMichael Pfeiffer { 496c43f0163SMichael Pfeiffer view->SetScale(0.5); 497c43f0163SMichael Pfeiffer view->PushState(); 498c43f0163SMichael Pfeiffer view->SetScale(0.5); 499c43f0163SMichael Pfeiffer view->FillRect(frame); 500c43f0163SMichael Pfeiffer view->PopState(); 501c43f0163SMichael Pfeiffer // black rectangle in left, top corner 502c43f0163SMichael Pfeiffer // with half the size of the rectangle 503c43f0163SMichael Pfeiffer // from test testSetScaling 504c43f0163SMichael Pfeiffer } 505c43f0163SMichael Pfeiffer 506c43f0163SMichael Pfeiffer static void testSetScale3(BView *view, BRect frame) 507c43f0163SMichael Pfeiffer { 508c43f0163SMichael Pfeiffer view->SetScale(0.5); 509c43f0163SMichael Pfeiffer view->PushState(); 510c43f0163SMichael Pfeiffer // if the second scale value differs slightly 511c43f0163SMichael Pfeiffer // the bug under BeOS R5 in testSetScale2 512c43f0163SMichael Pfeiffer // does not occur 513c43f0163SMichael Pfeiffer view->SetScale(0.5000001); 514c43f0163SMichael Pfeiffer view->FillRect(frame); 515c43f0163SMichael Pfeiffer view->PopState(); 516c43f0163SMichael Pfeiffer // black rectangle in left, top corner 517c43f0163SMichael Pfeiffer // with half the size of the rectangle 518c43f0163SMichael Pfeiffer // from test testSetScaling 519c43f0163SMichael Pfeiffer } 520c43f0163SMichael Pfeiffer 521c9c4a80aSMichael Pfeiffer static void testSetOriginAndScale(BView *view, BRect frame) 522c9c4a80aSMichael Pfeiffer { 523c9c4a80aSMichael Pfeiffer frame.InsetBy(2, 2); 524c9c4a80aSMichael Pfeiffer BPoint center = centerPoint(frame); 525c9c4a80aSMichael Pfeiffer 526c9c4a80aSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 527c9c4a80aSMichael Pfeiffer view->SetOrigin(center); 528c9c4a80aSMichael Pfeiffer view->FillRect(r); 529c9c4a80aSMichael Pfeiffer 530c9c4a80aSMichael Pfeiffer view->SetScale(0.5); 531c9c4a80aSMichael Pfeiffer view->SetHighColor(kRed); 532c9c4a80aSMichael Pfeiffer view->FillRect(r); 533c9c4a80aSMichael Pfeiffer } 534c9c4a80aSMichael Pfeiffer 535*4b05331dSMichael Pfeiffer static void testSetOriginAndScale2(BView *view, BRect frame) 536*4b05331dSMichael Pfeiffer { 537*4b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 538*4b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 539*4b05331dSMichael Pfeiffer 540*4b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 541*4b05331dSMichael Pfeiffer view->SetOrigin(center); 542*4b05331dSMichael Pfeiffer view->FillRect(r); 543*4b05331dSMichael Pfeiffer 544*4b05331dSMichael Pfeiffer view->SetScale(0.5); 545*4b05331dSMichael Pfeiffer view->SetHighColor(kRed); 546*4b05331dSMichael Pfeiffer view->FillRect(r); 547*4b05331dSMichael Pfeiffer 548*4b05331dSMichael Pfeiffer view->SetOrigin(0, 0); 549*4b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 550*4b05331dSMichael Pfeiffer view->FillRect(r); 551*4b05331dSMichael Pfeiffer } 552*4b05331dSMichael Pfeiffer 553*4b05331dSMichael Pfeiffer static void testSetOriginAndScale3(BView *view, BRect frame) 554*4b05331dSMichael Pfeiffer { 555*4b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 556*4b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 557*4b05331dSMichael Pfeiffer 558*4b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 559*4b05331dSMichael Pfeiffer view->SetOrigin(center); 560*4b05331dSMichael Pfeiffer view->FillRect(r); 561*4b05331dSMichael Pfeiffer 562*4b05331dSMichael Pfeiffer view->SetScale(0.5); 563*4b05331dSMichael Pfeiffer view->SetHighColor(kRed); 564*4b05331dSMichael Pfeiffer view->FillRect(r); 565*4b05331dSMichael Pfeiffer 566*4b05331dSMichael Pfeiffer view->SetScale(0.25); 567*4b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 568*4b05331dSMichael Pfeiffer view->FillRect(r); 569*4b05331dSMichael Pfeiffer } 570*4b05331dSMichael Pfeiffer 571*4b05331dSMichael Pfeiffer static void testSetOriginAndScale4(BView *view, BRect frame) 572*4b05331dSMichael Pfeiffer { 573*4b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 574*4b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 575*4b05331dSMichael Pfeiffer 576*4b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 577*4b05331dSMichael Pfeiffer view->SetOrigin(center); 578*4b05331dSMichael Pfeiffer view->FillRect(r); 579*4b05331dSMichael Pfeiffer 580*4b05331dSMichael Pfeiffer view->SetScale(0.5); 581*4b05331dSMichael Pfeiffer view->SetHighColor(kRed); 582*4b05331dSMichael Pfeiffer view->FillRect(r); 583*4b05331dSMichael Pfeiffer 584*4b05331dSMichael Pfeiffer view->PushState(); 585*4b05331dSMichael Pfeiffer // 586*4b05331dSMichael Pfeiffer view->SetOrigin(center.x+1, center.y); 587*4b05331dSMichael Pfeiffer // +1 to work around BeOS bug 588*4b05331dSMichael Pfeiffer // where setting the origin has no 589*4b05331dSMichael Pfeiffer // effect if it is the same as 590*4b05331dSMichael Pfeiffer // the previous value althou 591*4b05331dSMichael Pfeiffer // it is from the "outer" coordinate 592*4b05331dSMichael Pfeiffer // system 593*4b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 594*4b05331dSMichael Pfeiffer view->FillRect(r); 595*4b05331dSMichael Pfeiffer view->PopState(); 596*4b05331dSMichael Pfeiffer } 597*4b05331dSMichael Pfeiffer 598*4b05331dSMichael Pfeiffer static void testSetOriginAndScale5(BView *view, BRect frame) 599*4b05331dSMichael Pfeiffer { 600*4b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 601*4b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 602*4b05331dSMichael Pfeiffer 603*4b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 604*4b05331dSMichael Pfeiffer view->SetOrigin(center); 605*4b05331dSMichael Pfeiffer view->FillRect(r); 606*4b05331dSMichael Pfeiffer 607*4b05331dSMichael Pfeiffer view->SetScale(0.5); 608*4b05331dSMichael Pfeiffer view->SetHighColor(kRed); 609*4b05331dSMichael Pfeiffer view->FillRect(r); 610*4b05331dSMichael Pfeiffer 611*4b05331dSMichael Pfeiffer view->PushState(); 612*4b05331dSMichael Pfeiffer view->SetScale(0.75); 613*4b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 614*4b05331dSMichael Pfeiffer view->FillRect(r); 615*4b05331dSMichael Pfeiffer view->PopState(); 616*4b05331dSMichael Pfeiffer } 617*4b05331dSMichael Pfeiffer 618c43f0163SMichael Pfeiffer static void testSetFontSize(BView *view, BRect frame) 619c43f0163SMichael Pfeiffer { 620c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 621c43f0163SMichael Pfeiffer int size = frame.IntegerHeight() / 3; 622c43f0163SMichael Pfeiffer 623c43f0163SMichael Pfeiffer frame.OffsetBy(0, size); 624c43f0163SMichael Pfeiffer view->MovePenTo(BPoint(frame.left, frame.top)); 625c43f0163SMichael Pfeiffer view->SetFontSize(size); 626c43f0163SMichael Pfeiffer view->DrawString("Haiku"); 627c43f0163SMichael Pfeiffer 628c43f0163SMichael Pfeiffer size *= 2; 629c43f0163SMichael Pfeiffer frame.OffsetBy(0, size); 630c43f0163SMichael Pfeiffer view->MovePenTo(BPoint(frame.left, frame.top)); 631c43f0163SMichael Pfeiffer view->SetFontSize(size); 632c43f0163SMichael Pfeiffer view->DrawString("Haiku"); 633c43f0163SMichael Pfeiffer } 634c43f0163SMichael Pfeiffer 635c43f0163SMichael Pfeiffer // TODO 636c43f0163SMichael Pfeiffer // - drawing mode 637c43f0163SMichael Pfeiffer // - blending mode 638c43f0163SMichael Pfeiffer // - line mode 639c43f0163SMichael Pfeiffer // - push/pop state 640c43f0163SMichael Pfeiffer // - move pen 641c43f0163SMichael Pfeiffer // - set font 642c43f0163SMichael Pfeiffer 643c43f0163SMichael Pfeiffer 64482afdb09SMichael Pfeiffer TestCase gTestCases[] = { 64554730332SMichael Pfeiffer { "Test No Operation", testNoOp }, 64654730332SMichael Pfeiffer { "Test DrawChar", testDrawChar }, 64782afdb09SMichael Pfeiffer { "Test Draw String", testDrawString }, 64854730332SMichael Pfeiffer { "Test Draw String With Length", testDrawStringWithLength }, 64954730332SMichael Pfeiffer { "Test FillArc", testFillArc }, 65054730332SMichael Pfeiffer { "Test StrokeArc", testStrokeArc }, 651c43f0163SMichael Pfeiffer // testFillBezier fails under BeOS because the 652c43f0163SMichael Pfeiffer // direct draw version is not correct 65354730332SMichael Pfeiffer { "Test FillBezier", testFillBezier }, 65454730332SMichael Pfeiffer { "Test StrokeBezier", testStrokeBezier }, 65554730332SMichael Pfeiffer { "Test FillEllipse", testFillEllipse }, 65654730332SMichael Pfeiffer { "Test StrokeEllipse", testStrokeEllipse }, 65754730332SMichael Pfeiffer { "Test FillPolygon", testFillPolygon }, 65854730332SMichael Pfeiffer { "Test StrokePolygon", testStrokePolygon }, 65954730332SMichael Pfeiffer { "Test FillRect", testFillRect }, 66054730332SMichael Pfeiffer { "Test StrokeRect", testStrokeRect }, 66154730332SMichael Pfeiffer { "Test FillRegion", testFillRegion }, 66254730332SMichael Pfeiffer { "Test FillRoundRect", testFillRoundRect }, 66354730332SMichael Pfeiffer { "Test StrokeRoundRect", testStrokeRoundRect }, 66454730332SMichael Pfeiffer { "Test FillTriangle", testFillTriangle }, 66554730332SMichael Pfeiffer { "Test StrokeTriangle", testStrokeTriangle }, 66654730332SMichael Pfeiffer { "Test StrokeLine", testStrokeLine }, 66754730332SMichael Pfeiffer { "Test FillShape", testFillShape }, 66854730332SMichael Pfeiffer { "Test StrokeShape", testStrokeShape }, 66982afdb09SMichael Pfeiffer { "Test Record Picture", testRecordPicture }, 67082afdb09SMichael Pfeiffer { "Test Record And Play Picture", testRecordAndPlayPicture }, 67182afdb09SMichael Pfeiffer { "Test Record And Play Picture With Offset", testRecordAndPlayPictureWithOffset }, 67254730332SMichael Pfeiffer { "Test AppendToPicture", testAppendToPicture }, 67354730332SMichael Pfeiffer { "Test LineArray", testLineArray }, 67454730332SMichael Pfeiffer { "Test InvertRect", testInvertRect }, 67554730332SMichael Pfeiffer { "Test Bitmap", testBitmap }, 676c43f0163SMichael Pfeiffer { "Test ConstrainClippingRegion", testConstrainClippingRegion }, 677c43f0163SMichael Pfeiffer { "Test ClipToPicture", testClipToPicture }, 678c43f0163SMichael Pfeiffer { "Test ClipToInversePicture", testClipToInversePicture }, 679c43f0163SMichael Pfeiffer { "Test SetPenSize", testSetPenSize }, 680c43f0163SMichael Pfeiffer { "Test SetPenSize2", testSetPenSize2 }, 681c43f0163SMichael Pfeiffer { "Test Pattern", testPattern }, 682c43f0163SMichael Pfeiffer { "Test SetOrigin", testSetOrigin }, 683c43f0163SMichael Pfeiffer { "Test SetOrigin2", testSetOrigin2 }, 684c43f0163SMichael Pfeiffer { "Test SetScale", testSetScale }, 685c43f0163SMichael Pfeiffer // testSetScale2 fails under BeOS. The picture versions of the 686c43f0163SMichael Pfeiffer // rectangle are twice as large as the direct draw version 687c43f0163SMichael Pfeiffer { "Test SetScale2*", testSetScale2 }, 688c43f0163SMichael Pfeiffer { "Test SetScale3", testSetScale3 }, 689c9c4a80aSMichael Pfeiffer { "Test SetOriginAndScale", testSetOriginAndScale }, 690*4b05331dSMichael Pfeiffer { "Test SetOriginAndScale2", testSetOriginAndScale2 }, 691*4b05331dSMichael Pfeiffer { "Test SetOriginAndScale3", testSetOriginAndScale3 }, 692*4b05331dSMichael Pfeiffer { "Test SetOriginAndScale4", testSetOriginAndScale4 }, 693*4b05331dSMichael Pfeiffer { "Test SetOriginAndScale5", testSetOriginAndScale5 }, 694c43f0163SMichael Pfeiffer { "Test SetFontSize", testSetFontSize }, 69582afdb09SMichael Pfeiffer { NULL, NULL } 69682afdb09SMichael Pfeiffer }; 69762c7fd0fSMichael Pfeiffer 698