当前位置: 首页>>代码示例>>C#>>正文


C# Viewport2D.Flatten方法代码示例

本文整理汇总了C#中Sledge.UI.Viewport2D.Flatten方法的典型用法代码示例。如果您正苦于以下问题:C# Viewport2D.Flatten方法的具体用法?C# Viewport2D.Flatten怎么用?C# Viewport2D.Flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sledge.UI.Viewport2D的用法示例。


在下文中一共展示了Viewport2D.Flatten方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTransformationMatrix

        public override Matrix4? GetTransformationMatrix(Viewport2D viewport, ViewportEvent e, BaseBoxTool.BoxState state, Document doc, IEnumerable<Widget> activeWidgets)
        {
            var origin = viewport.ZeroUnusedCoordinate((state.PreTransformBoxStart + state.PreTransformBoxEnd) / 2);
            var rw = activeWidgets.OfType<RotationWidget>().FirstOrDefault();
            if (rw != null) origin = rw.GetPivotPoint();

            var forigin = viewport.Flatten(origin);

            var origv = (state.MoveStart - forigin).Normalise();
            var newv = (viewport.ScreenToWorld(e.X, viewport.Height - e.Y) - forigin).Normalise();

            var angle = DMath.Acos(Math.Max(-1, Math.Min(1, origv.Dot(newv))));
            if ((origv.Cross(newv).Z < 0)) angle = 2 * DMath.PI - angle;

            var shf = KeyboardState.Shift;
            var def = Select.RotationStyle;
            var snap = (def == RotationStyle.SnapOnShift && shf) || (def == RotationStyle.SnapOffShift && !shf);
            if (snap)
            {
                var deg = angle * (180 / DMath.PI);
                var rnd = Math.Round(deg / 15) * 15;
                angle = rnd * (DMath.PI / 180);
            }

            Matrix4 rotm;
            if (viewport.Direction == Viewport2D.ViewDirection.Top) rotm = Matrix4.CreateRotationZ((float)angle);
            else if (viewport.Direction == Viewport2D.ViewDirection.Front) rotm = Matrix4.CreateRotationX((float)angle);
            else rotm = Matrix4.CreateRotationY((float)-angle); // The Y axis rotation goes in the reverse direction for whatever reason

            var mov = Matrix4.CreateTranslation((float)-origin.X, (float)-origin.Y, (float)-origin.Z);
            var rot = Matrix4.Mult(mov, rotm);
            return Matrix4.Mult(rot, Matrix4.Invert(mov));
        }
开发者ID:silky,项目名称:sledge,代码行数:33,代码来源:RotateTool.cs

示例2: GetOriginForTransform

 private static Coordinate GetOriginForTransform(Viewport2D viewport, BaseBoxTool.BoxState state)
 {
     decimal x = 0;
     decimal y = 0;
     var cstart = viewport.Flatten(state.PreTransformBoxStart);
     var cend = viewport.Flatten(state.PreTransformBoxEnd);
     switch (state.Handle)
     {
         case BaseBoxTool.ResizeHandle.TopLeft:
         case BaseBoxTool.ResizeHandle.Top:
         case BaseBoxTool.ResizeHandle.TopRight:
         case BaseBoxTool.ResizeHandle.Left:
         case BaseBoxTool.ResizeHandle.Right:
             y = cstart.Y;
             break;
         case BaseBoxTool.ResizeHandle.BottomLeft:
         case BaseBoxTool.ResizeHandle.Bottom:
         case BaseBoxTool.ResizeHandle.BottomRight:
             y = cend.Y;
             break;
     }
     switch (state.Handle)
     {
         case BaseBoxTool.ResizeHandle.Top:
         case BaseBoxTool.ResizeHandle.TopRight:
         case BaseBoxTool.ResizeHandle.Right:
         case BaseBoxTool.ResizeHandle.BottomRight:
         case BaseBoxTool.ResizeHandle.Bottom:
             x = cstart.X;
             break;
         case BaseBoxTool.ResizeHandle.TopLeft:
         case BaseBoxTool.ResizeHandle.Left:
         case BaseBoxTool.ResizeHandle.BottomLeft:
             x = cend.X;
             break;
     }
     return viewport.Expand(new Coordinate(x, y, 0));
 }
开发者ID:jpiolho,项目名称:sledge,代码行数:38,代码来源:ResizeTool.cs

示例3: GetTransformationMatrix

        public override Matrix4? GetTransformationMatrix(Viewport2D viewport, ViewportEvent e, BaseBoxTool.BoxState state, Document doc)
        {
            var shearUpDown = state.Handle == BaseBoxTool.ResizeHandle.Left || state.Handle == BaseBoxTool.ResizeHandle.Right;
            var shearTopRight = state.Handle == BaseBoxTool.ResizeHandle.Top || state.Handle == BaseBoxTool.ResizeHandle.Right;

            var nsmd = viewport.ScreenToWorld(e.X, viewport.Height - e.Y) - state.MoveStart;
            var mouseDiff = SnapIfNeeded(nsmd, doc);
            if (KeyboardState.Shift)
            {
                mouseDiff = doc.Snap(nsmd, doc.Map.GridSpacing / 2);
            }

            var relative = viewport.Flatten(state.PreTransformBoxEnd - state.PreTransformBoxStart);
            var shearOrigin = (shearTopRight) ? state.PreTransformBoxStart : state.PreTransformBoxEnd;

            var shearAmount = new Coordinate(mouseDiff.X / relative.Y, mouseDiff.Y / relative.X, 0);
            if (!shearTopRight) shearAmount *= -1;

            var shearMatrix = Matrix4.Identity;
            var sax = (float)shearAmount.X;
            var say = (float)shearAmount.Y;

            switch (viewport.Direction)
            {
                case Viewport2D.ViewDirection.Top:
                    if (shearUpDown) shearMatrix.M12 = say;
                    else shearMatrix.M21 = sax;
                    break;
                case Viewport2D.ViewDirection.Front:
                    if (shearUpDown) shearMatrix.M23 = say;
                    else shearMatrix.M32 = sax;
                    break;
                case Viewport2D.ViewDirection.Side:
                    if (shearUpDown) shearMatrix.M13 = say;
                    else shearMatrix.M31 = sax;
                    break;
            }

            var stran = Matrix4.CreateTranslation((float)-shearOrigin.X, (float)-shearOrigin.Y, (float)-shearOrigin.Z);
            var shear = Matrix4.Mult(stran, shearMatrix);
            return Matrix4.Mult(shear, Matrix4.Invert(stran));
        }
开发者ID:jpiolho,项目名称:sledge,代码行数:42,代码来源:SkewTool.cs

示例4: RenderTransformBox

        private void RenderTransformBox(Viewport2D viewport)
        {
            if (!CurrentTransform.HasValue) return;

            var box = new Box(State.PreTransformBoxStart, State.PreTransformBoxEnd);
            var trans = CreateMatrixMultTransformation(CurrentTransform.Value);
            box = box.Transform(trans);
            var s = viewport.Flatten(box.Start);
            var e = viewport.Flatten(box.End);

            GL.Enable(EnableCap.LineStipple);
            GL.LineStipple(10, 0xAAAA);
            GL.Begin(PrimitiveType.Lines);
            GL.Color4(Color.FromArgb(64, BoxColour));

            Coord(s.DX, s.DY, e.DZ);
            Coord(e.DX, s.DY, e.DZ);

            Coord(s.DX, e.DY, e.DZ);
            Coord(e.DX, e.DY, e.DZ);

            Coord(s.DX, s.DY, e.DZ);
            Coord(s.DX, e.DY, e.DZ);

            Coord(e.DX, s.DY, e.DZ);
            Coord(e.DX, e.DY, e.DZ);

            GL.End();
            GL.Disable(EnableCap.LineStipple);

            RenderBoxText(viewport, s, e);
        }
开发者ID:074769,项目名称:sledge,代码行数:32,代码来源:SelectTool.cs

示例5: MouseHoverWhenDrawn

        /// <summary>
        /// When the mouse is hovering over the box, do collision tests against the handles and change the cursor if needed.
        /// </summary>
        /// <param name="viewport">The viewport</param>
        /// <param name="e">The mouse event</param>
        protected override void MouseHoverWhenDrawn(Viewport2D viewport, ViewportEvent e)
        {
            if (_currentTool == null)
            {
                base.MouseHoverWhenDrawn(viewport, e);
                return;
            }

            var padding = 7 / viewport.Zoom;

            viewport.Cursor = Cursors.Default;
            State.Action = BoxAction.Drawn;
            State.ActiveViewport = null;

            var now = viewport.ScreenToWorld(e.X, viewport.Height - e.Y);
            var start = viewport.Flatten(State.BoxStart);
            var end = viewport.Flatten(State.BoxEnd);

            var ccs = new Coordinate(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y), 0);
            var cce = new Coordinate(Math.Max(start.X, end.X), Math.Max(start.Y, end.Y), 0);

            // Check center handle
            if (now.X > ccs.X && now.X < cce.X && now.Y > ccs.Y && now.Y < cce.Y)
            {
                State.Handle = ResizeHandle.Center;
                State.ActiveViewport = viewport;
                State.Action = BoxAction.ReadyToResize;
                viewport.Cursor = CursorForHandle(State.Handle);
                return;
            }

            // Check other handles
            foreach (var handle in _currentTool.GetHandles(start, end, viewport.Zoom).Where(x => _currentTool.FilterHandle(x.Item1)))
            {
                var x = handle.Item2;
                var y = handle.Item3;
                if (now.X < x - padding || now.X > x + padding || now.Y < y - padding || now.Y > y + padding) continue;
                State.Handle = handle.Item1;
                State.ActiveViewport = viewport;
                State.Action = BoxAction.ReadyToResize;
                viewport.Cursor = CursorForHandle(State.Handle);
                return;
            }
        }
开发者ID:074769,项目名称:sledge,代码行数:49,代码来源:SelectTool.cs

示例6: Render2D

        public void Render2D(Viewport2D viewport, MapObject o)
        {
            if (viewport.Zoom < 1) return;

            var entityData = o.GetEntityData();
            if (entityData == null) return;

            var start = viewport.WorldToScreen(viewport.Flatten(o.BoundingBox.Start));
            var end = viewport.WorldToScreen(viewport.Flatten(o.BoundingBox.End));
            if (start.X >= viewport.Width || end.X <= 0 || start.Y >= viewport.Height || end.Y <= 0) return;

            var text = entityData.Name;
            var nameProp = entityData.GetPropertyValue("targetname");
            if (!String.IsNullOrWhiteSpace(nameProp)) text += ": " + nameProp;

            // Center the text horizontally
            var wid = _printer.Measure(text, _printerFont, new RectangleF(0, 0, viewport.Width, viewport.Height));
            var cx = (float)(start.X + (end.X - start.X) / 2);
            var bounds = new RectangleF(cx - wid.BoundingBox.Width / 2, viewport.Height - (float)end.Y - _printerFont.Height - 6, viewport.Width, viewport.Height);

            _printer.Print(text, _printerFont, o.Colour, bounds);
        }
开发者ID:silky,项目名称:sledge,代码行数:22,代码来源:EntityTextHelper.cs

示例7: GetVerticesAtPoint

        /// <summary>
        /// Get the VM points at the provided coordinate, ordered from top to bottom (for the supplied viewport).
        /// </summary>
        /// <param name="x">The X coordinate</param>
        /// <param name="y">The Y coordinate</param>
        /// <param name="viewport">The viewport</param>
        /// <returns>The points ordered from top to bottom, or an empty set if no points were found</returns>
        public List<VMPoint> GetVerticesAtPoint(int x, int y, Viewport2D viewport)
        {
            var p = viewport.ScreenToWorld(x, y);
            var d = 5 / viewport.Zoom; // Tolerance value = 5 pixels

            // Order by the unused coordinate in the view (which is the up axis) descending to get the "closest" point
            return (from point in Points
                    let c = viewport.Flatten(point.Coordinate)
                    where p.X >= c.X - d && p.X <= c.X + d && p.Y >= c.Y - d && p.Y <= c.Y + d
                    let unused = viewport.GetUnusedCoordinate(point.Coordinate)
                    orderby unused.X + unused.Y + unused.Z descending
                    select point).ToList();
        }
开发者ID:074769,项目名称:sledge,代码行数:20,代码来源:VMTool.cs

示例8: GetVerticesAtPoint

        public override List<VMPoint> GetVerticesAtPoint(int x, int y, Viewport2D viewport)
        {
            var verts = MainTool.GetVerticesAtPoint(x, y, viewport);

            var p = viewport.ScreenToWorld(x, y);
            var d = 8 / viewport.Zoom; // Tolerance value = 8 pixels
            var c = viewport.Flatten(_origin.Coordinate);
            if (p.X >= c.X - d && p.X <= c.X + d && p.Y >= c.Y - d && p.Y <= c.Y + d)
            {
                verts.Insert(0, _origin);
            }

            return verts;
        }
开发者ID:jpiolho,项目名称:sledge,代码行数:14,代码来源:ScaleTool.cs

示例9: SnapBoxCoordinatesIfNeeded

        private Tuple<Coordinate, Coordinate> SnapBoxCoordinatesIfNeeded(Viewport2D viewport, Coordinate start, Coordinate end)
        {
            if (State.Action == BoxAction.Resizing && State.Handle == ResizeHandle.Center)
            {
                // Pick the corner to snap
                var ms = State.MoveStart;
                var pts = viewport.Flatten(State.PreTransformBoxStart);
                var pte = viewport.Flatten(State.PreTransformBoxEnd);
                var ss = SnapIfNeeded(start);
                var se = SnapIfNeeded(end);
                var middle = (pts + pte) / 2;
                var delta = ss - start;
                if (ms.Y > middle.Y)
                {
                    // Top
                    delta.Y = se.Y - end.Y;
                }
                if (ms.X > middle.X)
                {
                    // Right
                    delta.X = se.X - end.X;
                }
                start += delta;
                end += delta;
            }

            var cstart = viewport.Expand(start) + viewport.GetUnusedCoordinate(State.BoxStart);
            var cend = viewport.Expand(end) + viewport.GetUnusedCoordinate(State.BoxEnd);
            return Tuple.Create(cstart, cend);
        }
开发者ID:KonstantinUb,项目名称:sledge,代码行数:30,代码来源:BaseBoxTool.cs

示例10: OverrideViewportContextMenu

 public override void OverrideViewportContextMenu(ViewportContextMenu menu, Viewport2D vp, ViewportEvent e)
 {
     menu.Items.Clear();
     var point = vp.ScreenToWorld(e.X, vp.Height - e.Y);
     var loc = vp.Flatten(_location);
     if ((loc-point).VectorMagnitude() < 10)
     {
         var item = new ToolStripMenuItem("Create Object");
         item.Click += (sender, args) => CreateEntity(_location);
         menu.Items.Add(item);
     }
 }
开发者ID:jpiolho,项目名称:sledge,代码行数:12,代码来源:EntityTool.cs

示例11: ViewportRightClick

 public void ViewportRightClick(Viewport2D vp, ViewportEvent e)
 {
     ViewportContextMenu.Instance.AddNonSelectionItems(_document, vp);
     if (!_document.Selection.IsEmpty() && !_document.Selection.InFaceSelection && ToolManager.ActiveTool is SelectTool)
     {
         var selectionBoundingBox = _document.Selection.GetSelectionBoundingBox();
         var point = vp.ScreenToWorld(e.X, vp.Height - e.Y);
         var start = vp.Flatten(selectionBoundingBox.Start);
         var end = vp.Flatten(selectionBoundingBox.End);
         if (point.X >= start.X && point.X <= end.X && point.Y >= start.Y && point.Y <= end.Y)
         {
             // Clicked inside the selection bounds
             ViewportContextMenu.Instance.AddSelectionItems(_document, vp);
         }
     }
     if (ToolManager.ActiveTool != null) ToolManager.ActiveTool.OverrideViewportContextMenu(ViewportContextMenu.Instance, vp, e);
     if (ViewportContextMenu.Instance.Items.Count > 0) ViewportContextMenu.Instance.Show(vp, e.X, e.Y);
 }
开发者ID:KonstantinUb,项目名称:sledge,代码行数:18,代码来源:DocumentSubscriptions.cs

示例12: SnapToSelection

        protected Coordinate SnapToSelection(Coordinate c, Viewport2D vp)
        {
            if (!Document.Map.SnapToGrid) return c;

            var snap = (Select.SnapStyle == SnapStyle.SnapOnAlt && KeyboardState.Alt) ||
                       (Select.SnapStyle == SnapStyle.SnapOffAlt && !KeyboardState.Alt);

            if (!snap) return c;

            var snapped = c.Snap(Document.Map.GridSpacing);
            if (Document.Selection.InFaceSelection || Document.Selection.IsEmpty()) return snapped;

            // Try and snap the the selection box center
            var selBox = Document.Selection.GetSelectionBoundingBox();
            var selCenter = vp.Flatten(selBox.Center);
            if (DMath.Abs(selCenter.X - c.X) < selBox.Width / 10 && DMath.Abs(selCenter.Y - c.Y) < selBox.Height / 10) return selCenter;

            var objects = Document.Selection.GetSelectedObjects().ToList();

            // Try and snap to an object center
            foreach (var mo in objects)
            {
                if (!(mo is Entity) && !(mo is Solid)) continue;
                var center = vp.Flatten(mo.BoundingBox.Center);
                if (DMath.Abs(center.X - c.X) >= mo.BoundingBox.Width / 10) continue;
                if (DMath.Abs(center.Y - c.Y) >= mo.BoundingBox.Height / 10) continue;
                return center;
            }

            // Get all the edges of the selected objects
            var lines = objects.SelectMany(x =>
            {
                if (x is Entity) return x.BoundingBox.GetBoxLines();
                if (x is Solid) return ((Solid) x).Faces.SelectMany(f => f.GetLines());
                return new Line[0];
            }).Select(x => new Line(vp.Flatten(x.Start), vp.Flatten(x.End))).ToList();

            // Try and snap to an edge
            var closest = snapped;
            foreach (var line in lines)
            {
                // if the line and the grid are in the same spot, return the snapped point
                if (line.ClosestPoint(snapped).EquivalentTo(snapped)) return snapped;

                // Test for corners and midpoints within a 10% tolerance
                var pointTolerance = (line.End - line.Start).VectorMagnitude() / 10;
                if ((line.Start - c).VectorMagnitude() < pointTolerance) return line.Start;
                if ((line.End - c).VectorMagnitude() < pointTolerance) return line.End;

                var center = (line.Start + line.End) / 2;
                if ((center - c).VectorMagnitude() < pointTolerance) return center;

                // If the line is closer to the grid point, return the line
                var lineSnap = line.ClosestPoint(c);
                if ((closest - c).VectorMagnitude() > (lineSnap - c).VectorMagnitude()) closest = lineSnap;
            }
            return closest;
        }
开发者ID:silky,项目名称:sledge,代码行数:58,代码来源:BaseTool.cs

示例13: GetBoxCoordinatesForSelectionResize

 private Tuple<Coordinate, Coordinate> GetBoxCoordinatesForSelectionResize(Viewport2D viewport, ViewportEvent e, BaseBoxTool.BoxState state, Document document)
 {
     if (state.Action != BaseBoxTool.BoxAction.Resizing) return Tuple.Create(state.BoxStart, state.BoxEnd);
     var now = SnapIfNeeded(viewport.ScreenToWorld(e.X, viewport.Height - e.Y), document);
     var cstart = viewport.Flatten(state.BoxStart);
     var cend = viewport.Flatten(state.BoxEnd);
     switch (state.Handle)
     {
         case BaseBoxTool.ResizeHandle.TopLeft:
             cstart.X = Math.Min(now.X, cend.X - 1);
             cend.Y = Math.Max(now.Y, cstart.Y + 1);
             break;
         case BaseBoxTool.ResizeHandle.Top:
             cend.Y = Math.Max(now.Y, cstart.Y + 1);
             break;
         case BaseBoxTool.ResizeHandle.TopRight:
             cend.X = Math.Max(now.X, cstart.X + 1);
             cend.Y = Math.Max(now.Y, cstart.Y + 1);
             break;
         case BaseBoxTool.ResizeHandle.Left:
             cstart.X = Math.Min(now.X, cend.X - 1);
             break;
         case BaseBoxTool.ResizeHandle.Center:
             var cdiff = cend - cstart;
             cstart = viewport.Flatten(state.PreTransformBoxStart) + now - SnapIfNeeded(state.MoveStart, document);
             cend = cstart + cdiff;
             break;
         case BaseBoxTool.ResizeHandle.Right:
             cend.X = Math.Max(now.X, cstart.X + 1);
             break;
         case BaseBoxTool.ResizeHandle.BottomLeft:
             cstart.X = Math.Min(now.X, cend.X - 1);
             cstart.Y = Math.Min(now.Y, cend.Y - 1);
             break;
         case BaseBoxTool.ResizeHandle.Bottom:
             cstart.Y = Math.Min(now.Y, cend.Y - 1);
             break;
         case BaseBoxTool.ResizeHandle.BottomRight:
             cend.X = Math.Max(now.X, cstart.X + 1);
             cstart.Y = Math.Min(now.Y, cend.Y - 1);
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     return SnapBoxCoordinatesIfNeeded(viewport, state, document, cstart, cend);
 }
开发者ID:jpiolho,项目名称:sledge,代码行数:46,代码来源:ResizeTool.cs

示例14: GetResizeOrigin

 protected override Coordinate GetResizeOrigin(Viewport2D viewport)
 {
     if (State.Action == BoxAction.Resizing && State.Handle == ResizeHandle.Center && !Document.Selection.IsEmpty())
     {
         var sel = Document.Selection.GetSelectedParents().ToList();
         if (sel.Count == 1 && sel[0] is Entity && !sel[0].HasChildren)
         {
             return viewport.Flatten(((Entity) sel[0]).Origin);
         }
     }
     return base.GetResizeOrigin(viewport);
 }
开发者ID:silky,项目名称:sledge,代码行数:12,代码来源:SelectTool.cs

示例15: MouseHoverWhenDrawn

 protected virtual void MouseHoverWhenDrawn(Viewport2D viewport, ViewportEvent e)
 {
     var now = viewport.ScreenToWorld(e.X, viewport.Height - e.Y);
     var start = viewport.Flatten(State.BoxStart);
     var end = viewport.Flatten(State.BoxEnd);
     var handle = GetHandle(now, start, end, HandleWidth / viewport.Zoom);
     if (handle.HasValue)
     {
         viewport.Cursor = CursorForHandle(handle.Value);
         State.Handle = handle.Value;
         State.Action = BoxAction.ReadyToResize;
         State.ActiveViewport = viewport;
     }
     else
     {
         viewport.Cursor = Cursors.Default;
         State.Action = BoxAction.Drawn;
         State.ActiveViewport = null;
     }
 }
开发者ID:KonstantinUb,项目名称:sledge,代码行数:20,代码来源:BaseBoxTool.cs


注:本文中的Sledge.UI.Viewport2D.Flatten方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。