1 /*
2 * Copyright 2006-2010, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5
6
7 #include "TransformGradientCommand.h"
8
9 #include <new>
10 #include <stdio.h>
11
12 #include "GradientTransformable.h"
13
14
15 using std::nothrow;
16
17
TransformGradientCommand(TransformBox * box,Gradient * gradient,BPoint pivot,BPoint translation,double rotation,double xScale,double yScale,const char * name)18 TransformGradientCommand::TransformGradientCommand(TransformBox* box,
19 Gradient* gradient, BPoint pivot, BPoint translation, double rotation,
20 double xScale, double yScale, const char* name)
21 :
22 TransformCommand(pivot, translation, rotation, xScale, yScale, name),
23 fTransformBox(box),
24 fGradient(gradient)
25 {
26 if (fGradient == NULL)
27 return;
28
29 fGradient->AcquireReference();
30
31 if (fTransformBox != NULL)
32 fTransformBox->AddListener(this);
33 }
34
35
~TransformGradientCommand()36 TransformGradientCommand::~TransformGradientCommand()
37 {
38 if (fGradient != NULL)
39 fGradient->ReleaseReference();
40
41 if (fTransformBox != NULL)
42 fTransformBox->RemoveListener(this);
43 }
44
45
46 status_t
InitCheck()47 TransformGradientCommand::InitCheck()
48 {
49 return fGradient != NULL ? TransformCommand::InitCheck() : B_NO_INIT;
50 }
51
52 // #pragma mark -
53
54 // TransformBoxDeleted
55 void
TransformBoxDeleted(const TransformBox * box)56 TransformGradientCommand::TransformBoxDeleted(const TransformBox* box)
57 {
58 if (fTransformBox == box) {
59 if (fTransformBox != NULL)
60 fTransformBox->RemoveListener(this);
61 fTransformBox = NULL;
62 }
63 }
64
65
66 // #pragma mark -
67
68
69 status_t
_SetTransformation(BPoint pivot,BPoint translation,double rotation,double xScale,double yScale) const70 TransformGradientCommand::_SetTransformation(BPoint pivot, BPoint translation,
71 double rotation, double xScale, double yScale) const
72 {
73 if (fTransformBox) {
74 fTransformBox->SetTransformation(pivot, translation, rotation, xScale,
75 yScale);
76 return B_OK;
77 }
78
79 ChannelTransform transform;
80 transform.SetTransformation(pivot, translation, rotation, xScale, yScale);
81
82 // Reset and apply transformation. (Gradients never have an original
83 // transformation that needs to be taken into account, the box always
84 // assignes it completely.)
85 fGradient->Reset();
86 fGradient->Multiply(transform);
87
88 return B_OK;
89 }
90
91