xref: /haiku/src/tests/kits/interface/flatten_picture/PictureTestCases.cpp (revision b070314f50636b69267f3e4c7a0a1b6d2d4fbfbf)
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 
centerPoint(BRect rect)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 
testNoOp(BView * view,BRect frame)3254730332SMichael Pfeiffer static void testNoOp(BView *view, BRect frame)
3382afdb09SMichael Pfeiffer {
3482afdb09SMichael Pfeiffer 	// no op
3582afdb09SMichael Pfeiffer }
3682afdb09SMichael Pfeiffer 
testDrawChar(BView * view,BRect frame)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 
testDrawString(BView * view,BRect frame)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 
testDrawStringWithLength(BView * view,BRect frame)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 
testDrawStringWithOffsets(BView * view,BRect frame)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);
88*b070314fSJackBurton79 	BPoint point(frame.left, baseline);
89*b070314fSJackBurton79 	BPoint pointArray[] = {
90*b070314fSJackBurton79 		point,
91*b070314fSJackBurton79 		point,
92*b070314fSJackBurton79 		point,
93*b070314fSJackBurton79 		point,
94*b070314fSJackBurton79 		point
95*b070314fSJackBurton79 	};
96*b070314fSJackBurton79 
97*b070314fSJackBurton79 	for (size_t i = 1; i < (sizeof(pointArray) / sizeof(pointArray[0])); i++)
98*b070314fSJackBurton79 		pointArray[i] = pointArray[i - 1] + BPoint(10, 0);
99*b070314fSJackBurton79 
100*b070314fSJackBurton79 	view->DrawString("Haiku", pointArray, sizeof(pointArray) / sizeof(pointArray[0]));
101abf565b1SStefano Ceccherini }
102abf565b1SStefano Ceccherini 
103abf565b1SStefano Ceccherini 
testDrawStringWithoutPosition(BView * view,BRect frame)1043211dcccSJackBurton79 static void testDrawStringWithoutPosition(BView* view, BRect frame)
1053211dcccSJackBurton79 {
1063211dcccSJackBurton79 	BFont font;
1073211dcccSJackBurton79 	view->GetFont(&font);
1083211dcccSJackBurton79 	font_height height;
1093211dcccSJackBurton79 	font.GetHeight(&height);
1103211dcccSJackBurton79 	float baseline = frame.bottom - height.descent;
1113211dcccSJackBurton79 	// draw base line
1123211dcccSJackBurton79 	view->SetHighColor(kGreen);
1133211dcccSJackBurton79 	view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1));
1143211dcccSJackBurton79 
1153211dcccSJackBurton79 	view->SetHighColor(kBlack);
1163211dcccSJackBurton79 	view->MovePenTo(BPoint(frame.left, baseline));
1173211dcccSJackBurton79 	view->DrawString("H");
1183211dcccSJackBurton79 	view->DrawString("a");
1193211dcccSJackBurton79 	view->DrawString("i");
1203211dcccSJackBurton79 	view->DrawString("k");
1213211dcccSJackBurton79 	view->DrawString("u");
1223211dcccSJackBurton79 }
1233211dcccSJackBurton79 
1243211dcccSJackBurton79 
testFillArc(BView * view,BRect frame)12554730332SMichael Pfeiffer static void testFillArc(BView *view, BRect frame)
12682afdb09SMichael Pfeiffer {
12782afdb09SMichael Pfeiffer 	frame.InsetBy(2, 2);
12854730332SMichael Pfeiffer 	view->FillArc(frame, 45, 180);
12954730332SMichael Pfeiffer }
13054730332SMichael Pfeiffer 
testStrokeArc(BView * view,BRect frame)13154730332SMichael Pfeiffer static void testStrokeArc(BView *view, BRect frame)
13254730332SMichael Pfeiffer {
13354730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
13454730332SMichael Pfeiffer 	view->StrokeArc(frame, 45, 180);
13554730332SMichael Pfeiffer }
13654730332SMichael Pfeiffer 
testFillBezier(BView * view,BRect frame)13754730332SMichael Pfeiffer static void testFillBezier(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->FillBezier(points);
14654730332SMichael Pfeiffer }
14754730332SMichael Pfeiffer 
testStrokeBezier(BView * view,BRect frame)14854730332SMichael Pfeiffer static void testStrokeBezier(BView *view, BRect frame)
14954730332SMichael Pfeiffer {
15054730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
15154730332SMichael Pfeiffer 	BPoint points[4];
15254730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.bottom);
15354730332SMichael Pfeiffer 	points[1] = BPoint(frame.left, frame.top);
15454730332SMichael Pfeiffer 	points[1] = BPoint(frame.left, frame.top);
15554730332SMichael Pfeiffer 	points[3] = BPoint(frame.right, frame.top);
15654730332SMichael Pfeiffer 	view->StrokeBezier(points);
15754730332SMichael Pfeiffer }
15854730332SMichael Pfeiffer 
testFillEllipse(BView * view,BRect frame)15954730332SMichael Pfeiffer static void testFillEllipse(BView *view, BRect frame)
16054730332SMichael Pfeiffer {
16154730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
16254730332SMichael Pfeiffer 	view->FillEllipse(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->FillEllipse(centerPoint(frame), r, s);
16854730332SMichael Pfeiffer }
16954730332SMichael Pfeiffer 
testStrokeEllipse(BView * view,BRect frame)17054730332SMichael Pfeiffer static void testStrokeEllipse(BView *view, BRect frame)
17154730332SMichael Pfeiffer {
17254730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
17354730332SMichael Pfeiffer 	view->StrokeEllipse(frame);
17454730332SMichael Pfeiffer 
17554730332SMichael Pfeiffer 	view->SetHighColor(kRed);
17654730332SMichael Pfeiffer 	float r = frame.Width() / 3;
17754730332SMichael Pfeiffer 	float s = frame.Height() / 4;
17854730332SMichael Pfeiffer 	view->StrokeEllipse(centerPoint(frame), r, s);
17954730332SMichael Pfeiffer }
18054730332SMichael Pfeiffer 
testFillPolygon(BView * view,BRect frame)18154730332SMichael Pfeiffer static void testFillPolygon(BView *view, BRect frame)
18254730332SMichael Pfeiffer {
18354730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
18454730332SMichael Pfeiffer 
18554730332SMichael Pfeiffer 	BPoint points[4];
18654730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.top);
18754730332SMichael Pfeiffer 	points[1] = BPoint(frame.right, frame.bottom);
18854730332SMichael Pfeiffer 	points[2] = BPoint(frame.right, frame.top);
18954730332SMichael Pfeiffer 	points[3] = BPoint(frame.left, frame.bottom);
19054730332SMichael Pfeiffer 
19154730332SMichael Pfeiffer 	view->FillPolygon(points, 4);
19254730332SMichael Pfeiffer }
19354730332SMichael Pfeiffer 
testStrokePolygon(BView * view,BRect frame)19454730332SMichael Pfeiffer static void testStrokePolygon(BView *view, BRect frame)
19554730332SMichael Pfeiffer {
19654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
19754730332SMichael Pfeiffer 
19854730332SMichael Pfeiffer 	BPoint points[4];
19954730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.top);
20054730332SMichael Pfeiffer 	points[1] = BPoint(frame.right, frame.bottom);
20154730332SMichael Pfeiffer 	points[2] = BPoint(frame.right, frame.top);
20254730332SMichael Pfeiffer 	points[3] = BPoint(frame.left, frame.bottom);
20354730332SMichael Pfeiffer 
20454730332SMichael Pfeiffer 	view->StrokePolygon(points, 4);
20554730332SMichael Pfeiffer }
20654730332SMichael Pfeiffer 
testFillRect(BView * view,BRect frame)20754730332SMichael Pfeiffer static void testFillRect(BView *view, BRect frame)
20854730332SMichael Pfeiffer {
20954730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
21082afdb09SMichael Pfeiffer 	view->FillRect(frame);
21182afdb09SMichael Pfeiffer }
21282afdb09SMichael Pfeiffer 
testFillRectGradientLinear(BView * view,BRect frame)213abf565b1SStefano Ceccherini static void testFillRectGradientLinear(BView* view, BRect frame)
214abf565b1SStefano Ceccherini {
215abf565b1SStefano Ceccherini 	BGradientLinear gradient(0, 0, frame.right, frame.bottom);
216abf565b1SStefano Ceccherini 	gradient.AddColor(kRed, 0);
217abf565b1SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
218abf565b1SStefano Ceccherini 	frame.InsetBy(2, 2);
219abf565b1SStefano Ceccherini 	view->FillRect(frame, gradient);
220abf565b1SStefano Ceccherini }
221abf565b1SStefano Ceccherini 
testFillRectGradientRadial(BView * view,BRect frame)222abf565b1SStefano Ceccherini static void testFillRectGradientRadial(BView* view, BRect frame)
223abf565b1SStefano Ceccherini {
224abf565b1SStefano Ceccherini 	BGradientRadial gradient(10, 10, 10);
225abf565b1SStefano Ceccherini 	gradient.AddColor(kRed, 0);
226abf565b1SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
227abf565b1SStefano Ceccherini 	frame.InsetBy(2, 2);
228abf565b1SStefano Ceccherini 	view->FillRect(frame, gradient);
229abf565b1SStefano Ceccherini }
230abf565b1SStefano Ceccherini 
testFillRectGradientRadialFocus(BView * view,BRect frame)231abf565b1SStefano Ceccherini static void testFillRectGradientRadialFocus(BView* view, BRect frame)
232abf565b1SStefano Ceccherini {
233abf565b1SStefano Ceccherini 	BGradientRadialFocus gradient(0, 0, 10, 10, 5);
234abf565b1SStefano Ceccherini 	gradient.AddColor(kRed, 0);
235abf565b1SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
236abf565b1SStefano Ceccherini 	frame.InsetBy(2, 2);
237abf565b1SStefano Ceccherini 	view->FillRect(frame, gradient);
238abf565b1SStefano Ceccherini }
239abf565b1SStefano Ceccherini 
testFillRectGradientDiamond(BView * view,BRect frame)240abf565b1SStefano Ceccherini static void testFillRectGradientDiamond(BView* view, BRect frame)
241abf565b1SStefano Ceccherini {
242abf565b1SStefano Ceccherini 	BGradientDiamond gradient(0, 10);
243abf565b1SStefano Ceccherini 	gradient.AddColor(kRed, 0);
244abf565b1SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
245abf565b1SStefano Ceccherini 	frame.InsetBy(2, 2);
246abf565b1SStefano Ceccherini 	view->FillRect(frame, gradient);
247abf565b1SStefano Ceccherini }
248abf565b1SStefano Ceccherini 
testFillRectGradientConic(BView * view,BRect frame)249abf565b1SStefano Ceccherini static void testFillRectGradientConic(BView* view, BRect frame)
250abf565b1SStefano Ceccherini {
251abf565b1SStefano Ceccherini 	BGradientConic gradient(0, 0, 10);
252abf565b1SStefano Ceccherini 	gradient.AddColor(kRed, 0);
253abf565b1SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
254abf565b1SStefano Ceccherini 	frame.InsetBy(2, 2);
255abf565b1SStefano Ceccherini 	view->FillRect(frame, gradient);
256abf565b1SStefano Ceccherini }
257abf565b1SStefano Ceccherini 
testStrokeRect(BView * view,BRect frame)25854730332SMichael Pfeiffer static void testStrokeRect(BView *view, BRect frame)
25982afdb09SMichael Pfeiffer {
26082afdb09SMichael Pfeiffer 	frame.InsetBy(2, 2);
26182afdb09SMichael Pfeiffer 	view->StrokeRect(frame);
26282afdb09SMichael Pfeiffer }
26382afdb09SMichael Pfeiffer 
testFillRegion(BView * view,BRect frame)26454730332SMichael Pfeiffer static void testFillRegion(BView *view, BRect frame)
26582afdb09SMichael Pfeiffer {
26654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
26754730332SMichael Pfeiffer 	BRegion region(frame);
268b8c65995SStefano Ceccherini 	frame.InsetBy(10, 10);
26954730332SMichael Pfeiffer 	region.Exclude(frame);
27054730332SMichael Pfeiffer 	view->FillRegion(&region);
27154730332SMichael Pfeiffer }
27254730332SMichael Pfeiffer 
testFillRegionGradientLinear(BView * view,BRect frame)273b8c65995SStefano Ceccherini static void testFillRegionGradientLinear(BView* view, BRect frame)
274b8c65995SStefano Ceccherini {
275b8c65995SStefano Ceccherini 	BGradientLinear gradient(0, 0, frame.right, frame.bottom);
276b8c65995SStefano Ceccherini 	gradient.AddColor(kRed, 0);
277b8c65995SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
278b8c65995SStefano Ceccherini 	frame.InsetBy(2, 2);
279b8c65995SStefano Ceccherini 	BRegion region(frame);
280b8c65995SStefano Ceccherini 	frame.InsetBy(10, 10);
281b8c65995SStefano Ceccherini 	region.Exclude(frame);
282b8c65995SStefano Ceccherini 	view->FillRegion(&region, gradient);
283b8c65995SStefano Ceccherini }
284b8c65995SStefano Ceccherini 
testFillRegionGradientRadial(BView * view,BRect frame)285b8c65995SStefano Ceccherini static void testFillRegionGradientRadial(BView* view, BRect frame)
286b8c65995SStefano Ceccherini {
287b8c65995SStefano Ceccherini 	BGradientRadial gradient(10, 10, 10);
288b8c65995SStefano Ceccherini 	gradient.AddColor(kRed, 0);
289b8c65995SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
290b8c65995SStefano Ceccherini 	frame.InsetBy(2, 2);
291b8c65995SStefano Ceccherini 	BRegion region(frame);
292b8c65995SStefano Ceccherini 	frame.InsetBy(10, 10);
293b8c65995SStefano Ceccherini 	region.Exclude(frame);
294b8c65995SStefano Ceccherini 	view->FillRegion(&region, gradient);
295b8c65995SStefano Ceccherini }
296b8c65995SStefano Ceccherini 
testFillRegionGradientRadialFocus(BView * view,BRect frame)297b8c65995SStefano Ceccherini static void testFillRegionGradientRadialFocus(BView* view, BRect frame)
298b8c65995SStefano Ceccherini {
299b8c65995SStefano Ceccherini 	BGradientRadialFocus gradient(0, 0, 10, 10, 5);
300b8c65995SStefano Ceccherini 	gradient.AddColor(kRed, 0);
301b8c65995SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
302b8c65995SStefano Ceccherini 	frame.InsetBy(2, 2);
303b8c65995SStefano Ceccherini 	BRegion region(frame);
304b8c65995SStefano Ceccherini 	frame.InsetBy(10, 10);
305b8c65995SStefano Ceccherini 	region.Exclude(frame);
306b8c65995SStefano Ceccherini 	view->FillRegion(&region, gradient);
307b8c65995SStefano Ceccherini }
308b8c65995SStefano Ceccherini 
testFillRegionGradientDiamond(BView * view,BRect frame)309b8c65995SStefano Ceccherini static void testFillRegionGradientDiamond(BView* view, BRect frame)
310b8c65995SStefano Ceccherini {
311b8c65995SStefano Ceccherini 	BGradientDiamond gradient(0, 10);
312b8c65995SStefano Ceccherini 	gradient.AddColor(kRed, 0);
313b8c65995SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
314b8c65995SStefano Ceccherini 	frame.InsetBy(2, 2);
315b8c65995SStefano Ceccherini 	BRegion region(frame);
316b8c65995SStefano Ceccherini 	frame.InsetBy(10, 10);
317b8c65995SStefano Ceccherini 	region.Exclude(frame);
318b8c65995SStefano Ceccherini 	view->FillRegion(&region, gradient);
319b8c65995SStefano Ceccherini }
320b8c65995SStefano Ceccherini 
testFillRegionGradientConic(BView * view,BRect frame)321b8c65995SStefano Ceccherini static void testFillRegionGradientConic(BView* view, BRect frame)
322b8c65995SStefano Ceccherini {
323b8c65995SStefano Ceccherini 	BGradientConic gradient(0, 0, 10);
324b8c65995SStefano Ceccherini 	gradient.AddColor(kRed, 0);
325b8c65995SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
326b8c65995SStefano Ceccherini 	frame.InsetBy(2, 2);
327b8c65995SStefano Ceccherini 	BRegion region(frame);
328b8c65995SStefano Ceccherini 	frame.InsetBy(10, 10);
329b8c65995SStefano Ceccherini 	region.Exclude(frame);
330b8c65995SStefano Ceccherini 	view->FillRegion(&region, gradient);
331b8c65995SStefano Ceccherini }
332b8c65995SStefano Ceccherini 
testFillRoundRect(BView * view,BRect frame)33354730332SMichael Pfeiffer static void testFillRoundRect(BView *view, BRect frame)
33454730332SMichael Pfeiffer {
33554730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
33654730332SMichael Pfeiffer 	view->FillRoundRect(frame, 5, 3);
33754730332SMichael Pfeiffer }
33854730332SMichael Pfeiffer 
testFillRoundRectGradientLinear(BView * view,BRect frame)33900c573d6SStefano Ceccherini static void testFillRoundRectGradientLinear(BView* view, BRect frame)
34000c573d6SStefano Ceccherini {
34100c573d6SStefano Ceccherini 	BGradientLinear gradient(0, 0, frame.right, frame.bottom);
34200c573d6SStefano Ceccherini 	gradient.AddColor(kRed, 0);
34300c573d6SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
34400c573d6SStefano Ceccherini 	frame.InsetBy(2, 2);
34500c573d6SStefano Ceccherini 	view->FillRoundRect(frame, 5, 3, gradient);
34600c573d6SStefano Ceccherini }
34700c573d6SStefano Ceccherini 
testFillRoundRectGradientRadial(BView * view,BRect frame)34800c573d6SStefano Ceccherini static void testFillRoundRectGradientRadial(BView* view, BRect frame)
34900c573d6SStefano Ceccherini {
35000c573d6SStefano Ceccherini 	BGradientRadial gradient(10, 10, 10);
35100c573d6SStefano Ceccherini 	gradient.AddColor(kRed, 0);
35200c573d6SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
35300c573d6SStefano Ceccherini 	frame.InsetBy(2, 2);
35400c573d6SStefano Ceccherini 	view->FillRoundRect(frame, 5, 3, gradient);
35500c573d6SStefano Ceccherini }
35600c573d6SStefano Ceccherini 
testFillRoundRectGradientRadialFocus(BView * view,BRect frame)35700c573d6SStefano Ceccherini static void testFillRoundRectGradientRadialFocus(BView* view, BRect frame)
35800c573d6SStefano Ceccherini {
35900c573d6SStefano Ceccherini 	BGradientRadialFocus gradient(0, 0, 10, 10, 5);
36000c573d6SStefano Ceccherini 	gradient.AddColor(kRed, 0);
36100c573d6SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
36200c573d6SStefano Ceccherini 	view->FillRoundRect(frame, 5, 3, gradient);
36300c573d6SStefano Ceccherini }
36400c573d6SStefano Ceccherini 
testFillRoundRectGradientDiamond(BView * view,BRect frame)36500c573d6SStefano Ceccherini static void testFillRoundRectGradientDiamond(BView* view, BRect frame)
36600c573d6SStefano Ceccherini {
36700c573d6SStefano Ceccherini 	BGradientDiamond gradient(0, 10);
36800c573d6SStefano Ceccherini 	gradient.AddColor(kRed, 0);
36900c573d6SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
37000c573d6SStefano Ceccherini 	frame.InsetBy(2, 2);
37100c573d6SStefano Ceccherini 	view->FillRoundRect(frame, 5, 3, gradient);
37200c573d6SStefano Ceccherini }
37300c573d6SStefano Ceccherini 
testFillRoundRectGradientConic(BView * view,BRect frame)37400c573d6SStefano Ceccherini static void testFillRoundRectGradientConic(BView* view, BRect frame)
37500c573d6SStefano Ceccherini {
37600c573d6SStefano Ceccherini 	BGradientConic gradient(0, 0, 10);
37700c573d6SStefano Ceccherini 	gradient.AddColor(kRed, 0);
37800c573d6SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
37900c573d6SStefano Ceccherini 	frame.InsetBy(2, 2);
38000c573d6SStefano Ceccherini 	view->FillRoundRect(frame, 5, 3, gradient);
38100c573d6SStefano Ceccherini }
38200c573d6SStefano Ceccherini 
testStrokeRoundRect(BView * view,BRect frame)38354730332SMichael Pfeiffer static void testStrokeRoundRect(BView *view, BRect frame)
38454730332SMichael Pfeiffer {
38554730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
38654730332SMichael Pfeiffer 	view->StrokeRoundRect(frame, 5, 3);
38754730332SMichael Pfeiffer }
38854730332SMichael Pfeiffer 
testFillTriangle(BView * view,BRect frame)38954730332SMichael Pfeiffer static void testFillTriangle(BView *view, BRect frame)
39054730332SMichael Pfeiffer {
39154730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
39254730332SMichael Pfeiffer 	BPoint points[3];
39354730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.bottom);
39454730332SMichael Pfeiffer 	points[1] = BPoint(centerPoint(frame).x, frame.top);
39554730332SMichael Pfeiffer 	points[2] = BPoint(frame.right, frame.bottom);
39654730332SMichael Pfeiffer 	view->FillTriangle(points[0], points[1], points[2]);
39754730332SMichael Pfeiffer }
39854730332SMichael Pfeiffer 
testFillTriangleGradientLinear(BView * view,BRect frame)399e5f9dfebSStefano Ceccherini static void testFillTriangleGradientLinear(BView* view, BRect frame)
400e5f9dfebSStefano Ceccherini {
401e5f9dfebSStefano Ceccherini 	BGradientLinear gradient(0, 0, frame.right, frame.bottom);
402e5f9dfebSStefano Ceccherini 	gradient.AddColor(kRed, 0);
403e5f9dfebSStefano Ceccherini 	gradient.AddColor(kBlue, 255);
404e5f9dfebSStefano Ceccherini 	frame.InsetBy(2, 2);
405e5f9dfebSStefano Ceccherini 	BPoint points[3];
406e5f9dfebSStefano Ceccherini 	points[0] = BPoint(frame.left, frame.bottom);
407e5f9dfebSStefano Ceccherini 	points[1] = BPoint(centerPoint(frame).x, frame.top);
408e5f9dfebSStefano Ceccherini 	points[2] = BPoint(frame.right, frame.bottom);
409e5f9dfebSStefano Ceccherini 	view->FillTriangle(points[0], points[1], points[2], gradient);
410e5f9dfebSStefano Ceccherini }
411e5f9dfebSStefano Ceccherini 
testFillTriangleGradientRadial(BView * view,BRect frame)412e5f9dfebSStefano Ceccherini static void testFillTriangleGradientRadial(BView* view, BRect frame)
413e5f9dfebSStefano Ceccherini {
414e5f9dfebSStefano Ceccherini 	BGradientRadial gradient(10, 10, 10);
415e5f9dfebSStefano Ceccherini 	gradient.AddColor(kRed, 0);
416e5f9dfebSStefano Ceccherini 	gradient.AddColor(kBlue, 255);
417e5f9dfebSStefano Ceccherini 	frame.InsetBy(2, 2);
418e5f9dfebSStefano Ceccherini 	BPoint points[3];
419e5f9dfebSStefano Ceccherini 	points[0] = BPoint(frame.left, frame.bottom);
420e5f9dfebSStefano Ceccherini 	points[1] = BPoint(centerPoint(frame).x, frame.top);
421e5f9dfebSStefano Ceccherini 	points[2] = BPoint(frame.right, frame.bottom);
422e5f9dfebSStefano Ceccherini 	view->FillTriangle(points[0], points[1], points[2], gradient);
423e5f9dfebSStefano Ceccherini }
424e5f9dfebSStefano Ceccherini 
testFillTriangleGradientRadialFocus(BView * view,BRect frame)425e5f9dfebSStefano Ceccherini static void testFillTriangleGradientRadialFocus(BView* view, BRect frame)
426e5f9dfebSStefano Ceccherini {
427e5f9dfebSStefano Ceccherini 	BGradientRadialFocus gradient(0, 0, 10, 10, 5);
428e5f9dfebSStefano Ceccherini 	gradient.AddColor(kRed, 0);
429e5f9dfebSStefano Ceccherini 	gradient.AddColor(kBlue, 255);
430e5f9dfebSStefano Ceccherini 	frame.InsetBy(2, 2);
431e5f9dfebSStefano Ceccherini 	BPoint points[3];
432e5f9dfebSStefano Ceccherini 	points[0] = BPoint(frame.left, frame.bottom);
433e5f9dfebSStefano Ceccherini 	points[1] = BPoint(centerPoint(frame).x, frame.top);
434e5f9dfebSStefano Ceccherini 	points[2] = BPoint(frame.right, frame.bottom);
435e5f9dfebSStefano Ceccherini 	view->FillTriangle(points[0], points[1], points[2], gradient);
436e5f9dfebSStefano Ceccherini }
437e5f9dfebSStefano Ceccherini 
testFillTriangleGradientDiamond(BView * view,BRect frame)438e5f9dfebSStefano Ceccherini static void testFillTriangleGradientDiamond(BView* view, BRect frame)
439e5f9dfebSStefano Ceccherini {
440e5f9dfebSStefano Ceccherini 	BGradientDiamond gradient(0, 10);
441e5f9dfebSStefano Ceccherini 	gradient.AddColor(kRed, 0);
442e5f9dfebSStefano Ceccherini 	gradient.AddColor(kBlue, 255);
443e5f9dfebSStefano Ceccherini 	frame.InsetBy(2, 2);
444e5f9dfebSStefano Ceccherini 	BPoint points[3];
445e5f9dfebSStefano Ceccherini 	points[0] = BPoint(frame.left, frame.bottom);
446e5f9dfebSStefano Ceccherini 	points[1] = BPoint(centerPoint(frame).x, frame.top);
447e5f9dfebSStefano Ceccherini 	points[2] = BPoint(frame.right, frame.bottom);
448e5f9dfebSStefano Ceccherini 	view->FillTriangle(points[0], points[1], points[2], gradient);
449e5f9dfebSStefano Ceccherini }
450e5f9dfebSStefano Ceccherini 
testFillTriangleGradientConic(BView * view,BRect frame)451e5f9dfebSStefano Ceccherini static void testFillTriangleGradientConic(BView* view, BRect frame)
452e5f9dfebSStefano Ceccherini {
453e5f9dfebSStefano Ceccherini 	BGradientConic gradient(0, 0, 10);
454e5f9dfebSStefano Ceccherini 	gradient.AddColor(kRed, 0);
455e5f9dfebSStefano Ceccherini 	gradient.AddColor(kBlue, 255);
456e5f9dfebSStefano Ceccherini 	frame.InsetBy(2, 2);
457e5f9dfebSStefano Ceccherini 	BPoint points[3];
458e5f9dfebSStefano Ceccherini 	points[0] = BPoint(frame.left, frame.bottom);
459e5f9dfebSStefano Ceccherini 	points[1] = BPoint(centerPoint(frame).x, frame.top);
460e5f9dfebSStefano Ceccherini 	points[2] = BPoint(frame.right, frame.bottom);
461e5f9dfebSStefano Ceccherini 	view->FillTriangle(points[0], points[1], points[2], gradient);
462e5f9dfebSStefano Ceccherini }
463e5f9dfebSStefano Ceccherini 
testStrokeTriangle(BView * view,BRect frame)46454730332SMichael Pfeiffer static void testStrokeTriangle(BView *view, BRect frame)
46554730332SMichael Pfeiffer {
46654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
46754730332SMichael Pfeiffer 	BPoint points[3];
46854730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.bottom);
46954730332SMichael Pfeiffer 	points[1] = BPoint(centerPoint(frame).x, frame.top);
47054730332SMichael Pfeiffer 	points[2] = BPoint(frame.right, frame.bottom);
47154730332SMichael Pfeiffer 	view->StrokeTriangle(points[0], points[1], points[2]);
47254730332SMichael Pfeiffer }
47354730332SMichael Pfeiffer 
testStrokeLine(BView * view,BRect frame)47454730332SMichael Pfeiffer static void testStrokeLine(BView *view, BRect frame)
47554730332SMichael Pfeiffer {
47654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
47754730332SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top));
47854730332SMichael Pfeiffer 
47954730332SMichael Pfeiffer 	frame.top += 2;
48054730332SMichael Pfeiffer 	frame.bottom -= 2;
48182afdb09SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.bottom));
48254730332SMichael Pfeiffer 
48354730332SMichael Pfeiffer 	frame.bottom += 2;;
48454730332SMichael Pfeiffer 	frame.top = frame.bottom;
48554730332SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.right, frame.top), BPoint(frame.left, frame.top));
48682afdb09SMichael Pfeiffer }
48782afdb09SMichael Pfeiffer 
testFillShape(BView * view,BRect frame)48854730332SMichael Pfeiffer static void testFillShape(BView *view, BRect frame)
48982afdb09SMichael 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->FillShape(&shape);
49782afdb09SMichael Pfeiffer }
49882afdb09SMichael Pfeiffer 
testStrokeShape(BView * view,BRect frame)49954730332SMichael Pfeiffer static void testStrokeShape(BView *view, BRect frame)
50054730332SMichael Pfeiffer {
50154730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
50254730332SMichael Pfeiffer 	BShape shape;
50354730332SMichael Pfeiffer 	shape.MoveTo(BPoint(frame.left, frame.bottom));
50454730332SMichael Pfeiffer 	shape.LineTo(BPoint(frame.right, frame.top));
50554730332SMichael Pfeiffer 	shape.LineTo(BPoint(frame.left, frame.top));
50654730332SMichael Pfeiffer 	shape.LineTo(BPoint(frame.right, frame.bottom));
50754730332SMichael Pfeiffer 	view->StrokeShape(&shape);
50854730332SMichael Pfeiffer }
50954730332SMichael Pfeiffer 
testRecordPicture(BView * view,BRect frame)51054730332SMichael Pfeiffer static void testRecordPicture(BView *view, BRect frame)
51182afdb09SMichael Pfeiffer {
51282afdb09SMichael Pfeiffer 	BPicture *picture = new BPicture();
51382afdb09SMichael Pfeiffer 	view->BeginPicture(picture);
51482afdb09SMichael Pfeiffer 	view->FillRect(frame);
51582afdb09SMichael Pfeiffer 	view->EndPicture();
51682afdb09SMichael Pfeiffer 	delete picture;
51782afdb09SMichael Pfeiffer }
51882afdb09SMichael Pfeiffer 
testRecordAndPlayPicture(BView * view,BRect frame)51954730332SMichael Pfeiffer static void testRecordAndPlayPicture(BView *view, BRect frame)
52082afdb09SMichael Pfeiffer {
52182afdb09SMichael Pfeiffer 	BPicture *picture = new BPicture();
52282afdb09SMichael Pfeiffer 	view->BeginPicture(picture);
52382afdb09SMichael Pfeiffer 	frame.InsetBy(2, 2);
52482afdb09SMichael Pfeiffer 	view->FillRect(frame);
52582afdb09SMichael Pfeiffer 	view->EndPicture();
52682afdb09SMichael Pfeiffer 	view->DrawPicture(picture);
52782afdb09SMichael Pfeiffer 	delete picture;
52882afdb09SMichael Pfeiffer }
52982afdb09SMichael Pfeiffer 
testRecordAndPlayPictureWithOffset(BView * view,BRect frame)53054730332SMichael Pfeiffer static void testRecordAndPlayPictureWithOffset(BView *view, BRect frame)
53182afdb09SMichael Pfeiffer {
53282afdb09SMichael Pfeiffer 	BPicture *picture = new BPicture();
53382afdb09SMichael Pfeiffer 	view->BeginPicture(picture);
53482afdb09SMichael Pfeiffer 	frame.InsetBy(frame.Width() / 4, frame.Height() / 4);
53582afdb09SMichael Pfeiffer 	frame.OffsetTo(0, 0);
53682afdb09SMichael Pfeiffer 	view->FillRect(frame);
53782afdb09SMichael Pfeiffer 	view->EndPicture();
53882afdb09SMichael Pfeiffer 
53982afdb09SMichael Pfeiffer 	view->DrawPicture(picture, BPoint(10, 10));
54082afdb09SMichael Pfeiffer 	// color of picture should not change
54154730332SMichael Pfeiffer 	view->SetLowColor(kGreen);
54254730332SMichael Pfeiffer 	view->SetLowColor(kRed);
54382afdb09SMichael Pfeiffer 	view->DrawPicture(picture, BPoint(0, 0));
54482afdb09SMichael Pfeiffer 	delete picture;
54582afdb09SMichael Pfeiffer }
54682afdb09SMichael Pfeiffer 
testAppendToPicture(BView * view,BRect frame)54754730332SMichael Pfeiffer static void testAppendToPicture(BView *view, BRect frame)
54854730332SMichael Pfeiffer {
54954730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
55054730332SMichael Pfeiffer 	view->BeginPicture(new BPicture());
55154730332SMichael Pfeiffer 	view->FillRect(frame);
55254730332SMichael Pfeiffer 	BPicture* picture = view->EndPicture();
55354730332SMichael Pfeiffer 	if (picture == NULL)
55454730332SMichael Pfeiffer 		return;
55554730332SMichael Pfeiffer 
55654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
55754730332SMichael Pfeiffer 	view->AppendToPicture(picture);
55854730332SMichael Pfeiffer 	view->SetHighColor(kRed);
55954730332SMichael Pfeiffer 	view->FillRect(frame);
56054730332SMichael Pfeiffer 	if (view->EndPicture() != picture)
56154730332SMichael Pfeiffer 		return;
56254730332SMichael Pfeiffer 
56354730332SMichael Pfeiffer 	view->DrawPicture(picture);
56454730332SMichael Pfeiffer 	delete picture;
56554730332SMichael Pfeiffer }
56654730332SMichael Pfeiffer 
testDrawScaledPicture(BView * view,BRect frame)5678247141fSMichael Pfeiffer static void testDrawScaledPicture(BView* view, BRect frame)
5688247141fSMichael Pfeiffer {
5698247141fSMichael Pfeiffer 	view->BeginPicture(new BPicture());
5708247141fSMichael Pfeiffer 	view->FillRect(BRect(0, 0, 15, 15));
5718247141fSMichael Pfeiffer 	BPicture* picture = view->EndPicture();
5728247141fSMichael Pfeiffer 
5738247141fSMichael Pfeiffer 	// first unscaled at left, top
5748247141fSMichael Pfeiffer 	view->DrawPicture(picture, BPoint(2, 2));
5758247141fSMichael Pfeiffer 
5768247141fSMichael Pfeiffer 	// draw scaled at middle top
5778247141fSMichael Pfeiffer 	view->SetScale(0.5);
5788247141fSMichael Pfeiffer 	// the drawing offset must be scaled too!
579ff973abcSMichael Pfeiffer 	view->DrawPicture(picture, BPoint(frame.Width(), 4));
5808247141fSMichael Pfeiffer 
5818247141fSMichael Pfeiffer 	delete picture;
5828247141fSMichael Pfeiffer }
5838247141fSMichael Pfeiffer 
testLineArray(BView * view,BRect frame)58454730332SMichael Pfeiffer static void testLineArray(BView *view, BRect frame)
58554730332SMichael Pfeiffer {
58654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
58754730332SMichael Pfeiffer 	view->BeginLineArray(3);
58854730332SMichael Pfeiffer 	view->AddLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top), kBlack);
58954730332SMichael Pfeiffer 
59054730332SMichael Pfeiffer 	frame.top += 2;
59154730332SMichael Pfeiffer 	frame.bottom -= 2;
59254730332SMichael Pfeiffer 	view->AddLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.bottom), kRed);
59354730332SMichael Pfeiffer 
59454730332SMichael Pfeiffer 	frame.bottom += 2;;
59554730332SMichael Pfeiffer 	frame.top = frame.bottom;
59654730332SMichael Pfeiffer 	view->AddLine(BPoint(frame.right, frame.top), BPoint(frame.left, frame.top), kGreen);
59754730332SMichael Pfeiffer 
59854730332SMichael Pfeiffer 	view->EndLineArray();
59954730332SMichael Pfeiffer }
60054730332SMichael Pfeiffer 
testInvertRect(BView * view,BRect frame)60154730332SMichael Pfeiffer static void testInvertRect(BView *view, BRect frame)
60254730332SMichael Pfeiffer {
60354730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
60454730332SMichael Pfeiffer 	view->InvertRect(frame);
60554730332SMichael Pfeiffer }
60654730332SMichael Pfeiffer 
testInvertRectSetDrawingMode(BView * view,BRect frame)6077cf26360SStefano Ceccherini static void testInvertRectSetDrawingMode(BView *view, BRect frame)
6087cf26360SStefano Ceccherini {
6097cf26360SStefano Ceccherini 	view->SetDrawingMode(B_OP_ALPHA);
6107cf26360SStefano Ceccherini 	view->SetHighColor(128, 128, 128, 128);
6117cf26360SStefano Ceccherini 	frame.InsetBy(2, 2);
6127cf26360SStefano Ceccherini 	view->InvertRect(frame);
6137cf26360SStefano Ceccherini 	frame.InsetBy(10, 10);
6147cf26360SStefano Ceccherini 	view->FillRect(frame, B_SOLID_HIGH);
6157cf26360SStefano Ceccherini }
6167cf26360SStefano Ceccherini 
isBorder(int32 x,int32 y,int32 width,int32 height)6174f422578SMichael Pfeiffer static bool isBorder(int32 x, int32 y, int32 width, int32 height) {
6184f422578SMichael Pfeiffer 	return x == 0 || y == 0 || x == width - 1 || y == height - 1;
6194f422578SMichael Pfeiffer }
6204f422578SMichael Pfeiffer 
fillBitmap(BBitmap & bitmap)6214f422578SMichael Pfeiffer static void fillBitmap(BBitmap &bitmap) {
6224f422578SMichael Pfeiffer 	int32 height = bitmap.Bounds().IntegerHeight()+1;
6234f422578SMichael Pfeiffer 	int32 width = bitmap.Bounds().IntegerWidth()+1;
6244f422578SMichael Pfeiffer 	for (int32 y = 0; y < height; y ++) {
6254f422578SMichael Pfeiffer 		for (int32 x = 0; x < width; x ++) {
62682afdb09SMichael Pfeiffer 			char *pixel = (char*)bitmap.Bits();
62782afdb09SMichael Pfeiffer 			pixel += bitmap.BytesPerRow() * y + 4 * x;
6284f422578SMichael Pfeiffer 			if (isBorder(x, y, width, height)) {
6294f422578SMichael Pfeiffer 				// fill with green
6304f422578SMichael Pfeiffer 				pixel[0] = 255;
6314f422578SMichael Pfeiffer 				pixel[1] = 0;
6324f422578SMichael Pfeiffer 				pixel[2] = 255;
6334f422578SMichael Pfeiffer 				pixel[3] = 0;
6344f422578SMichael Pfeiffer 			} else  {
63582afdb09SMichael Pfeiffer 				// fill with blue
63682afdb09SMichael Pfeiffer 				pixel[0] = 255;
63782afdb09SMichael Pfeiffer 				pixel[1] = 0;
63882afdb09SMichael Pfeiffer 				pixel[2] = 0;
63982afdb09SMichael Pfeiffer 				pixel[3] = 255;
64082afdb09SMichael Pfeiffer 			}
64182afdb09SMichael Pfeiffer 		}
6424f422578SMichael Pfeiffer 	}
6434f422578SMichael Pfeiffer }
6444f422578SMichael Pfeiffer 
testDrawBitmap(BView * view,BRect frame)6454f422578SMichael Pfeiffer static void testDrawBitmap(BView *view, BRect frame) {
6464f422578SMichael Pfeiffer 	BBitmap bitmap(frame, B_RGBA32);
6474f422578SMichael Pfeiffer 	fillBitmap(bitmap);
64882afdb09SMichael Pfeiffer 	view->DrawBitmap(&bitmap, BPoint(0, 0));
64982afdb09SMichael Pfeiffer }
65082afdb09SMichael Pfeiffer 
testDrawBitmapAtPoint(BView * view,BRect frame)6514f422578SMichael Pfeiffer static void testDrawBitmapAtPoint(BView *view, BRect frame) {
6524f422578SMichael Pfeiffer 	frame.InsetBy(2, 2);
6534f422578SMichael Pfeiffer 
6544f422578SMichael Pfeiffer 	BRect bounds(frame);
6554f422578SMichael Pfeiffer 	bounds.OffsetTo(0, 0);
6564f422578SMichael Pfeiffer 	bounds.right /= 2;
6574f422578SMichael Pfeiffer 	bounds.bottom /= 2;
6584f422578SMichael Pfeiffer 
6594f422578SMichael Pfeiffer 	BBitmap bitmap(bounds, B_RGBA32);
6604f422578SMichael Pfeiffer 	fillBitmap(bitmap);
6614f422578SMichael Pfeiffer 	view->DrawBitmap(&bitmap, centerPoint(frame));
6624f422578SMichael Pfeiffer }
6634f422578SMichael Pfeiffer 
testDrawBitmapAtRect(BView * view,BRect frame)6644f422578SMichael Pfeiffer static void testDrawBitmapAtRect(BView *view, BRect frame) {
6654f422578SMichael Pfeiffer 	BRect bounds(frame);
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 
testDrawLargeBitmap(BView * view,BRect frame)6724f422578SMichael Pfeiffer static void testDrawLargeBitmap(BView *view, BRect frame) {
6734f422578SMichael Pfeiffer 	BRect bounds(frame);
6744f422578SMichael Pfeiffer 	bounds.OffsetTo(0, 0);
6758247141fSMichael Pfeiffer 	bounds.right *= 4;
6768247141fSMichael Pfeiffer 	bounds.bottom *= 4;
6774f422578SMichael Pfeiffer 	BBitmap bitmap(bounds, B_RGBA32);
6784f422578SMichael Pfeiffer 	fillBitmap(bitmap);
6794f422578SMichael Pfeiffer 	frame.InsetBy(2, 2);
6804f422578SMichael Pfeiffer 	view->DrawBitmap(&bitmap, frame);
6814f422578SMichael Pfeiffer }
6824f422578SMichael Pfeiffer 
testConstrainClippingRegion(BView * view,BRect frame)683c43f0163SMichael Pfeiffer static void testConstrainClippingRegion(BView *view, BRect frame)
684c43f0163SMichael Pfeiffer {
685c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
686c43f0163SMichael Pfeiffer 	// draw background
687c43f0163SMichael Pfeiffer 	view->SetHighColor(kRed);
688c43f0163SMichael Pfeiffer 	view->FillRect(frame);
689c43f0163SMichael Pfeiffer 
690c43f0163SMichael Pfeiffer 	frame.InsetBy(1, 1);
691c43f0163SMichael Pfeiffer 	BRegion region(frame);
692c43f0163SMichael Pfeiffer 	BRect r(frame);
693c43f0163SMichael Pfeiffer 	r.InsetBy(r.IntegerWidth() / 4, r.IntegerHeight() / 4);
694c43f0163SMichael Pfeiffer 	region.Exclude(r);
695c43f0163SMichael Pfeiffer 	view->ConstrainClippingRegion(&region);
696c43f0163SMichael Pfeiffer 
697c43f0163SMichael Pfeiffer 	frame.InsetBy(-1, -1);
698c43f0163SMichael Pfeiffer 	view->SetHighColor(kBlack);
699c43f0163SMichael Pfeiffer 	view->FillRect(frame);
700c43f0163SMichael Pfeiffer 	// a filled black rectangle with a red one pixel border
701c43f0163SMichael Pfeiffer 	// and inside a red rectangle should be drawn.
702c43f0163SMichael Pfeiffer }
703c43f0163SMichael Pfeiffer 
testClipToPicture(BView * view,BRect frame)704c43f0163SMichael Pfeiffer static void testClipToPicture(BView *view, BRect frame)
705c43f0163SMichael Pfeiffer {
706c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
707c43f0163SMichael Pfeiffer 	view->BeginPicture(new BPicture());
708c43f0163SMichael Pfeiffer 	view->FillEllipse(frame);
709c43f0163SMichael Pfeiffer 	BPicture *picture = view->EndPicture();
710c43f0163SMichael Pfeiffer 	if (picture == NULL)
711c43f0163SMichael Pfeiffer 		return;
712c43f0163SMichael Pfeiffer 
713c43f0163SMichael Pfeiffer 	view->ClipToPicture(picture);
714c43f0163SMichael Pfeiffer 	delete picture;
715c43f0163SMichael Pfeiffer 
716c43f0163SMichael Pfeiffer 	view->FillRect(frame);
717c43f0163SMichael Pfeiffer 	// black ellipse should be drawn
718c43f0163SMichael Pfeiffer }
719c43f0163SMichael Pfeiffer 
testClipToInversePicture(BView * view,BRect frame)720c43f0163SMichael Pfeiffer static void testClipToInversePicture(BView *view, BRect frame)
721c43f0163SMichael Pfeiffer {
722c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
723c43f0163SMichael Pfeiffer 
724c43f0163SMichael Pfeiffer 	view->BeginPicture(new BPicture());
725c43f0163SMichael Pfeiffer 	view->FillEllipse(frame);
726c43f0163SMichael Pfeiffer 	BPicture *picture = view->EndPicture();
727c43f0163SMichael Pfeiffer 	if (picture == NULL)
728c43f0163SMichael Pfeiffer 		return;
729c43f0163SMichael Pfeiffer 
730c43f0163SMichael Pfeiffer 	view->ClipToInversePicture(picture);
731c43f0163SMichael Pfeiffer 	delete picture;
732c43f0163SMichael Pfeiffer 
733c43f0163SMichael Pfeiffer 	view->FillRect(frame);
734c43f0163SMichael Pfeiffer 	// white ellipse inside a black rectangle
735c43f0163SMichael Pfeiffer }
736c43f0163SMichael Pfeiffer 
testSetPenSize(BView * view,BRect frame)737c43f0163SMichael Pfeiffer static void testSetPenSize(BView *view, BRect frame)
738c43f0163SMichael Pfeiffer {
739c43f0163SMichael Pfeiffer 	frame.InsetBy(8, 2);
740c43f0163SMichael Pfeiffer 	float x = centerPoint(frame).x;
741c43f0163SMichael Pfeiffer 
742c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top));
743c43f0163SMichael Pfeiffer 
744c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, 5);
745c43f0163SMichael Pfeiffer 	view->SetPenSize(1);
746c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
747c43f0163SMichael Pfeiffer 	view->SetPenSize(0);
748c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));
749c43f0163SMichael Pfeiffer 
750c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, 5);
751c43f0163SMichael Pfeiffer 	view->SetPenSize(1);
752c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
753c43f0163SMichael Pfeiffer 	view->SetPenSize(2);
754c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));
755c43f0163SMichael Pfeiffer 
756c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, 5);
757c43f0163SMichael Pfeiffer 	view->SetPenSize(1);
758c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
759c43f0163SMichael Pfeiffer 	view->SetPenSize(3);
760c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));
761c43f0163SMichael Pfeiffer 
762c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, 5);
763c43f0163SMichael Pfeiffer 	view->SetPenSize(1);
764c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
765c43f0163SMichael Pfeiffer 	view->SetPenSize(4);
766c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));
767c43f0163SMichael Pfeiffer }
768c43f0163SMichael Pfeiffer 
testSetPenSize2(BView * view,BRect frame)769c43f0163SMichael Pfeiffer static void testSetPenSize2(BView *view, BRect frame)
770c43f0163SMichael Pfeiffer {
771c43f0163SMichael Pfeiffer 	// test if pen size is scaled too
772c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
773c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, 5);
774c43f0163SMichael Pfeiffer 	view->SetPenSize(4);
775c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top));
776c43f0163SMichael Pfeiffer 	view->SetScale(0.5);
777c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left + 2, frame.bottom), BPoint(frame.right + 2, frame.bottom));
778c43f0163SMichael Pfeiffer 
779c43f0163SMichael Pfeiffer 	// black line from left to right, 4 pixel size
780c43f0163SMichael Pfeiffer 	// below black line with half the length of the first one
781c43f0163SMichael Pfeiffer 	// and 2 pixel size
782c43f0163SMichael Pfeiffer }
783c43f0163SMichael Pfeiffer 
testPattern(BView * view,BRect frame)784c43f0163SMichael Pfeiffer static void testPattern(BView *view, BRect frame)
785c43f0163SMichael Pfeiffer {
786c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
787c43f0163SMichael Pfeiffer 	int x = frame.IntegerWidth() / 3;
788c43f0163SMichael Pfeiffer 	frame.right = frame.left + x - 2;
789c43f0163SMichael Pfeiffer 		// -2 for an empty pixel row between
790c43f0163SMichael Pfeiffer 		// filled rectangles
791c43f0163SMichael Pfeiffer 
792c43f0163SMichael Pfeiffer 	view->SetLowColor(kGreen);
793c43f0163SMichael Pfeiffer 	view->SetHighColor(kRed);
794c43f0163SMichael Pfeiffer 
795c43f0163SMichael Pfeiffer 	view->FillRect(frame, B_SOLID_HIGH);
796c43f0163SMichael Pfeiffer 
797c43f0163SMichael Pfeiffer 	frame.OffsetBy(x, 0);
798c43f0163SMichael Pfeiffer 	view->FillRect(frame, B_MIXED_COLORS);
799c43f0163SMichael Pfeiffer 
800c43f0163SMichael Pfeiffer 	frame.OffsetBy(x, 0);
801c43f0163SMichael Pfeiffer 	view->FillRect(frame, B_SOLID_LOW);
802c43f0163SMichael Pfeiffer }
803c43f0163SMichael Pfeiffer 
testSetOrigin(BView * view,BRect frame)804c43f0163SMichael Pfeiffer static void testSetOrigin(BView *view, BRect frame)
805c43f0163SMichael Pfeiffer {
806c43f0163SMichael Pfeiffer 	BPoint origin = view->Origin();
807c43f0163SMichael Pfeiffer 	BPoint center = centerPoint(frame);
808c43f0163SMichael Pfeiffer 	view->SetOrigin(center);
809c43f0163SMichael Pfeiffer 
810c43f0163SMichael Pfeiffer 	BRect r(0, 0, center.x, center.y);
811c43f0163SMichael Pfeiffer 	view->SetHighColor(kBlue);
812c43f0163SMichael Pfeiffer 	view->FillRect(r);
813c43f0163SMichael Pfeiffer 
814c43f0163SMichael Pfeiffer 	view->SetOrigin(origin);
815c43f0163SMichael Pfeiffer 	view->SetHighColor(kRed);
816c43f0163SMichael Pfeiffer 	view->FillRect(r);
817c43f0163SMichael Pfeiffer 
818c43f0163SMichael Pfeiffer 	// red rectangle in left, top corner
819c43f0163SMichael Pfeiffer 	// blue rectangle in right, bottom corner
820c43f0163SMichael Pfeiffer 	// the red rectangle overwrites the
821c43f0163SMichael Pfeiffer 	// top, left pixel of the blue rectangle
822c43f0163SMichael Pfeiffer }
823c43f0163SMichael Pfeiffer 
testSetOrigin2(BView * view,BRect frame)824c43f0163SMichael Pfeiffer static void testSetOrigin2(BView *view, BRect frame)
825c43f0163SMichael Pfeiffer {
826c43f0163SMichael Pfeiffer 	BPoint center = centerPoint(frame);
827c43f0163SMichael Pfeiffer 	BRect r(0, 0, center.x, center.y);
828c43f0163SMichael Pfeiffer 	view->SetOrigin(center);
829c43f0163SMichael Pfeiffer 	view->PushState();
830c43f0163SMichael Pfeiffer 		view->SetOrigin(BPoint(-center.x, 0));
831c43f0163SMichael Pfeiffer 		view->FillRect(r);
832c43f0163SMichael Pfeiffer 	view->PopState();
833c43f0163SMichael Pfeiffer 	// black rectangle in left, bottom corner
834c43f0163SMichael Pfeiffer }
835c43f0163SMichael Pfeiffer 
testSetScale(BView * view,BRect frame)836c43f0163SMichael Pfeiffer static void testSetScale(BView *view, BRect frame)
837c43f0163SMichael Pfeiffer {
838c43f0163SMichael Pfeiffer 	view->SetScale(0.5);
839c43f0163SMichael Pfeiffer 	view->FillRect(frame);
840c43f0163SMichael Pfeiffer 	// black rectangle in left, top corner
841c43f0163SMichael Pfeiffer }
842c43f0163SMichael Pfeiffer 
testSetScale2(BView * view,BRect frame)843c43f0163SMichael Pfeiffer static void testSetScale2(BView *view, BRect frame)
844c43f0163SMichael Pfeiffer {
845c43f0163SMichael Pfeiffer 	view->SetScale(0.5);
846c43f0163SMichael Pfeiffer 	view->PushState();
847c43f0163SMichael Pfeiffer 		view->SetScale(0.5);
848c43f0163SMichael Pfeiffer 		view->FillRect(frame);
849c43f0163SMichael Pfeiffer 	view->PopState();
850c43f0163SMichael Pfeiffer 	// black rectangle in left, top corner
851c43f0163SMichael Pfeiffer 	// with half the size of the rectangle
852c43f0163SMichael Pfeiffer 	// from test testSetScaling
853c43f0163SMichael Pfeiffer }
854c43f0163SMichael Pfeiffer 
testSetScale3(BView * view,BRect frame)855c43f0163SMichael Pfeiffer static void testSetScale3(BView *view, BRect frame)
856c43f0163SMichael Pfeiffer {
857c43f0163SMichael Pfeiffer 	view->SetScale(0.5);
858c43f0163SMichael Pfeiffer 	view->PushState();
859c43f0163SMichael Pfeiffer 		// if the second scale value differs slightly
860c43f0163SMichael Pfeiffer 		// the bug under BeOS R5 in testSetScale2
861c43f0163SMichael Pfeiffer 		// does not occur
862c43f0163SMichael Pfeiffer 		view->SetScale(0.5000001);
863c43f0163SMichael Pfeiffer 		view->FillRect(frame);
864c43f0163SMichael Pfeiffer 	view->PopState();
865c43f0163SMichael Pfeiffer 	// black rectangle in left, top corner
866c43f0163SMichael Pfeiffer 	// with half the size of the rectangle
867c43f0163SMichael Pfeiffer 	// from test testSetScaling
868c43f0163SMichael Pfeiffer }
869c43f0163SMichael Pfeiffer 
testSetOriginAndScale(BView * view,BRect frame)870c9c4a80aSMichael Pfeiffer static void testSetOriginAndScale(BView *view, BRect frame)
871c9c4a80aSMichael Pfeiffer {
872c9c4a80aSMichael Pfeiffer 	frame.InsetBy(2, 2);
873c9c4a80aSMichael Pfeiffer 	BPoint center = centerPoint(frame);
874c9c4a80aSMichael Pfeiffer 
875c9c4a80aSMichael Pfeiffer 	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
876c9c4a80aSMichael Pfeiffer 	view->SetOrigin(center);
877c9c4a80aSMichael Pfeiffer 	view->FillRect(r);
878c9c4a80aSMichael Pfeiffer 
879c9c4a80aSMichael Pfeiffer 	view->SetScale(0.5);
880c9c4a80aSMichael Pfeiffer 	view->SetHighColor(kRed);
881c9c4a80aSMichael Pfeiffer 	view->FillRect(r);
882c9c4a80aSMichael Pfeiffer }
883c9c4a80aSMichael Pfeiffer 
testSetOriginAndScale2(BView * view,BRect frame)8844b05331dSMichael Pfeiffer static void testSetOriginAndScale2(BView *view, BRect frame)
8854b05331dSMichael Pfeiffer {
8864b05331dSMichael Pfeiffer 	frame.InsetBy(2, 2);
8874b05331dSMichael Pfeiffer 	BPoint center = centerPoint(frame);
8884b05331dSMichael Pfeiffer 
8894b05331dSMichael Pfeiffer 	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
8904b05331dSMichael Pfeiffer 	view->SetOrigin(center);
8914b05331dSMichael Pfeiffer 	view->FillRect(r);
8924b05331dSMichael Pfeiffer 
8934b05331dSMichael Pfeiffer 	view->SetScale(0.5);
8944b05331dSMichael Pfeiffer 	view->SetHighColor(kRed);
8954b05331dSMichael Pfeiffer 	view->FillRect(r);
8964b05331dSMichael Pfeiffer 
8974b05331dSMichael Pfeiffer 	view->SetOrigin(0, 0);
8984b05331dSMichael Pfeiffer 	view->SetHighColor(kGreen);
8994b05331dSMichael Pfeiffer 	view->FillRect(r);
9004b05331dSMichael Pfeiffer }
9014b05331dSMichael Pfeiffer 
testSetOriginAndScale3(BView * view,BRect frame)9024b05331dSMichael Pfeiffer static void testSetOriginAndScale3(BView *view, BRect frame)
9034b05331dSMichael Pfeiffer {
9044b05331dSMichael Pfeiffer 	frame.InsetBy(2, 2);
9054b05331dSMichael Pfeiffer 	BPoint center = centerPoint(frame);
9064b05331dSMichael Pfeiffer 
9074b05331dSMichael Pfeiffer 	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
9084b05331dSMichael Pfeiffer 	view->SetOrigin(center);
9094b05331dSMichael Pfeiffer 	view->FillRect(r);
9104b05331dSMichael Pfeiffer 
9114b05331dSMichael Pfeiffer 	view->SetScale(0.5);
9124b05331dSMichael Pfeiffer 	view->SetHighColor(kRed);
9134b05331dSMichael Pfeiffer 	view->FillRect(r);
9144b05331dSMichael Pfeiffer 
9154b05331dSMichael Pfeiffer 	view->SetScale(0.25);
9164b05331dSMichael Pfeiffer 	view->SetHighColor(kGreen);
9174b05331dSMichael Pfeiffer 	view->FillRect(r);
9184b05331dSMichael Pfeiffer }
9194b05331dSMichael Pfeiffer 
testSetOriginAndScale4(BView * view,BRect frame)9204b05331dSMichael Pfeiffer static void testSetOriginAndScale4(BView *view, BRect frame)
9214b05331dSMichael Pfeiffer {
9224b05331dSMichael Pfeiffer 	frame.InsetBy(2, 2);
9234b05331dSMichael Pfeiffer 	BPoint center = centerPoint(frame);
9244b05331dSMichael Pfeiffer 
9254b05331dSMichael Pfeiffer 	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
9264b05331dSMichael Pfeiffer 	view->SetOrigin(center);
9274b05331dSMichael Pfeiffer 	view->FillRect(r);
9284b05331dSMichael Pfeiffer 
9294b05331dSMichael Pfeiffer 	view->SetScale(0.5);
9304b05331dSMichael Pfeiffer 	view->SetHighColor(kRed);
9314b05331dSMichael Pfeiffer 	view->FillRect(r);
9324b05331dSMichael Pfeiffer 
9334b05331dSMichael Pfeiffer 	view->PushState();
9344b05331dSMichael Pfeiffer 		//
9354b05331dSMichael Pfeiffer 		view->SetOrigin(center.x+1, center.y);
9364b05331dSMichael Pfeiffer 			// +1 to work around BeOS bug
9374b05331dSMichael Pfeiffer 			// where setting the origin has no
9384b05331dSMichael Pfeiffer 			// effect if it is the same as
9394b05331dSMichael Pfeiffer 			// the previous value althou
9404b05331dSMichael Pfeiffer 			// it is from the "outer" coordinate
9414b05331dSMichael Pfeiffer 			// system
9424b05331dSMichael Pfeiffer 		view->SetHighColor(kGreen);
9434b05331dSMichael Pfeiffer 		view->FillRect(r);
9444b05331dSMichael Pfeiffer 	view->PopState();
9454b05331dSMichael Pfeiffer }
9464b05331dSMichael Pfeiffer 
testSetOriginAndScale5(BView * view,BRect frame)9474b05331dSMichael Pfeiffer static void testSetOriginAndScale5(BView *view, BRect frame)
9484b05331dSMichael Pfeiffer {
9494b05331dSMichael Pfeiffer 	frame.InsetBy(2, 2);
9504b05331dSMichael Pfeiffer 	BPoint center = centerPoint(frame);
9514b05331dSMichael Pfeiffer 
9524b05331dSMichael Pfeiffer 	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
9534b05331dSMichael Pfeiffer 	view->SetOrigin(center);
9544b05331dSMichael Pfeiffer 	view->FillRect(r);
9554b05331dSMichael Pfeiffer 
9564b05331dSMichael Pfeiffer 	view->SetScale(0.5);
9574b05331dSMichael Pfeiffer 	view->SetHighColor(kRed);
9584b05331dSMichael Pfeiffer 	view->FillRect(r);
9594b05331dSMichael Pfeiffer 
9604b05331dSMichael Pfeiffer 	view->PushState();
9614b05331dSMichael Pfeiffer 	view->SetScale(0.75);
9624b05331dSMichael Pfeiffer 	view->SetHighColor(kGreen);
9634b05331dSMichael Pfeiffer 	view->FillRect(r);
9644b05331dSMichael Pfeiffer 	view->PopState();
9654b05331dSMichael Pfeiffer }
9664b05331dSMichael Pfeiffer 
testSetFontSize(BView * view,BRect frame)967c43f0163SMichael Pfeiffer static void testSetFontSize(BView *view, BRect frame)
968c43f0163SMichael Pfeiffer {
969c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
970c43f0163SMichael Pfeiffer 	int size = frame.IntegerHeight() / 3;
971c43f0163SMichael Pfeiffer 
972c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, size);
973c43f0163SMichael Pfeiffer 	view->MovePenTo(BPoint(frame.left, frame.top));
974c43f0163SMichael Pfeiffer 	view->SetFontSize(size);
975c43f0163SMichael Pfeiffer 	view->DrawString("Haiku");
976c43f0163SMichael Pfeiffer 
977c43f0163SMichael Pfeiffer 	size *= 2;
978c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, size);
979c43f0163SMichael Pfeiffer 	view->MovePenTo(BPoint(frame.left, frame.top));
980c43f0163SMichael Pfeiffer 	view->SetFontSize(size);
981c43f0163SMichael Pfeiffer 	view->DrawString("Haiku");
982c43f0163SMichael Pfeiffer }
983c43f0163SMichael Pfeiffer 
testSetFontFamilyAndStyle(BView * view,BRect frame)9842fb98dccSStefano Ceccherini static void testSetFontFamilyAndStyle(BView *view, BRect frame)
9852fb98dccSStefano Ceccherini {
9862fb98dccSStefano Ceccherini 	view->DrawString("This is a test", BPoint(2, 6));
9872fb98dccSStefano Ceccherini 
9882fb98dccSStefano Ceccherini 	BFont font;
9892fb98dccSStefano Ceccherini 	view->GetFont(&font);
9902fb98dccSStefano Ceccherini 
9912fb98dccSStefano Ceccherini 	int32 families = count_font_families();
9922fb98dccSStefano Ceccherini 	font_family familyName;
9932fb98dccSStefano Ceccherini 	get_font_family(families - 1, &familyName);
9942fb98dccSStefano Ceccherini 
9952fb98dccSStefano Ceccherini 	int32 styles = count_font_styles(familyName);
9962fb98dccSStefano Ceccherini 	font_style styleName;
9972fb98dccSStefano Ceccherini 	get_font_style(familyName, styles - 1, &styleName);
9982fb98dccSStefano Ceccherini 	font.SetFamilyAndStyle(familyName, styleName);
9992fb98dccSStefano Ceccherini 	view->SetFont(&font);
10002fb98dccSStefano Ceccherini 	view->DrawString( "This is a test", BPoint(2, 19));
10012fb98dccSStefano Ceccherini }
10022fb98dccSStefano Ceccherini 
testSetDrawingMode(BView * view,BRect frame)100315cf50e0SStefano Ceccherini static void testSetDrawingMode(BView *view, BRect frame)
100415cf50e0SStefano Ceccherini {
1005ed70c5f3SStefano Ceccherini 	frame.InsetBy(2, 2);
100615cf50e0SStefano Ceccherini 	view->StrokeLine(frame.LeftTop(), frame.RightBottom());
100715cf50e0SStefano Ceccherini 	view->StrokeLine(frame.LeftBottom(), frame.RightTop());
100815cf50e0SStefano Ceccherini 	view->SetDrawingMode(B_OP_ALPHA);
100915cf50e0SStefano Ceccherini 	rgb_color color = kRed;
101015cf50e0SStefano Ceccherini 	color.alpha = 127;
101115cf50e0SStefano Ceccherini 	view->SetHighColor(color);
101215cf50e0SStefano Ceccherini 	view->FillRect(frame, B_SOLID_HIGH);
101315cf50e0SStefano Ceccherini }
101415cf50e0SStefano Ceccherini 
testPushPopState(BView * view,BRect frame)1015ed70c5f3SStefano Ceccherini static void testPushPopState(BView *view, BRect frame)
1016ed70c5f3SStefano Ceccherini {
1017ed70c5f3SStefano Ceccherini 	frame.InsetBy(2, 2);
1018ed70c5f3SStefano Ceccherini 	view->SetHighColor(kGreen);
1019ed70c5f3SStefano Ceccherini 	view->PushState();
1020ed70c5f3SStefano Ceccherini 	view->SetHighColor(kRed);
1021ed70c5f3SStefano Ceccherini 	view->PopState();
1022ed70c5f3SStefano Ceccherini 
1023ed70c5f3SStefano Ceccherini 	view->FillRect(frame, B_SOLID_HIGH);
1024ed70c5f3SStefano Ceccherini }
1025ed70c5f3SStefano Ceccherini 
testFontRotation(BView * view,BRect frame)10268247141fSMichael Pfeiffer static void testFontRotation(BView* view, BRect frame)
10278247141fSMichael Pfeiffer {
10288247141fSMichael Pfeiffer 	BFont font;
10298247141fSMichael Pfeiffer 	view->GetFont(&font);
10308247141fSMichael Pfeiffer 
10318247141fSMichael Pfeiffer 	font.SetRotation(90);
10328247141fSMichael Pfeiffer 	view->SetFont(&font, B_FONT_ROTATION);
10338247141fSMichael Pfeiffer 	view->DrawString("This is a test!", BPoint(frame.Width() / 2, frame.bottom - 3));
10348247141fSMichael Pfeiffer 
10358247141fSMichael Pfeiffer 	view->GetFont(&font);
10368247141fSMichael Pfeiffer 	if (font.Rotation() != 90.0)
10378247141fSMichael Pfeiffer 		fprintf(stderr, "Error: Rotation is %f but should be 90.0\n", font.Rotation());
10388247141fSMichael Pfeiffer }
103915cf50e0SStefano Ceccherini 
1040abf565b1SStefano Ceccherini 
testClipToRect(BView * view,BRect frame)104159a26ab6SJackBurton79 static void testClipToRect(BView* view, BRect frame)
104259a26ab6SJackBurton79 {
104359a26ab6SJackBurton79 	BRect clipped = frame;
104459a26ab6SJackBurton79 	clipped.InsetBy(5, 5);
104559a26ab6SJackBurton79 
104659a26ab6SJackBurton79 	view->ClipToRect(clipped);
104759a26ab6SJackBurton79 
104859a26ab6SJackBurton79 	view->FillRect(frame);
104959a26ab6SJackBurton79 }
105059a26ab6SJackBurton79 
105159a26ab6SJackBurton79 
testClipToInverseRect(BView * view,BRect frame)105259a26ab6SJackBurton79 static void testClipToInverseRect(BView* view, BRect frame)
105359a26ab6SJackBurton79 {
105459a26ab6SJackBurton79 	BRect clipped = frame;
105559a26ab6SJackBurton79 	clipped.InsetBy(5, 5);
105659a26ab6SJackBurton79 
105759a26ab6SJackBurton79 	view->ClipToInverseRect(clipped);
105859a26ab6SJackBurton79 
105959a26ab6SJackBurton79 	view->FillRect(frame);
106059a26ab6SJackBurton79 }
106159a26ab6SJackBurton79 
106259a26ab6SJackBurton79 
testClipToShape(BView * view,BRect frame)106359a26ab6SJackBurton79 static void testClipToShape(BView* view, BRect frame)
106459a26ab6SJackBurton79 {
106559a26ab6SJackBurton79 	frame.InsetBy(2, 2);
106659a26ab6SJackBurton79 	BShape shape;
106759a26ab6SJackBurton79 	shape.MoveTo(BPoint(frame.left, frame.bottom));
106859a26ab6SJackBurton79 	shape.LineTo(BPoint(frame.right, frame.top));
106959a26ab6SJackBurton79 	shape.LineTo(BPoint(frame.left, frame.top));
107059a26ab6SJackBurton79 	shape.LineTo(BPoint(frame.right, frame.bottom));
107159a26ab6SJackBurton79 	view->ClipToShape(&shape);
107259a26ab6SJackBurton79 
107359a26ab6SJackBurton79 	view->FillRect(frame);
107459a26ab6SJackBurton79 }
107559a26ab6SJackBurton79 
107659a26ab6SJackBurton79 
testClipToInverseShape(BView * view,BRect frame)107759a26ab6SJackBurton79 static void testClipToInverseShape(BView* view, BRect frame)
107859a26ab6SJackBurton79 {
107959a26ab6SJackBurton79 	frame.InsetBy(2, 2);
108059a26ab6SJackBurton79 	BShape shape;
108159a26ab6SJackBurton79 	shape.MoveTo(BPoint(frame.left, frame.bottom));
108259a26ab6SJackBurton79 	shape.LineTo(BPoint(frame.right, frame.top));
108359a26ab6SJackBurton79 	shape.LineTo(BPoint(frame.left, frame.top));
108459a26ab6SJackBurton79 	shape.LineTo(BPoint(frame.right, frame.bottom));
108559a26ab6SJackBurton79 	view->ClipToInverseShape(&shape);
108659a26ab6SJackBurton79 
108759a26ab6SJackBurton79 	view->FillRect(frame);
108859a26ab6SJackBurton79 }
1089abf565b1SStefano Ceccherini 
1090abf565b1SStefano Ceccherini 
1091c43f0163SMichael Pfeiffer // TODO
1092c43f0163SMichael Pfeiffer // - blending mode
1093c43f0163SMichael Pfeiffer // - line mode
1094c43f0163SMichael Pfeiffer // - push/pop state
1095c43f0163SMichael Pfeiffer // - move pen
1096c43f0163SMichael Pfeiffer // - set font
1097c43f0163SMichael Pfeiffer 
1098c43f0163SMichael Pfeiffer 
109982afdb09SMichael Pfeiffer TestCase gTestCases[] = {
110054730332SMichael Pfeiffer 	{ "Test No Operation", testNoOp },
110154730332SMichael Pfeiffer 	{ "Test DrawChar", testDrawChar },
110282afdb09SMichael Pfeiffer 	{ "Test Draw String", testDrawString },
110354730332SMichael Pfeiffer 	{ "Test Draw String With Length", testDrawStringWithLength },
1104abf565b1SStefano Ceccherini 	{ "Test Draw String With Offsets", testDrawStringWithOffsets },
11053211dcccSJackBurton79 	{ "Test Draw String Without Position", testDrawStringWithoutPosition },
110654730332SMichael Pfeiffer 	{ "Test FillArc", testFillArc },
110754730332SMichael Pfeiffer 	{ "Test StrokeArc", testStrokeArc },
1108c43f0163SMichael Pfeiffer 	// testFillBezier fails under BeOS because the
1109c43f0163SMichael Pfeiffer 	// direct draw version is not correct
111054730332SMichael Pfeiffer 	{ "Test FillBezier", testFillBezier },
111154730332SMichael Pfeiffer 	{ "Test StrokeBezier", testStrokeBezier },
111254730332SMichael Pfeiffer 	{ "Test FillEllipse", testFillEllipse },
111354730332SMichael Pfeiffer 	{ "Test StrokeEllipse", testStrokeEllipse },
111454730332SMichael Pfeiffer 	{ "Test FillPolygon", testFillPolygon },
111554730332SMichael Pfeiffer 	{ "Test StrokePolygon", testStrokePolygon },
111654730332SMichael Pfeiffer 	{ "Test FillRect", testFillRect },
1117abf565b1SStefano Ceccherini 	{ "Test FillRectGradientLinear", testFillRectGradientLinear },
1118abf565b1SStefano Ceccherini 	{ "Test FillRectGradientRadial", testFillRectGradientRadial },
1119abf565b1SStefano Ceccherini 	{ "Test FillRectGradientRadialFocus", testFillRectGradientRadialFocus },
1120abf565b1SStefano Ceccherini 	{ "Test FillRectGradientDiamond", testFillRectGradientDiamond },
1121abf565b1SStefano Ceccherini 	{ "Test FillRectGradientConic", testFillRectGradientConic },
112254730332SMichael Pfeiffer 	{ "Test StrokeRect", testStrokeRect },
112354730332SMichael Pfeiffer 	{ "Test FillRegion", testFillRegion },
1124b8c65995SStefano Ceccherini 	{ "Test FillRegionGradientLinear", testFillRegionGradientLinear },
1125b8c65995SStefano Ceccherini 	{ "Test FillRegionGradientRadial", testFillRegionGradientRadial },
1126b8c65995SStefano Ceccherini 	{ "Test FillRegionGradientRadialFocus", testFillRegionGradientRadialFocus },
1127b8c65995SStefano Ceccherini 	{ "Test FillRegionGradientDiamond", testFillRegionGradientDiamond },
1128b8c65995SStefano Ceccherini 	{ "Test FillRegionGradientConic", testFillRegionGradientConic },
112954730332SMichael Pfeiffer 	{ "Test FillRoundRect", testFillRoundRect },
113000c573d6SStefano Ceccherini 	{ "Test FillRoundRectGradientLinear", testFillRoundRectGradientLinear },
113100c573d6SStefano Ceccherini 	{ "Test FillRoundRectGradientRadial", testFillRoundRectGradientRadial },
113200c573d6SStefano Ceccherini 	{ "Test FillRoundRectGradientRadialFocus", testFillRoundRectGradientRadialFocus },
113300c573d6SStefano Ceccherini 	{ "Test FillRoundRectGradientDiamond", testFillRoundRectGradientDiamond },
113400c573d6SStefano Ceccherini 	{ "Test FillRoundRectGradientConic", testFillRoundRectGradientConic },
113554730332SMichael Pfeiffer 	{ "Test StrokeRoundRect", testStrokeRoundRect },
113654730332SMichael Pfeiffer 	{ "Test FillTriangle", testFillTriangle },
1137e5f9dfebSStefano Ceccherini 	{ "Test FillTriangleGradientLinear", testFillTriangleGradientLinear },
1138e5f9dfebSStefano Ceccherini 	{ "Test FillTriangleGradientRadial", testFillTriangleGradientRadial },
1139e5f9dfebSStefano Ceccherini 	{ "Test FillTriangleGradientRadialFocus", testFillTriangleGradientRadialFocus },
1140e5f9dfebSStefano Ceccherini 	{ "Test FillTriangleGradientDiamond", testFillTriangleGradientDiamond },
1141e5f9dfebSStefano Ceccherini 	{ "Test FillTriangleGradientConic", testFillTriangleGradientConic },
114254730332SMichael Pfeiffer 	{ "Test StrokeTriangle", testStrokeTriangle },
114354730332SMichael Pfeiffer 	{ "Test StrokeLine", testStrokeLine },
114454730332SMichael Pfeiffer 	{ "Test FillShape", testFillShape },
114554730332SMichael Pfeiffer 	{ "Test StrokeShape", testStrokeShape },
114682afdb09SMichael Pfeiffer 	{ "Test Record Picture", testRecordPicture },
114782afdb09SMichael Pfeiffer 	{ "Test Record And Play Picture", testRecordAndPlayPicture },
114882afdb09SMichael Pfeiffer 	{ "Test Record And Play Picture With Offset", testRecordAndPlayPictureWithOffset },
114954730332SMichael Pfeiffer 	{ "Test AppendToPicture", testAppendToPicture },
11508247141fSMichael Pfeiffer 	{ "Test Draw Scaled Picture", testDrawScaledPicture },
115154730332SMichael Pfeiffer 	{ "Test LineArray", testLineArray },
115254730332SMichael Pfeiffer 	{ "Test InvertRect", testInvertRect },
11537cf26360SStefano Ceccherini 	{ "Test InvertRectSetDrawingMode", testInvertRectSetDrawingMode },
11544f422578SMichael Pfeiffer 	{ "Test DrawBitmap", testDrawBitmap },
11554f422578SMichael Pfeiffer 	{ "Test DrawBitmapAtPoint", testDrawBitmapAtPoint },
11564f422578SMichael Pfeiffer 	{ "Test DrawBitmapAtRect", testDrawBitmapAtRect },
11575f380e34SMichael Pfeiffer 	{ "Test DrawLargeBitmap", testDrawLargeBitmap },
1158c43f0163SMichael Pfeiffer 	{ "Test ConstrainClippingRegion", testConstrainClippingRegion },
1159c43f0163SMichael Pfeiffer 	{ "Test ClipToPicture", testClipToPicture },
1160c43f0163SMichael Pfeiffer 	{ "Test ClipToInversePicture", testClipToInversePicture },
116159a26ab6SJackBurton79 	{ "Test ClipToRect", testClipToRect },
116259a26ab6SJackBurton79 	{ "Test ClipToInverseRect", testClipToInverseRect },
116359a26ab6SJackBurton79 	{ "Test ClipToShape", testClipToShape },
116459a26ab6SJackBurton79 	{ "Test ClipToInverseShape", testClipToInverseShape },
1165c43f0163SMichael Pfeiffer 	{ "Test SetPenSize", testSetPenSize },
1166c43f0163SMichael Pfeiffer 	{ "Test SetPenSize2", testSetPenSize2 },
1167c43f0163SMichael Pfeiffer 	{ "Test Pattern", testPattern },
1168c43f0163SMichael Pfeiffer 	{ "Test SetOrigin", testSetOrigin },
1169c43f0163SMichael Pfeiffer 	{ "Test SetOrigin2", testSetOrigin2 },
1170c43f0163SMichael Pfeiffer 	{ "Test SetScale", testSetScale },
1171c43f0163SMichael Pfeiffer 	// testSetScale2 fails under BeOS. The picture versions of the
1172c43f0163SMichael Pfeiffer 	// rectangle are twice as large as the direct draw version
1173b8c65995SStefano Ceccherini 	{ "Test SetScale2", testSetScale2 },
1174c43f0163SMichael Pfeiffer 	{ "Test SetScale3", testSetScale3 },
1175c9c4a80aSMichael Pfeiffer 	{ "Test SetOriginAndScale", testSetOriginAndScale },
11764b05331dSMichael Pfeiffer 	{ "Test SetOriginAndScale2", testSetOriginAndScale2 },
11774b05331dSMichael Pfeiffer 	{ "Test SetOriginAndScale3", testSetOriginAndScale3 },
11784b05331dSMichael Pfeiffer 	{ "Test SetOriginAndScale4", testSetOriginAndScale4 },
11794b05331dSMichael Pfeiffer 	{ "Test SetOriginAndScale5", testSetOriginAndScale5 },
1180c43f0163SMichael Pfeiffer 	{ "Test SetFontSize", testSetFontSize },
11812fb98dccSStefano Ceccherini 	{ "Test SetFontFamilyAndStyle", testSetFontFamilyAndStyle },
118215cf50e0SStefano Ceccherini 	{ "Test SetDrawingMode", testSetDrawingMode },
1183ed70c5f3SStefano Ceccherini 	{ "Test PushPopState", testPushPopState },
11848247141fSMichael Pfeiffer 	{ "Test FontRotation", testFontRotation },
118582afdb09SMichael Pfeiffer 	{ NULL, NULL }
118682afdb09SMichael Pfeiffer };
118762c7fd0fSMichael Pfeiffer 
11882fb98dccSStefano Ceccherini 
1189