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
This commit is contained in:
Stephan Aßmus 2010-05-19 14:03:41 +00:00
parent 8dfea16fe3
commit c88bc5e973
5 changed files with 147 additions and 9 deletions

View File

@ -289,6 +289,7 @@ Application Icon-O-Matic :
TransformBoxStates.cpp
TransformCommand.cpp
TransformGradientBox.cpp
TransformGradientCommand.cpp
TransformObjectsCommand.cpp
TransformPointsBox.cpp
TransformShapesBox.cpp

View File

@ -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);
}

View File

@ -0,0 +1,91 @@
/*
* Copyright 2006-2010, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "TransformGradientCommand.h"
#include <new>
#include <stdio.h>
#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;
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2006-2010, Stephan Aßmus <superstippi@gmx.de>. 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

View File

@ -103,7 +103,6 @@ TransformObjectsCommand::_SetTransformation(
return B_OK;
}
ChannelTransform transform;
transform.SetTransformation(pivot, translation,
rotation, xScale, yScale);