2 * Copyright 2006, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "TransformPointsCommand.h"
14 #include "ChannelTransform.h"
15 #include "VectorPath.h"
20 TransformPointsCommand::TransformPointsCommand(
25 const control_point
* points
,
36 : TransformCommand(pivot
,
45 fIndices(indices
&& count
> 0 ?
46 new (nothrow
) int32
[count
] : NULL
),
47 fPoints(points
&& count
> 0 ?
48 new (nothrow
) control_point
[count
] : NULL
),
51 if (!fIndices
|| !fPoints
)
54 memcpy(fIndices
, indices
, fCount
* sizeof(int32
));
55 memcpy(fPoints
, points
, fCount
* sizeof(control_point
));
58 fTransformBox
->AddListener(this);
62 TransformPointsCommand::~TransformPointsCommand()
65 fTransformBox
->RemoveListener(this);
73 TransformPointsCommand::InitCheck()
75 return fPath
&& fIndices
&& fPoints
? TransformCommand::InitCheck()
81 // TransformBoxDeleted
83 TransformPointsCommand::TransformBoxDeleted(
84 const TransformBox
* box
)
86 if (fTransformBox
== box
) {
88 fTransformBox
->RemoveListener(this);
97 TransformPointsCommand::_SetTransformation(
98 BPoint pivot
, BPoint translation
,
100 double xScale
, double yScale
) const
103 fTransformBox
->SetTransformation(pivot
, translation
,
104 rotation
, xScale
, yScale
);
109 ChannelTransform transform
;
110 transform
.SetTransformation(pivot
, translation
,
111 rotation
, xScale
, yScale
);
112 // restore original points and apply transformation
113 for (int32 i
= 0; i
< fCount
; i
++) {
114 BPoint point
= transform
.Transform(fPoints
[i
].point
);
115 BPoint pointIn
= transform
.Transform(fPoints
[i
].point_in
);
116 BPoint pointOut
= transform
.Transform(fPoints
[i
].point_out
);
117 if (!fPath
->SetPoint(fIndices
[i
], point
, pointIn
, pointOut
,
118 fPoints
[i
].connected
))