xref: /haiku/src/apps/icon-o-matic/transformable/TransformCommand.cpp (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2  * Copyright 2006-2007, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #include "TransformCommand.h"
10 
11 #include <stdio.h>
12 
13 // constructor
14 TransformCommand::TransformCommand(BPoint pivot,
15 								   BPoint translation,
16 								   double rotation,
17 								   double xScale,
18 								   double yScale,
19 								   const char* actionName,
20 								   uint32 nameIndex)
21 	: Command(),
22 	  fOldPivot(pivot),
23 	  fOldTranslation(translation),
24 	  fOldRotation(rotation),
25 	  fOldXScale(xScale),
26 	  fOldYScale(yScale),
27 
28 	  fNewPivot(pivot),
29 	  fNewTranslation(translation),
30 	  fNewRotation(rotation),
31 	  fNewXScale(xScale),
32 	  fNewYScale(yScale),
33 
34 	  fName(actionName),
35 	  fNameIndex(nameIndex)
36 {
37 }
38 
39 // constructor
40 TransformCommand::TransformCommand(const char* actionName,
41 								   uint32 nameIndex)
42 	: Command(),
43 	  fOldPivot(B_ORIGIN),
44 	  fOldTranslation(B_ORIGIN),
45 	  fOldRotation(0.0),
46 	  fOldXScale(1.0),
47 	  fOldYScale(1.0),
48 
49 	  fNewPivot(B_ORIGIN),
50 	  fNewTranslation(B_ORIGIN),
51 	  fNewRotation(0.0),
52 	  fNewXScale(1.0),
53 	  fNewYScale(1.0),
54 
55 	  fName(actionName),
56 	  fNameIndex(nameIndex)
57 {
58 }
59 
60 // destructor
61 TransformCommand::~TransformCommand()
62 {
63 }
64 
65 // InitCheck
66 status_t
67 TransformCommand::InitCheck()
68 {
69 	if ((fNewPivot != fOldPivot
70 		 || fNewTranslation != fOldTranslation
71 		 || fNewRotation != fOldRotation
72 		 || fNewXScale != fOldXScale
73 		 || fNewYScale != fOldYScale))
74 		return B_OK;
75 
76 	return B_NO_INIT;
77 }
78 
79 // Perform
80 status_t
81 TransformCommand::Perform()
82 {
83 	// objects are already transformed
84 	return B_OK;
85 }
86 
87 // Undo
88 status_t
89 TransformCommand::Undo()
90 {
91 	_SetTransformation(fOldPivot,
92 					   fOldTranslation,
93 					   fOldRotation,
94 					   fOldXScale,
95 					   fOldYScale);
96 	return B_OK;
97 }
98 
99 // Redo
100 status_t
101 TransformCommand::Redo()
102 {
103 	_SetTransformation(fNewPivot,
104 					   fNewTranslation,
105 					   fNewRotation,
106 					   fNewXScale,
107 					   fNewYScale);
108 	return B_OK;
109 }
110 
111 // GetName
112 void
113 TransformCommand::GetName(BString& name)
114 {
115 	name << _GetString(fNameIndex, fName.String());
116 }
117 
118 // SetNewTransformation
119 void
120 TransformCommand::SetNewTransformation(BPoint pivot,
121 									   BPoint translation,
122 									   double rotation,
123 									   double xScale,
124 									   double yScale)
125 {
126 	fNewPivot = pivot;
127 	fNewTranslation = translation;
128 	fNewRotation = rotation;
129 	fNewXScale = xScale;
130 	fNewYScale = yScale;
131 }
132 
133 // SetNewTranslation
134 void
135 TransformCommand::SetNewTranslation(BPoint translation)
136 {
137 	// NOTE: convinience method for nudging
138 	fNewTranslation = translation;
139 }
140 
141 // SetName
142 void
143 TransformCommand::SetName(const char* actionName, uint32 nameIndex)
144 {
145 	fName.SetTo(actionName);
146 	fNameIndex = nameIndex;
147 }
148 
149