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
30class shape_data : public BReferenceable {
31public:
32	uint32*	opList;
33	BPoint*	ptList;
34	int32	opCount;
35	int32	opSize;
36	int32	ptCount;
37	int32	ptSize;
38
39	bool    fOwnsMemory;
40
41	shape_data()
42		:
43		fOwnsMemory(false)
44	{
45	}
46
47	~shape_data()
48	{
49		if (fOwnsMemory) {
50			delete[] opList;
51			delete[] ptList;
52		}
53	}
54
55	shape_data(const shape_data& other)
56	{
57		opList = new(std::nothrow) uint32[other.opCount];
58		ptList = new(std::nothrow) BPoint[other.ptCount];
59		fOwnsMemory = true;
60		opCount = other.opCount;
61		opSize = other.opSize;
62		ptCount = other.ptCount;
63		ptSize = other.ptSize;
64		memcpy((void*)opList, other.opList, opSize);
65		memcpy((void*)ptList, other.ptList, ptSize);
66	}
67
68	BRect DetermineBoundingBox() const
69	{
70		BRect bounds;
71
72		if (ptCount == 0)
73			return bounds;
74
75		// TODO: This implementation doesn't take into account curves at all.
76		bounds.left = ptList[0].x;
77		bounds.top = ptList[0].y;
78		bounds.right = ptList[0].x;
79		bounds.bottom = ptList[0].y;
80
81		for (int32 i = 1; i < ptCount; i++) {
82			if (bounds.left > ptList[i].x)
83				bounds.left = ptList[i].x;
84
85			if (bounds.top > ptList[i].y)
86				bounds.top = ptList[i].y;
87
88			if (bounds.right < ptList[i].x)
89				bounds.right = ptList[i].x;
90
91			if (bounds.bottom < ptList[i].y)
92				bounds.bottom = ptList[i].y;
93		}
94
95		return bounds;
96	}
97};
98
99
100#endif	// SHAPE_PRIVATE_H
101