1 /* 2 * Copyright 2006, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #include "ResetTransformationCommand.h" 10 11 #include <new> 12 #include <stdio.h> 13 14 #include <Catalog.h> 15 #include <Locale.h> 16 17 #include "ChannelTransform.h" 18 19 20 #undef B_TRANSLATION_CONTEXT 21 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-ResetTransformationCmd" 22 23 24 using std::nothrow; 25 26 // constructor 27 ResetTransformationCommand::ResetTransformationCommand( 28 Transformable** const objects, 29 int32 count) 30 : Command(), 31 fObjects(objects && count > 0 ? 32 new (nothrow) Transformable*[count] : NULL), 33 fOriginals(objects && count > 0 ? 34 new (nothrow) double[ 35 count * Transformable::matrix_size] : NULL), 36 fCount(count) 37 { 38 if (!fObjects || !fOriginals) 39 return; 40 41 memcpy(fObjects, objects, fCount * sizeof(Transformable*)); 42 43 int32 matrixSize = Transformable::matrix_size; 44 for (int32 i = 0; i < fCount; i++) { 45 fObjects[i]->StoreTo(&fOriginals[matrixSize * i]); 46 } 47 } 48 49 // destructor 50 ResetTransformationCommand::~ResetTransformationCommand() 51 { 52 delete[] fObjects; 53 delete[] fOriginals; 54 } 55 56 // InitCheck 57 status_t 58 ResetTransformationCommand::InitCheck() 59 { 60 return fObjects && fOriginals ? B_OK : B_NO_INIT; 61 } 62 63 // Perform 64 status_t 65 ResetTransformationCommand::Perform() 66 { 67 // reset transformations 68 for (int32 i = 0; i < fCount; i++) { 69 if (fObjects[i]) 70 fObjects[i]->Reset(); 71 } 72 return B_OK; 73 } 74 75 // Undo 76 status_t 77 ResetTransformationCommand::Undo() 78 { 79 // reset transformations 80 int32 matrixSize = Transformable::matrix_size; 81 for (int32 i = 0; i < fCount; i++) { 82 if (fObjects[i]) 83 fObjects[i]->LoadFrom(&fOriginals[i * matrixSize]); 84 } 85 return B_OK; 86 } 87 88 // GetName 89 void 90 ResetTransformationCommand::GetName(BString& name) 91 { 92 if (fCount > 1) 93 name << B_TRANSLATE("Reset Transformations"); 94 else 95 name << B_TRANSLATE("Reset Transformation"); 96 } 97