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


C# UI.ViewportEvent类代码示例

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


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

示例1: MouseDown

        public override void MouseDown(ViewportBase viewport, ViewportEvent e)
        {
            var vp = viewport as Viewport3D;
            if (vp == null || e.Button != MouseButtons.Left) return;

            // Do selection
            e.Handled = true;
            var ray = vp.CastRayFromScreen(e.X, e.Y);
            var hits = MainTool.GetCopies().Where(x => x.BoundingBox.IntersectsWith(ray));
            var clickedFace = hits.SelectMany(f => f.Faces)
                .Select(x => new { Item = x, Intersection = x.GetIntersectionPoint(ray) })
                .Where(x => x.Intersection != null)
                .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                .Select(x => x.Item)
                .FirstOrDefault();

            var faces = new List<Face>();
            if (clickedFace != null)
            {
                if (KeyboardState.Shift) faces.AddRange(clickedFace.Parent.Faces);
                else faces.Add(clickedFace);
            }

            if (!KeyboardState.Ctrl) _selection.Clear();
            _selection.AddRange(faces);

            UpdateSelection();
        }
开发者ID:jpiolho,项目名称:sledge,代码行数:28,代码来源:EditFaceTool.cs

示例2: KeyDown

 public void KeyDown(ViewportEvent e)
 {
     if (e.KeyCode == Keys.Space)
     {
         Viewport.Cursor = Cursors.SizeAll;
         e.Handled = true;
     }
     var str = e.KeyCode.ToString();
     if (str.StartsWith("NumPad") || str.StartsWith("D"))
     {
         var last = str.Last();
         if (Char.IsDigit(last))
         {
             var press = (int) Char.GetNumericValue(last);
             if (press >= 0 && press <= 9)
             {
                 if (press == 0) press = 10;
                 var num = Math.Max(press - 6, 6 - press);
                 var pow = (decimal) Math.Pow(2, num);
                 var zoom = press < 6 ? 1 / pow : pow;
                 Viewport2D.Zoom = zoom;
                 Mediator.Publish(EditorMediator.ViewZoomChanged, Viewport2D.Zoom);
             }
         }
     }
 }
开发者ID:074769,项目名称:sledge,代码行数:26,代码来源:Camera2DViewportListener.cs

示例3: 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

示例4: KeyDown

        public void KeyDown(ViewportEvent e)
        {
            if (e.KeyCode == Keys.Space)
            {
                Viewport.Cursor = Cursors.SizeAll;
                if (!Sledge.Settings.View.Camera2DPanRequiresMouseClick)
                {
                    Viewport.Capture = true;
                    var p = e.Sender.PointToClient(Cursor.Position);
                    _mouseDown = new Coordinate(p.X, Viewport2D.Height - p.Y, 0);
                }
                e.Handled = true;
            }

            var moveAllowed = DocumentManager.CurrentDocument != null &&
                              (DocumentManager.CurrentDocument.Selection.IsEmpty()
                               || !Sledge.Settings.Select.ArrowKeysNudgeSelection);
            if (moveAllowed)
            {
                var shift = new Coordinate(0, 0, 0);

                switch (e.KeyCode)
                {
                    case Keys.Left:
                        shift.X = -Viewport.Width / Viewport2D.Zoom / 4;
                        break;
                    case Keys.Right:
                        shift.X = Viewport.Width / Viewport2D.Zoom / 4;
                        break;
                    case Keys.Up:
                        shift.Y = Viewport.Height / Viewport2D.Zoom / 4;
                        break;
                    case Keys.Down:
                        shift.Y = -Viewport.Height / Viewport2D.Zoom / 4;
                        break;
                }

                Viewport2D.Position += shift;
            }

            var str = e.KeyCode.ToString();
            if (str.StartsWith("NumPad") || str.StartsWith("D"))
            {
                var last = str.Last();
                if (Char.IsDigit(last))
                {
                    var press = (int) Char.GetNumericValue(last);
                    if (press >= 0 && press <= 9)
                    {
                        if (press == 0) press = 10;
                        var num = Math.Max(press - 6, 6 - press);
                        var pow = (decimal) Math.Pow(2, num);
                        var zoom = press < 6 ? 1 / pow : pow;
                        Viewport2D.Zoom = zoom;
                        Mediator.Publish(EditorMediator.ViewZoomChanged, Viewport2D.Zoom);
                    }
                }
            }
        }
开发者ID:silky,项目名称:sledge,代码行数:59,代码来源:Camera2DViewportListener.cs

示例5: MouseDown

 public void MouseDown(ViewportEvent e)
 {
     if (_showing)
     {
         _menu.Show(Viewport, new Point(e.X, e.Y));
         e.Handled = true;
     }
 }
开发者ID:silky,项目名称:sledge,代码行数:8,代码来源:ViewportLabelListener.cs

示例6: MouseDown

 public override void MouseDown(ViewportBase viewport, ViewportEvent e)
 {
     if (!(viewport is Viewport3D) || (e.Button != MouseButtons.Left && e.Button != MouseButtons.Right)) return;
     _multiplier = e.Button == MouseButtons.Left ? 1 : -1;
     //PaintCurrentPoint((Viewport3D) viewport);
     _mouseDown = true;
     _moveCount = 0;
 }
开发者ID:silky,项目名称:sledge,代码行数:8,代码来源:GeometryTool.cs

示例7: KeyUp

 public void KeyUp(ViewportEvent e)
 {
     if (e.KeyCode == Keys.Space)
     {
         Viewport.Cursor = Cursors.Default;
         e.Handled = true;
     }
 }
开发者ID:074769,项目名称:sledge,代码行数:8,代码来源:Camera2DViewportListener.cs

示例8: KeyDown

 public override void KeyDown(ViewportBase viewport, ViewportEvent e)
 {
     switch (e.KeyCode)
     {
         case Keys.Enter:
             CreateEntity(_location);
             _state = EntityState.None;
             break;
         case Keys.Escape:
             _state = EntityState.None;
             break;
     }
 }
开发者ID:KonstantinUb,项目名称:sledge,代码行数:13,代码来源:EntityTool.cs

示例9: MouseMove

        public override void MouseMove(ViewportBase viewport, ViewportEvent e)
        {
            var vp = viewport as Viewport3D;
            if (vp == null) return;

            _mousePos.X = e.X;
            _mousePos.Y = e.Y;

            if (_currentPoint == null) return;

            if (_mouseDown)
            {
                _moveCount++;
                //PaintCurrentPoint(vp);
            }
        }
开发者ID:jpiolho,项目名称:sledge,代码行数:16,代码来源:GeometryTool.cs

示例10: MouseDown

        public override void MouseDown(ViewportBase viewport, ViewportEvent e)
        {
            return;

            var vp = viewport as Viewport3D;
            if (vp == null || (e.Button != MouseButtons.Left && e.Button != MouseButtons.Right)) return;

            var ray = vp.CastRayFromScreen(e.X, e.Y);
            var hits = Document.Map.WorldSpawn.GetAllNodesIntersectingWith(ray).OfType<Solid>();
            var clickedFace = hits.SelectMany(f => f.Faces)
                .Select(x => new { Item = x, Intersection = x.GetIntersectionPoint(ray) })
                .Where(x => x.Intersection != null)
                .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                .Select(x => x.Item)
                .FirstOrDefault();
            // TODO: Select
            //TextureItem itemToSelect = null;
            // if ((behaviour == SelectBehaviour.Select || behaviour == SelectBehaviour.LiftSelect) && !KeyboardState.Ctrl)
            // {
            //     Selection.Clear();
            // }
            //if (clickedFace != null)
            //{
            //    var faces = new List<Face>();
            //    if (KeyboardState.Shift) faces.AddRange(clickedFace.Parent.Faces);
            //    else faces.Add(clickedFace);
            //    if (behaviour == SelectBehaviour.Select || behaviour == SelectBehaviour.LiftSelect)
            //    {
            //        foreach (var face in faces)
            //        {
            //            if (face.IsSelected) Selection.Deselect(face);
            //            else Selection.Select(face);
            //        }
            //    }
            //    if (behaviour == SelectBehaviour.Lift || behaviour == SelectBehaviour.LiftSelect)
            //    {
            //        var tex = faces.Where(face => face.Texture.Texture != null).FirstOrDefault();
            //        itemToSelect = tex != null ? TexturePackage.GetItem(tex.Texture.Name) : null;
            //    }
            //}
            //Document.UpdateDisplayLists();
            //_form.SelectionChanged();
            //if (itemToSelect != null)
            //{
            //    _form.SelectTexture(itemToSelect);
            //}
        }
开发者ID:jpiolho,项目名称:sledge,代码行数:47,代码来源:SelectTool.cs

示例11: 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

示例12: MouseDown

        public override void MouseDown(ViewportBase viewport, ViewportEvent e)
        {
            var vp = viewport as Viewport3D;
            if (vp == null) return;

            // Get the ray that is cast from the clicked point along the viewport frustrum
            var ray = vp.CastRayFromScreen(e.X, e.Y);

            // Grab all the elements that intersect with the ray
            var hits = Document.Map.WorldSpawn.GetAllNodesIntersectingWith(ray);

            // Sort the list of intersecting elements by distance from ray origin and grab the first hit
            var hit = hits
                .Select(x => new {Item = x, Intersection = GetIntersectionPoint(x, ray)})
                .Where(x => x.Intersection != null)
                .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                .FirstOrDefault();

            if (hit == null) return; // Nothing was clicked

            CreateDecal(hit.Intersection);
        }
开发者ID:KonstantinUb,项目名称:sledge,代码行数:22,代码来源:DecalTool.cs

示例13: MouseDown

        public override void MouseDown(ViewportBase viewport, ViewportEvent ve)
        {
            if (viewport is Viewport2D)
            {
                var vp2 = (Viewport2D)viewport;
                if (ve.Button == MouseButtons.Left && MouseOverPivot(vp2, ve))
                {
                    _movingPivot = true;
                    ve.Handled = true;
                }
                return;
            }

            var vp = viewport as Viewport3D;
            if (vp == null || vp != _activeViewport) return;

            if (ve.Button != MouseButtons.Left || _mouseOver == CircleType.None) return;
            _mouseDown = _mouseOver;
            _mouseDownPoint = new Coordinate(ve.X, vp.Height - ve.Y, 0);
            _mouseMovePoint = null;
            ve.Handled = true;
            vp.AquireInputLock(this);
        }
开发者ID:silky,项目名称:sledge,代码行数:23,代码来源:RotationWidget.cs

示例14: GetTransformationMatrix

 public override Matrix4? GetTransformationMatrix(Viewport2D viewport, ViewportEvent e, BaseBoxTool.BoxState state, Document doc)
 {
     var coords = GetBoxCoordinatesForSelectionResize(viewport, e, state, doc);
     state.BoxStart = coords.Item1;
     state.BoxEnd = coords.Item2;
     Matrix4 resizeMatrix;
     if (state.Handle == BaseBoxTool.ResizeHandle.Center)
     {
         var movement = state.BoxStart - state.PreTransformBoxStart;
         resizeMatrix = Matrix4.CreateTranslation((float)movement.X, (float)movement.Y, (float)movement.Z);
     }
     else
     {
         var resize = (state.PreTransformBoxStart - state.BoxStart) +
                      (state.BoxEnd - state.PreTransformBoxEnd);
         resize = resize.ComponentDivide(state.PreTransformBoxEnd - state.PreTransformBoxStart);
         resize += new Coordinate(1, 1, 1);
         var offset = -GetOriginForTransform(viewport, state);
         var trans = Matrix4.CreateTranslation((float)offset.X, (float)offset.Y, (float)offset.Z);
         var scale = Matrix4.Mult(trans, Matrix4.Scale((float)resize.X, (float)resize.Y, (float)resize.Z));
         resizeMatrix = Matrix4.Mult(scale, Matrix4.Invert(trans));
     }
     return resizeMatrix;
 }
开发者ID:jpiolho,项目名称:sledge,代码行数:24,代码来源:ResizeTool.cs

示例15: MouseLeave

 public override void MouseLeave(ViewportBase viewport, ViewportEvent e)
 {
     _activeViewport = null;
 }
开发者ID:silky,项目名称:sledge,代码行数:4,代码来源:Widget.cs


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