public void SetImage (ImageDescription image) { Gtk.ImageMenuItem it = item as Gtk.ImageMenuItem; if (it == null) return; if (!image.IsNull) { if (defImage == null) item.StateChanged += ImageMenuItemStateChanged; defImage = image; selImage = new ImageDescription { Backend = image.Backend, Size = image.Size, Alpha = image.Alpha, Styles = image.Styles.Add ("sel") }; var img = new ImageBox (context, image); img.ShowAll (); it.Image = img; GtkWorkarounds.ForceImageOnMenuItem (it); } else { if (defImage.HasValue) { item.StateChanged -= ImageMenuItemStateChanged; defImage = selImage = null; } it.Image = null; } }
public override object Create(ImageDescription img) { NSImage nimg = img.ToNSImage (); return new ImagePatternInfo () { Image = nimg }; }
void Draw(object ctx, Rectangle bounds, ImageDescription idesc, Toolkit toolkit) { var c = new Context (ctx, toolkit); if (idesc.Styles != StyleSet.Empty) c.SetStyles (idesc.Styles); c.Reset (null); c.Save (); c.GlobalAlpha = idesc.Alpha; OnDraw (c, bounds); c.Restore (); }
public void SetImage (ImageDescription image) { Gtk.ImageMenuItem it = item as Gtk.ImageMenuItem; if (it == null) return; if (!image.IsNull) { var img = new ImageBox (context, image); img.ShowAll (); it.Image = img; GtkWorkarounds.ForceImageOnMenuItem (it); } else it.Image = null; }
public override void DrawImage(object backend, ImageDescription img, double x, double y) { CairoContextBackend ctx = (CairoContextBackend)backend; img.Alpha *= ctx.GlobalAlpha; var pix = (Xwt.GtkBackend.GtkImage) img.Backend; pix.Draw (ApplicationContext, ctx.Context, ctx.ScaleFactor, x, y, img); }
public void SetIcon(ImageDescription imageBackend) { window.Icon = imageBackend.ToImageSource (); }
public override void DrawImage(object backend, ImageDescription img, double x, double y) { var srcRect = new Rectangle (Point.Zero, img.Size); var destRect = new Rectangle (x, y, img.Size.Width, img.Size.Height); DrawImage (backend, img, srcRect, destRect); }
public override object Create (ImageDescription img) { return new ImagePattern (ApplicationContext, img); }
public ImageBox (ApplicationContext actx, ImageDescription img): this (actx) { Image = img; }
public abstract object Create(ImageDescription img);
/// <summary> /// Renders an image at the provided native context /// </summary> /// <param name="nativeContext">Native context.</param> /// <param name="img">Image.</param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> public virtual void RenderImage(object nativeWidget, object nativeContext, ImageDescription img, double x, double y) { }
public abstract void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect);
public abstract void DrawImage(object backend, ImageDescription img, double x, double y);
public void SetIcon(ImageDescription icon) { Window.IconList = ((GtkImage)icon.Backend).Frames.Select (f => f.Pixbuf).ToArray (); }
public override void DrawImage(object backend, ImageDescription img, Xwt.Rectangle srcRect, Xwt.Rectangle destRect) { var ctx = (VectorBackend)backend; ctx.Commands.Add (DrawingCommand.DrawImage2); ctx.Images.Add (img); ctx.Rectangles.Add (srcRect); ctx.Rectangles.Add (destRect); }
public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc) { if (drawCallback != null) { DrawingContext c = new DrawingContext (dc, scaleFactor); actx.InvokeUserCode (delegate { drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height), idesc, actx.Toolkit); }); } else { if (idesc.Alpha < 1) dc.PushOpacity (idesc.Alpha); var f = GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false); var bmpImage = f as BitmapSource; // When an image is a single bitmap that doesn't have the same intrinsic size as the drawing size, dc.DrawImage makes a very poor job of down/up scaling it. // Thus we handle this manually by using a TransformedBitmap to handle the conversion in a better way when it's needed. var scaledWidth = idesc.Size.Width * scaleFactor; var scaledHeight = idesc.Size.Height * scaleFactor; if (bmpImage != null && (Math.Abs (bmpImage.PixelHeight - scaledHeight) > 0.001 || Math.Abs (bmpImage.PixelWidth - scaledWidth) > 0.001)) f = new TransformedBitmap (bmpImage, new ScaleTransform (scaledWidth / bmpImage.PixelWidth, scaledHeight / bmpImage.PixelHeight)); dc.DrawImage (f, new Rect (x, y, idesc.Size.Width, idesc.Size.Height)); if (idesc.Alpha < 1) dc.Pop (); } }
public void SetIcon (ImageDescription icon) { }
void DrawPixbuf (Cairo.Context ctx, Gdk.Pixbuf img, double x, double y, ImageDescription idesc) { ctx.Save (); ctx.Translate (x, y); ctx.Scale (idesc.Size.Width / (double)img.Width, idesc.Size.Height / (double)img.Height); Gdk.CairoHelper.SetSourcePixbuf (ctx, img, 0, 0); #pragma warning disable 618 using (var pattern = ctx.Source as Cairo.SurfacePattern) { if (pattern != null) { if (idesc.Size.Width > img.Width || idesc.Size.Height > img.Height) { // Fixes blur issue when rendering on an image surface pattern.Filter = Cairo.Filter.Fast; } else pattern.Filter = Cairo.Filter.Good; } } #pragma warning restore 618 if (idesc.Alpha >= 1) ctx.Paint (); else ctx.PaintWithAlpha (idesc.Alpha); ctx.Restore (); }
void DrawPixbuf(Cairo.Context ctx, Gdk.Pixbuf img, double x, double y, ImageDescription idesc) { ctx.Save (); ctx.Translate (x, y); ctx.Scale (idesc.Size.Width / (double)img.Width, idesc.Size.Height / (double)img.Height); Gdk.CairoHelper.SetSourcePixbuf (ctx, img, 0, 0); if (idesc.Alpha == 1) ctx.Paint (); else ctx.PaintWithAlpha (idesc.Alpha); ctx.Restore (); }
public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc) { if (drawCallback != null) { DrawingContext c = new DrawingContext (dc, scaleFactor); actx.InvokeUserCode (delegate { drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height)); }); } else { if (idesc.Alpha < 1) dc.PushOpacity (idesc.Alpha); var f = GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false); dc.DrawImage (f, new Rect (x, y, idesc.Size.Width, idesc.Size.Height)); if (idesc.Alpha < 1) dc.Pop (); } }
Gdk.Pixbuf RenderFrame(ApplicationContext actx, double scaleFactor, double width, double height) { using (var sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, (int)(width * scaleFactor), (int)(height * scaleFactor))) using (var ctx = new Cairo.Context (sf)) { ImageDescription idesc = new ImageDescription () { Alpha = 1, Size = new Size (width * scaleFactor, height * scaleFactor) }; Draw (actx, ctx, 1, 0, 0, idesc); var f = new ImageFrame (ImageBuilderBackend.CreatePixbuf (sf), (int)width, (int)height); AddFrame (f); return f.Pixbuf; } }
public override object Create(ImageDescription img) { return new ImagePatternBackend () { Image = img }; }
public void SetImage(ImageDescription imageBackend) { if (imageBackend.IsNull) this.menuItem.Icon = null; else this.menuItem.Icon = new ImageBox (Context) { ImageSource = imageBackend }; }
public ImagePattern (ApplicationContext actx, ImageDescription im) { this.actx = actx; this.image = im; }
public abstract object Create (ImageDescription img);
public override void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect) { CGContext ctx = ((CGContextBackend)backend).Context; NSImage image = img.ToNSImage (); ctx.SaveState (); ctx.SetAlpha ((float)img.Alpha); double rx = destRect.Width / srcRect.Width; double ry = destRect.Height / srcRect.Height; ctx.AddRect (new RectangleF ((float)destRect.X, (float)destRect.Y, (float)destRect.Width, (float)destRect.Height)); ctx.Clip (); ctx.TranslateCTM ((float)(destRect.X - (srcRect.X * rx)), (float)(destRect.Y - (srcRect.Y * ry))); ctx.ScaleCTM ((float)rx, (float)ry); if (image is CustomImage) { ((CustomImage)image).DrawInContext ((CGContextBackend)backend); } else { RectangleF rr = new RectangleF (0, 0, (float)image.Size.Width, image.Size.Height); ctx.ScaleCTM (1f, -1f); ctx.DrawImage (new RectangleF (0, -image.Size.Height, image.Size.Width, image.Size.Height), image.AsCGImage (ref rr, NSGraphicsContext.CurrentContext, null)); } ctx.RestoreState (); }
public override void DrawImage(object backend, ImageDescription img, double x, double y) { var c = (DrawingContext) backend; WpfImage bmp = (WpfImage) img.Backend; bmp.Draw (ApplicationContext, c.Context, c.ScaleFactor, x, y, img); }
public void SetContent(string label, bool useMnemonic, ImageDescription image, ContentPosition position) { Widget.UseUnderline = useMnemonic; this.image = image; if (label != null && label.Length == 0) label = null; Button b = (Button) Frontend; if (label != null && image.Backend == null && b.Type == ButtonType.Normal) { Widget.Label = label; return; } if (b.Type == ButtonType.Disclosure) { Widget.Label = null; Widget.Image = new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out); Widget.Image.ShowAll (); return; } Gtk.Widget contentWidget = null; Gtk.Widget imageWidget = null; if (image.Backend != null) imageWidget = new ImageBox (ApplicationContext, image.WithDefaultSize (Gtk.IconSize.Button)); labelWidget = null; if (label != null && imageWidget == null) { contentWidget = labelWidget = new Gtk.Label (label); } else if (label == null && imageWidget != null) { contentWidget = imageWidget; } else if (label != null && imageWidget != null) { Gtk.Box box = position == ContentPosition.Left || position == ContentPosition.Right ? (Gtk.Box) new Gtk.HBox (false, 3) : (Gtk.Box) new Gtk.VBox (false, 3); labelWidget = new Gtk.Label (label) { UseUnderline = useMnemonic }; if (position == ContentPosition.Left || position == ContentPosition.Top) { box.PackStart (imageWidget, false, false, 0); box.PackStart (labelWidget, false, false, 0); } else { box.PackStart (labelWidget, false, false, 0); box.PackStart (imageWidget, false, false, 0); } contentWidget = box; } var expandButtonContent = false; if (b.Type == ButtonType.DropDown) { if (contentWidget != null) { Gtk.HBox box = new Gtk.HBox (false, 3); box.PackStart (contentWidget, true, true, 3); box.PackStart (new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out), false, false, 0); contentWidget = box; expandButtonContent = true; } else contentWidget = new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out); } if (contentWidget != null) { contentWidget.ShowAll (); Widget.Label = null; Widget.Image = contentWidget; var alignment = Widget.Child as Gtk.Alignment; if (alignment != null) { if (expandButtonContent) { var box = alignment.Child as Gtk.Box; if (box != null) { alignment.Xscale = 1; box.SetChildPacking (box.Children [0], true, true, 0, Gtk.PackType.Start); if (labelWidget != null) labelWidget.Xalign = 0; } } else if (position == ContentPosition.Left && (contentWidget is Gtk.Box)) { // in case the button is wider than its natural size and has text and an image on the left, // optimize its alignment to make the text more centered. // FIXME: more sophisticated size calculation alignment.Xalign = 0.475f; } } if (labelWidget != null) { labelWidget.UseUnderline = useMnemonic; if (customFont != null) labelWidget.ModifyFont (customFont); if (customLabelColor.HasValue) { labelWidget.SetForegroundColor (customLabelColor.Value); labelWidget.SetForegroundColor (Gtk.StateType.Prelight, customLabelColor.Value); } } } else Widget.Label = null; }
public override void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect) { var c = (DrawingContext) backend; WpfImage bmp = (WpfImage)img.Backend; c.Context.PushClip (new RectangleGeometry (destRect.ToWpfRect ())); c.Context.PushTransform (new TranslateTransform (destRect.X - srcRect.X, destRect.Y - srcRect.Y)); var sw = destRect.Width / srcRect.Width; var sh = destRect.Height / srcRect.Height; c.Context.PushTransform (new ScaleTransform (sw, sh)); bmp.Draw (ApplicationContext, c.Context, c.ScaleFactor, 0, 0, img); c.Context.Pop (); // Scale c.Context.Pop (); // Translate c.Context.Pop (); // Clip }
public override void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect) { CairoContextBackend ctx = (CairoContextBackend)backend; ctx.Context.Save (); ctx.Context.NewPath(); ctx.Context.Rectangle (destRect.X, destRect.Y, destRect.Width, destRect.Height); ctx.Context.Clip (); double sx = destRect.Width / srcRect.Width; double sy = destRect.Height / srcRect.Height; ctx.Context.Translate (destRect.X-srcRect.X*sx, destRect.Y-srcRect.Y*sy); ctx.Context.Scale (sx, sy); img.Alpha *= ctx.GlobalAlpha; var pix = (Xwt.GtkBackend.GtkImage) img.Backend; pix.Draw (ApplicationContext, ctx.Context, ctx.ScaleFactor, 0, 0, img); ctx.Context.Restore (); }
Gdk.Pixbuf RenderFrame (ApplicationContext actx, double scaleFactor, double width, double height) { var swidth = Math.Max ((int)(width * scaleFactor), 1); var sheight = Math.Max ((int)(height * scaleFactor), 1); using (var sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, swidth, sheight)) using (var ctx = new Cairo.Context (sf)) { ImageDescription idesc = new ImageDescription () { Alpha = 1, Size = new Size (width, height) }; ctx.Scale (scaleFactor, scaleFactor); Draw (actx, ctx, scaleFactor, 0, 0, idesc); var f = new ImageFrame (ImageBuilderBackend.CreatePixbuf (sf), Math.Max((int)width,1), Math.Max((int)height,1), true); AddFrame (f); return f.Pixbuf; } }
public void SetContent(string label, bool useMnemonic, ImageDescription image, ContentPosition position) { var accessText = new SWC.AccessText (); accessText.Text = label; if (image.IsNull) if (useMnemonic) Button.Content = accessText; else Button.Content = accessText.Text.Replace ("_", "__"); else { SWC.DockPanel grid = new SWC.DockPanel (); var imageCtrl = new ImageBox (Context); imageCtrl.ImageSource = image; SWC.DockPanel.SetDock (imageCtrl, DataConverter.ToWpfDock (position)); grid.Children.Add (imageCtrl); if (!string.IsNullOrEmpty (label)) { SWC.Label labelCtrl = new SWC.Label (); if (useMnemonic) labelCtrl.Content = accessText; else labelCtrl.Content = label; labelCtrl.SetBinding (SWC.Label.ForegroundProperty, new Binding ("Foreground") { Source = Button }); grid.Children.Add (labelCtrl); } Button.Content = grid; } Button.InvalidateMeasure (); }
public void Draw (ApplicationContext actx, Cairo.Context ctx, double scaleFactor, double x, double y, ImageDescription idesc) { if (stockId != null) { ImageFrame frame = null; if (frames != null) frame = frames.FirstOrDefault (f => f.Width == (int) idesc.Size.Width && f.Height == (int) idesc.Size.Height && f.Scale == scaleFactor); if (frame == null) { frame = new ImageFrame (ImageHandler.CreateBitmap (stockId, idesc.Size.Width, idesc.Size.Height, scaleFactor), (int)idesc.Size.Width, (int)idesc.Size.Height, false); frame.Scale = scaleFactor; AddFrame (frame); } DrawPixbuf (ctx, frame.Pixbuf, x, y, idesc); } else if (drawCallback != null) { CairoContextBackend c = new CairoContextBackend (scaleFactor) { Context = ctx }; if (actx != null) { actx.InvokeUserCode (delegate { drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height)); }); } else drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height)); } else { DrawPixbuf (ctx, GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false), x, y, idesc); } }
ImageSource RenderFrame(ApplicationContext actx, double scaleFactor, double width, double height) { ImageDescription idesc = new ImageDescription () { Alpha = 1, Size = new Size (width, height) }; SWM.DrawingVisual visual = new SWM.DrawingVisual (); using (SWM.DrawingContext ctx = visual.RenderOpen ()) { ctx.PushTransform (new ScaleTransform (scaleFactor, scaleFactor)); Draw (actx, ctx, scaleFactor, 0, 0, idesc); ctx.Pop (); } SWMI.RenderTargetBitmap bmp = new SWMI.RenderTargetBitmap ((int)(width * scaleFactor), (int)(height * scaleFactor), 96, 96, PixelFormats.Pbgra32); bmp.Render (visual); var f = new ImageFrame (bmp, width, height); AddFrame (f); return bmp; }
/// <summary> /// Converts an image to a bitmap of the specified size /// </summary> /// <returns>The bitmap.</returns> /// <param name="handle">Image handle.</param> /// <param name="width">Width.</param> /// <param name="height">Height.</param> public abstract object ConvertToBitmap(ImageDescription idesc, double scaleFactor, ImageFormat format);