void myMouseWheel(object sender, MouseWheelEventArgs e)
        {
            System.Windows.Media.Matrix m = i.RenderTransform.Value;

            // zooms in and out
            if (e.Delta > 0)
            {

                m.ScaleAt(
                    1.5,
                    1.5,
                    e.GetPosition(w).X,
                    e.GetPosition(w).Y);
            }
            else
            {
                m.ScaleAt(
                    1.0 / 1.5,
                    1.0 / 1.5,
                    e.GetPosition(w).X,
                    e.GetPosition(w).Y);
            }

            // attempts a tranform
            //m.Translate(0, 1);

            i.RenderTransform = new MatrixTransform(m);
        }
        public static void GetScaleFactors(out double dpiX, out double dpiY)
        {
            dpiX = 1.0;
            dpiY = 1.0;
            try
            {
                System.Windows.Media.Matrix conversionMatrix = new System.Windows.Media.Matrix();
                var source = new HwndSource(new HwndSourceParameters());

                conversionMatrix = source.CompositionTarget.TransformFromDevice;
                if (conversionMatrix.M11 != 0)
                {
                    dpiX = conversionMatrix.M11;
                }
                if (conversionMatrix.M22 != 0)
                {
                    dpiY = conversionMatrix.M22;
                }
            }
            catch (Exception exc)
            {
                dpiX = 1.0;
                dpiY = 1.0;
                System.Console.Write("BaseUtils.UpdateScaleFactor(): " + exc.ToString());
            }
        }
예제 #3
0
        protected Vector CalculateL2(Vector vectorT0, Vector vectorT1, Vector vectorT2, Vector vectorT3, Vector vectorT4, double r1, double r2, double r3)
        {
            Vector vectorM1;
            Vector vectorM2;
            Vector vectorM3;
            Vector vectorM1M2;
            Vector vectorM2M3;
            System.Windows.Media.Matrix m = new System.Windows.Media.Matrix();
            Vector vectorL = new Vector();

            vectorM1 = CalculateM2(vectorT1, vectorT0, vectorT2, r1);
            vectorM2 = CalculateM2(vectorT2, vectorT1, vectorT3, r2);
            vectorM3 = CalculateM2(vectorT3, vectorT2, vectorT4, r3);

            vectorM1M2 = (vectorT2 + vectorM2) - (vectorT1 + vectorM1);
            vectorM2M3 = (vectorT3 + vectorM3) - (vectorT2 + vectorM2);

            m.M11 = (r2 - r3) / vectorM2M3.Length;
            m.M12 = -Math.Sqrt(1 - ((r2 - r3) * (r2 - r3)) / vectorM2M3.LengthSquared);
            m.M21 = -m.M12;
            m.M22 = m.M11;

            vectorL = path.MatrixMultiplication(vectorM2M3, m);

            vectorL = (r2 / vectorL.Length) * vectorL;

            if ((vectorM1M2.X * vectorM2M3.Y - vectorM1M2.Y * vectorM2M3.X) > 0)
            {
                vectorL = -vectorL;
            }

            return vectorL;
        }
예제 #4
0
 public MatrixAnimation(Matrix fromValue, Matrix toValue, Duration duration, FillBehavior fillBehavior)
 {
     From = fromValue;
     To = toValue;
     Duration = duration;
     FillBehavior = fillBehavior;
 }
예제 #5
0
        /// <summary>
        /// Gets the system DPI scale factor (compared to 96 dpi).
        /// From http://blogs.msdn.com/jaimer/archive/2007/03/07/getting-system-dpi-in-wpf-app.aspx
        /// Should not be called before the Loaded event (else XamlException mat throw)
        /// </summary>
        /// <returns>A Point object containing the X- and Y- scale factor.</returns>
        private static Point GetSystemDpiFactor()
        {
            PresentationSource source = PresentationSource.FromVisual(Application.Current.MainWindow);

            System.Windows.Media.Matrix m = source.CompositionTarget.TransformToDevice;
            return(new Point(m.M11, m.M22));
        }
        private string SaveBitmap()
        {
            System.Windows.Media.Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
            Double dpiX = m.M11 * 96;
            Double dpiY = m.M22 * 96;
            //200*12
            //7*60
            int width  = GetFitBMPWidth();
            int height = GetFitBMPHeight();
            var wb     = new System.Windows.Media.Imaging.WriteableBitmap(width, height, dpiX, dpiY,
                                                                          PixelFormats.Pbgra32, null);

            wb.Lock();
            var bmp = new System.Drawing.Bitmap(wb.PixelWidth, wb.PixelHeight,
                                                wb.BackBufferStride,
                                                System.Drawing.Imaging.PixelFormat.Format32bppPArgb,
                                                wb.BackBuffer);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); // Good old Graphics
            DrawEverything(g);
            //g.DrawLine( ... ); // etc...

            // ...and finally:
            g.Dispose();
            string temp  = System.Environment.GetEnvironmentVariable("TEMP");
            string sFile = temp + "\\snapshot.png";

            bmp.Save(sFile);
            bmp.Dispose();

            //wb.AddDirtyRect( ... );
            wb.Unlock();
            return(sFile);
        }
예제 #7
0
 void OnLoaded(object sender, RoutedEventArgs e)
 {
     Transform  = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
     Controller = new GameController(this);
     Controller.Startup(new FileStorage());
     SkiaView.InvalidateVisual();
 }
예제 #8
0
        public void DrawCellText(Cell cell, SolidColor textColor, DrawMode drawMode, double scale)
        {
            var sheet = cell.Worksheet;

            if (sheet == null)
            {
                return;
            }

            //if (cell.formattedText == null)
            //{
            //	sheet.UpdateCellFont(cell);
            //}

            if (cell.InnerStyle.RotationAngle != 0)
            {
                System.Windows.Media.Matrix m = System.Windows.Media.Matrix.Identity;
                m.Rotate(cell.InnerStyle.RotationAngle);
                m.Translate(cell.Bounds.OriginX * sheet.ScaleFactor, cell.Bounds.OriginY * sheet.ScaleFactor);

                this.PushTransform(m);
                this.PlatformGraphics.DrawText(cell.formattedText, new WPFPoint(-cell.formattedText.Width * 0.5, -cell.formattedText.Height * 0.5));
                this.PopTransform();
            }
            else
            {
                this.PlatformGraphics.DrawText(cell.formattedText, cell.TextBounds.Location);
            }
        }
예제 #9
0
        public override void Manipulate(System.Windows.Input.ManipulationDeltaEventArgs args, ref System.Windows.Media.Matrix matrix)
        {
            base.Manipulate(args, ref matrix);

            ManipulationDelta delta  = args.DeltaManipulation;
            Point             center = args.ManipulationOrigin;


            Vector scale = new Vector(matrix.M11, matrix.M22);

            if (MaxScale == 0.0 || MaxScale > scale.Length)
            {
                //matrix.ScaleAtPrepend(delta.Scale.X, delta.Scale.Y, center.X, center.Y);
                System.Windows.Media.Matrix m = new System.Windows.Media.Matrix(matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.OffsetX, matrix.OffsetY);
                //m.ScalePrepend(delta.Scale.X, delta.Scale.Y);

                matrix.ScalePrepend(delta.Scale.X, delta.Scale.Y);

                if (!this.ElementInsideContainer() && (delta.Scale.X > 1 || delta.Scale.Y > 1))
                {
                    if (lastPositionInside != null)
                    {
                        matrix = m;
                        //matrix = new System.Windows.Media.Matrix(lastPositionInside.M11, lastPositionInside.M12, lastPositionInside.M21, lastPositionInside.M22, lastPositionInside.OffsetX, lastPositionInside.OffsetY);
                    }
                    args.Handled = true;
                }
                else
                {
                    lastPositionInside = new System.Windows.Media.Matrix(matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.OffsetX, matrix.OffsetY);
                }
            }
        }
예제 #10
0
파일: MathUtil.cs 프로젝트: vincenthamm/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(Matrix matrix, Point p)
 {
     matrix.Invert();
     s_tempPts[0] = p;
     matrix.Transform(s_tempPts);
     return s_tempPts[0];
 }
예제 #11
0
        /// <summary>
        /// Offset a Point[]
        /// </summary>
        /// <param name="points"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static Point[] Offset(this Point[] points, double distance)
        {
            List <Point>?offsetPointList = new List <Point>();
            int          segmentCount    = points.Length - 1;

            for (int si = 0; si < segmentCount; ++si)
            {
                Point  pointA  = points[si];
                Point  pointB  = points[si + 1];
                Vector tangent = (pointB - pointA);
                tangent.Normalize();
                Matrix matrix = new System.Windows.Media.Matrix();
                matrix.Rotate(-90.0);
                Vector normal = Vector.Multiply(tangent, matrix);
                Vector offset = new Vector(normal.X * distance, normal.Y * distance);

                offsetPointList.Add(new Point(pointA.X + offset.X, pointA.Y + offset.Y));
                offsetPointList.Add(new Point(pointB.X + offset.X, pointB.Y + offset.Y));
            }

            Point[]? offsetPoints = offsetPointList.ToArray();
            if (points.IsClosed())
            {
                offsetPoints = offsetPoints.Close();
            }

            return(offsetPoints);
        }
예제 #12
0
파일: MathUtil.cs 프로젝트: vincenthamm/ATF
 /// <summary>
 /// Creates a GDI transform representing a non-uniform scale and translation</summary>
 /// <param name="translation">Translation</param>
 /// <param name="xScale">X scale</param>
 /// <param name="yScale">Y scale</param>
 /// <returns>GDI transform representing a non-uniform scale and translation</returns>
 public static Matrix GetTransform(Point translation, double xScale, double yScale)
 {
     Matrix transform = new Matrix();
     transform.Translate(translation.X, translation.Y);
     transform.Scale(xScale, yScale);
     return transform;
 }
예제 #13
0
 internal static MatrixTransform MakeMatrixTransform(Matrix xf)
 {
     return new MatrixTransform()
       {
     Matrix = xf
       };
 }
        public override Drawing.Matrix GetCTM(object backend)
        {
            var c = (DrawingContext)backend;

            SWM.Matrix m = c.CurrentTransform;
            return(new Drawing.Matrix(m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY));
        }
예제 #15
0
      /// <summary>Creates a new <see cref=""/> instance.</summary>
      public DiagramPaginator(DiagramCanvas source, Size printSize) {
         PageSize = printSize;
         _contentSize = new Size(printSize.Width - 2 * Margin, printSize.Height - 2 * Margin);
         _frameRect = new Rect(new Point(Margin, Margin), _contentSize);
         _frameRect.Inflate(1, 1);
         _framePen = new Pen(Brushes.Black, 0.1);

         var scale = 0.25; // hardcoded zoom for printing
         var bounds = new Rect(0, 0, source.ActualWidth, source.ActualHeight);
         _pageCountX = (int)((bounds.Width * scale) / _contentSize.Width) + 1;
         _pageCountY = (int)((bounds.Height * scale) / _contentSize.Height) + 1;

         // Transformation to borderless print size
         var matrix = new Matrix();
         matrix.Translate(-bounds.Left, -bounds.Top);
         matrix.Scale(scale, scale);
         matrix.Translate((_pageCountX * _contentSize.Width - bounds.Width * scale) / 2, (_pageCountY * _contentSize.Height - bounds.Height * scale) / 2);

         // Create a new visual
         var printImage = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, 96, 96, PixelFormats.Pbgra32);
         printImage.Render(source);

         var printVisual = new DrawingVisual();
         var printContext = printVisual.RenderOpen();
         printContext.PushTransform(new MatrixTransform(matrix));
         printContext.DrawImage(printImage, bounds);
         printContext.Close();
         _printDiagram = printVisual.Drawing;
      }
예제 #16
0
        protected DpiHelper(double logicalDpi)
        {
            LogicalDpiX = logicalDpi;
            LogicalDpiY = logicalDpi;
            IntPtr dc = NativeMethods.User32.GetDC(IntPtr.Zero);

            if (dc != IntPtr.Zero)
            {
                DeviceDpiX = NativeMethods.Gdi32.GetDeviceCaps(dc, 88);
                DeviceDpiY = NativeMethods.Gdi32.GetDeviceCaps(dc, 90);
                NativeMethods.User32.ReleaseDC(IntPtr.Zero, dc);
            }
            else
            {
                DeviceDpiX = LogicalDpiX;
                DeviceDpiY = LogicalDpiY;
            }
            System.Windows.Media.Matrix identity1 = System.Windows.Media.Matrix.Identity;
            System.Windows.Media.Matrix identity2 = System.Windows.Media.Matrix.Identity;
            identity1.Scale(DeviceDpiX / LogicalDpiX, DeviceDpiY / LogicalDpiY);
            identity2.Scale(LogicalDpiX / DeviceDpiX, LogicalDpiY / DeviceDpiY);
            _transformFromDevice = new MatrixTransform(identity2);
            _transformFromDevice.Freeze();
            _transformToDevice = new MatrixTransform(identity1);
            _transformToDevice.Freeze();
        }
예제 #17
0
        public void Draw(Mesh mesh)
        {
            if (mesh != null && mesh.Fragment != null && mesh.VertexBuffer != null && mesh.IndexBuffer != null)
            {
                WP.View = mesh.Projection == Mesh.ProjectionType.Unit ? UnitView : PixelView;

                System.Windows.Media.Matrix world = System.Windows.Media.Matrix.Multiply(mesh.LocalTransform, mesh.WorldTransform);
                WP.World = Utils.Convert(world);

                SharpDX.Matrix vw   = SharpDX.Matrix.Multiply(WP.World, WP.View);
                Vector4        posA = Vector2.Transform(new Vector2((float)mesh.AABB.Left, (float)mesh.AABB.Bottom), vw);
                Vector4        posB = Vector2.Transform(new Vector2((float)mesh.AABB.Right, (float)mesh.AABB.Top), vw);

                float minX = Math.Min(posA.X, posB.X);
                float maxX = Math.Max(posA.X, posB.X);

                if (maxX < -1f || minX > 1f)
                {
                    return;
                }


                PrimitiveTopology topology = mesh.Geometry == Mesh.GeometryType.Polygons ? PrimitiveTopology.TriangleList : PrimitiveTopology.LineList;
                int indexCount             = (mesh.Geometry == Mesh.GeometryType.Polygons ? 3 : 2) * mesh.PrimitiveCount;

                SetAlphaBlend(mesh.UseAlpha);
                Setup(mesh.Fragment, mesh.VertexBufferBinding, mesh.IndexBuffer, topology);
                RenderDevice.ImmediateContext.DrawIndexed(indexCount, 0, 0);
                SetAlphaBlend(false);

                Statistics.Add(mesh.PrimitiveCount);
            }
        }
예제 #18
0
파일: MathUtil.cs 프로젝트: vincenthamm/ATF
 /// <summary>
 /// Transforms vector's x-coordinate with assumed 0.0 y-coordinate</summary>
 /// <param name="matrix">Matrix representing transform, as from system A to system B</param>
 /// <param name="x">X-coordinate of a vector in coordinate system A</param>
 /// <returns>X-coordinate of a vector in coordinate system B</returns>
 public static double TransformVector(Matrix matrix, double x)
 {
     s_tempVcs[0].X = x;
     s_tempVcs[0].Y = 0.0f;
     matrix.Transform(s_tempVcs);
     return s_tempVcs[0].X;
 }
예제 #19
0
 internal static Matrix Multiply(Matrix m1, Matrix m2)
 {
     return new Matrix(
         (m1.M11 * m2.M11) + (m1.M12 * m2.M21), (m1.M11 * m2.M12) + (m1.M12 * m2.M22),
         (m1.M21 * m2.M11) + (m1.M22 * m2.M21), (m1.M21 * m2.M12) + (m1.M22 * m2.M22),
         (m1.OffsetX * m2.M11) + (m1.OffsetY * m2.M21) + m2.OffsetX, (m1.OffsetX * m2.M12) + (m1.OffsetY * m2.M22) + m2.OffsetY);
 }
        private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
        {
            // MINMAXINFO structure
            Win32.MINMAXINFO mmi = (Win32.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(Win32.MINMAXINFO));

            // Get handle for nearest monitor to this window
            WindowInteropHelper wih = new WindowInteropHelper(this);
            IntPtr hMonitor         = Win32.MonitorFromWindow(wih.Handle, Win32.MONITOR_DEFAULTTONEAREST);

            // Get monitor info
            Win32.MONITORINFOEX monitorInfo = new Win32.MONITORINFOEX();
            monitorInfo.cbSize = Marshal.SizeOf(monitorInfo);
            Win32.GetMonitorInfo(new HandleRef(this, hMonitor), monitorInfo);

            // Get HwndSource
            HwndSource source = HwndSource.FromHwnd(wih.Handle);

            if (source == null)
            {
                // Should never be null
                throw new Exception("Cannot get HwndSource instance.");
            }
            if (source.CompositionTarget == null)
            {
                // Should never be null
                throw new Exception("Cannot get HwndTarget instance.");
            }

            // Get transformation matrix
            System.Windows.Media.Matrix matrix = source.CompositionTarget.TransformFromDevice;

            // Convert working area
            Win32.RECT           workingArea        = monitorInfo.rcWork;
            System.Windows.Point dpiIndependentSize =
                matrix.Transform(new System.Windows.Point(
                                     workingArea.Right - workingArea.Left,
                                     workingArea.Bottom - workingArea.Top
                                     ));

            // Convert minimum size
            System.Windows.Point dpiIndenpendentTrackingSize = matrix.Transform(new System.Windows.Point(
                                                                                    this.MinWidth,
                                                                                    this.MinHeight
                                                                                    ));

            // Set the maximized size of the window
            mmi.ptMaxSize.x = (int)dpiIndependentSize.X;
            mmi.ptMaxSize.y = (int)dpiIndependentSize.Y;

            // Set the position of the maximized window
            mmi.ptMaxPosition.x = 0;
            mmi.ptMaxPosition.y = 0;

            // Set the minimum tracking size
            mmi.ptMinTrackSize.x = (int)dpiIndenpendentTrackingSize.X;
            mmi.ptMinTrackSize.y = (int)dpiIndenpendentTrackingSize.Y;

            Marshal.StructureToPtr(mmi, lParam, true);
        }
예제 #21
0
 /// <summary>
 /// Rotates the quadrilateral clockwise around the specified point.
 /// </summary>
 /// <param name="degrees">angle in degrees (clockwise)</param>
 /// <param name="center">center point around which the quadrilateral is rotated</param>
 public void Rotate(double degrees, Point center) {
   Matrix mat = new Matrix();
   // NOTE: Matrix.RotateAt() rotates clockwise.
   mat.RotateAt(degrees, center.X, center.Y);
   this.A = mat.Transform(this.A);
   this.B = mat.Transform(this.B);
   this.C = mat.Transform(this.C);
   this.D = mat.Transform(this.D);
 }
예제 #22
0
        private Point TranslatePoint(Point p, double xOffset, double yOffset, double scaleX, double scaleY)
        {
            System.Windows.Media.Matrix transformationMatrix = new System.Windows.Media.Matrix(scaleX, 0, 0, scaleX, xOffset, yOffset);
            System.Windows.Point        point = new System.Windows.Point(p.X, p.Y);

            var mappedPoint = System.Windows.Point.Multiply(point, transformationMatrix);

            return(new Point((int)mappedPoint.X, (int)mappedPoint.Y));
            //return new Point((int)(p.X + xOffset), (int)(p.Y + yOffset));
        }
예제 #23
0
		public UnmanagedMatrix (Matrix m) :
			this ()
		{
			SetValue (UnmanagedMatrix.M11Property, m.M11);
			SetValue (UnmanagedMatrix.M12Property, m.M12);
			SetValue (UnmanagedMatrix.M21Property, m.M21);
			SetValue (UnmanagedMatrix.M22Property, m.M22);
			SetValue (UnmanagedMatrix.OffsetXProperty, m.OffsetX);
			SetValue (UnmanagedMatrix.OffsetYProperty, m.OffsetY);
		}
예제 #24
0
        private Point GetTextureCoordinate(double t, double y)
        {
            var TYtoUV = new Matrix();
            TYtoUV.Scale(1/(2*Math.PI), -0.5);

            var p = new Point(t, y);
            p = p*TYtoUV;

            return p;
        }
        public static Rectangle CalculateWindowPosOnAvailableScreen(Rectangle origRect)
        {
            Rectangle screenRect            = System.Windows.Forms.SystemInformation.VirtualScreen;
            Rectangle origRectInScreenCoord = origRect;

            System.Windows.Media.Matrix conversionMatrix = new System.Windows.Media.Matrix();
            bool matrixInitialized = false;

            try
            {
                if (System.Windows.Application.Current.MainWindow != null)
                {
                    conversionMatrix = PresentationSource.FromVisual(System.Windows.Application.Current.MainWindow).CompositionTarget.TransformFromDevice;
                    if (conversionMatrix.M11 != 0 && conversionMatrix.M22 != 0)
                    {
                        matrixInitialized = true;
                    }
                }
            }
            catch
            {
                matrixInitialized = false;
            }

            if (matrixInitialized)
            {
                origRectInScreenCoord.X      = (int)((double)origRect.X / conversionMatrix.M11);
                origRectInScreenCoord.Y      = (int)((double)origRect.Y / conversionMatrix.M22);
                origRectInScreenCoord.Width  = (int)((double)origRect.Width / conversionMatrix.M11);
                origRectInScreenCoord.Height = (int)((double)origRect.Height / conversionMatrix.M22);
            }

            if (screenRect.Contains(origRectInScreenCoord))
            {
                return(origRect);
            }
            else
            {
                Rectangle newRect = new Rectangle(origRectInScreenCoord.Left, origRectInScreenCoord.Top, origRectInScreenCoord.Width, origRectInScreenCoord.Height);
                newRect.Width  = (origRectInScreenCoord.Width < screenRect.Width) ? (int)origRectInScreenCoord.Width : (int)2 * screenRect.Width / 3;
                newRect.Height = (origRectInScreenCoord.Height < screenRect.Height) ? (int)origRectInScreenCoord.Height : (int)2 * screenRect.Height / 3;
                newRect.X      = (int)(screenRect.X + (screenRect.Width - newRect.Width) / 2);
                newRect.Y      = (int)(screenRect.Y + (screenRect.Height - newRect.Height) / 2);

                if (matrixInitialized)
                {
                    newRect.X      = (int)(newRect.X * conversionMatrix.M11);
                    newRect.Y      = (int)(newRect.Y * conversionMatrix.M22);
                    newRect.Width  = (int)((double)newRect.Width * conversionMatrix.M11);
                    newRect.Height = (int)((double)newRect.Height * conversionMatrix.M22);
                }

                return(newRect);
            }
        }
예제 #26
0
파일: Util.cs 프로젝트: mingyaaaa/xwt
        public static double GetScaleFactor(this SWM.Visual self)
        {
            PresentationSource source = PresentationSource.FromVisual(self);

            if (source == null)
            {
                return(1);
            }

            SWM.Matrix m = source.CompositionTarget.TransformToDevice;
            return(m.M11);
        }
예제 #27
0
파일: Util.cs 프로젝트: mingyaaaa/xwt
        public static Size GetPixelRatios(this SWM.Visual self)
        {
            var source = PresentationSource.FromVisual(self);

            if (source == null)
            {
                return(new Size(1, 1));
            }

            SWM.Matrix m = source.CompositionTarget.TransformToDevice;
            return(new Size(m.M11, m.M22));
        }
예제 #28
0
        private Point GetTextureCoordinate(double t, double y)
        {
            var TYtoUV = new Matrix();

            TYtoUV.Scale(1 / (2 * Math.PI), -0.5);

            var p = new Point(t, y);

            p = p * TYtoUV;

            return(p);
        }
예제 #29
0
        public void FindLines(StreamGeometry geometry, bool stroke, bool fill, Matrix trans) 
        {
            Debug.Assert(stroke || fill, "should not be a nop"); 

            _transform = trans;
            _fill      = fill;
            _stroke    = stroke; 

            PathGeometry.ParsePathGeometryData(geometry.GetPathGeometryData(), this); 
 
            CheckCloseFigure();
        } 
예제 #30
0
        private static void UpdateRenderTransform(UIElement renderedGeometry, IViewport viewport)
        {
            var matrix = new XamlMedia.Matrix();

            if (viewport.IsRotated)
            {
                var center = viewport.WorldToScreen(viewport.Center);
                MatrixHelper.RotateAt(ref matrix, viewport.Rotation, center.X, center.Y);
            }

            renderedGeometry.RenderTransform = new XamlMedia.MatrixTransform {
                Matrix = matrix
            };
        }
        static DpiHelper()
        {
            using (SafeDC desktop = SafeDC.GetDesktop()) {
                // Can get these in the static constructor.  They shouldn't vary window to window,
                // and changing the system DPI requires a restart.
                int pixelsPerInchX = NativeMethods.GetDeviceCaps(desktop, DeviceCap.LOGPIXELSX);
                int pixelsPerInchY = NativeMethods.GetDeviceCaps(desktop, DeviceCap.LOGPIXELSY);

                _transformToDip = Matrix.Identity;
                _transformToDip.Scale(96d / (double)pixelsPerInchX, 96d / (double)pixelsPerInchY);
                _transformToDevice = Matrix.Identity;
                _transformToDevice.Scale((double)pixelsPerInchX / 96d, (double)pixelsPerInchY / 96d);
            }
        }
예제 #32
0
 internal static Matrix CreateMatrix(GeneralTransform transform)
 {
     if (transform != null && !IsIdentity(transform))
     {
         Point offset = transform.Transform(new Point(0, 0));
         Point i = transform.Transform(new Point(1, 0)).Minus(offset);
         Point j = transform.Transform(new Point(0, 1)).Minus(offset);
         Matrix matrix = new Matrix(i.X, i.Y, j.X, j.Y, offset.X, offset.Y);
         return matrix;
     }
     else
     {
         return Matrix.Identity;
     }
 }
예제 #33
0
    static DpiHelper()
    {
      var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
      var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static);

      var pixelsPerInchX = (int) dpiXProperty.GetValue(null, null); //SystemParameters.DpiX;
      DpiX = (double) pixelsPerInchX;
      var pixelsPerInchY = (int) dpiYProperty.GetValue(null, null); //SystemParameters.Dpi;
      DpiY = (double) pixelsPerInchY;

      _transformToLogical = Matrix.Identity;
      _transformToLogical.Scale(96d/(double) pixelsPerInchX, 96d/(double) pixelsPerInchY);
      _transformToDevice = Matrix.Identity;
      _transformToDevice.Scale((double) pixelsPerInchX/96d, (double) pixelsPerInchY/96d);
    }
        public static Rect GetLeftScreenBounds(Visual visual)
        {
            Rect returnRect = new Rect(0, 0, 0, 0);

            if (Screen.AllScreens.Length > 0)
            {
                returnRect.X      = Screen.AllScreens[0].Bounds.X;
                returnRect.Y      = Screen.AllScreens[0].Bounds.Y;
                returnRect.Width  = Screen.AllScreens[0].Bounds.Width;
                returnRect.Height = Screen.AllScreens[0].Bounds.Height;

                for (int i = 1; i < Screen.AllScreens.Length; ++i)
                {
                    if (Screen.AllScreens[i].Bounds.X < returnRect.X)
                    {
                        returnRect.X      = Screen.AllScreens[i].Bounds.X;
                        returnRect.Y      = Screen.AllScreens[i].Bounds.Y;
                        returnRect.Width  = Screen.AllScreens[i].Bounds.Width;
                        returnRect.Height = Screen.AllScreens[i].Bounds.Height;
                    }
                }
            }

            double dpiX = 1.0;
            double dpiY = 1.0;

            try
            {
                System.Windows.Media.Matrix conversionMatrix = new System.Windows.Media.Matrix();
                conversionMatrix = PresentationSource.FromVisual(visual).CompositionTarget.TransformFromDevice;
                if (conversionMatrix.M11 != 0)
                {
                    dpiX = conversionMatrix.M11;
                }
                if (conversionMatrix.M22 != 0)
                {
                    dpiY = conversionMatrix.M22;
                }
            }
            catch { }

            returnRect.X      = returnRect.X * dpiX;
            returnRect.Y      = returnRect.Y * dpiY;
            returnRect.Width  = returnRect.Width * dpiX;
            returnRect.Height = returnRect.Height * dpiY;

            return(returnRect);
        }
예제 #35
0
        public void Transform(Vector2 position, Vector2 scale, Vector2 origin,
                              Vector2 sourceOrigin, Vector2 sourceSize, float rotation,
                              SpriteEffects spriteEffects, ref Matrix matrix)
        {
            // Performance thoughts:
            // These conditionals could be removed by bit-twiddling to integer and then casting to double
            // But how does that compare to the performance hit of converting int to double?
            // (Does it matter? Doesn't seem to...)
            double reflectX          = ((spriteEffects & SpriteEffects.FlipHorizontally) != 0) ? -1 : 1;
            double reflectY          = ((spriteEffects & SpriteEffects.FlipVertically) != 0) ? -1 : 1;
            double reflectTranslateX = ((spriteEffects & SpriteEffects.FlipHorizontally) != 0) ? -sourceSize.X : 0;
            double reflectTranslateY = ((spriteEffects & SpriteEffects.FlipVertically) != 0) ? -sourceSize.Y : 0;

            // Matrix Operations:
            //Transform2D t = Transform2D.Identity;
            //t *= Transform2D.CreateTranslate(new Vector2(reflectTranslateX - sourceOrigin.X, reflectTranslateY - sourceOrigin.Y));
            //t *= Transform2D.CreateScale(new Vector2(reflectX, reflectY));
            //t *= Transform2D.CreateTranslateScaleRotate(-origin, new Vector2(scale.X, scale.Y), rotation);
            //t *= Transform2D.CreateTranslate(position);
            //transform.Matrix = t.AsSilverlightMatrix;


            // Inlined Version (Rough maths is in Book 2010A)
            double cos = Math.Cos(rotation);
            double sin = Math.Sin(rotation);

            double A = cos * scale.X; double B = sin * scale.X;
            double C = -sin * scale.Y; double D = cos * scale.Y;
            double pX = (reflectX * (reflectTranslateX - sourceOrigin.X) - origin.X);
            double pY = (reflectY * (reflectTranslateY - sourceOrigin.Y) - origin.Y);

            double M11     = reflectX * A;
            double M12     = reflectX * B;
            double M21     = reflectY * C;
            double M22     = reflectY * D;
            double OffsetX = pX * A + pY * C + position.X;
            double OffsetY = pX * B + pY * D + position.Y;

            // Multiply with transform matrix (assume it is Affine 2D, this is Asserted in SpriteBatch.Begin)
            SWM.Matrix m = new System.Windows.Media.Matrix();
            m.M11            = M11 * matrix.M11 + M12 * matrix.M21;
            m.M12            = M11 * matrix.M12 + M12 * matrix.M22;
            m.M21            = M21 * matrix.M11 + M22 * matrix.M21;
            m.M22            = M21 * matrix.M12 + M22 * matrix.M22;
            m.OffsetX        = OffsetX * matrix.M11 + OffsetY * matrix.M21 + matrix.M41;
            m.OffsetY        = OffsetX * matrix.M12 + OffsetY * matrix.M22 + matrix.M42;
            transform.Matrix = m;
        }
예제 #36
0
        public static double GetWindowsScaleTransform(this Visual visual)
        {
            Matrix m = Matrix.Identity;
            var    presentationSource = PresentationSource.FromVisual(visual);

            if (presentationSource != null)
            {
                if (presentationSource.CompositionTarget != null)
                {
                    m = presentationSource.CompositionTarget.TransformToDevice;
                }
            }
            double totalTransform = m.M11;

            return(totalTransform);
        }
예제 #37
0
파일: Sprite.cs 프로젝트: mikairi/SoshiLand
        public void Transform(Vector2 position, Vector2 scale, Vector2 origin,
				Vector2 sourceOrigin, Vector2 sourceSize, float rotation,
				SpriteEffects spriteEffects, ref Matrix matrix)
        {
            // Performance thoughts:
            // These conditionals could be removed by bit-twiddling to integer and then casting to double
            // But how does that compare to the performance hit of converting int to double?
            // (Does it matter? Doesn't seem to...)
            double reflectX = ((spriteEffects & SpriteEffects.FlipHorizontally) != 0) ? -1 : 1;
            double reflectY = ((spriteEffects & SpriteEffects.FlipVertically)   != 0) ? -1 : 1;
            double reflectTranslateX = ((spriteEffects & SpriteEffects.FlipHorizontally) != 0) ? -sourceSize.X : 0;
            double reflectTranslateY = ((spriteEffects & SpriteEffects.FlipVertically)   != 0) ? -sourceSize.Y : 0;

            // Matrix Operations:
            //Transform2D t = Transform2D.Identity;
            //t *= Transform2D.CreateTranslate(new Vector2(reflectTranslateX - sourceOrigin.X, reflectTranslateY - sourceOrigin.Y));
            //t *= Transform2D.CreateScale(new Vector2(reflectX, reflectY));
            //t *= Transform2D.CreateTranslateScaleRotate(-origin, new Vector2(scale.X, scale.Y), rotation);
            //t *= Transform2D.CreateTranslate(position);
            //transform.Matrix = t.AsSilverlightMatrix;

            // Inlined Version (Rough maths is in Book 2010A)
            double cos = Math.Cos(rotation);
            double sin = Math.Sin(rotation);

            double A =  cos * scale.X; double B = sin * scale.X;
            double C = -sin * scale.Y; double D = cos * scale.Y;
            double pX = (reflectX * (reflectTranslateX - sourceOrigin.X) - origin.X);
            double pY = (reflectY * (reflectTranslateY - sourceOrigin.Y) - origin.Y);

            double M11 = reflectX * A;
            double M12 = reflectX * B;
            double M21 = reflectY * C;
            double M22 = reflectY * D;
            double OffsetX = pX * A + pY * C + position.X;
            double OffsetY = pX * B + pY * D + position.Y;

            // Multiply with transform matrix (assume it is Affine 2D, this is Asserted in SpriteBatch.Begin)
            SWM.Matrix m = new System.Windows.Media.Matrix();
            m.M11 = M11 * matrix.M11 + M12 * matrix.M21;
            m.M12 = M11 * matrix.M12 + M12 * matrix.M22;
            m.M21 = M21 * matrix.M11 + M22 * matrix.M21;
            m.M22 = M21 * matrix.M12 + M22 * matrix.M22;
            m.OffsetX = OffsetX * matrix.M11 + OffsetY * matrix.M21 + matrix.M41;
            m.OffsetY =	OffsetX * matrix.M12 + OffsetY * matrix.M22 + matrix.M42;
            transform.Matrix = m;
        }
예제 #38
0
        void border_MouseUp(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement border = sender as FrameworkElement;

            Console.WriteLine("border_MouseUp:" + touchPad.Children.IndexOf(border));

            System.Windows.Media.Matrix m = border.RenderTransform.Value;

            border.Opacity = 1;
            border.ReleaseMouseCapture();

            //检查操作
            this.CheckManipulationDelete();
            this.CheckManipulationDoubleClick();

            e.Handled = true;
        }
예제 #39
0
        public Graphics.Size MeasureCellText(Cell cell, DrawMode drawMode, double scale)
        {
            if (cell.InnerStyle.RotationAngle != 0)
            {
                System.Windows.Media.Matrix m = System.Windows.Media.Matrix.Identity;

                double   hw = cell.formattedText.Width * 0.5, hh = cell.formattedText.Height * 0.5;
                WPFPoint p1 = new WPFPoint(-hw, -hh), p2 = new WPFPoint(hw, hh);
                m.Rotate(cell.InnerStyle.RotationAngle);
                p1 *= m; p2 *= m;
                return(new Graphics.Size(Math.Abs(p1.X - p2.X), Math.Abs(p1.Y - p2.Y)));
            }
            else
            {
                return(new Graphics.Size(cell.formattedText.Width, cell.formattedText.Height));
            }
        }
예제 #40
0
        protected Vector CalculateB(Vector vectorP, Vector vectorM, double r)
        {
            Vector vectorC = vectorM - vectorP;
            Vector vectorB;
            Vector vectorR;

            float b = (float)Math.Sqrt(vectorC.LengthSquared - r * r);

            System.Windows.Media.Matrix m = new System.Windows.Media.Matrix(-r, -b, b, -r, 0, 0);

            vectorR = path.MatrixMultiplication(vectorC, m);
            vectorR = (r / vectorC.LengthSquared) * vectorR;

            vectorB = vectorM + vectorR - vectorP;

            return(vectorB);
        }
예제 #41
0
        /// <summary>
        /// Get the arc points to connect two line segments
        /// </summary>
        /// <param name="pointA"></param>
        /// <param name="pointB"></param>
        /// <param name="pointC"></param>
        /// <param name="pointD"></param>
        /// <returns></returns>
        public static List <Point> GetConnectingArcPoints(Point pointA, Point pointB, Point pointC, Point pointD)
        {
            List <Point>?results = new List <Point>();

            if (!IsIntersection(pointA, pointB, pointC, pointD, out Point intersection))
            {
                return(results);
            }

            Vector tangent1 = (pointB - pointA);

            tangent1.Normalize();
            Matrix matrix = new System.Windows.Media.Matrix();

            matrix.Rotate(90.0);
            Vector negativenormal1 = Vector.Multiply(tangent1, matrix);
            Vector tangent2        = (pointD - pointC);

            tangent2.Normalize();
            Vector negativenormal2 = Vector.Multiply(tangent2, matrix);

            if (IsIntersection(pointB, new Point(pointB.X + negativenormal1.X, pointB.Y + negativenormal1.Y),
                               pointC, new Point(pointC.X + negativenormal2.X, pointC.Y + negativenormal2.Y), out Point arc_origin))
            {
                double angle = Vector.AngleBetween(pointB - arc_origin, pointC - arc_origin);
                if (Abs(angle) > 5.0)
                {
                    double theta_div = Round(Abs(angle) / 5.0, 0) + 1;
                    if (theta_div > 1)
                    {
                        double delta = angle / theta_div;
                        for (double i = 1; i < theta_div; ++i)
                        {
                            Matrix rotationMatrix = new System.Windows.Media.Matrix();
                            rotationMatrix.Rotate(delta * i);
                            Vector arc_vector = pointB - arc_origin;
                            arc_vector = Vector.Multiply(arc_vector, rotationMatrix);
                            results.Add(new Point(arc_origin.X + arc_vector.X, arc_origin.Y + arc_vector.Y));
                        }
                    }
                }
            }

            return(results);
        }
예제 #42
0
        void SetZoom(double zoom)
        {
            MainInkCanvas.Width = zoom * 1000;
            var scale = pdf.scale;

            double ver_offset = scrollViewer.VerticalOffset;
            double view_h     = scrollViewer.ViewportHeight;

            double ra = (ver_offset + view_h / 2) / scrollViewer.ExtentHeight;

            double top = 0;

            for (int i = 0; i < pdf.pages.Count; i++)
            {
                var img  = GetImageWithPage(i);
                var page = pdf.pages[i];
                img.Top.Width  = zoom * scale * page.width;
                img.Top.Height = zoom * scale * page.height / 2;
                page.Top       = top;
                InkCanvas.SetTop(img.Top, top);
                top += zoom * scale * page.height / 2;
                img.Bottom.Width  = zoom * scale * page.width;
                img.Bottom.Height = zoom * scale * page.height / 2;
                InkCanvas.SetTop(img.Bottom, top);
                top += zoom * scale * page.height / 2;

                if (Math.Abs(pdf.last_render_zoom - zoom) >= 0.4)
                {
                    pdf.dirt = true;
                }
            }
            var ver_offset_new = top * ra - view_h / 2;

            scrollViewer.ScrollToVerticalOffset(ver_offset_new);
            MainInkCanvas.Height = top;
            var ma = new System.Windows.Media.Matrix();

            ma.ScaleAt(1 / render_zoom, 1 / render_zoom, 0, 0);
            //ma.Translate(-render_zoom / 2 * 1000, 0);
            ma.ScaleAt(zoom, zoom, 0, 0);
            MainInkCanvas.Strokes.Transform(ma, false);

            render_zoom = zoom;
            CheckInView(ver_offset_new, view_h);
        }
예제 #43
0
        /// <summary>
        /// Draw outline on image
        /// </summary>
        /// <param name="strategy">is text strategy</param>
        /// <param name="image">is the image to be draw upon</param>
        /// <param name="offset">offsets the text (typically used for shadows)</param>
        /// <param name="textContext">is text context</param>
        /// <returns>true if successful</returns>
        public static bool DrawTextImage(
            ITextStrategy strategy,
            ref System.Windows.Media.Imaging.WriteableBitmap image,
            System.Windows.Point offset,
            TextContext textContext,
            System.Windows.Media.Matrix mat)
        {
            if (strategy == null || image == null || textContext == null)
            {
                return(false);
            }

            RenderTargetBitmap bmp = new RenderTargetBitmap((int)(image.Width), (int)(image.Height), 96, 96, PixelFormats.Pbgra32);

            DrawingVisual drawingVisual = new DrawingVisual();

            DrawingContext drawingContext = drawingVisual.RenderOpen();

            MatrixTransform mat_trans = new MatrixTransform();

            mat_trans.Matrix = mat;

            drawingContext.PushTransform(mat_trans);

            drawingContext.DrawImage(image, new Rect(0.0, 0.0, image.Width, image.Height));

            bool bRet = strategy.DrawString(drawingContext,
                                            textContext.fontFamily,
                                            textContext.fontStyle,
                                            textContext.fontWeight,
                                            textContext.nfontSize,
                                            textContext.pszText,
                                            new System.Windows.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y),
                                            textContext.ci);

            drawingContext.Pop();

            drawingContext.Close();

            bmp.Render(drawingVisual);

            image = new System.Windows.Media.Imaging.WriteableBitmap(bmp);

            return(bRet);
        }
예제 #44
0
        public void Begin(GraphicsDevice device, SpriteBlendMode blendMode, SpriteSortMode sortMode, SaveStateMode stateMode, Local.Matrix transformMatrix)
        {

            //transformMatrix = Matrix.Identity;


            Rect rect = new Rect(
                (device.Viewport.X),
                (device.Viewport.Y),
                device.Viewport.Width,
                device.Viewport.Height);

            if (rect != lastRect || !MatricesAreEqual(transformMatrix, lastMatrix))
            {
                transformMatrix.M41 += device.Viewport.X;
                transformMatrix.M42 += device.Viewport.Y;
                MatrixTransform matrixTransform = new MatrixTransform();
                System.Windows.Media.Matrix matrix = new System.Windows.Media.Matrix(
                   transformMatrix.M11,
                    transformMatrix.M12,
                    transformMatrix.M21,
                    transformMatrix.M22,
                    transformMatrix.M41,
                    transformMatrix.M42);
                matrixTransform.Matrix = matrix;
                System.Windows.Media.RectangleGeometry rectangleGeometry = new System.Windows.Media.RectangleGeometry();
                rectangleGeometry.Rect = rect;
                MatrixTransform inverse = matrixTransform.Inverse as MatrixTransform;

                rectangleGeometry.Transform = inverse;
                Canvas.Clip = rectangleGeometry;

                matrixTransform.Matrix = matrix;
                TransformMatrix = transformMatrix;
                lastRect = rect;
                lastMatrix = transformMatrix;
                Canvas.Width = rect.Width;
                Canvas.Height = rect.Height;
            }
            InUse = true;
            Begin();
        }
예제 #45
0
        /// <summary>
        /// Generate mask image of the text strategy.
        /// </summary>
        /// <param name="strategy">is text strategy</param>
        /// <param name="width">is the mask image width</param>
        /// <param name="height">is the mask image height</param>
        /// <param name="offset">offsets the text (typically used for shadows)</param>
        /// <param name="textContext">is text context</param>
        /// <returns>a valid mask image if successful</returns>
        public static System.Windows.Media.Imaging.WriteableBitmap GenMask(
            ITextStrategy strategy,
            int width,
            int height,
            System.Windows.Point offset,
            TextContext textContext,
            System.Windows.Media.Matrix mat)
        {
            if (strategy == null || textContext == null)
            {
                return(null);
            }

            RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);

            DrawingVisual drawingVisual = new DrawingVisual();

            DrawingContext drawingContext = drawingVisual.RenderOpen();

            MatrixTransform mat_trans = new MatrixTransform();

            mat_trans.Matrix = mat;

            drawingContext.PushTransform(mat_trans);

            strategy.DrawString(drawingContext,
                                textContext.fontFamily,
                                textContext.fontStyle,
                                textContext.fontWeight,
                                textContext.nfontSize,
                                textContext.pszText,
                                new System.Windows.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y),
                                textContext.ci);

            drawingContext.Pop();

            drawingContext.Close();

            bmp.Render(drawingVisual);

            return(new System.Windows.Media.Imaging.WriteableBitmap(bmp));
        }
예제 #46
0
        /// <summary>
        /// Inverts a Matrix. The Invert functionality on the Matrix type is 
        /// internal to the framework only. Since Matrix is a struct, an out 
        /// parameter must be presented.
        /// </summary>
        /// <param name="m">The Matrix object.</param>
        /// <param name="outputMatrix">The matrix to return by an output 
        /// parameter.</param>
        /// <returns>Returns a value indicating whether the type was 
        /// successfully inverted. If the determinant is 0.0, then it cannot 
        /// be inverted and the original instance will remain untouched.</returns>
        public static bool Invert(this Matrix m, out Matrix outputMatrix)
        {
            double determinant = m.M11 * m.M22 - m.M12 * m.M21;
            if(determinant == 0.0)
            {
                outputMatrix = m;
                return false;
            }

            Matrix matCopy = m;
            m.M11 = matCopy.M22 / determinant;
            m.M12 = -1 * matCopy.M12 / determinant;
            m.M21 = -1 * matCopy.M21 / determinant;
            m.M22 = matCopy.M11 / determinant;
            m.OffsetX = (matCopy.OffsetY * matCopy.M21 - matCopy.OffsetX * matCopy.M22) / determinant;
            m.OffsetY = (matCopy.OffsetX * matCopy.M12 - matCopy.OffsetY * matCopy.M11) / determinant;

            outputMatrix = m;
            return true;
        }
예제 #47
0
        void border_MouseMove(object sender, MouseEventArgs e)
        {
            FrameworkElement border = sender as FrameworkElement;

            if (!border.IsMouseCaptured)
            {
                return;
            }

            System.Windows.Point nowPoint = Mouse.GetPosition(this);

            System.Windows.Media.Matrix m = border.RenderTransform.Value;
            m.OffsetX = startOffset.X + (nowPoint.X - startPoint.X);
            m.OffsetY = startOffset.Y + (nowPoint.Y - startPoint.Y);

            border.RenderTransform = new MatrixTransform(m);
            e.Handled = true;

            isChanged = true;
        }
        internal GraphPaginator( DrawingVisual source, Size printSize )
        {
            PageSize = printSize;

            contentSize = new Size( printSize.Width - 2 * Margin, printSize.Height - 2 * Margin );

            myFrameRect = new Rect( new Point( Margin, Margin ), contentSize );
            myFrameRect.Inflate( 1, 1 );
            myFramePen = new Pen( Brushes.Black, 0.1 );

            // Transformation to borderless print size
            var bounds = source.DescendantBounds;
            bounds.Union( source.ContentBounds );

            var m = new Matrix();
            m.Translate( -bounds.Left, -bounds.Top );

            double scale = 16; // hardcoded zoom for printing
            myPageCountX = ( int )( ( bounds.Width * scale ) / contentSize.Width ) + 1;
            myPageCountY = ( int )( ( bounds.Height * scale ) / contentSize.Height ) + 1;
            m.Scale( scale, scale );
        
            // Center on available pages
            m.Translate( ( myPageCountX * contentSize.Width - bounds.Width * scale ) / 2, ( myPageCountY * contentSize.Height - bounds.Height * scale ) / 2 );

            var target = new DrawingVisual();
            using( var dc = target.RenderOpen() )
            {
                dc.PushTransform( new MatrixTransform( m ) );
                dc.DrawDrawing( source.Drawing );

                foreach( DrawingVisual child in source.Children )
                {
                    dc.DrawDrawing( child.Drawing );
                }
            }
            myGraph = target.Drawing;
        }
예제 #49
0
        internal static PdfColors.RadialGradient ConvertRadialGradientBrush(RadialGradientBrush brush, double opacity, IPosition position, double width, double height)
        {
            if (width * height == 0)
            {
                return null;
            }

            var center1 = new Point(brush.GradientOrigin.X * height, brush.GradientOrigin.Y * height);
            var center2 = new Point(brush.Center.X * height, brush.Center.Y * height);
            PdfColors.RadialGradient pdfGradient = new PdfColors.RadialGradient(center1, center2, 0, height / 2);

            var matrix = new Matrix(width / height, 0, 0, 1, 0, 0);
            var newMatrix = matrix = MathHelper.Multiply(position.Matrix, matrix);
            pdfGradient.Position = new Telerik.Windows.Documents.Fixed.Model.Data.MatrixPosition(newMatrix);

            foreach (var gradientStop in brush.GradientStops)
            {
                var rgbColor = new PdfColors.RgbColor((byte)(gradientStop.Color.A * opacity), gradientStop.Color.R, gradientStop.Color.G, gradientStop.Color.B);
                pdfGradient.GradientStops.Add(new PdfColors.GradientStop(rgbColor, gradientStop.Offset));
            }

            return pdfGradient;
        }
예제 #50
0
파일: MathUtil.cs 프로젝트: vincenthamm/ATF
 /// <summary>
 /// Transforms rectangle</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="r">Rectangle</param>
 /// <returns>Transformed rectangle</returns>
 public static Rect Transform(Matrix matrix, Rect r)
 {
     s_tempPts[0] = new Point(r.Left, r.Top);
     s_tempPts[1] = new Point(r.Right, r.Bottom);
     matrix.Transform(s_tempPts);
     return new Rect(
         s_tempPts[0].X, s_tempPts[0].Y,
         s_tempPts[1].X - s_tempPts[0].X, s_tempPts[1].Y - s_tempPts[0].Y);
 }
예제 #51
0
        // Find all straight lines within a PathGeometry
        private void _ProcessOutlinePath(Matrix transform, PathGeometry pathGeom) 
        {
            PathFigureCollection pathFigures = pathGeom.Figures; 
 
            foreach (PathFigure pathFigure in pathFigures)
            { 
                PathSegmentCollection pathSegments = pathFigure.Segments;
                Point startPoint = pathFigure.StartPoint;
                Point lastPoint = startPoint;
 
                foreach (PathSegment pathSegment in pathSegments)
                { 
                    if (pathSegment is ArcSegment) 
                    {
                        lastPoint = (pathSegment as ArcSegment).Point; 
                    }
                    else if (pathSegment is BezierSegment)
                    {
                        lastPoint = (pathSegment as BezierSegment).Point3; 
                    }
                    else if (pathSegment is LineSegment) 
                    { 
                        Point endPoint = (pathSegment as LineSegment).Point;
                        _AddLine(lastPoint, endPoint, transform); 
                        lastPoint = endPoint;
                    }
                    else if (pathSegment is PolyBezierSegment)
                    { 
                        PointCollection points = (pathSegment as PolyBezierSegment).Points;
                        lastPoint = points[points.Count - 1]; 
                    } 
                    else if (pathSegment is PolyLineSegment)
                    { 
                        PointCollection points = (pathSegment as PolyLineSegment).Points;
                        foreach (Point point in points)
                        {
                            _AddLine(lastPoint, point, transform); 
                            lastPoint = point;
                        } 
                    } 
                    else if (pathSegment is PolyQuadraticBezierSegment)
                    { 
                        PointCollection points = (pathSegment as PolyQuadraticBezierSegment).Points;
                        lastPoint = points[points.Count - 1];
                    }
                    else if (pathSegment is QuadraticBezierSegment) 
                    {
                        lastPoint = (pathSegment as QuadraticBezierSegment).Point2; 
                    } 
                    else
                    { 
                        Debug.Assert(false);
                    }
                }
 
                if (pathFigure.IsClosed)
                { 
                     _AddLine(lastPoint, startPoint, transform); 
                }
            } 
        }
예제 #52
0
        // Check if a Geometry bound has a line shape 
        internal bool _ProcessFilledRect(Matrix transform, Rect bounds) 
        {
            const double maxLineWidth = 10; 
            const double minLineRatio = 5;

            if (bounds.Height > bounds.Width && bounds.Width < maxLineWidth && bounds.Height > bounds.Width * minLineRatio)
            { 
                double center = bounds.Left + .5 * bounds.Width;
                _AddLine(new Point(center, bounds.Top), new Point(center, bounds.Bottom), transform); 
 
                return true;
            } 
            else if (bounds.Height < maxLineWidth && bounds.Width > bounds.Height * minLineRatio)
            {
                double center = bounds.Top + .5 * bounds.Height;
                _AddLine(new Point(bounds.Left, center), new Point(bounds.Right, center), transform); 

                return true; 
            } 

            return false; 
        }
예제 #53
0
        // Check if each PathFigure within a PathGeometry has a line shape
        private void _ProcessSolidPath(Matrix transform, PathGeometry pathGeom) 
        {
            PathFigureCollection pathFigures = pathGeom.Figures; 
 
            // Single figure should already covered by bounding box check
            if ((pathFigures != null) && (pathFigures.Count > 1)) 
            {
                foreach (PathFigure pathFigure in pathFigures)
                {
                    PathGeometry pg = new PathGeometry(); 
                    pg.Figures.Add(pathFigure);
 
                    _ProcessFilledRect(transform, pg.Bounds); 
                }
            } 
        }
예제 #54
0
        /// <summary>
        /// ����������֮��������ͷ
        /// </summary>
        /// <param name="pathfig">��ͷ���ڵ���״</param>
        /// <param name="startPoint">��ʼ��</param>
        /// <param name="endPoint">������</param>
        private void CalculateArrow(PathFigure pathfig, Point startPoint, Point endPoint)
        {
            var polyseg = pathfig.Segments[0] as PolyLineSegment;
            if (polyseg != null)
            {
                var matx = new Matrix();
                Vector vect = startPoint - endPoint;

                // ��ȡ��λ����
                vect.Normalize();
                vect *= this.ArrowLength;

                // ��ת�нǵ�һ��
                matx.Rotate(this.ArrowAngle / 2);

                // �����ϰ�μ�ͷ�ĵ�
                pathfig.StartPoint = endPoint + (vect * matx);

                polyseg.Points.Clear();
                polyseg.Points.Add(endPoint);

                matx.Rotate(-this.ArrowAngle);

                // �����°�μ�ͷ�ĵ�
                polyseg.Points.Add(endPoint + (vect * matx));
            }

            pathfig.IsClosed = this.IsArrowClosed;
        }
예제 #55
0
        public void _AddLine(Point startP, Point endP, Matrix transform) 
        { 
            startP = transform.Transform(startP);
            endP   = transform.Transform(endP); 

            if (startP.X == endP.X)
            {
                _lines.AddVertical(startP, endP); 
            }
            else if (startP.Y == endP.Y) 
            { 
                _lines.AddHorizontal(startP, endP);
            } 
        }
예제 #56
0
        public void ProcessPath(Path path, Matrix transform)
        { 
            if (path == null) 
            {
                throw new ArgumentNullException("path"); 
            }

            Geometry geom   = path.Data;
            bool     fill   = path.Fill != null; 
            bool     stroke = path.Stroke != null;
 
            if ((geom == null) || (! fill && ! stroke)) 
            {
                return; 
            }

            Transform transPath = path.RenderTransform;
 
            if (transPath != null)
            { 
                transform *= transPath.Value; 
            }
 
            // When filling, we may be able to determine from bounding box only
            if (fill && _ProcessFilledRect(transform, geom.Bounds))
            {
                fill = false; 

                if (! stroke) 
                { 
                    return;
                } 
            }

            StreamGeometry sgeo = geom as StreamGeometry;
 
            // Avoiding convert to PathGeometry if it's StreamGeometry, which can be walked
 
            if (sgeo != null) 
            {
                if (_geometryWalker == null) 
                {
                    _geometryWalker = new GeometryWalker(this);
                }
 
                _geometryWalker.FindLines(sgeo, stroke, fill, transform);
            } 
            else 
            {
                PathGeometry pathGeom = PathGeometry.CreateFromGeometry(geom); 

                if (pathGeom != null)
                {
                    if (fill) 
                    {
                        _ProcessSolidPath(transform, pathGeom); 
                    } 

                    if (stroke) 
                    {
                        _ProcessOutlinePath(transform, pathGeom);
                    }
                } 
            }
        } 
예제 #57
0
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            var li = sender as RadioButton;

            // Strings used to display results
            string syntaxString, resultType, operationString;

            switch (li?.Name)
            {
                //begin switch

                case "rb1":
                {
                    // Translates a Point by a Vector using the overloaded + operator.

                    var point1 = new Point(10, 5);
                    var vector1 = new System.Windows.Vector(20, 30);

                    var pointResult = point1 + vector1;

                    // pointResult is equal to (-10,-25) 

                    // Displaying Results
                    syntaxString = "pointResult = point1 + vector1;";
                    resultType = "Point";
                    operationString = "Translating a Point by a Vector";
                    ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb2":
                {
                    // Adds a Vector to a Vector using the overloaded + operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);


                    // vectorResult is equal to (65,100)
                    var vectorResult = vector1 + vector2;


                    // Displaying Results
                    syntaxString = "vectorResult = vector1 + vector2;";
                    resultType = "Vector";
                    operationString = "Adding a Vector to a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb3":
                {
                    // Adds a Vector to a Vector using the static Add method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var vectorResult = System.Windows.Vector.Add(vector1, vector2);

                    // vectorResult is equal to (65,100)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Add(vector1, vector2);";
                    resultType = "Vector";
                    operationString = "Adding a Vector to a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb4":
                {
                    // Translates a Point by a Vector using the static Add method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var point1 = new Point(10, 5);

                    var pointResult = System.Windows.Vector.Add(vector1, point1);

                    // vectorResult is equal to (30,35)

                    // Displaying Results
                    syntaxString = "pointResult = Vector.Add(vector1, point1);";
                    resultType = "Point";
                    operationString = "Translating a Point by a Vector";
                    ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb5":
                {
                    // Subtracts a Vector from a Vector using the overloaded - operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var vectorResult = vector1 - vector2;

                    // vector Result is equal to (-25, -40)

                    // Displaying Results 
                    syntaxString = "vectorResult = vector1 - vector2;";
                    resultType = "Vector";
                    operationString = "Subtracting a Vector from a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb6":
                {
                    // Subtracts a Vector from a Vector using the static Subtract method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var vectorResult = System.Windows.Vector.Subtract(vector1, vector2);

                    // vector Result is equal to (-25, -40)

                    // Displaying Results
                    syntaxString = "Vector.Subtract(vector1, vector2);";
                    resultType = "Vector";
                    operationString = "Subtracting a Vector from a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb7":
                {
                    // Multiplies a Vector by a Scalar using the overloaded * operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = vector1*scalar1;

                    // vectorResult is equal to (1500,2250)

                    // Displaying Results
                    syntaxString = "vectorResult = vector1 * scalar1;";
                    resultType = "Vector";
                    operationString = "Multiplies a Vector by a Scalar";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb8":
                {
                    // Multiplies a Scalar by a Vector using the overloaded * operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = scalar1*vector1;

                    // vectorResult is equal to (1500,2250)

                    // Displaying Results
                    syntaxString = "vectorResult = scalar1 * vector1;";
                    resultType = "Vector";
                    operationString = "Multiplies a Scalar by a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb9":
                {
                    // Multiplies a Vector by a Vector using the overloaded * operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var doubleResult = vector1*vector2;

                    // doubleResult is equal to 3000

                    // Displaying Results
                    syntaxString = "doubleResult = vector1 * vector2;";
                    resultType = "Double";
                    operationString = "Multiplies a Vector by a Vector";
                    ShowResults(doubleResult.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }

                case "rb10":
                {
                    // Multiplies a Vector by a Matrix using the overloaded * operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var matrix1 = new Matrix(40, 50, 60, 70, 80, 90);

                    var vectorResult = vector1*matrix1;

                    // vector Result is equal to (2600,3100)


                    // Displaying Results
                    syntaxString = "vectorResult = vector1 * matrix1;";
                    resultType = "Vector";
                    operationString = "Multiplies a Vector by a Matrix";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb11":
                {
                    // Multiplies a Vector by a Scalar using the static Multiply method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = System.Windows.Vector.Multiply(vector1, scalar1);

                    // vectorResult is equal to (1500,2250)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Multiply(vector1, scalar1);";
                    resultType = "Vector";
                    operationString = "Multiplies a Vector by a Scalar";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb12":
                {
                    // Multiplies a Scalar by a Vector using the static Multiply method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = System.Windows.Vector.Multiply(scalar1, vector1);

                    // vectorResult is equal to (1500,2250)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Multiply(scalar1, vector1);";
                    resultType = "Vector";
                    operationString = "Multiplies a Scalar by a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb13":
                {
                    // Multiplies a Vector by a Vector using the static Multiply method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var doubleResult = System.Windows.Vector.Multiply(vector1, vector2);

                    // doubleResult is equal to 3000

                    // Displaying Results
                    syntaxString = "DoubleResult = Vector.Multiply(vector1,vector2);";
                    resultType = "Double";
                    operationString = "Multiplies a Vector by a Vector";
                    ShowResults(doubleResult.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }

                case "rb14":
                {
                    // Multiplies a Vector by a Matrix using the static Multiply method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var matrix1 = new Matrix(40, 50, 60, 70, 80, 90);

                    var vectorResult = System.Windows.Vector.Multiply(vector1, matrix1);

                    // vector Result is equal to (2600,3100)


                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Multiply(vector1,matrix1);";
                    resultType = "Vector";
                    operationString = "Multiplies a Vector by a Matrix";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb15":
                {
                    // Divides a Vector by a Scalar using the overloaded / operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = vector1/scalar1;

                    // vectorResult is approximately equal to (0.26667,0.4)

                    // Displaying Results
                    syntaxString = "vectorResult = vector1 / scalar1;";
                    resultType = "Vector";
                    operationString = "Dividing a Vector by a Scalar";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb16":
                {
                    // Divides a Vector by a Double using the static Divide method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = System.Windows.Vector.Divide(vector1, scalar1);

                    // vectorResult is approximately equal to (0.26667,0.4)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Divide(vector1, scalar1);";
                    resultType = "Vector";
                    operationString = "Dividing a Vector by a Scalar";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb17":
                {
                    // Gets the hashcode of a Vector structure

                    var vector1 = new System.Windows.Vector(20, 30);

                    var vectorHashCode = vector1.GetHashCode();

                    // Displaying Results
                    syntaxString = "vectorHashCode = vector1.GetHashCode();";
                    resultType = "int";
                    operationString = "Getting the hashcode of a Vector";
                    ShowResults(vectorHashCode.ToString(), syntaxString, resultType, operationString);
                    break;
                }


                case "rb18":
                {
                    // Gets the length of a Vector.  

                    var vector1 = new System.Windows.Vector(20, 30);

                    var length = vector1.Length;

                    // length is approximately equal to 36.0555


                    // Displaying Results
                    syntaxString = "length = vector1.Length();";
                    resultType = "Double";
                    operationString = "Getting the length of a Vector";
                    ShowResults(length.ToString(CultureInfo.InvariantCulture), syntaxString, resultType, operationString);
                    break;
                }

                case "rb19":
                {
                    // Gets the square of the length of a Vector.  

                    var vector1 = new System.Windows.Vector(20, 30);

                    var lengthSq = vector1.LengthSquared;

                    // lengthSq is equal to 1300

                    // Displaying Results
                    syntaxString = "lengthSq = vector1.LengthSquared;";
                    resultType = "Double";
                    operationString = "Getting the length square of a Vector";
                    ShowResults(lengthSq.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }
                case "rb20":
                {
                    // Normalizes a Vector using the Normalize method.  

                    var vector1 = new System.Windows.Vector(20, 30);

                    vector1.Normalize();

                    // vector1 is approximately equal to (0.5547,0.8321) 

                    // Displaying Results
                    syntaxString = "vector1.Normalize();";
                    resultType = "Vector";
                    operationString = "Normalizing a Vector";
                    ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb21":
                {
                    // Calculates the angle between two Vectors using the static AngleBetween method. 

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var angleBetween = System.Windows.Vector.AngleBetween(vector1, vector2);

                    // angleBetween is approximately equal to 0.9548

                    // Displaying Results
                    syntaxString = "angleBetween = Vector.AngleBetween(vector1, vector2);";
                    resultType = "Double";
                    operationString = "Calculating the angle between two Vectors";
                    ShowResults(angleBetween.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }

                case "rb22":
                {
                    // Calculates the cross product of two Vectors using the static  CrossProduct method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var crossProduct = System.Windows.Vector.CrossProduct(vector1, vector2);

                    // crossProduct is equal to 50

                    // Displaying Results
                    syntaxString = "crossProduct = Vector.CrossProduct(vector1,vector2);";
                    resultType = "Double";
                    operationString = "Calculating the crossproduct of two Vectors";
                    ShowResults(crossProduct.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }


                case "rb23":
                {
                    // Calculates the determinant of two Vectors using the static Determinant method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var determinant = System.Windows.Vector.Determinant(vector1, vector2);

                    // determinant is equal to 50

                    // Displaying Results
                    syntaxString = "determinant = Vector.Determinant(vector1, vector2);";
                    resultType = "Double";
                    operationString = "Calculating the determinant of two Vectors";
                    ShowResults(determinant.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }


                case "rb24":
                {
                    // Checks if two Vectors are equal using the overloaded equality operator.

                    // Declaring vecto1 and initializing x,y values
                    var vector1 = new System.Windows.Vector(20, 30);

                    // Declaring vector2 without initializing x,y values
                    var vector2 = new System.Windows.Vector
                    {
                        X = 45,
                        Y = 70
                    };

                    // Boolean to hold the result of the comparison

                    // assigning values to vector2

                    // Comparing Vectors for equality
                    var areEqual = (vector1 == vector2);

                    // areEqual is False

                    // Displaying Results
                    syntaxString = "areEqual = (vector1 == vector2);";
                    resultType = "Boolean";
                    operationString = "Checking if two vectors are equal";
                    ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                    break;
                }


                case "rb25":
                {
                    // Checks if two Vectors are equal using the static Equals method.

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var areEqual = System.Windows.Vector.Equals(vector1, vector2);

                    // areEqual is False    

                    // Displaying Results
                    syntaxString = "areEqual = Vector.Equals(vector1, vector2);";
                    resultType = "Boolean";
                    operationString = "Checking if two vectors are equal";
                    ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb26":
                {
                    // Compares an Object and a Vector for equality using the non-static Equals method.

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var areEqual = vector1.Equals(vector2);

                    // areEqual is False    


                    // Displaying Results
                    syntaxString = "areEqual = vector1.Equals(vector2);";
                    resultType = "Boolean";
                    operationString = "Checking if two vectors are equal";
                    ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb27":
                {
                    // Converts a string representation of a vector into a Vector structure

                    var vectorResult = System.Windows.Vector.Parse("1,3");

                    // vectorResult is equal to (1,3)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Parse(\"1,3\");";
                    resultType = "Vector";
                    operationString = "Converting a string into a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb28":
                {
                    // Checks if two Vectors are not equal using the overloaded inequality operator.

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var areNotEqual = (vector1 != vector2);

                    // areNotEqual is True

                    // Displaying Results
                    syntaxString = "areNotEqual = (vector1 != vector2);";
                    resultType = "Boolean";
                    operationString = "Checking if two points are not equal";
                    ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb29":
                {
                    // Negates a Vector using the Negate method.

                    var vector1 = new System.Windows.Vector(20, 30);

                    vector1.Negate();

                    // vector1 is equal to (-20, -30)

                    // Displaying Results
                    syntaxString = "vector1.Negate();";
                    resultType = "void";
                    operationString = "Negating a vector";
                    ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb30":
                {
                    // Negates a Vector using the overloaded unary negation operator.

                    var vector1 = new System.Windows.Vector(20, 30);

                    var vectorResult = -vector1;

                    // vectorResult is equal to (-20, -30)

                    // Displaying Results
                    syntaxString = "vectorResult = -vector1;";
                    resultType = "Vector";
                    operationString = "Negating a vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb31":
                {
                    // Gets a String representation of a Vector structure

                    var vector1 = new System.Windows.Vector(20, 30);

                    var vectorString = vector1.ToString();

                    // vectorString is equal to 10,5

                    // Displaying Results
                    syntaxString = "vectorString = vector1.ToString();";
                    resultType = "String";
                    operationString = "Getting the string representation of a Vector";
                    ShowResults(vectorString, syntaxString, resultType, operationString);
                    break;
                }
                case "rb32":
                {
                    // Explicitly converts a Vector structure into a Size structure
                    // Returns a Size.

                    var vector1 = new System.Windows.Vector(20, 30);

                    var size1 = (Size) vector1;

                    // size1 has a width of 20 and a height of 30

                    // Displaying Results
                    syntaxString = "size1 = (Size)vector1;";
                    resultType = "Size";
                    operationString = "Expliciting casting a Vector into a Size";
                    ShowResults(size1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb33":
                {
                    // Explicitly converts a Vector structure into a Point structure
                    // Returns a Point.

                    var vector1 = new System.Windows.Vector(20, 30);

                    var point1 = (Point) vector1;

                    // point1 is equal to (20, 30)

                    // Displaying Results
                    syntaxString = "point1 = (Point)vector1;";
                    resultType = "Point";
                    operationString = "Expliciting casting a Vector into a Point";
                    ShowResults(point1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                // task example.  this case statement is not referenced from the list of radio buttons
                case "rb40":
                {
                    // adds two vectors using Add and +

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    vector1 = vector1 + vector2;
                    // vector1 is now equal to (65, 100)

                    vector1 = System.Windows.Vector.Add(vector1, vector2);
                    // vector1 is now equal to (110, 170)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Negate(vector1);";
                    resultType = "Vector";
                    operationString = "Negating a vector";
                    ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
            } // end switch
        }
예제 #58
0
        // Method to display the variables used in the operations
        public void ShowVars()
        {
            // Displays the values of the variables
            var p1 = new Point(10, 5);
            var p2 = new Point(15, 40);

            var v1 = new System.Windows.Vector(20, 30);
            var v2 = new System.Windows.Vector(45, 70);

            var m1 = new Matrix(40, 50, 60, 70, 80, 90);

            double s1 = 75;

            txtPoint1.Text = p1.ToString();
            txtPoint2.Text = p2.ToString();
            txtVector1.Text = v1.ToString();
            txtVector2.Text = v2.ToString();
            txtMatrix1.Text = m1.ToString();
            txtScalar1.Text = s1.ToString(CultureInfo.InvariantCulture);
        }
예제 #59
0
파일: Core.cs 프로젝트: hcilab-um/STim
        private double CalculateBodyOrientationAngle(WagSkeleton userSkeleton)
        {
            Microsoft.Kinect.Joint shoulderLeft = userSkeleton.TransformedJoints[JointType.ShoulderLeft];
              Microsoft.Kinect.Joint shoulderRight = userSkeleton.TransformedJoints[JointType.ShoulderRight];

              Vector shoulderVector = new Vector(shoulderRight.Position.X - shoulderLeft.Position.X, shoulderRight.Position.Z - shoulderLeft.Position.Z);
              System.Windows.Media.Matrix matrix = new System.Windows.Media.Matrix();
              matrix.Rotate(-90);
              Vector bodyFacingDirection = matrix.Transform(shoulderVector);
              Vector displayLocation = -new Vector(userSkeleton.HeadLocation.X, userSkeleton.HeadLocation.Z);
              double orientationAngle = Math.Abs(Vector.AngleBetween(displayLocation, bodyFacingDirection));
              return Math.Abs(orientationAngle);
        }
예제 #60
0
        internal static PathGeometry TransformRectangle(Matrix matrix, Rect rectangle)
        {
            Point topLeft = matrix.Transform(new Point(rectangle.Left, rectangle.Top));
            Point topRight = matrix.Transform(new Point(rectangle.Right, rectangle.Top));
            Point bottomRight = matrix.Transform(new Point(rectangle.Right, rectangle.Bottom));
            Point bottomLeft = matrix.Transform(new Point(rectangle.Left, rectangle.Bottom));

            var path = new PathGeometry();
            PathFigure figure = new PathFigure();
            path.Figures.Add(figure);
            figure.IsClosed = true;

            figure.StartPoint = topLeft;
#if WPF
            figure.Segments.Add(new LineSegment(topRight, false));
            figure.Segments.Add(new LineSegment(bottomRight, false));
            figure.Segments.Add(new LineSegment(bottomLeft, false));
#elif SILVERLIGHT
            figure.Segments.Add(new LineSegment { Point = topRight });
            figure.Segments.Add(new LineSegment { Point = bottomRight });
            figure.Segments.Add(new LineSegment { Point = bottomLeft });

#endif
            return path;
        }