xref: /haiku/headers/private/interface/ShapePrivate.h (revision 344ded80d400028c8f561b4b876257b94c12db4a)
1 /*
2  * Copyright 2003-2010 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Axel Dörfler, axeld@pinc-software.de
7  *		Adrian Oanca, adioanca@cotty.iren.ro
8  */
9 #ifndef SHAPE_PRIVATE_H
10 #define SHAPE_PRIVATE_H
11 
12 #include <Shape.h>
13 #include <Point.h>
14 #include <Rect.h>
15 #include <Referenceable.h>
16 
17 #include <string.h>
18 #include <stdio.h>
19 
20 
21 #define OP_LINETO			0x10000000
22 #define OP_BEZIERTO			0x20000000
23 #define OP_CLOSE			0x40000000
24 #define OP_MOVETO			0x80000000
25 #define OP_LARGE_ARC_TO_CW	0x01000000
26 #define OP_LARGE_ARC_TO_CCW	0x02000000
27 #define OP_SMALL_ARC_TO_CW	0x04000000
28 #define OP_SMALL_ARC_TO_CCW	0x08000000
29 
30 
31 class shape_data : public BReferenceable {
32 public:
33 	uint32*	opList;
34 	BPoint*	ptList;
35 	int32	opCount;
36 	int32	opSize;
37 	int32	ptCount;
38 	int32	ptSize;
39 
40 	bool    fOwnsMemory;
41 
42 	shape_data()
43 		:
44 		fOwnsMemory(false)
45 	{
46 	}
47 
48 	~shape_data()
49 	{
50 		if (fOwnsMemory) {
51 			delete[] opList;
52 			delete[] ptList;
53 		}
54 	}
55 
56 	shape_data(const shape_data& other)
57 	{
58 		opList = new(std::nothrow) uint32[other.opCount];
59 		ptList = new(std::nothrow) BPoint[other.ptCount];
60 		fOwnsMemory = true;
61 		opCount = other.opCount;
62 		opSize = other.opSize;
63 		ptCount = other.ptCount;
64 		ptSize = other.ptSize;
65 		memcpy((void*)opList, other.opList, opSize);
66 		memcpy((void*)ptList, other.ptList, ptSize);
67 	}
68 
69 	BRect DetermineBoundingBox() const
70 	{
71 		BRect bounds;
72 
73 		if (ptCount == 0)
74 			return bounds;
75 
76 		// TODO: This implementation doesn't take into account curves at all.
77 		bounds.left = ptList[0].x;
78 		bounds.top = ptList[0].y;
79 		bounds.right = ptList[0].x;
80 		bounds.bottom = ptList[0].y;
81 
82 		for (int32 i = 1; i < ptCount; i++) {
83 			if (bounds.left > ptList[i].x)
84 				bounds.left = ptList[i].x;
85 
86 			if (bounds.top > ptList[i].y)
87 				bounds.top = ptList[i].y;
88 
89 			if (bounds.right < ptList[i].x)
90 				bounds.right = ptList[i].x;
91 
92 			if (bounds.bottom < ptList[i].y)
93 				bounds.bottom = ptList[i].y;
94 		}
95 
96 		return bounds;
97 	}
98 };
99 
100 
101 class BShape::Private {
102 public:
103 								Private(BShape& shape) : fShape(shape) {}
104 
105 			void				GetData(int32* opCount, int32* ptCount,
106 									uint32** opList, BPoint** ptList);
107 			void				SetData(int32 opCount, int32 ptCount,
108 									const uint32* opList,
109 									const BPoint* ptList);
110 			shape_data*			PrivateData() {return (shape_data*)fShape.fPrivateData;}
111 
112 private:
113 			BShape&				fShape;
114 };
115 
116 
117 #endif	// SHAPE_PRIVATE_H
118