xref: /haiku/src/tests/servers/app/painter/ShapeConverter.cpp (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 /*
2  * Copyright 2005, Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Simple BShape to agg::path_storage converter, implemented as BShapeIterator.
6  *
7  */
8 
9 
10 #include "ShapeConverter.h"
11 
12 // constructor
13 ShapeConverter::ShapeConverter()
14 	: BShapeIterator(),
15 	  Transformable(),
16 	  fPath(NULL)
17 {
18 }
19 
20 // constructor
21 ShapeConverter::ShapeConverter(agg::path_storage* path)
22 	: BShapeIterator(),
23 	  Transformable(),
24 	  fPath(path)
25 {
26 }
27 
28 // SetPath
29 void
30 ShapeConverter::SetPath(agg::path_storage* path)
31 {
32 	fPath = path;
33 }
34 
35 // IterateMoveTo
36 status_t
37 ShapeConverter::IterateMoveTo(BPoint* point)
38 {
39 	double x = point->x;
40 	double y = point->y;
41 	Transform(&x, &y);
42 
43 	fPath->move_to(x, y);
44 
45 	return B_OK;
46 }
47 
48 // IterateLineTo
49 status_t
50 ShapeConverter::IterateLineTo(int32 lineCount, BPoint* linePts)
51 {
52 	while (lineCount--) {
53 
54 		double x = linePts->x;
55 		double y = linePts->y;
56 		Transform(&x, &y);
57 
58 		fPath->line_to(x, y);
59 
60 		linePts++;
61 	}
62 	return B_OK;
63 }
64 
65 // IterateBezierTo
66 status_t
67 ShapeConverter::IterateBezierTo(int32 bezierCount, BPoint* bezierPts)
68 {
69 	bezierCount /= 3;
70 	while (bezierCount--) {
71 
72 		double x1 = bezierPts[0].x;
73 		double y1 = bezierPts[0].y;
74 
75 		double x2 = bezierPts[1].x;
76 		double y2 = bezierPts[1].y;
77 
78 		double x3 = bezierPts[2].x;
79 		double y3 = bezierPts[2].y;
80 
81 		Transform(&x1, &y1);
82 		Transform(&x2, &y2);
83 		Transform(&x3, &y3);
84 
85 		fPath->curve4(x1, y1, x2, y2, x3, y3);
86 
87 		bezierPts += 3;
88 	}
89 	return B_OK;
90 }
91 
92 // IterateClose
93 status_t
94 ShapeConverter::IterateClose()
95 {
96 	fPath->close_polygon();
97 	return B_OK;
98 }
99