コード例 #1
0
        private void printNode(node <string> t, Tuple <double, double> parent, double x1, double x2, double y, Canvas cnv)
        {
            if (t == null)
            {
                return;
            }

            double x = (x2 + x1) / 2.0;

            VisualNode v = new VisualNode();

            v.node  = t;
            t.vnode = v;
            v.changeKey(t.key);
            v.changeValue(t.value());

            double curx = x - v.Width / 2;
            double cury = y - v.Height / 2;

            Tuple <double, double> p = new Tuple <double, double>(x, y);

            if (parent != null)
            {
                Line l = new Line();
                l.X1                  = p.Item1;
                l.Y1                  = p.Item2;
                l.X2                  = parent.Item1;
                l.Y2                  = parent.Item2;
                l.Stroke              = Brushes.Olive;
                l.StrokeThickness     = 2;
                l.SnapsToDevicePixels = true;
                l.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
                cnv.Children.Add(l);
            }

            v.SetValue(Canvas.LeftProperty, curx);
            v.SetValue(Canvas.TopProperty, cury);
            cnv.Children.Add(v);
            printNode(t.left, p, x1, x, y + 80, cnv);
            printNode(t.right, p, x, x2, y + 80, cnv);
            v.MouseDoubleClick   += v_MouseDoubleClick;
            v.MouseRightButtonUp += v_MouseRightButtonUp;
        }
コード例 #2
0
        void v_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (parentWindow == null)
            {
                VisualNode     cur = (VisualNode)sender;
                node <string>  curNode = (node <string>)cur.node;
                Treap <string> first = new Treap <string>(), second = new Treap <string>();
                tr.split(ref first, ref second, curNode.key);
                MainWindow firstMainWindow = new MainWindow();
                firstMainWindow.tr = first;
                firstMainWindow.printTreap();
                MainWindow secondMainWindow = new MainWindow();
                secondMainWindow.tr = second;

                secondMainWindow.printTreap();
                firstMainWindow.Show();
                secondMainWindow.Show();
                this.Close();
            }
        }