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 11abf565b1SStefano Ceccherini #include <GradientLinear.h> 12abf565b1SStefano Ceccherini #include <GradientRadial.h> 13abf565b1SStefano Ceccherini #include <GradientRadialFocus.h> 14abf565b1SStefano Ceccherini #include <GradientDiamond.h> 15abf565b1SStefano Ceccherini #include <GradientConic.h> 16abf565b1SStefano Ceccherini 178247141fSMichael Pfeiffer #include <stdio.h> 188247141fSMichael Pfeiffer 1954730332SMichael Pfeiffer static const rgb_color kBlack = {0, 0, 0}; 2054730332SMichael Pfeiffer static const rgb_color kWhite = {255, 255, 255}; 2154730332SMichael Pfeiffer static const rgb_color kRed = {255, 0, 0}; 2254730332SMichael Pfeiffer static const rgb_color kGreen = {0, 255, 0}; 2354730332SMichael Pfeiffer static const rgb_color kBlue = {0, 0, 255}; 2454730332SMichael Pfeiffer 2554730332SMichael Pfeiffer static BPoint centerPoint(BRect rect) 2654730332SMichael Pfeiffer { 2754730332SMichael Pfeiffer int x = (int)(rect.left + rect.IntegerWidth() / 2); 2854730332SMichael Pfeiffer int y = (int)(rect.top + rect.IntegerHeight() / 2); 2954730332SMichael Pfeiffer return BPoint(x, y); 3054730332SMichael Pfeiffer } 3154730332SMichael Pfeiffer 3254730332SMichael Pfeiffer static void testNoOp(BView *view, BRect frame) 3382afdb09SMichael Pfeiffer { 3482afdb09SMichael Pfeiffer // no op 3582afdb09SMichael Pfeiffer } 3682afdb09SMichael Pfeiffer 3754730332SMichael Pfeiffer static void testDrawChar(BView *view, BRect frame) 3854730332SMichael Pfeiffer { 3954730332SMichael Pfeiffer view->MovePenTo(frame.left, frame.bottom - 5); 4054730332SMichael Pfeiffer view->DrawChar('A'); 4154730332SMichael Pfeiffer 4254730332SMichael Pfeiffer view->DrawChar('B', BPoint(frame.left + 20, frame.bottom - 5)); 4354730332SMichael Pfeiffer } 4454730332SMichael Pfeiffer 4554730332SMichael Pfeiffer static void testDrawString(BView *view, BRect frame) 4682afdb09SMichael Pfeiffer { 4782afdb09SMichael Pfeiffer BFont font; 4882afdb09SMichael Pfeiffer view->GetFont(&font); 4982afdb09SMichael Pfeiffer font_height height; 5082afdb09SMichael Pfeiffer font.GetHeight(&height); 5182afdb09SMichael Pfeiffer float baseline = frame.bottom - height.descent; 5282afdb09SMichael Pfeiffer // draw base line 5354730332SMichael Pfeiffer view->SetHighColor(kGreen); 5482afdb09SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1)); 5582afdb09SMichael Pfeiffer 5654730332SMichael Pfeiffer view->SetHighColor(kBlack); 5782afdb09SMichael Pfeiffer view->DrawString("Haiku [ÖÜÄöüä]", BPoint(frame.left, baseline)); 5882afdb09SMichael Pfeiffer } 5982afdb09SMichael Pfeiffer 6054730332SMichael Pfeiffer static void testDrawStringWithLength(BView *view, BRect frame) 6154730332SMichael Pfeiffer { 6254730332SMichael Pfeiffer BFont font; 6354730332SMichael Pfeiffer view->GetFont(&font); 6454730332SMichael Pfeiffer font_height height; 6554730332SMichael Pfeiffer font.GetHeight(&height); 6654730332SMichael Pfeiffer float baseline = frame.bottom - height.descent; 6754730332SMichael Pfeiffer // draw base line 6854730332SMichael Pfeiffer view->SetHighColor(kGreen); 6954730332SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1)); 7054730332SMichael Pfeiffer 7154730332SMichael Pfeiffer view->SetHighColor(kBlack); 7254730332SMichael Pfeiffer view->DrawString("Haiku [ÖÜÄöüä]", 13, BPoint(frame.left, baseline)); 7354730332SMichael Pfeiffer } 7454730332SMichael Pfeiffer 75abf565b1SStefano Ceccherini 76abf565b1SStefano Ceccherini static void testDrawStringWithOffsets(BView* view, BRect frame) 77abf565b1SStefano Ceccherini { 78abf565b1SStefano Ceccherini BFont font; 79abf565b1SStefano Ceccherini view->GetFont(&font); 80abf565b1SStefano Ceccherini font_height height; 81abf565b1SStefano Ceccherini font.GetHeight(&height); 82abf565b1SStefano Ceccherini float baseline = frame.bottom - height.descent; 83abf565b1SStefano Ceccherini // draw base line 84abf565b1SStefano Ceccherini view->SetHighColor(kGreen); 85abf565b1SStefano Ceccherini view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1)); 86abf565b1SStefano Ceccherini 87abf565b1SStefano Ceccherini view->SetHighColor(kBlack); 88abf565b1SStefano Ceccherini const BPoint pointArray[] = { BPoint(frame.left, baseline) }; 89abf565b1SStefano Ceccherini view->DrawString("Haiku [ÖÜÄöüä]", pointArray, sizeof(pointArray) / sizeof(pointArray[0])); 90abf565b1SStefano Ceccherini } 91abf565b1SStefano Ceccherini 92abf565b1SStefano Ceccherini 9354730332SMichael Pfeiffer static void testFillArc(BView *view, BRect frame) 9482afdb09SMichael Pfeiffer { 9582afdb09SMichael Pfeiffer frame.InsetBy(2, 2); 9654730332SMichael Pfeiffer view->FillArc(frame, 45, 180); 9754730332SMichael Pfeiffer } 9854730332SMichael Pfeiffer 9954730332SMichael Pfeiffer static void testStrokeArc(BView *view, BRect frame) 10054730332SMichael Pfeiffer { 10154730332SMichael Pfeiffer frame.InsetBy(2, 2); 10254730332SMichael Pfeiffer view->StrokeArc(frame, 45, 180); 10354730332SMichael Pfeiffer } 10454730332SMichael Pfeiffer 10554730332SMichael Pfeiffer static void testFillBezier(BView *view, BRect frame) 10654730332SMichael Pfeiffer { 10754730332SMichael Pfeiffer frame.InsetBy(2, 2); 10854730332SMichael Pfeiffer BPoint points[4]; 10954730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 11054730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 11154730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 11254730332SMichael Pfeiffer points[3] = BPoint(frame.right, frame.top); 11354730332SMichael Pfeiffer view->FillBezier(points); 11454730332SMichael Pfeiffer } 11554730332SMichael Pfeiffer 11654730332SMichael Pfeiffer static void testStrokeBezier(BView *view, BRect frame) 11754730332SMichael Pfeiffer { 11854730332SMichael Pfeiffer frame.InsetBy(2, 2); 11954730332SMichael Pfeiffer BPoint points[4]; 12054730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 12154730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 12254730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 12354730332SMichael Pfeiffer points[3] = BPoint(frame.right, frame.top); 12454730332SMichael Pfeiffer view->StrokeBezier(points); 12554730332SMichael Pfeiffer } 12654730332SMichael Pfeiffer 12754730332SMichael Pfeiffer static void testFillEllipse(BView *view, BRect frame) 12854730332SMichael Pfeiffer { 12954730332SMichael Pfeiffer frame.InsetBy(2, 2); 13054730332SMichael Pfeiffer view->FillEllipse(frame); 13154730332SMichael Pfeiffer 13254730332SMichael Pfeiffer view->SetHighColor(kRed); 13354730332SMichael Pfeiffer float r = frame.Width() / 3; 13454730332SMichael Pfeiffer float s = frame.Height() / 4; 13554730332SMichael Pfeiffer view->FillEllipse(centerPoint(frame), r, s); 13654730332SMichael Pfeiffer } 13754730332SMichael Pfeiffer 13854730332SMichael Pfeiffer static void testStrokeEllipse(BView *view, BRect frame) 13954730332SMichael Pfeiffer { 14054730332SMichael Pfeiffer frame.InsetBy(2, 2); 14154730332SMichael Pfeiffer view->StrokeEllipse(frame); 14254730332SMichael Pfeiffer 14354730332SMichael Pfeiffer view->SetHighColor(kRed); 14454730332SMichael Pfeiffer float r = frame.Width() / 3; 14554730332SMichael Pfeiffer float s = frame.Height() / 4; 14654730332SMichael Pfeiffer view->StrokeEllipse(centerPoint(frame), r, s); 14754730332SMichael Pfeiffer } 14854730332SMichael Pfeiffer 14954730332SMichael Pfeiffer static void testFillPolygon(BView *view, BRect frame) 15054730332SMichael Pfeiffer { 15154730332SMichael Pfeiffer frame.InsetBy(2, 2); 15254730332SMichael Pfeiffer 15354730332SMichael Pfeiffer BPoint points[4]; 15454730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.top); 15554730332SMichael Pfeiffer points[1] = BPoint(frame.right, frame.bottom); 15654730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.top); 15754730332SMichael Pfeiffer points[3] = BPoint(frame.left, frame.bottom); 15854730332SMichael Pfeiffer 15954730332SMichael Pfeiffer view->FillPolygon(points, 4); 16054730332SMichael Pfeiffer } 16154730332SMichael Pfeiffer 16254730332SMichael Pfeiffer static void testStrokePolygon(BView *view, BRect frame) 16354730332SMichael Pfeiffer { 16454730332SMichael Pfeiffer frame.InsetBy(2, 2); 16554730332SMichael Pfeiffer 16654730332SMichael Pfeiffer BPoint points[4]; 16754730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.top); 16854730332SMichael Pfeiffer points[1] = BPoint(frame.right, frame.bottom); 16954730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.top); 17054730332SMichael Pfeiffer points[3] = BPoint(frame.left, frame.bottom); 17154730332SMichael Pfeiffer 17254730332SMichael Pfeiffer view->StrokePolygon(points, 4); 17354730332SMichael Pfeiffer } 17454730332SMichael Pfeiffer 17554730332SMichael Pfeiffer static void testFillRect(BView *view, BRect frame) 17654730332SMichael Pfeiffer { 17754730332SMichael Pfeiffer frame.InsetBy(2, 2); 17882afdb09SMichael Pfeiffer view->FillRect(frame); 17982afdb09SMichael Pfeiffer } 18082afdb09SMichael Pfeiffer 181abf565b1SStefano Ceccherini static void testFillRectGradientLinear(BView* view, BRect frame) 182abf565b1SStefano Ceccherini { 183abf565b1SStefano Ceccherini BGradientLinear gradient(0, 0, frame.right, frame.bottom); 184abf565b1SStefano Ceccherini gradient.AddColor(kRed, 0); 185abf565b1SStefano Ceccherini gradient.AddColor(kBlue, 255); 186abf565b1SStefano Ceccherini frame.InsetBy(2, 2); 187abf565b1SStefano Ceccherini view->FillRect(frame, gradient); 188abf565b1SStefano Ceccherini } 189abf565b1SStefano Ceccherini 190abf565b1SStefano Ceccherini static void testFillRectGradientRadial(BView* view, BRect frame) 191abf565b1SStefano Ceccherini { 192abf565b1SStefano Ceccherini BGradientRadial gradient(10, 10, 10); 193abf565b1SStefano Ceccherini gradient.AddColor(kRed, 0); 194abf565b1SStefano Ceccherini gradient.AddColor(kBlue, 255); 195abf565b1SStefano Ceccherini frame.InsetBy(2, 2); 196abf565b1SStefano Ceccherini view->FillRect(frame, gradient); 197abf565b1SStefano Ceccherini } 198abf565b1SStefano Ceccherini 199abf565b1SStefano Ceccherini static void testFillRectGradientRadialFocus(BView* view, BRect frame) 200abf565b1SStefano Ceccherini { 201abf565b1SStefano Ceccherini BGradientRadialFocus gradient(0, 0, 10, 10, 5); 202abf565b1SStefano Ceccherini gradient.AddColor(kRed, 0); 203abf565b1SStefano Ceccherini gradient.AddColor(kBlue, 255); 204abf565b1SStefano Ceccherini frame.InsetBy(2, 2); 205abf565b1SStefano Ceccherini view->FillRect(frame, gradient); 206abf565b1SStefano Ceccherini } 207abf565b1SStefano Ceccherini 208abf565b1SStefano Ceccherini static void testFillRectGradientDiamond(BView* view, BRect frame) 209abf565b1SStefano Ceccherini { 210abf565b1SStefano Ceccherini BGradientDiamond gradient(0, 10); 211abf565b1SStefano Ceccherini gradient.AddColor(kRed, 0); 212abf565b1SStefano Ceccherini gradient.AddColor(kBlue, 255); 213abf565b1SStefano Ceccherini frame.InsetBy(2, 2); 214abf565b1SStefano Ceccherini view->FillRect(frame, gradient); 215abf565b1SStefano Ceccherini } 216abf565b1SStefano Ceccherini 217abf565b1SStefano Ceccherini static void testFillRectGradientConic(BView* view, BRect frame) 218abf565b1SStefano Ceccherini { 219abf565b1SStefano Ceccherini BGradientConic gradient(0, 0, 10); 220abf565b1SStefano Ceccherini gradient.AddColor(kRed, 0); 221abf565b1SStefano Ceccherini gradient.AddColor(kBlue, 255); 222abf565b1SStefano Ceccherini frame.InsetBy(2, 2); 223abf565b1SStefano Ceccherini view->FillRect(frame, gradient); 224abf565b1SStefano Ceccherini } 225abf565b1SStefano Ceccherini 22654730332SMichael Pfeiffer static void testStrokeRect(BView *view, BRect frame) 22782afdb09SMichael Pfeiffer { 22882afdb09SMichael Pfeiffer frame.InsetBy(2, 2); 22982afdb09SMichael Pfeiffer view->StrokeRect(frame); 23082afdb09SMichael Pfeiffer } 23182afdb09SMichael Pfeiffer 23254730332SMichael Pfeiffer static void testFillRegion(BView *view, BRect frame) 23382afdb09SMichael Pfeiffer { 23454730332SMichael Pfeiffer frame.InsetBy(2, 2); 23554730332SMichael Pfeiffer BRegion region(frame); 236*b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 23754730332SMichael Pfeiffer region.Exclude(frame); 23854730332SMichael Pfeiffer view->FillRegion(®ion); 23954730332SMichael Pfeiffer } 24054730332SMichael Pfeiffer 241*b8c65995SStefano Ceccherini static void testFillRegionGradientLinear(BView* view, BRect frame) 242*b8c65995SStefano Ceccherini { 243*b8c65995SStefano Ceccherini BGradientLinear gradient(0, 0, frame.right, frame.bottom); 244*b8c65995SStefano Ceccherini gradient.AddColor(kRed, 0); 245*b8c65995SStefano Ceccherini gradient.AddColor(kBlue, 255); 246*b8c65995SStefano Ceccherini frame.InsetBy(2, 2); 247*b8c65995SStefano Ceccherini BRegion region(frame); 248*b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 249*b8c65995SStefano Ceccherini region.Exclude(frame); 250*b8c65995SStefano Ceccherini view->FillRegion(®ion, gradient); 251*b8c65995SStefano Ceccherini } 252*b8c65995SStefano Ceccherini 253*b8c65995SStefano Ceccherini static void testFillRegionGradientRadial(BView* view, BRect frame) 254*b8c65995SStefano Ceccherini { 255*b8c65995SStefano Ceccherini BGradientRadial gradient(10, 10, 10); 256*b8c65995SStefano Ceccherini gradient.AddColor(kRed, 0); 257*b8c65995SStefano Ceccherini gradient.AddColor(kBlue, 255); 258*b8c65995SStefano Ceccherini frame.InsetBy(2, 2); 259*b8c65995SStefano Ceccherini BRegion region(frame); 260*b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 261*b8c65995SStefano Ceccherini region.Exclude(frame); 262*b8c65995SStefano Ceccherini view->FillRegion(®ion, gradient); 263*b8c65995SStefano Ceccherini } 264*b8c65995SStefano Ceccherini 265*b8c65995SStefano Ceccherini static void testFillRegionGradientRadialFocus(BView* view, BRect frame) 266*b8c65995SStefano Ceccherini { 267*b8c65995SStefano Ceccherini BGradientRadialFocus gradient(0, 0, 10, 10, 5); 268*b8c65995SStefano Ceccherini gradient.AddColor(kRed, 0); 269*b8c65995SStefano Ceccherini gradient.AddColor(kBlue, 255); 270*b8c65995SStefano Ceccherini frame.InsetBy(2, 2); 271*b8c65995SStefano Ceccherini BRegion region(frame); 272*b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 273*b8c65995SStefano Ceccherini region.Exclude(frame); 274*b8c65995SStefano Ceccherini view->FillRegion(®ion, gradient); 275*b8c65995SStefano Ceccherini } 276*b8c65995SStefano Ceccherini 277*b8c65995SStefano Ceccherini static void testFillRegionGradientDiamond(BView* view, BRect frame) 278*b8c65995SStefano Ceccherini { 279*b8c65995SStefano Ceccherini BGradientDiamond gradient(0, 10); 280*b8c65995SStefano Ceccherini gradient.AddColor(kRed, 0); 281*b8c65995SStefano Ceccherini gradient.AddColor(kBlue, 255); 282*b8c65995SStefano Ceccherini frame.InsetBy(2, 2); 283*b8c65995SStefano Ceccherini BRegion region(frame); 284*b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 285*b8c65995SStefano Ceccherini region.Exclude(frame); 286*b8c65995SStefano Ceccherini view->FillRegion(®ion, gradient); 287*b8c65995SStefano Ceccherini } 288*b8c65995SStefano Ceccherini 289*b8c65995SStefano Ceccherini static void testFillRegionGradientConic(BView* view, BRect frame) 290*b8c65995SStefano Ceccherini { 291*b8c65995SStefano Ceccherini BGradientConic gradient(0, 0, 10); 292*b8c65995SStefano Ceccherini gradient.AddColor(kRed, 0); 293*b8c65995SStefano Ceccherini gradient.AddColor(kBlue, 255); 294*b8c65995SStefano Ceccherini frame.InsetBy(2, 2); 295*b8c65995SStefano Ceccherini BRegion region(frame); 296*b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 297*b8c65995SStefano Ceccherini region.Exclude(frame); 298*b8c65995SStefano Ceccherini view->FillRegion(®ion, gradient); 299*b8c65995SStefano Ceccherini } 300*b8c65995SStefano Ceccherini 30154730332SMichael Pfeiffer static void testFillRoundRect(BView *view, BRect frame) 30254730332SMichael Pfeiffer { 30354730332SMichael Pfeiffer frame.InsetBy(2, 2); 30454730332SMichael Pfeiffer view->FillRoundRect(frame, 5, 3); 30554730332SMichael Pfeiffer } 30654730332SMichael Pfeiffer 30754730332SMichael Pfeiffer static void testStrokeRoundRect(BView *view, BRect frame) 30854730332SMichael Pfeiffer { 30954730332SMichael Pfeiffer frame.InsetBy(2, 2); 31054730332SMichael Pfeiffer view->StrokeRoundRect(frame, 5, 3); 31154730332SMichael Pfeiffer } 31254730332SMichael Pfeiffer 31354730332SMichael Pfeiffer static void testFillTriangle(BView *view, BRect frame) 31454730332SMichael Pfeiffer { 31554730332SMichael Pfeiffer frame.InsetBy(2, 2); 31654730332SMichael Pfeiffer BPoint points[3]; 31754730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 31854730332SMichael Pfeiffer points[1] = BPoint(centerPoint(frame).x, frame.top); 31954730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.bottom); 32054730332SMichael Pfeiffer view->FillTriangle(points[0], points[1], points[2]); 32154730332SMichael Pfeiffer } 32254730332SMichael Pfeiffer 32354730332SMichael Pfeiffer static void testStrokeTriangle(BView *view, BRect frame) 32454730332SMichael Pfeiffer { 32554730332SMichael Pfeiffer frame.InsetBy(2, 2); 32654730332SMichael Pfeiffer BPoint points[3]; 32754730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 32854730332SMichael Pfeiffer points[1] = BPoint(centerPoint(frame).x, frame.top); 32954730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.bottom); 33054730332SMichael Pfeiffer view->StrokeTriangle(points[0], points[1], points[2]); 33154730332SMichael Pfeiffer } 33254730332SMichael Pfeiffer 33354730332SMichael Pfeiffer static void testStrokeLine(BView *view, BRect frame) 33454730332SMichael Pfeiffer { 33554730332SMichael Pfeiffer frame.InsetBy(2, 2); 33654730332SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top)); 33754730332SMichael Pfeiffer 33854730332SMichael Pfeiffer frame.top += 2; 33954730332SMichael Pfeiffer frame.bottom -= 2; 34082afdb09SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.bottom)); 34154730332SMichael Pfeiffer 34254730332SMichael Pfeiffer frame.bottom += 2;; 34354730332SMichael Pfeiffer frame.top = frame.bottom; 34454730332SMichael Pfeiffer view->StrokeLine(BPoint(frame.right, frame.top), BPoint(frame.left, frame.top)); 34582afdb09SMichael Pfeiffer } 34682afdb09SMichael Pfeiffer 34754730332SMichael Pfeiffer static void testFillShape(BView *view, BRect frame) 34882afdb09SMichael Pfeiffer { 34954730332SMichael Pfeiffer frame.InsetBy(2, 2); 35054730332SMichael Pfeiffer BShape shape; 35154730332SMichael Pfeiffer shape.MoveTo(BPoint(frame.left, frame.bottom)); 35254730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.top)); 35354730332SMichael Pfeiffer shape.LineTo(BPoint(frame.left, frame.top)); 35454730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.bottom)); 35554730332SMichael Pfeiffer view->FillShape(&shape); 35682afdb09SMichael Pfeiffer } 35782afdb09SMichael Pfeiffer 35854730332SMichael Pfeiffer static void testStrokeShape(BView *view, BRect frame) 35954730332SMichael Pfeiffer { 36054730332SMichael Pfeiffer frame.InsetBy(2, 2); 36154730332SMichael Pfeiffer BShape shape; 36254730332SMichael Pfeiffer shape.MoveTo(BPoint(frame.left, frame.bottom)); 36354730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.top)); 36454730332SMichael Pfeiffer shape.LineTo(BPoint(frame.left, frame.top)); 36554730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.bottom)); 36654730332SMichael Pfeiffer view->StrokeShape(&shape); 36754730332SMichael Pfeiffer } 36854730332SMichael Pfeiffer 36954730332SMichael Pfeiffer static void testRecordPicture(BView *view, BRect frame) 37082afdb09SMichael Pfeiffer { 37182afdb09SMichael Pfeiffer BPicture *picture = new BPicture(); 37282afdb09SMichael Pfeiffer view->BeginPicture(picture); 37382afdb09SMichael Pfeiffer view->FillRect(frame); 37482afdb09SMichael Pfeiffer view->EndPicture(); 37582afdb09SMichael Pfeiffer delete picture; 37682afdb09SMichael Pfeiffer } 37782afdb09SMichael Pfeiffer 37854730332SMichael Pfeiffer static void testRecordAndPlayPicture(BView *view, BRect frame) 37982afdb09SMichael Pfeiffer { 38082afdb09SMichael Pfeiffer BPicture *picture = new BPicture(); 38182afdb09SMichael Pfeiffer view->BeginPicture(picture); 38282afdb09SMichael Pfeiffer frame.InsetBy(2, 2); 38382afdb09SMichael Pfeiffer view->FillRect(frame); 38482afdb09SMichael Pfeiffer view->EndPicture(); 38582afdb09SMichael Pfeiffer view->DrawPicture(picture); 38682afdb09SMichael Pfeiffer delete picture; 38782afdb09SMichael Pfeiffer } 38882afdb09SMichael Pfeiffer 38954730332SMichael Pfeiffer static void testRecordAndPlayPictureWithOffset(BView *view, BRect frame) 39082afdb09SMichael Pfeiffer { 39182afdb09SMichael Pfeiffer BPicture *picture = new BPicture(); 39282afdb09SMichael Pfeiffer view->BeginPicture(picture); 39382afdb09SMichael Pfeiffer frame.InsetBy(frame.Width() / 4, frame.Height() / 4); 39482afdb09SMichael Pfeiffer frame.OffsetTo(0, 0); 39582afdb09SMichael Pfeiffer view->FillRect(frame); 39682afdb09SMichael Pfeiffer view->EndPicture(); 39782afdb09SMichael Pfeiffer 39882afdb09SMichael Pfeiffer view->DrawPicture(picture, BPoint(10, 10)); 39982afdb09SMichael Pfeiffer // color of picture should not change 40054730332SMichael Pfeiffer view->SetLowColor(kGreen); 40154730332SMichael Pfeiffer view->SetLowColor(kRed); 40282afdb09SMichael Pfeiffer view->DrawPicture(picture, BPoint(0, 0)); 40382afdb09SMichael Pfeiffer delete picture; 40482afdb09SMichael Pfeiffer } 40582afdb09SMichael Pfeiffer 40654730332SMichael Pfeiffer static void testAppendToPicture(BView *view, BRect frame) 40754730332SMichael Pfeiffer { 40854730332SMichael Pfeiffer frame.InsetBy(2, 2); 40954730332SMichael Pfeiffer view->BeginPicture(new BPicture()); 41054730332SMichael Pfeiffer view->FillRect(frame); 41154730332SMichael Pfeiffer BPicture* picture = view->EndPicture(); 41254730332SMichael Pfeiffer if (picture == NULL) 41354730332SMichael Pfeiffer return; 41454730332SMichael Pfeiffer 41554730332SMichael Pfeiffer frame.InsetBy(2, 2); 41654730332SMichael Pfeiffer view->AppendToPicture(picture); 41754730332SMichael Pfeiffer view->SetHighColor(kRed); 41854730332SMichael Pfeiffer view->FillRect(frame); 41954730332SMichael Pfeiffer if (view->EndPicture() != picture) 42054730332SMichael Pfeiffer return; 42154730332SMichael Pfeiffer 42254730332SMichael Pfeiffer view->DrawPicture(picture); 42354730332SMichael Pfeiffer delete picture; 42454730332SMichael Pfeiffer } 42554730332SMichael Pfeiffer 4268247141fSMichael Pfeiffer static void testDrawScaledPicture(BView* view, BRect frame) 4278247141fSMichael Pfeiffer { 4288247141fSMichael Pfeiffer view->BeginPicture(new BPicture()); 4298247141fSMichael Pfeiffer view->FillRect(BRect(0, 0, 15, 15)); 4308247141fSMichael Pfeiffer BPicture* picture = view->EndPicture(); 4318247141fSMichael Pfeiffer 4328247141fSMichael Pfeiffer // first unscaled at left, top 4338247141fSMichael Pfeiffer view->DrawPicture(picture, BPoint(2, 2)); 4348247141fSMichael Pfeiffer 4358247141fSMichael Pfeiffer // draw scaled at middle top 4368247141fSMichael Pfeiffer view->SetScale(0.5); 4378247141fSMichael Pfeiffer // the drawing offset must be scaled too! 438ff973abcSMichael Pfeiffer view->DrawPicture(picture, BPoint(frame.Width(), 4)); 4398247141fSMichael Pfeiffer 4408247141fSMichael Pfeiffer delete picture; 4418247141fSMichael Pfeiffer } 4428247141fSMichael Pfeiffer 44354730332SMichael Pfeiffer static void testLineArray(BView *view, BRect frame) 44454730332SMichael Pfeiffer { 44554730332SMichael Pfeiffer frame.InsetBy(2, 2); 44654730332SMichael Pfeiffer view->BeginLineArray(3); 44754730332SMichael Pfeiffer view->AddLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top), kBlack); 44854730332SMichael Pfeiffer 44954730332SMichael Pfeiffer frame.top += 2; 45054730332SMichael Pfeiffer frame.bottom -= 2; 45154730332SMichael Pfeiffer view->AddLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.bottom), kRed); 45254730332SMichael Pfeiffer 45354730332SMichael Pfeiffer frame.bottom += 2;; 45454730332SMichael Pfeiffer frame.top = frame.bottom; 45554730332SMichael Pfeiffer view->AddLine(BPoint(frame.right, frame.top), BPoint(frame.left, frame.top), kGreen); 45654730332SMichael Pfeiffer 45754730332SMichael Pfeiffer view->EndLineArray(); 45854730332SMichael Pfeiffer } 45954730332SMichael Pfeiffer 46054730332SMichael Pfeiffer static void testInvertRect(BView *view, BRect frame) 46154730332SMichael Pfeiffer { 46254730332SMichael Pfeiffer frame.InsetBy(2, 2); 46354730332SMichael Pfeiffer view->InvertRect(frame); 46454730332SMichael Pfeiffer } 46554730332SMichael Pfeiffer 4667cf26360SStefano Ceccherini static void testInvertRectSetDrawingMode(BView *view, BRect frame) 4677cf26360SStefano Ceccherini { 4687cf26360SStefano Ceccherini view->SetDrawingMode(B_OP_ALPHA); 4697cf26360SStefano Ceccherini view->SetHighColor(128, 128, 128, 128); 4707cf26360SStefano Ceccherini frame.InsetBy(2, 2); 4717cf26360SStefano Ceccherini view->InvertRect(frame); 4727cf26360SStefano Ceccherini frame.InsetBy(10, 10); 4737cf26360SStefano Ceccherini view->FillRect(frame, B_SOLID_HIGH); 4747cf26360SStefano Ceccherini } 4757cf26360SStefano Ceccherini 4764f422578SMichael Pfeiffer static bool isBorder(int32 x, int32 y, int32 width, int32 height) { 4774f422578SMichael Pfeiffer return x == 0 || y == 0 || x == width - 1 || y == height - 1; 4784f422578SMichael Pfeiffer } 4794f422578SMichael Pfeiffer 4804f422578SMichael Pfeiffer static void fillBitmap(BBitmap &bitmap) { 4814f422578SMichael Pfeiffer int32 height = bitmap.Bounds().IntegerHeight()+1; 4824f422578SMichael Pfeiffer int32 width = bitmap.Bounds().IntegerWidth()+1; 4834f422578SMichael Pfeiffer for (int32 y = 0; y < height; y ++) { 4844f422578SMichael Pfeiffer for (int32 x = 0; x < width; x ++) { 48582afdb09SMichael Pfeiffer char *pixel = (char*)bitmap.Bits(); 48682afdb09SMichael Pfeiffer pixel += bitmap.BytesPerRow() * y + 4 * x; 4874f422578SMichael Pfeiffer if (isBorder(x, y, width, height)) { 4884f422578SMichael Pfeiffer // fill with green 4894f422578SMichael Pfeiffer pixel[0] = 255; 4904f422578SMichael Pfeiffer pixel[1] = 0; 4914f422578SMichael Pfeiffer pixel[2] = 255; 4924f422578SMichael Pfeiffer pixel[3] = 0; 4934f422578SMichael Pfeiffer } else { 49482afdb09SMichael Pfeiffer // fill with blue 49582afdb09SMichael Pfeiffer pixel[0] = 255; 49682afdb09SMichael Pfeiffer pixel[1] = 0; 49782afdb09SMichael Pfeiffer pixel[2] = 0; 49882afdb09SMichael Pfeiffer pixel[3] = 255; 49982afdb09SMichael Pfeiffer } 50082afdb09SMichael Pfeiffer } 5014f422578SMichael Pfeiffer } 5024f422578SMichael Pfeiffer } 5034f422578SMichael Pfeiffer 5044f422578SMichael Pfeiffer static void testDrawBitmap(BView *view, BRect frame) { 5054f422578SMichael Pfeiffer BBitmap bitmap(frame, B_RGBA32); 5064f422578SMichael Pfeiffer fillBitmap(bitmap); 50782afdb09SMichael Pfeiffer view->DrawBitmap(&bitmap, BPoint(0, 0)); 50882afdb09SMichael Pfeiffer } 50982afdb09SMichael Pfeiffer 5104f422578SMichael Pfeiffer static void testDrawBitmapAtPoint(BView *view, BRect frame) { 5114f422578SMichael Pfeiffer frame.InsetBy(2, 2); 5124f422578SMichael Pfeiffer 5134f422578SMichael Pfeiffer BRect bounds(frame); 5144f422578SMichael Pfeiffer bounds.OffsetTo(0, 0); 5154f422578SMichael Pfeiffer bounds.right /= 2; 5164f422578SMichael Pfeiffer bounds.bottom /= 2; 5174f422578SMichael Pfeiffer 5184f422578SMichael Pfeiffer BBitmap bitmap(bounds, B_RGBA32); 5194f422578SMichael Pfeiffer fillBitmap(bitmap); 5204f422578SMichael Pfeiffer view->DrawBitmap(&bitmap, centerPoint(frame)); 5214f422578SMichael Pfeiffer } 5224f422578SMichael Pfeiffer 5234f422578SMichael Pfeiffer static void testDrawBitmapAtRect(BView *view, BRect frame) { 5244f422578SMichael Pfeiffer BRect bounds(frame); 5254f422578SMichael Pfeiffer BBitmap bitmap(bounds, B_RGBA32); 5264f422578SMichael Pfeiffer fillBitmap(bitmap); 5274f422578SMichael Pfeiffer frame.InsetBy(2, 2); 5284f422578SMichael Pfeiffer view->DrawBitmap(&bitmap, frame); 5294f422578SMichael Pfeiffer } 5304f422578SMichael Pfeiffer 5314f422578SMichael Pfeiffer static void testDrawLargeBitmap(BView *view, BRect frame) { 5324f422578SMichael Pfeiffer BRect bounds(frame); 5334f422578SMichael Pfeiffer bounds.OffsetTo(0, 0); 5348247141fSMichael Pfeiffer bounds.right *= 4; 5358247141fSMichael Pfeiffer bounds.bottom *= 4; 5364f422578SMichael Pfeiffer BBitmap bitmap(bounds, B_RGBA32); 5374f422578SMichael Pfeiffer fillBitmap(bitmap); 5384f422578SMichael Pfeiffer frame.InsetBy(2, 2); 5394f422578SMichael Pfeiffer view->DrawBitmap(&bitmap, frame); 5404f422578SMichael Pfeiffer } 5414f422578SMichael Pfeiffer 542c43f0163SMichael Pfeiffer static void testConstrainClippingRegion(BView *view, BRect frame) 543c43f0163SMichael Pfeiffer { 544c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 545c43f0163SMichael Pfeiffer // draw background 546c43f0163SMichael Pfeiffer view->SetHighColor(kRed); 547c43f0163SMichael Pfeiffer view->FillRect(frame); 548c43f0163SMichael Pfeiffer 549c43f0163SMichael Pfeiffer frame.InsetBy(1, 1); 550c43f0163SMichael Pfeiffer BRegion region(frame); 551c43f0163SMichael Pfeiffer BRect r(frame); 552c43f0163SMichael Pfeiffer r.InsetBy(r.IntegerWidth() / 4, r.IntegerHeight() / 4); 553c43f0163SMichael Pfeiffer region.Exclude(r); 554c43f0163SMichael Pfeiffer view->ConstrainClippingRegion(®ion); 555c43f0163SMichael Pfeiffer 556c43f0163SMichael Pfeiffer frame.InsetBy(-1, -1); 557c43f0163SMichael Pfeiffer view->SetHighColor(kBlack); 558c43f0163SMichael Pfeiffer view->FillRect(frame); 559c43f0163SMichael Pfeiffer // a filled black rectangle with a red one pixel border 560c43f0163SMichael Pfeiffer // and inside a red rectangle should be drawn. 561c43f0163SMichael Pfeiffer } 562c43f0163SMichael Pfeiffer 563c43f0163SMichael Pfeiffer static void testClipToPicture(BView *view, BRect frame) 564c43f0163SMichael Pfeiffer { 565c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 566c43f0163SMichael Pfeiffer view->BeginPicture(new BPicture()); 567c43f0163SMichael Pfeiffer view->FillEllipse(frame); 568c43f0163SMichael Pfeiffer BPicture *picture = view->EndPicture(); 569c43f0163SMichael Pfeiffer if (picture == NULL) 570c43f0163SMichael Pfeiffer return; 571c43f0163SMichael Pfeiffer 572c43f0163SMichael Pfeiffer view->ClipToPicture(picture); 573c43f0163SMichael Pfeiffer delete picture; 574c43f0163SMichael Pfeiffer 575c43f0163SMichael Pfeiffer view->FillRect(frame); 576c43f0163SMichael Pfeiffer // black ellipse should be drawn 577c43f0163SMichael Pfeiffer } 578c43f0163SMichael Pfeiffer 579c43f0163SMichael Pfeiffer static void testClipToInversePicture(BView *view, BRect frame) 580c43f0163SMichael Pfeiffer { 581c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 582c43f0163SMichael Pfeiffer 583c43f0163SMichael Pfeiffer view->BeginPicture(new BPicture()); 584c43f0163SMichael Pfeiffer view->FillEllipse(frame); 585c43f0163SMichael Pfeiffer BPicture *picture = view->EndPicture(); 586c43f0163SMichael Pfeiffer if (picture == NULL) 587c43f0163SMichael Pfeiffer return; 588c43f0163SMichael Pfeiffer 589c43f0163SMichael Pfeiffer view->ClipToInversePicture(picture); 590c43f0163SMichael Pfeiffer delete picture; 591c43f0163SMichael Pfeiffer 592c43f0163SMichael Pfeiffer view->FillRect(frame); 593c43f0163SMichael Pfeiffer // white ellipse inside a black rectangle 594c43f0163SMichael Pfeiffer } 595c43f0163SMichael Pfeiffer 596c43f0163SMichael Pfeiffer static void testSetPenSize(BView *view, BRect frame) 597c43f0163SMichael Pfeiffer { 598c43f0163SMichael Pfeiffer frame.InsetBy(8, 2); 599c43f0163SMichael Pfeiffer float x = centerPoint(frame).x; 600c43f0163SMichael Pfeiffer 601c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top)); 602c43f0163SMichael Pfeiffer 603c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 604c43f0163SMichael Pfeiffer view->SetPenSize(1); 605c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 606c43f0163SMichael Pfeiffer view->SetPenSize(0); 607c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 608c43f0163SMichael Pfeiffer 609c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 610c43f0163SMichael Pfeiffer view->SetPenSize(1); 611c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 612c43f0163SMichael Pfeiffer view->SetPenSize(2); 613c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 614c43f0163SMichael Pfeiffer 615c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 616c43f0163SMichael Pfeiffer view->SetPenSize(1); 617c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 618c43f0163SMichael Pfeiffer view->SetPenSize(3); 619c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 620c43f0163SMichael Pfeiffer 621c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 622c43f0163SMichael Pfeiffer view->SetPenSize(1); 623c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 624c43f0163SMichael Pfeiffer view->SetPenSize(4); 625c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 626c43f0163SMichael Pfeiffer } 627c43f0163SMichael Pfeiffer 628c43f0163SMichael Pfeiffer static void testSetPenSize2(BView *view, BRect frame) 629c43f0163SMichael Pfeiffer { 630c43f0163SMichael Pfeiffer // test if pen size is scaled too 631c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 632c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 633c43f0163SMichael Pfeiffer view->SetPenSize(4); 634c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top)); 635c43f0163SMichael Pfeiffer view->SetScale(0.5); 636c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left + 2, frame.bottom), BPoint(frame.right + 2, frame.bottom)); 637c43f0163SMichael Pfeiffer 638c43f0163SMichael Pfeiffer // black line from left to right, 4 pixel size 639c43f0163SMichael Pfeiffer // below black line with half the length of the first one 640c43f0163SMichael Pfeiffer // and 2 pixel size 641c43f0163SMichael Pfeiffer } 642c43f0163SMichael Pfeiffer 643c43f0163SMichael Pfeiffer static void testPattern(BView *view, BRect frame) 644c43f0163SMichael Pfeiffer { 645c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 646c43f0163SMichael Pfeiffer int x = frame.IntegerWidth() / 3; 647c43f0163SMichael Pfeiffer frame.right = frame.left + x - 2; 648c43f0163SMichael Pfeiffer // -2 for an empty pixel row between 649c43f0163SMichael Pfeiffer // filled rectangles 650c43f0163SMichael Pfeiffer 651c43f0163SMichael Pfeiffer view->SetLowColor(kGreen); 652c43f0163SMichael Pfeiffer view->SetHighColor(kRed); 653c43f0163SMichael Pfeiffer 654c43f0163SMichael Pfeiffer view->FillRect(frame, B_SOLID_HIGH); 655c43f0163SMichael Pfeiffer 656c43f0163SMichael Pfeiffer frame.OffsetBy(x, 0); 657c43f0163SMichael Pfeiffer view->FillRect(frame, B_MIXED_COLORS); 658c43f0163SMichael Pfeiffer 659c43f0163SMichael Pfeiffer frame.OffsetBy(x, 0); 660c43f0163SMichael Pfeiffer view->FillRect(frame, B_SOLID_LOW); 661c43f0163SMichael Pfeiffer } 662c43f0163SMichael Pfeiffer 663c43f0163SMichael Pfeiffer static void testSetOrigin(BView *view, BRect frame) 664c43f0163SMichael Pfeiffer { 665c43f0163SMichael Pfeiffer BPoint origin = view->Origin(); 666c43f0163SMichael Pfeiffer BPoint center = centerPoint(frame); 667c43f0163SMichael Pfeiffer view->SetOrigin(center); 668c43f0163SMichael Pfeiffer 669c43f0163SMichael Pfeiffer BRect r(0, 0, center.x, center.y); 670c43f0163SMichael Pfeiffer view->SetHighColor(kBlue); 671c43f0163SMichael Pfeiffer view->FillRect(r); 672c43f0163SMichael Pfeiffer 673c43f0163SMichael Pfeiffer view->SetOrigin(origin); 674c43f0163SMichael Pfeiffer view->SetHighColor(kRed); 675c43f0163SMichael Pfeiffer view->FillRect(r); 676c43f0163SMichael Pfeiffer 677c43f0163SMichael Pfeiffer // red rectangle in left, top corner 678c43f0163SMichael Pfeiffer // blue rectangle in right, bottom corner 679c43f0163SMichael Pfeiffer // the red rectangle overwrites the 680c43f0163SMichael Pfeiffer // top, left pixel of the blue rectangle 681c43f0163SMichael Pfeiffer } 682c43f0163SMichael Pfeiffer 683c43f0163SMichael Pfeiffer static void testSetOrigin2(BView *view, BRect frame) 684c43f0163SMichael Pfeiffer { 685c43f0163SMichael Pfeiffer BPoint center = centerPoint(frame); 686c43f0163SMichael Pfeiffer BRect r(0, 0, center.x, center.y); 687c43f0163SMichael Pfeiffer view->SetOrigin(center); 688c43f0163SMichael Pfeiffer view->PushState(); 689c43f0163SMichael Pfeiffer view->SetOrigin(BPoint(-center.x, 0)); 690c43f0163SMichael Pfeiffer view->FillRect(r); 691c43f0163SMichael Pfeiffer view->PopState(); 692c43f0163SMichael Pfeiffer // black rectangle in left, bottom corner 693c43f0163SMichael Pfeiffer } 694c43f0163SMichael Pfeiffer 695c43f0163SMichael Pfeiffer static void testSetScale(BView *view, BRect frame) 696c43f0163SMichael Pfeiffer { 697c43f0163SMichael Pfeiffer view->SetScale(0.5); 698c43f0163SMichael Pfeiffer view->FillRect(frame); 699c43f0163SMichael Pfeiffer // black rectangle in left, top corner 700c43f0163SMichael Pfeiffer } 701c43f0163SMichael Pfeiffer 702c43f0163SMichael Pfeiffer static void testSetScale2(BView *view, BRect frame) 703c43f0163SMichael Pfeiffer { 704c43f0163SMichael Pfeiffer view->SetScale(0.5); 705c43f0163SMichael Pfeiffer view->PushState(); 706c43f0163SMichael Pfeiffer view->SetScale(0.5); 707c43f0163SMichael Pfeiffer view->FillRect(frame); 708c43f0163SMichael Pfeiffer view->PopState(); 709c43f0163SMichael Pfeiffer // black rectangle in left, top corner 710c43f0163SMichael Pfeiffer // with half the size of the rectangle 711c43f0163SMichael Pfeiffer // from test testSetScaling 712c43f0163SMichael Pfeiffer } 713c43f0163SMichael Pfeiffer 714c43f0163SMichael Pfeiffer static void testSetScale3(BView *view, BRect frame) 715c43f0163SMichael Pfeiffer { 716c43f0163SMichael Pfeiffer view->SetScale(0.5); 717c43f0163SMichael Pfeiffer view->PushState(); 718c43f0163SMichael Pfeiffer // if the second scale value differs slightly 719c43f0163SMichael Pfeiffer // the bug under BeOS R5 in testSetScale2 720c43f0163SMichael Pfeiffer // does not occur 721c43f0163SMichael Pfeiffer view->SetScale(0.5000001); 722c43f0163SMichael Pfeiffer view->FillRect(frame); 723c43f0163SMichael Pfeiffer view->PopState(); 724c43f0163SMichael Pfeiffer // black rectangle in left, top corner 725c43f0163SMichael Pfeiffer // with half the size of the rectangle 726c43f0163SMichael Pfeiffer // from test testSetScaling 727c43f0163SMichael Pfeiffer } 728c43f0163SMichael Pfeiffer 729c9c4a80aSMichael Pfeiffer static void testSetOriginAndScale(BView *view, BRect frame) 730c9c4a80aSMichael Pfeiffer { 731c9c4a80aSMichael Pfeiffer frame.InsetBy(2, 2); 732c9c4a80aSMichael Pfeiffer BPoint center = centerPoint(frame); 733c9c4a80aSMichael Pfeiffer 734c9c4a80aSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 735c9c4a80aSMichael Pfeiffer view->SetOrigin(center); 736c9c4a80aSMichael Pfeiffer view->FillRect(r); 737c9c4a80aSMichael Pfeiffer 738c9c4a80aSMichael Pfeiffer view->SetScale(0.5); 739c9c4a80aSMichael Pfeiffer view->SetHighColor(kRed); 740c9c4a80aSMichael Pfeiffer view->FillRect(r); 741c9c4a80aSMichael Pfeiffer } 742c9c4a80aSMichael Pfeiffer 7434b05331dSMichael Pfeiffer static void testSetOriginAndScale2(BView *view, BRect frame) 7444b05331dSMichael Pfeiffer { 7454b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 7464b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 7474b05331dSMichael Pfeiffer 7484b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 7494b05331dSMichael Pfeiffer view->SetOrigin(center); 7504b05331dSMichael Pfeiffer view->FillRect(r); 7514b05331dSMichael Pfeiffer 7524b05331dSMichael Pfeiffer view->SetScale(0.5); 7534b05331dSMichael Pfeiffer view->SetHighColor(kRed); 7544b05331dSMichael Pfeiffer view->FillRect(r); 7554b05331dSMichael Pfeiffer 7564b05331dSMichael Pfeiffer view->SetOrigin(0, 0); 7574b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 7584b05331dSMichael Pfeiffer view->FillRect(r); 7594b05331dSMichael Pfeiffer } 7604b05331dSMichael Pfeiffer 7614b05331dSMichael Pfeiffer static void testSetOriginAndScale3(BView *view, BRect frame) 7624b05331dSMichael Pfeiffer { 7634b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 7644b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 7654b05331dSMichael Pfeiffer 7664b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 7674b05331dSMichael Pfeiffer view->SetOrigin(center); 7684b05331dSMichael Pfeiffer view->FillRect(r); 7694b05331dSMichael Pfeiffer 7704b05331dSMichael Pfeiffer view->SetScale(0.5); 7714b05331dSMichael Pfeiffer view->SetHighColor(kRed); 7724b05331dSMichael Pfeiffer view->FillRect(r); 7734b05331dSMichael Pfeiffer 7744b05331dSMichael Pfeiffer view->SetScale(0.25); 7754b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 7764b05331dSMichael Pfeiffer view->FillRect(r); 7774b05331dSMichael Pfeiffer } 7784b05331dSMichael Pfeiffer 7794b05331dSMichael Pfeiffer static void testSetOriginAndScale4(BView *view, BRect frame) 7804b05331dSMichael Pfeiffer { 7814b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 7824b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 7834b05331dSMichael Pfeiffer 7844b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 7854b05331dSMichael Pfeiffer view->SetOrigin(center); 7864b05331dSMichael Pfeiffer view->FillRect(r); 7874b05331dSMichael Pfeiffer 7884b05331dSMichael Pfeiffer view->SetScale(0.5); 7894b05331dSMichael Pfeiffer view->SetHighColor(kRed); 7904b05331dSMichael Pfeiffer view->FillRect(r); 7914b05331dSMichael Pfeiffer 7924b05331dSMichael Pfeiffer view->PushState(); 7934b05331dSMichael Pfeiffer // 7944b05331dSMichael Pfeiffer view->SetOrigin(center.x+1, center.y); 7954b05331dSMichael Pfeiffer // +1 to work around BeOS bug 7964b05331dSMichael Pfeiffer // where setting the origin has no 7974b05331dSMichael Pfeiffer // effect if it is the same as 7984b05331dSMichael Pfeiffer // the previous value althou 7994b05331dSMichael Pfeiffer // it is from the "outer" coordinate 8004b05331dSMichael Pfeiffer // system 8014b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 8024b05331dSMichael Pfeiffer view->FillRect(r); 8034b05331dSMichael Pfeiffer view->PopState(); 8044b05331dSMichael Pfeiffer } 8054b05331dSMichael Pfeiffer 8064b05331dSMichael Pfeiffer static void testSetOriginAndScale5(BView *view, BRect frame) 8074b05331dSMichael Pfeiffer { 8084b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 8094b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 8104b05331dSMichael Pfeiffer 8114b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 8124b05331dSMichael Pfeiffer view->SetOrigin(center); 8134b05331dSMichael Pfeiffer view->FillRect(r); 8144b05331dSMichael Pfeiffer 8154b05331dSMichael Pfeiffer view->SetScale(0.5); 8164b05331dSMichael Pfeiffer view->SetHighColor(kRed); 8174b05331dSMichael Pfeiffer view->FillRect(r); 8184b05331dSMichael Pfeiffer 8194b05331dSMichael Pfeiffer view->PushState(); 8204b05331dSMichael Pfeiffer view->SetScale(0.75); 8214b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 8224b05331dSMichael Pfeiffer view->FillRect(r); 8234b05331dSMichael Pfeiffer view->PopState(); 8244b05331dSMichael Pfeiffer } 8254b05331dSMichael Pfeiffer 826c43f0163SMichael Pfeiffer static void testSetFontSize(BView *view, BRect frame) 827c43f0163SMichael Pfeiffer { 828c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 829c43f0163SMichael Pfeiffer int size = frame.IntegerHeight() / 3; 830c43f0163SMichael Pfeiffer 831c43f0163SMichael Pfeiffer frame.OffsetBy(0, size); 832c43f0163SMichael Pfeiffer view->MovePenTo(BPoint(frame.left, frame.top)); 833c43f0163SMichael Pfeiffer view->SetFontSize(size); 834c43f0163SMichael Pfeiffer view->DrawString("Haiku"); 835c43f0163SMichael Pfeiffer 836c43f0163SMichael Pfeiffer size *= 2; 837c43f0163SMichael Pfeiffer frame.OffsetBy(0, size); 838c43f0163SMichael Pfeiffer view->MovePenTo(BPoint(frame.left, frame.top)); 839c43f0163SMichael Pfeiffer view->SetFontSize(size); 840c43f0163SMichael Pfeiffer view->DrawString("Haiku"); 841c43f0163SMichael Pfeiffer } 842c43f0163SMichael Pfeiffer 8432fb98dccSStefano Ceccherini static void testSetFontFamilyAndStyle(BView *view, BRect frame) 8442fb98dccSStefano Ceccherini { 8452fb98dccSStefano Ceccherini view->DrawString("This is a test", BPoint(2, 6)); 8462fb98dccSStefano Ceccherini 8472fb98dccSStefano Ceccherini BFont font; 8482fb98dccSStefano Ceccherini view->GetFont(&font); 8492fb98dccSStefano Ceccherini 8502fb98dccSStefano Ceccherini int32 families = count_font_families(); 8512fb98dccSStefano Ceccherini font_family familyName; 8522fb98dccSStefano Ceccherini get_font_family(families - 1, &familyName); 8532fb98dccSStefano Ceccherini 8542fb98dccSStefano Ceccherini int32 styles = count_font_styles(familyName); 8552fb98dccSStefano Ceccherini font_style styleName; 8562fb98dccSStefano Ceccherini get_font_style(familyName, styles - 1, &styleName); 8572fb98dccSStefano Ceccherini font.SetFamilyAndStyle(familyName, styleName); 8582fb98dccSStefano Ceccherini view->SetFont(&font); 8592fb98dccSStefano Ceccherini view->DrawString( "This is a test", BPoint(2, 19)); 8602fb98dccSStefano Ceccherini } 8612fb98dccSStefano Ceccherini 86215cf50e0SStefano Ceccherini static void testSetDrawingMode(BView *view, BRect frame) 86315cf50e0SStefano Ceccherini { 864ed70c5f3SStefano Ceccherini frame.InsetBy(2, 2); 86515cf50e0SStefano Ceccherini view->StrokeLine(frame.LeftTop(), frame.RightBottom()); 86615cf50e0SStefano Ceccherini view->StrokeLine(frame.LeftBottom(), frame.RightTop()); 86715cf50e0SStefano Ceccherini view->SetDrawingMode(B_OP_ALPHA); 86815cf50e0SStefano Ceccherini rgb_color color = kRed; 86915cf50e0SStefano Ceccherini color.alpha = 127; 87015cf50e0SStefano Ceccherini view->SetHighColor(color); 87115cf50e0SStefano Ceccherini view->FillRect(frame, B_SOLID_HIGH); 87215cf50e0SStefano Ceccherini } 87315cf50e0SStefano Ceccherini 874ed70c5f3SStefano Ceccherini static void testPushPopState(BView *view, BRect frame) 875ed70c5f3SStefano Ceccherini { 876ed70c5f3SStefano Ceccherini frame.InsetBy(2, 2); 877ed70c5f3SStefano Ceccherini view->SetHighColor(kGreen); 878ed70c5f3SStefano Ceccherini view->PushState(); 879ed70c5f3SStefano Ceccherini view->SetHighColor(kRed); 880ed70c5f3SStefano Ceccherini view->PopState(); 881ed70c5f3SStefano Ceccherini 882ed70c5f3SStefano Ceccherini view->FillRect(frame, B_SOLID_HIGH); 883ed70c5f3SStefano Ceccherini } 884ed70c5f3SStefano Ceccherini 8858247141fSMichael Pfeiffer static void testFontRotation(BView* view, BRect frame) 8868247141fSMichael Pfeiffer { 8878247141fSMichael Pfeiffer BFont font; 8888247141fSMichael Pfeiffer view->GetFont(&font); 8898247141fSMichael Pfeiffer 8908247141fSMichael Pfeiffer font.SetRotation(90); 8918247141fSMichael Pfeiffer view->SetFont(&font, B_FONT_ROTATION); 8928247141fSMichael Pfeiffer view->DrawString("This is a test!", BPoint(frame.Width() / 2, frame.bottom - 3)); 8938247141fSMichael Pfeiffer 8948247141fSMichael Pfeiffer view->GetFont(&font); 8958247141fSMichael Pfeiffer if (font.Rotation() != 90.0) 8968247141fSMichael Pfeiffer fprintf(stderr, "Error: Rotation is %f but should be 90.0\n", font.Rotation()); 8978247141fSMichael Pfeiffer } 89815cf50e0SStefano Ceccherini 899abf565b1SStefano Ceccherini 900abf565b1SStefano Ceccherini 901abf565b1SStefano Ceccherini 902c43f0163SMichael Pfeiffer // TODO 903c43f0163SMichael Pfeiffer // - blending mode 904c43f0163SMichael Pfeiffer // - line mode 905c43f0163SMichael Pfeiffer // - push/pop state 906c43f0163SMichael Pfeiffer // - move pen 907c43f0163SMichael Pfeiffer // - set font 908c43f0163SMichael Pfeiffer 909c43f0163SMichael Pfeiffer 91082afdb09SMichael Pfeiffer TestCase gTestCases[] = { 91154730332SMichael Pfeiffer { "Test No Operation", testNoOp }, 91254730332SMichael Pfeiffer { "Test DrawChar", testDrawChar }, 91382afdb09SMichael Pfeiffer { "Test Draw String", testDrawString }, 91454730332SMichael Pfeiffer { "Test Draw String With Length", testDrawStringWithLength }, 915abf565b1SStefano Ceccherini { "Test Draw String With Offsets", testDrawStringWithOffsets }, 916abf565b1SStefano Ceccherini 91754730332SMichael Pfeiffer { "Test FillArc", testFillArc }, 91854730332SMichael Pfeiffer { "Test StrokeArc", testStrokeArc }, 919c43f0163SMichael Pfeiffer // testFillBezier fails under BeOS because the 920c43f0163SMichael Pfeiffer // direct draw version is not correct 92154730332SMichael Pfeiffer { "Test FillBezier", testFillBezier }, 92254730332SMichael Pfeiffer { "Test StrokeBezier", testStrokeBezier }, 92354730332SMichael Pfeiffer { "Test FillEllipse", testFillEllipse }, 92454730332SMichael Pfeiffer { "Test StrokeEllipse", testStrokeEllipse }, 92554730332SMichael Pfeiffer { "Test FillPolygon", testFillPolygon }, 92654730332SMichael Pfeiffer { "Test StrokePolygon", testStrokePolygon }, 92754730332SMichael Pfeiffer { "Test FillRect", testFillRect }, 928abf565b1SStefano Ceccherini { "Test FillRectGradientLinear", testFillRectGradientLinear }, 929abf565b1SStefano Ceccherini { "Test FillRectGradientRadial", testFillRectGradientRadial }, 930abf565b1SStefano Ceccherini { "Test FillRectGradientRadialFocus", testFillRectGradientRadialFocus }, 931abf565b1SStefano Ceccherini { "Test FillRectGradientDiamond", testFillRectGradientDiamond }, 932abf565b1SStefano Ceccherini { "Test FillRectGradientConic", testFillRectGradientConic }, 93354730332SMichael Pfeiffer { "Test StrokeRect", testStrokeRect }, 93454730332SMichael Pfeiffer { "Test FillRegion", testFillRegion }, 935*b8c65995SStefano Ceccherini { "Test FillRegionGradientLinear", testFillRegionGradientLinear }, 936*b8c65995SStefano Ceccherini { "Test FillRegionGradientRadial", testFillRegionGradientRadial }, 937*b8c65995SStefano Ceccherini { "Test FillRegionGradientRadialFocus", testFillRegionGradientRadialFocus }, 938*b8c65995SStefano Ceccherini { "Test FillRegionGradientDiamond", testFillRegionGradientDiamond }, 939*b8c65995SStefano Ceccherini { "Test FillRegionGradientConic", testFillRegionGradientConic }, 94054730332SMichael Pfeiffer { "Test FillRoundRect", testFillRoundRect }, 94154730332SMichael Pfeiffer { "Test StrokeRoundRect", testStrokeRoundRect }, 94254730332SMichael Pfeiffer { "Test FillTriangle", testFillTriangle }, 94354730332SMichael Pfeiffer { "Test StrokeTriangle", testStrokeTriangle }, 94454730332SMichael Pfeiffer { "Test StrokeLine", testStrokeLine }, 94554730332SMichael Pfeiffer { "Test FillShape", testFillShape }, 94654730332SMichael Pfeiffer { "Test StrokeShape", testStrokeShape }, 94782afdb09SMichael Pfeiffer { "Test Record Picture", testRecordPicture }, 94882afdb09SMichael Pfeiffer { "Test Record And Play Picture", testRecordAndPlayPicture }, 94982afdb09SMichael Pfeiffer { "Test Record And Play Picture With Offset", testRecordAndPlayPictureWithOffset }, 95054730332SMichael Pfeiffer { "Test AppendToPicture", testAppendToPicture }, 9518247141fSMichael Pfeiffer { "Test Draw Scaled Picture", testDrawScaledPicture }, 95254730332SMichael Pfeiffer { "Test LineArray", testLineArray }, 95354730332SMichael Pfeiffer { "Test InvertRect", testInvertRect }, 9547cf26360SStefano Ceccherini { "Test InvertRectSetDrawingMode", testInvertRectSetDrawingMode }, 9554f422578SMichael Pfeiffer { "Test DrawBitmap", testDrawBitmap }, 9564f422578SMichael Pfeiffer { "Test DrawBitmapAtPoint", testDrawBitmapAtPoint }, 9574f422578SMichael Pfeiffer { "Test DrawBitmapAtRect", testDrawBitmapAtRect }, 9585f380e34SMichael Pfeiffer { "Test DrawLargeBitmap", testDrawLargeBitmap }, 959c43f0163SMichael Pfeiffer { "Test ConstrainClippingRegion", testConstrainClippingRegion }, 960c43f0163SMichael Pfeiffer { "Test ClipToPicture", testClipToPicture }, 961c43f0163SMichael Pfeiffer { "Test ClipToInversePicture", testClipToInversePicture }, 962c43f0163SMichael Pfeiffer { "Test SetPenSize", testSetPenSize }, 963c43f0163SMichael Pfeiffer { "Test SetPenSize2", testSetPenSize2 }, 964c43f0163SMichael Pfeiffer { "Test Pattern", testPattern }, 965c43f0163SMichael Pfeiffer { "Test SetOrigin", testSetOrigin }, 966c43f0163SMichael Pfeiffer { "Test SetOrigin2", testSetOrigin2 }, 967c43f0163SMichael Pfeiffer { "Test SetScale", testSetScale }, 968c43f0163SMichael Pfeiffer // testSetScale2 fails under BeOS. The picture versions of the 969c43f0163SMichael Pfeiffer // rectangle are twice as large as the direct draw version 970*b8c65995SStefano Ceccherini { "Test SetScale2", testSetScale2 }, 971c43f0163SMichael Pfeiffer { "Test SetScale3", testSetScale3 }, 972c9c4a80aSMichael Pfeiffer { "Test SetOriginAndScale", testSetOriginAndScale }, 9734b05331dSMichael Pfeiffer { "Test SetOriginAndScale2", testSetOriginAndScale2 }, 9744b05331dSMichael Pfeiffer { "Test SetOriginAndScale3", testSetOriginAndScale3 }, 9754b05331dSMichael Pfeiffer { "Test SetOriginAndScale4", testSetOriginAndScale4 }, 9764b05331dSMichael Pfeiffer { "Test SetOriginAndScale5", testSetOriginAndScale5 }, 977c43f0163SMichael Pfeiffer { "Test SetFontSize", testSetFontSize }, 9782fb98dccSStefano Ceccherini { "Test SetFontFamilyAndStyle", testSetFontFamilyAndStyle }, 97915cf50e0SStefano Ceccherini { "Test SetDrawingMode", testSetDrawingMode }, 980ed70c5f3SStefano Ceccherini { "Test PushPopState", testPushPopState }, 9818247141fSMichael Pfeiffer { "Test FontRotation", testFontRotation }, 98282afdb09SMichael Pfeiffer { NULL, NULL } 98382afdb09SMichael Pfeiffer }; 98462c7fd0fSMichael Pfeiffer 9852fb98dccSStefano Ceccherini 986