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