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


C# UI.Viewport2D类代码示例

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


Viewport2D类属于Sledge.UI命名空间,在下文中一共展示了Viewport2D类的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: BeforeRender2D

 public void BeforeRender2D(Viewport2D viewport)
 {
     _offset = 3 / (double)viewport.Zoom;
     _fadeDistance = 200 / (double)viewport.Zoom;
     var mp = viewport.PointToClient(Control.MousePosition);
     _mousePos = viewport.ScreenToWorld(new Coordinate(mp.X, viewport.Height - mp.Y, 0));
     GL.Enable(EnableCap.LineSmooth);
     GL.Begin(BeginMode.Lines);
 }
开发者ID:jpiolho,项目名称:sledge,代码行数:9,代码来源:CenterHandlesHelper.cs

示例3: Render2D

 public void Render2D(Viewport2D viewport, MapObject o)
 {
     if (Sledge.Settings.Select.CenterHandlesActiveViewportOnly && !viewport.IsFocused) return;
     var center = viewport.Flatten(o.BoundingBox.Center);
     double a = 192;
     if (Sledge.Settings.Select.CenterHandlesFollowCursor)
     {
         var dist = (double) (center - _mousePos).VectorMagnitude();
         if (dist >= _fadeDistance) return;
         a = 192 * ((_fadeDistance - dist) / _fadeDistance);
     }
     GL.Color4(Color.FromArgb((int) a, o.Colour));
     GL.Vertex2(center.DX - _offset, center.DY - _offset);
     GL.Vertex2(center.DX + _offset, center.DY + _offset);
     GL.Vertex2(center.DX - _offset, center.DY + _offset);
     GL.Vertex2(center.DX + _offset, center.DY - _offset);
 }
开发者ID:ChristopherHaws,项目名称:sledge,代码行数:17,代码来源:CenterHandlesHelper.cs

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

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

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

示例7: Render2D

 public void Render2D(Viewport2D viewport, MapObject o)
 {
     throw new NotImplementedException();
 }
开发者ID:ChristopherHaws,项目名称:sledge,代码行数:4,代码来源:CordonHelper.cs

示例8: Render2D

 protected override void Render2D(Viewport2D viewport)
 {
     base.Render2D(viewport);
     if (ShouldDrawBox(viewport) && _preview != null)
     {
         GL.Color3(GetRenderColour());
         Graphics.Helpers.Matrix.Push();
         var matrix = viewport.GetModelViewMatrix();
         GL.MultMatrix(ref matrix);
         MapObjectRenderer.DrawWireframe(_preview, true, false);
         Graphics.Helpers.Matrix.Pop();
     }
 }
开发者ID:KonstantinUb,项目名称:sledge,代码行数:13,代码来源:BrushTool.cs

示例9: OverrideViewportContextMenu

 public override void OverrideViewportContextMenu(ViewportContextMenu menu, Viewport2D vp, ViewportEvent e)
 {
     menu.Items.Clear();
     if (State.Handle == ResizeHandle.Center)
     {
         var item = new ToolStripMenuItem("Create Object");
         item.Click += (sender, args) => BoxDrawnConfirm(vp);
         menu.Items.Add(item);
     }
 }
开发者ID:KonstantinUb,项目名称:sledge,代码行数:10,代码来源:BrushTool.cs

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

示例11: GetTransformMatrix

 private Matrix4? GetTransformMatrix(Viewport2D viewport, ViewportEvent e)
 {
     if (_currentTool == null) return null;
     return State.Handle == ResizeHandle.Center
                ? _tools.OfType<ResizeTool>().First().GetTransformationMatrix(viewport, e, State, Document, _widgets)
                : _currentTool.GetTransformationMatrix(viewport, e, State, Document, _widgets);
 }
开发者ID:074769,项目名称:sledge,代码行数:7,代码来源:SelectTool.cs

示例12: Render2D

        protected override void Render2D(Viewport2D viewport)
        {
            if (_currentTool == null)
            {
                base.Render2D(viewport);
                return;
            }

            var start = viewport.Flatten(State.BoxStart);
            var end = viewport.Flatten(State.BoxEnd);

            if (ShouldDrawBox(viewport))
            {
                RenderBox(viewport, start, end);
            }

            if (ShouldRenderResizeBox(viewport))
            {
                RenderResizeBox(viewport, start, end);
            }

            if (ShouldRenderHandles())
            {
                RenderHandles(viewport, start, end);
            }

            if (State.Action == BoxAction.Resizing && CurrentTransform.HasValue)
            {
                RenderTransformBox(viewport);
            }
            else if (ShouldDrawBox(viewport))
            {
                RenderBoxText(viewport, start, end);
            }
        }
开发者ID:074769,项目名称:sledge,代码行数:35,代码来源:SelectTool.cs

示例13: 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;

            _printer.Print(text, _printerFont, o.Colour, new RectangleF((float)start.X + 2, viewport.Height - (float)end.Y - _printerFont.Height - 6, viewport.Width, viewport.Height));
        }
开发者ID:074769,项目名称:sledge,代码行数:17,代码来源:EntityTextHelper.cs

示例14: BeforeRender2D

 public void BeforeRender2D(Viewport2D viewport)
 {
     _printer.Begin();
 }
开发者ID:074769,项目名称:sledge,代码行数:4,代码来源:EntityTextHelper.cs

示例15: AfterRender2D

 public void AfterRender2D(Viewport2D viewport)
 {
     _printer.End();
 }
开发者ID:074769,项目名称:sledge,代码行数:4,代码来源:EntityTextHelper.cs


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