1/*
2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stephan A��mus <superstippi@gmx.de>
7 */
8
9#include "NudgePointsCommand.h"
10
11#include <new>
12#include <stdio.h>
13
14#include <Catalog.h>
15#include <Locale.h>
16#include <StringFormat.h>
17
18#include "VectorPath.h"
19
20
21#undef B_TRANSLATION_CONTEXT
22#define B_TRANSLATION_CONTEXT "Icon-O-Matic-NudgePointsCommand"
23
24
25using std::nothrow;
26
27
28static BString
29_GetName(int32 count)
30{
31	static BStringFormat format(B_TRANSLATE("Nudge {0, plural, "
32		"one{vertex} other{vertices}}"));
33	BString name;
34	format.Format(name, count);
35	return name;
36}
37
38
39// constructor
40NudgePointsCommand::NudgePointsCommand(VectorPath* path,
41									   const int32* indices,
42									   const control_point* points,
43									   int32 count)
44	: TransformCommand(B_ORIGIN,
45					   B_ORIGIN,
46					   0.0,
47					   1.0,
48					   1.0,
49					   _GetName(count)),
50	  fPath(path),
51	  fIndices(NULL),
52	  fPoints(NULL),
53	  fCount(count)
54{
55	if (fCount > 0 && indices) {
56		fIndices = new (nothrow) int32[fCount];
57		memcpy(fIndices, indices, fCount * sizeof(int32));
58	}
59	if (fCount > 0 && points) {
60		fPoints = new (nothrow) control_point[fCount];
61		memcpy((void*)fPoints, points, fCount * sizeof(control_point));
62	}
63}
64
65// destructor
66NudgePointsCommand::~NudgePointsCommand()
67{
68	delete[] fIndices;
69	delete[] fPoints;
70}
71
72// InitCheck
73status_t
74NudgePointsCommand::InitCheck()
75{
76	if (fPath && fIndices && fPoints)
77		return TransformCommand::InitCheck();
78	else
79		return B_NO_INIT;
80}
81
82// _SetTransformation
83status_t
84NudgePointsCommand::_SetTransformation(BPoint pivot,
85									   BPoint translation,
86									   double rotation,
87									   double xScale,
88									   double yScale) const
89{
90	if (!fPath)
91		return B_NO_INIT;
92
93	AutoNotificationSuspender _(fPath);
94
95	// restore original path
96	for (int32 i = 0; i < fCount; i++) {
97		fPath->SetPoint(fIndices[i], fPoints[i].point + translation,
98									 fPoints[i].point_in + translation,
99									 fPoints[i].point_out + translation,
100									 fPoints[i].connected);
101	}
102
103	return B_OK;
104}
105
106