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