* Copyright 2006, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "ResetTransformationCommand.h"
#include <new>
#include <stdio.h>
#include <Catalog.h>
#include <Locale.h>
#include <StringFormat.h>
#include "ChannelTransform.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-ResetTransformationCmd"
using std::nothrow;
ResetTransformationCommand::ResetTransformationCommand(
Transformable** const objects,
int32 count)
: Command(),
fObjects(objects && count > 0 ?
new (nothrow) Transformable*[count] : NULL),
fOriginals(objects && count > 0 ?
new (nothrow) double[
count * Transformable::matrix_size] : NULL),
fCount(count)
{
if (!fObjects || !fOriginals)
return;
memcpy(fObjects, objects, fCount * sizeof(Transformable*));
int32 matrixSize = Transformable::matrix_size;
for (int32 i = 0; i < fCount; i++) {
fObjects[i]->StoreTo(&fOriginals[matrixSize * i]);
}
}
ResetTransformationCommand::~ResetTransformationCommand()
{
delete[] fObjects;
delete[] fOriginals;
}
status_t
ResetTransformationCommand::InitCheck()
{
return fObjects && fOriginals ? B_OK : B_NO_INIT;
}
status_t
ResetTransformationCommand::Perform()
{
for (int32 i = 0; i < fCount; i++) {
if (fObjects[i])
fObjects[i]->Reset();
}
return B_OK;
}
status_t
ResetTransformationCommand::Undo()
{
int32 matrixSize = Transformable::matrix_size;
for (int32 i = 0; i < fCount; i++) {
if (fObjects[i])
fObjects[i]->LoadFrom(&fOriginals[i * matrixSize]);
}
return B_OK;
}
void
ResetTransformationCommand::GetName(BString& name)
{
static BStringFormat format(B_TRANSLATE("Reset {0, plural, "
"one{transformation} other{transformations}}"));
format.Format(name, fCount);
}