Reverse manipulations for Scale Convert – Part 1

I’ve got first result. The patch below allows reverse manipulations for Scale convert type.

diff --git a/synfig-studio/trunk/src/gtkmm/canvasview.cpp b/synfig-studio/trunk/src/gtkmm/canvasview.cpp
index 3154ae4..6a8e4cb 100644
--- a/synfig-studio/trunk/src/gtkmm/canvasview.cpp
+++ b/synfig-studio/trunk/src/gtkmm/canvasview.cpp
@@ -2684,6 +2684,21 @@ CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDes

+    if (ValueNode_Scale::Handle scale_value_node = ValueNode_Scale::Handle::cast_dynamic(value_desc.get_value_node()))
+    {
+        int scalar_index(scale_value_node->get_link_index_from_name("scalar"));
+        Real scalar((*(scale_value_node->get_link(scalar_index)))(get_time()).get(Real()));
+        if (scalar == 0.0)
+        {
+            return false;
+        }
+        else
+        {
+            int link_index(scale_value_node->get_link_index_from_name("link"));
+            return canvas_interface()->change_value(synfigapp::ValueDesc(scale_value_node,link_index), value / scalar);
+        }
+    }
case ValueBase::TYPE_REAL:
diff --git a/synfig-studio/trunk/src/synfigapp/instance.cpp b/synfig-studio/trunk/src/synfigapp/instance.cpp
index 020d337..c3c542b 100644
--- a/synfig-studio/trunk/src/synfigapp/instance.cpp
+++ b/synfig-studio/trunk/src/synfigapp/instance.cpp
@@ -42,6 +42,7 @@
#include <synfig/valuenode_blinecalctangent.h>
#include <synfig/valuenode_blinecalcvertex.h>
#include <synfig/valuenode_blinecalcwidth.h>
+#include <synfig/valuenode_scale.h>
#include <map>

#include "general.h"
@@ -74,6 +75,7 @@ synfigapp::is_editable(synfig::ValueNode::Handle value_node)
         || ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_node)
         || ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_node)
         || ValueNode_BLineCalcWidth::Handle::cast_dynamic(value_node)
+        || ValueNode_Scale::Handle::cast_dynamic(value_node)
return true;
return false;

I’ll try to explain some parts of code above. But first want to remind you again what I have no knowledge of C/C++. Be prepared to see some nonsense mumbling here and there. 🙂

Ready? K, here we go.

First of all, as I planned, I have changed synfig-studio/trunk/src/synfigapp/instance.cpp by adding a line:

|| ValueNode_Scale::Handle::cast_dynamic(value_node)

That will indicate the duck converted to the Scale as accessible for manipulations. Inacessible ducks are marked with grey colour. Compiler thrown me an error about undefined  ValueNode_Scale and I have added second line at the header:

#include <synfig/valuenode_scale.h>

After that I need to define how the scale convert will pass the reverse transformation to the linked value. CanvasView::on_duck_changed in synfig-studio/trunk/src/gtkmm/canvasview.cpp is a function responsible for that. Changes are started with condition detecting the Scale convert:

if (ValueNode_Scale::Handle scale_value_node = ValueNode_Scale::Handle::cast_dynamic(value_desc.get_value_node()))

At the same time we assigning respective convert value node to scale_value_node variable. Scale convert does value*scalar transformation. Value is already passed to the function as value variable. To make reverse transformation value / scalar we need to get the scalar.

int scalar_index(scale_value_node->get_link_index_from_name("scalar"));
Real scalar((*(scale_value_node->get_link(scalar_index)))(get_time()).get(Real()));

Argument for get_link_index_from_name() I have figured from the synfig-core/trunk/src/valuenode_scale.cpp. I found that Scale convert arguments are identified by “scalar” and “link” strings. It seems *(scale_value_node->get_link(scalar_index)) is same type as scale_value_node. So get_link() gets the value node linked to the parameter. Scalar_index is needed to identify the parameter. Don’t know what * means.

Now we have the scalar variable. At this moment I’m quite confused about wide range of ways of getting variables. “Real scalar(…)” is quite unusual for python programmer. Few lines above we had “ValueNode_Scale::Handle scale_value_node = …” form. Though, I sure I will spot the difference soon.

We have one exception when we don’t want to perform reverse transformation – when the scalar is equal to zero. In this case we will just leaving thing as is:

if (scalar == 0.0)
    return false;

…if scalar non equal to zero, then we must perfom reverse transformation:

     int link_index(scale_value_node->get_link_index_from_name("link"));
     return canvas_interface()->change_value(synfigapp::ValueDesc(scale_value_node,link_index), value / scalar);

For now I understand ValueDesc as graphical representation of ValueNode on the canvas. It’s like a wrapper around ValueNode, containing information about layer owning it, etc. that’s just my first impression I’ve got examining the api. canvas_interface()->change_value() function changes the duck position on the canvas. To use it you need to pass ValueDesc variable which will point to ValueNode you want to change and new value itself. synfigapp::ValueDesc(scale_value_node,link_index) getting corresponding ValueDesc from scale_value_node ValueNode parameter which index is link_index.

That’s all. Almost. Currently reverse manipulation not works for Radius and Angle ducks. I’ll dig it up next time.



  1. pixelgeek said

    I’m amazed by your earlier comment that you don’t know any C/C++. You certainly aren’t letting that slow you down!

    Regarding “Don’t know what * means”, you might want to dig into pointers and their use –

    • Uranus-235 said

      Thanks, still feeling like monkey with grenade. :))) I’ll look at the link when I have time.

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: