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