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 "VectorPath.h" 15 16 using std::nothrow; 17 18 // constructor 19 NudgePointsCommand::NudgePointsCommand(VectorPath* path, 20 const int32* indices, 21 const control_point* points, 22 int32 count) 23 : TransformCommand(B_ORIGIN, 24 B_ORIGIN, 25 0.0, 26 1.0, 27 1.0, 28 count > 1 ? "Nudge Control Points" : "Nudge Control Point", 29 // count > 1 ? NUDGE_CONTROL_POINTS : NUDGE_CONTROL_POINT), 30 -1), 31 fPath(path), 32 fIndices(NULL), 33 fPoints(NULL), 34 fCount(count) 35 { 36 if (fCount > 0 && indices) { 37 fIndices = new (nothrow) int32[fCount]; 38 memcpy(fIndices, indices, fCount * sizeof(int32)); 39 } 40 if (fCount > 0 && points) { 41 fPoints = new (nothrow) control_point[fCount]; 42 memcpy(fPoints, points, fCount * sizeof(control_point)); 43 } 44 } 45 46 // destructor 47 NudgePointsCommand::~NudgePointsCommand() 48 { 49 delete[] fIndices; 50 delete[] fPoints; 51 } 52 53 // InitCheck 54 status_t 55 NudgePointsCommand::InitCheck() 56 { 57 if (fPath && fIndices && fPoints) 58 return TransformCommand::InitCheck(); 59 else 60 return B_NO_INIT; 61 } 62 63 // _SetTransformation 64 status_t 65 NudgePointsCommand::_SetTransformation(BPoint pivot, 66 BPoint translation, 67 double rotation, 68 double xScale, 69 double yScale) const 70 { 71 if (!fPath) 72 return B_NO_INIT; 73 74 AutoNotificationSuspender _(fPath); 75 76 // restore original path 77 for (int32 i = 0; i < fCount; i++) { 78 fPath->SetPoint(fIndices[i], fPoints[i].point + translation, 79 fPoints[i].point_in + translation, 80 fPoints[i].point_out + translation, 81 fPoints[i].connected); 82 } 83 84 return B_OK; 85 } 86 87