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 933211dcccSJackBurton79 static void testDrawStringWithoutPosition(BView* view, BRect frame) 943211dcccSJackBurton79 { 953211dcccSJackBurton79 BFont font; 963211dcccSJackBurton79 view->GetFont(&font); 973211dcccSJackBurton79 font_height height; 983211dcccSJackBurton79 font.GetHeight(&height); 993211dcccSJackBurton79 float baseline = frame.bottom - height.descent; 1003211dcccSJackBurton79 // draw base line 1013211dcccSJackBurton79 view->SetHighColor(kGreen); 1023211dcccSJackBurton79 view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1)); 1033211dcccSJackBurton79 1043211dcccSJackBurton79 view->SetHighColor(kBlack); 1053211dcccSJackBurton79 view->MovePenTo(BPoint(frame.left, baseline)); 1063211dcccSJackBurton79 view->DrawString("H"); 1073211dcccSJackBurton79 view->DrawString("a"); 1083211dcccSJackBurton79 view->DrawString("i"); 1093211dcccSJackBurton79 view->DrawString("k"); 1103211dcccSJackBurton79 view->DrawString("u"); 1113211dcccSJackBurton79 } 1123211dcccSJackBurton79 1133211dcccSJackBurton79 11454730332SMichael Pfeiffer static void testFillArc(BView *view, BRect frame) 11582afdb09SMichael Pfeiffer { 11682afdb09SMichael Pfeiffer frame.InsetBy(2, 2); 11754730332SMichael Pfeiffer view->FillArc(frame, 45, 180); 11854730332SMichael Pfeiffer } 11954730332SMichael Pfeiffer 12054730332SMichael Pfeiffer static void testStrokeArc(BView *view, BRect frame) 12154730332SMichael Pfeiffer { 12254730332SMichael Pfeiffer frame.InsetBy(2, 2); 12354730332SMichael Pfeiffer view->StrokeArc(frame, 45, 180); 12454730332SMichael Pfeiffer } 12554730332SMichael Pfeiffer 12654730332SMichael Pfeiffer static void testFillBezier(BView *view, BRect frame) 12754730332SMichael Pfeiffer { 12854730332SMichael Pfeiffer frame.InsetBy(2, 2); 12954730332SMichael Pfeiffer BPoint points[4]; 13054730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 13154730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 13254730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 13354730332SMichael Pfeiffer points[3] = BPoint(frame.right, frame.top); 13454730332SMichael Pfeiffer view->FillBezier(points); 13554730332SMichael Pfeiffer } 13654730332SMichael Pfeiffer 13754730332SMichael Pfeiffer static void testStrokeBezier(BView *view, BRect frame) 13854730332SMichael Pfeiffer { 13954730332SMichael Pfeiffer frame.InsetBy(2, 2); 14054730332SMichael Pfeiffer BPoint points[4]; 14154730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 14254730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 14354730332SMichael Pfeiffer points[1] = BPoint(frame.left, frame.top); 14454730332SMichael Pfeiffer points[3] = BPoint(frame.right, frame.top); 14554730332SMichael Pfeiffer view->StrokeBezier(points); 14654730332SMichael Pfeiffer } 14754730332SMichael Pfeiffer 14854730332SMichael Pfeiffer static void testFillEllipse(BView *view, BRect frame) 14954730332SMichael Pfeiffer { 15054730332SMichael Pfeiffer frame.InsetBy(2, 2); 15154730332SMichael Pfeiffer view->FillEllipse(frame); 15254730332SMichael Pfeiffer 15354730332SMichael Pfeiffer view->SetHighColor(kRed); 15454730332SMichael Pfeiffer float r = frame.Width() / 3; 15554730332SMichael Pfeiffer float s = frame.Height() / 4; 15654730332SMichael Pfeiffer view->FillEllipse(centerPoint(frame), r, s); 15754730332SMichael Pfeiffer } 15854730332SMichael Pfeiffer 15954730332SMichael Pfeiffer static void testStrokeEllipse(BView *view, BRect frame) 16054730332SMichael Pfeiffer { 16154730332SMichael Pfeiffer frame.InsetBy(2, 2); 16254730332SMichael Pfeiffer view->StrokeEllipse(frame); 16354730332SMichael Pfeiffer 16454730332SMichael Pfeiffer view->SetHighColor(kRed); 16554730332SMichael Pfeiffer float r = frame.Width() / 3; 16654730332SMichael Pfeiffer float s = frame.Height() / 4; 16754730332SMichael Pfeiffer view->StrokeEllipse(centerPoint(frame), r, s); 16854730332SMichael Pfeiffer } 16954730332SMichael Pfeiffer 17054730332SMichael Pfeiffer static void testFillPolygon(BView *view, BRect frame) 17154730332SMichael Pfeiffer { 17254730332SMichael Pfeiffer frame.InsetBy(2, 2); 17354730332SMichael Pfeiffer 17454730332SMichael Pfeiffer BPoint points[4]; 17554730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.top); 17654730332SMichael Pfeiffer points[1] = BPoint(frame.right, frame.bottom); 17754730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.top); 17854730332SMichael Pfeiffer points[3] = BPoint(frame.left, frame.bottom); 17954730332SMichael Pfeiffer 18054730332SMichael Pfeiffer view->FillPolygon(points, 4); 18154730332SMichael Pfeiffer } 18254730332SMichael Pfeiffer 18354730332SMichael Pfeiffer static void testStrokePolygon(BView *view, BRect frame) 18454730332SMichael Pfeiffer { 18554730332SMichael Pfeiffer frame.InsetBy(2, 2); 18654730332SMichael Pfeiffer 18754730332SMichael Pfeiffer BPoint points[4]; 18854730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.top); 18954730332SMichael Pfeiffer points[1] = BPoint(frame.right, frame.bottom); 19054730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.top); 19154730332SMichael Pfeiffer points[3] = BPoint(frame.left, frame.bottom); 19254730332SMichael Pfeiffer 19354730332SMichael Pfeiffer view->StrokePolygon(points, 4); 19454730332SMichael Pfeiffer } 19554730332SMichael Pfeiffer 19654730332SMichael Pfeiffer static void testFillRect(BView *view, BRect frame) 19754730332SMichael Pfeiffer { 19854730332SMichael Pfeiffer frame.InsetBy(2, 2); 19982afdb09SMichael Pfeiffer view->FillRect(frame); 20082afdb09SMichael Pfeiffer } 20182afdb09SMichael Pfeiffer 202abf565b1SStefano Ceccherini static void testFillRectGradientLinear(BView* view, BRect frame) 203abf565b1SStefano Ceccherini { 204abf565b1SStefano Ceccherini BGradientLinear gradient(0, 0, frame.right, frame.bottom); 205abf565b1SStefano Ceccherini gradient.AddColor(kRed, 0); 206abf565b1SStefano Ceccherini gradient.AddColor(kBlue, 255); 207abf565b1SStefano Ceccherini frame.InsetBy(2, 2); 208abf565b1SStefano Ceccherini view->FillRect(frame, gradient); 209abf565b1SStefano Ceccherini } 210abf565b1SStefano Ceccherini 211abf565b1SStefano Ceccherini static void testFillRectGradientRadial(BView* view, BRect frame) 212abf565b1SStefano Ceccherini { 213abf565b1SStefano Ceccherini BGradientRadial gradient(10, 10, 10); 214abf565b1SStefano Ceccherini gradient.AddColor(kRed, 0); 215abf565b1SStefano Ceccherini gradient.AddColor(kBlue, 255); 216abf565b1SStefano Ceccherini frame.InsetBy(2, 2); 217abf565b1SStefano Ceccherini view->FillRect(frame, gradient); 218abf565b1SStefano Ceccherini } 219abf565b1SStefano Ceccherini 220abf565b1SStefano Ceccherini static void testFillRectGradientRadialFocus(BView* view, BRect frame) 221abf565b1SStefano Ceccherini { 222abf565b1SStefano Ceccherini BGradientRadialFocus gradient(0, 0, 10, 10, 5); 223abf565b1SStefano Ceccherini gradient.AddColor(kRed, 0); 224abf565b1SStefano Ceccherini gradient.AddColor(kBlue, 255); 225abf565b1SStefano Ceccherini frame.InsetBy(2, 2); 226abf565b1SStefano Ceccherini view->FillRect(frame, gradient); 227abf565b1SStefano Ceccherini } 228abf565b1SStefano Ceccherini 229abf565b1SStefano Ceccherini static void testFillRectGradientDiamond(BView* view, BRect frame) 230abf565b1SStefano Ceccherini { 231abf565b1SStefano Ceccherini BGradientDiamond gradient(0, 10); 232abf565b1SStefano Ceccherini gradient.AddColor(kRed, 0); 233abf565b1SStefano Ceccherini gradient.AddColor(kBlue, 255); 234abf565b1SStefano Ceccherini frame.InsetBy(2, 2); 235abf565b1SStefano Ceccherini view->FillRect(frame, gradient); 236abf565b1SStefano Ceccherini } 237abf565b1SStefano Ceccherini 238abf565b1SStefano Ceccherini static void testFillRectGradientConic(BView* view, BRect frame) 239abf565b1SStefano Ceccherini { 240abf565b1SStefano Ceccherini BGradientConic gradient(0, 0, 10); 241abf565b1SStefano Ceccherini gradient.AddColor(kRed, 0); 242abf565b1SStefano Ceccherini gradient.AddColor(kBlue, 255); 243abf565b1SStefano Ceccherini frame.InsetBy(2, 2); 244abf565b1SStefano Ceccherini view->FillRect(frame, gradient); 245abf565b1SStefano Ceccherini } 246abf565b1SStefano Ceccherini 24754730332SMichael Pfeiffer static void testStrokeRect(BView *view, BRect frame) 24882afdb09SMichael Pfeiffer { 24982afdb09SMichael Pfeiffer frame.InsetBy(2, 2); 25082afdb09SMichael Pfeiffer view->StrokeRect(frame); 25182afdb09SMichael Pfeiffer } 25282afdb09SMichael Pfeiffer 25354730332SMichael Pfeiffer static void testFillRegion(BView *view, BRect frame) 25482afdb09SMichael Pfeiffer { 25554730332SMichael Pfeiffer frame.InsetBy(2, 2); 25654730332SMichael Pfeiffer BRegion region(frame); 257b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 25854730332SMichael Pfeiffer region.Exclude(frame); 25954730332SMichael Pfeiffer view->FillRegion(®ion); 26054730332SMichael Pfeiffer } 26154730332SMichael Pfeiffer 262b8c65995SStefano Ceccherini static void testFillRegionGradientLinear(BView* view, BRect frame) 263b8c65995SStefano Ceccherini { 264b8c65995SStefano Ceccherini BGradientLinear gradient(0, 0, frame.right, frame.bottom); 265b8c65995SStefano Ceccherini gradient.AddColor(kRed, 0); 266b8c65995SStefano Ceccherini gradient.AddColor(kBlue, 255); 267b8c65995SStefano Ceccherini frame.InsetBy(2, 2); 268b8c65995SStefano Ceccherini BRegion region(frame); 269b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 270b8c65995SStefano Ceccherini region.Exclude(frame); 271b8c65995SStefano Ceccherini view->FillRegion(®ion, gradient); 272b8c65995SStefano Ceccherini } 273b8c65995SStefano Ceccherini 274b8c65995SStefano Ceccherini static void testFillRegionGradientRadial(BView* view, BRect frame) 275b8c65995SStefano Ceccherini { 276b8c65995SStefano Ceccherini BGradientRadial gradient(10, 10, 10); 277b8c65995SStefano Ceccherini gradient.AddColor(kRed, 0); 278b8c65995SStefano Ceccherini gradient.AddColor(kBlue, 255); 279b8c65995SStefano Ceccherini frame.InsetBy(2, 2); 280b8c65995SStefano Ceccherini BRegion region(frame); 281b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 282b8c65995SStefano Ceccherini region.Exclude(frame); 283b8c65995SStefano Ceccherini view->FillRegion(®ion, gradient); 284b8c65995SStefano Ceccherini } 285b8c65995SStefano Ceccherini 286b8c65995SStefano Ceccherini static void testFillRegionGradientRadialFocus(BView* view, BRect frame) 287b8c65995SStefano Ceccherini { 288b8c65995SStefano Ceccherini BGradientRadialFocus gradient(0, 0, 10, 10, 5); 289b8c65995SStefano Ceccherini gradient.AddColor(kRed, 0); 290b8c65995SStefano Ceccherini gradient.AddColor(kBlue, 255); 291b8c65995SStefano Ceccherini frame.InsetBy(2, 2); 292b8c65995SStefano Ceccherini BRegion region(frame); 293b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 294b8c65995SStefano Ceccherini region.Exclude(frame); 295b8c65995SStefano Ceccherini view->FillRegion(®ion, gradient); 296b8c65995SStefano Ceccherini } 297b8c65995SStefano Ceccherini 298b8c65995SStefano Ceccherini static void testFillRegionGradientDiamond(BView* view, BRect frame) 299b8c65995SStefano Ceccherini { 300b8c65995SStefano Ceccherini BGradientDiamond gradient(0, 10); 301b8c65995SStefano Ceccherini gradient.AddColor(kRed, 0); 302b8c65995SStefano Ceccherini gradient.AddColor(kBlue, 255); 303b8c65995SStefano Ceccherini frame.InsetBy(2, 2); 304b8c65995SStefano Ceccherini BRegion region(frame); 305b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 306b8c65995SStefano Ceccherini region.Exclude(frame); 307b8c65995SStefano Ceccherini view->FillRegion(®ion, gradient); 308b8c65995SStefano Ceccherini } 309b8c65995SStefano Ceccherini 310b8c65995SStefano Ceccherini static void testFillRegionGradientConic(BView* view, BRect frame) 311b8c65995SStefano Ceccherini { 312b8c65995SStefano Ceccherini BGradientConic gradient(0, 0, 10); 313b8c65995SStefano Ceccherini gradient.AddColor(kRed, 0); 314b8c65995SStefano Ceccherini gradient.AddColor(kBlue, 255); 315b8c65995SStefano Ceccherini frame.InsetBy(2, 2); 316b8c65995SStefano Ceccherini BRegion region(frame); 317b8c65995SStefano Ceccherini frame.InsetBy(10, 10); 318b8c65995SStefano Ceccherini region.Exclude(frame); 319b8c65995SStefano Ceccherini view->FillRegion(®ion, gradient); 320b8c65995SStefano Ceccherini } 321b8c65995SStefano Ceccherini 32254730332SMichael Pfeiffer static void testFillRoundRect(BView *view, BRect frame) 32354730332SMichael Pfeiffer { 32454730332SMichael Pfeiffer frame.InsetBy(2, 2); 32554730332SMichael Pfeiffer view->FillRoundRect(frame, 5, 3); 32654730332SMichael Pfeiffer } 32754730332SMichael Pfeiffer 32800c573d6SStefano Ceccherini static void testFillRoundRectGradientLinear(BView* view, BRect frame) 32900c573d6SStefano Ceccherini { 33000c573d6SStefano Ceccherini BGradientLinear gradient(0, 0, frame.right, frame.bottom); 33100c573d6SStefano Ceccherini gradient.AddColor(kRed, 0); 33200c573d6SStefano Ceccherini gradient.AddColor(kBlue, 255); 33300c573d6SStefano Ceccherini frame.InsetBy(2, 2); 33400c573d6SStefano Ceccherini view->FillRoundRect(frame, 5, 3, gradient); 33500c573d6SStefano Ceccherini } 33600c573d6SStefano Ceccherini 33700c573d6SStefano Ceccherini static void testFillRoundRectGradientRadial(BView* view, BRect frame) 33800c573d6SStefano Ceccherini { 33900c573d6SStefano Ceccherini BGradientRadial gradient(10, 10, 10); 34000c573d6SStefano Ceccherini gradient.AddColor(kRed, 0); 34100c573d6SStefano Ceccherini gradient.AddColor(kBlue, 255); 34200c573d6SStefano Ceccherini frame.InsetBy(2, 2); 34300c573d6SStefano Ceccherini view->FillRoundRect(frame, 5, 3, gradient); 34400c573d6SStefano Ceccherini } 34500c573d6SStefano Ceccherini 34600c573d6SStefano Ceccherini static void testFillRoundRectGradientRadialFocus(BView* view, BRect frame) 34700c573d6SStefano Ceccherini { 34800c573d6SStefano Ceccherini BGradientRadialFocus gradient(0, 0, 10, 10, 5); 34900c573d6SStefano Ceccherini gradient.AddColor(kRed, 0); 35000c573d6SStefano Ceccherini gradient.AddColor(kBlue, 255); 35100c573d6SStefano Ceccherini view->FillRoundRect(frame, 5, 3, gradient); 35200c573d6SStefano Ceccherini } 35300c573d6SStefano Ceccherini 35400c573d6SStefano Ceccherini static void testFillRoundRectGradientDiamond(BView* view, BRect frame) 35500c573d6SStefano Ceccherini { 35600c573d6SStefano Ceccherini BGradientDiamond gradient(0, 10); 35700c573d6SStefano Ceccherini gradient.AddColor(kRed, 0); 35800c573d6SStefano Ceccherini gradient.AddColor(kBlue, 255); 35900c573d6SStefano Ceccherini frame.InsetBy(2, 2); 36000c573d6SStefano Ceccherini view->FillRoundRect(frame, 5, 3, gradient); 36100c573d6SStefano Ceccherini } 36200c573d6SStefano Ceccherini 36300c573d6SStefano Ceccherini static void testFillRoundRectGradientConic(BView* view, BRect frame) 36400c573d6SStefano Ceccherini { 36500c573d6SStefano Ceccherini BGradientConic gradient(0, 0, 10); 36600c573d6SStefano Ceccherini gradient.AddColor(kRed, 0); 36700c573d6SStefano Ceccherini gradient.AddColor(kBlue, 255); 36800c573d6SStefano Ceccherini frame.InsetBy(2, 2); 36900c573d6SStefano Ceccherini view->FillRoundRect(frame, 5, 3, gradient); 37000c573d6SStefano Ceccherini } 37100c573d6SStefano Ceccherini 37254730332SMichael Pfeiffer static void testStrokeRoundRect(BView *view, BRect frame) 37354730332SMichael Pfeiffer { 37454730332SMichael Pfeiffer frame.InsetBy(2, 2); 37554730332SMichael Pfeiffer view->StrokeRoundRect(frame, 5, 3); 37654730332SMichael Pfeiffer } 37754730332SMichael Pfeiffer 37854730332SMichael Pfeiffer static void testFillTriangle(BView *view, BRect frame) 37954730332SMichael Pfeiffer { 38054730332SMichael Pfeiffer frame.InsetBy(2, 2); 38154730332SMichael Pfeiffer BPoint points[3]; 38254730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 38354730332SMichael Pfeiffer points[1] = BPoint(centerPoint(frame).x, frame.top); 38454730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.bottom); 38554730332SMichael Pfeiffer view->FillTriangle(points[0], points[1], points[2]); 38654730332SMichael Pfeiffer } 38754730332SMichael Pfeiffer 388e5f9dfebSStefano Ceccherini static void testFillTriangleGradientLinear(BView* view, BRect frame) 389e5f9dfebSStefano Ceccherini { 390e5f9dfebSStefano Ceccherini BGradientLinear gradient(0, 0, frame.right, frame.bottom); 391e5f9dfebSStefano Ceccherini gradient.AddColor(kRed, 0); 392e5f9dfebSStefano Ceccherini gradient.AddColor(kBlue, 255); 393e5f9dfebSStefano Ceccherini frame.InsetBy(2, 2); 394e5f9dfebSStefano Ceccherini BPoint points[3]; 395e5f9dfebSStefano Ceccherini points[0] = BPoint(frame.left, frame.bottom); 396e5f9dfebSStefano Ceccherini points[1] = BPoint(centerPoint(frame).x, frame.top); 397e5f9dfebSStefano Ceccherini points[2] = BPoint(frame.right, frame.bottom); 398e5f9dfebSStefano Ceccherini view->FillTriangle(points[0], points[1], points[2], gradient); 399e5f9dfebSStefano Ceccherini } 400e5f9dfebSStefano Ceccherini 401e5f9dfebSStefano Ceccherini static void testFillTriangleGradientRadial(BView* view, BRect frame) 402e5f9dfebSStefano Ceccherini { 403e5f9dfebSStefano Ceccherini BGradientRadial gradient(10, 10, 10); 404e5f9dfebSStefano Ceccherini gradient.AddColor(kRed, 0); 405e5f9dfebSStefano Ceccherini gradient.AddColor(kBlue, 255); 406e5f9dfebSStefano Ceccherini frame.InsetBy(2, 2); 407e5f9dfebSStefano Ceccherini BPoint points[3]; 408e5f9dfebSStefano Ceccherini points[0] = BPoint(frame.left, frame.bottom); 409e5f9dfebSStefano Ceccherini points[1] = BPoint(centerPoint(frame).x, frame.top); 410e5f9dfebSStefano Ceccherini points[2] = BPoint(frame.right, frame.bottom); 411e5f9dfebSStefano Ceccherini view->FillTriangle(points[0], points[1], points[2], gradient); 412e5f9dfebSStefano Ceccherini } 413e5f9dfebSStefano Ceccherini 414e5f9dfebSStefano Ceccherini static void testFillTriangleGradientRadialFocus(BView* view, BRect frame) 415e5f9dfebSStefano Ceccherini { 416e5f9dfebSStefano Ceccherini BGradientRadialFocus gradient(0, 0, 10, 10, 5); 417e5f9dfebSStefano Ceccherini gradient.AddColor(kRed, 0); 418e5f9dfebSStefano Ceccherini gradient.AddColor(kBlue, 255); 419e5f9dfebSStefano Ceccherini frame.InsetBy(2, 2); 420e5f9dfebSStefano Ceccherini BPoint points[3]; 421e5f9dfebSStefano Ceccherini points[0] = BPoint(frame.left, frame.bottom); 422e5f9dfebSStefano Ceccherini points[1] = BPoint(centerPoint(frame).x, frame.top); 423e5f9dfebSStefano Ceccherini points[2] = BPoint(frame.right, frame.bottom); 424e5f9dfebSStefano Ceccherini view->FillTriangle(points[0], points[1], points[2], gradient); 425e5f9dfebSStefano Ceccherini } 426e5f9dfebSStefano Ceccherini 427e5f9dfebSStefano Ceccherini static void testFillTriangleGradientDiamond(BView* view, BRect frame) 428e5f9dfebSStefano Ceccherini { 429e5f9dfebSStefano Ceccherini BGradientDiamond gradient(0, 10); 430e5f9dfebSStefano Ceccherini gradient.AddColor(kRed, 0); 431e5f9dfebSStefano Ceccherini gradient.AddColor(kBlue, 255); 432e5f9dfebSStefano Ceccherini frame.InsetBy(2, 2); 433e5f9dfebSStefano Ceccherini BPoint points[3]; 434e5f9dfebSStefano Ceccherini points[0] = BPoint(frame.left, frame.bottom); 435e5f9dfebSStefano Ceccherini points[1] = BPoint(centerPoint(frame).x, frame.top); 436e5f9dfebSStefano Ceccherini points[2] = BPoint(frame.right, frame.bottom); 437e5f9dfebSStefano Ceccherini view->FillTriangle(points[0], points[1], points[2], gradient); 438e5f9dfebSStefano Ceccherini } 439e5f9dfebSStefano Ceccherini 440e5f9dfebSStefano Ceccherini static void testFillTriangleGradientConic(BView* view, BRect frame) 441e5f9dfebSStefano Ceccherini { 442e5f9dfebSStefano Ceccherini BGradientConic gradient(0, 0, 10); 443e5f9dfebSStefano Ceccherini gradient.AddColor(kRed, 0); 444e5f9dfebSStefano Ceccherini gradient.AddColor(kBlue, 255); 445e5f9dfebSStefano Ceccherini frame.InsetBy(2, 2); 446e5f9dfebSStefano Ceccherini BPoint points[3]; 447e5f9dfebSStefano Ceccherini points[0] = BPoint(frame.left, frame.bottom); 448e5f9dfebSStefano Ceccherini points[1] = BPoint(centerPoint(frame).x, frame.top); 449e5f9dfebSStefano Ceccherini points[2] = BPoint(frame.right, frame.bottom); 450e5f9dfebSStefano Ceccherini view->FillTriangle(points[0], points[1], points[2], gradient); 451e5f9dfebSStefano Ceccherini } 452e5f9dfebSStefano Ceccherini 45354730332SMichael Pfeiffer static void testStrokeTriangle(BView *view, BRect frame) 45454730332SMichael Pfeiffer { 45554730332SMichael Pfeiffer frame.InsetBy(2, 2); 45654730332SMichael Pfeiffer BPoint points[3]; 45754730332SMichael Pfeiffer points[0] = BPoint(frame.left, frame.bottom); 45854730332SMichael Pfeiffer points[1] = BPoint(centerPoint(frame).x, frame.top); 45954730332SMichael Pfeiffer points[2] = BPoint(frame.right, frame.bottom); 46054730332SMichael Pfeiffer view->StrokeTriangle(points[0], points[1], points[2]); 46154730332SMichael Pfeiffer } 46254730332SMichael Pfeiffer 46354730332SMichael Pfeiffer static void testStrokeLine(BView *view, BRect frame) 46454730332SMichael Pfeiffer { 46554730332SMichael Pfeiffer frame.InsetBy(2, 2); 46654730332SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top)); 46754730332SMichael Pfeiffer 46854730332SMichael Pfeiffer frame.top += 2; 46954730332SMichael Pfeiffer frame.bottom -= 2; 47082afdb09SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.bottom)); 47154730332SMichael Pfeiffer 47254730332SMichael Pfeiffer frame.bottom += 2;; 47354730332SMichael Pfeiffer frame.top = frame.bottom; 47454730332SMichael Pfeiffer view->StrokeLine(BPoint(frame.right, frame.top), BPoint(frame.left, frame.top)); 47582afdb09SMichael Pfeiffer } 47682afdb09SMichael Pfeiffer 47754730332SMichael Pfeiffer static void testFillShape(BView *view, BRect frame) 47882afdb09SMichael Pfeiffer { 47954730332SMichael Pfeiffer frame.InsetBy(2, 2); 48054730332SMichael Pfeiffer BShape shape; 48154730332SMichael Pfeiffer shape.MoveTo(BPoint(frame.left, frame.bottom)); 48254730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.top)); 48354730332SMichael Pfeiffer shape.LineTo(BPoint(frame.left, frame.top)); 48454730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.bottom)); 48554730332SMichael Pfeiffer view->FillShape(&shape); 48682afdb09SMichael Pfeiffer } 48782afdb09SMichael Pfeiffer 48854730332SMichael Pfeiffer static void testStrokeShape(BView *view, BRect frame) 48954730332SMichael Pfeiffer { 49054730332SMichael Pfeiffer frame.InsetBy(2, 2); 49154730332SMichael Pfeiffer BShape shape; 49254730332SMichael Pfeiffer shape.MoveTo(BPoint(frame.left, frame.bottom)); 49354730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.top)); 49454730332SMichael Pfeiffer shape.LineTo(BPoint(frame.left, frame.top)); 49554730332SMichael Pfeiffer shape.LineTo(BPoint(frame.right, frame.bottom)); 49654730332SMichael Pfeiffer view->StrokeShape(&shape); 49754730332SMichael Pfeiffer } 49854730332SMichael Pfeiffer 49954730332SMichael Pfeiffer static void testRecordPicture(BView *view, BRect frame) 50082afdb09SMichael Pfeiffer { 50182afdb09SMichael Pfeiffer BPicture *picture = new BPicture(); 50282afdb09SMichael Pfeiffer view->BeginPicture(picture); 50382afdb09SMichael Pfeiffer view->FillRect(frame); 50482afdb09SMichael Pfeiffer view->EndPicture(); 50582afdb09SMichael Pfeiffer delete picture; 50682afdb09SMichael Pfeiffer } 50782afdb09SMichael Pfeiffer 50854730332SMichael Pfeiffer static void testRecordAndPlayPicture(BView *view, BRect frame) 50982afdb09SMichael Pfeiffer { 51082afdb09SMichael Pfeiffer BPicture *picture = new BPicture(); 51182afdb09SMichael Pfeiffer view->BeginPicture(picture); 51282afdb09SMichael Pfeiffer frame.InsetBy(2, 2); 51382afdb09SMichael Pfeiffer view->FillRect(frame); 51482afdb09SMichael Pfeiffer view->EndPicture(); 51582afdb09SMichael Pfeiffer view->DrawPicture(picture); 51682afdb09SMichael Pfeiffer delete picture; 51782afdb09SMichael Pfeiffer } 51882afdb09SMichael Pfeiffer 51954730332SMichael Pfeiffer static void testRecordAndPlayPictureWithOffset(BView *view, BRect frame) 52082afdb09SMichael Pfeiffer { 52182afdb09SMichael Pfeiffer BPicture *picture = new BPicture(); 52282afdb09SMichael Pfeiffer view->BeginPicture(picture); 52382afdb09SMichael Pfeiffer frame.InsetBy(frame.Width() / 4, frame.Height() / 4); 52482afdb09SMichael Pfeiffer frame.OffsetTo(0, 0); 52582afdb09SMichael Pfeiffer view->FillRect(frame); 52682afdb09SMichael Pfeiffer view->EndPicture(); 52782afdb09SMichael Pfeiffer 52882afdb09SMichael Pfeiffer view->DrawPicture(picture, BPoint(10, 10)); 52982afdb09SMichael Pfeiffer // color of picture should not change 53054730332SMichael Pfeiffer view->SetLowColor(kGreen); 53154730332SMichael Pfeiffer view->SetLowColor(kRed); 53282afdb09SMichael Pfeiffer view->DrawPicture(picture, BPoint(0, 0)); 53382afdb09SMichael Pfeiffer delete picture; 53482afdb09SMichael Pfeiffer } 53582afdb09SMichael Pfeiffer 53654730332SMichael Pfeiffer static void testAppendToPicture(BView *view, BRect frame) 53754730332SMichael Pfeiffer { 53854730332SMichael Pfeiffer frame.InsetBy(2, 2); 53954730332SMichael Pfeiffer view->BeginPicture(new BPicture()); 54054730332SMichael Pfeiffer view->FillRect(frame); 54154730332SMichael Pfeiffer BPicture* picture = view->EndPicture(); 54254730332SMichael Pfeiffer if (picture == NULL) 54354730332SMichael Pfeiffer return; 54454730332SMichael Pfeiffer 54554730332SMichael Pfeiffer frame.InsetBy(2, 2); 54654730332SMichael Pfeiffer view->AppendToPicture(picture); 54754730332SMichael Pfeiffer view->SetHighColor(kRed); 54854730332SMichael Pfeiffer view->FillRect(frame); 54954730332SMichael Pfeiffer if (view->EndPicture() != picture) 55054730332SMichael Pfeiffer return; 55154730332SMichael Pfeiffer 55254730332SMichael Pfeiffer view->DrawPicture(picture); 55354730332SMichael Pfeiffer delete picture; 55454730332SMichael Pfeiffer } 55554730332SMichael Pfeiffer 5568247141fSMichael Pfeiffer static void testDrawScaledPicture(BView* view, BRect frame) 5578247141fSMichael Pfeiffer { 5588247141fSMichael Pfeiffer view->BeginPicture(new BPicture()); 5598247141fSMichael Pfeiffer view->FillRect(BRect(0, 0, 15, 15)); 5608247141fSMichael Pfeiffer BPicture* picture = view->EndPicture(); 5618247141fSMichael Pfeiffer 5628247141fSMichael Pfeiffer // first unscaled at left, top 5638247141fSMichael Pfeiffer view->DrawPicture(picture, BPoint(2, 2)); 5648247141fSMichael Pfeiffer 5658247141fSMichael Pfeiffer // draw scaled at middle top 5668247141fSMichael Pfeiffer view->SetScale(0.5); 5678247141fSMichael Pfeiffer // the drawing offset must be scaled too! 568ff973abcSMichael Pfeiffer view->DrawPicture(picture, BPoint(frame.Width(), 4)); 5698247141fSMichael Pfeiffer 5708247141fSMichael Pfeiffer delete picture; 5718247141fSMichael Pfeiffer } 5728247141fSMichael Pfeiffer 57354730332SMichael Pfeiffer static void testLineArray(BView *view, BRect frame) 57454730332SMichael Pfeiffer { 57554730332SMichael Pfeiffer frame.InsetBy(2, 2); 57654730332SMichael Pfeiffer view->BeginLineArray(3); 57754730332SMichael Pfeiffer view->AddLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top), kBlack); 57854730332SMichael Pfeiffer 57954730332SMichael Pfeiffer frame.top += 2; 58054730332SMichael Pfeiffer frame.bottom -= 2; 58154730332SMichael Pfeiffer view->AddLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.bottom), kRed); 58254730332SMichael Pfeiffer 58354730332SMichael Pfeiffer frame.bottom += 2;; 58454730332SMichael Pfeiffer frame.top = frame.bottom; 58554730332SMichael Pfeiffer view->AddLine(BPoint(frame.right, frame.top), BPoint(frame.left, frame.top), kGreen); 58654730332SMichael Pfeiffer 58754730332SMichael Pfeiffer view->EndLineArray(); 58854730332SMichael Pfeiffer } 58954730332SMichael Pfeiffer 59054730332SMichael Pfeiffer static void testInvertRect(BView *view, BRect frame) 59154730332SMichael Pfeiffer { 59254730332SMichael Pfeiffer frame.InsetBy(2, 2); 59354730332SMichael Pfeiffer view->InvertRect(frame); 59454730332SMichael Pfeiffer } 59554730332SMichael Pfeiffer 5967cf26360SStefano Ceccherini static void testInvertRectSetDrawingMode(BView *view, BRect frame) 5977cf26360SStefano Ceccherini { 5987cf26360SStefano Ceccherini view->SetDrawingMode(B_OP_ALPHA); 5997cf26360SStefano Ceccherini view->SetHighColor(128, 128, 128, 128); 6007cf26360SStefano Ceccherini frame.InsetBy(2, 2); 6017cf26360SStefano Ceccherini view->InvertRect(frame); 6027cf26360SStefano Ceccherini frame.InsetBy(10, 10); 6037cf26360SStefano Ceccherini view->FillRect(frame, B_SOLID_HIGH); 6047cf26360SStefano Ceccherini } 6057cf26360SStefano Ceccherini 6064f422578SMichael Pfeiffer static bool isBorder(int32 x, int32 y, int32 width, int32 height) { 6074f422578SMichael Pfeiffer return x == 0 || y == 0 || x == width - 1 || y == height - 1; 6084f422578SMichael Pfeiffer } 6094f422578SMichael Pfeiffer 6104f422578SMichael Pfeiffer static void fillBitmap(BBitmap &bitmap) { 6114f422578SMichael Pfeiffer int32 height = bitmap.Bounds().IntegerHeight()+1; 6124f422578SMichael Pfeiffer int32 width = bitmap.Bounds().IntegerWidth()+1; 6134f422578SMichael Pfeiffer for (int32 y = 0; y < height; y ++) { 6144f422578SMichael Pfeiffer for (int32 x = 0; x < width; x ++) { 61582afdb09SMichael Pfeiffer char *pixel = (char*)bitmap.Bits(); 61682afdb09SMichael Pfeiffer pixel += bitmap.BytesPerRow() * y + 4 * x; 6174f422578SMichael Pfeiffer if (isBorder(x, y, width, height)) { 6184f422578SMichael Pfeiffer // fill with green 6194f422578SMichael Pfeiffer pixel[0] = 255; 6204f422578SMichael Pfeiffer pixel[1] = 0; 6214f422578SMichael Pfeiffer pixel[2] = 255; 6224f422578SMichael Pfeiffer pixel[3] = 0; 6234f422578SMichael Pfeiffer } else { 62482afdb09SMichael Pfeiffer // fill with blue 62582afdb09SMichael Pfeiffer pixel[0] = 255; 62682afdb09SMichael Pfeiffer pixel[1] = 0; 62782afdb09SMichael Pfeiffer pixel[2] = 0; 62882afdb09SMichael Pfeiffer pixel[3] = 255; 62982afdb09SMichael Pfeiffer } 63082afdb09SMichael Pfeiffer } 6314f422578SMichael Pfeiffer } 6324f422578SMichael Pfeiffer } 6334f422578SMichael Pfeiffer 6344f422578SMichael Pfeiffer static void testDrawBitmap(BView *view, BRect frame) { 6354f422578SMichael Pfeiffer BBitmap bitmap(frame, B_RGBA32); 6364f422578SMichael Pfeiffer fillBitmap(bitmap); 63782afdb09SMichael Pfeiffer view->DrawBitmap(&bitmap, BPoint(0, 0)); 63882afdb09SMichael Pfeiffer } 63982afdb09SMichael Pfeiffer 6404f422578SMichael Pfeiffer static void testDrawBitmapAtPoint(BView *view, BRect frame) { 6414f422578SMichael Pfeiffer frame.InsetBy(2, 2); 6424f422578SMichael Pfeiffer 6434f422578SMichael Pfeiffer BRect bounds(frame); 6444f422578SMichael Pfeiffer bounds.OffsetTo(0, 0); 6454f422578SMichael Pfeiffer bounds.right /= 2; 6464f422578SMichael Pfeiffer bounds.bottom /= 2; 6474f422578SMichael Pfeiffer 6484f422578SMichael Pfeiffer BBitmap bitmap(bounds, B_RGBA32); 6494f422578SMichael Pfeiffer fillBitmap(bitmap); 6504f422578SMichael Pfeiffer view->DrawBitmap(&bitmap, centerPoint(frame)); 6514f422578SMichael Pfeiffer } 6524f422578SMichael Pfeiffer 6534f422578SMichael Pfeiffer static void testDrawBitmapAtRect(BView *view, BRect frame) { 6544f422578SMichael Pfeiffer BRect bounds(frame); 6554f422578SMichael Pfeiffer BBitmap bitmap(bounds, B_RGBA32); 6564f422578SMichael Pfeiffer fillBitmap(bitmap); 6574f422578SMichael Pfeiffer frame.InsetBy(2, 2); 6584f422578SMichael Pfeiffer view->DrawBitmap(&bitmap, frame); 6594f422578SMichael Pfeiffer } 6604f422578SMichael Pfeiffer 6614f422578SMichael Pfeiffer static void testDrawLargeBitmap(BView *view, BRect frame) { 6624f422578SMichael Pfeiffer BRect bounds(frame); 6634f422578SMichael Pfeiffer bounds.OffsetTo(0, 0); 6648247141fSMichael Pfeiffer bounds.right *= 4; 6658247141fSMichael Pfeiffer bounds.bottom *= 4; 6664f422578SMichael Pfeiffer BBitmap bitmap(bounds, B_RGBA32); 6674f422578SMichael Pfeiffer fillBitmap(bitmap); 6684f422578SMichael Pfeiffer frame.InsetBy(2, 2); 6694f422578SMichael Pfeiffer view->DrawBitmap(&bitmap, frame); 6704f422578SMichael Pfeiffer } 6714f422578SMichael Pfeiffer 672c43f0163SMichael Pfeiffer static void testConstrainClippingRegion(BView *view, BRect frame) 673c43f0163SMichael Pfeiffer { 674c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 675c43f0163SMichael Pfeiffer // draw background 676c43f0163SMichael Pfeiffer view->SetHighColor(kRed); 677c43f0163SMichael Pfeiffer view->FillRect(frame); 678c43f0163SMichael Pfeiffer 679c43f0163SMichael Pfeiffer frame.InsetBy(1, 1); 680c43f0163SMichael Pfeiffer BRegion region(frame); 681c43f0163SMichael Pfeiffer BRect r(frame); 682c43f0163SMichael Pfeiffer r.InsetBy(r.IntegerWidth() / 4, r.IntegerHeight() / 4); 683c43f0163SMichael Pfeiffer region.Exclude(r); 684c43f0163SMichael Pfeiffer view->ConstrainClippingRegion(®ion); 685c43f0163SMichael Pfeiffer 686c43f0163SMichael Pfeiffer frame.InsetBy(-1, -1); 687c43f0163SMichael Pfeiffer view->SetHighColor(kBlack); 688c43f0163SMichael Pfeiffer view->FillRect(frame); 689c43f0163SMichael Pfeiffer // a filled black rectangle with a red one pixel border 690c43f0163SMichael Pfeiffer // and inside a red rectangle should be drawn. 691c43f0163SMichael Pfeiffer } 692c43f0163SMichael Pfeiffer 693c43f0163SMichael Pfeiffer static void testClipToPicture(BView *view, BRect frame) 694c43f0163SMichael Pfeiffer { 695c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 696c43f0163SMichael Pfeiffer view->BeginPicture(new BPicture()); 697c43f0163SMichael Pfeiffer view->FillEllipse(frame); 698c43f0163SMichael Pfeiffer BPicture *picture = view->EndPicture(); 699c43f0163SMichael Pfeiffer if (picture == NULL) 700c43f0163SMichael Pfeiffer return; 701c43f0163SMichael Pfeiffer 702c43f0163SMichael Pfeiffer view->ClipToPicture(picture); 703c43f0163SMichael Pfeiffer delete picture; 704c43f0163SMichael Pfeiffer 705c43f0163SMichael Pfeiffer view->FillRect(frame); 706c43f0163SMichael Pfeiffer // black ellipse should be drawn 707c43f0163SMichael Pfeiffer } 708c43f0163SMichael Pfeiffer 709c43f0163SMichael Pfeiffer static void testClipToInversePicture(BView *view, BRect frame) 710c43f0163SMichael Pfeiffer { 711c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 712c43f0163SMichael Pfeiffer 713c43f0163SMichael Pfeiffer view->BeginPicture(new BPicture()); 714c43f0163SMichael Pfeiffer view->FillEllipse(frame); 715c43f0163SMichael Pfeiffer BPicture *picture = view->EndPicture(); 716c43f0163SMichael Pfeiffer if (picture == NULL) 717c43f0163SMichael Pfeiffer return; 718c43f0163SMichael Pfeiffer 719c43f0163SMichael Pfeiffer view->ClipToInversePicture(picture); 720c43f0163SMichael Pfeiffer delete picture; 721c43f0163SMichael Pfeiffer 722c43f0163SMichael Pfeiffer view->FillRect(frame); 723c43f0163SMichael Pfeiffer // white ellipse inside a black rectangle 724c43f0163SMichael Pfeiffer } 725c43f0163SMichael Pfeiffer 726c43f0163SMichael Pfeiffer static void testSetPenSize(BView *view, BRect frame) 727c43f0163SMichael Pfeiffer { 728c43f0163SMichael Pfeiffer frame.InsetBy(8, 2); 729c43f0163SMichael Pfeiffer float x = centerPoint(frame).x; 730c43f0163SMichael Pfeiffer 731c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top)); 732c43f0163SMichael Pfeiffer 733c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 734c43f0163SMichael Pfeiffer view->SetPenSize(1); 735c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 736c43f0163SMichael Pfeiffer view->SetPenSize(0); 737c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 738c43f0163SMichael Pfeiffer 739c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 740c43f0163SMichael Pfeiffer view->SetPenSize(1); 741c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 742c43f0163SMichael Pfeiffer view->SetPenSize(2); 743c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 744c43f0163SMichael Pfeiffer 745c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 746c43f0163SMichael Pfeiffer view->SetPenSize(1); 747c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 748c43f0163SMichael Pfeiffer view->SetPenSize(3); 749c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 750c43f0163SMichael Pfeiffer 751c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 752c43f0163SMichael Pfeiffer view->SetPenSize(1); 753c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top)); 754c43f0163SMichael Pfeiffer view->SetPenSize(4); 755c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top)); 756c43f0163SMichael Pfeiffer } 757c43f0163SMichael Pfeiffer 758c43f0163SMichael Pfeiffer static void testSetPenSize2(BView *view, BRect frame) 759c43f0163SMichael Pfeiffer { 760c43f0163SMichael Pfeiffer // test if pen size is scaled too 761c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 762c43f0163SMichael Pfeiffer frame.OffsetBy(0, 5); 763c43f0163SMichael Pfeiffer view->SetPenSize(4); 764c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top)); 765c43f0163SMichael Pfeiffer view->SetScale(0.5); 766c43f0163SMichael Pfeiffer view->StrokeLine(BPoint(frame.left + 2, frame.bottom), BPoint(frame.right + 2, frame.bottom)); 767c43f0163SMichael Pfeiffer 768c43f0163SMichael Pfeiffer // black line from left to right, 4 pixel size 769c43f0163SMichael Pfeiffer // below black line with half the length of the first one 770c43f0163SMichael Pfeiffer // and 2 pixel size 771c43f0163SMichael Pfeiffer } 772c43f0163SMichael Pfeiffer 773c43f0163SMichael Pfeiffer static void testPattern(BView *view, BRect frame) 774c43f0163SMichael Pfeiffer { 775c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 776c43f0163SMichael Pfeiffer int x = frame.IntegerWidth() / 3; 777c43f0163SMichael Pfeiffer frame.right = frame.left + x - 2; 778c43f0163SMichael Pfeiffer // -2 for an empty pixel row between 779c43f0163SMichael Pfeiffer // filled rectangles 780c43f0163SMichael Pfeiffer 781c43f0163SMichael Pfeiffer view->SetLowColor(kGreen); 782c43f0163SMichael Pfeiffer view->SetHighColor(kRed); 783c43f0163SMichael Pfeiffer 784c43f0163SMichael Pfeiffer view->FillRect(frame, B_SOLID_HIGH); 785c43f0163SMichael Pfeiffer 786c43f0163SMichael Pfeiffer frame.OffsetBy(x, 0); 787c43f0163SMichael Pfeiffer view->FillRect(frame, B_MIXED_COLORS); 788c43f0163SMichael Pfeiffer 789c43f0163SMichael Pfeiffer frame.OffsetBy(x, 0); 790c43f0163SMichael Pfeiffer view->FillRect(frame, B_SOLID_LOW); 791c43f0163SMichael Pfeiffer } 792c43f0163SMichael Pfeiffer 793c43f0163SMichael Pfeiffer static void testSetOrigin(BView *view, BRect frame) 794c43f0163SMichael Pfeiffer { 795c43f0163SMichael Pfeiffer BPoint origin = view->Origin(); 796c43f0163SMichael Pfeiffer BPoint center = centerPoint(frame); 797c43f0163SMichael Pfeiffer view->SetOrigin(center); 798c43f0163SMichael Pfeiffer 799c43f0163SMichael Pfeiffer BRect r(0, 0, center.x, center.y); 800c43f0163SMichael Pfeiffer view->SetHighColor(kBlue); 801c43f0163SMichael Pfeiffer view->FillRect(r); 802c43f0163SMichael Pfeiffer 803c43f0163SMichael Pfeiffer view->SetOrigin(origin); 804c43f0163SMichael Pfeiffer view->SetHighColor(kRed); 805c43f0163SMichael Pfeiffer view->FillRect(r); 806c43f0163SMichael Pfeiffer 807c43f0163SMichael Pfeiffer // red rectangle in left, top corner 808c43f0163SMichael Pfeiffer // blue rectangle in right, bottom corner 809c43f0163SMichael Pfeiffer // the red rectangle overwrites the 810c43f0163SMichael Pfeiffer // top, left pixel of the blue rectangle 811c43f0163SMichael Pfeiffer } 812c43f0163SMichael Pfeiffer 813c43f0163SMichael Pfeiffer static void testSetOrigin2(BView *view, BRect frame) 814c43f0163SMichael Pfeiffer { 815c43f0163SMichael Pfeiffer BPoint center = centerPoint(frame); 816c43f0163SMichael Pfeiffer BRect r(0, 0, center.x, center.y); 817c43f0163SMichael Pfeiffer view->SetOrigin(center); 818c43f0163SMichael Pfeiffer view->PushState(); 819c43f0163SMichael Pfeiffer view->SetOrigin(BPoint(-center.x, 0)); 820c43f0163SMichael Pfeiffer view->FillRect(r); 821c43f0163SMichael Pfeiffer view->PopState(); 822c43f0163SMichael Pfeiffer // black rectangle in left, bottom corner 823c43f0163SMichael Pfeiffer } 824c43f0163SMichael Pfeiffer 825c43f0163SMichael Pfeiffer static void testSetScale(BView *view, BRect frame) 826c43f0163SMichael Pfeiffer { 827c43f0163SMichael Pfeiffer view->SetScale(0.5); 828c43f0163SMichael Pfeiffer view->FillRect(frame); 829c43f0163SMichael Pfeiffer // black rectangle in left, top corner 830c43f0163SMichael Pfeiffer } 831c43f0163SMichael Pfeiffer 832c43f0163SMichael Pfeiffer static void testSetScale2(BView *view, BRect frame) 833c43f0163SMichael Pfeiffer { 834c43f0163SMichael Pfeiffer view->SetScale(0.5); 835c43f0163SMichael Pfeiffer view->PushState(); 836c43f0163SMichael Pfeiffer view->SetScale(0.5); 837c43f0163SMichael Pfeiffer view->FillRect(frame); 838c43f0163SMichael Pfeiffer view->PopState(); 839c43f0163SMichael Pfeiffer // black rectangle in left, top corner 840c43f0163SMichael Pfeiffer // with half the size of the rectangle 841c43f0163SMichael Pfeiffer // from test testSetScaling 842c43f0163SMichael Pfeiffer } 843c43f0163SMichael Pfeiffer 844c43f0163SMichael Pfeiffer static void testSetScale3(BView *view, BRect frame) 845c43f0163SMichael Pfeiffer { 846c43f0163SMichael Pfeiffer view->SetScale(0.5); 847c43f0163SMichael Pfeiffer view->PushState(); 848c43f0163SMichael Pfeiffer // if the second scale value differs slightly 849c43f0163SMichael Pfeiffer // the bug under BeOS R5 in testSetScale2 850c43f0163SMichael Pfeiffer // does not occur 851c43f0163SMichael Pfeiffer view->SetScale(0.5000001); 852c43f0163SMichael Pfeiffer view->FillRect(frame); 853c43f0163SMichael Pfeiffer view->PopState(); 854c43f0163SMichael Pfeiffer // black rectangle in left, top corner 855c43f0163SMichael Pfeiffer // with half the size of the rectangle 856c43f0163SMichael Pfeiffer // from test testSetScaling 857c43f0163SMichael Pfeiffer } 858c43f0163SMichael Pfeiffer 859c9c4a80aSMichael Pfeiffer static void testSetOriginAndScale(BView *view, BRect frame) 860c9c4a80aSMichael Pfeiffer { 861c9c4a80aSMichael Pfeiffer frame.InsetBy(2, 2); 862c9c4a80aSMichael Pfeiffer BPoint center = centerPoint(frame); 863c9c4a80aSMichael Pfeiffer 864c9c4a80aSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 865c9c4a80aSMichael Pfeiffer view->SetOrigin(center); 866c9c4a80aSMichael Pfeiffer view->FillRect(r); 867c9c4a80aSMichael Pfeiffer 868c9c4a80aSMichael Pfeiffer view->SetScale(0.5); 869c9c4a80aSMichael Pfeiffer view->SetHighColor(kRed); 870c9c4a80aSMichael Pfeiffer view->FillRect(r); 871c9c4a80aSMichael Pfeiffer } 872c9c4a80aSMichael Pfeiffer 8734b05331dSMichael Pfeiffer static void testSetOriginAndScale2(BView *view, BRect frame) 8744b05331dSMichael Pfeiffer { 8754b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 8764b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 8774b05331dSMichael Pfeiffer 8784b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 8794b05331dSMichael Pfeiffer view->SetOrigin(center); 8804b05331dSMichael Pfeiffer view->FillRect(r); 8814b05331dSMichael Pfeiffer 8824b05331dSMichael Pfeiffer view->SetScale(0.5); 8834b05331dSMichael Pfeiffer view->SetHighColor(kRed); 8844b05331dSMichael Pfeiffer view->FillRect(r); 8854b05331dSMichael Pfeiffer 8864b05331dSMichael Pfeiffer view->SetOrigin(0, 0); 8874b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 8884b05331dSMichael Pfeiffer view->FillRect(r); 8894b05331dSMichael Pfeiffer } 8904b05331dSMichael Pfeiffer 8914b05331dSMichael Pfeiffer static void testSetOriginAndScale3(BView *view, BRect frame) 8924b05331dSMichael Pfeiffer { 8934b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 8944b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 8954b05331dSMichael Pfeiffer 8964b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 8974b05331dSMichael Pfeiffer view->SetOrigin(center); 8984b05331dSMichael Pfeiffer view->FillRect(r); 8994b05331dSMichael Pfeiffer 9004b05331dSMichael Pfeiffer view->SetScale(0.5); 9014b05331dSMichael Pfeiffer view->SetHighColor(kRed); 9024b05331dSMichael Pfeiffer view->FillRect(r); 9034b05331dSMichael Pfeiffer 9044b05331dSMichael Pfeiffer view->SetScale(0.25); 9054b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 9064b05331dSMichael Pfeiffer view->FillRect(r); 9074b05331dSMichael Pfeiffer } 9084b05331dSMichael Pfeiffer 9094b05331dSMichael Pfeiffer static void testSetOriginAndScale4(BView *view, BRect frame) 9104b05331dSMichael Pfeiffer { 9114b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 9124b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 9134b05331dSMichael Pfeiffer 9144b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 9154b05331dSMichael Pfeiffer view->SetOrigin(center); 9164b05331dSMichael Pfeiffer view->FillRect(r); 9174b05331dSMichael Pfeiffer 9184b05331dSMichael Pfeiffer view->SetScale(0.5); 9194b05331dSMichael Pfeiffer view->SetHighColor(kRed); 9204b05331dSMichael Pfeiffer view->FillRect(r); 9214b05331dSMichael Pfeiffer 9224b05331dSMichael Pfeiffer view->PushState(); 9234b05331dSMichael Pfeiffer // 9244b05331dSMichael Pfeiffer view->SetOrigin(center.x+1, center.y); 9254b05331dSMichael Pfeiffer // +1 to work around BeOS bug 9264b05331dSMichael Pfeiffer // where setting the origin has no 9274b05331dSMichael Pfeiffer // effect if it is the same as 9284b05331dSMichael Pfeiffer // the previous value althou 9294b05331dSMichael Pfeiffer // it is from the "outer" coordinate 9304b05331dSMichael Pfeiffer // system 9314b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 9324b05331dSMichael Pfeiffer view->FillRect(r); 9334b05331dSMichael Pfeiffer view->PopState(); 9344b05331dSMichael Pfeiffer } 9354b05331dSMichael Pfeiffer 9364b05331dSMichael Pfeiffer static void testSetOriginAndScale5(BView *view, BRect frame) 9374b05331dSMichael Pfeiffer { 9384b05331dSMichael Pfeiffer frame.InsetBy(2, 2); 9394b05331dSMichael Pfeiffer BPoint center = centerPoint(frame); 9404b05331dSMichael Pfeiffer 9414b05331dSMichael Pfeiffer BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2); 9424b05331dSMichael Pfeiffer view->SetOrigin(center); 9434b05331dSMichael Pfeiffer view->FillRect(r); 9444b05331dSMichael Pfeiffer 9454b05331dSMichael Pfeiffer view->SetScale(0.5); 9464b05331dSMichael Pfeiffer view->SetHighColor(kRed); 9474b05331dSMichael Pfeiffer view->FillRect(r); 9484b05331dSMichael Pfeiffer 9494b05331dSMichael Pfeiffer view->PushState(); 9504b05331dSMichael Pfeiffer view->SetScale(0.75); 9514b05331dSMichael Pfeiffer view->SetHighColor(kGreen); 9524b05331dSMichael Pfeiffer view->FillRect(r); 9534b05331dSMichael Pfeiffer view->PopState(); 9544b05331dSMichael Pfeiffer } 9554b05331dSMichael Pfeiffer 956c43f0163SMichael Pfeiffer static void testSetFontSize(BView *view, BRect frame) 957c43f0163SMichael Pfeiffer { 958c43f0163SMichael Pfeiffer frame.InsetBy(2, 2); 959c43f0163SMichael Pfeiffer int size = frame.IntegerHeight() / 3; 960c43f0163SMichael Pfeiffer 961c43f0163SMichael Pfeiffer frame.OffsetBy(0, size); 962c43f0163SMichael Pfeiffer view->MovePenTo(BPoint(frame.left, frame.top)); 963c43f0163SMichael Pfeiffer view->SetFontSize(size); 964c43f0163SMichael Pfeiffer view->DrawString("Haiku"); 965c43f0163SMichael Pfeiffer 966c43f0163SMichael Pfeiffer size *= 2; 967c43f0163SMichael Pfeiffer frame.OffsetBy(0, size); 968c43f0163SMichael Pfeiffer view->MovePenTo(BPoint(frame.left, frame.top)); 969c43f0163SMichael Pfeiffer view->SetFontSize(size); 970c43f0163SMichael Pfeiffer view->DrawString("Haiku"); 971c43f0163SMichael Pfeiffer } 972c43f0163SMichael Pfeiffer 9732fb98dccSStefano Ceccherini static void testSetFontFamilyAndStyle(BView *view, BRect frame) 9742fb98dccSStefano Ceccherini { 9752fb98dccSStefano Ceccherini view->DrawString("This is a test", BPoint(2, 6)); 9762fb98dccSStefano Ceccherini 9772fb98dccSStefano Ceccherini BFont font; 9782fb98dccSStefano Ceccherini view->GetFont(&font); 9792fb98dccSStefano Ceccherini 9802fb98dccSStefano Ceccherini int32 families = count_font_families(); 9812fb98dccSStefano Ceccherini font_family familyName; 9822fb98dccSStefano Ceccherini get_font_family(families - 1, &familyName); 9832fb98dccSStefano Ceccherini 9842fb98dccSStefano Ceccherini int32 styles = count_font_styles(familyName); 9852fb98dccSStefano Ceccherini font_style styleName; 9862fb98dccSStefano Ceccherini get_font_style(familyName, styles - 1, &styleName); 9872fb98dccSStefano Ceccherini font.SetFamilyAndStyle(familyName, styleName); 9882fb98dccSStefano Ceccherini view->SetFont(&font); 9892fb98dccSStefano Ceccherini view->DrawString( "This is a test", BPoint(2, 19)); 9902fb98dccSStefano Ceccherini } 9912fb98dccSStefano Ceccherini 99215cf50e0SStefano Ceccherini static void testSetDrawingMode(BView *view, BRect frame) 99315cf50e0SStefano Ceccherini { 994ed70c5f3SStefano Ceccherini frame.InsetBy(2, 2); 99515cf50e0SStefano Ceccherini view->StrokeLine(frame.LeftTop(), frame.RightBottom()); 99615cf50e0SStefano Ceccherini view->StrokeLine(frame.LeftBottom(), frame.RightTop()); 99715cf50e0SStefano Ceccherini view->SetDrawingMode(B_OP_ALPHA); 99815cf50e0SStefano Ceccherini rgb_color color = kRed; 99915cf50e0SStefano Ceccherini color.alpha = 127; 100015cf50e0SStefano Ceccherini view->SetHighColor(color); 100115cf50e0SStefano Ceccherini view->FillRect(frame, B_SOLID_HIGH); 100215cf50e0SStefano Ceccherini } 100315cf50e0SStefano Ceccherini 1004ed70c5f3SStefano Ceccherini static void testPushPopState(BView *view, BRect frame) 1005ed70c5f3SStefano Ceccherini { 1006ed70c5f3SStefano Ceccherini frame.InsetBy(2, 2); 1007ed70c5f3SStefano Ceccherini view->SetHighColor(kGreen); 1008ed70c5f3SStefano Ceccherini view->PushState(); 1009ed70c5f3SStefano Ceccherini view->SetHighColor(kRed); 1010ed70c5f3SStefano Ceccherini view->PopState(); 1011ed70c5f3SStefano Ceccherini 1012ed70c5f3SStefano Ceccherini view->FillRect(frame, B_SOLID_HIGH); 1013ed70c5f3SStefano Ceccherini } 1014ed70c5f3SStefano Ceccherini 10158247141fSMichael Pfeiffer static void testFontRotation(BView* view, BRect frame) 10168247141fSMichael Pfeiffer { 10178247141fSMichael Pfeiffer BFont font; 10188247141fSMichael Pfeiffer view->GetFont(&font); 10198247141fSMichael Pfeiffer 10208247141fSMichael Pfeiffer font.SetRotation(90); 10218247141fSMichael Pfeiffer view->SetFont(&font, B_FONT_ROTATION); 10228247141fSMichael Pfeiffer view->DrawString("This is a test!", BPoint(frame.Width() / 2, frame.bottom - 3)); 10238247141fSMichael Pfeiffer 10248247141fSMichael Pfeiffer view->GetFont(&font); 10258247141fSMichael Pfeiffer if (font.Rotation() != 90.0) 10268247141fSMichael Pfeiffer fprintf(stderr, "Error: Rotation is %f but should be 90.0\n", font.Rotation()); 10278247141fSMichael Pfeiffer } 102815cf50e0SStefano Ceccherini 1029abf565b1SStefano Ceccherini 1030*59a26ab6SJackBurton79 static void testClipToRect(BView* view, BRect frame) 1031*59a26ab6SJackBurton79 { 1032*59a26ab6SJackBurton79 BRect clipped = frame; 1033*59a26ab6SJackBurton79 clipped.InsetBy(5, 5); 1034*59a26ab6SJackBurton79 1035*59a26ab6SJackBurton79 view->ClipToRect(clipped); 1036*59a26ab6SJackBurton79 1037*59a26ab6SJackBurton79 view->FillRect(frame); 1038*59a26ab6SJackBurton79 } 1039*59a26ab6SJackBurton79 1040*59a26ab6SJackBurton79 1041*59a26ab6SJackBurton79 static void testClipToInverseRect(BView* view, BRect frame) 1042*59a26ab6SJackBurton79 { 1043*59a26ab6SJackBurton79 BRect clipped = frame; 1044*59a26ab6SJackBurton79 clipped.InsetBy(5, 5); 1045*59a26ab6SJackBurton79 1046*59a26ab6SJackBurton79 view->ClipToInverseRect(clipped); 1047*59a26ab6SJackBurton79 1048*59a26ab6SJackBurton79 view->FillRect(frame); 1049*59a26ab6SJackBurton79 } 1050*59a26ab6SJackBurton79 1051*59a26ab6SJackBurton79 1052*59a26ab6SJackBurton79 static void testClipToShape(BView* view, BRect frame) 1053*59a26ab6SJackBurton79 { 1054*59a26ab6SJackBurton79 frame.InsetBy(2, 2); 1055*59a26ab6SJackBurton79 BShape shape; 1056*59a26ab6SJackBurton79 shape.MoveTo(BPoint(frame.left, frame.bottom)); 1057*59a26ab6SJackBurton79 shape.LineTo(BPoint(frame.right, frame.top)); 1058*59a26ab6SJackBurton79 shape.LineTo(BPoint(frame.left, frame.top)); 1059*59a26ab6SJackBurton79 shape.LineTo(BPoint(frame.right, frame.bottom)); 1060*59a26ab6SJackBurton79 view->ClipToShape(&shape); 1061*59a26ab6SJackBurton79 1062*59a26ab6SJackBurton79 view->FillRect(frame); 1063*59a26ab6SJackBurton79 } 1064*59a26ab6SJackBurton79 1065*59a26ab6SJackBurton79 1066*59a26ab6SJackBurton79 static void testClipToInverseShape(BView* view, BRect frame) 1067*59a26ab6SJackBurton79 { 1068*59a26ab6SJackBurton79 frame.InsetBy(2, 2); 1069*59a26ab6SJackBurton79 BShape shape; 1070*59a26ab6SJackBurton79 shape.MoveTo(BPoint(frame.left, frame.bottom)); 1071*59a26ab6SJackBurton79 shape.LineTo(BPoint(frame.right, frame.top)); 1072*59a26ab6SJackBurton79 shape.LineTo(BPoint(frame.left, frame.top)); 1073*59a26ab6SJackBurton79 shape.LineTo(BPoint(frame.right, frame.bottom)); 1074*59a26ab6SJackBurton79 view->ClipToInverseShape(&shape); 1075*59a26ab6SJackBurton79 1076*59a26ab6SJackBurton79 view->FillRect(frame); 1077*59a26ab6SJackBurton79 } 1078abf565b1SStefano Ceccherini 1079abf565b1SStefano Ceccherini 1080c43f0163SMichael Pfeiffer // TODO 1081c43f0163SMichael Pfeiffer // - blending mode 1082c43f0163SMichael Pfeiffer // - line mode 1083c43f0163SMichael Pfeiffer // - push/pop state 1084c43f0163SMichael Pfeiffer // - move pen 1085c43f0163SMichael Pfeiffer // - set font 1086c43f0163SMichael Pfeiffer 1087c43f0163SMichael Pfeiffer 108882afdb09SMichael Pfeiffer TestCase gTestCases[] = { 108954730332SMichael Pfeiffer { "Test No Operation", testNoOp }, 109054730332SMichael Pfeiffer { "Test DrawChar", testDrawChar }, 109182afdb09SMichael Pfeiffer { "Test Draw String", testDrawString }, 109254730332SMichael Pfeiffer { "Test Draw String With Length", testDrawStringWithLength }, 1093abf565b1SStefano Ceccherini { "Test Draw String With Offsets", testDrawStringWithOffsets }, 10943211dcccSJackBurton79 { "Test Draw String Without Position", testDrawStringWithoutPosition }, 109554730332SMichael Pfeiffer { "Test FillArc", testFillArc }, 109654730332SMichael Pfeiffer { "Test StrokeArc", testStrokeArc }, 1097c43f0163SMichael Pfeiffer // testFillBezier fails under BeOS because the 1098c43f0163SMichael Pfeiffer // direct draw version is not correct 109954730332SMichael Pfeiffer { "Test FillBezier", testFillBezier }, 110054730332SMichael Pfeiffer { "Test StrokeBezier", testStrokeBezier }, 110154730332SMichael Pfeiffer { "Test FillEllipse", testFillEllipse }, 110254730332SMichael Pfeiffer { "Test StrokeEllipse", testStrokeEllipse }, 110354730332SMichael Pfeiffer { "Test FillPolygon", testFillPolygon }, 110454730332SMichael Pfeiffer { "Test StrokePolygon", testStrokePolygon }, 110554730332SMichael Pfeiffer { "Test FillRect", testFillRect }, 1106abf565b1SStefano Ceccherini { "Test FillRectGradientLinear", testFillRectGradientLinear }, 1107abf565b1SStefano Ceccherini { "Test FillRectGradientRadial", testFillRectGradientRadial }, 1108abf565b1SStefano Ceccherini { "Test FillRectGradientRadialFocus", testFillRectGradientRadialFocus }, 1109abf565b1SStefano Ceccherini { "Test FillRectGradientDiamond", testFillRectGradientDiamond }, 1110abf565b1SStefano Ceccherini { "Test FillRectGradientConic", testFillRectGradientConic }, 111154730332SMichael Pfeiffer { "Test StrokeRect", testStrokeRect }, 111254730332SMichael Pfeiffer { "Test FillRegion", testFillRegion }, 1113b8c65995SStefano Ceccherini { "Test FillRegionGradientLinear", testFillRegionGradientLinear }, 1114b8c65995SStefano Ceccherini { "Test FillRegionGradientRadial", testFillRegionGradientRadial }, 1115b8c65995SStefano Ceccherini { "Test FillRegionGradientRadialFocus", testFillRegionGradientRadialFocus }, 1116b8c65995SStefano Ceccherini { "Test FillRegionGradientDiamond", testFillRegionGradientDiamond }, 1117b8c65995SStefano Ceccherini { "Test FillRegionGradientConic", testFillRegionGradientConic }, 111854730332SMichael Pfeiffer { "Test FillRoundRect", testFillRoundRect }, 111900c573d6SStefano Ceccherini { "Test FillRoundRectGradientLinear", testFillRoundRectGradientLinear }, 112000c573d6SStefano Ceccherini { "Test FillRoundRectGradientRadial", testFillRoundRectGradientRadial }, 112100c573d6SStefano Ceccherini { "Test FillRoundRectGradientRadialFocus", testFillRoundRectGradientRadialFocus }, 112200c573d6SStefano Ceccherini { "Test FillRoundRectGradientDiamond", testFillRoundRectGradientDiamond }, 112300c573d6SStefano Ceccherini { "Test FillRoundRectGradientConic", testFillRoundRectGradientConic }, 112454730332SMichael Pfeiffer { "Test StrokeRoundRect", testStrokeRoundRect }, 112554730332SMichael Pfeiffer { "Test FillTriangle", testFillTriangle }, 1126e5f9dfebSStefano Ceccherini { "Test FillTriangleGradientLinear", testFillTriangleGradientLinear }, 1127e5f9dfebSStefano Ceccherini { "Test FillTriangleGradientRadial", testFillTriangleGradientRadial }, 1128e5f9dfebSStefano Ceccherini { "Test FillTriangleGradientRadialFocus", testFillTriangleGradientRadialFocus }, 1129e5f9dfebSStefano Ceccherini { "Test FillTriangleGradientDiamond", testFillTriangleGradientDiamond }, 1130e5f9dfebSStefano Ceccherini { "Test FillTriangleGradientConic", testFillTriangleGradientConic }, 113154730332SMichael Pfeiffer { "Test StrokeTriangle", testStrokeTriangle }, 113254730332SMichael Pfeiffer { "Test StrokeLine", testStrokeLine }, 113354730332SMichael Pfeiffer { "Test FillShape", testFillShape }, 113454730332SMichael Pfeiffer { "Test StrokeShape", testStrokeShape }, 113582afdb09SMichael Pfeiffer { "Test Record Picture", testRecordPicture }, 113682afdb09SMichael Pfeiffer { "Test Record And Play Picture", testRecordAndPlayPicture }, 113782afdb09SMichael Pfeiffer { "Test Record And Play Picture With Offset", testRecordAndPlayPictureWithOffset }, 113854730332SMichael Pfeiffer { "Test AppendToPicture", testAppendToPicture }, 11398247141fSMichael Pfeiffer { "Test Draw Scaled Picture", testDrawScaledPicture }, 114054730332SMichael Pfeiffer { "Test LineArray", testLineArray }, 114154730332SMichael Pfeiffer { "Test InvertRect", testInvertRect }, 11427cf26360SStefano Ceccherini { "Test InvertRectSetDrawingMode", testInvertRectSetDrawingMode }, 11434f422578SMichael Pfeiffer { "Test DrawBitmap", testDrawBitmap }, 11444f422578SMichael Pfeiffer { "Test DrawBitmapAtPoint", testDrawBitmapAtPoint }, 11454f422578SMichael Pfeiffer { "Test DrawBitmapAtRect", testDrawBitmapAtRect }, 11465f380e34SMichael Pfeiffer { "Test DrawLargeBitmap", testDrawLargeBitmap }, 1147c43f0163SMichael Pfeiffer { "Test ConstrainClippingRegion", testConstrainClippingRegion }, 1148c43f0163SMichael Pfeiffer { "Test ClipToPicture", testClipToPicture }, 1149c43f0163SMichael Pfeiffer { "Test ClipToInversePicture", testClipToInversePicture }, 1150*59a26ab6SJackBurton79 { "Test ClipToRect", testClipToRect }, 1151*59a26ab6SJackBurton79 { "Test ClipToInverseRect", testClipToInverseRect }, 1152*59a26ab6SJackBurton79 { "Test ClipToShape", testClipToShape }, 1153*59a26ab6SJackBurton79 { "Test ClipToInverseShape", testClipToInverseShape }, 1154c43f0163SMichael Pfeiffer { "Test SetPenSize", testSetPenSize }, 1155c43f0163SMichael Pfeiffer { "Test SetPenSize2", testSetPenSize2 }, 1156c43f0163SMichael Pfeiffer { "Test Pattern", testPattern }, 1157c43f0163SMichael Pfeiffer { "Test SetOrigin", testSetOrigin }, 1158c43f0163SMichael Pfeiffer { "Test SetOrigin2", testSetOrigin2 }, 1159c43f0163SMichael Pfeiffer { "Test SetScale", testSetScale }, 1160c43f0163SMichael Pfeiffer // testSetScale2 fails under BeOS. The picture versions of the 1161c43f0163SMichael Pfeiffer // rectangle are twice as large as the direct draw version 1162b8c65995SStefano Ceccherini { "Test SetScale2", testSetScale2 }, 1163c43f0163SMichael Pfeiffer { "Test SetScale3", testSetScale3 }, 1164c9c4a80aSMichael Pfeiffer { "Test SetOriginAndScale", testSetOriginAndScale }, 11654b05331dSMichael Pfeiffer { "Test SetOriginAndScale2", testSetOriginAndScale2 }, 11664b05331dSMichael Pfeiffer { "Test SetOriginAndScale3", testSetOriginAndScale3 }, 11674b05331dSMichael Pfeiffer { "Test SetOriginAndScale4", testSetOriginAndScale4 }, 11684b05331dSMichael Pfeiffer { "Test SetOriginAndScale5", testSetOriginAndScale5 }, 1169c43f0163SMichael Pfeiffer { "Test SetFontSize", testSetFontSize }, 11702fb98dccSStefano Ceccherini { "Test SetFontFamilyAndStyle", testSetFontFamilyAndStyle }, 117115cf50e0SStefano Ceccherini { "Test SetDrawingMode", testSetDrawingMode }, 1172ed70c5f3SStefano Ceccherini { "Test PushPopState", testPushPopState }, 11738247141fSMichael Pfeiffer { "Test FontRotation", testFontRotation }, 117482afdb09SMichael Pfeiffer { NULL, NULL } 117582afdb09SMichael Pfeiffer }; 117662c7fd0fSMichael Pfeiffer 11772fb98dccSStefano Ceccherini 1178