xref: /haiku/src/tests/kits/interface/flatten_picture/PictureTest.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 /*
2  * Copyright 2007, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Pfeiffer
7  */
8 
9 #ifndef _PICTURE_TEST_H
10 #define _PICTURE_TEST_H
11 
12 #include <InterfaceKit.h>
13 #include <String.h>
14 
15 typedef void (draw_func)(BView *view, BRect frame);
16 
17 class PictureTest {
18 
19 public:
20 	PictureTest();
21 	virtual ~PictureTest();
22 
23 	void SetColorSpace(color_space colorSpace) { fColorSpace = colorSpace; }
24 
25 	bool Test(draw_func* func, BRect frame);
26 
27 	const char *ErrorMessage() const { return fErrorMessage.String(); }
28 
29 	BBitmap *DirectBitmap(bool detach = false);
30 	BBitmap *BitmapFromPicture(bool detach = false);
31 	BBitmap *BitmapFromRestoredPicture(bool detach = false);
32 
33 protected:
34 	virtual BPicture *SaveAndRestore(BPicture *picture) = 0;
35 	void SetErrorMessage(const char* message);
36 
37 private:
38 
39 	void CleanUp();
40 
41 	BPicture *RecordPicture(draw_func* func, BRect frame);
42 
43 	BBitmap *CreateBitmap(draw_func* func, BRect frame);
44 	BBitmap *CreateBitmap(BPicture *picture, BRect frame);
45 
46 	bool IsSame(BBitmap *bitmap1, BBitmap *bitmap2, BString &reason);
47 
48 	color_space fColorSpace;
49 
50 	BBitmap *fDirectBitmap;
51 	BBitmap *fBitmapFromPicture;
52 	BBitmap *fBitmapFromRestoredPicture;
53 
54 	BString fErrorMessage;
55 };
56 
57 class FlattenPictureTest : public PictureTest
58 {
59 public:
60 	FlattenPictureTest();
61 
62 protected:
63 	BPicture *SaveAndRestore(BPicture *picture);
64 };
65 
66 class ArchivePictureTest : public PictureTest
67 {
68 public:
69 	ArchivePictureTest();
70 
71 protected:
72 	BPicture *SaveAndRestore(BPicture *picture);
73 };
74 
75 #endif
76