Invert() public method

public Invert ( ) : Cairo.Status
return Cairo.Status
コード例 #1
0
ファイル: ZoomableCairoArea.cs プロジェクト: tabrath/meshwork
 public void DeviceToUser(ref double x, ref double y)
 {
     Cairo.Matrix inv = (Cairo.Matrix) this.transformMatrix.Clone();
     Cairo.Status cs  = inv.Invert();
     if (cs == Cairo.Status.Success)
     {
         inv.TransformPoint(ref x, ref y);
     }
     else
     {
         throw new Exception("Unable to transform device coordinates to user coordinates because the matrix was uninvertible (" + cs.ToString() + ").");
     }
 }
コード例 #2
0
        //
        // this functions calculates the transformation needed to center and completely fill the
        // viewport with the Surface at the given tilt
        //
        public Matrix Fill(Gdk.Rectangle viewport, double tilt)
        {
            if (tilt == 0.0)
                return Fill (viewport);

            Matrix m = new Matrix ();
            m.InitIdentity ();

            double len;
            double orig_len;
            if (Bounds.Width > Bounds.Height) {
                len = viewport.Height;
                orig_len = Bounds.Height;
            } else {
                len = viewport.Width;
                orig_len = Bounds.Width;
            }

            double a = Math.Sqrt (viewport.Width * viewport.Width + viewport.Height * viewport.Height);
            double alpha = Math.Acos (len / a);
            double theta = alpha - Math.Abs (tilt);

            double slen = a * Math.Cos (theta);

            double scale = slen / orig_len;

            double x_offset = (viewport.Width  - Bounds.Width * scale) / 2.0;
            double y_offset = (viewport.Height  - Bounds.Height * scale) / 2.0;

            m.Translate (x_offset, y_offset);
            m.Scale (scale, scale);
            m.Invert ();
            m.Translate (viewport.Width * 0.5, viewport.Height * 0.5);
            m.Rotate (tilt);
            m.Translate (viewport.Width * -0.5, viewport.Height * -0.5);
            m.Invert ();
            return m;
        }