Exemplo n.º 1
0
		public virtual void Initialize (string name, Gdk.Pixbuf icon)
		{
			DND.SourceSet (this);
			AboveChild = true;

			Gtk.HBox hbox = new HBox (false, 6);
			hbox.BorderWidth = 3;

			if (icon != null) {
				icon = icon.ScaleSimple (16, 16, Gdk.InterpType.Bilinear);
				hbox.PackStart (new Gtk.Image (icon), false, false, 0);
			}

			Gtk.Label label = new Gtk.Label ("<small>" + name + "</small>");
			label.UseMarkup = true;
			label.Justify = Justification.Left;
			label.Xalign = 0;
			hbox.PackEnd (label, true, true, 0);

			Add (hbox);
		}
Exemplo n.º 2
0
		static void AddToIconFactory (string stockId, Gdk.Pixbuf pixbuf, Gdk.Pixbuf pixbuf2x, Gtk.IconSize iconSize)
		{
			Gtk.IconSet iconSet = iconFactory.Lookup (stockId);
			if (iconSet == null) {
				iconSet = new Gtk.IconSet ();
				iconFactory.Add (stockId, iconSet);
			}

			Gtk.IconSource source = new Gtk.IconSource ();
			Gtk.IconSource source2x = null;

			if (Platform.IsWindows) {
				var pixel_scale = Mono.TextEditor.GtkWorkarounds.GetPixelScale ();
				source.Pixbuf = pixbuf.ScaleSimple ((int)(pixbuf.Width * pixel_scale), (int)(pixbuf.Height * pixel_scale), Gdk.InterpType.Bilinear);
			} else {
				source.Pixbuf = pixbuf;
			}

			source.Size = iconSize;
			source.SizeWildcarded = iconSize == Gtk.IconSize.Invalid;

			if (pixbuf2x != null) {
				if (Mono.TextEditor.GtkWorkarounds.SetSourceScale (source, 1)) {
					Mono.TextEditor.GtkWorkarounds.SetSourceScaleWildcarded (source, false);
					source2x = new Gtk.IconSource ();
					source2x.Pixbuf = pixbuf2x;
					source2x.Size = iconSize;
					source2x.SizeWildcarded = iconSize == Gtk.IconSize.Invalid;
					Mono.TextEditor.GtkWorkarounds.SetSourceScale (source2x, 2);
					Mono.TextEditor.GtkWorkarounds.SetSourceScaleWildcarded (source2x, false);
				}
			} else {
				Mono.TextEditor.GtkWorkarounds.SetSourceScaleWildcarded (source, true);
			}

			iconSet.AddSource (source);
			if (source2x != null)
				iconSet.AddSource (source2x);
		}
		Gdk.Pixbuf FixMarkerSize (Gdk.Pixbuf pix)
		{
			// Returns a marker image with a size that fits the line height
			
			TextIter iter = View.Buffer.GetIterAtMark (View.Buffer.InsertMark);
			int markerSize = View.GetIterLocation (iter).Height;
			
			if (pix.Height <= markerSize)
				return pix;
				
			int width = pix.Width;
			int height = markerSize;
			
			if ((pix.Width - width) > (pix.Height - height)) {
				if (pix.Width != width) {
					float prop = (float) pix.Height / (float) pix.Width;
					return pix.ScaleSimple (width, (int)(width * prop), Gdk.InterpType.Bilinear);
				}
			} else {
				if (pix.Height != height) {
					float prop = (float) pix.Width / (float) pix.Height;
					return pix.ScaleSimple ((int)(height * prop), height, Gdk.InterpType.Bilinear);
				}
			}
			return pix;
		}
Exemplo n.º 4
0
		Gdk.Pixbuf GetThumbnail (Gdk.Pixbuf pix)
		{
			if (pix.Width > pix.Height) {
				if (pix.Width > thumbnailSize) {
					float prop = (float) pix.Height / (float) pix.Width;
					return pix.ScaleSimple (thumbnailSize, (int)(thumbnailSize * prop), Gdk.InterpType.Bilinear);
				}
			} else {
				if (pix.Height > thumbnailSize) {
					float prop = (float) pix.Width / (float) pix.Height;
					return pix.ScaleSimple ((int)(thumbnailSize * prop), thumbnailSize, Gdk.InterpType.Bilinear);
				}
			}
			return pix;
		}
Exemplo n.º 5
0
        public static Gdk.Pixbuf Resize(Gdk.Pixbuf pixbuf, int maxWidth, int maxHeight)
        {
            if (pixbuf == null) return(null);

            double scaleWidth = maxWidth / (double) pixbuf.Width;
            double scaleHeight = maxHeight / (double) pixbuf.Height;

            double s = Math.Min(scaleWidth, scaleHeight);
            //if (s >= 1.0) return(pixbuf);

            int w = (int) Math.Round(s*pixbuf.Width);
            int h = (int) Math.Round(s*pixbuf.Height);

            return(pixbuf.ScaleSimple(w, h, Gdk.InterpType.Bilinear));
        }
Exemplo n.º 6
0
 Gdk.Pixbuf ScaleImage(Gdk.Pixbuf pix, int width, int height)
 {
     if ((pix.Width - width) > (pix.Height - height)) {
         if (pix.Width != width) {
             float prop = (float) pix.Height / (float) pix.Width;
             return pix.ScaleSimple (width, (int)(width * prop), Gdk.InterpType.Bilinear);
         }
     } else {
         if (pix.Height != height) {
             float prop = (float) pix.Width / (float) pix.Height;
             return pix.ScaleSimple ((int)(height * prop), height, Gdk.InterpType.Bilinear);
         }
     }
     return pix;
 }
Exemplo n.º 7
0
        private void DrawImageSized(PageImage pi, Gdk.Pixbuf im, Cairo.Context g, Cairo.Rectangle r)
        {
            double height, width;      // some work variables 
            StyleInfo si = pi.SI;

            // adjust drawing rectangle based on padding 
//            System.Drawing.RectangleF r2 = new System.Drawing.RectangleF(r.Left + PixelsX(si.PaddingLeft),
//                r.Top + PixelsY(si.PaddingTop),
//                r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
//                r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));
            Cairo.Rectangle r2 = new Cairo.Rectangle(r.X + PixelsX(si.PaddingLeft),
                                     r.Y + PixelsY(si.PaddingTop),
                                     r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                                     r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            Cairo.Rectangle ir;   // int work rectangle 
            switch (pi.Sizing)
            {
                case ImageSizingEnum.AutoSize:
//                    // Note: GDI+ will stretch an image when you only provide 
//                    //  the left/top coordinates.  This seems pretty stupid since 
//                    //  it results in the image being out of focus even though 
//                    //  you don't want the image resized. 
//                    if (g.DpiX == im.HorizontalResolution &&
//                        g.DpiY == im.VerticalResolution)
                    float imwidth = PixelsX(im.Width);
                    float imheight = PixelsX(im.Height);
                    ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                        imwidth, imheight);
//                    else
//                        ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
//                                           Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
                    //g.DrawImage(im, ir);
                    im = im.ScaleSimple((int)r2.Width, (int)r2.Height, Gdk.InterpType.Hyper);
                    g.DrawPixbufRect(im, ir);
                    break;
                case ImageSizingEnum.Clip:
//                    Region saveRegion = g.Clip;
                    g.Save();
//                    Region clipRegion = new Region(g.Clip.GetRegionData());
//                    clipRegion.Intersect(r2);
//                    g.Clip = clipRegion;
                    g.Rectangle(r2);
                    g.Clip();
				
//                    if (dpiX == im.HorizontalResolution &&
//                        dpiY == im.VerticalResolution) 
                    ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                        im.Width, im.Height);
//                    else
//                        ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
//                                           Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
//                    g.DrawImage(im, ir);
                    g.DrawPixbufRect(im, ir);					
//                    g.Clip = saveRegion;
                    g.Restore();
                    break;
                case ImageSizingEnum.FitProportional:
                    double ratioIm = (float)im.Height / (float)im.Width;
                    double ratioR = r2.Height / r2.Width;
                    height = r2.Height;
                    width = r2.Width;
                    if (ratioIm > ratioR)
                    { 
                        // this means the rectangle width must be corrected 
                        width = height * (1 / ratioIm);
                    }
                    else if (ratioIm < ratioR)
                    {  
                        // this means the ractangle height must be corrected 
                        height = width * ratioIm;
                    }
                    r2 = new Cairo.Rectangle(r2.X, r2.Y, width, height);
                    g.DrawPixbufRect(im, r2);
                    break;
                case ImageSizingEnum.Fit:
                default:
                    g.DrawPixbufRect(im, r2);
                    break;
            }
        }
Exemplo n.º 8
0
        public static void DrawPixbuf(this Context g, Gdk.Pixbuf pixbuf, PointD dest, int width, int height, PointD offset)
        {
            g.Save ();
            var drawnPixbuf = pixbuf.ScaleSimple(width,height, Gdk.InterpType.Hyper);

            Gdk.CairoHelper.SetSourcePixbuf (g, drawnPixbuf, dest.X + offset.X, dest.Y + offset.Y);
            g.Paint ();
            g.Restore ();
        }
Exemplo n.º 9
0
        public void DrawRoundedRectThumb(Context gc, double x, double y, double width,
						double height, double radius, double strokeWidth,
						Cairo.Color backgroundColor, Cairo.Color strokeColor,
						Gdk.Pixbuf image, double imageWidth, double imageHeight)
        {
            gc.Save ();
            double imagex, imagey;
            //double x1 = x + width;
            //double y1 = y + height;
            double pixbufScale;
            if (image.Width > image.Height)
                pixbufScale = imageWidth / image.Width;
            else
                pixbufScale = imageHeight / image.Height;
            Gdk.Pixbuf scaledImage = image.ScaleSimple ((int)Math.Round (image.Width * pixbufScale),
                                    (int)Math.Round (image.Height * pixbufScale),
                                    InterpType.Bilinear);
            imagex = GridAlign ((x + (width / 2)) - ((double) scaledImage.Width / 2));
            imagey = GridAlign ((y + (height / 2)) - ((double) scaledImage.Height / 2));
            this.CreateRoundedRectPath (gc, x, y, width, height, radius);
            gc.Color = backgroundColor;
            gc.LineWidth = strokeWidth;
            gc.FillPreserve ();
            Gdk.CairoHelper.SetSourcePixbuf (gc, scaledImage, imagex, imagey);
            gc.FillPreserve ();
            gc.Color = strokeColor;
            gc.Stroke ();
            gc.Restore ();

            scaledImage.Dispose();
        }
Exemplo n.º 10
0
		public static void DrawPixbufRect (this Context g, Gdk.Pixbuf pixbuf, Rectangle r)
		{
			Gdk.Pixbuf scaled = pixbuf.ScaleSimple ((int)r.Width, (int)r.Height, Gdk.InterpType.Bilinear);
			g.DrawPixbuf (scaled, (int)r.X, (int)r.Y);
		}
Exemplo n.º 11
0
        /// <summary>
        /// Gets preview of image.
        /// </summary>
        /// <param name="image">Original image.</param>
        /// <returns>Preview of original image.</returns>		
        private static Gdk.Pixbuf GetPreview(Gdk.Pixbuf image)
        {
            int width, height;

            if (image.Width < image.Height)
            {
                if (image.Height > MaxImageSize)
                {
                    height = MaxImageSize;
                    width = MaxImageSize * image.Width / image.Height;
                }
                else
                {
                    height = image.Height;
                    width = image.Width;
                }
            }
            else
            {
                if (image.Width > MaxImageSize)
                {
                    width = MaxImageSize;
                    height = MaxImageSize * image.Height / image.Width;
                }
                else
                {
                    width = image.Width;
                    height = image.Height;
                }
            }

            return image.ScaleSimple(width, height, Gdk.InterpType.Bilinear);
        }
Exemplo n.º 12
0
        public Gdk.Pixbuf GetThumbnail (Gdk.Pixbuf original, int squareDim)
        {
            int height = original.Height;
            int width = original.Width;

            if (height > width)
            {
                int newWidth = (width * squareDim)/height;
                return original.ScaleSimple (newWidth, squareDim, Gdk.InterpType.Bilinear);
            } else
            {
                int newHeight = (height * squareDim)/width;
                return original.ScaleSimple (squareDim, newHeight, Gdk.InterpType.Bilinear);
            }
        }
Exemplo n.º 13
0
		public static Gdk.Pixbuf ScaleIcon (Gdk.Pixbuf px, int width, int height)
		{
			var res = px.ScaleSimple (width, height, Gdk.InterpType.Bilinear);
			
			var icon2x = Get2xIconVariant (px);
			if (icon2x != null)
				Set2xIconVariant (res, ScaleIcon (icon2x, width*2, height * 2));
			return res;
		}
Exemplo n.º 14
0
        private static void Notify(string summary, string message,
						Gdk. Pixbuf image, Widget widget)
        {
            if (show_notifications == false) {
                return;
            }

            try {
                Notification nf = new Notification(summary, message);
                nf.AttachToWidget(widget);
                nf.Timeout = 4000;
                nf.Urgency = Urgency.Low;
                if (image != null) {
                    image = image.ScaleSimple (42, 42, Gdk.InterpType.Bilinear);
                    nf.Icon = image;
                }

                nf.Show();
            } catch (Exception) {
                show_notifications = false;
            }
        }
 public void SetIcon(Gdk.Pixbuf icon)
 {
     Properties.Set<Gdk.Pixbuf> ("Icon.Pixbuf_16", icon.ScaleSimple (16, 16, Gdk.InterpType.Bilinear));
 }