예제 #1
0
        public MainWindow()
        {
            InitializeComponent();


            grid = Graph;// new VirtualCanvas();
            grid.SmallScrollIncrement = new Size(_tileWidth + _tileMargin, _tileHeight + _tileMargin);

            //Scroller.Content = grid;
            object v = Scroller.GetValue(ScrollViewer.CanContentScrollProperty);

            Canvas target = grid.ContentCanvas;

            zoom     = new MapZoom(target);
            pan      = new Pan(target, zoom);
            rectZoom = new RectangleSelectionGesture(target, zoom, ModifierKeys.Control);
            rectZoom.ZoomSelection = true;
            autoScroll             = new AutoScroll(target, zoom);
            zoom.ZoomChanged      += new EventHandler(OnZoomChanged);

            grid.VisualsChanged     += new EventHandler <VisualChangeEventArgs>(OnVisualsChanged);
            ZoomSlider.ValueChanged += new RoutedPropertyChangedEventHandler <double>(OnZoomSliderValueChanged);

            grid.Scale.Changed     += new EventHandler(OnScaleChanged);
            grid.Translate.Changed += new EventHandler(OnScaleChanged);

            grid.Background = new SolidColorBrush(Color.FromRgb(0xd0, 0xd0, 0xd0));
            grid.ContentCanvas.Background = Brushes.White;

            AllocateNodes();
        }
예제 #2
0
            public Size MeasureText(VirtualCanvas parent, string label)
            {
                if (_parent != parent)
                {
                    FontFamily  fontFamily  = (FontFamily)parent.GetValue(TextBlock.FontFamilyProperty);
                    FontStyle   fontStyle   = (FontStyle)parent.GetValue(TextBlock.FontStyleProperty);
                    FontWeight  fontWeight  = (FontWeight)parent.GetValue(TextBlock.FontWeightProperty);
                    FontStretch fontStretch = (FontStretch)parent.GetValue(TextBlock.FontStretchProperty);
                    _fontSize = (double)parent.GetValue(TextBlock.FontSizeProperty);
                    _typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
                    _parent   = parent;
                }
                FormattedText ft = new FormattedText(label, CultureInfo.CurrentUICulture,
                                                     FlowDirection.LeftToRight, _typeface, _fontSize, Brushes.Black);

                return(new Size(ft.Width, ft.Height));
            }
예제 #3
0
            public UIElement CreateVisual(VirtualCanvas parent)
            {
                if (_visual == null)
                {
                    switch (_shape)
                    {
                    case TestShapeType.Curve:
                    {
                        PathGeometry g = new PathGeometry();
                        PathFigure   f = new PathFigure();
                        f.StartPoint = _points[0];
                        g.Figures.Add(f);
                        for (int i = 0, n = _points.Length; i < n; i += 3)
                        {
                            BezierSegment s = new BezierSegment(_points[i], _points[i + 1], _points[i + 2], true);
                            f.Segments.Add(s);
                        }
                        Path p = new Path();
                        p.Data = g;

                        p.Stroke          = Stroke;
                        p.StrokeThickness = 2;

                        //DropShadowBitmapEffect effect = new DropShadowBitmapEffect();
                        //effect.Opacity = 0.8;
                        //effect.ShadowDepth = 3;
                        //effect.Direction = 270;
                        //c.BitmapEffect = effect;
                        _visual = p;
                        break;
                    }

                    case TestShapeType.Ellipse:
                    {
                        Canvas c = new Canvas();

                        Ellipse e = new Ellipse();
                        c.Width  = e.Width = _bounds.Width;
                        c.Height = e.Height = _bounds.Height;
                        c.Children.Add(e);

                        Size   s = MeasureText(parent, Label);
                        double x = (_bounds.Width - s.Width) / 2;
                        double y = (_bounds.Height - s.Height) / 2;

                        TextBlock text = new TextBlock();
                        text.Text = Label;
                        Canvas.SetLeft(text, x);
                        Canvas.SetTop(text, y);
                        c.Children.Add(text);

                        e.StrokeThickness = 2;
                        e.Stroke          = Stroke;
                        e.Fill            = Fill;

                        //DropShadowBitmapEffect effect = new DropShadowBitmapEffect();
                        //effect.Opacity = 0.8;
                        //effect.ShadowDepth = 3;
                        //effect.Direction = 270;
                        //c.BitmapEffect = effect;
                        _visual = c;
                        break;
                    }

                    case TestShapeType.Rectangle:
                    {
                        Border b = new Border();
                        b.CornerRadius = new CornerRadius(3);
                        b.Width        = _bounds.Width;
                        b.Height       = _bounds.Height;
                        TextBlock text = new TextBlock();
                        text.Text = Label;
                        text.VerticalAlignment   = VerticalAlignment.Center;
                        text.HorizontalAlignment = HorizontalAlignment.Center;
                        b.Child      = text;
                        b.Background = Fill;
                        //DropShadowBitmapEffect effect = new DropShadowBitmapEffect();
                        //effect.Opacity = 0.8;
                        //effect.ShadowDepth = 3;
                        //effect.Direction = 270;
                        //b.BitmapEffect = effect;
                        _visual = b;
                        break;
                    }
                    }
                }
                return(_visual);
            }