Getting started Coding

Hello! I have been looking through the source code documentation, infrastructure, and the coding tutorials, and I feel I have gained enough knowledge about how to program in Synfig to work on a feature, but I would like to confirm if I am thinking correctly about it. (I looked for more information explaining the nuts and bolts of Synfig on this forum, but did not find what I was looking for)

The feature is to automate the process of “filling in” a part of a drawing consisting of multiple outline layers by duplicating all of the component ducks, creating a region based on those ducks, and linking the ducks together. This will allow the user to seamlessly color everything and have an easier time animating. Here is the original topic I posted:
[Suggestion: Expanding Fill Tool (Paintbucket) Functionality)

I was thinking that the feature would work as follows:

  1. User selects all the nodes to define the region
  2. User selects an option in the right-click menu to open a dialogue
  3. The dialogue displays a copy of all the selected ducks exactly as they looked in the main canvas
  4. The user clicks on each duck in the order that they should be connected: a number appears over each duck as the user clicks
  5. The user confirms the input, and Synfig creates the region from those ducks
  6. Synfig Automatically links each duck to its counterpart in the original outline layers.

I found a “Dialogue_Setup” class, and a Duck class. I’m not sure how to “getSelectedDucks” from the main canvas, however, or render them on the dialogue either. I could try looking for them, but I’ve had some difficulty in understanding the code documentation, and was wondering if developers with more experience in Synfig could think of the classes off the top of their head.

So you are in the right place! :slight_smile:

This is a really good selection feature to start coding. It will be very useful for the artist work flow to have that action available.

It looks reasonable but I would add one extra functionality although it would imply more work. It would be great that the dialog offers an initial connection of the vertexes to the user so it is only needed to press the accept button. It would reduce the working time.
Also, linking or not should be optional.

It is not easy to make a summary here of such complex tasks. I would try to start assuming that you have little knowledge of the code structure:
There are three main components on Synfig:
ETL: Extended template library
synfig-core: the core of the renderer and the storage of data for synfig. Independent of user interface, provides a command line interface to be used in a terminal.
synfig-studio: It has two components as well: gui and synfigapp. Gui holds all the graphical user interface components for the Synfig Studio application and synfigapp holds all the interface between the gui and the synfig-core. (it is now really full true because synfig-studio uses synfig-core components directly in many cases but well)

To perform the feature you need to learn to:

  1. Add a new action
  2. Create dialogs and show and hide them.
  3. Create a Layer, Create a canvas with that layer and render it to a surface.
  4. Based on the layers of the canvas, create some kind of marks (old ducks name) to show where the vertexes are.
  5. Show the surface and the marks on the dialogue (I strongly recommend to use Cairo)
  6. Handle the mouse inputs to select the vertexes in the right order.
  7. Perform the creation of the new layer and insert it on the document canvas layer stack.
  8. Link the vertexes from the new layer with the existing ones

Too many brick pieces to put all together but the result would be very pleased!

Tips:
For actions: Actions are all derived classes and they are stored at synfig-studio/src/synfigapp/actions. All they have the same structure: has a vocabulary, expects some values passed on with its corresponding tags, does som work before currently execute the action and finally perform the action. Many of them are undoable so the undo has to be defined too by storing the previous values.
For dialogs you can learn just reading how some other dialogs are managed.
For Layer creation just find the layer class you want to create and call its constructor. There are many examples on the code, specially on the actions to insert a layer on the layer stack.
For canvas and render it to a surface you can take a look to the Navigator or the Preview dialogs.
For the marks on the layer to show the vertexes position, you might want to follow a similar structure than the Duckamatic>Workarea classes have, doing a specialization of them. It possibly would need duplication of many variables but on contrary you can reuse many of the code. Alternatively you should create your own class to hold and manage those selectable widgets on the drawing area. Possibly this is the most innovative task to do. The same comments go for the mouse handling here.
For perform the new layer creation and insert it on the canvas stack I think that if you reach this point it would be easy :wink:
For linking the new included vertexes to the other layers you will do use of the current actions ValueDescLink and its derivatives.

Additional tips:
I assume you’re coding under Mac or Linux so it would be great to have some tools around:
Git: learn to use the simpler git commands. There are good git interfaces for all platforms
github: open an account at github and fork the repository.
build environment: before start coding, be sure that you can build without any issue in your platform.
IDE: we don’t have an official IDE to use in any platform but people are happy with Anjuta or Geany under Linux and Xcode under Mac. Always need to use the build scripts to rebuild the code once modified.
Try to make when possible atomic commits with the minimum significance modifications each time keeping the code always possible to build. It would help a lot to further debug by bisection method.
Try to keep same style of coding than the current one.
Finally, synfig-devl mailing list is a good place for off line and properly stored threads for discussion or help request on development.

Good luck!!!
-G