xref: /haiku/src/tests/kits/interface/flatten_picture/PictureTestCases.cpp (revision abf565b12b875bb6a6f4b5792d0615bec262763b)
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 
11*abf565b1SStefano Ceccherini #include <GradientLinear.h>
12*abf565b1SStefano Ceccherini #include <GradientRadial.h>
13*abf565b1SStefano Ceccherini #include <GradientRadialFocus.h>
14*abf565b1SStefano Ceccherini #include <GradientDiamond.h>
15*abf565b1SStefano Ceccherini #include <GradientConic.h>
16*abf565b1SStefano Ceccherini 
178247141fSMichael Pfeiffer #include <stdio.h>
188247141fSMichael Pfeiffer 
1954730332SMichael Pfeiffer static const rgb_color kBlack = {0, 0, 0};
2054730332SMichael Pfeiffer static const rgb_color kWhite = {255, 255, 255};
2154730332SMichael Pfeiffer static const rgb_color kRed = {255, 0, 0};
2254730332SMichael Pfeiffer static const rgb_color kGreen = {0, 255, 0};
2354730332SMichael Pfeiffer static const rgb_color kBlue = {0, 0, 255};
2454730332SMichael Pfeiffer 
2554730332SMichael Pfeiffer static BPoint centerPoint(BRect rect)
2654730332SMichael Pfeiffer {
2754730332SMichael Pfeiffer 	int x = (int)(rect.left + rect.IntegerWidth() / 2);
2854730332SMichael Pfeiffer 	int y = (int)(rect.top + rect.IntegerHeight() / 2);
2954730332SMichael Pfeiffer 	return BPoint(x, y);
3054730332SMichael Pfeiffer }
3154730332SMichael Pfeiffer 
3254730332SMichael Pfeiffer static void testNoOp(BView *view, BRect frame)
3382afdb09SMichael Pfeiffer {
3482afdb09SMichael Pfeiffer 	// no op
3582afdb09SMichael Pfeiffer }
3682afdb09SMichael Pfeiffer 
3754730332SMichael Pfeiffer static void testDrawChar(BView *view, BRect frame)
3854730332SMichael Pfeiffer {
3954730332SMichael Pfeiffer 	view->MovePenTo(frame.left, frame.bottom - 5);
4054730332SMichael Pfeiffer 	view->DrawChar('A');
4154730332SMichael Pfeiffer 
4254730332SMichael Pfeiffer 	view->DrawChar('B', BPoint(frame.left + 20, frame.bottom - 5));
4354730332SMichael Pfeiffer }
4454730332SMichael Pfeiffer 
4554730332SMichael Pfeiffer static void testDrawString(BView *view, BRect frame)
4682afdb09SMichael Pfeiffer {
4782afdb09SMichael Pfeiffer 	BFont font;
4882afdb09SMichael Pfeiffer 	view->GetFont(&font);
4982afdb09SMichael Pfeiffer 	font_height height;
5082afdb09SMichael Pfeiffer 	font.GetHeight(&height);
5182afdb09SMichael Pfeiffer 	float baseline = frame.bottom - height.descent;
5282afdb09SMichael Pfeiffer 	// draw base line
5354730332SMichael Pfeiffer 	view->SetHighColor(kGreen);
5482afdb09SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1));
5582afdb09SMichael Pfeiffer 
5654730332SMichael Pfeiffer 	view->SetHighColor(kBlack);
5782afdb09SMichael Pfeiffer 	view->DrawString("Haiku [ÖÜÄöüä]", BPoint(frame.left, baseline));
5882afdb09SMichael Pfeiffer }
5982afdb09SMichael Pfeiffer 
6054730332SMichael Pfeiffer static void testDrawStringWithLength(BView *view, BRect frame)
6154730332SMichael Pfeiffer {
6254730332SMichael Pfeiffer 	BFont font;
6354730332SMichael Pfeiffer 	view->GetFont(&font);
6454730332SMichael Pfeiffer 	font_height height;
6554730332SMichael Pfeiffer 	font.GetHeight(&height);
6654730332SMichael Pfeiffer 	float baseline = frame.bottom - height.descent;
6754730332SMichael Pfeiffer 	// draw base line
6854730332SMichael Pfeiffer 	view->SetHighColor(kGreen);
6954730332SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1));
7054730332SMichael Pfeiffer 
7154730332SMichael Pfeiffer 	view->SetHighColor(kBlack);
7254730332SMichael Pfeiffer 	view->DrawString("Haiku [ÖÜÄöüä]", 13, BPoint(frame.left, baseline));
7354730332SMichael Pfeiffer }
7454730332SMichael Pfeiffer 
75*abf565b1SStefano Ceccherini 
76*abf565b1SStefano Ceccherini static void testDrawStringWithOffsets(BView* view, BRect frame)
77*abf565b1SStefano Ceccherini {
78*abf565b1SStefano Ceccherini 	BFont font;
79*abf565b1SStefano Ceccherini 	view->GetFont(&font);
80*abf565b1SStefano Ceccherini 	font_height height;
81*abf565b1SStefano Ceccherini 	font.GetHeight(&height);
82*abf565b1SStefano Ceccherini 	float baseline = frame.bottom - height.descent;
83*abf565b1SStefano Ceccherini 	// draw base line
84*abf565b1SStefano Ceccherini 	view->SetHighColor(kGreen);
85*abf565b1SStefano Ceccherini 	view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1));
86*abf565b1SStefano Ceccherini 
87*abf565b1SStefano Ceccherini 	view->SetHighColor(kBlack);
88*abf565b1SStefano Ceccherini 	const BPoint pointArray[] = { BPoint(frame.left, baseline) };
89*abf565b1SStefano Ceccherini 	view->DrawString("Haiku [ÖÜÄöüä]", pointArray, sizeof(pointArray) / sizeof(pointArray[0]));
90*abf565b1SStefano Ceccherini }
91*abf565b1SStefano Ceccherini 
92*abf565b1SStefano Ceccherini 
9354730332SMichael Pfeiffer static void testFillArc(BView *view, BRect frame)
9482afdb09SMichael Pfeiffer {
9582afdb09SMichael Pfeiffer 	frame.InsetBy(2, 2);
9654730332SMichael Pfeiffer 	view->FillArc(frame, 45, 180);
9754730332SMichael Pfeiffer }
9854730332SMichael Pfeiffer 
9954730332SMichael Pfeiffer static void testStrokeArc(BView *view, BRect frame)
10054730332SMichael Pfeiffer {
10154730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
10254730332SMichael Pfeiffer 	view->StrokeArc(frame, 45, 180);
10354730332SMichael Pfeiffer }
10454730332SMichael Pfeiffer 
10554730332SMichael Pfeiffer static void testFillBezier(BView *view, BRect frame)
10654730332SMichael Pfeiffer {
10754730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
10854730332SMichael Pfeiffer 	BPoint points[4];
10954730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.bottom);
11054730332SMichael Pfeiffer 	points[1] = BPoint(frame.left, frame.top);
11154730332SMichael Pfeiffer 	points[1] = BPoint(frame.left, frame.top);
11254730332SMichael Pfeiffer 	points[3] = BPoint(frame.right, frame.top);
11354730332SMichael Pfeiffer 	view->FillBezier(points);
11454730332SMichael Pfeiffer }
11554730332SMichael Pfeiffer 
11654730332SMichael Pfeiffer static void testStrokeBezier(BView *view, BRect frame)
11754730332SMichael Pfeiffer {
11854730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
11954730332SMichael Pfeiffer 	BPoint points[4];
12054730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.bottom);
12154730332SMichael Pfeiffer 	points[1] = BPoint(frame.left, frame.top);
12254730332SMichael Pfeiffer 	points[1] = BPoint(frame.left, frame.top);
12354730332SMichael Pfeiffer 	points[3] = BPoint(frame.right, frame.top);
12454730332SMichael Pfeiffer 	view->StrokeBezier(points);
12554730332SMichael Pfeiffer }
12654730332SMichael Pfeiffer 
12754730332SMichael Pfeiffer static void testFillEllipse(BView *view, BRect frame)
12854730332SMichael Pfeiffer {
12954730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
13054730332SMichael Pfeiffer 	view->FillEllipse(frame);
13154730332SMichael Pfeiffer 
13254730332SMichael Pfeiffer 	view->SetHighColor(kRed);
13354730332SMichael Pfeiffer 	float r = frame.Width() / 3;
13454730332SMichael Pfeiffer 	float s = frame.Height() / 4;
13554730332SMichael Pfeiffer 	view->FillEllipse(centerPoint(frame), r, s);
13654730332SMichael Pfeiffer }
13754730332SMichael Pfeiffer 
13854730332SMichael Pfeiffer static void testStrokeEllipse(BView *view, BRect frame)
13954730332SMichael Pfeiffer {
14054730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
14154730332SMichael Pfeiffer 	view->StrokeEllipse(frame);
14254730332SMichael Pfeiffer 
14354730332SMichael Pfeiffer 	view->SetHighColor(kRed);
14454730332SMichael Pfeiffer 	float r = frame.Width() / 3;
14554730332SMichael Pfeiffer 	float s = frame.Height() / 4;
14654730332SMichael Pfeiffer 	view->StrokeEllipse(centerPoint(frame), r, s);
14754730332SMichael Pfeiffer }
14854730332SMichael Pfeiffer 
14954730332SMichael Pfeiffer static void testFillPolygon(BView *view, BRect frame)
15054730332SMichael Pfeiffer {
15154730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
15254730332SMichael Pfeiffer 
15354730332SMichael Pfeiffer 	BPoint points[4];
15454730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.top);
15554730332SMichael Pfeiffer 	points[1] = BPoint(frame.right, frame.bottom);
15654730332SMichael Pfeiffer 	points[2] = BPoint(frame.right, frame.top);
15754730332SMichael Pfeiffer 	points[3] = BPoint(frame.left, frame.bottom);
15854730332SMichael Pfeiffer 
15954730332SMichael Pfeiffer 	view->FillPolygon(points, 4);
16054730332SMichael Pfeiffer }
16154730332SMichael Pfeiffer 
16254730332SMichael Pfeiffer static void testStrokePolygon(BView *view, BRect frame)
16354730332SMichael Pfeiffer {
16454730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
16554730332SMichael Pfeiffer 
16654730332SMichael Pfeiffer 	BPoint points[4];
16754730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.top);
16854730332SMichael Pfeiffer 	points[1] = BPoint(frame.right, frame.bottom);
16954730332SMichael Pfeiffer 	points[2] = BPoint(frame.right, frame.top);
17054730332SMichael Pfeiffer 	points[3] = BPoint(frame.left, frame.bottom);
17154730332SMichael Pfeiffer 
17254730332SMichael Pfeiffer 	view->StrokePolygon(points, 4);
17354730332SMichael Pfeiffer }
17454730332SMichael Pfeiffer 
17554730332SMichael Pfeiffer static void testFillRect(BView *view, BRect frame)
17654730332SMichael Pfeiffer {
17754730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
17882afdb09SMichael Pfeiffer 	view->FillRect(frame);
17982afdb09SMichael Pfeiffer }
18082afdb09SMichael Pfeiffer 
181*abf565b1SStefano Ceccherini 
182*abf565b1SStefano Ceccherini static void testFillRectGradientLinear(BView* view, BRect frame)
183*abf565b1SStefano Ceccherini {
184*abf565b1SStefano Ceccherini 	BGradientLinear gradient(0, 0, frame.right, frame.bottom);
185*abf565b1SStefano Ceccherini 	gradient.AddColor(kRed, 0);
186*abf565b1SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
187*abf565b1SStefano Ceccherini 	frame.InsetBy(2, 2);
188*abf565b1SStefano Ceccherini 	view->FillRect(frame, gradient);
189*abf565b1SStefano Ceccherini }
190*abf565b1SStefano Ceccherini 
191*abf565b1SStefano Ceccherini static void testFillRectGradientRadial(BView* view, BRect frame)
192*abf565b1SStefano Ceccherini {
193*abf565b1SStefano Ceccherini 	BGradientRadial gradient(10, 10, 10);
194*abf565b1SStefano Ceccherini 	gradient.AddColor(kRed, 0);
195*abf565b1SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
196*abf565b1SStefano Ceccherini 	frame.InsetBy(2, 2);
197*abf565b1SStefano Ceccherini 	view->FillRect(frame, gradient);
198*abf565b1SStefano Ceccherini }
199*abf565b1SStefano Ceccherini 
200*abf565b1SStefano Ceccherini static void testFillRectGradientRadialFocus(BView* view, BRect frame)
201*abf565b1SStefano Ceccherini {
202*abf565b1SStefano Ceccherini 	BGradientRadialFocus gradient(0, 0, 10, 10, 5);
203*abf565b1SStefano Ceccherini 	gradient.AddColor(kRed, 0);
204*abf565b1SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
205*abf565b1SStefano Ceccherini 	frame.InsetBy(2, 2);
206*abf565b1SStefano Ceccherini 	view->FillRect(frame, gradient);
207*abf565b1SStefano Ceccherini }
208*abf565b1SStefano Ceccherini 
209*abf565b1SStefano Ceccherini static void testFillRectGradientDiamond(BView* view, BRect frame)
210*abf565b1SStefano Ceccherini {
211*abf565b1SStefano Ceccherini 	BGradientDiamond gradient(0, 10);
212*abf565b1SStefano Ceccherini 	gradient.AddColor(kRed, 0);
213*abf565b1SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
214*abf565b1SStefano Ceccherini 	frame.InsetBy(2, 2);
215*abf565b1SStefano Ceccherini 	view->FillRect(frame, gradient);
216*abf565b1SStefano Ceccherini }
217*abf565b1SStefano Ceccherini 
218*abf565b1SStefano Ceccherini static void testFillRectGradientConic(BView* view, BRect frame)
219*abf565b1SStefano Ceccherini {
220*abf565b1SStefano Ceccherini 	BGradientConic gradient(0, 0, 10);
221*abf565b1SStefano Ceccherini 	gradient.AddColor(kRed, 0);
222*abf565b1SStefano Ceccherini 	gradient.AddColor(kBlue, 255);
223*abf565b1SStefano Ceccherini 	frame.InsetBy(2, 2);
224*abf565b1SStefano Ceccherini 	view->FillRect(frame, gradient);
225*abf565b1SStefano Ceccherini }
226*abf565b1SStefano Ceccherini 
22754730332SMichael Pfeiffer static void testStrokeRect(BView *view, BRect frame)
22882afdb09SMichael Pfeiffer {
22982afdb09SMichael Pfeiffer 	frame.InsetBy(2, 2);
23082afdb09SMichael Pfeiffer 	view->StrokeRect(frame);
23182afdb09SMichael Pfeiffer }
23282afdb09SMichael Pfeiffer 
23354730332SMichael Pfeiffer static void testFillRegion(BView *view, BRect frame)
23482afdb09SMichael Pfeiffer {
23554730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
23654730332SMichael Pfeiffer 	BRegion region(frame);
23754730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
23854730332SMichael Pfeiffer 	region.Exclude(frame);
23954730332SMichael Pfeiffer 	view->FillRegion(&region);
24054730332SMichael Pfeiffer }
24154730332SMichael Pfeiffer 
24254730332SMichael Pfeiffer static void testFillRoundRect(BView *view, BRect frame)
24354730332SMichael Pfeiffer {
24454730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
24554730332SMichael Pfeiffer 	view->FillRoundRect(frame, 5, 3);
24654730332SMichael Pfeiffer }
24754730332SMichael Pfeiffer 
24854730332SMichael Pfeiffer static void testStrokeRoundRect(BView *view, BRect frame)
24954730332SMichael Pfeiffer {
25054730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
25154730332SMichael Pfeiffer 	view->StrokeRoundRect(frame, 5, 3);
25254730332SMichael Pfeiffer }
25354730332SMichael Pfeiffer 
25454730332SMichael Pfeiffer static void testFillTriangle(BView *view, BRect frame)
25554730332SMichael Pfeiffer {
25654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
25754730332SMichael Pfeiffer 	BPoint points[3];
25854730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.bottom);
25954730332SMichael Pfeiffer 	points[1] = BPoint(centerPoint(frame).x, frame.top);
26054730332SMichael Pfeiffer 	points[2] = BPoint(frame.right, frame.bottom);
26154730332SMichael Pfeiffer 	view->FillTriangle(points[0], points[1], points[2]);
26254730332SMichael Pfeiffer }
26354730332SMichael Pfeiffer 
26454730332SMichael Pfeiffer static void testStrokeTriangle(BView *view, BRect frame)
26554730332SMichael Pfeiffer {
26654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
26754730332SMichael Pfeiffer 	BPoint points[3];
26854730332SMichael Pfeiffer 	points[0] = BPoint(frame.left, frame.bottom);
26954730332SMichael Pfeiffer 	points[1] = BPoint(centerPoint(frame).x, frame.top);
27054730332SMichael Pfeiffer 	points[2] = BPoint(frame.right, frame.bottom);
27154730332SMichael Pfeiffer 	view->StrokeTriangle(points[0], points[1], points[2]);
27254730332SMichael Pfeiffer }
27354730332SMichael Pfeiffer 
27454730332SMichael Pfeiffer static void testStrokeLine(BView *view, BRect frame)
27554730332SMichael Pfeiffer {
27654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
27754730332SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top));
27854730332SMichael Pfeiffer 
27954730332SMichael Pfeiffer 	frame.top += 2;
28054730332SMichael Pfeiffer 	frame.bottom -= 2;
28182afdb09SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.bottom));
28254730332SMichael Pfeiffer 
28354730332SMichael Pfeiffer 	frame.bottom += 2;;
28454730332SMichael Pfeiffer 	frame.top = frame.bottom;
28554730332SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.right, frame.top), BPoint(frame.left, frame.top));
28682afdb09SMichael Pfeiffer }
28782afdb09SMichael Pfeiffer 
28854730332SMichael Pfeiffer static void testFillShape(BView *view, BRect frame)
28982afdb09SMichael Pfeiffer {
29054730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
29154730332SMichael Pfeiffer 	BShape shape;
29254730332SMichael Pfeiffer 	shape.MoveTo(BPoint(frame.left, frame.bottom));
29354730332SMichael Pfeiffer 	shape.LineTo(BPoint(frame.right, frame.top));
29454730332SMichael Pfeiffer 	shape.LineTo(BPoint(frame.left, frame.top));
29554730332SMichael Pfeiffer 	shape.LineTo(BPoint(frame.right, frame.bottom));
29654730332SMichael Pfeiffer 	view->FillShape(&shape);
29782afdb09SMichael Pfeiffer }
29882afdb09SMichael Pfeiffer 
29954730332SMichael Pfeiffer static void testStrokeShape(BView *view, BRect frame)
30054730332SMichael Pfeiffer {
30154730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
30254730332SMichael Pfeiffer 	BShape shape;
30354730332SMichael Pfeiffer 	shape.MoveTo(BPoint(frame.left, frame.bottom));
30454730332SMichael Pfeiffer 	shape.LineTo(BPoint(frame.right, frame.top));
30554730332SMichael Pfeiffer 	shape.LineTo(BPoint(frame.left, frame.top));
30654730332SMichael Pfeiffer 	shape.LineTo(BPoint(frame.right, frame.bottom));
30754730332SMichael Pfeiffer 	view->StrokeShape(&shape);
30854730332SMichael Pfeiffer }
30954730332SMichael Pfeiffer 
31054730332SMichael Pfeiffer static void testRecordPicture(BView *view, BRect frame)
31182afdb09SMichael Pfeiffer {
31282afdb09SMichael Pfeiffer 	BPicture *picture = new BPicture();
31382afdb09SMichael Pfeiffer 	view->BeginPicture(picture);
31482afdb09SMichael Pfeiffer 	view->FillRect(frame);
31582afdb09SMichael Pfeiffer 	view->EndPicture();
31682afdb09SMichael Pfeiffer 	delete picture;
31782afdb09SMichael Pfeiffer }
31882afdb09SMichael Pfeiffer 
31954730332SMichael Pfeiffer static void testRecordAndPlayPicture(BView *view, BRect frame)
32082afdb09SMichael Pfeiffer {
32182afdb09SMichael Pfeiffer 	BPicture *picture = new BPicture();
32282afdb09SMichael Pfeiffer 	view->BeginPicture(picture);
32382afdb09SMichael Pfeiffer 	frame.InsetBy(2, 2);
32482afdb09SMichael Pfeiffer 	view->FillRect(frame);
32582afdb09SMichael Pfeiffer 	view->EndPicture();
32682afdb09SMichael Pfeiffer 	view->DrawPicture(picture);
32782afdb09SMichael Pfeiffer 	delete picture;
32882afdb09SMichael Pfeiffer }
32982afdb09SMichael Pfeiffer 
33054730332SMichael Pfeiffer static void testRecordAndPlayPictureWithOffset(BView *view, BRect frame)
33182afdb09SMichael Pfeiffer {
33282afdb09SMichael Pfeiffer 	BPicture *picture = new BPicture();
33382afdb09SMichael Pfeiffer 	view->BeginPicture(picture);
33482afdb09SMichael Pfeiffer 	frame.InsetBy(frame.Width() / 4, frame.Height() / 4);
33582afdb09SMichael Pfeiffer 	frame.OffsetTo(0, 0);
33682afdb09SMichael Pfeiffer 	view->FillRect(frame);
33782afdb09SMichael Pfeiffer 	view->EndPicture();
33882afdb09SMichael Pfeiffer 
33982afdb09SMichael Pfeiffer 	view->DrawPicture(picture, BPoint(10, 10));
34082afdb09SMichael Pfeiffer 	// color of picture should not change
34154730332SMichael Pfeiffer 	view->SetLowColor(kGreen);
34254730332SMichael Pfeiffer 	view->SetLowColor(kRed);
34382afdb09SMichael Pfeiffer 	view->DrawPicture(picture, BPoint(0, 0));
34482afdb09SMichael Pfeiffer 	delete picture;
34582afdb09SMichael Pfeiffer }
34682afdb09SMichael Pfeiffer 
34754730332SMichael Pfeiffer static void testAppendToPicture(BView *view, BRect frame)
34854730332SMichael Pfeiffer {
34954730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
35054730332SMichael Pfeiffer 	view->BeginPicture(new BPicture());
35154730332SMichael Pfeiffer 	view->FillRect(frame);
35254730332SMichael Pfeiffer 	BPicture* picture = view->EndPicture();
35354730332SMichael Pfeiffer 	if (picture == NULL)
35454730332SMichael Pfeiffer 		return;
35554730332SMichael Pfeiffer 
35654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
35754730332SMichael Pfeiffer 	view->AppendToPicture(picture);
35854730332SMichael Pfeiffer 	view->SetHighColor(kRed);
35954730332SMichael Pfeiffer 	view->FillRect(frame);
36054730332SMichael Pfeiffer 	if (view->EndPicture() != picture)
36154730332SMichael Pfeiffer 		return;
36254730332SMichael Pfeiffer 
36354730332SMichael Pfeiffer 	view->DrawPicture(picture);
36454730332SMichael Pfeiffer 	delete picture;
36554730332SMichael Pfeiffer }
36654730332SMichael Pfeiffer 
3678247141fSMichael Pfeiffer static void testDrawScaledPicture(BView* view, BRect frame)
3688247141fSMichael Pfeiffer {
3698247141fSMichael Pfeiffer 	view->BeginPicture(new BPicture());
3708247141fSMichael Pfeiffer 	view->FillRect(BRect(0, 0, 15, 15));
3718247141fSMichael Pfeiffer 	BPicture* picture = view->EndPicture();
3728247141fSMichael Pfeiffer 
3738247141fSMichael Pfeiffer 	// first unscaled at left, top
3748247141fSMichael Pfeiffer 	view->DrawPicture(picture, BPoint(2, 2));
3758247141fSMichael Pfeiffer 
3768247141fSMichael Pfeiffer 	// draw scaled at middle top
3778247141fSMichael Pfeiffer 	view->SetScale(0.5);
3788247141fSMichael Pfeiffer 	// the drawing offset must be scaled too!
379ff973abcSMichael Pfeiffer 	view->DrawPicture(picture, BPoint(frame.Width(), 4));
3808247141fSMichael Pfeiffer 
3818247141fSMichael Pfeiffer 	delete picture;
3828247141fSMichael Pfeiffer }
3838247141fSMichael Pfeiffer 
38454730332SMichael Pfeiffer static void testLineArray(BView *view, BRect frame)
38554730332SMichael Pfeiffer {
38654730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
38754730332SMichael Pfeiffer 	view->BeginLineArray(3);
38854730332SMichael Pfeiffer 	view->AddLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top), kBlack);
38954730332SMichael Pfeiffer 
39054730332SMichael Pfeiffer 	frame.top += 2;
39154730332SMichael Pfeiffer 	frame.bottom -= 2;
39254730332SMichael Pfeiffer 	view->AddLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.bottom), kRed);
39354730332SMichael Pfeiffer 
39454730332SMichael Pfeiffer 	frame.bottom += 2;;
39554730332SMichael Pfeiffer 	frame.top = frame.bottom;
39654730332SMichael Pfeiffer 	view->AddLine(BPoint(frame.right, frame.top), BPoint(frame.left, frame.top), kGreen);
39754730332SMichael Pfeiffer 
39854730332SMichael Pfeiffer 	view->EndLineArray();
39954730332SMichael Pfeiffer }
40054730332SMichael Pfeiffer 
40154730332SMichael Pfeiffer static void testInvertRect(BView *view, BRect frame)
40254730332SMichael Pfeiffer {
40354730332SMichael Pfeiffer 	frame.InsetBy(2, 2);
40454730332SMichael Pfeiffer 	view->InvertRect(frame);
40554730332SMichael Pfeiffer }
40654730332SMichael Pfeiffer 
4074f422578SMichael Pfeiffer static bool isBorder(int32 x, int32 y, int32 width, int32 height) {
4084f422578SMichael Pfeiffer 	return x == 0 || y == 0 || x == width - 1 || y == height - 1;
4094f422578SMichael Pfeiffer }
4104f422578SMichael Pfeiffer 
4114f422578SMichael Pfeiffer static void fillBitmap(BBitmap &bitmap) {
4124f422578SMichael Pfeiffer 	int32 height = bitmap.Bounds().IntegerHeight()+1;
4134f422578SMichael Pfeiffer 	int32 width = bitmap.Bounds().IntegerWidth()+1;
4144f422578SMichael Pfeiffer 	for (int32 y = 0; y < height; y ++) {
4154f422578SMichael Pfeiffer 		for (int32 x = 0; x < width; x ++) {
41682afdb09SMichael Pfeiffer 			char *pixel = (char*)bitmap.Bits();
41782afdb09SMichael Pfeiffer 			pixel += bitmap.BytesPerRow() * y + 4 * x;
4184f422578SMichael Pfeiffer 			if (isBorder(x, y, width, height)) {
4194f422578SMichael Pfeiffer 				// fill with green
4204f422578SMichael Pfeiffer 				pixel[0] = 255;
4214f422578SMichael Pfeiffer 				pixel[1] = 0;
4224f422578SMichael Pfeiffer 				pixel[2] = 255;
4234f422578SMichael Pfeiffer 				pixel[3] = 0;
4244f422578SMichael Pfeiffer 			} else  {
42582afdb09SMichael Pfeiffer 				// fill with blue
42682afdb09SMichael Pfeiffer 				pixel[0] = 255;
42782afdb09SMichael Pfeiffer 				pixel[1] = 0;
42882afdb09SMichael Pfeiffer 				pixel[2] = 0;
42982afdb09SMichael Pfeiffer 				pixel[3] = 255;
43082afdb09SMichael Pfeiffer 			}
43182afdb09SMichael Pfeiffer 		}
4324f422578SMichael Pfeiffer 	}
4334f422578SMichael Pfeiffer }
4344f422578SMichael Pfeiffer 
4354f422578SMichael Pfeiffer static void testDrawBitmap(BView *view, BRect frame) {
4364f422578SMichael Pfeiffer 	BBitmap bitmap(frame, B_RGBA32);
4374f422578SMichael Pfeiffer 	fillBitmap(bitmap);
43882afdb09SMichael Pfeiffer 	view->DrawBitmap(&bitmap, BPoint(0, 0));
43982afdb09SMichael Pfeiffer }
44082afdb09SMichael Pfeiffer 
4414f422578SMichael Pfeiffer static void testDrawBitmapAtPoint(BView *view, BRect frame) {
4424f422578SMichael Pfeiffer 	frame.InsetBy(2, 2);
4434f422578SMichael Pfeiffer 
4444f422578SMichael Pfeiffer 	BRect bounds(frame);
4454f422578SMichael Pfeiffer 	bounds.OffsetTo(0, 0);
4464f422578SMichael Pfeiffer 	bounds.right /= 2;
4474f422578SMichael Pfeiffer 	bounds.bottom /= 2;
4484f422578SMichael Pfeiffer 
4494f422578SMichael Pfeiffer 	BBitmap bitmap(bounds, B_RGBA32);
4504f422578SMichael Pfeiffer 	fillBitmap(bitmap);
4514f422578SMichael Pfeiffer 	view->DrawBitmap(&bitmap, centerPoint(frame));
4524f422578SMichael Pfeiffer }
4534f422578SMichael Pfeiffer 
4544f422578SMichael Pfeiffer static void testDrawBitmapAtRect(BView *view, BRect frame) {
4554f422578SMichael Pfeiffer 	BRect bounds(frame);
4564f422578SMichael Pfeiffer 	BBitmap bitmap(bounds, B_RGBA32);
4574f422578SMichael Pfeiffer 	fillBitmap(bitmap);
4584f422578SMichael Pfeiffer 	frame.InsetBy(2, 2);
4594f422578SMichael Pfeiffer 	view->DrawBitmap(&bitmap, frame);
4604f422578SMichael Pfeiffer }
4614f422578SMichael Pfeiffer 
4624f422578SMichael Pfeiffer static void testDrawLargeBitmap(BView *view, BRect frame) {
4634f422578SMichael Pfeiffer 	BRect bounds(frame);
4644f422578SMichael Pfeiffer 	bounds.OffsetTo(0, 0);
4658247141fSMichael Pfeiffer 	bounds.right *= 4;
4668247141fSMichael Pfeiffer 	bounds.bottom *= 4;
4674f422578SMichael Pfeiffer 	BBitmap bitmap(bounds, B_RGBA32);
4684f422578SMichael Pfeiffer 	fillBitmap(bitmap);
4694f422578SMichael Pfeiffer 	frame.InsetBy(2, 2);
4704f422578SMichael Pfeiffer 	view->DrawBitmap(&bitmap, frame);
4714f422578SMichael Pfeiffer }
4724f422578SMichael Pfeiffer 
473c43f0163SMichael Pfeiffer static void testConstrainClippingRegion(BView *view, BRect frame)
474c43f0163SMichael Pfeiffer {
475c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
476c43f0163SMichael Pfeiffer 	// draw background
477c43f0163SMichael Pfeiffer 	view->SetHighColor(kRed);
478c43f0163SMichael Pfeiffer 	view->FillRect(frame);
479c43f0163SMichael Pfeiffer 
480c43f0163SMichael Pfeiffer 	frame.InsetBy(1, 1);
481c43f0163SMichael Pfeiffer 	BRegion region(frame);
482c43f0163SMichael Pfeiffer 	BRect r(frame);
483c43f0163SMichael Pfeiffer 	r.InsetBy(r.IntegerWidth() / 4, r.IntegerHeight() / 4);
484c43f0163SMichael Pfeiffer 	region.Exclude(r);
485c43f0163SMichael Pfeiffer 	view->ConstrainClippingRegion(&region);
486c43f0163SMichael Pfeiffer 
487c43f0163SMichael Pfeiffer 	frame.InsetBy(-1, -1);
488c43f0163SMichael Pfeiffer 	view->SetHighColor(kBlack);
489c43f0163SMichael Pfeiffer 	view->FillRect(frame);
490c43f0163SMichael Pfeiffer 	// a filled black rectangle with a red one pixel border
491c43f0163SMichael Pfeiffer 	// and inside a red rectangle should be drawn.
492c43f0163SMichael Pfeiffer }
493c43f0163SMichael Pfeiffer 
494c43f0163SMichael Pfeiffer static void testClipToPicture(BView *view, BRect frame)
495c43f0163SMichael Pfeiffer {
496c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
497c43f0163SMichael Pfeiffer 	view->BeginPicture(new BPicture());
498c43f0163SMichael Pfeiffer 	view->FillEllipse(frame);
499c43f0163SMichael Pfeiffer 	BPicture *picture = view->EndPicture();
500c43f0163SMichael Pfeiffer 	if (picture == NULL)
501c43f0163SMichael Pfeiffer 		return;
502c43f0163SMichael Pfeiffer 
503c43f0163SMichael Pfeiffer 	view->ClipToPicture(picture);
504c43f0163SMichael Pfeiffer 	delete picture;
505c43f0163SMichael Pfeiffer 
506c43f0163SMichael Pfeiffer 	view->FillRect(frame);
507c43f0163SMichael Pfeiffer 	// black ellipse should be drawn
508c43f0163SMichael Pfeiffer }
509c43f0163SMichael Pfeiffer 
510c43f0163SMichael Pfeiffer static void testClipToInversePicture(BView *view, BRect frame)
511c43f0163SMichael Pfeiffer {
512c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
513c43f0163SMichael Pfeiffer 
514c43f0163SMichael Pfeiffer 	view->BeginPicture(new BPicture());
515c43f0163SMichael Pfeiffer 	view->FillEllipse(frame);
516c43f0163SMichael Pfeiffer 	BPicture *picture = view->EndPicture();
517c43f0163SMichael Pfeiffer 	if (picture == NULL)
518c43f0163SMichael Pfeiffer 		return;
519c43f0163SMichael Pfeiffer 
520c43f0163SMichael Pfeiffer 	view->ClipToInversePicture(picture);
521c43f0163SMichael Pfeiffer 	delete picture;
522c43f0163SMichael Pfeiffer 
523c43f0163SMichael Pfeiffer 	view->FillRect(frame);
524c43f0163SMichael Pfeiffer 	// white ellipse inside a black rectangle
525c43f0163SMichael Pfeiffer }
526c43f0163SMichael Pfeiffer 
527c43f0163SMichael Pfeiffer static void testSetPenSize(BView *view, BRect frame)
528c43f0163SMichael Pfeiffer {
529c43f0163SMichael Pfeiffer 	frame.InsetBy(8, 2);
530c43f0163SMichael Pfeiffer 	float x = centerPoint(frame).x;
531c43f0163SMichael Pfeiffer 
532c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top));
533c43f0163SMichael Pfeiffer 
534c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, 5);
535c43f0163SMichael Pfeiffer 	view->SetPenSize(1);
536c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
537c43f0163SMichael Pfeiffer 	view->SetPenSize(0);
538c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));
539c43f0163SMichael Pfeiffer 
540c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, 5);
541c43f0163SMichael Pfeiffer 	view->SetPenSize(1);
542c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
543c43f0163SMichael Pfeiffer 	view->SetPenSize(2);
544c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));
545c43f0163SMichael Pfeiffer 
546c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, 5);
547c43f0163SMichael Pfeiffer 	view->SetPenSize(1);
548c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
549c43f0163SMichael Pfeiffer 	view->SetPenSize(3);
550c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));
551c43f0163SMichael Pfeiffer 
552c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, 5);
553c43f0163SMichael Pfeiffer 	view->SetPenSize(1);
554c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
555c43f0163SMichael Pfeiffer 	view->SetPenSize(4);
556c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));
557c43f0163SMichael Pfeiffer }
558c43f0163SMichael Pfeiffer 
559c43f0163SMichael Pfeiffer static void testSetPenSize2(BView *view, BRect frame)
560c43f0163SMichael Pfeiffer {
561c43f0163SMichael Pfeiffer 	// test if pen size is scaled too
562c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
563c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, 5);
564c43f0163SMichael Pfeiffer 	view->SetPenSize(4);
565c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top));
566c43f0163SMichael Pfeiffer 	view->SetScale(0.5);
567c43f0163SMichael Pfeiffer 	view->StrokeLine(BPoint(frame.left + 2, frame.bottom), BPoint(frame.right + 2, frame.bottom));
568c43f0163SMichael Pfeiffer 
569c43f0163SMichael Pfeiffer 	// black line from left to right, 4 pixel size
570c43f0163SMichael Pfeiffer 	// below black line with half the length of the first one
571c43f0163SMichael Pfeiffer 	// and 2 pixel size
572c43f0163SMichael Pfeiffer }
573c43f0163SMichael Pfeiffer 
574c43f0163SMichael Pfeiffer static void testPattern(BView *view, BRect frame)
575c43f0163SMichael Pfeiffer {
576c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
577c43f0163SMichael Pfeiffer 	int x = frame.IntegerWidth() / 3;
578c43f0163SMichael Pfeiffer 	frame.right = frame.left + x - 2;
579c43f0163SMichael Pfeiffer 		// -2 for an empty pixel row between
580c43f0163SMichael Pfeiffer 		// filled rectangles
581c43f0163SMichael Pfeiffer 
582c43f0163SMichael Pfeiffer 	view->SetLowColor(kGreen);
583c43f0163SMichael Pfeiffer 	view->SetHighColor(kRed);
584c43f0163SMichael Pfeiffer 
585c43f0163SMichael Pfeiffer 	view->FillRect(frame, B_SOLID_HIGH);
586c43f0163SMichael Pfeiffer 
587c43f0163SMichael Pfeiffer 	frame.OffsetBy(x, 0);
588c43f0163SMichael Pfeiffer 	view->FillRect(frame, B_MIXED_COLORS);
589c43f0163SMichael Pfeiffer 
590c43f0163SMichael Pfeiffer 	frame.OffsetBy(x, 0);
591c43f0163SMichael Pfeiffer 	view->FillRect(frame, B_SOLID_LOW);
592c43f0163SMichael Pfeiffer }
593c43f0163SMichael Pfeiffer 
594c43f0163SMichael Pfeiffer static void testSetOrigin(BView *view, BRect frame)
595c43f0163SMichael Pfeiffer {
596c43f0163SMichael Pfeiffer 	BPoint origin = view->Origin();
597c43f0163SMichael Pfeiffer 	BPoint center = centerPoint(frame);
598c43f0163SMichael Pfeiffer 	view->SetOrigin(center);
599c43f0163SMichael Pfeiffer 
600c43f0163SMichael Pfeiffer 	BRect r(0, 0, center.x, center.y);
601c43f0163SMichael Pfeiffer 	view->SetHighColor(kBlue);
602c43f0163SMichael Pfeiffer 	view->FillRect(r);
603c43f0163SMichael Pfeiffer 
604c43f0163SMichael Pfeiffer 	view->SetOrigin(origin);
605c43f0163SMichael Pfeiffer 	view->SetHighColor(kRed);
606c43f0163SMichael Pfeiffer 	view->FillRect(r);
607c43f0163SMichael Pfeiffer 
608c43f0163SMichael Pfeiffer 	// red rectangle in left, top corner
609c43f0163SMichael Pfeiffer 	// blue rectangle in right, bottom corner
610c43f0163SMichael Pfeiffer 	// the red rectangle overwrites the
611c43f0163SMichael Pfeiffer 	// top, left pixel of the blue rectangle
612c43f0163SMichael Pfeiffer }
613c43f0163SMichael Pfeiffer 
614c43f0163SMichael Pfeiffer static void testSetOrigin2(BView *view, BRect frame)
615c43f0163SMichael Pfeiffer {
616c43f0163SMichael Pfeiffer 	BPoint center = centerPoint(frame);
617c43f0163SMichael Pfeiffer 	BRect r(0, 0, center.x, center.y);
618c43f0163SMichael Pfeiffer 	view->SetOrigin(center);
619c43f0163SMichael Pfeiffer 	view->PushState();
620c43f0163SMichael Pfeiffer 		view->SetOrigin(BPoint(-center.x, 0));
621c43f0163SMichael Pfeiffer 		view->FillRect(r);
622c43f0163SMichael Pfeiffer 	view->PopState();
623c43f0163SMichael Pfeiffer 	// black rectangle in left, bottom corner
624c43f0163SMichael Pfeiffer }
625c43f0163SMichael Pfeiffer 
626c43f0163SMichael Pfeiffer static void testSetScale(BView *view, BRect frame)
627c43f0163SMichael Pfeiffer {
628c43f0163SMichael Pfeiffer 	view->SetScale(0.5);
629c43f0163SMichael Pfeiffer 	view->FillRect(frame);
630c43f0163SMichael Pfeiffer 	// black rectangle in left, top corner
631c43f0163SMichael Pfeiffer }
632c43f0163SMichael Pfeiffer 
633c43f0163SMichael Pfeiffer static void testSetScale2(BView *view, BRect frame)
634c43f0163SMichael Pfeiffer {
635c43f0163SMichael Pfeiffer 	view->SetScale(0.5);
636c43f0163SMichael Pfeiffer 	view->PushState();
637c43f0163SMichael Pfeiffer 		view->SetScale(0.5);
638c43f0163SMichael Pfeiffer 		view->FillRect(frame);
639c43f0163SMichael Pfeiffer 	view->PopState();
640c43f0163SMichael Pfeiffer 	// black rectangle in left, top corner
641c43f0163SMichael Pfeiffer 	// with half the size of the rectangle
642c43f0163SMichael Pfeiffer 	// from test testSetScaling
643c43f0163SMichael Pfeiffer }
644c43f0163SMichael Pfeiffer 
645c43f0163SMichael Pfeiffer static void testSetScale3(BView *view, BRect frame)
646c43f0163SMichael Pfeiffer {
647c43f0163SMichael Pfeiffer 	view->SetScale(0.5);
648c43f0163SMichael Pfeiffer 	view->PushState();
649c43f0163SMichael Pfeiffer 		// if the second scale value differs slightly
650c43f0163SMichael Pfeiffer 		// the bug under BeOS R5 in testSetScale2
651c43f0163SMichael Pfeiffer 		// does not occur
652c43f0163SMichael Pfeiffer 		view->SetScale(0.5000001);
653c43f0163SMichael Pfeiffer 		view->FillRect(frame);
654c43f0163SMichael Pfeiffer 	view->PopState();
655c43f0163SMichael Pfeiffer 	// black rectangle in left, top corner
656c43f0163SMichael Pfeiffer 	// with half the size of the rectangle
657c43f0163SMichael Pfeiffer 	// from test testSetScaling
658c43f0163SMichael Pfeiffer }
659c43f0163SMichael Pfeiffer 
660c9c4a80aSMichael Pfeiffer static void testSetOriginAndScale(BView *view, BRect frame)
661c9c4a80aSMichael Pfeiffer {
662c9c4a80aSMichael Pfeiffer 	frame.InsetBy(2, 2);
663c9c4a80aSMichael Pfeiffer 	BPoint center = centerPoint(frame);
664c9c4a80aSMichael Pfeiffer 
665c9c4a80aSMichael Pfeiffer 	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
666c9c4a80aSMichael Pfeiffer 	view->SetOrigin(center);
667c9c4a80aSMichael Pfeiffer 	view->FillRect(r);
668c9c4a80aSMichael Pfeiffer 
669c9c4a80aSMichael Pfeiffer 	view->SetScale(0.5);
670c9c4a80aSMichael Pfeiffer 	view->SetHighColor(kRed);
671c9c4a80aSMichael Pfeiffer 	view->FillRect(r);
672c9c4a80aSMichael Pfeiffer }
673c9c4a80aSMichael Pfeiffer 
6744b05331dSMichael Pfeiffer static void testSetOriginAndScale2(BView *view, BRect frame)
6754b05331dSMichael Pfeiffer {
6764b05331dSMichael Pfeiffer 	frame.InsetBy(2, 2);
6774b05331dSMichael Pfeiffer 	BPoint center = centerPoint(frame);
6784b05331dSMichael Pfeiffer 
6794b05331dSMichael Pfeiffer 	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
6804b05331dSMichael Pfeiffer 	view->SetOrigin(center);
6814b05331dSMichael Pfeiffer 	view->FillRect(r);
6824b05331dSMichael Pfeiffer 
6834b05331dSMichael Pfeiffer 	view->SetScale(0.5);
6844b05331dSMichael Pfeiffer 	view->SetHighColor(kRed);
6854b05331dSMichael Pfeiffer 	view->FillRect(r);
6864b05331dSMichael Pfeiffer 
6874b05331dSMichael Pfeiffer 	view->SetOrigin(0, 0);
6884b05331dSMichael Pfeiffer 	view->SetHighColor(kGreen);
6894b05331dSMichael Pfeiffer 	view->FillRect(r);
6904b05331dSMichael Pfeiffer }
6914b05331dSMichael Pfeiffer 
6924b05331dSMichael Pfeiffer static void testSetOriginAndScale3(BView *view, BRect frame)
6934b05331dSMichael Pfeiffer {
6944b05331dSMichael Pfeiffer 	frame.InsetBy(2, 2);
6954b05331dSMichael Pfeiffer 	BPoint center = centerPoint(frame);
6964b05331dSMichael Pfeiffer 
6974b05331dSMichael Pfeiffer 	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
6984b05331dSMichael Pfeiffer 	view->SetOrigin(center);
6994b05331dSMichael Pfeiffer 	view->FillRect(r);
7004b05331dSMichael Pfeiffer 
7014b05331dSMichael Pfeiffer 	view->SetScale(0.5);
7024b05331dSMichael Pfeiffer 	view->SetHighColor(kRed);
7034b05331dSMichael Pfeiffer 	view->FillRect(r);
7044b05331dSMichael Pfeiffer 
7054b05331dSMichael Pfeiffer 	view->SetScale(0.25);
7064b05331dSMichael Pfeiffer 	view->SetHighColor(kGreen);
7074b05331dSMichael Pfeiffer 	view->FillRect(r);
7084b05331dSMichael Pfeiffer }
7094b05331dSMichael Pfeiffer 
7104b05331dSMichael Pfeiffer static void testSetOriginAndScale4(BView *view, BRect frame)
7114b05331dSMichael Pfeiffer {
7124b05331dSMichael Pfeiffer 	frame.InsetBy(2, 2);
7134b05331dSMichael Pfeiffer 	BPoint center = centerPoint(frame);
7144b05331dSMichael Pfeiffer 
7154b05331dSMichael Pfeiffer 	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
7164b05331dSMichael Pfeiffer 	view->SetOrigin(center);
7174b05331dSMichael Pfeiffer 	view->FillRect(r);
7184b05331dSMichael Pfeiffer 
7194b05331dSMichael Pfeiffer 	view->SetScale(0.5);
7204b05331dSMichael Pfeiffer 	view->SetHighColor(kRed);
7214b05331dSMichael Pfeiffer 	view->FillRect(r);
7224b05331dSMichael Pfeiffer 
7234b05331dSMichael Pfeiffer 	view->PushState();
7244b05331dSMichael Pfeiffer 		//
7254b05331dSMichael Pfeiffer 		view->SetOrigin(center.x+1, center.y);
7264b05331dSMichael Pfeiffer 			// +1 to work around BeOS bug
7274b05331dSMichael Pfeiffer 			// where setting the origin has no
7284b05331dSMichael Pfeiffer 			// effect if it is the same as
7294b05331dSMichael Pfeiffer 			// the previous value althou
7304b05331dSMichael Pfeiffer 			// it is from the "outer" coordinate
7314b05331dSMichael Pfeiffer 			// system
7324b05331dSMichael Pfeiffer 		view->SetHighColor(kGreen);
7334b05331dSMichael Pfeiffer 		view->FillRect(r);
7344b05331dSMichael Pfeiffer 	view->PopState();
7354b05331dSMichael Pfeiffer }
7364b05331dSMichael Pfeiffer 
7374b05331dSMichael Pfeiffer static void testSetOriginAndScale5(BView *view, BRect frame)
7384b05331dSMichael Pfeiffer {
7394b05331dSMichael Pfeiffer 	frame.InsetBy(2, 2);
7404b05331dSMichael Pfeiffer 	BPoint center = centerPoint(frame);
7414b05331dSMichael Pfeiffer 
7424b05331dSMichael Pfeiffer 	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
7434b05331dSMichael Pfeiffer 	view->SetOrigin(center);
7444b05331dSMichael Pfeiffer 	view->FillRect(r);
7454b05331dSMichael Pfeiffer 
7464b05331dSMichael Pfeiffer 	view->SetScale(0.5);
7474b05331dSMichael Pfeiffer 	view->SetHighColor(kRed);
7484b05331dSMichael Pfeiffer 	view->FillRect(r);
7494b05331dSMichael Pfeiffer 
7504b05331dSMichael Pfeiffer 	view->PushState();
7514b05331dSMichael Pfeiffer 	view->SetScale(0.75);
7524b05331dSMichael Pfeiffer 	view->SetHighColor(kGreen);
7534b05331dSMichael Pfeiffer 	view->FillRect(r);
7544b05331dSMichael Pfeiffer 	view->PopState();
7554b05331dSMichael Pfeiffer }
7564b05331dSMichael Pfeiffer 
757c43f0163SMichael Pfeiffer static void testSetFontSize(BView *view, BRect frame)
758c43f0163SMichael Pfeiffer {
759c43f0163SMichael Pfeiffer 	frame.InsetBy(2, 2);
760c43f0163SMichael Pfeiffer 	int size = frame.IntegerHeight() / 3;
761c43f0163SMichael Pfeiffer 
762c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, size);
763c43f0163SMichael Pfeiffer 	view->MovePenTo(BPoint(frame.left, frame.top));
764c43f0163SMichael Pfeiffer 	view->SetFontSize(size);
765c43f0163SMichael Pfeiffer 	view->DrawString("Haiku");
766c43f0163SMichael Pfeiffer 
767c43f0163SMichael Pfeiffer 	size *= 2;
768c43f0163SMichael Pfeiffer 	frame.OffsetBy(0, size);
769c43f0163SMichael Pfeiffer 	view->MovePenTo(BPoint(frame.left, frame.top));
770c43f0163SMichael Pfeiffer 	view->SetFontSize(size);
771c43f0163SMichael Pfeiffer 	view->DrawString("Haiku");
772c43f0163SMichael Pfeiffer }
773c43f0163SMichael Pfeiffer 
7742fb98dccSStefano Ceccherini static void testSetFontFamilyAndStyle(BView *view, BRect frame)
7752fb98dccSStefano Ceccherini {
7762fb98dccSStefano Ceccherini 	view->DrawString("This is a test", BPoint(2, 6));
7772fb98dccSStefano Ceccherini 
7782fb98dccSStefano Ceccherini 	BFont font;
7792fb98dccSStefano Ceccherini 	view->GetFont(&font);
7802fb98dccSStefano Ceccherini 
7812fb98dccSStefano Ceccherini 	int32 families = count_font_families();
7822fb98dccSStefano Ceccherini 	font_family familyName;
7832fb98dccSStefano Ceccherini 	get_font_family(families - 1, &familyName);
7842fb98dccSStefano Ceccherini 
7852fb98dccSStefano Ceccherini 	int32 styles = count_font_styles(familyName);
7862fb98dccSStefano Ceccherini 	font_style styleName;
7872fb98dccSStefano Ceccherini 	get_font_style(familyName, styles - 1, &styleName);
7882fb98dccSStefano Ceccherini 	font.SetFamilyAndStyle(familyName, styleName);
7892fb98dccSStefano Ceccherini 	view->SetFont(&font);
7902fb98dccSStefano Ceccherini 	view->DrawString( "This is a test", BPoint(2, 19));
7912fb98dccSStefano Ceccherini }
7922fb98dccSStefano Ceccherini 
79315cf50e0SStefano Ceccherini static void testSetDrawingMode(BView *view, BRect frame)
79415cf50e0SStefano Ceccherini {
795ed70c5f3SStefano Ceccherini 	frame.InsetBy(2, 2);
79615cf50e0SStefano Ceccherini 	view->StrokeLine(frame.LeftTop(), frame.RightBottom());
79715cf50e0SStefano Ceccherini 	view->StrokeLine(frame.LeftBottom(), frame.RightTop());
79815cf50e0SStefano Ceccherini 	view->SetDrawingMode(B_OP_ALPHA);
79915cf50e0SStefano Ceccherini 	rgb_color color = kRed;
80015cf50e0SStefano Ceccherini 	color.alpha = 127;
80115cf50e0SStefano Ceccherini 	view->SetHighColor(color);
80215cf50e0SStefano Ceccherini 	view->FillRect(frame, B_SOLID_HIGH);
80315cf50e0SStefano Ceccherini }
80415cf50e0SStefano Ceccherini 
805ed70c5f3SStefano Ceccherini static void testPushPopState(BView *view, BRect frame)
806ed70c5f3SStefano Ceccherini {
807ed70c5f3SStefano Ceccherini 	frame.InsetBy(2, 2);
808ed70c5f3SStefano Ceccherini 	view->SetHighColor(kGreen);
809ed70c5f3SStefano Ceccherini 	view->PushState();
810ed70c5f3SStefano Ceccherini 	view->SetHighColor(kRed);
811ed70c5f3SStefano Ceccherini 	view->PopState();
812ed70c5f3SStefano Ceccherini 
813ed70c5f3SStefano Ceccherini 	view->FillRect(frame, B_SOLID_HIGH);
814ed70c5f3SStefano Ceccherini }
815ed70c5f3SStefano Ceccherini 
8168247141fSMichael Pfeiffer static void testFontRotation(BView* view, BRect frame)
8178247141fSMichael Pfeiffer {
8188247141fSMichael Pfeiffer 	BFont font;
8198247141fSMichael Pfeiffer 	view->GetFont(&font);
8208247141fSMichael Pfeiffer 
8218247141fSMichael Pfeiffer 	font.SetRotation(90);
8228247141fSMichael Pfeiffer 	view->SetFont(&font, B_FONT_ROTATION);
8238247141fSMichael Pfeiffer 	view->DrawString("This is a test!", BPoint(frame.Width() / 2, frame.bottom - 3));
8248247141fSMichael Pfeiffer 
8258247141fSMichael Pfeiffer 	view->GetFont(&font);
8268247141fSMichael Pfeiffer 	if (font.Rotation() != 90.0)
8278247141fSMichael Pfeiffer 		fprintf(stderr, "Error: Rotation is %f but should be 90.0\n", font.Rotation());
8288247141fSMichael Pfeiffer }
82915cf50e0SStefano Ceccherini 
830*abf565b1SStefano Ceccherini 
831*abf565b1SStefano Ceccherini 
832*abf565b1SStefano Ceccherini 
833c43f0163SMichael Pfeiffer // TODO
834c43f0163SMichael Pfeiffer // - blending mode
835c43f0163SMichael Pfeiffer // - line mode
836c43f0163SMichael Pfeiffer // - push/pop state
837c43f0163SMichael Pfeiffer // - move pen
838c43f0163SMichael Pfeiffer // - set font
839c43f0163SMichael Pfeiffer 
840c43f0163SMichael Pfeiffer 
84182afdb09SMichael Pfeiffer TestCase gTestCases[] = {
84254730332SMichael Pfeiffer 	{ "Test No Operation", testNoOp },
84354730332SMichael Pfeiffer 	{ "Test DrawChar", testDrawChar },
84482afdb09SMichael Pfeiffer 	{ "Test Draw String", testDrawString },
84554730332SMichael Pfeiffer 	{ "Test Draw String With Length", testDrawStringWithLength },
846*abf565b1SStefano Ceccherini 	{ "Test Draw String With Offsets", testDrawStringWithOffsets },
847*abf565b1SStefano Ceccherini 
84854730332SMichael Pfeiffer 	{ "Test FillArc", testFillArc },
84954730332SMichael Pfeiffer 	{ "Test StrokeArc", testStrokeArc },
850c43f0163SMichael Pfeiffer 	// testFillBezier fails under BeOS because the
851c43f0163SMichael Pfeiffer 	// direct draw version is not correct
85254730332SMichael Pfeiffer 	{ "Test FillBezier", testFillBezier },
85354730332SMichael Pfeiffer 	{ "Test StrokeBezier", testStrokeBezier },
85454730332SMichael Pfeiffer 	{ "Test FillEllipse", testFillEllipse },
85554730332SMichael Pfeiffer 	{ "Test StrokeEllipse", testStrokeEllipse },
85654730332SMichael Pfeiffer 	{ "Test FillPolygon", testFillPolygon },
85754730332SMichael Pfeiffer 	{ "Test StrokePolygon", testStrokePolygon },
85854730332SMichael Pfeiffer 	{ "Test FillRect", testFillRect },
859*abf565b1SStefano Ceccherini 	{ "Test FillRectGradientLinear", testFillRectGradientLinear },
860*abf565b1SStefano Ceccherini 	{ "Test FillRectGradientRadial", testFillRectGradientRadial },
861*abf565b1SStefano Ceccherini 	{ "Test FillRectGradientRadialFocus", testFillRectGradientRadialFocus },
862*abf565b1SStefano Ceccherini 	{ "Test FillRectGradientDiamond", testFillRectGradientDiamond },
863*abf565b1SStefano Ceccherini 	{ "Test FillRectGradientConic", testFillRectGradientConic },
86454730332SMichael Pfeiffer 	{ "Test StrokeRect", testStrokeRect },
86554730332SMichael Pfeiffer 	{ "Test FillRegion", testFillRegion },
86654730332SMichael Pfeiffer 	{ "Test FillRoundRect", testFillRoundRect },
86754730332SMichael Pfeiffer 	{ "Test StrokeRoundRect", testStrokeRoundRect },
86854730332SMichael Pfeiffer 	{ "Test FillTriangle", testFillTriangle },
86954730332SMichael Pfeiffer 	{ "Test StrokeTriangle", testStrokeTriangle },
87054730332SMichael Pfeiffer 	{ "Test StrokeLine", testStrokeLine },
87154730332SMichael Pfeiffer 	{ "Test FillShape", testFillShape },
87254730332SMichael Pfeiffer 	{ "Test StrokeShape", testStrokeShape },
87382afdb09SMichael Pfeiffer 	{ "Test Record Picture", testRecordPicture },
87482afdb09SMichael Pfeiffer 	{ "Test Record And Play Picture", testRecordAndPlayPicture },
87582afdb09SMichael Pfeiffer 	{ "Test Record And Play Picture With Offset", testRecordAndPlayPictureWithOffset },
87654730332SMichael Pfeiffer 	{ "Test AppendToPicture", testAppendToPicture },
8778247141fSMichael Pfeiffer 	{ "Test Draw Scaled Picture", testDrawScaledPicture },
87854730332SMichael Pfeiffer 	{ "Test LineArray", testLineArray },
87954730332SMichael Pfeiffer 	{ "Test InvertRect", testInvertRect },
8804f422578SMichael Pfeiffer 	{ "Test DrawBitmap", testDrawBitmap },
8814f422578SMichael Pfeiffer 	{ "Test DrawBitmapAtPoint", testDrawBitmapAtPoint },
8824f422578SMichael Pfeiffer 	{ "Test DrawBitmapAtRect", testDrawBitmapAtRect },
8835f380e34SMichael Pfeiffer 	{ "Test DrawLargeBitmap", testDrawLargeBitmap },
884c43f0163SMichael Pfeiffer 	{ "Test ConstrainClippingRegion", testConstrainClippingRegion },
885c43f0163SMichael Pfeiffer 	{ "Test ClipToPicture", testClipToPicture },
886c43f0163SMichael Pfeiffer 	{ "Test ClipToInversePicture", testClipToInversePicture },
887c43f0163SMichael Pfeiffer 	{ "Test SetPenSize", testSetPenSize },
888c43f0163SMichael Pfeiffer 	{ "Test SetPenSize2", testSetPenSize2 },
889c43f0163SMichael Pfeiffer 	{ "Test Pattern", testPattern },
890c43f0163SMichael Pfeiffer 	{ "Test SetOrigin", testSetOrigin },
891c43f0163SMichael Pfeiffer 	{ "Test SetOrigin2", testSetOrigin2 },
892c43f0163SMichael Pfeiffer 	{ "Test SetScale", testSetScale },
893c43f0163SMichael Pfeiffer 	// testSetScale2 fails under BeOS. The picture versions of the
894c43f0163SMichael Pfeiffer 	// rectangle are twice as large as the direct draw version
895c43f0163SMichael Pfeiffer 	{ "Test SetScale2*", testSetScale2 },
896c43f0163SMichael Pfeiffer 	{ "Test SetScale3", testSetScale3 },
897c9c4a80aSMichael Pfeiffer 	{ "Test SetOriginAndScale", testSetOriginAndScale },
8984b05331dSMichael Pfeiffer 	{ "Test SetOriginAndScale2", testSetOriginAndScale2 },
8994b05331dSMichael Pfeiffer 	{ "Test SetOriginAndScale3", testSetOriginAndScale3 },
9004b05331dSMichael Pfeiffer 	{ "Test SetOriginAndScale4", testSetOriginAndScale4 },
9014b05331dSMichael Pfeiffer 	{ "Test SetOriginAndScale5", testSetOriginAndScale5 },
902c43f0163SMichael Pfeiffer 	{ "Test SetFontSize", testSetFontSize },
9032fb98dccSStefano Ceccherini 	{ "Test SetFontFamilyAndStyle", testSetFontFamilyAndStyle },
90415cf50e0SStefano Ceccherini 	{ "Test SetDrawingMode", testSetDrawingMode },
905ed70c5f3SStefano Ceccherini 	{ "Test PushPopState", testPushPopState },
9068247141fSMichael Pfeiffer 	{ "Test FontRotation", testFontRotation },
90782afdb09SMichael Pfeiffer 	{ NULL, NULL }
90882afdb09SMichael Pfeiffer };
90962c7fd0fSMichael Pfeiffer 
9102fb98dccSStefano Ceccherini 
911