public static Matrix GetTransform(this Node node) { double anchorX = node.AnchorX * node.Width; double anchorY = node.AnchorY * node.Height; Matrix transform = new Matrix (); transform.Translate (node.X + anchorX, node.Y + anchorY); transform.Rotate (node.Rotation); transform.Scale (node.Scale, node.Scale); transform.Translate (-anchorX, -anchorY); return transform; }
public static void SetSourceDrawable (Context ctx, Gdk.Drawable d, double x, double y) { try { gdk_cairo_set_source_pixmap (ctx.Handle, d.Handle, x, y); } catch (EntryPointNotFoundException) { int width, height; d.GetSize (out width, out height); XlibSurface surface = new XlibSurface (GdkUtils.GetXDisplay (d.Display), (IntPtr)GdkUtils.GetXid (d), GdkUtils.GetXVisual (d.Visual), width, height); SurfacePattern p = new SurfacePattern (surface); Matrix m = new Matrix (); m.Translate (-x, -y); p.Matrix = m; ctx.Source = p; } }
public bool OnExpose(Context ctx, Gdk.Rectangle viewport) { double percent = Math.Min ((DateTime.UtcNow - start).Ticks / (double) duration.Ticks, 1.0); frames ++; //ctx.Matrix = m; SurfacePattern p = new SurfacePattern (buffer.Surface); p.Filter = Filter.Fast; Matrix m = new Matrix (); m.Translate (pan_x * zoom, pan_y * zoom); m.Scale (zoom, zoom); zoom *= .98; p.Matrix = m; ctx.Source = p; ctx.Paint (); p.Destroy (); return percent < 1.0; }
public bool OnExpose(Context ctx, Gdk.Rectangle viewport) { double percent = Math.Min ((DateTime.UtcNow - start).Ticks / (double) duration.Ticks, 1.0); //Matrix m = info.Fill (allocation); Matrix m = new Matrix (); m.Translate (pan_x, pan_y); m.Scale (zoom, zoom); ctx.Matrix = m; SurfacePattern p = new SurfacePattern (info.Surface); ctx.Source = p; ctx.Paint (); p.Destroy (); return percent < 1.0; }
private Surface CreateScene (Cairo.Context window_cr, ImageSurface image, int reflect) { Surface surface = window_cr.Target.CreateSimilar (window_cr.Target.Content, image.Width, image.Height + reflect); Cairo.Context cr = new Context (surface); cr.Save (); cr.SetSource (image); cr.Paint (); cr.Rectangle (0, image.Height, image.Width, reflect); cr.Clip (); Matrix matrix = new Matrix (); matrix.InitScale (1, -1); matrix.Translate (0, -(2 * image.Height) + 1); cr.Transform (matrix); cr.SetSource (image); cr.Paint (); cr.Restore (); Color bg_transparent = BackgroundColor; bg_transparent.A = 0.65; LinearGradient mask = new LinearGradient (0, image.Height, 0, image.Height + reflect); mask.AddColorStop (0, bg_transparent); mask.AddColorStop (1, BackgroundColor); cr.Rectangle (0, image.Height, image.Width, reflect); cr.Pattern = mask; cr.Fill (); ((IDisposable)cr).Dispose (); return surface; }
public void Rotate (double angle, Size new_size) { double radians = (angle / 180d) * Math.PI; var old_size = PintaCore.Workspace.ImageSize; var xform = new Matrix (); xform.Translate (new_size.Width / 2.0, new_size.Height / 2.0); xform.Rotate (radians); xform.Translate (-old_size.Width / 2.0, -old_size.Height / 2.0); ApplyTransform (xform, new_size); }
public Matrix Fit(Gdk.Rectangle viewport) { Matrix m = new Matrix (); m.InitIdentity (); double scale = Math.Min (viewport.Width / (double) Bounds.Width, viewport.Height / (double) Bounds.Height); 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); return m; }
// // 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; }
public static Matrix ViewToControlMatrix(Rectangle controlBounds, Rectangle view, double settingsWidth, double settingsHeight) { var m = new Matrix (); m.Translate (view.X - controlBounds.X, view.Y - controlBounds.Y); m.Scale (view.Width / settingsWidth, view.Height / settingsHeight); return m; }
private Surface CreateScene(Cairo.Context window_cr, ImageSurface image, int reflect) { var target = window_cr.GetTarget (); Surface surface = target.CreateSimilar (target.Content, image.Width, image.Height + reflect); using (var cr = new Context (surface)) { cr.Save (); cr.SetSource (image); cr.Paint (); cr.Rectangle (0, image.Height, image.Width, reflect); cr.Clip (); Matrix matrix = new Matrix (); matrix.InitScale (1, -1); matrix.Translate (0, -(2 * image.Height) + 1); cr.Transform (matrix); cr.SetSource (image); cr.Paint (); cr.Restore (); Color bg_transparent = BackgroundColor; bg_transparent.A = 0.65; using (var mask = new LinearGradient (0, image.Height, 0, image.Height + reflect)) { mask.AddColorStop (0, bg_transparent); mask.AddColorStop (1, BackgroundColor); cr.Rectangle (0, image.Height, image.Width, reflect); cr.SetSource (mask); cr.Fill (); } } return surface; }
protected override bool OnExposeEvent (Gdk.EventExpose evnt) { if (evnt.Window != GdkWindow) { return base.OnExposeEvent (evnt); } Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window); if (reflect) { CairoExtensions.PushGroup (cr); } cr.Operator = Operator.Over; cr.Translate (Allocation.X + h_padding, Allocation.Y); cr.Rectangle (0, 0, Allocation.Width - h_padding, Math.Max (2 * bar_height, bar_height + bar_label_spacing + layout_height)); cr.Clip (); Pattern bar = RenderBar (Allocation.Width - 2 * h_padding, bar_height); cr.Save (); cr.SetSource (bar); cr.Paint (); cr.Restore (); if (reflect) { cr.Save (); cr.Rectangle (0, bar_height, Allocation.Width - h_padding, bar_height); cr.Clip (); Matrix matrix = new Matrix (); matrix.InitScale (1, -1); matrix.Translate (0, -(2 * bar_height) + 1); cr.Transform (matrix); cr.SetSource (bar); LinearGradient mask = new LinearGradient (0, 0, 0, bar_height); mask.AddColorStop (0.25, new Color (0, 0, 0, 0)); mask.AddColorStop (0.5, new Color (0, 0, 0, 0.125)); mask.AddColorStop (0.75, new Color (0, 0, 0, 0.4)); mask.AddColorStop (1.0, new Color (0, 0, 0, 0.7)); cr.Mask (mask); mask.Dispose (); cr.Restore (); CairoExtensions.PopGroupToSource (cr); cr.Paint (); } if (show_labels) { cr.Translate ((reflect ? Allocation.X : -h_padding) + (Allocation.Width - layout_width) / 2, (reflect ? Allocation.Y : 0) + bar_height + bar_label_spacing); RenderLabels (cr); } bar.Dispose (); CairoExtensions.DisposeContext (cr); return true; }
private static Matrix ComputeMatrix (RotateZoomData data) { var xform = new Matrix (); var image_size = PintaCore.Workspace.ImageSize; var center_x = image_size.Width / 2.0; var center_y = image_size.Height / 2.0; xform.Translate ((1 + data.Pan.X) * center_x, (1 + data.Pan.Y) * center_y); xform.Rotate ((-data.Angle / 180d) * Math.PI); xform.Scale (data.Zoom, data.Zoom); xform.Translate (-center_x, -center_y); return xform; }
protected override bool OnDrawn(Cairo.Context cr) { if (!CairoHelper.ShouldDrawWindow (cr, Window)) { return base.OnDrawn (cr); } if (reflect) { CairoExtensions.PushGroup (cr); } cr.Operator = Operator.Over; cr.Translate (h_padding, 0); cr.Rectangle (0, 0, Allocation.Width - h_padding, Math.Max (2 * bar_height, bar_height + bar_label_spacing + layout_height)); cr.Clip (); Pattern bar = RenderBar (Allocation.Width - 2 * h_padding, bar_height); cr.Save (); cr.Source = bar; cr.Paint (); cr.Restore (); if (reflect) { cr.Save (); cr.Rectangle (0, bar_height, Allocation.Width - h_padding, bar_height); cr.Clip (); Matrix matrix = new Matrix (); matrix.InitScale (1, -1); matrix.Translate (0, -(2 * bar_height) + 1); cr.Transform (matrix); cr.Pattern = bar; LinearGradient mask = new LinearGradient (0, 0, 0, bar_height); mask.AddColorStop (0.25, new Color (0, 0, 0, 0)); mask.AddColorStop (0.5, new Color (0, 0, 0, 0.125)); mask.AddColorStop (0.75, new Color (0, 0, 0, 0.4)); mask.AddColorStop (1.0, new Color (0, 0, 0, 0.7)); cr.Mask (mask); mask.Destroy (); cr.Restore (); CairoExtensions.PopGroupToSource (cr); cr.Paint (); } if (show_labels) { cr.Translate ((reflect ? 0 : -h_padding) + (Allocation.Width - layout_width) / 2, bar_height + bar_label_spacing); RenderLabels (cr); } bar.Destroy (); return true; }