main.vala 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. class TestNode : GFlow.SimpleNode {
  2. public GFlow.SimpleSource source1;
  3. public GFlow.SimpleSource source2;
  4. public GFlow.SimpleSink sink1;
  5. public TestNode(string name) {
  6. this.name = name;
  7. try {
  8. this.source1 = new GFlow.SimpleSource(typeof(int));
  9. this.source1.name = "%s quelle 1".printf(name);
  10. this.add_source(source1);
  11. this.source2 = new GFlow.SimpleSource(typeof(int));
  12. this.source2.name = "%s quelle 2".printf(name);
  13. this.add_source(source2);
  14. this.sink1 = new GFlow.SimpleSink(1);
  15. this.sink1.name = "%s abfluss 2".printf(name);
  16. this.add_sink(sink1);
  17. this.sink1.max_sources = 10;
  18. } catch (GFlow.NodeError e) {
  19. warning("Couldn't build node");
  20. }
  21. }
  22. public void register_colors(GtkFlow.NodeView nv) {
  23. var src_widget1 = nv.retrieve_dock(this.source1);
  24. var src_widget2 = nv.retrieve_dock(this.source2);
  25. var snk_widget1 = nv.retrieve_dock(this.sink1);
  26. src_widget1.resolve_color.connect_after((d,v)=>{ return {1.0f,0.0f,0.0f,1.0f};});
  27. src_widget2.resolve_color.connect_after((d,v)=>{ return {0.0f,1.0f,0.0f,1.0f};});
  28. snk_widget1.resolve_color.connect_after((d,v)=>{ return {0.0f,0.0f,1.0f,1.0f};});
  29. }
  30. }
  31. int main (string[] args) {
  32. var app = new Gtk.Application(
  33. "de.grindhold.GtkFlow4Example",
  34. ApplicationFlags.FLAGS_NONE
  35. );
  36. app.activate.connect(() => {
  37. var win = new Gtk.ApplicationWindow(app);
  38. var btn = new Gtk.Button.with_label("Spawn Node");
  39. var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
  40. var sw = new Gtk.ScrolledWindow();
  41. var nv = new GtkFlow.NodeView();
  42. var mm = new GtkFlow.Minimap();
  43. sw.child=nv;
  44. sw.vexpand=true;
  45. mm.nodeview = nv;
  46. btn.clicked.connect(()=>{
  47. var node = new TestNode("TestNode");
  48. nv.add(new GtkFlow.Node(node));
  49. });
  50. var n1 = new TestNode("foo");
  51. var n2 = new TestNode("bar");
  52. var gn1 = new GtkFlow.Node(n1);
  53. gn1.add_child(new Gtk.Button.with_label("EEEEEE!"));
  54. gn1.highlight_color = {0.6f,1.0f,0.0f,0.3f};
  55. nv.add(gn1);
  56. n1.register_colors(nv);
  57. nv.add(new GtkFlow.Node(n2));
  58. n2.register_colors(nv);
  59. try {
  60. n1.source1.link(n2.sink1);
  61. } catch (Error e) {
  62. warning("could not link nodees:"+ e.message);
  63. }
  64. win.child = box;
  65. box.append(btn);
  66. box.append(mm);
  67. box.append(sw);
  68. win.present();
  69. });
  70. return app.run(args);
  71. }