1 /* 2 * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "RotatePathIndicesCommand.h" 7 8 #include <stdio.h> 9 10 #include "VectorPath.h" 11 12 13 RotatePathIndicesCommand::RotatePathIndicesCommand(VectorPath* path, 14 bool clockWise) 15 : 16 PathCommand(path), 17 fClockWise(clockWise) 18 { 19 } 20 21 22 RotatePathIndicesCommand::~RotatePathIndicesCommand() 23 { 24 } 25 26 27 status_t 28 RotatePathIndicesCommand::InitCheck() 29 { 30 status_t ret = PathCommand::InitCheck(); 31 if (ret == B_OK && fPath->CountPoints() < 2) 32 return B_NOT_SUPPORTED; 33 return ret; 34 } 35 36 37 status_t 38 RotatePathIndicesCommand::Perform() 39 { 40 return _Rotate(fClockWise); 41 } 42 43 44 status_t 45 RotatePathIndicesCommand::Undo() 46 { 47 return _Rotate(!fClockWise); 48 } 49 50 51 void 52 RotatePathIndicesCommand::GetName(BString& name) 53 { 54 name << "Rotate Path Indices"; 55 } 56 57 58 status_t 59 RotatePathIndicesCommand::_Rotate(bool clockWise) 60 { 61 BPoint point; 62 BPoint pointIn; 63 BPoint pointOut; 64 bool connected; 65 66 int32 removeIndex; 67 int32 addIndex; 68 if (!clockWise) { 69 removeIndex = fPath->CountPoints() - 1; 70 addIndex = 0; 71 } else { 72 removeIndex = 0; 73 addIndex = fPath->CountPoints() - 1; 74 } 75 76 if (!fPath->GetPointsAt(removeIndex, point, pointIn, pointOut, &connected)) 77 return B_ERROR; 78 79 fPath->RemovePoint(removeIndex); 80 fPath->AddPoint(point, addIndex); 81 fPath->SetPoint(addIndex, point, pointIn, pointOut, connected); 82 83 return B_OK; 84 } 85 86