From c88bc5e973fe56886e5cfd3c16982c2eb25d4d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 19 May 2010 14:03:41 +0000 Subject: [PATCH] When a TransformationBox is used to change the transformation of a gradient, it only ever changes one gradient at a time, and adopts itself to the current gradient transformation. When applying it's own transformation on the gradient, it could then reset and assign the transformation. On the other hand, the regular TransformObjectCommand works on a different assumption, which is that the object has it's own original transformation, and the transform box transformation is chained on top of that. So the TransformGradientBox cannot use a TransformObjectsCommand for the undo stack. Whenever such a command could not use the box to apply the transformation, it would mess up the gradient's transformation and the undo/redo chain. -> Use a dedicated TransformGradientsCommand which works the same as the TransformGradientsBox when applying the transformation. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36866 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/icon-o-matic/Jamfile | 1 + .../transformable/TransformGradientBox.cpp | 13 +-- .../TransformGradientCommand.cpp | 91 +++++++++++++++++++ .../transformable/TransformGradientCommand.h | 50 ++++++++++ .../transformable/TransformObjectsCommand.cpp | 1 - 5 files changed, 147 insertions(+), 9 deletions(-) create mode 100644 src/apps/icon-o-matic/transformable/TransformGradientCommand.cpp create mode 100644 src/apps/icon-o-matic/transformable/TransformGradientCommand.h diff --git a/src/apps/icon-o-matic/Jamfile b/src/apps/icon-o-matic/Jamfile index 6829c72633..6204c93254 100644 --- a/src/apps/icon-o-matic/Jamfile +++ b/src/apps/icon-o-matic/Jamfile @@ -289,6 +289,7 @@ Application Icon-O-Matic : TransformBoxStates.cpp TransformCommand.cpp TransformGradientBox.cpp + TransformGradientCommand.cpp TransformObjectsCommand.cpp TransformPointsBox.cpp TransformShapesBox.cpp diff --git a/src/apps/icon-o-matic/transformable/TransformGradientBox.cpp b/src/apps/icon-o-matic/transformable/TransformGradientBox.cpp index 3fd7058162..fc207ce69f 100644 --- a/src/apps/icon-o-matic/transformable/TransformGradientBox.cpp +++ b/src/apps/icon-o-matic/transformable/TransformGradientBox.cpp @@ -16,7 +16,7 @@ #include "GradientTransformable.h" #include "Shape.h" #include "StateView.h" -#include "TransformObjectsCommand.h" +#include "TransformGradientCommand.h" using std::nothrow; @@ -104,7 +104,7 @@ TransformGradientBox::ObjectChanged(const Observable* object) return; } - // any TransformObjectsCommand cannot use the TransformBox + // any TransformGradientCommand cannot use the TransformBox // anymore _NotifyDeleted(); @@ -179,11 +179,8 @@ TransformGradientBox::ViewSpaceRotation() const TransformCommand* TransformGradientBox::MakeCommand(const char* commandName, uint32 nameIndex) { - Transformable* objects[1]; - objects[0] = fGradient; - - return new TransformObjectsCommand(this, objects, fOriginals, 1, Pivot(), - Translation(), LocalRotation(), LocalXScale(), LocalYScale(), commandName, - nameIndex); + return new TransformGradientCommand(this, fGradient, Pivot(), + Translation(), LocalRotation(), LocalXScale(), LocalYScale(), + commandName, nameIndex); } diff --git a/src/apps/icon-o-matic/transformable/TransformGradientCommand.cpp b/src/apps/icon-o-matic/transformable/TransformGradientCommand.cpp new file mode 100644 index 0000000000..e7f60f9168 --- /dev/null +++ b/src/apps/icon-o-matic/transformable/TransformGradientCommand.cpp @@ -0,0 +1,91 @@ +/* + * Copyright 2006-2010, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include "TransformGradientCommand.h" + +#include +#include + +#include "GradientTransformable.h" + + +using std::nothrow; + + +TransformGradientCommand::TransformGradientCommand(TransformBox* box, + Gradient* gradient, BPoint pivot, BPoint translation, double rotation, + double xScale, double yScale, const char* name, int32 nameIndex) + : + TransformCommand(pivot, translation, rotation, xScale, yScale, name, + nameIndex), + fTransformBox(box), + fGradient(gradient) +{ + if (fGradient == NULL) + return; + +// fGradient->Acquire(); + + if (fTransformBox != NULL) + fTransformBox->AddListener(this); +} + + +TransformGradientCommand::~TransformGradientCommand() +{ +// if (fGradient != NULL) +// fGradient->Release(); + + if (fTransformBox != NULL) + fTransformBox->RemoveListener(this); +} + + +status_t +TransformGradientCommand::InitCheck() +{ + return fGradient != NULL ? TransformCommand::InitCheck() : B_NO_INIT; +} + +// #pragma mark - + +// TransformBoxDeleted +void +TransformGradientCommand::TransformBoxDeleted(const TransformBox* box) +{ + if (fTransformBox == box) { + if (fTransformBox != NULL) + fTransformBox->RemoveListener(this); + fTransformBox = NULL; + } +} + + +// #pragma mark - + + +status_t +TransformGradientCommand::_SetTransformation(BPoint pivot, BPoint translation, + double rotation, double xScale, double yScale) const +{ + if (fTransformBox) { + fTransformBox->SetTransformation(pivot, translation, rotation, xScale, + yScale); + return B_OK; + } + + ChannelTransform transform; + transform.SetTransformation(pivot, translation, rotation, xScale, yScale); + + // Reset and apply transformation. (Gradients never have an original + // transformation that needs to be taken into account, the box always + // assignes it completely.) + fGradient->Reset(); + fGradient->Multiply(transform); + + return B_OK; +} + diff --git a/src/apps/icon-o-matic/transformable/TransformGradientCommand.h b/src/apps/icon-o-matic/transformable/TransformGradientCommand.h new file mode 100644 index 0000000000..e2131d75ab --- /dev/null +++ b/src/apps/icon-o-matic/transformable/TransformGradientCommand.h @@ -0,0 +1,50 @@ +/* + * Copyright 2006-2010, Stephan Aßmus . All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef TRANSFORM_GRADIENT_COMMAND_H +#define TRANSFORM_GRADIENT_COMMAND_H + + +#include "TransformBox.h" +#include "TransformCommand.h" + + +namespace BPrivate { +namespace Icon { + class Gradient; +} +} +using namespace BPrivate::Icon; + + +class TransformGradientCommand : public TransformCommand, + public TransformBoxListener { +public: + TransformGradientCommand( + TransformBox* box, Gradient* gradient, + BPoint pivot, BPoint translation, + double rotation, double xScale, + double yScale, const char* name, + int32 nameIndex); + virtual ~TransformGradientCommand(); + + // Command interface + virtual status_t InitCheck(); + + // TransformBoxListener interface + virtual void TransformBoxDeleted(const TransformBox* box); + +protected: + // TransformCommand interface + virtual status_t _SetTransformation(BPoint pivotDiff, + BPoint translationDiff, + double rotationDiff, double xScaleDiff, + double yScaleDiff) const; + + TransformBox* fTransformBox; + Gradient* fGradient; +}; + + +#endif // TRANSFORM_GRADIENT_COMMAND_H diff --git a/src/apps/icon-o-matic/transformable/TransformObjectsCommand.cpp b/src/apps/icon-o-matic/transformable/TransformObjectsCommand.cpp index bd7e700738..0e2d19e247 100644 --- a/src/apps/icon-o-matic/transformable/TransformObjectsCommand.cpp +++ b/src/apps/icon-o-matic/transformable/TransformObjectsCommand.cpp @@ -103,7 +103,6 @@ TransformObjectsCommand::_SetTransformation( return B_OK; } - ChannelTransform transform; transform.SetTransformation(pivot, translation, rotation, xScale, yScale);