108e109e5SStephan Aßmus /*
208e109e5SStephan Aßmus * Copyright 2014 Stephan Aßmus <superstippi@gmx.de>
308e109e5SStephan Aßmus * All rights reserved. Distributed under the terms of the MIT license.
408e109e5SStephan Aßmus */
508e109e5SStephan Aßmus
608e109e5SStephan Aßmus
7e966330cSStephan Aßmus #include <algorithm>
808e109e5SStephan Aßmus #include <stdio.h>
908e109e5SStephan Aßmus #include <string.h>
1008e109e5SStephan Aßmus
1108e109e5SStephan Aßmus #include <Application.h>
1205a19d41SStephan Aßmus #include <Bitmap.h>
13e966330cSStephan Aßmus #include <GradientLinear.h>
14b6c34f4cSAdrien Destugues #include <Picture.h>
15b6c34f4cSAdrien Destugues #include <Region.h>
1605a19d41SStephan Aßmus #include <Resources.h>
1705a19d41SStephan Aßmus #include <Roster.h>
1808e109e5SStephan Aßmus #include <String.h>
1908e109e5SStephan Aßmus #include <StringView.h>
2008e109e5SStephan Aßmus
21*15db9924SAdrien Destugues #include "harness.h"
2208e109e5SStephan Aßmus
23b6c34f4cSAdrien Destugues static const char* kAppSignature = "application/x-vnd.Haiku-Transformation";
2408e109e5SStephan Aßmus
2508e109e5SStephan Aßmus
26ae4fa7ceSStephan Aßmus class BitmapTest : public Test {
27ae4fa7ceSStephan Aßmus public:
BitmapTest(const char * name)28ae4fa7ceSStephan Aßmus BitmapTest(const char* name)
29ae4fa7ceSStephan Aßmus :
30ae4fa7ceSStephan Aßmus Test(name),
31ae4fa7ceSStephan Aßmus fBitmap(_LoadBitmap(555))
32ae4fa7ceSStephan Aßmus {
33ae4fa7ceSStephan Aßmus }
34ae4fa7ceSStephan Aßmus
35ae4fa7ceSStephan Aßmus private:
36ae4fa7ceSStephan Aßmus status_t
_GetAppResources(BResources & resources) const37ae4fa7ceSStephan Aßmus _GetAppResources(BResources& resources) const
38ae4fa7ceSStephan Aßmus {
39ae4fa7ceSStephan Aßmus app_info info;
40ae4fa7ceSStephan Aßmus status_t status = be_app->GetAppInfo(&info);
41ae4fa7ceSStephan Aßmus if (status != B_OK)
42ae4fa7ceSStephan Aßmus return status;
43ae4fa7ceSStephan Aßmus
44ae4fa7ceSStephan Aßmus return resources.SetTo(&info.ref);
45ae4fa7ceSStephan Aßmus }
46ae4fa7ceSStephan Aßmus
47ae4fa7ceSStephan Aßmus
_LoadBitmap(int resourceID) const48ae4fa7ceSStephan Aßmus BBitmap* _LoadBitmap(int resourceID) const
49ae4fa7ceSStephan Aßmus {
50ae4fa7ceSStephan Aßmus BResources resources;
51ae4fa7ceSStephan Aßmus status_t status = _GetAppResources(resources);
52ae4fa7ceSStephan Aßmus if (status != B_OK)
53ae4fa7ceSStephan Aßmus return NULL;
54ae4fa7ceSStephan Aßmus
55ae4fa7ceSStephan Aßmus size_t dataSize;
56ae4fa7ceSStephan Aßmus const void* data = resources.LoadResource(B_MESSAGE_TYPE, resourceID,
57ae4fa7ceSStephan Aßmus &dataSize);
58ae4fa7ceSStephan Aßmus if (data == NULL)
59ae4fa7ceSStephan Aßmus return NULL;
60ae4fa7ceSStephan Aßmus
61ae4fa7ceSStephan Aßmus BMemoryIO stream(data, dataSize);
62ae4fa7ceSStephan Aßmus
63ae4fa7ceSStephan Aßmus // Try to read as an archived bitmap.
64ae4fa7ceSStephan Aßmus BMessage archive;
65ae4fa7ceSStephan Aßmus status = archive.Unflatten(&stream);
66ae4fa7ceSStephan Aßmus if (status != B_OK)
67ae4fa7ceSStephan Aßmus return NULL;
68ae4fa7ceSStephan Aßmus
69ae4fa7ceSStephan Aßmus BBitmap* bitmap = new BBitmap(&archive);
70ae4fa7ceSStephan Aßmus
71ae4fa7ceSStephan Aßmus status = bitmap->InitCheck();
72ae4fa7ceSStephan Aßmus if (status != B_OK) {
73ae4fa7ceSStephan Aßmus delete bitmap;
74ae4fa7ceSStephan Aßmus bitmap = NULL;
75ae4fa7ceSStephan Aßmus }
76ae4fa7ceSStephan Aßmus
77ae4fa7ceSStephan Aßmus return bitmap;
78ae4fa7ceSStephan Aßmus }
79ae4fa7ceSStephan Aßmus
80ae4fa7ceSStephan Aßmus protected:
81ae4fa7ceSStephan Aßmus BBitmap* fBitmap;
82ae4fa7ceSStephan Aßmus };
83ae4fa7ceSStephan Aßmus
84ae4fa7ceSStephan Aßmus
8508e109e5SStephan Aßmus // #pragma mark - Test1
8608e109e5SStephan Aßmus
8708e109e5SStephan Aßmus
8808e109e5SStephan Aßmus class RectsTest : public Test {
8908e109e5SStephan Aßmus public:
RectsTest()9008e109e5SStephan Aßmus RectsTest()
9108e109e5SStephan Aßmus :
9208e109e5SStephan Aßmus Test("Rects")
9308e109e5SStephan Aßmus {
9408e109e5SStephan Aßmus }
9508e109e5SStephan Aßmus
Draw(BView * view,BRect updateRect)9608e109e5SStephan Aßmus virtual void Draw(BView* view, BRect updateRect)
9708e109e5SStephan Aßmus {
9808e109e5SStephan Aßmus view->DrawString("Rects", BPoint(20, 30));
9908e109e5SStephan Aßmus
10008e109e5SStephan Aßmus view->SetDrawingMode(B_OP_ALPHA);
10108e109e5SStephan Aßmus view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
10208e109e5SStephan Aßmus
10308e109e5SStephan Aßmus BRect rect(view->Bounds());
1042f9ac958SAdrien Destugues rect.OffsetTo(B_ORIGIN);
1052f9ac958SAdrien Destugues
10608e109e5SStephan Aßmus rect.InsetBy(rect.Width() / 3, rect.Height() / 3);
10708e109e5SStephan Aßmus BPoint center(
10808e109e5SStephan Aßmus rect.left + rect.Width() / 2,
10908e109e5SStephan Aßmus rect.top + rect.Height() / 2);
11008e109e5SStephan Aßmus
111d93591ffSStephan Aßmus for (int32 i = 0; i < 360; i += 40) {
11208e109e5SStephan Aßmus BAffineTransform transform;
11308e109e5SStephan Aßmus transform.RotateBy(center, i * M_PI / 180.0);
11408e109e5SStephan Aßmus view->SetTransform(transform);
115d93591ffSStephan Aßmus
116d93591ffSStephan Aßmus view->SetHighColor(51, 151, 255, 20);
11708e109e5SStephan Aßmus view->FillRect(rect);
118d93591ffSStephan Aßmus
119d93591ffSStephan Aßmus view->SetHighColor(51, 255, 151, 180);
120d93591ffSStephan Aßmus view->DrawString("Rect", center);
12108e109e5SStephan Aßmus }
12208e109e5SStephan Aßmus }
12308e109e5SStephan Aßmus };
12408e109e5SStephan Aßmus
12508e109e5SStephan Aßmus
126ae4fa7ceSStephan Aßmus // #pragma mark - AlphaMaskBitmapTest
12705a19d41SStephan Aßmus
12805a19d41SStephan Aßmus
129ae4fa7ceSStephan Aßmus class AlphaMaskBitmapTest : public BitmapTest {
13005a19d41SStephan Aßmus public:
AlphaMaskBitmapTest()131ae4fa7ceSStephan Aßmus AlphaMaskBitmapTest()
13205a19d41SStephan Aßmus :
133ae4fa7ceSStephan Aßmus BitmapTest("Alpha Masked Bitmap")
13405a19d41SStephan Aßmus {
13505a19d41SStephan Aßmus }
13605a19d41SStephan Aßmus
Draw(BView * view,BRect updateRect)13705a19d41SStephan Aßmus virtual void Draw(BView* view, BRect updateRect)
13805a19d41SStephan Aßmus {
13905a19d41SStephan Aßmus BRect rect(view->Bounds());
14005a19d41SStephan Aßmus
14105a19d41SStephan Aßmus if (fBitmap == NULL) {
14205a19d41SStephan Aßmus view->SetHighColor(255, 0, 0);
14305a19d41SStephan Aßmus view->FillRect(rect);
14405a19d41SStephan Aßmus view->SetHighColor(0, 0, 0);
14505a19d41SStephan Aßmus view->DrawString("Failed to load the bitmap.", BPoint(20, 20));
14605a19d41SStephan Aßmus return;
14705a19d41SStephan Aßmus }
14805a19d41SStephan Aßmus
14905a19d41SStephan Aßmus rect.left = (rect.Width() - fBitmap->Bounds().Width()) / 2;
15005a19d41SStephan Aßmus rect.top = (rect.Height() - fBitmap->Bounds().Height()) / 2;
15105a19d41SStephan Aßmus rect.right = rect.left + fBitmap->Bounds().Width();
15205a19d41SStephan Aßmus rect.bottom = rect.top + fBitmap->Bounds().Height();
15305a19d41SStephan Aßmus
15405a19d41SStephan Aßmus BPoint center(
15505a19d41SStephan Aßmus rect.left + rect.Width() / 2,
15605a19d41SStephan Aßmus rect.top + rect.Height() / 2);
15705a19d41SStephan Aßmus
15805a19d41SStephan Aßmus BPicture picture;
15905a19d41SStephan Aßmus view->BeginPicture(&picture);
16005a19d41SStephan Aßmus view->SetDrawingMode(B_OP_ALPHA);
16105a19d41SStephan Aßmus view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE);
16205a19d41SStephan Aßmus BFont font;
16305a19d41SStephan Aßmus view->GetFont(&font);
16405a19d41SStephan Aßmus font.SetSize(70);
16505a19d41SStephan Aßmus view->SetFont(&font);
16605a19d41SStephan Aßmus view->SetHighColor(0, 0, 0, 80);
16705a19d41SStephan Aßmus view->FillRect(view->Bounds());
16805a19d41SStephan Aßmus view->SetHighColor(0, 0, 0, 255);
16905a19d41SStephan Aßmus view->DrawString("CLIPPING", BPoint(0, center.y + 35));
17005a19d41SStephan Aßmus view->EndPicture();
17105a19d41SStephan Aßmus
17205a19d41SStephan Aßmus view->ClipToPicture(&picture);
17305a19d41SStephan Aßmus
17405a19d41SStephan Aßmus BAffineTransform transform;
17505a19d41SStephan Aßmus transform.RotateBy(center, 30 * M_PI / 180.0);
17605a19d41SStephan Aßmus view->SetTransform(transform);
17705a19d41SStephan Aßmus
17805a19d41SStephan Aßmus view->DrawBitmap(fBitmap, fBitmap->Bounds(), rect);
17905a19d41SStephan Aßmus }
18005a19d41SStephan Aßmus };
18105a19d41SStephan Aßmus
18205a19d41SStephan Aßmus
183e966330cSStephan Aßmus // #pragma mark - Gradient
184e966330cSStephan Aßmus
185e966330cSStephan Aßmus
186e966330cSStephan Aßmus class GradientTest : public Test {
187e966330cSStephan Aßmus public:
GradientTest()188e966330cSStephan Aßmus GradientTest()
189e966330cSStephan Aßmus :
190e966330cSStephan Aßmus Test("Gradient")
191e966330cSStephan Aßmus {
192e966330cSStephan Aßmus }
193e966330cSStephan Aßmus
Draw(BView * view,BRect updateRect)194e966330cSStephan Aßmus virtual void Draw(BView* view, BRect updateRect)
195e966330cSStephan Aßmus {
196e966330cSStephan Aßmus BRect rect(view->Bounds());
197e966330cSStephan Aßmus rect.InsetBy(rect.Width() / 3, rect.Height() / 3);
198e966330cSStephan Aßmus BPoint center(
199e966330cSStephan Aßmus rect.left + rect.Width() / 2,
200e966330cSStephan Aßmus rect.top + rect.Height() / 2);
201e966330cSStephan Aßmus
202e966330cSStephan Aßmus BAffineTransform transform;
203e966330cSStephan Aßmus transform.RotateBy(center, 30.0 * M_PI / 180.0);
204e966330cSStephan Aßmus view->SetTransform(transform);
205e966330cSStephan Aßmus
206e966330cSStephan Aßmus rgb_color top = (rgb_color){ 255, 255, 0, 255 };
207e966330cSStephan Aßmus rgb_color bottom = (rgb_color){ 0, 255, 255, 255 };
208e966330cSStephan Aßmus
209e966330cSStephan Aßmus BGradientLinear gradient;
210e966330cSStephan Aßmus gradient.AddColor(top, 0.0f);
211e966330cSStephan Aßmus gradient.AddColor(bottom, 255.0f);
212e966330cSStephan Aßmus gradient.SetStart(rect.LeftTop());
213e966330cSStephan Aßmus gradient.SetEnd(rect.LeftBottom());
214e966330cSStephan Aßmus
215e966330cSStephan Aßmus float radius = std::min(rect.Width() / 5, rect.Height() / 5);
216e966330cSStephan Aßmus
217e966330cSStephan Aßmus view->FillRoundRect(rect, radius, radius, gradient);
218e966330cSStephan Aßmus }
219e966330cSStephan Aßmus };
22005a19d41SStephan Aßmus
22105a19d41SStephan Aßmus
2229f44851eSStephan Aßmus // #pragma mark - NestedStates
2239f44851eSStephan Aßmus
2249f44851eSStephan Aßmus
2259f44851eSStephan Aßmus class NestedStatesTest : public Test {
2269f44851eSStephan Aßmus public:
NestedStatesTest()2279f44851eSStephan Aßmus NestedStatesTest()
2289f44851eSStephan Aßmus :
2299f44851eSStephan Aßmus Test("Nested view states")
2309f44851eSStephan Aßmus {
2319f44851eSStephan Aßmus }
2329f44851eSStephan Aßmus
Draw(BView * view,BRect updateRect)2339f44851eSStephan Aßmus virtual void Draw(BView* view, BRect updateRect)
2349f44851eSStephan Aßmus {
2359f44851eSStephan Aßmus BAffineTransform transform;
2369f44851eSStephan Aßmus transform.RotateBy(BPoint(100, 100), 30.0 * M_PI / 180.0);
2379f44851eSStephan Aßmus view->SetTransform(transform);
2389f44851eSStephan Aßmus
2399f44851eSStephan Aßmus rgb_color top = (rgb_color){ 255, 0, 0, 255 };
2409f44851eSStephan Aßmus rgb_color bottom = (rgb_color){ 255, 255, 0, 255 };
2419f44851eSStephan Aßmus
2429f44851eSStephan Aßmus BRect rect(20, 20, 120, 120);
2439f44851eSStephan Aßmus
2449f44851eSStephan Aßmus BGradientLinear gradient;
2459f44851eSStephan Aßmus gradient.AddColor(top, 0.0f);
2469f44851eSStephan Aßmus gradient.AddColor(bottom, 255.0f);
2479f44851eSStephan Aßmus gradient.SetStart(rect.LeftTop());
2489f44851eSStephan Aßmus gradient.SetEnd(rect.LeftBottom());
2499f44851eSStephan Aßmus
2509f44851eSStephan Aßmus view->FillRoundRect(rect, 20, 20, gradient);
2519f44851eSStephan Aßmus
2529f44851eSStephan Aßmus view->PushState();
2539f44851eSStephan Aßmus // Should be in the same place!
2549f44851eSStephan Aßmus view->StrokeRoundRect(rect, 20, 20);
2559f44851eSStephan Aßmus
2569f44851eSStephan Aßmus // Now rotated by another 30 degree
2579f44851eSStephan Aßmus view->SetTransform(transform);
2589f44851eSStephan Aßmus
2599f44851eSStephan Aßmus view->SetDrawingMode(B_OP_ALPHA);
2609f44851eSStephan Aßmus view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE);
2619f44851eSStephan Aßmus view->SetHighColor(0, 0, 255, 120);
2629f44851eSStephan Aßmus view->FillRoundRect(rect, 20, 20);
2639f44851eSStephan Aßmus
2649f44851eSStephan Aßmus view->PopState();
2659f44851eSStephan Aßmus }
2669f44851eSStephan Aßmus };
2679f44851eSStephan Aßmus
2689f44851eSStephan Aßmus
2692f9ac958SAdrien Destugues // #pragma mark - Clipping
2702f9ac958SAdrien Destugues
2712f9ac958SAdrien Destugues
2722f9ac958SAdrien Destugues class ClippingTest : public Test {
2732f9ac958SAdrien Destugues public:
ClippingTest()2742f9ac958SAdrien Destugues ClippingTest()
2752f9ac958SAdrien Destugues :
2762f9ac958SAdrien Destugues Test("View bounds clipping")
2772f9ac958SAdrien Destugues {
2782f9ac958SAdrien Destugues }
2792f9ac958SAdrien Destugues
Draw(BView * view,BRect updateRect)2802f9ac958SAdrien Destugues virtual void Draw(BView* view, BRect updateRect)
2812f9ac958SAdrien Destugues {
2822f9ac958SAdrien Destugues BRect r (20, 20, 50, 50);
2832f9ac958SAdrien Destugues view->SetHighColor(ui_color(B_FAILURE_COLOR));
2842f9ac958SAdrien Destugues view->FillRect(r);
2852f9ac958SAdrien Destugues
2862f9ac958SAdrien Destugues BAffineTransform transform;
2872f9ac958SAdrien Destugues transform.TranslateBy(400, 400);
2882f9ac958SAdrien Destugues view->SetTransform(transform);
2892f9ac958SAdrien Destugues
2902f9ac958SAdrien Destugues // Make sure this rectangle is drawn, even when the original one is out
2912f9ac958SAdrien Destugues // of the view bounds (for example because of scrolling).
2922f9ac958SAdrien Destugues view->SetHighColor(ui_color(B_SUCCESS_COLOR));
2932f9ac958SAdrien Destugues view->FillRect(r);
2942f9ac958SAdrien Destugues }
2952f9ac958SAdrien Destugues };
2962f9ac958SAdrien Destugues
2972f9ac958SAdrien Destugues
298b6c34f4cSAdrien Destugues // #pragma mark - Clipping
299b6c34f4cSAdrien Destugues
300b6c34f4cSAdrien Destugues
301b6c34f4cSAdrien Destugues class TextClippingTest : public Test {
302b6c34f4cSAdrien Destugues public:
TextClippingTest()303b6c34f4cSAdrien Destugues TextClippingTest()
304b6c34f4cSAdrien Destugues :
305b6c34f4cSAdrien Destugues Test("Text clipping")
306b6c34f4cSAdrien Destugues {
307b6c34f4cSAdrien Destugues }
308b6c34f4cSAdrien Destugues
Draw(BView * view,BRect updateRect)309b6c34f4cSAdrien Destugues virtual void Draw(BView* view, BRect updateRect)
310b6c34f4cSAdrien Destugues {
311b6c34f4cSAdrien Destugues BFont font;
312b6c34f4cSAdrien Destugues view->GetFont(&font);
313b6c34f4cSAdrien Destugues font.SetSize(70);
314b6c34f4cSAdrien Destugues view->SetFont(&font);
315b6c34f4cSAdrien Destugues
316b6c34f4cSAdrien Destugues float width = view->Bounds().Width();
317b6c34f4cSAdrien Destugues
318b6c34f4cSAdrien Destugues // The translation make the text, which has negative coordinates, be
319b6c34f4cSAdrien Destugues // visible inside the viewport.
320b6c34f4cSAdrien Destugues BAffineTransform transform;
321b6c34f4cSAdrien Destugues transform.TranslateBy(width, 0);
322b6c34f4cSAdrien Destugues view->SetTransform(transform);
323b6c34f4cSAdrien Destugues
324b6c34f4cSAdrien Destugues const char* str = "CLIPPING";
325b6c34f4cSAdrien Destugues
326b6c34f4cSAdrien Destugues // Test the standard DrawString method
327b6c34f4cSAdrien Destugues
328b6c34f4cSAdrien Destugues // Draw the text bounds
329b6c34f4cSAdrien Destugues float size = view->StringWidth(str);
330b6c34f4cSAdrien Destugues BRect r(-width, 0, size - width, 70);
331b6c34f4cSAdrien Destugues view->SetHighColor(ui_color(B_SUCCESS_COLOR));
332b6c34f4cSAdrien Destugues view->FillRect(r);
333b6c34f4cSAdrien Destugues
334b6c34f4cSAdrien Destugues // Draw the text (which should fit inside the bounds rectangle)
335b6c34f4cSAdrien Destugues view->SetHighColor(0, 0, 0, 255);
336b6c34f4cSAdrien Destugues view->DrawString(str, BPoint(-width, 70));
337b6c34f4cSAdrien Destugues
338b6c34f4cSAdrien Destugues // Test with offset-based DrawString
339b6c34f4cSAdrien Destugues BPoint offsets[strlen(str)];
340b6c34f4cSAdrien Destugues for(unsigned int i = 0; i < strlen(str); i++)
341b6c34f4cSAdrien Destugues {
342b6c34f4cSAdrien Destugues offsets[i].x = i * 35 - width;
343b6c34f4cSAdrien Destugues offsets[i].y = 145;
344b6c34f4cSAdrien Destugues }
345b6c34f4cSAdrien Destugues
346b6c34f4cSAdrien Destugues // Draw the text bounds
347b6c34f4cSAdrien Destugues view->SetHighColor(ui_color(B_SUCCESS_COLOR));
348b6c34f4cSAdrien Destugues r = BRect(offsets[0], offsets[strlen(str) - 1]);
349b6c34f4cSAdrien Destugues r.top = 75;
350b6c34f4cSAdrien Destugues view->FillRect(r);
351b6c34f4cSAdrien Destugues
352b6c34f4cSAdrien Destugues // Draw the text (which should fit inside the bounds rectangle)
353b6c34f4cSAdrien Destugues view->SetHighColor(0, 0, 0, 255);
354b6c34f4cSAdrien Destugues view->DrawString(str, offsets, strlen(str));
355b6c34f4cSAdrien Destugues
356b6c34f4cSAdrien Destugues }
357b6c34f4cSAdrien Destugues };
358b6c34f4cSAdrien Destugues
359b6c34f4cSAdrien Destugues
360ae4fa7ceSStephan Aßmus // #pragma mark - BitmapClipTest
361569bd922SAdrien Destugues
362569bd922SAdrien Destugues
363ae4fa7ceSStephan Aßmus class BitmapClipTest : public BitmapTest {
364569bd922SAdrien Destugues public:
BitmapClipTest()365569bd922SAdrien Destugues BitmapClipTest()
366569bd922SAdrien Destugues :
367ae4fa7ceSStephan Aßmus BitmapTest("Bitmap clipping")
368569bd922SAdrien Destugues {
369569bd922SAdrien Destugues }
370569bd922SAdrien Destugues
Draw(BView * view,BRect updateRect)371569bd922SAdrien Destugues virtual void Draw(BView* view, BRect updateRect)
372569bd922SAdrien Destugues {
373569bd922SAdrien Destugues BRect rect(view->Bounds());
374569bd922SAdrien Destugues
375569bd922SAdrien Destugues if (fBitmap == NULL) {
376569bd922SAdrien Destugues view->SetHighColor(255, 0, 0);
377569bd922SAdrien Destugues view->FillRect(rect);
378569bd922SAdrien Destugues view->SetHighColor(0, 0, 0);
379569bd922SAdrien Destugues view->DrawString("Failed to load the bitmap.", BPoint(20, 20));
380569bd922SAdrien Destugues return;
381569bd922SAdrien Destugues }
382569bd922SAdrien Destugues
383569bd922SAdrien Destugues rect = fBitmap->Bounds();
384569bd922SAdrien Destugues
385569bd922SAdrien Destugues view->SetHighColor(ui_color(B_FAILURE_COLOR));
386569bd922SAdrien Destugues view->FillRect(rect);
387569bd922SAdrien Destugues
388569bd922SAdrien Destugues // The rect offset should compensate the transform translation, so the
389b6c34f4cSAdrien Destugues // bitmap should be drawn at the view origin. It will then exactly
390b6c34f4cSAdrien Destugues // cover the red rectangle, which should not be visible anymore.
391569bd922SAdrien Destugues rect.OffsetBy(0, 40);
392569bd922SAdrien Destugues
393569bd922SAdrien Destugues BAffineTransform transform;
394569bd922SAdrien Destugues transform.TranslateBy(0, -40);
395569bd922SAdrien Destugues view->SetTransform(transform);
396569bd922SAdrien Destugues
397569bd922SAdrien Destugues view->DrawBitmap(fBitmap, fBitmap->Bounds(), rect);
398569bd922SAdrien Destugues }
399569bd922SAdrien Destugues };
400569bd922SAdrien Destugues
401569bd922SAdrien Destugues
402a4a2abe0SAdrien Destugues // #pragma mark - PixelAlignTest
403a4a2abe0SAdrien Destugues
404a4a2abe0SAdrien Destugues
405a4a2abe0SAdrien Destugues class PixelAlignTest : public Test {
406a4a2abe0SAdrien Destugues public:
PixelAlignTest()407a4a2abe0SAdrien Destugues PixelAlignTest()
408a4a2abe0SAdrien Destugues :
409a4a2abe0SAdrien Destugues Test("Pixel alignment")
410a4a2abe0SAdrien Destugues {
411a4a2abe0SAdrien Destugues }
412a4a2abe0SAdrien Destugues
Draw(BView * view,BRect updateRect)413a4a2abe0SAdrien Destugues virtual void Draw(BView* view, BRect updateRect)
414a4a2abe0SAdrien Destugues {
415a4a2abe0SAdrien Destugues BRect rect(20, 20, 120, 120);
416a4a2abe0SAdrien Destugues view->SetHighColor(ui_color(B_SUCCESS_COLOR));
417a4a2abe0SAdrien Destugues view->StrokeRect(rect);
418a4a2abe0SAdrien Destugues
419a4a2abe0SAdrien Destugues BAffineTransform transform;
420a4a2abe0SAdrien Destugues transform.TranslateBy(140, 0);
421a4a2abe0SAdrien Destugues view->SetTransform(transform);
422a4a2abe0SAdrien Destugues
423a4a2abe0SAdrien Destugues // Translating a pixel-aligned rectangle by an integer number of
424a4a2abe0SAdrien Destugues // pixels should result in a pixel-aligned rectangle.
425a4a2abe0SAdrien Destugues view->SetHighColor(ui_color(B_FAILURE_COLOR));
426a4a2abe0SAdrien Destugues view->StrokeRect(rect);
427a4a2abe0SAdrien Destugues }
428a4a2abe0SAdrien Destugues };
429a4a2abe0SAdrien Destugues
430a4a2abe0SAdrien Destugues
43108e109e5SStephan Aßmus // #pragma mark -
43208e109e5SStephan Aßmus
43308e109e5SStephan Aßmus
43408e109e5SStephan Aßmus int
main(int argc,char ** argv)43508e109e5SStephan Aßmus main(int argc, char** argv)
43608e109e5SStephan Aßmus {
43708e109e5SStephan Aßmus BApplication app(kAppSignature);
43808e109e5SStephan Aßmus
439*15db9924SAdrien Destugues TestWindow* window = new TestWindow("Transformation tests");
44008e109e5SStephan Aßmus
44108e109e5SStephan Aßmus window->AddTest(new RectsTest());
442569bd922SAdrien Destugues window->AddTest(new BitmapClipTest());
443b6c34f4cSAdrien Destugues window->AddTest(new TextClippingTest());
444ae4fa7ceSStephan Aßmus window->AddTest(new AlphaMaskBitmapTest());
445e966330cSStephan Aßmus window->AddTest(new GradientTest());
4469f44851eSStephan Aßmus window->AddTest(new NestedStatesTest());
4472f9ac958SAdrien Destugues window->AddTest(new ClippingTest());
448a4a2abe0SAdrien Destugues window->AddTest(new PixelAlignTest());
44908e109e5SStephan Aßmus
450b6c34f4cSAdrien Destugues window->SetToTest(2);
45108e109e5SStephan Aßmus window->Show();
45208e109e5SStephan Aßmus
45308e109e5SStephan Aßmus app.Run();
45408e109e5SStephan Aßmus return 0;
45508e109e5SStephan Aßmus }
456