1fb07ece0SStephan Aßmus /*
2325a6253SAxel Dörfler * Copyright 2006-2007, Haiku.
3fb07ece0SStephan Aßmus * Distributed under the terms of the MIT License.
4fb07ece0SStephan Aßmus *
5fb07ece0SStephan Aßmus * Authors:
6fb07ece0SStephan Aßmus * Stephan Aßmus <superstippi@gmx.de>
7fb07ece0SStephan Aßmus */
8fb07ece0SStephan Aßmus
9fb07ece0SStephan Aßmus
10325a6253SAxel Dörfler #include "StrokeTransformer.h"
11fb07ece0SStephan Aßmus
12fb07ece0SStephan Aßmus #ifdef ICON_O_MATIC
13fb07ece0SStephan Aßmus # include <Message.h>
14fb07ece0SStephan Aßmus
15fb07ece0SStephan Aßmus # include "CommonPropertyIDs.h"
16fb07ece0SStephan Aßmus # include "OptionProperty.h"
17fb07ece0SStephan Aßmus # include "Property.h"
18fb07ece0SStephan Aßmus # include "PropertyObject.h"
19fb07ece0SStephan Aßmus #endif // ICON_O_MATIC
20fb07ece0SStephan Aßmus
21325a6253SAxel Dörfler #include <new>
22325a6253SAxel Dörfler
2325dc253dSIngo Weinhold
2425dc253dSIngo Weinhold _USING_ICON_NAMESPACE
25fb07ece0SStephan Aßmus using std::nothrow;
26fb07ece0SStephan Aßmus
27325a6253SAxel Dörfler
28fb07ece0SStephan Aßmus // constructor
StrokeTransformer(VertexSource & source)29fb07ece0SStephan Aßmus StrokeTransformer::StrokeTransformer(VertexSource& source)
30c6c2c042SZardshard : Transformer("Stroke"),
31c6c2c042SZardshard PathTransformer(source),
32fb07ece0SStephan Aßmus Stroke(source)
33fb07ece0SStephan Aßmus {
34fb07ece0SStephan Aßmus }
35fb07ece0SStephan Aßmus
36fb07ece0SStephan Aßmus // constructor
StrokeTransformer(VertexSource & source,BMessage * archive)37fb07ece0SStephan Aßmus StrokeTransformer::StrokeTransformer(VertexSource& source,
38fb07ece0SStephan Aßmus BMessage* archive)
39c6c2c042SZardshard : Transformer(archive),
40c6c2c042SZardshard PathTransformer(source),
41fb07ece0SStephan Aßmus Stroke(source)
42fb07ece0SStephan Aßmus {
43fb07ece0SStephan Aßmus if (!archive)
44fb07ece0SStephan Aßmus return;
45fb07ece0SStephan Aßmus
46fb07ece0SStephan Aßmus int32 mode;
47fb07ece0SStephan Aßmus if (archive->FindInt32("line cap", &mode) == B_OK)
48fb07ece0SStephan Aßmus line_cap((agg::line_cap_e)mode);
49fb07ece0SStephan Aßmus
50fb07ece0SStephan Aßmus if (archive->FindInt32("line join", &mode) == B_OK)
51fb07ece0SStephan Aßmus line_join((agg::line_join_e)mode);
52fb07ece0SStephan Aßmus
53fb07ece0SStephan Aßmus if (archive->FindInt32("inner join", &mode) == B_OK)
54fb07ece0SStephan Aßmus inner_join((agg::inner_join_e)mode);
55fb07ece0SStephan Aßmus
56fb07ece0SStephan Aßmus double value;
57fb07ece0SStephan Aßmus if (archive->FindDouble("width", &value) == B_OK)
58fb07ece0SStephan Aßmus width(value);
59fb07ece0SStephan Aßmus
60fb07ece0SStephan Aßmus if (archive->FindDouble("miter limit", &value) == B_OK)
61fb07ece0SStephan Aßmus miter_limit(value);
62fb07ece0SStephan Aßmus
63fb07ece0SStephan Aßmus if (archive->FindDouble("inner miter limit", &value) == B_OK)
64fb07ece0SStephan Aßmus inner_miter_limit(value);
65fb07ece0SStephan Aßmus
66fb07ece0SStephan Aßmus if (archive->FindDouble("shorten", &value) == B_OK)
67fb07ece0SStephan Aßmus shorten(value);
68fb07ece0SStephan Aßmus }
69fb07ece0SStephan Aßmus
70fb07ece0SStephan Aßmus // destructor
~StrokeTransformer()71fb07ece0SStephan Aßmus StrokeTransformer::~StrokeTransformer()
72fb07ece0SStephan Aßmus {
73fb07ece0SStephan Aßmus }
74fb07ece0SStephan Aßmus
75fb07ece0SStephan Aßmus // Clone
76fb07ece0SStephan Aßmus Transformer*
Clone() const77c6c2c042SZardshard StrokeTransformer::Clone() const
78fb07ece0SStephan Aßmus {
79*0822ec27SPulkoMandy StrokeTransformer* clone = new (nothrow) StrokeTransformer(*fSource);
80fb07ece0SStephan Aßmus if (clone) {
81fb07ece0SStephan Aßmus clone->line_cap(line_cap());
82fb07ece0SStephan Aßmus clone->line_join(line_join());
83fb07ece0SStephan Aßmus clone->inner_join(inner_join());
84fb07ece0SStephan Aßmus clone->width(width());
85fb07ece0SStephan Aßmus clone->miter_limit(miter_limit());
86fb07ece0SStephan Aßmus clone->inner_miter_limit(inner_miter_limit());
87fb07ece0SStephan Aßmus clone->shorten(shorten());
88fb07ece0SStephan Aßmus }
89fb07ece0SStephan Aßmus return clone;
90fb07ece0SStephan Aßmus }
91fb07ece0SStephan Aßmus
92fb07ece0SStephan Aßmus // rewind
93fb07ece0SStephan Aßmus void
rewind(unsigned path_id)94fb07ece0SStephan Aßmus StrokeTransformer::rewind(unsigned path_id)
95fb07ece0SStephan Aßmus {
96fb07ece0SStephan Aßmus Stroke::rewind(path_id);
97fb07ece0SStephan Aßmus }
98fb07ece0SStephan Aßmus
99fb07ece0SStephan Aßmus // vertex
100fb07ece0SStephan Aßmus unsigned
vertex(double * x,double * y)101fb07ece0SStephan Aßmus StrokeTransformer::vertex(double* x, double* y)
102fb07ece0SStephan Aßmus {
103fb07ece0SStephan Aßmus return Stroke::vertex(x, y);
104fb07ece0SStephan Aßmus }
105fb07ece0SStephan Aßmus
106fb07ece0SStephan Aßmus // SetSource
107fb07ece0SStephan Aßmus void
SetSource(VertexSource & source)108fb07ece0SStephan Aßmus StrokeTransformer::SetSource(VertexSource& source)
109fb07ece0SStephan Aßmus {
110c6c2c042SZardshard PathTransformer::SetSource(source);
111fb07ece0SStephan Aßmus Stroke::attach(source);
112fb07ece0SStephan Aßmus }
113fb07ece0SStephan Aßmus
114fb07ece0SStephan Aßmus // WantsOpenPaths
115fb07ece0SStephan Aßmus bool
WantsOpenPaths() const116fb07ece0SStephan Aßmus StrokeTransformer::WantsOpenPaths() const
117fb07ece0SStephan Aßmus {
118fb07ece0SStephan Aßmus return true;
119fb07ece0SStephan Aßmus }
120fb07ece0SStephan Aßmus
121fb07ece0SStephan Aßmus // ApproximationScale
122fb07ece0SStephan Aßmus double
ApproximationScale() const123fb07ece0SStephan Aßmus StrokeTransformer::ApproximationScale() const
124fb07ece0SStephan Aßmus {
125*0822ec27SPulkoMandy double scale = fSource->ApproximationScale();
12612a257d7SStephan Aßmus double factor = fabs(width());
12712a257d7SStephan Aßmus if (factor > 1.0)
12812a257d7SStephan Aßmus scale *= factor;
12912a257d7SStephan Aßmus return scale;
130fb07ece0SStephan Aßmus }
131fb07ece0SStephan Aßmus
132fb07ece0SStephan Aßmus // #pragma mark -
133fb07ece0SStephan Aßmus
134fb07ece0SStephan Aßmus #ifdef ICON_O_MATIC
135fb07ece0SStephan Aßmus
136fb07ece0SStephan Aßmus // Archive
137fb07ece0SStephan Aßmus status_t
Archive(BMessage * into,bool deep) const138fb07ece0SStephan Aßmus StrokeTransformer::Archive(BMessage* into, bool deep) const
139fb07ece0SStephan Aßmus {
140fb07ece0SStephan Aßmus status_t ret = Transformer::Archive(into, deep);
141fb07ece0SStephan Aßmus
142fb07ece0SStephan Aßmus if (ret == B_OK)
143fb07ece0SStephan Aßmus into->what = archive_code;
144fb07ece0SStephan Aßmus
145fb07ece0SStephan Aßmus if (ret == B_OK)
146fb07ece0SStephan Aßmus ret = into->AddInt32("line cap", line_cap());
147fb07ece0SStephan Aßmus
148fb07ece0SStephan Aßmus if (ret == B_OK)
149fb07ece0SStephan Aßmus ret = into->AddInt32("line join", line_join());
150fb07ece0SStephan Aßmus
151fb07ece0SStephan Aßmus if (ret == B_OK)
152fb07ece0SStephan Aßmus ret = into->AddInt32("inner join", inner_join());
153fb07ece0SStephan Aßmus
154fb07ece0SStephan Aßmus if (ret == B_OK)
155fb07ece0SStephan Aßmus ret = into->AddDouble("width", width());
156fb07ece0SStephan Aßmus
157fb07ece0SStephan Aßmus if (ret == B_OK)
158fb07ece0SStephan Aßmus ret = into->AddDouble("miter limit", miter_limit());
159fb07ece0SStephan Aßmus
160fb07ece0SStephan Aßmus if (ret == B_OK)
161fb07ece0SStephan Aßmus ret = into->AddDouble("inner miter limit", inner_miter_limit());
162fb07ece0SStephan Aßmus
163fb07ece0SStephan Aßmus if (ret == B_OK)
164fb07ece0SStephan Aßmus ret = into->AddDouble("shorten",shorten());
165fb07ece0SStephan Aßmus
166fb07ece0SStephan Aßmus return ret;
167fb07ece0SStephan Aßmus }
168fb07ece0SStephan Aßmus
169fb07ece0SStephan Aßmus // MakePropertyObject
170fb07ece0SStephan Aßmus PropertyObject*
MakePropertyObject() const171fb07ece0SStephan Aßmus StrokeTransformer::MakePropertyObject() const
172fb07ece0SStephan Aßmus {
173fb07ece0SStephan Aßmus PropertyObject* object = Transformer::MakePropertyObject();
174fb07ece0SStephan Aßmus if (!object)
175fb07ece0SStephan Aßmus return NULL;
176fb07ece0SStephan Aßmus
177fb07ece0SStephan Aßmus // width
178fb07ece0SStephan Aßmus object->AddProperty(new FloatProperty(PROPERTY_WIDTH, width()));
179fb07ece0SStephan Aßmus
180fb07ece0SStephan Aßmus // cap mode
181fb07ece0SStephan Aßmus OptionProperty* property = new OptionProperty(PROPERTY_CAP_MODE);
182fb07ece0SStephan Aßmus property->AddOption(agg::butt_cap, "Butt");
183fb07ece0SStephan Aßmus property->AddOption(agg::square_cap, "Square");
184fb07ece0SStephan Aßmus property->AddOption(agg::round_cap, "Round");
185fb07ece0SStephan Aßmus property->SetCurrentOptionID(line_cap());
186fb07ece0SStephan Aßmus
187fb07ece0SStephan Aßmus object->AddProperty(property);
188fb07ece0SStephan Aßmus
189fb07ece0SStephan Aßmus // join mode
190fb07ece0SStephan Aßmus property = new OptionProperty(PROPERTY_JOIN_MODE);
191fb07ece0SStephan Aßmus property->AddOption(agg::miter_join, "Miter");
192fb07ece0SStephan Aßmus property->AddOption(agg::round_join, "Round");
193fb07ece0SStephan Aßmus property->AddOption(agg::bevel_join, "Bevel");
194fb07ece0SStephan Aßmus property->SetCurrentOptionID(line_join());
195fb07ece0SStephan Aßmus
196fb07ece0SStephan Aßmus object->AddProperty(property);
197fb07ece0SStephan Aßmus
198fb07ece0SStephan Aßmus // miter limit
199fb07ece0SStephan Aßmus if (line_join() == agg::miter_join) {
200fb07ece0SStephan Aßmus object->AddProperty(new FloatProperty(PROPERTY_MITER_LIMIT,
201fb07ece0SStephan Aßmus miter_limit()));
202fb07ece0SStephan Aßmus }
203fb07ece0SStephan Aßmus
2042f953b71SStephan Aßmus // // shorten
2052f953b71SStephan Aßmus // object->AddProperty(new FloatProperty(PROPERTY_STROKE_SHORTEN,
2062f953b71SStephan Aßmus // shorten()));
207fb07ece0SStephan Aßmus
208fb07ece0SStephan Aßmus return object;
209fb07ece0SStephan Aßmus }
210fb07ece0SStephan Aßmus
211fb07ece0SStephan Aßmus // SetToPropertyObject
212fb07ece0SStephan Aßmus bool
SetToPropertyObject(const PropertyObject * object)213fb07ece0SStephan Aßmus StrokeTransformer::SetToPropertyObject(const PropertyObject* object)
214fb07ece0SStephan Aßmus {
215fb07ece0SStephan Aßmus AutoNotificationSuspender _(this);
216fb07ece0SStephan Aßmus Transformer::SetToPropertyObject(object);
217fb07ece0SStephan Aßmus
218fb07ece0SStephan Aßmus // width
219fb07ece0SStephan Aßmus float w = object->Value(PROPERTY_WIDTH, (float)width());
220fb07ece0SStephan Aßmus if (w != width()) {
221fb07ece0SStephan Aßmus width(w);
222fb07ece0SStephan Aßmus Notify();
223fb07ece0SStephan Aßmus }
224fb07ece0SStephan Aßmus
225fb07ece0SStephan Aßmus // cap mode
226fb07ece0SStephan Aßmus OptionProperty* property = dynamic_cast<OptionProperty*>(
227fb07ece0SStephan Aßmus object->FindProperty(PROPERTY_CAP_MODE));
228fb07ece0SStephan Aßmus if (property && line_cap() != property->CurrentOptionID()) {
229fb07ece0SStephan Aßmus line_cap((agg::line_cap_e)property->CurrentOptionID());
230fb07ece0SStephan Aßmus Notify();
231fb07ece0SStephan Aßmus }
232fb07ece0SStephan Aßmus // join mode
233fb07ece0SStephan Aßmus property = dynamic_cast<OptionProperty*>(
234fb07ece0SStephan Aßmus object->FindProperty(PROPERTY_JOIN_MODE));
235fb07ece0SStephan Aßmus if (property && line_join() != property->CurrentOptionID()) {
236fb07ece0SStephan Aßmus line_join((agg::line_join_e)property->CurrentOptionID());
237fb07ece0SStephan Aßmus Notify();
238fb07ece0SStephan Aßmus }
239fb07ece0SStephan Aßmus
240fb07ece0SStephan Aßmus // miter limit
241fb07ece0SStephan Aßmus float l = object->Value(PROPERTY_MITER_LIMIT, (float)miter_limit());
242fb07ece0SStephan Aßmus if (l != miter_limit()) {
243fb07ece0SStephan Aßmus miter_limit(l);
244fb07ece0SStephan Aßmus Notify();
245fb07ece0SStephan Aßmus }
246fb07ece0SStephan Aßmus
247fb07ece0SStephan Aßmus // shorten
248fb07ece0SStephan Aßmus float s = object->Value(PROPERTY_STROKE_SHORTEN, (float)shorten());
249fb07ece0SStephan Aßmus if (s != shorten()) {
250fb07ece0SStephan Aßmus shorten(s);
251fb07ece0SStephan Aßmus Notify();
252fb07ece0SStephan Aßmus }
253fb07ece0SStephan Aßmus
254fb07ece0SStephan Aßmus return HasPendingNotifications();
255fb07ece0SStephan Aßmus }
256fb07ece0SStephan Aßmus
257fb07ece0SStephan Aßmus #endif // ICON_O_MATIC
258fb07ece0SStephan Aßmus
259fb07ece0SStephan Aßmus
260