//------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------

        private static void GeometryCombineModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CombinedGeometry target = ((CombinedGeometry)d);


            target.PropertyChanged(GeometryCombineModeProperty);
        }
예제 #2
0
        public override void PushClipExclude(RRect rect)
        {
            var geometry = new CombinedGeometry();
            geometry.Geometry1 = new RectangleGeometry(Utils.Convert(_clipStack.Peek()));
            geometry.Geometry2 = new RectangleGeometry(Utils.Convert(rect));
            geometry.GeometryCombineMode = GeometryCombineMode.Exclude;

            _clipStack.Push(_clipStack.Peek());
            _g.PushClip(geometry);
        }
예제 #3
0
        //Draws outline from inside line boundry to outside line boundry
        public void DrawCircleOutline(Color color)
        {
            using (DrawingContext dc = this.RenderOpen())
            {
                EllipseGeometry bigEllips = new EllipseGeometry(centre, radius, radius);
                EllipseGeometry smallEllips = new EllipseGeometry(centre, radius - lineThickness, radius - lineThickness);
                CombinedGeometry ellipseOutline = new CombinedGeometry(GeometryCombineMode.Exclude, bigEllips, smallEllips);
                dc.DrawGeometry(new SolidColorBrush(color), new Pen(new SolidColorBrush(color), 1), ellipseOutline);


            }
        }
예제 #4
0
        public string Text2Path(String strText, string strCulture, bool LtoR, string strTypeFace, int nSize, Thickness masks)
        {
            // Set up the Culture
            if (strCulture == "")
                strCulture = "en-us";
            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(strCulture);

            // Set up the flow direction
            System.Windows.FlowDirection fd;
            if (LtoR)
                fd = FlowDirection.LeftToRight;
            else
                fd = FlowDirection.RightToLeft;

            // Set up the font family from the parameter
            FontFamily ff = new FontFamily(strTypeFace);

            // Create the new typeface
            System.Windows.Media.Typeface tf = new System.Windows.Media.Typeface(ff,

                FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);

            // Create a formatted text object from the text,

            // culture, flowdirection, typeface, size and black

            FormattedText t = new FormattedText(strText, ci, fd, tf, nSize,

                System.Windows.Media.Brushes.Black);

            // Build a Geometry out of this
            Geometry g = t.BuildGeometry(new Point(0, 0));

            // Get the Path info from the geometry
            PathGeometry p = g.GetFlattenedPathGeometry();
            var x = nSize - masks.Left - masks.Right;
            var y = nSize - masks.Top - masks.Bottom;
            var size = new Size(x < 0 ? 0 : x, y < 0 ? 0 : y);
            var rectv = new Rect(new Point(masks.Left, masks.Top), size);

            RectangleGeometry rg = new RectangleGeometry(rectv);
            var cg = new CombinedGeometry(p, rg);
            cg.GeometryCombineMode = GeometryCombineMode.Intersect;

            p = cg.GetFlattenedPathGeometry();

            // Return the path info
            return p.ToString();
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            EllipseGeometry ellipse = new EllipseGeometry(new Point(50, 150), 50, 20);
            RectangleGeometry rect = new RectangleGeometry(new Rect(50, 150, 50, 20), 5, 5);

            //注意到GeometryCombineMode枚举,它有四个枚举值,如果我们有A,B分别表示两个图形的话
            //GeometryCombineMode.Exclude:  合并结果为A-B
            //GeometryCombineMode.Intersect:  合并结果为A与B的相交部分
            //GeometryCombineMode.Union:  合并结果为A+B
            //GeometryCombineMode.Xor:  合并结果为(A-B)+(B-A)
            CombinedGeometry combined = new CombinedGeometry(GeometryCombineMode.Xor, ellipse, rect);

            drawingContext.DrawGeometry(Brushes.Black, new Pen(Brushes.BlanchedAlmond, 2),combined);
        }
        private static void Geometry1PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // The first change to the default value of a mutable collection property (e.g. GeometryGroup.Children)
            // will promote the property value from a default value to a local value. This is technically a sub-property
            // change because the collection was changed and not a new collection set (GeometryGroup.Children.
            // Add versus GeometryGroup.Children = myNewChildrenCollection). However, we never marshalled
            // the default value to the compositor. If the property changes from a default value, the new local value
            // needs to be marshalled to the compositor. We detect this scenario with the second condition
            // e.OldValueSource != e.NewValueSource. Specifically in this scenario the OldValueSource will be
            // Default and the NewValueSource will be Local.
            if (e.IsASubPropertyChange &&
                (e.OldValueSource == e.NewValueSource))
            {
                return;
            }


            CombinedGeometry target = ((CombinedGeometry)d);


            Geometry oldV = (Geometry)e.OldValue;
            Geometry newV = (Geometry)e.NewValue;

            System.Windows.Threading.Dispatcher dispatcher = target.Dispatcher;

            if (dispatcher != null)
            {
                DUCE.IResource targetResource = (DUCE.IResource)target;
                using (CompositionEngineLock.Acquire())
                {
                    int channelCount = targetResource.GetChannelCount();

                    for (int channelIndex = 0; channelIndex < channelCount; channelIndex++)
                    {
                        DUCE.Channel channel = targetResource.GetChannel(channelIndex);
                        Debug.Assert(!channel.IsOutOfBandChannel);
                        Debug.Assert(!targetResource.GetHandle(channel).IsNull);
                        target.ReleaseResource(oldV, channel);
                        target.AddRefResource(newV, channel);
                    }
                }
            }

            target.PropertyChanged(Geometry1Property);
        }
예제 #7
0
        protected virtual Geometry CreateGeometry(Geometry box, Geometry connector)
        {
            var ballonGeometry = new CombinedGeometry(GeometryCombineMode.Union, box, connector);

            // ballonGeometry.Freeze();
            return ballonGeometry;
        }
예제 #8
0
        /// <summary>
        /// Walk up the tree from the adorned element to the AdornerLayer's parent, accumulating 
        /// clip geometries as we go.  Called when IsClipEnabled == true to allow an adorner 
        /// to be clipped (which normally, it isn't).
        /// </summary> 
        private CombinedGeometry GetClipGeometry(Visual element, Adorner adorner)
        {
            Visual oldElement = null;
 
            // we intentionally do not ascend in to a 3D scene
            Visual adornerLayerParent = VisualTreeHelper.GetParent(this) as Visual; 
            if (adornerLayerParent == null) 
            {
                return null; 
            }

            CombinedGeometry combinedGeometry = null;
 
            // If the element has been removed from the tree and we've not yet had a chance
            // to remove the adorner, there's obviously no clipping 
            if (!adornerLayerParent.IsAncestorOf(element)) 
            {
                return null; 
            }

            while (element != adornerLayerParent && element != null)
            { 
                Geometry geometry = VisualTreeHelper.GetClip(element);
                if (geometry != null) 
                { 
                    if (combinedGeometry == null)
                    { 
                        combinedGeometry = new CombinedGeometry(geometry, null);
                    }
                    else
                    { 
                        GeneralTransform transform = oldElement.TransformToAncestor(element);
                        combinedGeometry.Transform = transform.AffineTransform; 
                        combinedGeometry = new CombinedGeometry(combinedGeometry, geometry); 
                        combinedGeometry.GeometryCombineMode = GeometryCombineMode.Intersect;
                    } 
                    oldElement = element;
                }

                // we intentionally separate adorners from spanning 3D boundaries 
                // and if the parent is ever 3D there was a mistake
                element = (Visual)VisualTreeHelper.GetParent(element); 
            } 
            if (combinedGeometry != null)
            { 
                // transform the last combined geometry up to the top
                GeneralTransform transform = oldElement.TransformToAncestor(adornerLayerParent);
                if (transform == null)
                { 
                    combinedGeometry = null;
                } 
                else 
                {
                    TransformGroup transformGroup = new TransformGroup(); 
                    transformGroup.Children.Add(transform.AffineTransform);

                    // Now transform back down to the adorner
                    transform = adornerLayerParent.TransformToDescendant(adorner); 
                    if (transform == null)
                    { 
                        combinedGeometry = null; 
                    }
                    else 
                    {
                        transformGroup.Children.Add(transform.AffineTransform);
                        combinedGeometry.Transform = transformGroup;
                    } 
                }
            } 
 
            return combinedGeometry;
        } 
예제 #9
0
 private static Geometry CombineGeometries(IReadOnlyList<Geometry> geometries)
 {
     Debug.Assert(geometries.Count > 0);
     if (geometries.Count == 1) return geometries.First();
     var seed = new CombinedGeometry(GeometryCombineMode.Union, geometries[0], geometries[1]);
     return geometries.Skip(2).Aggregate(seed, (cg, g) => new CombinedGeometry(GeometryCombineMode.Union, cg, g));
 }
예제 #10
0
        public KeyValuePair<Point, Point> Ellipse(Point at, double alpha, double beta, Size radiuses)
        {
            //alpha = Math.Abs(alpha) % 360;
            //beta = Math.Abs(beta) % 360;

            //if (beta - alpha >= 360d) beta = alpha + 360d;

            Point from = new Point((at.X + Math.Cos(ToRadians(alpha)) * radiuses.Width), (at.Y - Math.Sin(ToRadians(alpha)) * radiuses.Height));
            Point to = new Point((at.X + Math.Cos(ToRadians(beta)) * radiuses.Width), (at.Y - Math.Sin(ToRadians(beta)) * radiuses.Height));

            Path tmpPath = new Path();

            ArcSegment tmpArc = new ArcSegment();
            tmpArc.Point = to;
            tmpArc.Size = radiuses;
            tmpArc.SweepDirection = SweepDirection.Counterclockwise;
            tmpArc.IsLargeArc = (Math.Abs(beta - alpha) > 180d ? true : false);

            PathFigure tmpFigure = new PathFigure();
            tmpFigure.StartPoint = from;
            tmpFigure.Segments.Add(tmpArc);

            PathGeometry tmpGeometry = new PathGeometry();
            tmpGeometry.Figures.Add(tmpFigure);

            CombinedGeometry tmpCombined = new CombinedGeometry();
            tmpCombined.GeometryCombineMode = GeometryCombineMode.Exclude;
            tmpCombined.Geometry1 = tmpGeometry;

            tmpFigure = new PathFigure();
            tmpFigure.StartPoint = from;
            tmpFigure.Segments.Add(new LineSegment(at, false));
            tmpFigure.Segments.Add(new LineSegment(to, false));
            tmpFigure.IsClosed = true;
            tmpGeometry = new PathGeometry();
            tmpGeometry.Figures.Add(tmpFigure);

            tmpCombined.Geometry2 = tmpGeometry;

            tmpPath.Data = tmpCombined;
            tmpPath.Stroke = brush;
            tmpPath.StrokeThickness = LineThickness;
            tmpPath.StrokeDashArray = LineStyle;
            tmpPath.StrokeDashCap = LineCapStyle;
            tmpPath.StrokeLineJoin = LineJoinStyle;
            tmpPath.Fill = brush;

            buffer.Add(tmpPath);

            return new KeyValuePair<Point, Point>(from, to);
        }
예제 #11
0
        static Drawing DrawCharacter(char ch, Typeface typeFace, double fontSize, GameColor color, GameColor bgColor,
			bool drawOutline, double outlineThickness, bool reverse)
        {
            Color c;
            if (color == GameColor.None)
                c = Colors.White;
            else
                c = color.ToWindowsColor();

            DrawingGroup dGroup = new DrawingGroup();
            var brush = new SolidColorBrush(c);
            var bgBrush = bgColor != GameColor.None ? new SolidColorBrush(bgColor.ToWindowsColor()) : Brushes.Transparent;
            using (DrawingContext dc = dGroup.Open())
            {
                var formattedText = new FormattedText(
                        ch.ToString(),
                        System.Globalization.CultureInfo.InvariantCulture,
                        FlowDirection.LeftToRight,
                        typeFace,
                        fontSize, Brushes.Black);

                var geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));
                var pen = drawOutline ? new Pen(Brushes.Black, outlineThickness) : null;
                var boundingGeometry = new RectangleGeometry(pen != null ? geometry.GetRenderBounds(pen) : geometry.Bounds);

                if (reverse)
                    geometry = new CombinedGeometry(GeometryCombineMode.Exclude, boundingGeometry, geometry);

                dc.DrawGeometry(bgBrush, null, boundingGeometry);
                dc.DrawGeometry(brush, pen, geometry);
            }

            return dGroup;
        }
        /// <summary>
        /// Coercion call back for clip property which ensures that the cell overlapping with frozen 
        /// column gets clipped appropriately.
        /// </summary>
        /// <param name="d"></param>
        /// <param name="baseValue"></param>
        /// <returns></returns>
        private static object OnCoerceClip(DependencyObject d, object baseValue)
        {
            DataGridCell cell = (DataGridCell)d;
            Geometry geometry = baseValue as Geometry;
            Geometry frozenGeometry = DataGridHelper.GetFrozenClipForCell(cell);
            if (frozenGeometry != null)
            {
                if (geometry == null)
                {
                    return frozenGeometry;
                }

                geometry = new CombinedGeometry(GeometryCombineMode.Intersect, geometry, frozenGeometry);
            }

            return geometry;
        }
예제 #13
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     
     #line 4 "..\..\BookPage.xaml"
     ((WPFMitsuControls.BookPage)(target)).Loaded += new System.Windows.RoutedEventHandler(this.OnLoaded);
     
     #line default
     #line hidden
     return;
     case 2:
     this.mainGrid = ((System.Windows.Controls.Grid)(target));
     return;
     case 3:
     this.page2 = ((System.Windows.Controls.ContentPresenter)(target));
     return;
     case 4:
     this.nextPageShadowCanvas = ((System.Windows.Controls.Canvas)(target));
     return;
     case 5:
     this.nextPageShadow = ((System.Windows.Media.LinearGradientBrush)(target));
     return;
     case 6:
     this.nextPageShadowCanvasOffset1 = ((System.Windows.Media.GradientStop)(target));
     return;
     case 7:
     this.nextPageShadowCanvasOffset2 = ((System.Windows.Media.GradientStop)(target));
     return;
     case 8:
     this.clippingPage0 = ((System.Windows.Media.CombinedGeometry)(target));
     return;
     case 9:
     this.page0 = ((System.Windows.Controls.ContentPresenter)(target));
     return;
     case 10:
     this.gridShadow = ((System.Windows.Controls.Canvas)(target));
     return;
     case 11:
     this.pageShadow = ((System.Windows.Media.LinearGradientBrush)(target));
     return;
     case 12:
     this.rectangleVisible = ((System.Windows.Controls.Grid)(target));
     return;
     case 13:
     this.rectangleTranslate = ((System.Windows.Media.TranslateTransform)(target));
     return;
     case 14:
     this.rectangleRotate = ((System.Windows.Media.RotateTransform)(target));
     return;
     case 15:
     this.clippingFigure = ((System.Windows.Media.PathGeometry)(target));
     return;
     case 16:
     this.page1 = ((System.Windows.Controls.ContentPresenter)(target));
     return;
     case 17:
     this.canvasReflection = ((System.Windows.Controls.Canvas)(target));
     return;
     case 18:
     this.pageReflection = ((System.Windows.Media.LinearGradientBrush)(target));
     return;
     }
     this._contentLoaded = true;
 }
        /// <summary>
        /// When overridden in a derived class, participates in rendering operations that are directed by the layout system. 
        /// In this case the rendering draws additional line between info box and its origin vertex control, when
        /// the mouse is over either vertex control or its info box.
        /// </summary>
        /// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            var element = OriginElement as FrameworkElement;

            if (element != null && (IsMouseOver || element.IsMouseOver))
            {
                var mainWindow = this.GetParent<DockableGraph>(null);
                
                var gt = element.TransformToVisual(this);
                var elementCenter = gt.Transform(new Point(element.ActualWidth / 2, element.ActualHeight / 2));
                var elementSize = new Size(element.ActualWidth, element.ActualHeight);
                var elementRect = new Rect(gt.Transform(new Point(0, 0)), elementSize);

                var thisCenter = new Point(ActualWidth / 2, ActualHeight / 2);

                // The total area we'll be drawing in.
                var totalRect = new Rect(elementRect.Location, elementRect.Size);
                totalRect.Union(new Rect(new Point(0, 0), new Size(ActualWidth, ActualHeight)));

                // Create geometry objects to work with.
                var elementRectangleGeometry = new RectangleGeometry(elementRect);
                var totalRectangleGeometry = new RectangleGeometry(totalRect);

                // We'll now remove the element's rectangle from where we're drawing, so that we 
                // don't draw on top of it, but will draw on top of everything else.
                CombinedGeometry clipGeometry = new CombinedGeometry(GeometryCombineMode.Exclude, totalRectangleGeometry, elementRectangleGeometry);

                drawingContext.PushClip(clipGeometry);

                //var node = OriginElement.Vertex as TraceLab.Core.Experiments.ExperimentNode;
                //Point vertexCenter = new Point(node.Data.X, node.Data.Y);

                Pen solidPen = new Pen(System.Windows.Media.Brushes.LightCoral, 1.0);
                drawingContext.DrawLine(solidPen, elementCenter, thisCenter);

                // Pop off the RectangleGeometry
                drawingContext.Pop();
            }

            base.OnRender(drawingContext);
        }
예제 #15
0
        Drawing Test(char ch)
        {
            var typeFace = new Typeface(new FontFamily("arial"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);

            int fontSize = 64;

            DrawingGroup dGroup = new DrawingGroup();
            var brush = new SolidColorBrush(Colors.Black);
            using (DrawingContext dc = dGroup.Open())
            {
                var formattedText = new FormattedText(
                        ch.ToString(),
                        System.Globalization.CultureInfo.InvariantCulture,
                        FlowDirection.LeftToRight,
                        typeFace,
                        fontSize, Brushes.Black, null, TextFormattingMode.Display);

                bool drawOutline = false;
                double outlineThickness = 0;
                CharRenderMode mode = CharRenderMode.Caps;
                bool reverse = false;

                var geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));
                var pen = drawOutline ? new Pen(Brushes.Black, outlineThickness) : null;
                var bounds = pen != null ? geometry.GetRenderBounds(pen) : geometry.Bounds;

                if (bounds.IsEmpty)
                    return null;

                Rect bb;

                switch (mode)
                {
                    case CharRenderMode.Full:
                        {
                            double size = formattedText.Height;
                            bb = new Rect(bounds.X + bounds.Width / 2 - size / 2, 0, size, size);
                        }
                        break;

                    case CharRenderMode.Caps:
                        {
                            double size = typeFace.CapsHeight * fontSize;
                            bb = new Rect(bounds.X + bounds.Width / 2 - size / 2, formattedText.Baseline - size,
                                size, size);
                        }
                        break;

                    case CharRenderMode.Free:
                        bb = bounds;
                        break;

                    default:
                        throw new Exception();
                }

                if (reverse)
                    geometry = new CombinedGeometry(GeometryCombineMode.Exclude, new RectangleGeometry(bb), geometry);

                dc.DrawRectangle(Brushes.Transparent, null, bb);

                dc.DrawGeometry(brush, pen, geometry);

                /*
                var dl = new Action<double>((y) =>
                    dc.DrawLine(new Pen(Brushes.Red, 1), new Point(bb.Left, y), new Point(bb.Right, y)));

                dl(0);
                dl(formattedText.Baseline);
                dl(fontSize);
                dl(formattedText.Height);
                dl(formattedText.Baseline - typeFace.CapsHeight * fontSize);
                 */
            }

            return dGroup;
        }
예제 #16
0
파일: WPFDrawer.cs 프로젝트: norniel/Game
        public void DrawDayNight(double lightness, GameDateTime gameDateTime, List<BurningProps> lightObjects)
        {
            var drawingGroup = new DrawingGroup();

            // Create a DrawingBrush.
            DrawingBrush myDrawingBrush = new DrawingBrush();

            // Create a drawing.
            GeometryDrawing myBlackDrawing = new GeometryDrawing();
            // myGeometryDrawing.Brush
            myBlackDrawing.Brush = Brushes.Black;
            myBlackDrawing.Pen = new Pen(Brushes.Black, 1);
            GeometryGroup rectangle = new GeometryGroup();
            rectangle.FillRule = FillRule.EvenOdd;
            rectangle.Children.Add(new RectangleGeometry(new System.Windows.Rect() { Height = _canvas.Height, Width = _canvas.Width }));

            GeometryGroup rectangle11 = new GeometryGroup();
            rectangle11.FillRule = FillRule.Nonzero;
            foreach (var lightObject in lightObjects)
            {
                rectangle11.Children.Add(
                    new EllipseGeometry(new System.Windows.Point(lightObject.Point.X + 10, lightObject.Point.Y + 10),
                        20 * lightObject.LightRadius, 20 * lightObject.LightRadius));
            }
            rectangle.Children.Add(rectangle11);
            var combined = new CombinedGeometry(GeometryCombineMode.Exclude, rectangle, rectangle11);
            myBlackDrawing.Geometry = combined;

            drawingGroup.Children.Add(myBlackDrawing);
            myDrawingBrush.Drawing = drawingGroup;
            Rectangle rec = new Rectangle()
            {
                Fill = myDrawingBrush,
                Stroke = Brushes.Black,
                Height = _canvas.Height,
                Width = _canvas.Width,
                Opacity = lightness,
                IsEnabled = false
            };

            _canvas.Children.Add(rec);
            Canvas.SetLeft(rec, 0);
            Canvas.SetTop(rec, 0);

            _ListBoxDateTime.Items.Clear();
            _ListBoxDateTime.Items.Add(string.Format("{0}:{1}:{2}", gameDateTime.Day, gameDateTime.Hour, gameDateTime.Minute));
        }
예제 #17
0
        private void ensureClip(Size layoutSlotSize)
        {
            Geometry clipGeometry = GetLayoutClip(layoutSlotSize);

            if(Clip != null)
            {
                if(clipGeometry == null)
                    clipGeometry = Clip;
                else
                {
                    CombinedGeometry cg = new CombinedGeometry(
                        GeometryCombineMode.Intersect,
                        clipGeometry,
                        Clip);

                    clipGeometry = cg;
                }
            }

            ChangeVisualClip(clipGeometry, true /* dontSetWhenClose */);
        }
예제 #18
0
 /// <summary>
 /// Draw background (with hole)
 /// </summary>
 /// <param name="dc"></param>
 private void DrawBackground(DrawingContext dc)
 {
     var rec = new RectangleGeometry(new Rect(0, 0, RenderSize.Width, RenderSize.Height));
     var hole = new EllipseGeometry(center, HoleRadius, HoleRadius);
     var geo = new CombinedGeometry(rec, hole) {
                                                  GeometryCombineMode = GeometryCombineMode.Exclude
                                              };
     dc.DrawGeometry(new SolidColorBrush(BackgroundColor), null, geo);
 }
예제 #19
0
        // TODO If the Line's use a Fill color, draw a hole in it
        // TODO Implement IsInteractive
        // TODO When a background color is specified, and the background is not Null, create a layer with a hole?

        protected override void OnRender(DrawingContext dc)
        {
            if (Children.Count < 1 || Ticks < 0) return;

            spokes = Children.Count;
            deltaAngle = 360D / spokes;
            center = new Point(RenderSize.Width / 2, RenderSize.Height / 2);
            radius = Math.Min(RenderSize.Width, RenderSize.Height) / 2;
            //dc.DrawEllipse(null, pen, center, radius, radius);

            // Draw the background ticks between minRadius and maxRadius
            var scale = Maximum - Minimum;
            minRadius = Math.Max(radius / scale, HoleRadius);
            maxRadius = radius * .8;
            deltaRadius = (maxRadius - minRadius);
            deltaTickRadius = deltaRadius / (Ticks - 1);
            spokeLength = maxRadius + 10;

            DrawBackground(dc);

            for (var i = HoleRadius > 0 ? 1 : 0; i < Ticks; i++)
            {
                var curRadius = minRadius + i*deltaTickRadius;
                var angle = 0D;
                var p1 = GetPoint(center, curRadius, angle);
                for (var j = 0; j < spokes; j++)
                {
                    angle = (j + 1)*deltaAngle;
                    var p2 = GetPoint(center, curRadius, angle);
                    dc.DrawLine(DashedPen, p1, p2);
                    p1 = p2;
                }
                // Draw the labels
                p1 = new Point(p1.X + 5, p1.Y - 15);
                if (i == 0)
                    dc.DrawText(new FormattedText(Minimum.ToString(CultureInfo.InvariantCulture), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, LabelFont, 14, Brushes.Black), p1);
                else if (i == Ticks - 1)
                    dc.DrawText(new FormattedText(Maximum.ToString(CultureInfo.InvariantCulture), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, LabelFont, 14, Brushes.Black), p1);
            }

            // Draw the spokes
            for (var i = 0; i < spokes; i++)
            {
                var angle = i * deltaAngle;
                var p1 = GetPoint(center, spokeLength, angle);
                var p2 = HoleRadius <= 0
                             ? center
                             : GetPoint(center, HoleRadius, angle);
                dc.DrawLine(Pen, p1, p2);
                if (IsInteractive)
                    dc.DrawLine(InvisiblePen, p1, p2);
            }

            // Draw the chart lines
            if (Lines == null) return;
            if (scale <= 0) return;
            
            foreach (var line in Lines)
            {
                if (line.PointDataSource.Any())
                {
                    var angle = 0D;
                    var curRadius = minRadius + (line.PointDataSource[0] - Minimum)*deltaRadius/scale;
                    var p1 = GetPoint(center, curRadius, angle);
                    var myPathFigure = new PathFigure
                                           {
                                               StartPoint = p1,
                                               Segments = new PathSegmentCollection()
                                           };
                    var pts = new PointCollection(spokes) {p1};
                    for (var j = 1; j < spokes; j++)
                    {
                        angle = j*deltaAngle;
                        curRadius = minRadius +
                                    ((j >= line.PointDataSource.Count ? Minimum : line.PointDataSource[j]) - Minimum)*
                                    deltaRadius/scale;
                        var p2 = GetPoint(center, curRadius, angle);
                        myPathFigure.Segments.Add(new LineSegment {Point = p2});
                        pts.Add(p2);
                    }
                    myPathFigure.Segments.Add(new LineSegment {Point = p1});
                    var myPathGeometry = new PathGeometry {Figures = new PathFigureCollection {myPathFigure}};
                    var pen = new Pen(new SolidColorBrush(line.LineColor), line.LineThickness);
                    //dc.DrawGeometry(line.FillColor == Colors.Transparent 
                    //    ? null 
                    //    : new SolidColorBrush(line.FillColor), pen, myPathGeometry);

                    if (HoleRadius > 0 || line.FillColor == Colors.Transparent)
                    {
                        var hole = new EllipseGeometry(center, HoleRadius, HoleRadius);
                        var geo = new CombinedGeometry(myPathGeometry, hole)
                                      {
                                          GeometryCombineMode = GeometryCombineMode.Exclude
                                      };
                        dc.DrawGeometry(new SolidColorBrush(line.FillColor), pen, geo);
                    }
                    else
                        dc.DrawGeometry(null, pen, myPathGeometry);

                    if (line.CanEdit)
                    {
                        // Draw fat circles on each data point
                        var brush = new SolidColorBrush(line.LineColor);
                        var pointRadius = IsInteractive
                            ? InteractivePointRadius
                            : line.LineThickness + 2;
                        foreach (var pt in pts)
                            dc.DrawEllipse(brush, pen, pt, pointRadius, pointRadius);
                    }
                }
            }
        }
예제 #20
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            winmain.Top = 0;
            winmain.Left = SystemParameters.PrimaryScreenWidth * .05;
            winmain.Width = SystemParameters.PrimaryScreenWidth * .75;
            winmain.Height = SystemParameters.PrimaryScreenHeight/2;

            winmain.RenderTransform = new TranslateTransform();
            MoveY(winmain, 0, -(int)winmain.Height, 0);

            winmain.Background = new SolidColorBrush(Color.FromArgb(0, 255, 255, 255));
            RTBWidth = winmain.Width * .8;
            RTBHeight = winmain.Height * .7;
            RTBTop = -winmain.Height * .25;
            RTBLeft = 20;
            txtCmdLineTop = winmain.Height * .525;
            txtErrorTop = winmain.Height * .70;
            txtShift = (int)RTBWidth;

            RectangleGeometry s = new RectangleGeometry(new Rect(new Point(RTBLeft, FrameTop+10), new Point(RTBLeft + RTBWidth, FrameTop + RTBHeight+40/*winmain.Height*/)),6,6);

            Geometry g = new CombinedGeometry(s, new RectangleGeometry(new Rect(new Point(RTBLeft, FrameTop + RTBHeight + 40), new Point(RTBLeft + RTBWidth / 2, FrameTop + RTBHeight + 100))));

            theGrid.Clip = g;

            FrameTop = winmain.Height * .025;
            WindowShowing = false;

            HistoryList = new List<String>();
            BeginLogic();
               InitBackground();
               InitOptions();
               if (InTutorialMode)
               {
               TutorialMode();
               LoadTutorialPages();
               ShowHide();
               }
               else
               {
               InitAllTextBoxes();
               RefreshContents(RTBIndex);

               }

               InitNextPrevTagTxtBox();
        }
예제 #21
0
        private static Rectangle CreateWorkflowViewMask(Grid grid)
        {
            Rectangle workflowViewMask = new Rectangle();
            double width = scrollViewer.ComputedVerticalScrollBarVisibility == Visibility.Visible ? workflowView.ActualWidth - SystemParameters.VerticalScrollBarWidth : workflowView.ActualWidth;
            double height = scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible ? workflowView.ActualHeight - SystemParameters.HorizontalScrollBarHeight : workflowView.ActualHeight;
            workflowViewMask.Width = width;
            workflowViewMask.Height = height;
            Rect background = new Rect(0, 0, workflowViewMask.Width, workflowViewMask.Height);
            backgroundBrush = new SolidColorBrush(SystemColors.AppWorkspaceColor);

            drawingBrush = new DrawingBrush();
            RectangleGeometry maskGeometry = new RectangleGeometry(background);
            selectedGeometry = new RectangleGeometry(new Rect());

            CombinedGeometry combinedGeometry = new CombinedGeometry(
                GeometryCombineMode.Exclude,
                maskGeometry,
                selectedGeometry);

            GeometryDrawing geometryDrawing = new GeometryDrawing(backgroundBrush, null, combinedGeometry);

            workflowViewMask.Opacity = OPACITY;
            drawingBrush.Drawing = geometryDrawing;
            workflowViewMask.Fill = drawingBrush;

            workflowViewMask.VerticalAlignment = VerticalAlignment.Top;
            workflowViewMask.HorizontalAlignment = HorizontalAlignment.Left;

            if (!grid.Children.Contains(workflowViewMask))
            {
                grid.Children.Add(workflowViewMask);
            }

            return workflowViewMask;
        }
예제 #22
0
 public void NextFrame(object sender, EventArgs e)
 {
     if (this._numberOfFrames != 0)
     {
         if (this._frameList[this._frameCounter].disposalMethod == 2)
         {
             for (int i = 0; i < this._frameCounter; i++)
             {
                 if (this._frameList[i].Visibility == Visibility.Visible)
                 {
                     GifFrame frame = this._frameList[this._frameCounter];
                     RectangleGeometry geometry = new RectangleGeometry(new Rect((double)frame.left, (double)frame.top, (double)frame.width, (double)frame.height));
                     this.totalTransparentGeometry = new CombinedGeometry(GeometryCombineMode.Union, this.totalTransparentGeometry, geometry);
                     GifFrame frame2 = this._frameList[i];
                     RectangleGeometry geometry2 = new RectangleGeometry(new Rect((double)frame2.left, (double)frame2.top, (double)frame2.width, (double)frame2.height));
                     CombinedGeometry geometry3 = new CombinedGeometry(GeometryCombineMode.Exclude, geometry2, this.totalTransparentGeometry);
                     GeometryDrawing drawing = new GeometryDrawing(Brushes.Black, new Pen(Brushes.Black, 0.0), geometry3);
                     DrawingBrush brush = new DrawingBrush(drawing);
                     this._frameList[i].OpacityMask = brush;
                 }
             }
             this._frameList[this._frameCounter].Visibility = Visibility.Hidden;
         }
         if (this._frameList[this._frameCounter].disposalMethod >= 3)
         {
             this._frameList[this._frameCounter].Visibility = Visibility.Hidden;
         }
         this._frameCounter++;
         if (this._frameCounter < this._numberOfFrames)
         {
             this._frameList[this._frameCounter].Visibility = Visibility.Visible;
             this.SetTimer(this._frameList[this._frameCounter].delayTime * 10);
         }
         else
         {
             if (this._numberOfLoops != 0)
             {
                 this._currentLoop++;
             }
             if ((this._currentLoop < this._numberOfLoops) || (this._numberOfLoops == 0))
             {
                 for (int j = 0; j < this._frameList.Count; j++)
                 {
                     this._frameList[j].Visibility = Visibility.Hidden;
                     this._frameList[j].OpacityMask = null;
                 }
                 this.totalTransparentGeometry = null;
                 this._frameCounter = 0;
                 this._frameList[this._frameCounter].Visibility = Visibility.Visible;
                 this.SetTimer(this._frameList[this._frameCounter].delayTime * 10);
             }
         }
         base.InvalidateVisual();
     }
 }
예제 #23
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.gridLayout = ((System.Windows.Controls.Grid)(target));
                return;

            case 2:
                this.canvasMain = ((System.Windows.Controls.Canvas)(target));
                return;

            case 3:
                this.inkCanvas = ((System.Windows.Controls.InkCanvas)(target));

            #line 40 "..\..\..\..\Views\Controls\ClipWindow.xaml"
                this.inkCanvas.StrokeCollected += new System.Windows.Controls.InkCanvasStrokeCollectedEventHandler(this.inkCanvas_StrokeCollected);

            #line default
            #line hidden
                return;

            case 4:
                this.rect = ((System.Windows.Shapes.Rectangle)(target));
                return;

            case 5:
                this.cbGeo = ((System.Windows.Media.CombinedGeometry)(target));
                return;

            case 6:
                this.rectFull = ((System.Windows.Media.RectangleGeometry)(target));
                return;

            case 7:
                this.rectClip = ((System.Windows.Media.RectangleGeometry)(target));
                return;

            case 8:
                this.bdThumb = ((System.Windows.Controls.Border)(target));
                return;

            case 9:
                this.gridmagnifier = ((System.Windows.Controls.Grid)(target));
                return;

            case 10:
                this.magnifierRectangle = ((System.Windows.Shapes.Rectangle)(target));
                return;

            case 11:
                this.visualBrush = ((System.Windows.Media.VisualBrush)(target));
                return;

            case 12:
                this.tbUnSelection = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 13:
                this.runSize0 = ((System.Windows.Documents.Run)(target));
                return;

            case 14:
                this.tbSelection = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 15:
                this.runSize = ((System.Windows.Documents.Run)(target));
                return;

            case 16:
                this.stkpMenu = ((System.Windows.Controls.StackPanel)(target));

            #line 100 "..\..\..\..\Views\Controls\ClipWindow.xaml"
                this.stkpMenu.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new System.Windows.RoutedEventHandler(this.stkpMenu_Click));

            #line default
            #line hidden
                return;

            case 17:
                this.tbtnPen = ((System.Windows.Controls.Primitives.ToggleButton)(target));
                return;

            case 18:
                this.rbtnBackout = ((System.Windows.Controls.Primitives.RepeatButton)(target));
                return;

            case 19:
                this.listSizes = ((System.Windows.Controls.ListBox)(target));

            #line 143 "..\..\..\..\Views\Controls\ClipWindow.xaml"
                this.listSizes.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.listSizes_SelectionChanged);

            #line default
            #line hidden
                return;

            case 20:
                this.listColors = ((System.Windows.Controls.ListBox)(target));

            #line 172 "..\..\..\..\Views\Controls\ClipWindow.xaml"
                this.listColors.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.listColors_SelectionChanged);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
예제 #24
0
		protected override IEnumerable<LowerTileInfo> GetLoadedLowerTiles(IEnumerable<VisibleTileInfo> visibleTiles)
		{
			var memoryCache = (LRUMemoryCache)TileSystem.MemoryServer;
			var sourceServer = TileSystem.SourceServer;

			var actualVisibleTiles = visibleTiles.Where(tile => sourceServer.Contains(tile.Tile)).ToList();

			var currLevel = TileProvider.Level;
			var upperLevel = GetAvailableUpperLevel(currLevel);
			var cache = (ICollection<TileIndex>)memoryCache.GetCachedIndexes();

			var region = GetRegion(actualVisibleTiles);

			var server = TileSystem;
			var lowerTiles = TileProvider.GetTilesForRegion(region, upperLevel).Where(tile => server.IsLoaded(tile));

			var plotterTransform = Plotter.Transform;

			var lowerTileList = new List<LowerTileInfo>();
			foreach (var lowerTile in lowerTiles)
			{
				bool addToLowerTiles = false;
				var bounds = TileProvider.GetTileBounds(lowerTile);
				var shiftedScreenBounds = bounds.ViewportToScreen(plotterTransform);

				Geometry clip = new RectangleGeometry(shiftedScreenBounds);
				foreach (var tile in actualVisibleTiles)
				{
					if (tile.VisibleBounds.IntersectsWith(bounds))
					{
						if (!cache.Contains(tile.Tile))
						{
							addToLowerTiles = true;
						}
						else
						{
							var screenBounds = tile.VisibleBounds.ViewportToScreen(plotterTransform);
							clip = new CombinedGeometry(GeometryCombineMode.Exclude, clip, new RectangleGeometry(screenBounds));
						}
					}
				}

				if (addToLowerTiles)
					lowerTileList.Add(new LowerTileInfo { Id = lowerTile, Clip = clip });
			}

			return lowerTileList;
		}
예제 #25
0
        /// <summary>
        /// Builds a geometry group for the given visual taking into account the transform, clip and enumerating the drawings.
        /// </summary>
        /// <param name="myVisual"></param>
        /// <param name="g"></param>
        private static void EnumVisual(Visual myVisual, GeometryGroup g)
        {
            GeometryGroup currentParent = g;
            Matrix m = GetVisualTransform(myVisual);
            MatrixTransform mt = new MatrixTransform();
            mt.Matrix = m;
            currentParent.Transform = mt;

            Geometry clip = VisualTreeHelper.GetClip(myVisual);
            if (clip != null)
            {
                CombinedGeometry combinedGeometry = new CombinedGeometry();
                combinedGeometry.GeometryCombineMode = GeometryCombineMode.Intersect;
                combinedGeometry.Geometry1 = clip;
                GeometryGroup child = new GeometryGroup();
                child.FillRule = FillRule.Nonzero;
                combinedGeometry.Geometry2 = child;
                currentParent.Children.Add(combinedGeometry);
                currentParent = (GeometryGroup)combinedGeometry.Geometry2;
            }

            DrawingGroup dg = VisualTreeHelper.GetDrawing(myVisual);
            if (dg != null)
            {
                if (dg.Transform != null)
                {
                    if (currentParent.Transform != null)
                    {
                        Matrix compositeTransform = new Matrix();
                        compositeTransform = Matrix.Multiply(currentParent.Transform.Value, dg.Transform.Value);
                        MatrixTransform matrixtransform = new MatrixTransform(compositeTransform);
                        currentParent.Transform = matrixtransform;
                    }
                    else
                    {
                        currentParent.Transform = dg.Transform;
                    }
                }

                if (dg.ClipGeometry != null)
                {
                    CombinedGeometry combinedGeometry = new CombinedGeometry();
                    combinedGeometry.GeometryCombineMode = GeometryCombineMode.Intersect;
                    combinedGeometry.Geometry1 = dg.ClipGeometry;
                    GeometryGroup child = new GeometryGroup();
                    child.FillRule = FillRule.Nonzero;
                    combinedGeometry.Geometry2 = child;
                    currentParent.Children.Add(combinedGeometry);
                    currentParent = (GeometryGroup)combinedGeometry.Geometry2;
                }
                EnumerateDrawingGroup(dg, currentParent);
            }
            WalkChildren(myVisual, currentParent);
        }
예제 #26
0
파일: WPFDrawer.cs 프로젝트: norniel/Game
        public void DrawShaddow(Engine.Point innerPoint, Engine.Size innerSize)
        {
            var drawingGroup = new DrawingGroup();

            // Create a DrawingBrush.
            DrawingBrush myDrawingBrush = new DrawingBrush();

            // Create a drawing.
            GeometryDrawing myBlackDrawing = new GeometryDrawing();
            // myGeometryDrawing.Brush
            myBlackDrawing.Brush = Brushes.Black;
            myBlackDrawing.Pen = new Pen(Brushes.Black, 1);
            GeometryGroup rectangle = new GeometryGroup();
            rectangle.FillRule = FillRule.EvenOdd;
            rectangle.Children.Add(new RectangleGeometry(new System.Windows.Rect() { Height = _canvas.Height, Width = _canvas.Width }));

            GeometryGroup rectangle11 = new GeometryGroup();
            rectangle11.FillRule = FillRule.Nonzero;

            rectangle11.Children.Add(
                    new RectangleGeometry(new System.Windows.Rect(new System.Windows.Point(innerPoint.X, innerPoint.Y),
                    new System.Windows.Size(innerSize.Width * 20, innerSize.Height*20))));

            rectangle.Children.Add(rectangle11);
            var combined = new CombinedGeometry(GeometryCombineMode.Exclude, rectangle, rectangle11);
            myBlackDrawing.Geometry = combined;

            drawingGroup.Children.Add(myBlackDrawing);
            myDrawingBrush.Drawing = drawingGroup;
            Rectangle rec = new Rectangle()
            {
                Fill = myDrawingBrush,
                Stroke = Brushes.Black,
                Height = _canvas.Height,
                Width = _canvas.Width,
                Opacity = 0.5,
                IsEnabled = false
            };

            _canvas.Children.Add(rec);
            Canvas.SetLeft(rec, 0);
            Canvas.SetTop(rec, 0);
        }
        public Geometry BuildGeometryForRange(TextCoordinate end1, TextCoordinate end2)
        {
            if (end1 == end2)
            {
                // No selection. Empty geometry.
                return Geometry.Empty;
            }

            Geometry resultGeometry;

            if (end1.Line == end2.Line)
            {
                int left = Math.Min(end1.Index, end2.Index);
                int right = Math.Max(end1.Index, end2.Index);

                var rect = new Rect(left * this.charWidth, end1.Line * this.lineHeight, (right - left) * this.charWidth, this.lineHeight);

                // Must inflate the rect just a bit -- otherwise, rounding issues cause incomplete union combinations (below -- even though this
                // particular rect won't ever be combined, we want it to have the same size when single-line).
                rect.Inflate(.5, .5);
                resultGeometry = new RectangleGeometry(rect);
            }
            else
            {
                var top = (end1.Line < end2.Line) ? end1 : end2;
                var bottom = (end1.Line < end2.Line) ? end2 : end1;

                var topRect = new Rect(top.Index * charWidth, top.Line * this.lineHeight, this.maxHorizontal + this.canvas.ActualWidth + 2, this.lineHeight);
                var midRect = new Rect(0, (top.Line + 1) * this.lineHeight, this.maxHorizontal + this.canvas.ActualWidth + 2, (bottom.Line - top.Line - 1) * this.lineHeight);
                var bottomRect = new Rect(0, bottom.Line * this.lineHeight, bottom.Index * this.charWidth, this.lineHeight);

                // Inflate to ensure overlap for correct union combination
                topRect.Inflate(.5, .5);
                midRect.Inflate(.5, .5);
                bottomRect.Inflate(.5, .5);
                var topGeometry = new RectangleGeometry(topRect);
                var bottomGeometry = new RectangleGeometry(bottomRect);

                if (top.Line == bottom.Line - 1)
                {
                    // Just top and bottom -- no lines between
                    resultGeometry = new CombinedGeometry(GeometryCombineMode.Union, topGeometry, bottomGeometry);
                }
                else
                {
                    // Two combinations for 3 geometries
                    var midGeometry = new RectangleGeometry(midRect);
                    var firstCombinedGeometry = new CombinedGeometry(GeometryCombineMode.Union, topGeometry, midGeometry);

                    resultGeometry = new CombinedGeometry(GeometryCombineMode.Union, firstCombinedGeometry, bottomGeometry);
                }
            }

            resultGeometry.Transform = this.highlightTransform;
            return resultGeometry;
        }
예제 #28
0
        public void NextFrame(object sender, EventArgs e)
        {
            frameTimer.Stop();
            if (_numberOfFrames == 0) return;
            if (_frameList[_frameCounter].disposalMethod == 2)
            {
                // dispose = background, tricky code to make transparent last frames region
                for (int fc = 0; fc < _frameCounter; fc++)
                {
                    if (_frameList[fc].Visibility == Visibility.Visible)
                    {
                        GifFrame gf = _frameList[_frameCounter];
                        RectangleGeometry rg2 = new RectangleGeometry(new Rect(gf.left, gf.top, gf.width, gf.height));
                        totalTransparentGeometry = new CombinedGeometry(GeometryCombineMode.Union, totalTransparentGeometry, rg2);

                        GifFrame gfBack = _frameList[fc];
                        RectangleGeometry rgBack = new RectangleGeometry(new Rect(gfBack.left, gfBack.top, gfBack.width, gfBack.height));
                        CombinedGeometry cg = new CombinedGeometry(GeometryCombineMode.Exclude, rgBack, totalTransparentGeometry);
                        GeometryDrawing gd = new GeometryDrawing(Brushes.Black, new Pen(Brushes.Black, 0), cg);
                        DrawingBrush db = new DrawingBrush(gd);
                        _frameList[fc].OpacityMask = db;
                    }
                }

                _frameList[_frameCounter].Visibility = Visibility.Hidden;
            }
            if (_frameList[_frameCounter].disposalMethod >= 3)
            {
                _frameList[_frameCounter].Visibility = Visibility.Hidden;
            }
            _frameCounter++;

            if (_frameCounter < _numberOfFrames)
            {
                _frameList[_frameCounter].Visibility = Visibility.Visible;
                frameTimer.Interval = new TimeSpan(0, 0, 0, 0, _frameList[_frameCounter].delayTime * 10);
                frameTimer.Start();
            }
            else
            {
                if (_numberOfLoops != 0)
                {
                    _currentLoop++;
                }
                if (_currentLoop < _numberOfLoops || _numberOfLoops == 0)
                {
                    for (int f = 0; f < _frameList.Count; f++)
                    {
                        _frameList[f].Visibility = Visibility.Hidden;
                        _frameList[f].OpacityMask = null;
                    }
                    totalTransparentGeometry = null;
                    _frameCounter = 0;
                    _frameList[_frameCounter].Visibility = Visibility.Visible;
                    frameTimer.Interval = new TimeSpan(0, 0, 0, 0, _frameList[_frameCounter].delayTime * 10);
                    frameTimer.Start();
                }
            }
        }
    TryCalculatePerVertexVertexOverlap
    (
        IGraph oGraphClone,
        BackgroundWorker oBackgroundWorker,
        Dictionary<IVertex, VertexInformation> oVertexInformations,
        out ICollection<GraphMetricValueWithID> oPerVertexVertexOverlap
    )
    {
        Debug.Assert(oGraphClone != null);
        Debug.Assert(oBackgroundWorker != null);
        Debug.Assert(oVertexInformations != null);
        AssertValid();

        LinkedList<GraphMetricValueWithID> oLinkedList =
            new LinkedList<GraphMetricValueWithID>();

        oPerVertexVertexOverlap = oLinkedList;
        Int32 iCalculationsCompleted = 0;

        foreach (IVertex oVertex in oGraphClone.Vertices)
        {
            if ( CancellationPending(oBackgroundWorker, iCalculationsCompleted,
                oGraphClone.Vertices.Count,
                "Calculating per-vertex vertex overlap.") )
            {
                return (false);
            }

            Int32 iRowID;

            if ( !TryGetRowID(oVertex, out iRowID) )
            {
                goto SkipCalculation;
            }

            VertexInformation oVertexInformation = oVertexInformations[oVertex];

            // Note: It was determined experimentally that using a
            // CombinedGeometry here is much faster than using a GeometryGroup.

            CombinedGeometry oUnionOfIntersectionsOfBounds =
                new CombinedGeometry();

            Rect oVertexRectangle = oVertexInformation.Bounds.Bounds;

            foreach (IVertex oOtherVertex in oGraphClone.Vertices)
            {
                if (oOtherVertex == oVertex)
                {
                    continue;
                }

                VertexInformation oOtherVertexInformation =
                    oVertexInformations[oOtherVertex];

                Rect oOtherVertexRectangle =
                    oOtherVertexInformation.Bounds.Bounds;

                if ( !oOtherVertexRectangle.IntersectsWith(oVertexRectangle) )
                {
                    // This is an optimization.  Ruling out vertices whose
                    // rectangular bounds don't intersect is much faster than
                    // intersecting their geometries.

                    continue;
                }

                CombinedGeometry oIntersectionOfBounds = new CombinedGeometry(
                    GeometryCombineMode.Intersect, oVertexInformation.Bounds,
                    oOtherVertexInformation.Bounds);

                oUnionOfIntersectionsOfBounds = new CombinedGeometry(
                    GeometryCombineMode.Union, oUnionOfIntersectionsOfBounds,
                    oIntersectionOfBounds);
            }

            Double dVertexOverlap = 1.0 -
                ( GetArea(oUnionOfIntersectionsOfBounds) /
                    GetArea(oVertexInformation.Bounds) );

            oLinkedList.AddLast( new GraphMetricValueWithID(
                iRowID, dVertexOverlap) );

            SkipCalculation:

            iCalculationsCompleted++;
        }

        return (true);
    }
예제 #30
0
        public static Drawing DrawCharacter(char ch, Typeface typeFace, double fontSize, GameColor color, GameColor bgColor,
			bool drawOutline, double outlineThickness, bool reverse, CharRenderMode mode)
        {
            Color c;
            if (color == GameColor.None)
                c = Colors.White;
            else
                c = color.ToWindowsColor();

            DrawingGroup dGroup = new DrawingGroup();
            var brush = new SolidColorBrush(c);
            var bgBrush = bgColor != GameColor.None ? new SolidColorBrush(bgColor.ToWindowsColor()) : Brushes.Transparent;
            using (DrawingContext dc = dGroup.Open())
            {
                var formattedText = new FormattedText(
                        ch.ToString(),
                        System.Globalization.CultureInfo.InvariantCulture,
                        FlowDirection.LeftToRight,
                        typeFace,
                        fontSize, Brushes.Black);

                var geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));
                var pen = drawOutline ? new Pen(Brushes.Black, outlineThickness) : null;
                var bounds = pen != null ? geometry.GetRenderBounds(pen) : geometry.Bounds;

                Rect bb;

                switch (mode)
                {
                    case CharRenderMode.Full:
                        {
                            double size = formattedText.Height;
                            bb = new Rect(bounds.X + bounds.Width / 2 - size / 2, 0, size, size);
                        }
                        break;

                    case CharRenderMode.Caps:
                        {
                            double size = typeFace.CapsHeight * fontSize;
                            bb = new Rect(bounds.X + bounds.Width / 2 - size / 2, formattedText.Baseline - size,
                                size, size);
                        }
                        break;

                    case CharRenderMode.Free:
                        bb = bounds;
                        break;

                    default:
                        throw new Exception();
                }

                if (reverse)
                    geometry = new CombinedGeometry(GeometryCombineMode.Exclude, new RectangleGeometry(bb), geometry);

                //dc.DrawRectangle(bgBrush, new Pen(Brushes.Red, 1), bb);
                dc.DrawRectangle(bgBrush, null, bb);

                dc.DrawGeometry(brush, pen, geometry);

                /*
                var dl = new Action<double>((y) =>
                    dc.DrawLine(new Pen(Brushes.Red, 1), new Point(bb.Left, y), new Point(bb.Right, y)));

                dl(0);
                dl(formattedText.Baseline);
                dl(fontSize);
                dl(formattedText.Height);
                dl(formattedText.Baseline - typeFace.CapsHeight * fontSize);
                */
            }

            return dGroup;
        }
예제 #31
0
        protected override void OnRender(DrawingContext dc)
        {
            //warning : много хаков!
            if (_diagram == null)
                return;

            Rect actualViewport = new Rect(0, 0, ActualWidth, ActualHeight);

            dc.DrawRectangle(Brushes.White, null, actualViewport);

            Rect boundaries = _diagram.Boundaries;
            Rect viewport = _diagram.Viewport;

            double scale;

            double scaleX = actualViewport.Width / boundaries.Width;
            double scaleY = actualViewport.Height / boundaries.Height;

            scale = scaleX > scaleY ? scaleY : scaleX;

            //прямоугольник с элементами
            Rect viewerBoundaries = new Rect(0, 0, boundaries.Width * scale, boundaries.Height * scale);
            dc.DrawRectangle(Brushes.White, GlobalData.BorderPen, viewerBoundaries);

            //вьюпорт
            Vector offset = new Vector(-boundaries.Left, -boundaries.Top);
            Rect viewerViewport = new Rect(viewport.TopLeft, viewport.BottomRight);
            viewerViewport.Offset(offset.X , offset.Y);
            viewerViewport.Scale(scale, scale);

            //пересекаем
            RectangleGeometry geometryBoundaries = new RectangleGeometry(viewerBoundaries);
            RectangleGeometry geometryViewport = new RectangleGeometry(viewerViewport);
            CombinedGeometry geometryCombined = new CombinedGeometry(GeometryCombineMode.Exclude,
                geometryBoundaries, geometryViewport);

            SolidColorBrush brush = new SolidColorBrush(Colors.LightGray);
            dc.PushOpacity(0.3);

            dc.DrawGeometry(brush, null, geometryCombined);

            dc.Pop();

            dc.PushTransform(new ScaleTransform(scale, scale));
            dc.PushTransform(new TranslateTransform(offset.X, offset.Y));

            _diagram.DrawItems(dc);

            dc.Pop();
            dc.Pop();
        }
예제 #32
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 4 "..\..\BookPage.xaml"
                ((WPFMitsuControls.BookPage)(target)).Loaded += new System.Windows.RoutedEventHandler(this.OnLoaded);

            #line default
            #line hidden
                return;

            case 2:
                this.mainGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 3:
                this.page2 = ((System.Windows.Controls.ContentPresenter)(target));
                return;

            case 4:
                this.nextPageShadowCanvas = ((System.Windows.Controls.Canvas)(target));
                return;

            case 5:
                this.nextPageShadow = ((System.Windows.Media.LinearGradientBrush)(target));
                return;

            case 6:
                this.nextPageShadowCanvasOffset1 = ((System.Windows.Media.GradientStop)(target));
                return;

            case 7:
                this.nextPageShadowCanvasOffset2 = ((System.Windows.Media.GradientStop)(target));
                return;

            case 8:
                this.clippingPage0 = ((System.Windows.Media.CombinedGeometry)(target));
                return;

            case 9:
                this.page0 = ((System.Windows.Controls.ContentPresenter)(target));
                return;

            case 10:
                this.gridShadow = ((System.Windows.Controls.Canvas)(target));
                return;

            case 11:
                this.pageShadow = ((System.Windows.Media.LinearGradientBrush)(target));
                return;

            case 12:
                this.rectangleVisible = ((System.Windows.Controls.Grid)(target));
                return;

            case 13:
                this.rectangleTranslate = ((System.Windows.Media.TranslateTransform)(target));
                return;

            case 14:
                this.rectangleRotate = ((System.Windows.Media.RotateTransform)(target));
                return;

            case 15:
                this.clippingFigure = ((System.Windows.Media.PathGeometry)(target));
                return;

            case 16:
                this.page1 = ((System.Windows.Controls.ContentPresenter)(target));
                return;

            case 17:
                this.canvasReflection = ((System.Windows.Controls.Canvas)(target));
                return;

            case 18:
                this.pageReflection = ((System.Windows.Media.LinearGradientBrush)(target));
                return;
            }
            this._contentLoaded = true;
        }
예제 #33
0
        /// <summary>
        /// test collision between two Geometry object
        /// </summary>
        /// <param name="firstGeometry">first Geometry</param>
        /// <param name="secondGeometry">second Geometry</param>
        /// <returns>intersection Points</returns>
        private Point[] collisionDetect(Geometry firstGeometry, Geometry secondGeometry)
        {
            Geometry firstPathGeometry = firstGeometry.GetWidenedPathGeometry(new Pen(Brushes.Black, 1.0)); //retrieve PathGeometry class, inherit from Geometry Class
            Geometry secondPathGeometry = secondGeometry.GetWidenedPathGeometry(new Pen(Brushes.Black, 1.0));

            CombinedGeometry combGeometry = new CombinedGeometry(GeometryCombineMode.Intersect, firstPathGeometry, secondPathGeometry); //inherit from Geometry
            PathGeometry combPathGeometry = combGeometry.GetFlattenedPathGeometry();

            /*code below retrieve all intersection points of 2 geometry*/
            //combPathGeometry.Figures rappresenta una serie di piccoli segmenti geometrici che compongono la geometria
            Point[] intersectionPoints = new Point[combPathGeometry.Figures.Count];
            //ho inizializzato un'array di punti, però bisogna ancora trovare le coordinate di ognuno di essi
            for (int i = 0; i < combPathGeometry.Figures.Count; i++)
            {
                //crea una piccola geometria a partire dal segmento trovato e ritorna il suo bounding box rettangolare
                Rect fig = new PathGeometry(new PathFigure[] { combPathGeometry.Figures[i] }).Bounds;
                //trova il punto centrale a partire da questo rettangolo
                intersectionPoints[i] = new Point(fig.Left + fig.Width / 2.0, fig.Top + fig.Height / 2.0);
            }
            return intersectionPoints;
        }
예제 #34
0
        private void image1_MouseMove(object sender, MouseEventArgs e)
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Send,
                new DispatcherOperationCallback(delegate(object p)
                {
                    if (crop && e.LeftButton == MouseButtonState.Pressed)
                    {
                        Point newPoint = e.GetPosition(image1);

                        DrawingGroup d = new DrawingGroup();
                        DrawingContext ctxt = d.Open();

                        Image source = e.Source as Image;

                        if (source == null)
                            return null;

                        //The difference between rendered and in-image coordinates
                        double widthFactor = source.Source.Width / source.ActualWidth;
                        double heightFactor = source.Source.Height / source.ActualHeight;

                        newPoint.X *= widthFactor;
                        newPoint.Y *= heightFactor;

                        tempCropData = new Rect(newPoint, cropPivot);

                        if (tempCropData.Left < 0 ||
                           tempCropData.Right > source.Source.Width ||
                           tempCropData.Top < 0 ||
                           tempCropData.Bottom > source.Source.Height)
                        {
                            return null;
                        }

                        Geometry geom1 = new RectangleGeometry(
                            new Rect(0, 0, source.Source.Width, source.Source.Height));
                        Geometry geom2 = new RectangleGeometry(tempCropData);

                        CombinedGeometry geom = new CombinedGeometry(geom1, geom2);
                        geom.GeometryCombineMode = GeometryCombineMode.Exclude;

                        Color fadedColor = Color.FromArgb(200, 0, 0, 0);
                        Pen dotted = new Pen(Brushes.Red, 1.5);

                        dotted.DashStyle = new DashStyle(new double[] { 4.0, 4.0 }, 0);

                        ctxt.DrawGeometry(new SolidColorBrush(fadedColor), null, geom);

                        //If the rect will cause the surface to resize, make it fit
                        Rect smallerRect = new Rect(tempCropData.Location, tempCropData.Size);

                        if (tempCropData.Left <= 2)
                        {
                            smallerRect.X = 2;
                        }

                        if (tempCropData.Right >= (source.Source.Width - 2))
                        {
                            smallerRect.Width = source.Source.Width - 2 - smallerRect.Left;
                        }

                        ctxt.DrawRectangle(null, dotted, smallerRect);

                        String str = Math.Round(tempCropData.Width).ToString(); ;
                        str += " , ";
                        str += Math.Round(tempCropData.Height).ToString();

                        FormattedText text = new FormattedText(str,
                            CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                            new Typeface("Arial"), 32, Brushes.White);

                        Point textOrigin = tempCropData.BottomRight;

                        textOrigin.X -= 150;
                        textOrigin.Y += 5;

                        bool drawText = true;

                        if (textOrigin.Y + text.Height > source.Source.Height)
                        {
                            textOrigin.Y = tempCropData.Top - text.Height - 5;

                            if (textOrigin.Y < 0)
                            {
                                drawText = false;
                            }
                        }

                        if (textOrigin.X < 0)
                        {
                            textOrigin.X = 0;
                        }

                        if (drawText)
                        {
                            ctxt.DrawText(text, textOrigin);
                        }

                        ctxt.Close();

                        image1_Surface.Source = new DrawingImage(d);
                    }

                    return null;
                }), null);
        }