Skip to content

Commit

Permalink
Reversal of lists, strings, segments, and gradients
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmabit committed Aug 9, 2015
1 parent 2495e35 commit a74df30
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions synfig-core/src/synfig/valuenodes/valuenode_reverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

#include "valuenode_reverse.h"
#include <synfig/blinepoint.h>
#include <synfig/segment.h>
#include <synfig/gradient.h>

#include "valuenode_bline.h"
#include "valuenode_dilist.h"
Expand All @@ -46,6 +48,8 @@
#include <synfig/general.h>
#include <ETL/misc>

#include <algorithm>

#endif

/* === U S I N G =========================================================== */
Expand Down Expand Up @@ -140,6 +144,44 @@ ValueNode_Reverse::operator()(Time t)const
if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
printf("%s:%d operator()\n", __FILE__, __LINE__);

Type &type(get_type());

if(type == type_list)
{
ValueBase value = (*link_)(t);
const ValueBase::List &list = value.get_list();
ValueBase::List out;
out.resize(list.size());
std::reverse_copy(list.begin(), list.end(), out.begin());
value.set(out);
return value;
}
else
if(type == type_string)
{
String out = (*link_)(t).get(String());
std::reverse(out.begin(), out.end());
return out;
}
else
if(type == type_segment)
{
Segment out = (*link_)(t).get(Segment());
std::swap(out.p1, out.p2);
std::swap(out.t1, out.t2);
return out;
}
else
if(type == type_gradient)
{
const Gradient &grad = (*link_)(t).get(Gradient());
Gradient out;
for(Gradient::const_reverse_iterator it=grad.rbegin(),end=grad.rend(); it!=end; ++it) {
out.push_back(GradientCPoint(1 - it->pos, it->color));
}
return out;
}

return (*link_)(t);
}

Expand Down

0 comments on commit a74df30

Please sign in to comment.