コード例 #1
0
ファイル: ViewingAdapter.cs プロジェクト: jethac/ATF
        /// <summary>
        /// Frames the items in the current view</summary>
        /// <param name="items">Items to frame</param>
        public void Frame(IEnumerable<object> items)
        {
            if (ToggleFramingEnabled)
            {
                if (m_isUnframing)
                {
                    m_isUnframing = false;
                    m_transformAdapter.SetTransform(m_unframeMtrx.M11, m_unframeMtrx.M22, m_unframeMtrx.DX, m_unframeMtrx.DY);
                    return;
                }
                m_isUnframing = true;
                m_unframeMtrx = m_transformAdapter.Transform;
            }



            var bounds = GetBounds(items);

            // transform bounds from client space to graph space.
            Matrix3x2F invXform = Matrix3x2F.Invert(m_transformAdapter.Transform);
            var gBounds = Matrix3x2F.Transform(invXform, bounds);            
            var crect = AdaptedControl.ClientRectangle;
            crect.Inflate(-MarginSize.Width, -MarginSize.Height);
            if (crect.Width < 1 || crect.Height < 1) return;

            float sx = MathUtil.Clamp(crect.Width / gBounds.Width, m_transformAdapter.MinScale.X, m_transformAdapter.MaxScale.X);
            float sy = MathUtil.Clamp(crect.Height / gBounds.Height, m_transformAdapter.MinScale.Y, m_transformAdapter.MaxScale.Y);
            float scale = Math.Min(sx, sy);
            crect.X +=(int) (crect.Width - gBounds.Width * scale) / 2;
            crect.Y += (int)(crect.Height - gBounds.Height * scale) / 2;
            float tx = crect.X - gBounds.X * scale;
            float ty = crect.Y - gBounds.Y * scale;
            m_transformAdapter.SetTransform(scale, scale, tx, ty);            
        }
コード例 #2
0
ファイル: GridAdapter.cs プロジェクト: zparr/ATF
        // draw dragged events
        private void control_DrawingD2d(object sender, EventArgs e)
        {
            if (m_visible)
            {
                // Matrix transform = new Matrix();
                // if (m_transformAdapter != null)
                //     transform = m_transformAdapter.Transform;

                var d2dControl = AdaptedControl as D2dAdaptableControl;

                Matrix3x2F xform = d2dControl.D2dGraphics.Transform;
                d2dControl.D2dGraphics.Transform = Matrix3x2F.Identity;

                Matrix     transform  = m_transformAdapter.Transform;
                RectangleF clientRect = AdaptedControl.ClientRectangle;
                RectangleF canvasRect = GdiUtil.InverseTransform(transform, clientRect);

                // draw horizontal lines
                // ChartUtil.DrawHorizontalGrid(transform, canvasRect, m_verticalGridSpacing, d2dControl.Theme.GridPen, d2dControl.D2dGraphics);

                // draw vertical lines
                // ChartUtil.DrawVerticalGrid(transform, canvasRect, m_horizontalGridSpacing, d2dControl.Theme.GridPen, d2dControl.D2dGraphics);

                d2dControl.D2dGraphics.Transform = xform;
            }
        }
コード例 #3
0
ファイル: D2dGraphAdapter.cs プロジェクト: bfuller86/ATF
        /// <summary>
        /// Performs hit testing for rectangle bounds, in client coordinates</summary>
        /// <param name="pickRect">Pick rectangle, in client coordinates</param>
        /// <returns>Items that overlap with the rectangle, in client coordinates</returns>
        public virtual IEnumerable <object> Pick(Rectangle pickRect)
        {
            Matrix3x2F invXform = Matrix3x2F.Invert(m_d2dGraphics.Transform);
            RectangleF rect     = D2dUtil.Transform(invXform, pickRect);

            return(m_renderer.Pick(m_graph, rect, m_d2dGraphics));
        }
コード例 #4
0
ファイル: BirdEyeView.cs プロジェクト: zoombapup/ATF
            protected override void OnMouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button != MouseButtons.Left || !IsContextValid())
                {
                    return;
                }

                var sourceControl   = m_birdEyeView.m_sourceControl;
                var srcXformAdapter = sourceControl.Cast <ITransformAdapter>();
                var srcInvXform     = Matrix3x2F.Invert(srcXformAdapter.Transform);
                var grect           = Matrix3x2F.Transform(srcInvXform, sourceControl.ClientRectangle);
                var inxXform        = Matrix3x2F.Invert(m_transformAdapter.Transform);
                var gpt             = Matrix3x2F.TransformPoint(inxXform, e.Location);

                if (!grect.Contains(gpt))
                {
                    var   srcScale = srcXformAdapter.Scale;
                    float gcx      = grect.X + grect.Width / 2;
                    float gcy      = grect.Y + grect.Height / 2;
                    grect.X += gpt.X - gcx;
                    grect.Y += gpt.Y - gcy;
                    float tx = -grect.X * srcScale.X;
                    float ty = -grect.Y * srcScale.Y;
                    srcXformAdapter.Translation = new PointF(tx, ty);
                }
                m_hitGpt.X = gpt.X - grect.X;
                m_hitGpt.Y = gpt.Y - grect.Y;

                base.OnMouseDown(sender, e);
                AdaptedControl.Capture = true;
            }
コード例 #5
0
        private void control_DrawingD2d(object sender, EventArgs e)
        {
            if (Selector.IsSelecting)
            {
                var         d2dControl = (D2dAdaptableControl)sender;
                D2dGraphics g          = d2dControl.D2dGraphics;

                // Replace transform and anti-aliasing setting.
                Matrix3x2F xform = d2dControl.D2dGraphics.Transform;
                d2dControl.D2dGraphics.Transform = Matrix3x2F.Identity;
                D2dAntialiasMode oldAA = d2dControl.D2dGraphics.AntialiasMode;
                d2dControl.D2dGraphics.AntialiasMode = D2dAntialiasMode.Aliased;

                // Draw the selection rectangle.
                Rectangle rect = MakeSelectionRect(
                    ClientToCanvas(Selector.CurrentPoint), ClientToCanvas(Selector.FirstPoint));
                rect.Intersect(AdaptedControl.ClientRectangle);
                var rectF = new RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
                g.DrawRectangle(rectF, SelectionBorderColor, 1.0f, null);
                g.FillRectangle(rectF, SelectionFillColor);

                // Restore D2dGraphics settings.
                d2dControl.D2dGraphics.Transform     = xform;
                d2dControl.D2dGraphics.AntialiasMode = oldAA;
            }
        }
コード例 #6
0
        private void drawUGlyph(float wingLength, float x, float y, float lat, float lng, float width, Brush brush)
        {
            float rotationAngle = (float)Math.Atan((lng - lat) / width) * div;

            //rotationAngle += rotationAngle < 0 ? 90f : 45f;

            this.RenderTarget.Transform = Matrix3x2F.Rotation(rotationAngle, new D2D.Point2F(x, y));

            float hw = WINGLENGTH / 2;

            PathGeometry pLinesGeometry = this.Factory.CreatePathGeometry();
            GeometrySink gs             = pLinesGeometry.Open();

            gs.SetFillMode(FillMode.Winding);

            gs.BeginFigure(new D2D.Point2F(x, y), FigureBegin.Filled);
            gs.AddLine(new D2D.Point2F(x + hw, y + hw));
            gs.AddLine(new D2D.Point2F(x + hw, y - wingLength));
            gs.AddLine(new D2D.Point2F(x, y));
            gs.AddLine(new D2D.Point2F(x - hw, y + hw));
            gs.AddLine(new D2D.Point2F(x - hw, y - wingLength));
            gs.EndFigure(FigureEnd.Closed);

            gs.Close();

            brush.Opacity = 0.2f;
            this.RenderTarget.FillGeometry(pLinesGeometry, brush);

            brush.Opacity = 0.8f;
            this.RenderTarget.DrawGeometry(pLinesGeometry, brush, 0.8f);
            //this.RenderTarget.DrawRectangle(new D2D.RectF(x - RECTSIZE, y - RECTSIZE, x + RECTSIZE, y + RECTSIZE), brush, 0.8f);

            this.RenderTarget.Transform = Matrix3x2F.Identity;
        }
コード例 #7
0
        private void UpdateControl(D2dAdaptableControl source, D2dAdaptableControl target, Point cpt)
        {
            target.Context = source.Context;
            if (target.Context == null)
            {
                return;
            }


            // transform current mouse point to graph space.
            var        srcXform = source.As <ITransformAdapter>();
            Matrix3x2F mtrx     = Matrix3x2F.Invert(srcXform.Transform);
            var        gpt      = Matrix3x2F.TransformPoint(mtrx, cpt);

            var targetXform = target.As <ITransformAdapter>();

            var    csz         = target.ClientSize;
            PointF translation = new PointF(csz.Width / 2 - gpt.X * targetXform.Scale.X, csz.Height / 2 - gpt.Y * targetXform.Scale.Y);

            targetXform.Translation = translation;
            var edgeEditor = source.As <D2dGraphEdgeEditAdapter <Module, Connection, ICircuitPin> >();

            m_activeEdgeEditor = (edgeEditor != null && edgeEditor.IsDraggingEdge) ? edgeEditor : null;
            target.Invalidate();
        }
コード例 #8
0
        private static void TraceMatrix(Matrix3x2F matrix)
        {
#if _D2DTRACE
            Trace.WriteLine(string.Format("  Matrix3x2: {0}, {1}", matrix.M11, matrix.M12));
            Trace.WriteLine(string.Format("             {0}, {1}", matrix.M21, matrix.M22));
            Trace.WriteLine(string.Format("             {0}, {1}", matrix.M31, matrix.M32));
#endif
        }
コード例 #9
0
ファイル: D2dUtil.cs プロジェクト: blue3k/ATFClone
 /// <summary>
 /// Transforms rectangle</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="r">Rectangle</param>
 /// <returns>Transformed rectangle</returns>
 public static RectangleF Transform(Matrix3x2F matrix, RectangleF r)
 {
     s_tempPtsF[0] = new PointF(r.Left, r.Top);
     s_tempPtsF[1] = new PointF(r.Right, r.Bottom);
     s_tempPtsF[0] = Matrix3x2F.TransformPoint(matrix, s_tempPtsF[0]);
     s_tempPtsF[1] = Matrix3x2F.TransformPoint(matrix, s_tempPtsF[1]);
     return(MakeRectangle(s_tempPtsF[0], s_tempPtsF[1]));
 }
コード例 #10
0
ファイル: D2dUtil.cs プロジェクト: blue3k/ATFClone
        /// <summary>
        /// Transforms point by inverse transform</summary>
        /// <param name="matrix">Matrix representing transform</param>
        /// <param name="p">Point</param>
        /// <returns>Inverse transformed point</returns>
        public static Point InverseTransform(Matrix3x2F matrix, Point p)
        {
            Matrix3x2F inverse = matrix;

            inverse.Invert();
            s_tempPtsF[0] = p;
            s_tempPtsF[0] = Matrix3x2F.TransformPoint(inverse, s_tempPtsF[0]);
            return(new Point((int)s_tempPtsF[0].X, (int)s_tempPtsF[0].Y));
        }
コード例 #11
0
ファイル: BirdEyeView.cs プロジェクト: zoombapup/ATF
            private void control_MouseWheel(object sender, MouseEventArgs e)
            {
                if (!AdaptedControl.ClientRectangle.Contains(e.Location))
                {
                    return;
                }
                if (e.Button != MouseButtons.None ||
                    !IsContextValid())
                {
                    return;
                }

                // apply transformation to source control.
                var sourceControl   = m_birdEyeView.m_sourceControl;
                var srcXformAdapter = sourceControl.Cast <ITransformAdapter>();
                var srcInvXform     = Matrix3x2F.Invert(srcXformAdapter.Transform);
                var grect           = Matrix3x2F.Transform(srcInvXform, sourceControl.ClientRectangle);
                var inxXform        = Matrix3x2F.Invert(m_transformAdapter.Transform);
                var gpt             = Matrix3x2F.TransformPoint(inxXform, e.Location);

                if (!grect.Contains(gpt))
                {
                    return;
                }

                // zoom at the center of the grect.
                gpt.X = grect.X + grect.Width / 2;
                gpt.Y = grect.Y + grect.Height / 2;

                // transform gpt to client space of sourcecontrol.
                var srcCpt = Matrix3x2F.TransformPoint(srcXformAdapter.Transform, gpt);

                PointF translation      = srcXformAdapter.Translation;
                PointF scale            = srcXformAdapter.Scale;
                PointF scaleCenterStart = new PointF(
                    (srcCpt.X - translation.X) / scale.X,
                    (srcCpt.Y - translation.Y) / scale.Y);

                float delta = 1.0f + e.Delta / 1200.0f;

                scale = new PointF(
                    scale.X * delta,
                    scale.Y * delta);

                // constrain scale before calculating translation to maintain scroll center position
                scale = srcXformAdapter.ConstrainScale(scale);

                translation = new PointF(
                    srcCpt.X - scaleCenterStart.X * scale.X,
                    srcCpt.Y - scaleCenterStart.Y * scale.Y);

                srcXformAdapter.SetTransform(
                    scale.X,
                    scale.Y,
                    translation.X,
                    translation.Y);
            }
コード例 #12
0
        protected internal Matrix3x2F RandomMatrix3x2()
        {
            var which = Random.NextDouble();
            //return Matrix3x2F.Skew(90, 0); //check for bug 730701
            Matrix3x2F ret;

            if (which < 0.5)
            {
                ret = new Matrix3x2F(
                    1.0f - (float)Random.NextDouble() * (float)Random.NextDouble(),
                    (float)Random.NextDouble() * (float)Random.NextDouble(),
                    (float)Random.NextDouble() * (float)Random.NextDouble(),
                    1.0f - (float)Random.NextDouble() * (float)Random.NextDouble(),
                    (float)Random.NextDouble() * (float)Random.NextDouble(),
                    (float)Random.NextDouble() * (float)Random.NextDouble()
                    );
                TraceMatrix(ret);
                return(ret);
            }
            if (which < 0.8)
            {
                ret = Matrix3x2F.Identity;
                TraceMatrix(ret);
                return(ret);
            }
            if (which < 0.85)
            {
                ret = Matrix3x2F.Translation(
                    Random.Next(-20, 20),
                    Random.Next(-20, 20));
                TraceMatrix(ret);
                return(ret);
            }
            if (which < 0.90)
            {
                ret = Matrix3x2F.Skew(
                    (float)(Random.NextDouble() * Random.NextDouble() * 89),
                    (float)(Random.NextDouble() * Random.NextDouble() * 89),
                    CoinFlip ? new Point2F(0, 0) : RandomPoint());
                TraceMatrix(ret);
                return(ret);
            }
            if (which < 0.95)
            {
                ret = Matrix3x2F.Scale(
                    1 + (float)((Random.NextDouble() - 0.5) * Random.NextDouble()),
                    1 + (float)((Random.NextDouble() - 0.5) * Random.NextDouble()),
                    CoinFlip ? new Point2F(0, 0) : RandomPoint());
                TraceMatrix(ret);
                return(ret);
            }
            ret = Matrix3x2F.Rotation(
                (float)((Random.NextDouble() - 0.5) * Random.NextDouble() * 720),
                CoinFlip ? new Point2F(0, 0) : RandomPoint());
            TraceMatrix(ret);
            return(ret);
        }
コード例 #13
0
ファイル: D2DStorylinesScene.cs プロジェクト: petestmarie/E2
        private void drawTemporalUncertaintyGlyph(float wingLength, float x, float y, float lat, float lng, float width, Brush brush)
        {
            float rotationAngle = (float)Math.Atan((lng - lat) / width) * div;

            this.RenderTarget.Transform = Matrix3x2F.Rotation(rotationAngle, new D2D.Point2F(x, y));
            this.RenderTarget.DrawLine(new D2D.Point2F(x - wingLength - 5, y - 2), new D2D.Point2F(x + wingLength + 5, y - 2), brush, 1.5f);
            this.RenderTarget.DrawLine(new D2D.Point2F(x - wingLength - 5, y + 2), new D2D.Point2F(x + wingLength + 5, y + 2), brush, 1.5f);
            this.RenderTarget.Transform = Matrix3x2F.Identity;
        }
コード例 #14
0
        void RenderScene()
        {
            lock (syncObject)
            {
                if (device == null)
                {
                    CreateDeviceResources();
                }

                if (!pause)
                {
                    if (lastSavedDelta != 0)
                    {
                        startTime      = Environment.TickCount - lastSavedDelta;
                        lastSavedDelta = 0;
                    }
                    currentTimeVariation = (Environment.TickCount - startTime) / 6000.0f;
                    worldMatrix          = MatrixMath.MatrixTranslate(0, 0, currentTimeVariation);
                    textBrush.Transform  = Matrix3x2F.Translation(0, (4096f / 16f) * currentTimeVariation);
                }

                device.ClearDepthStencilView(
                    depthStencilView,
                    ClearOptions.Depth,
                    1,
                    0
                    );

                // Clear the back buffer
                device.ClearRenderTargetView(renderTargetView, backColor);

                diffuseVariable.Resource = null;

                technique.GetPassByIndex(0).Apply();

                // Draw the D2D content into our D3D surface
                RenderD2DContentIntoSurface();

                diffuseVariable.Resource = textureResourceView;

                // Update variables
                worldMatrixVariable.Matrix = worldMatrix;

                // Set index buffer
                device.IA.IndexBuffer = new IndexBuffer(facesIndexBuffer, Format.R16UInt, 0);

                // Draw the scene
                technique.GetPassByIndex(0).Apply();

                device.DrawIndexed((uint)Marshal.SizeOf(VertexArray.VerticesInstance), 0, 0);

                swapChain.Present(0, Microsoft.WindowsAPICodePack.DirectX.Graphics.PresentOptions.None);
            }
        }
コード例 #15
0
ファイル: Displayer.cs プロジェクト: hljlishen/Utilities
        private void InitializeDisplayerState()
        {
            var rtps = new RenderTargetProperties();
            var hrtp = new HwndRenderTargetProperties(Panel.Handle, new SizeU((uint)Panel.Width, (uint)Panel.Height), PresentOptions.None);

            Factory              = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded); //创建工厂
            rt                   = Factory.CreateHwndRenderTarget(rtps, hrtp);
            rt.AntiAliasMode     = AntiAliasMode.Aliased;
            rt.TextAntiAliasMode = TextAntiAliasMode.Aliased;
            (rt as HwndRenderTarget).Resize(new SizeU((uint)Panel.Width, (uint)Panel.Height));
            rt.Transform = Matrix3x2F.Scale(rt.Size.Width / Panel.Width, rt.Size.Height / Panel.Height);
        }
コード例 #16
0
        /// <summary>
        /// Draws a partially defined graph edge</summary>
        /// <param name="fromNode">Source node, or null</param>
        /// <param name="fromRoute">Source route, or null</param>
        /// <param name="toNode">Destination node, or null</param>
        /// <param name="toRoute">Destination route, or null</param>
        /// <param name="label">Edge label</param>
        /// <param name="endPoint">Endpoint to substitute for source or destination, if either is null</param>
        /// <param name="g">Graphics object</param>
        public override void Draw(
            TNode fromNode,
            BoundaryRoute fromRoute,
            TNode toNode,
            BoundaryRoute toRoute,
            string label,
            Point endPoint,
            D2dGraphics g)
        {
            // put endpoint into statechart space
            var inverse = g.Transform;

            inverse.Invert();
            PointF end = Matrix3x2F.TransformPoint(inverse, endPoint);

            PointF p1;
            PointF normal1;

            if (fromNode != null)
            {
                p1 = ParameterToPoint(fromNode.Bounds, fromRoute.Position, out normal1);
            }
            else
            {
                p1      = end;
                normal1 = new Point();
            }

            PointF p4;
            PointF normal2;

            if (toNode != null)
            {
                p4 = ParameterToPoint(toNode.Bounds, toRoute.Position, out normal2);
            }
            else
            {
                p4      = end;
                normal2 = new Point();
            }

            PointF p2, p3;
            float  d = GetTransitionPoints(p1, normal1, p4, normal2, out p2, out p3);

            DrawEdgeSpline(p1, p2, p3, p4, d, m_theme.OutlineBrush, g);

            if (!string.IsNullOrEmpty(label))
            {
                BezierCurve2F curve    = new BezierCurve2F(p1, p2, p3, p4);
                Vec2F         midpoint = curve.Evaluate(0.5f);
                g.DrawText(label, m_centerText, new PointF(midpoint.X, midpoint.Y), m_theme.TextBrush);
            }
        }
コード例 #17
0
ファイル: ViewingContext.cs プロジェクト: zoombapup/ATF
        /// <summary>
        /// Gets the bounding rectangle of all circuit items in client coordinates</summary>
        /// <returns>Bounding rectangle of all circuit items in client coordinates</returns>
        public Rectangle GetBounds()
        {
            if (m_graph == null)
            {
                return(Rectangle.Empty);
            }
            IEnumerable <object> items = m_graph.Nodes;
            var annoDiagram            = m_graph.As <IAnnotatedDiagram>();

            if (annoDiagram != null)
            {
                items = items.Concat(annoDiagram.Annotations);
            }
            Rectangle bounds = GetBounds(items);


            if (DomNode.Is <Group>())
            {
                // include group pins y range
                var group = DomNode.Cast <Group>();

                int yMin = int.MaxValue;
                int yMax = int.MinValue;

                foreach (var pin in group.InputGroupPins.Concat(group.OutputGroupPins))
                {
                    var grpPin = pin.Cast <GroupPin>();
                    if (grpPin.Bounds.Y < yMin)
                    {
                        yMin = grpPin.Bounds.Y;
                    }
                    if (grpPin.Bounds.Y > yMax)
                    {
                        yMax = grpPin.Bounds.Y;
                    }
                }

                // transform y range to client space
                if (yMin != int.MaxValue && yMax != int.MinValue)
                {
                    var transformAdapter = m_control.Cast <ITransformAdapter>();
                    var minPt            = Matrix3x2F.TransformPoint(transformAdapter.Transform, new PointF(0, yMin));
                    var maxPt            = Matrix3x2F.TransformPoint(transformAdapter.Transform, new PointF(0, yMax));

                    yMin = (int)minPt.Y;
                    yMax = (int)maxPt.Y;
                    int width  = bounds.Width;
                    int height = yMax - yMin + 1;
                    bounds = Rectangle.Union(bounds, new Rectangle(bounds.X, yMin, width, height));
                }
            }
            return(bounds);
        }
コード例 #18
0
        private void m_magnifier_Painting(object sender, EventArgs e)
        {
            var d2dControl = (D2dAdaptableControl)sender;

            if (d2dControl.Context != null)
            {
                var saveXform = d2dControl.D2dGraphics.Transform;
                var dragEdge  = m_activeEdgeEditor != null?m_activeEdgeEditor.GetDraggingEdge() : null;

                if (dragEdge != null)
                {
                    PointF start = dragEdge.StartPoint;
                    PointF end   = dragEdge.EndPoint;
                    if (dragEdge.FromRoute == null)
                    {
                        start = Matrix3x2F.TransformPoint(saveXform, start);
                    }

                    if (dragEdge.ToNode == null)
                    {
                        end = Matrix3x2F.TransformPoint(saveXform, end);
                    }

                    m_editor.CircuitRenderer.DrawPartialEdge(
                        dragEdge.FromNode,
                        dragEdge.FromRoute,
                        dragEdge.ToNode,
                        dragEdge.ToRoute,
                        dragEdge.Label,
                        start,
                        end,
                        d2dControl.D2dGraphics
                        );
                }
                else
                {
                    m_activeEdgeEditor = null;
                }

                var csz = d2dControl.ClientSize;

                d2dControl.D2dGraphics.Transform = Matrix3x2F.Identity;
                var currentCursor = Cursor.Current;
                var rect          = new Rectangle();
                rect.Location = new Point(csz.Width / 2 - currentCursor.HotSpot.X, csz.Height / 2 - currentCursor.HotSpot.Y);
                rect.Size     = Cursor.Current.Size;
                d2dControl.D2dGraphics.BeginGdiSection();
                Graphics g = d2dControl.D2dGraphics.Graphics;
                Cursor.Current.Draw(g, rect);
                d2dControl.D2dGraphics.EndGdiSection();
                d2dControl.D2dGraphics.Transform = saveXform;
            }
        }
コード例 #19
0
ファイル: GridAdapter.cs プロジェクト: zoombapup/ATF
        // draw dragged events
        private void control_DrawingD2d(object sender, EventArgs e)
        {
            if (m_visible)
            {
                var d2dControl = AdaptedControl as D2dAdaptableControl;

                Matrix3x2F xform = d2dControl.D2dGraphics.Transform;
                d2dControl.D2dGraphics.Transform = Matrix3x2F.Identity;

                d2dControl.D2dGraphics.Transform = xform;
            }
        }
コード例 #20
0
        /// <summary>
        /// Performs hit testing for rectangle bounds, in client coordinates</summary>
        /// <param name="pickRect">Pick rectangle, in client coordinates</param>
        /// <returns>Items that overlap with the rectangle, in client coordinates</returns>
        public override IEnumerable <object> Pick(Rectangle pickRect)
        {
#if CS_4
            Matrix3x2F           invXform         = Matrix3x2F.Invert(m_d2dGraphics.Transform);
            RectangleF           rect             = D2dUtil.Transform(invXform, pickRect);
            IEnumerable <object> pickedGraphNodes = base.Pick(pickRect);
#else
            // workaround a C#3 compiler bug( CS1911 warning)
            Matrix3x2F    invXform         = Matrix3x2F.Invert(m_d2dGraphics.Transform);
            RectangleF    rect             = D2dUtil.Transform(invXform, pickRect);
            List <object> pickedGraphNodes = new List <object>();
            foreach (TNode node in m_graph.Nodes)
            {
                RectangleF nodeBounds = m_renderer.GetBounds(node, m_d2dGraphics); // in graph space
                if (nodeBounds.IntersectsWith(rect))
                {
                    pickedGraphNodes.Add(node);
                }
            }
#endif
            foreach (var pickedGraphNode in pickedGraphNodes)
            {
                yield return(pickedGraphNode);
            }

            var pickedFloatingPins = new List <object>();
            var circuiElement      = m_graph.Cast <ICircuitElementType>();
            foreach (var pin in circuiElement.Inputs)
            {
                var        grpPIn     = pin.Cast <ICircuitGroupPin <TNode> >();
                RectangleF nodeBounds = m_renderer.GetBounds(grpPIn, true, m_d2dGraphics);
                if (nodeBounds.IntersectsWith(rect))
                {
                    pickedFloatingPins.Add(pin);
                }
            }

            foreach (var pin in circuiElement.Outputs)
            {
                var        grpPIn     = pin.Cast <ICircuitGroupPin <TNode> >();
                RectangleF nodeBounds = m_renderer.GetBounds(grpPIn, false, m_d2dGraphics);
                if (nodeBounds.IntersectsWith(rect))
                {
                    pickedFloatingPins.Add(pin);
                }
            }

            foreach (var floatingPin in pickedFloatingPins)
            {
                yield return(floatingPin);
            }
        }
コード例 #21
0
        /// <summary>
        /// Draw the planet.
        /// </summary>
        /// <param name="planet"></param>
        private void DrawPlanet(Ellipse planet)
        {
            // Get the size of the RenderTarget.
            float rtWidth  = this._renderTarget.Size.Width;
            float rtHeight = this._renderTarget.Size.Height;

            this._renderTarget.Transform = Matrix3x2F.Translation(10 + this._animateTranslateX, rtHeight / 2 - 100);
            this._renderTarget.FillEllipse(planet, this._planetBackgroundBrush);
            this._renderTarget.Transform = Matrix3x2F.Translation(23 + this._animateTranslateX, rtHeight / 2 - 121);
            this._renderTarget.FillGeometry(this._planetUpPath, this._continentBrush);
            this._renderTarget.Transform = Matrix3x2F.Translation(15 + this._animateTranslateX, rtHeight / 2 + 1);
            this._renderTarget.FillGeometry(this._planetDownPath, this._continentBrush);
        }
コード例 #22
0
ファイル: D2dGraphAdapter.cs プロジェクト: bfuller86/ATF
        /// <summary>
        /// Performs hit test for a point, in client coordinates</summary>
        /// <param name="pickPoint">Pick point, in client coordinates</param>
        /// <returns>Hit record for a point, in client coordinates</returns>
        DiagramHitRecord IPickingAdapter2.Pick(Point pickPoint)
        {
            Matrix3x2F invXform = Matrix3x2F.Invert(m_d2dGraphics.Transform);
            PointF     pt       = Matrix3x2F.TransformPoint(invXform, pickPoint);

            TEdge priorityEdge = null;

            if (m_selectionContext != null)
            {
                priorityEdge = m_selectionContext.GetLastSelected <TEdge>();
            }
            return(m_renderer.Pick(m_graph, priorityEdge, pt, m_d2dGraphics));
        }
コード例 #23
0
ファイル: D2dGraphAdapter.cs プロジェクト: bfuller86/ATF
        /// <summary>
        /// Performs hit test for a point, in client coordinates</summary>
        /// <param name="nodes">Nodes to test if hit</param>
        /// <param name="edges">Edges to test if hit</param>
        /// <param name="pickPoint">Pick point, in client coordinates</param>
        /// <returns>Hit record for a point, in client coordinates</returns>
        public GraphHitRecord <TNode, TEdge, TEdgeRoute> Pick(IEnumerable <TNode> nodes, IEnumerable <TEdge> edges, Point pickPoint)
        {
            Matrix3x2F invXform = Matrix3x2F.Invert(m_d2dGraphics.Transform);
            PointF     pt       = Matrix3x2F.TransformPoint(invXform, pickPoint);

            TEdge priorityEdge = null;

            if (m_selectionContext != null)
            {
                priorityEdge = m_selectionContext.GetLastSelected <TEdge>();
            }
            return(m_renderer.Pick(nodes, edges, priorityEdge, pt, m_d2dGraphics));
        }
コード例 #24
0
ファイル: Displayer.cs プロジェクト: hljlishen/Utilities
 private void Pb_SizeChanged(object sender, EventArgs e)
 {
     lock (Locker)
     {
         if (Panel.Width < 10 && Panel.Height < 10)  //卫语句,窗口最小化时会触发sizechanged事件,此时width和height都是0,会触发ValueInterval的范围过小异常
         {
             return;
         }
         Mapper.SetScreenArea(0, Panel.Width, 0, Panel.Height);
         (rt as HwndRenderTarget).Resize(new SizeU((uint)Panel.Width, (uint)Panel.Height));
         rt.Transform = Matrix3x2F.Scale(rt.Size.Width / Panel.Width, rt.Size.Height / Panel.Height);
         Redraw       = true;
     }
 }
コード例 #25
0
        /// <summary>
        /// Recreates the render target, if necessary, by calling SetRenderTarget</summary>
        protected override void RecreateRenderTarget()
        {
            var        curRT    = (WindowRenderTarget)D2dRenderTarget;
            Matrix3x2F xform    = Transform;
            var        hwnProps = new HwndRenderTargetProperties();

            hwnProps.Hwnd           = Hwnd;
            hwnProps.PixelSize      = curRT.PixelSize;
            hwnProps.PresentOptions = PresentOptions.Immediately;
            RenderTarget rt = new WindowRenderTarget(D2dFactory.NativeFactory, D2dFactory.RenderTargetProperties, hwnProps);

            SetRenderTarget(rt);
            Transform = xform;
        }
コード例 #26
0
        /// <summary>
        /// Draws a partially defined graph edge</summary>
        /// <param name="fromNode">Source node, or null</param>
        /// <param name="fromRoute">Source route, or null</param>
        /// <param name="toNode">Destination node, or null</param>
        /// <param name="toRoute">Destination route, or null</param>
        /// <param name="label">Edge label</param>
        /// <param name="endPoint">Endpoint to substitute for source or destination (in client coords), if either is null</param>
        /// <param name="g">Graphics object</param>
        public override void Draw(
            TNode fromNode,
            NumberedRoute fromRoute,
            TNode toNode,
            NumberedRoute toRoute,
            string label,
            Point endPoint,
            D2dGraphics g)
        {
            var inverse = g.Transform;

            inverse.Invert();
            PointF end = Matrix3x2F.TransformPoint(inverse, endPoint);

            TNode   node     = (fromNode != null) ? fromNode : toNode;
            CircleF boundary = GetBoundary(node);
            Vec2F   proj     = new Vec2F();

            if (CircleF.Project(new Vec2F(end), boundary, ref proj))
            {
                PointF start = new PointF(proj.X, proj.Y);
                g.DrawLine(start, end, m_theme.OutlineBrush);

                if (fromNode == null)
                {
                    PointF temp = end;
                    end   = start;
                    start = temp;
                }
                Vec2F endTangent    = new Vec2F(end.X - start.X, end.Y - start.Y);
                Vec2F arrowPosition = new Vec2F(end);
                DrawArrow(arrowPosition, endTangent, m_theme.OutlineBrush, g);

                if (!string.IsNullOrEmpty(label))
                {
                    PointF     textPoint = new PointF((end.X + start.X) * 0.5f, (end.Y + start.Y) * 0.5f);
                    RectangleF textBox   = new RectangleF(textPoint.X - 512, textPoint.Y, 1024, m_theme.TextFormat.FontHeight);
                    //g.DrawString(label, m_theme.Font, m_theme.TextBrush, textBox, m_theme.CenterStringFormat);
                    g.DrawText(label, m_theme.TextFormat, textBox, m_theme.TextBrush);
                }
            }
        }
コード例 #27
0
ファイル: BirdEyeView.cs プロジェクト: zoombapup/ATF
            private void PaintD2d(object sender, EventArgs e)
            {
                if (!IsContextValid())
                {
                    return;
                }
                var control       = (D2dAdaptableControl)AdaptedControl;
                var sourceControl = m_birdEyeView.m_sourceControl;

                var srcXformAdapter = sourceControl.Cast <ITransformAdapter>();

                D2dGraphics g        = control.D2dGraphics;
                Matrix3x2F  invXform = g.Transform;
                float       scaleX   = invXform.M11;

                invXform.Invert();

                Point cpt = control.PointToClient(Control.MousePosition);
                var   gpt = Matrix3x2F.TransformPoint(invXform, cpt);

                // transform client rect of source control to graph space.
                var srcInvXform = Matrix3x2F.Invert(srcXformAdapter.Transform);
                var grect       = Matrix3x2F.Transform(srcInvXform, sourceControl.ClientRectangle);

                float strokeWidth = m_dragging || (grect.Contains(gpt) && control.Focused)
                    ? 3.0f / scaleX : 1.5f / scaleX;

                g.DrawRectangle(grect, Color.Yellow, strokeWidth);

                Point srcCpt = sourceControl.PointToClient(Control.MousePosition);
                var   srcGpt = Matrix3x2F.TransformPoint(srcInvXform, srcCpt);

                if (sourceControl.Focused && grect.Contains(srcGpt) &&
                    !control.ClientRectangle.Contains(cpt))
                {
                    float      cursorSize = 7.0f / scaleX;
                    RectangleF cursorRect = new RectangleF(srcGpt.X - cursorSize / 2, srcGpt.Y - cursorSize / 2,
                                                           cursorSize, cursorSize);
                    g.FillEllipse(cursorRect, Color.Yellow);
                }
            }
コード例 #28
0
ファイル: ViewingAdapter.cs プロジェクト: zoombapup/ATF
        /// <summary>
        /// Frames the items in the current view</summary>
        /// <param name="items">Items to frame</param>
        public void Frame(IEnumerable <object> items)
        {
            if (ToggleFramingEnabled)
            {
                if (m_isUnframing)
                {
                    m_isUnframing = false;
                    m_transformAdapter.SetTransform(m_unframeMtrx.M11, m_unframeMtrx.M22, m_unframeMtrx.DX, m_unframeMtrx.DY);
                    return;
                }
                m_isUnframing = true;
                m_unframeMtrx = m_transformAdapter.Transform;
            }



            var bounds = GetBounds(items);

            // transform bounds from client space to graph space.
            Matrix3x2F invXform = Matrix3x2F.Invert(m_transformAdapter.Transform);
            var        gBounds  = Matrix3x2F.Transform(invXform, bounds);
            var        crect    = AdaptedControl.ClientRectangle;

            crect.Inflate(-MarginSize.Width, -MarginSize.Height);
            if (crect.Width < 1 || crect.Height < 1)
            {
                return;
            }

            float sx    = MathUtil.Clamp(crect.Width / gBounds.Width, m_transformAdapter.MinScale.X, m_transformAdapter.MaxScale.X);
            float sy    = MathUtil.Clamp(crect.Height / gBounds.Height, m_transformAdapter.MinScale.Y, m_transformAdapter.MaxScale.Y);
            float scale = Math.Min(sx, sy);

            crect.X += (int)(crect.Width - gBounds.Width * scale) / 2;
            crect.Y += (int)(crect.Height - gBounds.Height * scale) / 2;
            float tx = crect.X - gBounds.X * scale;
            float ty = crect.Y - gBounds.Y * scale;

            m_transformAdapter.SetTransform(scale, scale, tx, ty);
        }
コード例 #29
0
ファイル: Editor.cs プロジェクト: zoombapup/ATF
            /// <summary>
            /// Renders entire graph</summary>
            protected override void OnRender()
            {
                D2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;
                Matrix3x2F invMtrx = D2dGraphics.Transform;

                invMtrx.Invert();
                RectangleF boundsGr = Matrix3x2F.Transform(invMtrx, this.AdaptedControl.ClientRectangle);

                // Draw normal nodes on top of edges
                foreach (StateBase node in Graph.Nodes)
                {
                    RectangleF nodeBounds = Renderer.GetBounds(node, D2dGraphics);
                    if (!boundsGr.IntersectsWith(nodeBounds))
                    {
                        continue;
                    }
                    DiagramDrawingStyle style = GetStyle(node);
                    Renderer.Draw(node, style, D2dGraphics);
                }

                // Draw edges last for now. Todo: draw in layers, with edges and then nodes for each layer
                foreach (Transition edge in Graph.Edges)
                {
                    if (edge == HiddenEdge)
                    {
                        continue;
                    }

                    RectangleF edgeBounds = Renderer.GetBounds(edge, D2dGraphics);
                    if (!boundsGr.IntersectsWith(edgeBounds))
                    {
                        continue;
                    }

                    DiagramDrawingStyle style = GetStyle(edge);
                    Renderer.Draw(edge, style, D2dGraphics);
                }
            }
コード例 #30
0
        // draw dragged events
        private void control_DrawingD2d(object sender, EventArgs e)
        {
            if (m_visible)
            {
                var        d2dControl = AdaptedControl as D2dAdaptableControl;
                Matrix3x2F xform      = d2dControl.D2dGraphics.Transform;
                d2dControl.D2dGraphics.Transform = Matrix3x2F.Identity;
                Matrix     transform  = m_transformAdapter.Transform;
                RectangleF clientRect = AdaptedControl.ClientRectangle;
                RectangleF canvasRect = GdiUtil.InverseTransform(transform, clientRect);

                D2dAntialiasMode oldAA = d2dControl.D2dGraphics.AntialiasMode;
                d2dControl.D2dGraphics.AntialiasMode = D2dAntialiasMode.Aliased;
                // draw horizontal lines
                ChartUtil.DrawHorizontalGrid(transform, canvasRect, m_verticalGridSpacing, m_gridColor, d2dControl.D2dGraphics);

                // draw vertical lines
                ChartUtil.DrawVerticalGrid(transform, canvasRect, m_horizontalGridSpacing, m_gridColor, d2dControl.D2dGraphics);

                d2dControl.D2dGraphics.Transform     = xform;
                d2dControl.D2dGraphics.AntialiasMode = oldAA;
            }
        }
コード例 #31
0
ファイル: BirdEyeView.cs プロジェクト: zoombapup/ATF
            protected override void OnDragging(MouseEventArgs e)
            {
                base.OnDragging(e);
                if (e.Button != MouseButtons.Left || !IsContextValid())
                {
                    return;
                }

                AdaptedControl.Capture = true;


                m_dragging = true;
                var sourceControl   = m_birdEyeView.m_sourceControl;
                var srcXformAdapter = sourceControl.Cast <ITransformAdapter>();
                var inxXform        = Matrix3x2F.Invert(m_transformAdapter.Transform);
                var gpt             = Matrix3x2F.TransformPoint(inxXform, e.Location);

                gpt.X -= m_hitGpt.X;
                gpt.Y -= m_hitGpt.Y;
                var srcScale = srcXformAdapter.Scale;

                srcXformAdapter.Translation = new PointF(-gpt.X * srcScale.X, -gpt.Y * srcScale.Y);
            }
コード例 #32
0
ファイル: D2dUtil.cs プロジェクト: Joxx0r/ATF
 /// <summary>
 /// Transforms vector</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="v">Vector</param>
 /// <returns>Transformed vector</returns>
 public static PointF TransformVector(Matrix3x2F matrix, PointF v)
 {
     s_tempPtsF[0] = v;
     Matrix3x2F.TransformVector(matrix, s_tempPtsF[0]);
     return s_tempPtsF[0];
 }
コード例 #33
0
ファイル: D2dUtil.cs プロジェクト: Joxx0r/ATF
 /// <summary>
 /// Transforms point by inverse transform</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="p">Point</param>
 /// <returns>Inverse transformed point</returns>
 public static Point InverseTransform(Matrix3x2F matrix, Point p)
 {
     Matrix3x2F inverse = matrix;
     inverse.Invert();
     s_tempPtsF[0] = p;
     s_tempPtsF[0] = Matrix3x2F.TransformPoint(inverse, s_tempPtsF[0]);
     return new Point((int)s_tempPtsF[0].X, (int)s_tempPtsF[0].Y);
 }
コード例 #34
0
ファイル: D2dUtil.cs プロジェクト: Joxx0r/ATF
 /// <summary>
 /// Transforms rectangle</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="r">Rectangle</param>
 /// <returns>Transformed rectangle</returns>
 public static RectangleF Transform(Matrix3x2F matrix, RectangleF r)
 {
     s_tempPtsF[0] = new PointF(r.Left, r.Top);
     s_tempPtsF[1] = new PointF(r.Right, r.Bottom);
     s_tempPtsF[0] = Matrix3x2F.TransformPoint(matrix, s_tempPtsF[0]);
     s_tempPtsF[1] = Matrix3x2F.TransformPoint(matrix, s_tempPtsF[1]);
     return MakeRectangle(s_tempPtsF[0], s_tempPtsF[1]);
 }
コード例 #35
0
 protected internal Matrix3x2F RandomMatrix3x2()
 {
     var which = Random.NextDouble();
     //return Matrix3x2F.Skew(90, 0); //check for bug 730701
     Matrix3x2F ret;
     if (which < 0.5)
     {
         ret = new Matrix3x2F(
             1.0f - (float) Random.NextDouble()*(float) Random.NextDouble(),
             (float) Random.NextDouble()*(float) Random.NextDouble(),
             (float) Random.NextDouble()*(float) Random.NextDouble(),
             1.0f - (float) Random.NextDouble()*(float) Random.NextDouble(),
             (float) Random.NextDouble()*(float) Random.NextDouble(),
             (float) Random.NextDouble()*(float) Random.NextDouble()
             );
         TraceMatrix(ret);
         return ret;
     }
     if (which < 0.8)
     {
         ret = Matrix3x2F.Identity;
         TraceMatrix(ret);
         return ret;
     }
     if (which < 0.85)
     {
         ret = Matrix3x2F.Translation(
             Random.Next(-20, 20),
             Random.Next(-20, 20));
         TraceMatrix(ret);
         return ret;
     }
     if (which < 0.90)
     {
         ret = Matrix3x2F.Skew(
             (float)(Random.NextDouble() * Random.NextDouble() * 89),
             (float)(Random.NextDouble() * Random.NextDouble() * 89),
             CoinFlip ? new Point2F(0, 0) : RandomPoint());
         TraceMatrix(ret);
         return ret;
     }
     if (which < 0.95)
     {
         ret = Matrix3x2F.Scale(
             1 + (float)((Random.NextDouble() - 0.5) * Random.NextDouble()),
             1 + (float)((Random.NextDouble() - 0.5) * Random.NextDouble()),
             CoinFlip ? new Point2F(0, 0) : RandomPoint());
         TraceMatrix(ret);
         return ret;
     }
     ret = Matrix3x2F.Rotation(
         (float)((Random.NextDouble() - 0.5) * Random.NextDouble() * 720),
         CoinFlip ? new Point2F(0,0) : RandomPoint());
     TraceMatrix(ret);
     return ret;
 }
コード例 #36
0
ファイル: D2dGraphics.cs プロジェクト: sbambach/ATF
 /// <summary>
 /// Changes the rotation of the coordinate system by prepending the specified rotation
 /// to the Transform property</summary>
 /// <param name="angle">Angle of rotation, in degrees</param>
 public void RotateTransform(float angle)
 {
     var trans = Matrix3x2F.CreateRotation(angle);
     var xform = Transform;
     Transform = (trans * xform);
 }
コード例 #37
0
ファイル: D2dGraphics.cs プロジェクト: sbambach/ATF
 /// <summary>
 /// Changes the scale of the coordinate system by prepending the specified scale
 /// to the Transform property</summary>
 /// <param name="sx">Amount to scale by in the x-axis direction</param>
 /// <param name="sy">Amount to scale by in the y-axis direction</param>
 public void ScaleTransform(float sx, float sy)
 {
     var trans = Matrix3x2F.CreateScale(sx, sy);
     var xform = Transform;
     Transform = (trans * xform);
 }
コード例 #38
0
ファイル: D2dGraphics.cs プロジェクト: sbambach/ATF
 /// <summary>
 /// Changes the origin of the coordinate system by prepending the specified translation
 /// to the Transform property</summary>
 /// <param name="dx">X translation</param>
 /// <param name="dy">Y translation</param>
 /// <remarks>Modeled after GDI version http://msdn.microsoft.com/en-us/library/6a1d65f4.aspx </remarks>
 public void TranslateTransform(float dx, float dy)
 {
     var trans = Matrix3x2F.CreateTranslation(dx, dy);
     var xform = Transform;
     Transform = (trans * xform);
 }
コード例 #39
0
        private static void TraceMatrix(Matrix3x2F matrix)
        {
#if _D2DTRACE
            Trace.WriteLine(string.Format("  Matrix3x2: {0}, {1}", matrix.M11, matrix.M12));
            Trace.WriteLine(string.Format("             {0}, {1}", matrix.M21, matrix.M22));
            Trace.WriteLine(string.Format("             {0}, {1}", matrix.M31, matrix.M32));
#endif
        }
コード例 #40
0
ファイル: D2dUtil.cs プロジェクト: jethac/ATF
 /// <summary>
 /// Transforms rectangle</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="r">Rectangle</param>
 /// <returns>Transformed rectangle</returns>
 public static RectangleF Transform(Matrix3x2F matrix, RectangleF r)
 {
     return Matrix3x2F.Transform(matrix, r);          
 }
コード例 #41
0
ファイル: D2dUtil.cs プロジェクト: jethac/ATF
 /// <summary>
 /// Transforms point by inverse transform</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="p">Point</param>
 /// <returns>Inverse transformed point</returns>
 public static Point InverseTransform(Matrix3x2F matrix, Point p)
 {            
     Matrix3x2F inverse = Matrix3x2F.Invert(matrix);
     return Point.Truncate(Matrix3x2F.TransformPoint(inverse, p));                       
 }
コード例 #42
0
ファイル: D2dUtil.cs プロジェクト: jethac/ATF
 /// <summary>
 /// Transforms vector</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="v">Vector</param>
 /// <returns>Transformed vector</returns>
 public static PointF TransformVector(Matrix3x2F matrix, PointF v)
 {            
     return Matrix3x2F.TransformVector(matrix, v);
 }