1 /* 2 * Copyright 2006-2010, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2006-2009, 2023, Haiku. 4 * All rights reserved. Distributed under the terms of the MIT License. 5 * 6 * Authors: 7 * Stephan Aßmus <superstippi@gmx.de> 8 * Zardshard 9 */ 10 11 12 #include "PerspectiveCommand.h" 13 14 #include <Catalog.h> 15 #include <Locale.h> 16 17 #include "PerspectiveTransformer.h" 18 19 20 #undef B_TRANSLATION_CONTEXT 21 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-PerspectiveCommand" 22 23 24 PerspectiveCommand::PerspectiveCommand(PerspectiveBox* box, 25 PerspectiveTransformer* transformer, BPoint leftTop, BPoint rightTop 26 , BPoint leftBottom, BPoint rightBottom) 27 : fTransformBox(box), 28 fTransformer(transformer), 29 fOldLeftTop(leftTop), 30 fOldRightTop(rightTop), 31 fOldLeftBottom(leftBottom), 32 fOldRightBottom(rightBottom), 33 fNewLeftTop(leftTop), 34 fNewRightTop(rightTop), 35 fNewLeftBottom(leftBottom), 36 fNewRightBottom(rightBottom) 37 { 38 if (fTransformer == NULL) 39 return; 40 41 fTransformer->AcquireReference(); 42 43 if (fTransformBox != NULL) 44 fTransformBox->AddListener(this); 45 } 46 47 48 PerspectiveCommand::~PerspectiveCommand() 49 { 50 if (fTransformer != NULL) 51 fTransformer->ReleaseReference(); 52 53 if (fTransformBox != NULL) 54 fTransformBox->RemoveListener(this); 55 } 56 57 58 // pragma mark - 59 60 61 status_t 62 PerspectiveCommand::InitCheck() 63 { 64 if (fTransformer != NULL 65 && (fOldLeftTop != fNewLeftTop 66 || fOldRightTop != fNewRightTop 67 || fOldLeftBottom != fNewLeftBottom 68 || fOldRightBottom != fNewRightBottom)) 69 return B_OK; 70 71 return B_NO_INIT; 72 } 73 74 75 status_t 76 PerspectiveCommand::Perform() 77 { 78 // objects are already transformed 79 return B_OK; 80 } 81 82 83 status_t 84 PerspectiveCommand::Undo() 85 { 86 if (fTransformBox != NULL) { 87 fTransformBox->TransformTo(fOldLeftTop, fOldRightTop, fOldLeftBottom, fOldRightBottom); 88 return B_OK; 89 } 90 91 fTransformer->TransformTo(fOldLeftTop, fOldRightTop, fOldLeftBottom, fOldRightBottom); 92 return B_OK; 93 } 94 95 96 status_t 97 PerspectiveCommand::Redo() 98 { 99 if (fTransformBox != NULL) { 100 fTransformBox->TransformTo(fNewLeftTop, fNewRightTop, fNewLeftBottom, fNewRightBottom); 101 return B_OK; 102 } 103 104 fTransformer->TransformTo(fNewLeftTop, fNewRightTop, fNewLeftBottom, fNewRightBottom); 105 return B_OK; 106 } 107 108 109 void 110 PerspectiveCommand::GetName(BString& name) 111 { 112 name << B_TRANSLATE("Change perspective"); 113 } 114 115 116 // pragma mark - 117 118 119 void 120 PerspectiveCommand::PerspectiveBoxDeleted(const PerspectiveBox* box) 121 { 122 if (fTransformBox == box) { 123 if (fTransformBox != NULL) 124 fTransformBox->RemoveListener(this); 125 fTransformBox = NULL; 126 } 127 } 128 129 130 // #pragma mark - 131 132 133 void 134 PerspectiveCommand::SetNewPerspective( 135 BPoint leftTop, BPoint rightTop, BPoint leftBottom, BPoint rightBottom) 136 { 137 fNewLeftTop = leftTop; 138 fNewRightTop = rightTop; 139 fNewLeftBottom = leftBottom; 140 fNewRightBottom = rightBottom; 141 } 142