|
Carlos Lopez |
a09598 |
/* === S Y N F I G ========================================================= */
|
|
Carlos Lopez |
a09598 |
/*! \file stretch.cpp
|
|
Carlos Lopez |
a09598 |
** \brief Implementation of the "Stretch" layer
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** $Id$
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** \legal
|
|
Carlos Lopez |
a09598 |
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
|
|
Carlos Lopez |
a09598 |
** Copyright (c) 2007 Chris Moore
|
|
Carlos Lopez |
e83454 |
** Copyright (c) 2011-2013 Carlos Lรณpez
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** This package is free software; you can redistribute it and/or
|
|
Carlos Lopez |
a09598 |
** modify it under the terms of the GNU General Public License as
|
|
Carlos Lopez |
a09598 |
** published by the Free Software Foundation; either version 2 of
|
|
Carlos Lopez |
a09598 |
** the License, or (at your option) any later version.
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** This package is distributed in the hope that it will be useful,
|
|
Carlos Lopez |
a09598 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Carlos Lopez |
a09598 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Carlos Lopez |
a09598 |
** General Public License for more details.
|
|
Carlos Lopez |
a09598 |
** \endlegal
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
/* ========================================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === H E A D E R S ======================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#ifdef USING_PCH
|
|
Carlos Lopez |
a09598 |
# include "pch.h"
|
|
Carlos Lopez |
a09598 |
#else
|
|
Carlos Lopez |
a09598 |
#ifdef HAVE_CONFIG_H
|
|
Carlos Lopez |
a09598 |
# include <config.h></config.h>
|
|
Carlos Lopez |
a09598 |
#endif
|
|
Carlos Lopez |
a09598 |
|
|
bw |
94d8a6 |
#include <synfig localization.h=""></synfig>
|
|
bw |
94d8a6 |
#include <synfig general.h=""></synfig>
|
|
bw |
94d8a6 |
|
|
Carlos Lopez |
a09598 |
#include <synfig string.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig time.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig context.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig paramdesc.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig renddesc.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig surface.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig value.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig valuenode.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig transform.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
|
|
|
017bf3 |
#include "stretch.h"
|
|
|
017bf3 |
|
|
|
017bf3 |
#include <synfig common="" rendering="" task="" tasktransformation.h=""></synfig>
|
|
|
da4398 |
#include <synfig primitive="" rendering="" transformationaffine.h=""></synfig>
|
|
|
017bf3 |
|
|
Carlos Lopez |
a09598 |
#endif
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === U S I N G =========================================================== */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
using namespace std;
|
|
|
9f3c68 |
using namespace etl;
|
|
Carlos Lopez |
a09598 |
using namespace synfig;
|
|
|
144d3f |
using namespace modules;
|
|
|
9f3c68 |
using namespace lyr_std;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === G L O B A L S ======================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_INIT(Layer_Stretch);
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_SET_NAME(Layer_Stretch,"stretch");
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Stretch,N_("Stretch"));
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_SET_CATEGORY(Layer_Stretch,N_("Distortions"));
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_SET_VERSION(Layer_Stretch,"0.1");
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_SET_CVS_ID(Layer_Stretch,"$Id$");
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === P R O C E D U R E S ================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === M E T H O D S ======================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === E N T R Y P O I N T ================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Layer_Stretch::Layer_Stretch():
|
|
Carlos Lopez |
391e7e |
param_amount(ValueBase(Point(1,1))),
|
|
Carlos Lopez |
391e7e |
param_center(ValueBase(Point(0,0)))
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
5c5090 |
SET_INTERPOLATION_DEFAULTS();
|
|
Carlos Lopez |
5c5090 |
SET_STATIC_DEFAULTS();
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
bool
|
|
Carlos Lopez |
a09598 |
Layer_Stretch::set_param(const String & param, const ValueBase &value)
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
391e7e |
IMPORT_VALUE(param_amount);
|
|
Carlos Lopez |
391e7e |
IMPORT_VALUE(param_center);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return false;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
ValueBase
|
|
Carlos Lopez |
a09598 |
Layer_Stretch::get_param(const String ¶m)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
391e7e |
EXPORT_VALUE(param_amount);
|
|
Carlos Lopez |
391e7e |
EXPORT_VALUE(param_center);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
EXPORT_NAME();
|
|
Carlos Lopez |
a09598 |
EXPORT_VERSION();
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return ValueBase();
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Layer::Vocab
|
|
Carlos Lopez |
a09598 |
Layer_Stretch::get_param_vocab()const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
Layer::Vocab ret;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
ret.push_back(ParamDesc("amount")
|
|
Carlos Lopez |
a09598 |
.set_local_name(_("Amount"))
|
|
Carlos Lopez |
a09598 |
.set_origin("center")
|
|
Carlos Lopez |
42e8f2 |
.set_description(_("Size of the stretch relative to its Center"))
|
|
Carlos Lopez |
a09598 |
);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
ret.push_back(ParamDesc("center")
|
|
Carlos Lopez |
a09598 |
.set_local_name(_("Center"))
|
|
Carlos Lopez |
42e8f2 |
.set_description(_("Where the stretch distortion is centered"))
|
|
Carlos Lopez |
a09598 |
);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return ret;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
9f3c68 |
Layer::Handle
|
|
|
9f3c68 |
Layer_Stretch::hit_check(Context context, const Point &pos)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
391e7e |
Vector amount=param_amount.get(Vector());
|
|
Carlos Lopez |
391e7e |
Point center=param_center.get(Point());
|
|
Carlos Lopez |
391e7e |
|
|
Carlos Lopez |
a09598 |
Point npos(pos);
|
|
Carlos Lopez |
a09598 |
npos[0]=(npos[0]-center[0])/amount[0]+center[0];
|
|
Carlos Lopez |
a09598 |
npos[1]=(npos[1]-center[1])/amount[1]+center[1];
|
|
Carlos Lopez |
a09598 |
return context.hit_check(npos);
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Color
|
|
Carlos Lopez |
a09598 |
Layer_Stretch::get_color(Context context, const Point &pos)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
391e7e |
Vector amount=param_amount.get(Vector());
|
|
Carlos Lopez |
391e7e |
Point center=param_center.get(Point());
|
|
Carlos Lopez |
391e7e |
|
|
Carlos Lopez |
a09598 |
Point npos(pos);
|
|
Carlos Lopez |
a09598 |
npos[0]=(npos[0]-center[0])/amount[0]+center[0];
|
|
Carlos Lopez |
a09598 |
npos[1]=(npos[1]-center[1])/amount[1]+center[1];
|
|
Carlos Lopez |
a09598 |
return context.get_color(npos);
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
9f3c68 |
class lyr_std::Stretch_Trans : public Transform
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
etl::handle<const layer_stretch=""> layer;</const>
|
|
Carlos Lopez |
a09598 |
public:
|
|
Carlos Lopez |
a09598 |
Stretch_Trans(const Layer_Stretch* x):Transform(x->get_guid()),layer(x) { }
|
|
Carlos Lopez |
a09598 |
|
|
|
9f3c68 |
Vector perform(const Vector& x)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
391e7e |
Vector amount=layer->param_amount.get(Vector());
|
|
Carlos Lopez |
391e7e |
Point center=layer->param_center.get(Point());
|
|
Carlos Lopez |
391e7e |
|
|
Carlos Lopez |
391e7e |
return Vector((x[0]-center[0])*amount[0]+center[0],
|
|
Carlos Lopez |
391e7e |
(x[1]-center[1])*amount[1]+center[1]);
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
9f3c68 |
Vector unperform(const Vector& x)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
391e7e |
Vector amount=layer->param_amount.get(Vector());
|
|
Carlos Lopez |
391e7e |
Point center=layer->param_center.get(Point());
|
|
Carlos Lopez |
391e7e |
|
|
Carlos Lopez |
391e7e |
return Vector((x[0]-center[0])/amount[0]+center[0],
|
|
Carlos Lopez |
391e7e |
(x[1]-center[1])/amount[1]+center[1]);
|
|
Carlos Lopez |
a09598 |
}
|
|
Nikita Kitaev |
dc5e35 |
|
|
|
9f3c68 |
String get_string()const
|
|
Nikita Kitaev |
dc5e35 |
{
|
|
Nikita Kitaev |
dc5e35 |
return "stretch";
|
|
Nikita Kitaev |
dc5e35 |
}
|
|
Carlos Lopez |
a09598 |
};
|
|
Carlos Lopez |
a09598 |
etl::handle<transform></transform>
|
|
Carlos Lopez |
a09598 |
Layer_Stretch::get_transform()const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
return new Stretch_Trans(this);
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
Rect
|
|
Carlos Lopez |
a09598 |
Layer_Stretch::get_full_bounding_rect(Context context)const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
391e7e |
Vector amount=param_amount.get(Vector());
|
|
Carlos Lopez |
391e7e |
Point center=param_center.get(Point());
|
|
Carlos Lopez |
391e7e |
|
|
Carlos Lopez |
a09598 |
Rect rect(context.get_full_bounding_rect());
|
|
Carlos Lopez |
a09598 |
Point min(rect.get_min()), max(rect.get_max());
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
return Rect(Point((min[0]-center[0])*amount[0]+center[0],
|
|
Carlos Lopez |
a09598 |
(min[1]-center[1])*amount[1]+center[1]),
|
|
Carlos Lopez |
a09598 |
Point((max[0]-center[0])*amount[0]+center[0],
|
|
Carlos Lopez |
a09598 |
(max[1]-center[1])*amount[1]+center[1]));
|
|
Carlos Lopez |
a09598 |
}
|
|
|
017bf3 |
|
|
|
017bf3 |
rendering::Task::Handle
|
|
|
017bf3 |
Layer_Stretch::build_rendering_task_vfunc(Context context)const
|
|
|
017bf3 |
{
|
|
|
017bf3 |
Vector amount=param_amount.get(Vector());
|
|
|
017bf3 |
Point center=param_center.get(Point());
|
|
|
017bf3 |
|
|
|
5e2754 |
rendering::TaskTransformationAffine::Handle task_transformation(new rendering::TaskTransformationAffine());
|
|
|
5e2754 |
task_transformation->transformation->matrix =
|
|
|
093a8b |
Matrix().set_translate(center)
|
|
|
017bf3 |
* Matrix().set_scale(amount)
|
|
|
093a8b |
* Matrix().set_translate(-center);
|
|
|
017bf3 |
task_transformation->sub_task() = context.build_rendering_task();
|
|
|
017bf3 |
return task_transformation;
|
|
|
017bf3 |
}
|