コード例 #1
0
        void RescaleWidgets(Quadrangle originalHull, bool hullInFirstWidgetSpace, Vector2 hullsPivotPoint, List <Widget> widgets, int controlPointIndex,
                            Vector2 curMousePos, Vector2 prevMousePos, bool proportional)
        {
            Utils.ApplyTransformationToWidgetsGroupOobb(
                sv.Scene,
                widgets, hullsPivotPoint, hullInFirstWidgetSpace, curMousePos, prevMousePos,
                (originalVectorInOobbSpace, deformedVectorInOobbSpace) => {
                Vector2 deformationScaleInOobbSpace =
                    new Vector2(
                        Math.Abs(originalVectorInOobbSpace.X) < Mathf.ZeroTolerance
                                                                        ? 1
                                                                        : deformedVectorInOobbSpace.X / originalVectorInOobbSpace.X,
                        Math.Abs(originalVectorInOobbSpace.Y) < Mathf.ZeroTolerance
                                                                        ? 1
                                                                        : deformedVectorInOobbSpace.Y / originalVectorInOobbSpace.Y
                        );
                if (proportional)
                {
                    deformationScaleInOobbSpace.X = (deformationScaleInOobbSpace.X + deformationScaleInOobbSpace.Y) / 2;
                    deformationScaleInOobbSpace.Y = deformationScaleInOobbSpace.X;
                }

                if (!LookupInvolvedAxes[controlPointIndex][0])
                {
                    deformationScaleInOobbSpace.X = proportional ? deformationScaleInOobbSpace.Y : 1;
                }
                if (!LookupInvolvedAxes[controlPointIndex][1])
                {
                    deformationScaleInOobbSpace.Y = proportional ? deformationScaleInOobbSpace.X : 1;
                }

                return(Matrix32.Scaling(deformationScaleInOobbSpace));
            }
                );
        }
コード例 #2
0
ファイル: Application.cs プロジェクト: aologos/Citrus
        private static void SetupViewportAndProjectionMatrix()
        {
            Renderer.SetOrthogonalProjection(0, 0, The.World.Width, The.World.Height);
            var windowSize = The.Window.ClientSize;

            The.Window.Input.MousePositionTransform = Matrix32.Scaling(The.World.Width / windowSize.X,
                                                                       The.World.Height / windowSize.Y);
        }
コード例 #3
0
ファイル: RectangleTests.cs プロジェクト: aologos/Citrus
        public void TransformTest()
        {
            var rectangle = new Rectangle(Vector2.Zero, Vector2.One);

            rectangle = rectangle.Transform(Matrix32.Scaling(Vector2.Half));
            var expectedRectangle = new Rectangle(Vector2.Zero, Vector2.Half);

            Assert.That(rectangle, Is.EqualTo(expectedRectangle));
        }
コード例 #4
0
        IEnumerator <object> Rotate(Quadrangle hull, List <PointObject> points)
        {
            using (Document.Current.History.BeginTransaction()) {
                var t = Document.Current.Container.AsWidget.LocalToWorldTransform.CalcInversed();
                hull *= Matrix32.Scaling(Vector2.One / Document.Current.Container.AsWidget.Size);
                var center          = (hull.V1 + hull.V3) / 2;
                var size            = Document.Current.Container.AsWidget.Size;
                var mousePosInitial = (sv.MousePosition * t - center * size) / size;
                var rotation        = 0f;
                while (sv.Input.IsMousePressed())
                {
                    Document.Current.History.RollbackTransaction();
                    Utils.ChangeCursorIfDefault(Cursors.Rotate);
                    var b     = (sv.MousePosition * t - center * size) / size;
                    var angle = 0f;
                    if (mousePosInitial.Length > Mathf.ZeroTolerance && b.Length > Mathf.ZeroTolerance)
                    {
                        angle    = Mathf.Wrap180(b.Atan2Deg - mousePosInitial.Atan2Deg);
                        rotation = angle;
                    }
                    if (Math.Abs(angle) > Mathf.ZeroTolerance)
                    {
                        var        effectiveAngle = sv.Input.IsKeyPressed(Key.Shift) ? Utils.RoundTo(rotation, 15) : angle;
                        Quadrangle newBounds      = new Quadrangle();
                        for (int i = 0; i < 4; i++)
                        {
                            newBounds[i] = Vector2.RotateDeg(hull[i] - center, effectiveAngle) + center;
                        }
                        for (var i = 0; i < points.Count; i++)
                        {
                            var offset   = center - points[i].Offset / size;
                            var position = Vector2.RotateDeg((points[i].Position - offset), effectiveAngle) + offset;
                            Core.Operations.SetAnimableProperty.Perform(points[i], nameof(PointObject.Position), position, CoreUserPreferences.Instance.AutoKeyframes);
                            if (points[i] is SplinePoint)
                            {
                                Core.Operations.SetAnimableProperty.Perform(
                                    points[i],
                                    nameof(SplinePoint.TangentAngle),
                                    (points[i] as SplinePoint).TangentAngle - effectiveAngle,
                                    CoreUserPreferences.Instance.AutoKeyframes
                                    );
                            }
                        }
                    }

                    yield return(null);
                }
                sv.Input.ConsumeKey(Key.Mouse0);
                Window.Current.Invalidate();
                Document.Current.History.CommitTransaction();
            }
        }
コード例 #5
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);
            }
        }