Example GraphWin Call-Back FunctionsThe following simple example shows how to define and use call-back functions
to customize the interactive interface of GraphWin.
The call-back functions only print a message. In the main functions the
call-back functions are set for #include <LEDA/graphics/graphwin.h> #include <LEDA/geo/point.h> using namespace leda; bool new_node_pre_handler(GraphWin& gw,const point& p) { std::cout << "new_node_pre_handler(): "; std::cout << "create new node at point " << p << std::endl; return true; } void new_node_post_handler(GraphWin& gw, node v) { std::cout << "new_node_post_handler(): node "; gw.get_graph().print_node(v); std::cout << " was created" << std::endl << std::endl; } bool new_edge_pre_handler(GraphWin& gw,node v, node w) { std::cout << "new_edge_pre_handler(): "; std::cout << "create new edge with source "; gw.get_graph().print_node(v); std::cout << " and target "; gw.get_graph().print_node(w); std::cout << std::endl; return true; } void new_edge_post_handler(GraphWin& gw, edge e) { std::cout << "new_edge_post_handler(): edge "; gw.get_graph().print_edge(e); std::cout << " was created" << std::endl << std::endl; } bool start_move_node_handler(GraphWin& gw, node v) { std::cout << "start_move_node_handler(): move node "; gw.get_graph().print_node(v); std::cout << std::endl; return true; } bool move_node_handler(GraphWin& gw, node v, const point& p) { std::cout << "move_node_handler(): node "; gw.get_graph().print_node(v); std::cout << " is at point " << p << std::endl; return true; } void end_move_node_handler(GraphWin& gw, node v) { std::cout << "end_move_node_handler(): moving node "; gw.get_graph().print_node(v); std::cout << " finished" << std::endl << std::endl; } int main() { GraphWin gw; gw.set_new_node_handler(new_node_pre_handler); gw.set_new_node_handler(new_node_post_handler); gw.set_new_edge_handler(new_edge_pre_handler); gw.set_new_edge_handler(new_edge_post_handler); gw.set_start_move_node_handler(start_move_node_handler); gw.set_move_node_handler(move_node_handler); gw.set_end_move_node_handler(end_move_node_handler); gw.display(); gw.edit(); return 0; } |
See also:Customizing the Interactive Interface A Recipe for Online Demos of Graph Algorithms A Recipe for Online Demos of Network Algorithms Manual Pages: |