xref: /haiku/headers/private/interface/ShapePrivate.h (revision 4bd0c1066b227cec4b79883bdef697c7a27f2e90)
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 <Point.h>
13 #include <Rect.h>
14 #include <Referenceable.h>
15 
16 #include <string.h>
17 #include <stdio.h>
18 
19 
20 #define OP_LINETO			0x10000000
21 #define OP_BEZIERTO			0x20000000
22 #define OP_CLOSE			0x40000000
23 #define OP_MOVETO			0x80000000
24 #define OP_LARGE_ARC_TO_CW	0x01000000
25 #define OP_LARGE_ARC_TO_CCW	0x02000000
26 #define OP_SMALL_ARC_TO_CW	0x04000000
27 #define OP_SMALL_ARC_TO_CCW	0x08000000
28 
29 
30 struct shape_data : public BReferenceable {
31 	uint32*	opList;
32 	BPoint*	ptList;
33 	int32	opCount;
34 	int32	opSize;
35 	int32	ptCount;
36 	int32	ptSize;
37 
38 	bool    fOwnsMemory;
39 
40 	shape_data()
41 		:
42 		fOwnsMemory(false)
43 	{
44 	}
45 
46 	~shape_data()
47 	{
48 		if (fOwnsMemory) {
49 			delete[] opList;
50 			delete[] ptList;
51 		}
52 	}
53 
54 	shape_data(const shape_data& other)
55 	{
56 		opList = new(std::nothrow) uint32[other.opCount];
57 		ptList = new(std::nothrow) BPoint[other.ptCount];
58 		fOwnsMemory = true;
59 		opCount = other.opCount;
60 		opSize = other.opSize;
61 		ptCount = other.ptCount;
62 		ptSize = other.ptSize;
63 		memcpy(opList, other.opList, opSize);
64 		memcpy(ptList, other.ptList, ptSize);
65 	}
66 
67 	BRect DetermineBoundingBox() const
68 	{
69 		BRect bounds;
70 
71 		if (ptCount == 0)
72 			return bounds;
73 
74 		// TODO: This implementation doesn't take into account curves at all.
75 		bounds.left = ptList[0].x;
76 		bounds.top = ptList[0].y;
77 		bounds.right = ptList[0].x;
78 		bounds.bottom = ptList[0].y;
79 
80 		for (int32 i = 1; i < ptCount; i++) {
81 			if (bounds.left > ptList[i].x)
82 				bounds.left = ptList[i].x;
83 
84 			if (bounds.top > ptList[i].y)
85 				bounds.top = ptList[i].y;
86 
87 			if (bounds.right < ptList[i].x)
88 				bounds.right = ptList[i].x;
89 
90 			if (bounds.bottom < ptList[i].y)
91 				bounds.bottom = ptList[i].y;
92 		}
93 
94 		return bounds;
95 	}
96 };
97 
98 
99 #endif	// SHAPE_PRIVATE_H
100