2 * Copyright 2006-2007, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
10 #include "ContourTransformer.h"
15 # include "CommonPropertyIDs.h"
16 # include "OptionProperty.h"
17 # include "Property.h"
18 # include "PropertyObject.h"
19 #endif // ICON_O_MATIC
29 ContourTransformer::ContourTransformer(VertexSource
& source
)
30 : Transformer(source
, "Contour"),
33 auto_detect_orientation(true);
37 ContourTransformer::ContourTransformer(VertexSource
& source
,
39 : Transformer(source
, archive
),
42 auto_detect_orientation(true);
48 if (archive
->FindInt32("line join", &mode
) == B_OK
)
49 line_join((agg::line_join_e
)mode
);
51 if (archive
->FindInt32("inner join", &mode
) == B_OK
)
52 inner_join((agg::inner_join_e
)mode
);
55 if (archive
->FindDouble("width", &value
) == B_OK
)
58 if (archive
->FindDouble("miter limit", &value
) == B_OK
)
61 if (archive
->FindDouble("inner miter limit", &value
) == B_OK
)
62 inner_miter_limit(value
);
66 ContourTransformer::~ContourTransformer()
72 ContourTransformer::Clone(VertexSource
& source
) const
74 ContourTransformer
* clone
= new (nothrow
) ContourTransformer(source
);
76 clone
->line_join(line_join());
77 clone
->inner_join(inner_join());
78 clone
->width(width());
79 clone
->miter_limit(miter_limit());
80 clone
->inner_miter_limit(inner_miter_limit());
81 clone
->auto_detect_orientation(auto_detect_orientation());
88 ContourTransformer::rewind(unsigned path_id
)
90 Contour::rewind(path_id
);
95 ContourTransformer::vertex(double* x
, double* y
)
97 return Contour::vertex(x
, y
);
102 ContourTransformer::SetSource(VertexSource
& source
)
104 Transformer::SetSource(source
);
105 Contour::attach(source
);
108 // ApproximationScale
110 ContourTransformer::ApproximationScale() const
112 double scale
= fSource
.ApproximationScale();
113 double factor
= fabs(width());
125 ContourTransformer::Archive(BMessage
* into
, bool deep
) const
127 status_t ret
= Transformer::Archive(into
, deep
);
130 into
->what
= archive_code
;
133 ret
= into
->AddInt32("line join", line_join());
136 ret
= into
->AddInt32("inner join", inner_join());
139 ret
= into
->AddDouble("width", width());
142 ret
= into
->AddDouble("miter limit", miter_limit());
145 ret
= into
->AddDouble("inner miter limit", inner_miter_limit());
150 // MakePropertyObject
152 ContourTransformer::MakePropertyObject() const
154 PropertyObject
* object
= Transformer::MakePropertyObject();
159 object
->AddProperty(new FloatProperty(PROPERTY_WIDTH
, width()));
161 // auto detect orientation
162 object
->AddProperty(new BoolProperty(PROPERTY_DETECT_ORIENTATION
,
163 auto_detect_orientation()));
166 OptionProperty
* property
= new OptionProperty(PROPERTY_JOIN_MODE
);
167 property
->AddOption(agg::miter_join
, "Miter");
168 property
->AddOption(agg::round_join
, "Round");
169 property
->AddOption(agg::bevel_join
, "Bevel");
170 property
->SetCurrentOptionID(line_join());
172 object
->AddProperty(property
);
175 object
->AddProperty(new FloatProperty(PROPERTY_MITER_LIMIT
,
181 // SetToPropertyObject
183 ContourTransformer::SetToPropertyObject(const PropertyObject
* object
)
185 AutoNotificationSuspender
_(this);
186 Transformer::SetToPropertyObject(object
);
189 float w
= object
->Value(PROPERTY_WIDTH
, (float)width());
195 // auto detect orientation
196 bool ado
= object
->Value(PROPERTY_DETECT_ORIENTATION
,
197 auto_detect_orientation());
198 if (ado
!= auto_detect_orientation()) {
199 auto_detect_orientation(ado
);
204 OptionProperty
* property
= dynamic_cast<OptionProperty
*>(
205 object
->FindProperty(PROPERTY_JOIN_MODE
));
206 if (property
&& line_join() != property
->CurrentOptionID()) {
207 line_join((agg::line_join_e
)property
->CurrentOptionID());
212 float l
= object
->Value(PROPERTY_MITER_LIMIT
, (float)miter_limit());
213 if (l
!= miter_limit()) {
218 return HasPendingNotifications();
221 #endif // ICON_O_MATIC