コード例 #1
0
        public IEnumerator <object> Task()
        {
            while (true)
            {
                if (!SceneView.Instance.InputArea.IsMouseOverThisOrDescendant())
                {
                    yield return(null);

                    continue;
                }
                var selectedPointObjects = Document.Current.SelectedNodes().Editable().OfType <PointObject>().ToList();
                if (selectedPointObjects.Count() > 1)
                {
                    Utils.CalcHullAndPivot(selectedPointObjects, out var hull, out _);
                    hull = hull.Transform(Document.Current.Container.AsWidget.LocalToWorldTransform);
                    var expandedBoundsInSceneCoords = PointObjectsPresenter.ExpandAndTranslateToSpaceOf(hull, Document.Current.Container.AsWidget, sv) *
                                                      sv.Frame.CalcTransitionToSpaceOf(sv.Scene);
                    for (var i = 0; i < 4; i++)
                    {
                        if (sv.HitTestControlPoint(expandedBoundsInSceneCoords[i]))
                        {
                            Utils.ChangeCursorIfDefault(Cursors.Rotate);
                            if (sv.Input.ConsumeKeyPress(Key.Mouse0))
                            {
                                yield return(Rotate(hull, selectedPointObjects));
                            }
                        }
                    }
                }
                yield return(null);
            }
        }
コード例 #2
0
        public IEnumerator <object> Task()
        {
            while (true)
            {
                if (!SceneView.Instance.InputArea.IsMouseOverThisOrDescendant())
                {
                    yield return(null);

                    continue;
                }
                var points = Document.Current.SelectedNodes().Editable().OfType <PointObject>().ToList();
                if (points.Count > 1)
                {
                    Rectangle aabb;
                    Utils.CalcAABB(points, Document.Current.Container.AsWidget, out aabb);
                    var hull     = aabb.ToQuadrangle();
                    var hullSize = hull.V3 - hull.V1;
                    hullNormalized = hull * Matrix32.Scaling(Vector2.One / Document.Current.Container.AsWidget.Size);
                    var expandedHullInSceneCoords = PointObjectsPresenter.ExpandAndTranslateToSpaceOf(hull, Document.Current.Container.AsWidget, sv.Frame) *
                                                    sv.Frame.CalcTransitionToSpaceOf(sv.Scene);
                    for (int i = 0; i < 4; i++)
                    {
                        if (Mathf.Abs(hullSize.X) > Mathf.ZeroTolerance && Mathf.Abs(hullSize.Y) > Mathf.ZeroTolerance)
                        {
                            if (sv.HitTestResizeControlPoint(expandedHullInSceneCoords[i]))
                            {
                                Utils.ChangeCursorIfDefault(MouseCursor.SizeNS);
                                if (sv.Input.ConsumeKeyPress(Key.Mouse0))
                                {
                                    yield return(Rescale(i * 2, MouseCursor.SizeNS, points));
                                }
                            }
                        }
                    }
                    for (int i = 0; i < 4; i++)
                    {
                        if (Mathf.Abs(hullSize.X) < Mathf.ZeroTolerance && i % 2 == 1 ||
                            Mathf.Abs(hullSize.Y) < Mathf.ZeroTolerance && i % 2 == 0
                            )
                        {
                            continue;
                        }
                        var a = expandedHullInSceneCoords[i];
                        var b = expandedHullInSceneCoords[(i + 1) % 4];
                        if (sv.HitTestResizeControlPoint((a + b) / 2))
                        {
                            var cursor = MouseCursor.Default;
                            if (Mathf.Abs(hullSize.X) < Mathf.ZeroTolerance)
                            {
                                cursor = MouseCursor.SizeNS;
                            }
                            else if (Mathf.Abs(hullSize.Y) < Mathf.ZeroTolerance)
                            {
                                cursor = MouseCursor.SizeWE;
                            }
                            else
                            {
                                cursor = (b.X - a.X).Abs() > (b.Y - a.Y).Abs() ? MouseCursor.SizeNS : MouseCursor.SizeWE;
                            }
                            Utils.ChangeCursorIfDefault(cursor);
                            if (sv.Input.ConsumeKeyPress(Key.Mouse0))
                            {
                                yield return(Rescale(i * 2 + 1, cursor, points));
                            }
                        }
                    }
                }
                yield return(null);
            }
        }