xref: /haiku/src/apps/icon-o-matic/transformable/TransformGradientCommand.cpp (revision 7749d0bb0c358a3279b1b9cc76d8376e900130a5)
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 
18 TransformGradientCommand::TransformGradientCommand(TransformBox* box,
19 		Gradient* gradient, BPoint pivot, BPoint translation, double rotation,
20 		double xScale, double yScale, const char* name, int32 nameIndex)
21 	:
22 	TransformCommand(pivot, translation, rotation, xScale, yScale, name,
23 		nameIndex),
24 	fTransformBox(box),
25 	fGradient(gradient)
26 {
27 	if (fGradient == NULL)
28 		return;
29 
30 //	fGradient->Acquire();
31 
32 	if (fTransformBox != NULL)
33 		fTransformBox->AddListener(this);
34 }
35 
36 
37 TransformGradientCommand::~TransformGradientCommand()
38 {
39 //	if (fGradient != NULL)
40 //		fGradient->Release();
41 
42 	if (fTransformBox != NULL)
43 		fTransformBox->RemoveListener(this);
44 }
45 
46 
47 status_t
48 TransformGradientCommand::InitCheck()
49 {
50 	return fGradient != NULL ? TransformCommand::InitCheck() : B_NO_INIT;
51 }
52 
53 // #pragma mark -
54 
55 // TransformBoxDeleted
56 void
57 TransformGradientCommand::TransformBoxDeleted(const TransformBox* box)
58 {
59 	if (fTransformBox == box) {
60 		if (fTransformBox != NULL)
61 			fTransformBox->RemoveListener(this);
62 		fTransformBox = NULL;
63 	}
64 }
65 
66 
67 // #pragma mark -
68 
69 
70 status_t
71 TransformGradientCommand::_SetTransformation(BPoint pivot, BPoint translation,
72 	double rotation, double xScale, double yScale) const
73 {
74 	if (fTransformBox) {
75 		fTransformBox->SetTransformation(pivot, translation, rotation, xScale,
76 			yScale);
77 		return B_OK;
78 	}
79 
80 	ChannelTransform transform;
81 	transform.SetTransformation(pivot, translation, rotation, xScale, yScale);
82 
83 	// Reset and apply transformation. (Gradients never have an original
84 	// transformation that needs to be taken into account, the box always
85 	// assignes it completely.)
86 	fGradient->Reset();
87 	fGradient->Multiply(transform);
88 
89 	return B_OK;
90 }
91 
92