override protected Rect GetBoundingRectangleCore()
        {
            PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner);

            // If there's no source, the element is not visible, return empty rect
            if (presentationSource == null)
            {
                return(Rect.Empty);
            }

            HwndSource hwndSource = presentationSource as HwndSource;

            // If the source isn't an HwnSource, there's not much we can do, return empty rect
            if (hwndSource == null)
            {
                return(Rect.Empty);
            }

            Rect rectElement = new Rect(new Point(0, 0), _owner.RenderSize);
            Rect rectRoot    = PointUtil.ElementToRoot(rectElement, _owner, presentationSource);
            Rect rectClient  = PointUtil.RootToClient(rectRoot, presentationSource);
            Rect rectScreen  = PointUtil.ClientToScreen(rectClient, hwndSource);

            return(rectScreen);
        }
        override protected Point GetClickablePointCore()
        {
            Point pt = new Point(double.NaN, double.NaN);

            PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner);

            // If there's no source, the element is not visible, return (double.NaN, double.NaN) point
            if (presentationSource == null)
            {
                return(pt);
            }

            HwndSource hwndSource = presentationSource as HwndSource;

            // If the source isn't an HwnSource, there's not much we can do, return (double.NaN, double.NaN) point
            if (hwndSource == null)
            {
                return(pt);
            }

            Rect rectElement = new Rect(new Point(0, 0), _owner.RenderSize);
            Rect rectRoot    = PointUtil.ElementToRoot(rectElement, _owner, presentationSource);
            Rect rectClient  = PointUtil.RootToClient(rectRoot, presentationSource);
            Rect rectScreen  = PointUtil.ClientToScreen(rectClient, hwndSource);

            pt = new Point(rectScreen.Left + rectScreen.Width * 0.5, rectScreen.Top + rectScreen.Height * 0.5);

            return(pt);
        }
Exemplo n.º 3
0
        public void SetPoints(IEnumerable <Point> pts)
        {
            if (pts == null)
            {
                return;
            }

            var r = PointUtil.CircumscribeRect(pts);

            _points.Clear();
            foreach (var pt in pts)
            {
                _points.Add(pt - (Size)r.Location);
            }

            if (_points.Count > 1)
            {
                Bounds = r;
            }
            else
            {
                Bounds = Rectangle.Empty;
            }
            InvalidatePaint();
        }
Exemplo n.º 4
0
        /////////////////////////////////////////////////////////////////////

        public void SimulateDrtPacket(HwndSource window, Point ptClient, bool fStylusDown)
        {
            Point ptScreen = PointUtil.ClientToScreen(ptClient, window);
            Point ptTablet = TabletPointFromScreenPoint(ptScreen);

            _wisptis.SimulatePacketWithButton("HidDrt", (int)ptTablet.X, (int)ptTablet.Y, fStylusDown, /*fButtonDown*/ false);
        }
Exemplo n.º 5
0
        protected override Rect GetBoundingRectangleCore()
        {
            TextElement textElement = (TextElement)base.Owner;
            ITextView   textView    = textElement.TextContainer.TextView;

            if (textView == null || !textView.IsValid)
            {
                return(Rect.Empty);
            }
            Geometry tightBoundingGeometryFromTextPositions = textView.GetTightBoundingGeometryFromTextPositions(textElement.ContentStart, textElement.ContentEnd);

            if (tightBoundingGeometryFromTextPositions == null)
            {
                return(Rect.Empty);
            }
            PresentationSource presentationSource = PresentationSource.CriticalFromVisual(textView.RenderScope);

            if (presentationSource == null)
            {
                return(Rect.Empty);
            }
            HwndSource hwndSource = presentationSource as HwndSource;

            if (hwndSource == null)
            {
                return(Rect.Empty);
            }
            Rect bounds     = tightBoundingGeometryFromTextPositions.Bounds;
            Rect rectRoot   = PointUtil.ElementToRoot(bounds, textView.RenderScope, presentationSource);
            Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource);

            return(PointUtil.ClientToScreen(rectClient, hwndSource));
        }
Exemplo n.º 6
0
            /// <summary>
            /// 外枠との交点を求める.
            /// 複数の交点がある場合,line.Startに最も近い点を返す.
            /// </summary>
            public virtual Point GetIntersectionPoint(Line line)
            {
                /// 単純にBoundsの矩形との交点を求める

                var lLine = _owner.LeftLine;
                var tLine = _owner.TopLine;
                var rLine = _owner.RightLine;
                var bLine = _owner.BottomLine;

                var pts = new List <Point>(4);

                if (line.IntersectsWith(lLine))
                {
                    pts.Add(line.GetIntersectionPoint(lLine));
                }
                if (line.IntersectsWith(tLine))
                {
                    pts.Add(line.GetIntersectionPoint(tLine));
                }
                if (line.IntersectsWith(rLine))
                {
                    pts.Add(line.GetIntersectionPoint(rLine));
                }
                if (line.IntersectsWith(bLine))
                {
                    pts.Add(line.GetIntersectionPoint(bLine));
                }

                return(pts.Count == 0? Point.Empty: pts.FindMin(pt => (int)PointUtil.GetDistance(line.Start, pt)));
            }
Exemplo n.º 7
0
 public void MoveChild(Point move)
 {
     foreach (Control c in Parent.Controls)
     {
         c.Location = PointUtil.Plus(c.Location, move);
     }
 }
        public Point GetOffset(Point mousePoint)
        {
            var smp = PointToScreen(mousePoint);
            var cp  = Parent.PointToScreen(Location);

            return(PointUtil.Minus(smp, cp));
        }
Exemplo n.º 9
0
        private void makeDoor(int idx, bool isDoor)
        {
            GlobalEvent.OnDocumentChangeBefore(Canvas.instance.GetCurrent(), "add door");
            if (isVertical)
            {
                loc.X = 2;
            }
            else
            {
                loc.Y = 2;
            }

            Point newLoc = PointUtil.Plus(this.Location, loc);

            if (isVertical && newLoc.Y + 50 > this.Bottom)
            {
                return;
            }

            if (!isVertical && newLoc.X + 50 > this.Right)
            {
                return;
            }

            Door temp = new Door();

            temp.pA     = newLoc;
            temp.kind   = idx;
            temp.isDoor = isDoor;

            Canvas.instance.MakeDoor(temp);
            Canvas.instance.BindDoorToRoom();

            GlobalEvent.OnDocumentChangeAfter(Canvas.instance.GetCurrent(), "add door");
        }
Exemplo n.º 10
0
        public override void PointerMove(object sender, MouseEventArgs e)
        {
            if (isClick)
            {
                Point dPoint = PointUtil.Minus(PointToScreen(e.Location), mouse0);
                //Console.WriteLine("delta : " + dPoint.X + ", " + dPoint.Y);
                //Console.WriteLine("room : " + thisRoom.Location.X + ", " + thisRoom.Location.Y);
                switch (where)
                {
                case Where.leftbottom:
                    thisRoom.Location = new Point(location0.X + dPoint.X, location0.Y);
                    thisRoom.Size     = new Size(size0.Width - dPoint.X, size0.Height + dPoint.Y);
                    break;

                case Where.lefttop:
                    thisRoom.Location = PointUtil.Plus(location0, dPoint);
                    thisRoom.Size     = new Size(PointUtil.Minus(new Point(size0), dPoint));
                    break;

                case Where.rightbottom:
                    thisRoom.Size = new Size(PointUtil.Plus(new Point(size0), dPoint));
                    break;

                case Where.righttop:
                    thisRoom.Location = new Point(location0.X, location0.Y + dPoint.Y);
                    thisRoom.Size     = new Size(size0.Width + dPoint.X, size0.Height - dPoint.Y);
                    break;

                default:
                    break;
                }
                thisRoom.UpdateScalerPosition();
            }
        }
Exemplo n.º 11
0
    public static void Rotate(IEnumerable <BaseShapeViewModel> shapes, decimal angle, IHistory?history)
    {
        var groupBox = new GroupBox(shapes.ToList());

        if (groupBox.Boxes.Length <= 0)
        {
            return;
        }

        var boxes = groupBox.Boxes.ToList();

        var previous = new List <(PointShapeViewModel point, decimal x, decimal y)>();
        var next     = new List <(PointShapeViewModel point, decimal x, decimal y)>();

        var radians = angle * (decimal)Math.PI / 180m;
        var centerX = groupBox.Bounds.CenterX;
        var centerY = groupBox.Bounds.CenterY;

        foreach (var point in boxes.SelectMany(box => box.Points).Distinct())
        {
            PointUtil.Rotate(point, radians, centerX, centerY, out var x, out var y);
            previous.Add((point, (decimal)point.X, (decimal)point.Y));
            next.Add((point, x, y));
            point.X = (double)x;
            point.Y = (double)y;
        }

        history?.Snapshot(previous, next, (p) => previous.ForEach(p =>
        {
            p.point.X = (double)p.x;
            p.point.Y = (double)p.y;
        }));
    }
        internal override Rect GetVisibleBoundingRectCore()
        {
            PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner);

            // If there's no source, the element is not visible, return empty rect
            if (presentationSource == null)
            {
                return(Rect.Empty);
            }

            HwndSource hwndSource = presentationSource as HwndSource;

            // If the source isn't an HwnSource, there's not much we can do, return empty rect
            if (hwndSource == null)
            {
                return(Rect.Empty);
            }

            Rect rectElement = CalculateVisibleBoundingRect(_owner);
            Rect rectRoot    = PointUtil.ElementToRoot(rectElement, _owner, presentationSource);
            Rect rectClient  = PointUtil.RootToClient(rectRoot, presentationSource);
            Rect rectScreen  = PointUtil.ClientToScreen(rectClient, hwndSource);

            return(rectScreen);
        }
Exemplo n.º 13
0
        public void UpdateWindowPos()
        {
            if (this._isDisposed)
            {
                return;
            }
            PresentationSource presentationSource = null;
            CompositionTarget  compositionTarget  = null;

            if (this.CriticalHandle != IntPtr.Zero && base.IsVisible)
            {
                presentationSource = PresentationSource.CriticalFromVisual(this, false);
                if (presentationSource != null)
                {
                    compositionTarget = presentationSource.CompositionTarget;
                }
            }
            if (compositionTarget != null && compositionTarget.RootVisual != null)
            {
                NativeMethods.RECT rc = this.CalculateAssignedRC(presentationSource);
                Rect rcBoundingBox    = PointUtil.ToRect(rc);
                this.OnWindowPositionChanged(rcBoundingBox);
                UnsafeNativeMethods.ShowWindowAsync(this._hwnd, 5);
                return;
            }
            UnsafeNativeMethods.ShowWindowAsync(this._hwnd, 0);
        }
Exemplo n.º 14
0
        private bool ComputeBoundingRectangle(out Rect rect)
        {
            rect = Rect.Empty;

            PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner);

            // If there's no source, the element is not visible, return empty rect
            if (presentationSource == null)
            {
                return(false);
            }

            HwndSource hwndSource = presentationSource as HwndSource;

            // If the source isn't an HwndSource, there's not much we can do, return empty rect
            if (hwndSource == null)
            {
                return(false);
            }

            Rect rectElement = _owner.Visual2DContentBounds;
            // we use VisualTreeHelper.GetContainingVisual2D to transform from the containing Viewport3DVisual
            Rect rectRoot   = PointUtil.ElementToRoot(rectElement, VisualTreeHelper.GetContainingVisual2D(_owner), presentationSource);
            Rect rectClient = PointUtil.RootToClient(rectRoot, presentationSource);

            rect = PointUtil.ClientToScreen(rectClient, hwndSource);

            return(true);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Move the mouse to the specified position within the given element.  x and y are
        /// coordinates within the element, (0,0) is upper left, (1,1) is lower right.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public bool MoveMouse(UIElement target, double x, double y)
        {
            // This code is paraphrased from Popup.cs.

            PresentationSource source = PresentationSource.FromVisual(target);
            if (source == null) return false;

            // Transform (0,0) from the target element up to the root.
            Point ptTarget = new Point(0,0);
            GeneralTransform transform;
            try
            {
                transform = target.TransformToAncestor(source.RootVisual);
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine( "  MoveMouse to ({0},{1}) of {2} failed",
                                   x, y, Identify( target ) );
                // if visuals are not connected...
                return false;
            }
            Point ptRoot;
            transform.TryTransform(ptTarget, out ptRoot);
            Point ptClient = PointUtil.RootToClient(ptRoot, source);
            Point ptScreen = PointUtil.ClientToScreen(ptClient, source);
            
            // Get the width of the target element in pixels.
            Point size = source.CompositionTarget.TransformToDevice.Transform(new Point(target.RenderSize.Width, target.RenderSize.Height));

            Point moveToPoint = new Point(ptScreen.X + size.X * x, ptScreen.Y + size.Y * y);

            MoveMouse( moveToPoint );

            return true;
        }
Exemplo n.º 16
0
        internal override void Synchronize()
        {
            // Simulate a stylus move (if we are current stylus, inrange, visuals still valid to update
            // and has moved).
            if (InRange && _inputSource != null && _inputSource.Value != null &&
                _inputSource.Value.CompositionTarget != null && !_inputSource.Value.CompositionTarget.IsDisposed)
            {
                Point rawScreenPoint = new Point(_pointerData.Info.ptPixelLocationRaw.X, _pointerData.Info.ptPixelLocationRaw.Y);
                Point ptDevice       = PointUtil.ScreenToClient(rawScreenPoint, _inputSource.Value);

                // GlobalHitTest always returns an IInputElement, so we are sure to have one.
                IInputElement stylusOver     = Input.StylusDevice.GlobalHitTest(_inputSource.Value, ptDevice);
                bool          fOffsetChanged = false;

                if (_stylusOver == stylusOver)
                {
                    Point ptOffset = GetPosition(stylusOver);
                    fOffsetChanged = MS.Internal.DoubleUtil.AreClose(ptOffset.X, _rawElementRelativePosition.X) == false || MS.Internal.DoubleUtil.AreClose(ptOffset.Y, _rawElementRelativePosition.Y) == false;
                }

                if (fOffsetChanged || _stylusOver != stylusOver)
                {
                    int timeStamp = Environment.TickCount;

                    if (_currentStylusPoints != null &&
                        _currentStylusPoints.Count > 0 &&
                        StylusPointDescription.AreCompatible(PointerTabletDevice.StylusPointDescription, _currentStylusPoints.Description))
                    {
                        StylusPoint stylusPoint = _currentStylusPoints[_currentStylusPoints.Count - 1];
                        int[]       data        = stylusPoint.GetPacketData();

                        // get back to the correct coordinate system
                        Matrix m = _tabletDevice.TabletToScreen;
                        m.Invert();
                        Point ptTablet = ptDevice * m;

                        data[0] = (int)ptTablet.X;
                        data[1] = (int)ptTablet.Y;

                        RawStylusInputReport report = new RawStylusInputReport(InputMode.Foreground,
                                                                               timeStamp,
                                                                               _inputSource.Value,
                                                                               InAir ? RawStylusActions.InAirMove : RawStylusActions.Move,
                                                                               () => { return(PointerTabletDevice.StylusPointDescription); },
                                                                               TabletDevice.Id,
                                                                               Id,
                                                                               data);


                        report.Synchronized = true;

                        InputReportEventArgs inputReportEventArgs = new InputReportEventArgs(StylusDevice, report);
                        inputReportEventArgs.RoutedEvent = InputManager.PreviewInputReportEvent;

                        InputManager.Current.ProcessInput(inputReportEventArgs);
                    }
                }
            }
        }
Exemplo n.º 17
0
        public void PointDivisionFloat()
        {
            var a = new Point <float>(1, 1);
            var b = new Point <float>(2, 2);

            Assert.AreEqual(PointUtil.Divide(a, b), new Point <float>(.5f, .5f));
            Assert.AreEqual(PointUtil.Divide(a, 2), new Point <float>(.5f, .5f));
        }
Exemplo n.º 18
0
        public void PointDivisionInt()
        {
            var a = new Point <int>(4, 4);
            var b = new Point <int>(2, 2);

            Assert.AreEqual(PointUtil.Divide(a, b), new Point <int>(2, 2));
            Assert.AreEqual(PointUtil.Divide(a, 2), new Point <int>(2, 2));
        }
Exemplo n.º 19
0
        public void PointMultiplicationFloat()
        {
            var a = new Point <float>(.2f, .2f);
            var b = new Point <float>(4, 4);

            Assert.AreEqual(PointUtil.Multiply(a, b), new Point <float>(.8f, .8f));
            Assert.AreEqual(PointUtil.Multiply(a, 4), new Point <float>(.8f, .8f));
        }
Exemplo n.º 20
0
        public void PointMultiplicationInt()
        {
            var a = new Point <int>(2, 2);
            var b = new Point <int>(4, 4);

            Assert.AreEqual(PointUtil.Multiply(a, b), new Point <int>(8, 8));
            Assert.AreEqual(PointUtil.Multiply(b, 2), new Point <int>(8, 8));
        }
Exemplo n.º 21
0
        public void PointSubtractionFloat()
        {
            var a = new Point <float>(.1f, .1f);
            var b = new Point <float>(.2f, .2f);

            Assert.AreEqual(PointUtil.Subtract(a, b), new Point <float>(-.1f, -.1f));
            Assert.AreEqual(PointUtil.Subtract(a, .2f), new Point <float>(-.1f, -.1f));
        }
Exemplo n.º 22
0
        public void PointSubtractionInt()
        {
            var a = new Point <int>(1, 1);
            var b = new Point <int>(2, 2);

            Assert.AreEqual(PointUtil.Subtract(a, b), new Point <int>(-1, -1));
            Assert.AreEqual(PointUtil.Subtract(a, 2), new Point <int>(-1, -1));
        }
Exemplo n.º 23
0
        public void PointAdditionInt()
        {
            var a = new Point <int>(1, 1);
            var b = new Point <int>(2, 2);

            Assert.AreEqual(PointUtil.Add(a, b), new Point <int>(3, 3));
            Assert.AreEqual(PointUtil.Add(a, 2), new Point <int>(3, 3));
        }
Exemplo n.º 24
0
        public void PointAdditionFloat()
        {
            var a = new Point <float>(.1f, .1f);
            var b = new Point <float>(.2f, .2f);

            Assert.AreEqual(PointUtil.Add(a, b), new Point <float>(.3f, .3f));
            Assert.AreEqual(PointUtil.Add(a, .2f), new Point <float>(.3f, .3f));
        }
Exemplo n.º 25
0
        public override void Scale(SizeF scale)
        {
            var pts = new Point[] { Point1, Point2, };

            PointUtil.ScaleWithCircumscribeRect(pts, scale);
            Point1 = pts[0];
            Point2 = pts[1];
        }
Exemplo n.º 26
0
        /////////////////////////////////////////////////////////////////////
        public void SimulateLeftDoubleClick(HwndSource window, Point ptClient)
        {
            Point ptScreen = PointUtil.ClientToScreen(ptClient, window);

            Input.SendMouseInput(ptScreen.X, ptScreen.Y, 0, SendMouseInputFlags.LeftDown);
            Input.SendMouseInput(ptScreen.X, ptScreen.Y, 0, SendMouseInputFlags.LeftUp);
            Input.SendMouseInput(ptScreen.X, ptScreen.Y, 0, SendMouseInputFlags.LeftDown);
            Input.SendMouseInput(ptScreen.X, ptScreen.Y, 0, SendMouseInputFlags.LeftUp);
        }
Exemplo n.º 27
0
        public void FindShouldFind()
        {
            var layer = new Layer <int>(PointUtil.Subtract(PointUtil.zero, 5), PointUtil.Add(PointUtil.zero, 5));

            layer.Set(-5, -5, 2112);
            layer.Set(4, 4, 2113);

            Assert.AreEqual(new Point <int>(-5, -5), layer.Find(2112));
        }
Exemplo n.º 28
0
        //三角形の高さ (底辺p12からp3までの高さ)
        public static float getTriangleHeight(LDPoint p1, LDPoint p2, LDPoint p3)
        {
            LDPoint ab = p2 - p1;
            LDPoint ac = p3 - p1;
            float   D  = Math.Abs(ab.x() * ac.y() - ab.y() * ac.x());
            float   L  = PointUtil.distance(p1, p2);
            float   H  = D / L;

            return(H);
        }
Exemplo n.º 29
0
        public void WidthAndHeightConstructorShouldSetMinMaxSizeCorrectly()
        {
            const int width  = 9;
            const int height = 8;
            var       layer  = new Layer <int>(width, height);

            Assert.AreEqual(new Point <int>(0, 0), layer.min);
            Assert.AreEqual(new Point <int>(width, height), PointUtil.Add(layer.max, 1));
            Assert.AreEqual(new Point <int>(width, height), layer.size);
        }
Exemplo n.º 30
0
            internal Rect GetWindowRect()
            {
                NativeMethods.RECT rect = new NativeMethods.RECT(0, 0, 0, 0);

                if (IsWindowAlive())
                {
                    SafeNativeMethods.GetWindowRect(_window.CreateHandleRef(), ref rect);
                }

                return(PointUtil.ToRect(rect));
            }