xref: /haiku/src/apps/icon-o-matic/transformable/TransformCommand.cpp (revision 6427935280aaac0a1a4557bae55184708819560d)
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 	: Command(),
21 	  fOldPivot(pivot),
22 	  fOldTranslation(translation),
23 	  fOldRotation(rotation),
24 	  fOldXScale(xScale),
25 	  fOldYScale(yScale),
26 
27 	  fNewPivot(pivot),
28 	  fNewTranslation(translation),
29 	  fNewRotation(rotation),
30 	  fNewXScale(xScale),
31 	  fNewYScale(yScale),
32 
33 	  fName(actionName)
34 {
35 }
36 
37 // constructor
38 TransformCommand::TransformCommand(const char* actionName)
39 	: Command(),
40 	  fOldPivot(B_ORIGIN),
41 	  fOldTranslation(B_ORIGIN),
42 	  fOldRotation(0.0),
43 	  fOldXScale(1.0),
44 	  fOldYScale(1.0),
45 
46 	  fNewPivot(B_ORIGIN),
47 	  fNewTranslation(B_ORIGIN),
48 	  fNewRotation(0.0),
49 	  fNewXScale(1.0),
50 	  fNewYScale(1.0),
51 
52 	  fName(actionName)
53 {
54 }
55 
56 // destructor
57 TransformCommand::~TransformCommand()
58 {
59 }
60 
61 // InitCheck
62 status_t
63 TransformCommand::InitCheck()
64 {
65 	if ((fNewPivot != fOldPivot
66 		 || fNewTranslation != fOldTranslation
67 		 || fNewRotation != fOldRotation
68 		 || fNewXScale != fOldXScale
69 		 || fNewYScale != fOldYScale))
70 		return B_OK;
71 
72 	return B_NO_INIT;
73 }
74 
75 // Perform
76 status_t
77 TransformCommand::Perform()
78 {
79 	// objects are already transformed
80 	return B_OK;
81 }
82 
83 // Undo
84 status_t
85 TransformCommand::Undo()
86 {
87 	_SetTransformation(fOldPivot,
88 					   fOldTranslation,
89 					   fOldRotation,
90 					   fOldXScale,
91 					   fOldYScale);
92 	return B_OK;
93 }
94 
95 // Redo
96 status_t
97 TransformCommand::Redo()
98 {
99 	_SetTransformation(fNewPivot,
100 					   fNewTranslation,
101 					   fNewRotation,
102 					   fNewXScale,
103 					   fNewYScale);
104 	return B_OK;
105 }
106 
107 // GetName
108 void
109 TransformCommand::GetName(BString& name)
110 {
111 	name << fName.String();
112 }
113 
114 // SetNewTransformation
115 void
116 TransformCommand::SetNewTransformation(BPoint pivot,
117 									   BPoint translation,
118 									   double rotation,
119 									   double xScale,
120 									   double yScale)
121 {
122 	fNewPivot = pivot;
123 	fNewTranslation = translation;
124 	fNewRotation = rotation;
125 	fNewXScale = xScale;
126 	fNewYScale = yScale;
127 }
128 
129 // SetNewTranslation
130 void
131 TransformCommand::SetNewTranslation(BPoint translation)
132 {
133 	// NOTE: convinience method for nudging
134 	fNewTranslation = translation;
135 }
136 
137 // SetName
138 void
139 TransformCommand::SetName(const char* actionName)
140 {
141 	fName.SetTo(actionName);
142 }
143