How to handle icon for bone_object in iconcontroller.cpp?

Hi all,

I decided to try my hand at designing an icon for bone_object and pair_bone_object_bone_object. Made a prototype but when I tried to put it in the code, Synfig stopped compiling. Just like with my icon for type transformation I added this code to iconcontroller.cpp:

        if (type == type_transformation)
                return "type_transformation_icon";
        if (type == pair_bone_object_bone_object)
                return "pair_bone_object_bone_object_icon";

And compilation fails with the following error:

[1/2] Building CXX object synfig-studio/src/gui/CMakeFiles/synfigstudio.dir/iconcontroller.cpp.obj
FAILED: synfig-studio/src/gui/CMakeFiles/synfigstudio.dir/iconcontroller.cpp.obj
-SNIP-
.../synfig-studio/src/gui/iconcontroller.cpp.obj -c ../synfig-studio/src/gui/iconcontroller.cpp
../synfig-studio/src/gui/iconcontroller.cpp: In function 'std::string tudio::value_icon_name(synfig::Type&)':
../synfig-studio/src/gui/iconcontroller.cpp:386:21: error: 'pair_bone_object_bone_object' was not declared in this scope
  386 |         if (type == pair_bone_object_bone_object)
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.

So it’s not a type? How to properly handle it then? I made this hack and it’s working:

        if (type.description.name == "pair_bone_object_bone_object")
                return "pair_bone_object_bone_object_icon";

But I don’t know if it’s a good solution because we’re directly comparing strings unlike other proper types that are wrapped through their respective classes. Can you guys suggest how should icons without a dedicated type (if I understand properly) should be handled in the code?

Maybe you could use: types_namespace::TypePair<Bone, Bone>::instance or simply type_bone_object, type_bone_valuenode

1 Like

Yes, thank you! After a bit of struggling I got it!

It definitely better than comparing strings. In order to work this needs inclusion of “synfig/pair.h” and “synfig/valuenodes/valuenode_bone.h” otherwise compiler throws a swarm of errors which confused me at first. C++ is scary. Alright, now I can concentrate on designing the icon.