Logo Search packages:      
Sourcecode: inkscape version File versions

void sp_nodepath_selected_distribute ( Path::Path nodepath,
NR::Dim2  axis 
)

Distribute selected nodes on the specified axis

Definition at line 985 of file nodepath.cpp.

References Path::Path::selected.

{
    if ( !nodepath || !nodepath->selected ) { // no nodepath, or no nodes selected
        return;
    }

    if ( ! (nodepath->selected->next && nodepath->selected->next->next) ) { // less than 3 nodes selected
        return;
    }

    Path::Node *pNode = reinterpret_cast<Path::Node *>(nodepath->selected->data);
    std::vector<NodeSort> sorted;
    for (GList *l = nodepath->selected; l != NULL; l = l->next) {
        pNode = reinterpret_cast<Path::Node *>(l->data);
        if (pNode) {
            NodeSort n(pNode, axis);
            sorted.push_back(n);
            //dest[axis] = pNode->pos[axis];
            //sp_node_moveto(pNode, dest);
        }
    }
    std::sort(sorted.begin(), sorted.end());
    unsigned int len = sorted.size();
    //overall bboxes span
    float dist = (sorted.back()._coord -
                  sorted.front()._coord);
    //new distance between each bbox
    float step = (dist) / (len - 1);
    float pos = sorted.front()._coord;
    for ( std::vector<NodeSort> ::iterator it(sorted.begin());
          it < sorted.end();
          it ++ )
    {
        NR::Point dest((*it)._node->pos);
        dest[axis] = pos;
        sp_node_moveto((*it)._node, dest);
        pos += step;
    }

    if (axis == NR::X) {
        update_repr_keyed(nodepath, "node:move:horizontal");
    } else {
        update_repr_keyed(nodepath, "node:move:vertical");
    }
}


Generated by  Doxygen 1.6.0   Back to index