示例#1
0
		public static Gdk.Pixbuf LoadIcon (Gtk.Widget widget, string name, Gtk.IconSize size)
		{
			Gdk.Pixbuf res = widget.RenderIcon (name, size, null);
			if ((res != null)) {
				return res;
			} else {
				int sz;
				int sy;
				global::Gtk.Icon.SizeLookup (size, out  sz, out  sy);
				try {
					return Gtk.IconTheme.Default.LoadIcon (name, sz, 0);
				} catch (System.Exception) {
					if ((name != "gtk-missing-image")) {
						return Stetic.IconLoader.LoadIcon (widget, "gtk-missing-image", size);
					} else {
						Gdk.Pixmap pmap = new Gdk.Pixmap (Gdk.Screen.Default.RootWindow, sz, sz);
						Gdk.GC gc = new Gdk.GC (pmap);
						gc.RgbFgColor = new Gdk.Color (255, 255, 255);
						pmap.DrawRectangle (gc, true, 0, 0, sz, sz);
						gc.RgbFgColor = new Gdk.Color (0, 0, 0);
						pmap.DrawRectangle (gc, false, 0, 0, (sz - 1), (sz - 1));
						gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
						gc.RgbFgColor = new Gdk.Color (255, 0, 0);
						pmap.DrawLine (gc, (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)), ((sz - 1) - (sz / 4)));
						pmap.DrawLine (gc, ((sz - 1) - (sz / 4)), (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)));
						return Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, sz, sz);
					}
				}
			}
		}
示例#2
0
 public static Gdk.Pixbuf LoadIcon(Gtk.Widget widget, string name, Gtk.IconSize size, int sz)
 {
     Gdk.Pixbuf res = widget.RenderIcon(name, size, null);
     if ((res != null))
     {
         return(res);
     }
     else
     {
         try {
             return(Gtk.IconTheme.Default.LoadIcon(name, sz, 0));
         }
         catch (System.Exception) {
             if ((name != "gtk-missing-image"))
             {
                 return(Stetic.IconLoader.LoadIcon(widget, "gtk-missing-image", size, sz));
             }
             else
             {
                 Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, sz, sz);
                 Gdk.GC     gc   = new Gdk.GC(pmap);
                 gc.RgbFgColor = new Gdk.Color(255, 255, 255);
                 pmap.DrawRectangle(gc, true, 0, 0, sz, sz);
                 gc.RgbFgColor = new Gdk.Color(0, 0, 0);
                 pmap.DrawRectangle(gc, false, 0, 0, (sz - 1), (sz - 1));
                 gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                 gc.RgbFgColor = new Gdk.Color(255, 0, 0);
                 pmap.DrawLine(gc, (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)), ((sz - 1) - (sz / 4)));
                 pmap.DrawLine(gc, ((sz - 1) - (sz / 4)), (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)));
                 return(Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, sz, sz));
             }
         }
     }
 }
        internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor)
        {
            Gdk.Pixbuf result = null;

            Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(stockId);
            if (iconset != null)
            {
                // Find the size that better fits the requested size
                Gtk.IconSize gsize = Util.GetBestSizeFit(width);
                result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor);
                if (result == null || result.Width < width * scaleFactor)
                {
                    var gsize2x = Util.GetBestSizeFit(width * scaleFactor, iconset.Sizes);
                    if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize)
                    {
                        // Don't dispose the previous result since the icon is owned by the IconSet
                        result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null);
                    }
                }
            }

            if (result == null && Gtk.IconTheme.Default.HasIcon(stockId))
            {
                result = Gtk.IconTheme.Default.LoadIcon(stockId, (int)width, (Gtk.IconLookupFlags) 0);
            }

            if (result == null)
            {
                                #if XWT_GTK3
                // TODO: GTK3: render a custom gtk-missing-image icon if the stock icon
                //       if Gtk.Stock.MissingImage can not be loaded
                return(CreateBitmap(Gtk.Stock.MissingImage, width, height, scaleFactor));
                                #else
                int        w    = (int)width;
                int        h    = (int)height;
                Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, w, h);
                Gdk.GC     gc   = new Gdk.GC(pmap);
                gc.RgbFgColor = new Gdk.Color(255, 255, 255);
                pmap.DrawRectangle(gc, true, 0, 0, w, h);
                gc.RgbFgColor = new Gdk.Color(0, 0, 0);
                pmap.DrawRectangle(gc, false, 0, 0, (w - 1), (h - 1));
                gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                gc.RgbFgColor = new Gdk.Color(255, 0, 0);
                pmap.DrawLine(gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4)));
                pmap.DrawLine(gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4)));
                return(Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, w, h));
                                #endif
            }
            return(result);
        }
示例#4
0
	protected override Gdk.Pixmap Create(Gdk.Color fg, Gdk.Color bg)
	{
		Gdk.Window win = widget.GdkWindow;

		Gdk.GC gc = new Gdk.GC(win);
		Gdk.Pixmap pix = new Gdk.Pixmap(win, 4*2*width, height, -1);

		// draw the background
		gc.RgbFgColor = bg;
		pix.DrawRectangle(gc, true, 0, 0, 4*2*width, height);

		// render the bytes
		string s = "00011011";


		//Console.WriteLine(s);

		pangoLayout.SetText(s);


		gc.RgbFgColor = fg;
		pix.DrawLayout(gc, 0, 0, pangoLayout);

		return pix;
	}
示例#5
0
	protected override Gdk.Pixmap Create(Gdk.Color fg, Gdk.Color bg)
	{
		Gdk.Window win = widget.GdkWindow;

		Gdk.GC gc = new Gdk.GC(win);
		Gdk.Pixmap pix = new Gdk.Pixmap(win, 256*2*width, height, -1);

		// draw the background
		gc.RgbFgColor = bg;
		pix.DrawRectangle(gc, true, 0, 0, 256*2*width, height);

		// render the bytes
		string s;

		if (info.Uppercase == false)
			s = HexDrawer.HexTableLower;
		else
			s = HexDrawer.HexTableUpper;

		//System.Console.WriteLine(s);

		pangoLayout.SetText(s);


		gc.RgbFgColor = fg;
		pix.DrawLayout(gc, 0, 0, pangoLayout);

		return pix;
	}
示例#6
0
        public static Gdk.Pixbuf LoadIcon(Gtk.Widget widget, string name, Gtk.IconSize size)
        {
            #if GTK2
            Gdk.Pixbuf res = widget.RenderIcon(name, size, null);
            #elif GTK3
            Gdk.Pixbuf res = widget.RenderIconPixbuf(name, size);
            #endif

            if ((res != null))
            {
                return(res);
            }
            else
            {
                int sz;
                int sy;
                global::Gtk.Icon.SizeLookup(size, out sz, out sy);
                try {
                    return(Gtk.IconTheme.Default.LoadIcon(name, sz, 0));
                } catch (System.Exception) {
                    if ((name != "gtk-missing-image"))
                    {
                        return(Stetic.IconLoader.LoadIcon(widget, "gtk-missing-image", size));
                    }
                    else
                    {
                        #if GTK2
                        Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, sz, sz);
                        Gdk.GC     gc   = new Gdk.GC(pmap);
                        gc.RgbFgColor = new Gdk.Color(255, 255, 255);
                        pmap.DrawRectangle(gc, true, 0, 0, sz, sz);
                        gc.RgbFgColor = new Gdk.Color(0, 0, 0);
                        pmap.DrawRectangle(gc, false, 0, 0, (sz - 1), (sz - 1));
                        gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                        gc.RgbFgColor = new Gdk.Color(255, 0, 0);
                        pmap.DrawLine(gc, (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)), ((sz - 1) - (sz / 4)));
                        pmap.DrawLine(gc, ((sz - 1) - (sz / 4)), (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)));
                        return(Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, sz, sz));
                        #elif GTK3
                        throw new System.NotImplementedException();
                        #endif
                    }
                }
            }
        }
示例#7
0
        private void HandleRenderingQueueProgressMessageReport(string source, string destination, double progress, string status, IBitmapCore image)
        {
            Application.Invoke(delegate {
                source_label.Text               = source;
                destination_label.Text          = destination;
                processing_progressbar.Fraction = progress;
                processing_progressbar.Text     = status;

                mProcessingStatusIcon.Tooltip = "Processing " + System.IO.Path.GetFileName(source) + ". " + status + " (" + ((int)(progress * 100)).ToString() + "%)";

                thumb_image.Visible = (image != null);

                if ((DateTime.Now - updateMoment).TotalMilliseconds > drawingTimeSpan.TotalMilliseconds * 5 && image != null && this.Visible)
                {
                    updateMoment = DateTime.Now;
                    // Drawing
                    int size = 300, margins = 30;

                    thumb_image.SetSizeRequest(size + margins, size + margins);
                    using (Gdk.Pixmap pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1))
                    {
                        using (Gdk.Pixbuf pb = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, image.Width, image.Height))
                        {
                            using (Gdk.GC gc = new Gdk.GC(thumb_image.GdkWindow))
                            {
                                ((FloatBitmapGtk)image).DrawToPixbuf(pb, null);

                                Gdk.Pixbuf pb2;

                                if (pb.Width > pb.Height)
                                {
                                    pb2 = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear);
                                }
                                else
                                {
                                    pb2 = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear);
                                }

                                pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins));

                                pm.DrawPixbuf(gc, pb2, 0, 0,
                                              (size + margins) / 2 - pb2.Width / 2,
                                              (size + margins) / 2 - pb2.Height / 2,
                                              pb2.Width, pb2.Height, Gdk.RgbDither.Max, 0, 0);

                                pb2.Dispose();

                                thumb_image.SetFromPixmap(pm, null);
                            }
                        }
                    }
                    drawingTimeSpan = DateTime.Now - updateMoment;
                }
            });
        }
示例#8
0
        public static void Main(string[] args)
        {
            Application.Init();
            Window win = new Window(WindowType.Toplevel);

            VBox   vBox = new VBox();
            HScale transparencyScale = new HScale(0, 255, 1)
            {
                Value = 255
            };
            Image image = new Image();

            image.SetSizeRequest(200, 200);

            vBox.PackStart(transparencyScale);
            vBox.PackStart(image);
            win.Add(vBox);

            transparencyScale.ValueChanged += delegate {
                int    transparency = (int)transparencyScale.Value;
                byte[] tBytes       = BitConverter.GetBytes(transparency);

                Gdk.GC red = new Gdk.GC(win.GdkWindow)
                {
                    RgbFgColor = new Gdk.Color(255, 0, 0)
                };
                Gdk.GC black = new Gdk.GC(win.GdkWindow)
                {
                    RgbFgColor = new Gdk.Color(0, 0, 0)
                };
                Gdk.GC translucent = new Gdk.GC(win.GdkWindow)
                {
                    RgbFgColor = new Gdk.Color(tBytes[0], tBytes[0], tBytes[0])
                };
                Gdk.GC visible = new Gdk.GC(win.GdkWindow)
                {
                    RgbFgColor = new Gdk.Color(255, 255, 255)
                };

                Gdk.Pixmap pixmap = new Gdk.Pixmap(win.GdkWindow, 200, 200);
                pixmap.DrawRectangle(black, true, 0, 0, 200, 200);
                pixmap.DrawArc(red, true, 20, 20, 160, 160, 0, 23040);

                Gdk.Pixmap mask = new Gdk.Pixmap(win.GdkWindow, 200, 200);
                mask.DrawRectangle(visible, true, 0, 0, 200, 200);
                mask.DrawArc(translucent, true, 0, 0, 100, 100, 0, 23040);
                mask.DrawArc(translucent, true, 100, 100, 100, 100, 0, 23040);

                image.SetFromPixmap(pixmap, mask);
                image.ShowAll();
            };

            win.ShowAll();
            Application.Run();
        }
		protected override Gdk.Pixbuf RenderInitialPixbuf (Gdk.Window parentwindow, Gdk.Rectangle bounds)
		{
			//FIXME add a drop shadow on the pixmap, and expand the bounds to include this
			using (Gdk.Pixmap pixmap = new Gdk.Pixmap (parentwindow, bounds.Width, bounds.Height)) {
				using (var bgGc = new Gdk.GC(pixmap)) {
					bgGc.RgbFgColor = CairoExtensions.CairoColorToGdkColor (marker.colorMatrix[0, 0, 0, 0, 0]);
					pixmap.DrawRectangle (bgGc, true, 0, 0, bounds.Width, bounds.Height);
					pixmap.DrawLayout (marker.gc, 4, (bounds.Height - marker.Layouts[0].Height) / 2, marker.Layouts[0].Layout);
				}
				return Gdk.Pixbuf.FromDrawable (pixmap, Colormap, 0, 0, 0, 0, bounds.Width, bounds.Height);
			}
		}
示例#10
0
 protected override Gdk.Pixbuf RenderInitialPixbuf(Gdk.Window parentwindow, Gdk.Rectangle bounds)
 {
     //FIXME add a drop shadow on the pixmap, and expand the bounds to include this
     using (Gdk.Pixmap pixmap = new Gdk.Pixmap(parentwindow, bounds.Width, bounds.Height)) {
         using (var bgGc = new Gdk.GC(pixmap)) {
             bgGc.RgbFgColor = CairoExtensions.CairoColorToGdkColor(marker.colorMatrix[0, 0, 0, 0, 0]);
             pixmap.DrawRectangle(bgGc, true, 0, 0, bounds.Width, bounds.Height);
             pixmap.DrawLayout(marker.gc, 4, (bounds.Height - marker.Layouts[0].Height) / 2, marker.Layouts[0].Layout);
         }
         return(Gdk.Pixbuf.FromDrawable(pixmap, Colormap, 0, 0, 0, 0, bounds.Width, bounds.Height));
     }
 }
 public static Gdk.Pixbuf LoadIcon(string name, int sz) {
     try {
         return Gtk.IconTheme.Default.LoadIcon(name, sz, 0);
     }
     catch (System.Exception ) {
         if ((name != "gtk-missing-image")) {
             return Stetic.IconLoader.LoadIcon("gtk-missing-image", sz);
         }
         else {
             Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, sz, sz);
             Gdk.GC gc = new Gdk.GC(pmap);
             gc.RgbFgColor = new Gdk.Color(255, 255, 255);
             pmap.DrawRectangle(gc, true, 0, 0, sz, sz);
             gc.RgbFgColor = new Gdk.Color(0, 0, 0);
             pmap.DrawRectangle(gc, false, 0, 0, (sz - 1), (sz - 1));
             gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
             gc.RgbFgColor = new Gdk.Color(255, 0, 0);
             pmap.DrawLine(gc, (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)), ((sz - 1) - (sz / 4)));
             pmap.DrawLine(gc, ((sz - 1) - (sz / 4)), (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)));
             return Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, sz, sz);
         }
     }
 }
示例#12
0
        protected virtual void OnViewExposeEvent(object o, Gtk.ExposeEventArgs args)
        {
            Gdk.Window win = args.Event.Window;

            // Draw the window border
            win.DrawRectangle(darkgc, false, 0, 0, dimensions + 1, dimensions + 1);

            if (arena != null)
            {
                const int d = Constants.ARENA_SIZE;

                // Clear the pixmap
                view_pixmap.DrawRectangle(whitegc, true, 0, 0, d, d);
                arena.draw(view_graphics);

                if (scaling_ == ScalingMode.None)
                {
                    win.DrawDrawable(whitegc, view_pixmap, 0, 0, 1, 1, d, d);
                }
                else
                {
                    Gdk.Pixbuf pb = Gdk.Pixbuf.FromDrawable(view_pixmap, win.Screen.DefaultColormap,
                                                            0, 0, 0, 0, d, d);

                    Gdk.Pixbuf spb = null;
                    switch (scaling_)
                    {
                    case ScalingMode.Nearest2x:
                    case ScalingMode.Nearest3x:
                        spb = pb.ScaleSimple(dimensions, dimensions, Gdk.InterpType.Nearest);
                        break;

                    case ScalingMode.Bilinear2x:
                    case ScalingMode.Bilinear3x:
                        spb = pb.ScaleSimple(dimensions, dimensions, Gdk.InterpType.Bilinear);
                        break;
                    }

                    win.DrawPixbuf(whitegc, spb, 0, 0, 1, 1, dimensions, dimensions,
                                   Gdk.RgbDither.None, 0, 0);
                }
            }

            args.RetVal = true;
        }
        public void DrawWindowFrame(Gtk.Widget w, string caption, int x, int y, int width, int height)
        {
            Gdk.Drawable drawable = w.GdkWindow;
            Gdk.Pixmap   pix      = new Gdk.Pixmap(drawable, width, height, drawable.Depth);

            Gdk.GC gcc = new Gdk.GC(pix);
            gcc.Foreground = w.Style.Backgrounds [(int)Gtk.StateType.Normal];
            pix.DrawRectangle(gcc, true, 0, 0, width, height);

            IntPtr hdc = gdk_win32_hdc_get(pix.Handle, gcc.Handle, 0);

            RECT r = new RECT(0, 0, width, height);
            SIZE size;

            GetThemePartSize(hTheme, hdc, WP_CAPTION, CS_ACTIVE, ref r, 1, out size);

            r.Bottom = size.cy;
            DrawThemeBackground(hTheme, hdc, WP_CAPTION, CS_ACTIVE, ref r, ref r);

            RECT    rf = new RECT(FrameBorder, FrameBorder, width - FrameBorder * 2, size.cy);
            LOGFONT lf = new LOGFONT();

            GetThemeSysFont(hTheme, TMT_CAPTIONFONT, ref lf);
            IntPtr titleFont = CreateFontIndirect(ref lf);
            IntPtr oldFont   = SelectObject(hdc, titleFont);

            SetBkMode(hdc, 1 /*TRANSPARENT*/);
            DrawThemeText(hTheme, hdc, WP_CAPTION, CS_ACTIVE, caption, -1, DT_LEFT | DT_SINGLELINE | DT_WORD_ELLIPSIS, 0, ref rf);
            SelectObject(hdc, oldFont);
            DeleteObject(titleFont);

            int ny = r.Bottom;

            r = new RECT(0, ny, width, height);
            DrawThemeBackground(hTheme, hdc, WP_FRAMEBOTTOM, 0, ref r, ref r);

            gdk_win32_hdc_release(pix.Handle, gcc.Handle, 0);

            Gdk.Pixbuf img = Gdk.Pixbuf.FromDrawable(pix, pix.Colormap, 0, 0, 0, 0, width, height);
            drawable.DrawPixbuf(new Gdk.GC(drawable), img, 0, 0, x, y, width, height, Gdk.RgbDither.None, 0, 0);
            drawable.DrawRectangle(w.Style.BackgroundGC(Gtk.StateType.Normal), true, x + FrameBorder, y + size.cy, width - FrameBorder * 2, height - FrameBorder - size.cy);
        }
示例#14
0
        protected override Gdk.Pixmap Create(Gdk.Color fg, Gdk.Color bg)
        {
            Gdk.Window win = widget.GdkWindow;

            Gdk.GC     gc  = new Gdk.GC(win);
            Gdk.Pixmap pix = new Gdk.Pixmap(win, 256 * 2 * width, height, -1);

            // draw the background
            gc.RgbFgColor = bg;
            pix.DrawRectangle(gc, true, 0, 0, 256 * 2 * width, height);

            // render the bytes
            string s;

            if (info.Uppercase == false)
            {
                s = HexDrawer.HexTableLower;
            }
            else
            {
                s = HexDrawer.HexTableUpper;
            }

            //System.Console.WriteLine(s);

            gc.RgbFgColor = fg;

            // Render the text in two parts (256 printable characters each).  We do
            // this to work around a bug in some drivers that fail to render text
            // that ends up wider than 4096 pixels.
            pangoLayout.SetText(s.Substring(0, 256));
            pix.DrawLayout(gc, 0, 0, pangoLayout);

            // The second part also contains the two Zero Width Non-Joiner
            // characters, so it's actually 258 string characters, although still
            // 256 printable characters.
            pangoLayout.SetText(s.Substring(256));
            pix.DrawLayout(gc, 128 * 2 * width, 0, pangoLayout);

            return(pix);
        }
示例#15
0
		public void DrawWindowFrame (Gtk.Widget w, string caption, int x, int y, int width, int height)
		{
			Gdk.Drawable drawable = w.GdkWindow;
			Gdk.Pixmap pix = new Gdk.Pixmap (drawable, width, height, drawable.Depth);

			Gdk.GC gcc = new Gdk.GC (pix);
			gcc.Foreground = w.Style.Backgrounds [(int)Gtk.StateType.Normal];
			pix.DrawRectangle (gcc, true, 0, 0, width, height);

			IntPtr hdc = gdk_win32_hdc_get (pix.Handle, gcc.Handle, 0);

			RECT r = new RECT (0, 0, width, height);
			SIZE size;
			GetThemePartSize (hTheme, hdc, WP_CAPTION, CS_ACTIVE, ref r, 1, out size);

			r.Bottom = size.cy;
			DrawThemeBackground (hTheme, hdc, WP_CAPTION, CS_ACTIVE, ref r, ref r);

			RECT rf = new RECT (FrameBorder, FrameBorder, width - FrameBorder * 2, size.cy);
			LOGFONT lf = new LOGFONT ();
			GetThemeSysFont (hTheme, TMT_CAPTIONFONT, ref lf);
			IntPtr titleFont = CreateFontIndirect (ref lf);
			IntPtr oldFont = SelectObject (hdc, titleFont);
			SetBkMode (hdc, 1 /*TRANSPARENT*/);
			DrawThemeText (hTheme, hdc, WP_CAPTION, CS_ACTIVE, caption, -1, DT_LEFT | DT_SINGLELINE | DT_WORD_ELLIPSIS, 0, ref rf);
			SelectObject (hdc, oldFont);
			DeleteObject (titleFont);

			int ny = r.Bottom;
			r = new RECT (0, ny, width, height);
			DrawThemeBackground (hTheme, hdc, WP_FRAMEBOTTOM, 0, ref r, ref r);

			gdk_win32_hdc_release (pix.Handle, gcc.Handle, 0);

			Gdk.Pixbuf img = Gdk.Pixbuf.FromDrawable (pix, pix.Colormap, 0, 0, 0, 0, width, height);
			drawable.DrawPixbuf (new Gdk.GC (drawable), img, 0, 0, x, y, width, height, Gdk.RgbDither.None, 0, 0);
			drawable.DrawRectangle (w.Style.BackgroundGC (Gtk.StateType.Normal), true, x + FrameBorder, y + size.cy, width - FrameBorder * 2, height - FrameBorder - size.cy);
		}
示例#16
0
        internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor)
        {
            Gdk.Pixbuf result = null;

            Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault (stockId);
            if (iconset != null) {
                // Find the size that better fits the requested size
                Gtk.IconSize gsize = Util.GetBestSizeFit (width);
                result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor);
                if (result == null || result.Width < width * scaleFactor) {
                    var gsize2x = Util.GetBestSizeFit (width * scaleFactor, iconset.Sizes);
                    if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize)
                        // Don't dispose the previous result since the icon is owned by the IconSet
                        result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null);
                }
            }

            if (result == null && Gtk.IconTheme.Default.HasIcon (stockId))
                result = Gtk.IconTheme.Default.LoadIcon (stockId, (int)width, (Gtk.IconLookupFlags)0);

            if (result == null) {
            //				return CreateBitmap (Gtk.Stock.MissingImage, width, height, scaleFactor);
                int w = (int) width;
                int h = (int) height;
                Gdk.Pixmap pmap = new Gdk.Pixmap (Gdk.Screen.Default.RootWindow, w, h);
                Gdk.GC gc = new Gdk.GC (pmap);
                gc.RgbFgColor = new Gdk.Color (255, 255, 255);
                pmap.DrawRectangle (gc, true, 0, 0, w, h);
                gc.RgbFgColor = new Gdk.Color (0, 0, 0);
                pmap.DrawRectangle (gc, false, 0, 0, (w - 1), (h - 1));
                gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                gc.RgbFgColor = new Gdk.Color (255, 0, 0);
                pmap.DrawLine (gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4)));
                pmap.DrawLine (gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4)));
                return Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, w, h);
            }
            return result;
        }
示例#17
0
        protected void UpdatePreview()
        {
            thumb_image.Clear();
            FileIsGood = false;

            int size = 200, margins = 30;

            if (System.IO.File.Exists(mFilename))              // Selected item is a file
            {
                origsize_label.Markup = "";

                GLib.Timeout.Add(100, new GLib.TimeoutHandler(delegate {
                    Gdk.Pixmap pm = null;
                    Gdk.GC gc     = null;
                    Gdk.Pixbuf pb = null;
                    try
                    {
                        pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1);
                        gc = new Gdk.GC(thumb_image.GdkWindow);
                        pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins));

                        RawDescriptionLoader rdl = RawDescriptionLoader.FromFile(mFilename);

                        string idtext = "";
                        try
                        {
                            idtext += "Shot has been taken\n" +
                                      "   on <b>" + rdl.TimeStamp.ToString("MMMM, d, yyyy") + "</b> at <b>" + rdl.TimeStamp.ToString("h:mm:ss tt") + "</b>,\n";

                            idtext += "   with <b>" + rdl.CameraMaker + " " + rdl.CameraModel + "</b>\n\n";
                            idtext += "ISO speed: <b>" + rdl.ISOSpeed.ToString("0") + "</b>\n";
                            if (rdl.Shutter > 1)
                            {
                                idtext += "Shutter: <b>" + rdl.Shutter.ToString("0.0") + "</b> sec\n";
                            }
                            else
                            {
                                idtext += "Shutter: <b>1/" + (1.0 / (rdl.Shutter + 0.000001)).ToString("0") + "</b> sec\n";
                            }

                            idtext += "Aperture: <b>" + rdl.Aperture.ToString("0.0") + "</b>\n" +
                                      "Focal length: <b>" + rdl.FocalLength.ToString("0") + "</b> mm\n";

                            if (rdl.Artist != "")
                            {
                                idtext += "Artist: <b>" + rdl.Artist + "</b>\n";
                            }
                            if (rdl.Description != "")
                            {
                                idtext += "Description: <b>" + rdl.Description + "</b>\n";
                            }

                            Console.WriteLine(rdl.Flip);

                            // Creating the thumbnail pixbuf
                            pb = new Gdk.Pixbuf(rdl.ThumbnailData);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Can't load the thumbnail: " + ex.Message);
                            idtext += "\n<i>Can't load the thumbnail.</i>";
                        }
                        identification_label.Markup = idtext;

                        if (pb != null)
                        {
                            // Scaling the thumbnail
                            Gdk.Pixbuf pbold = pb;
                            int imgw         = pb.Width, imgh = pb.Height;
                            if (pb.Width > pb.Height)
                            {
                                pb = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear);
                            }
                            else
                            {
                                pb = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear);
                            }

                            pbold.Dispose();

                            // Rotating the thumbnail
                            if (rdl.Flip != RawDescriptionLoader.FlipValues.None)
                            {
                                pbold = pb;

                                if (rdl.Flip == RawDescriptionLoader.FlipValues.UpsideDown)
                                {
                                    pb = pb.RotateSimple(Gdk.PixbufRotation.Upsidedown);
                                }
                                else if (rdl.Flip == RawDescriptionLoader.FlipValues.Clockwise)
                                {
                                    int t = imgw;
                                    imgw  = imgh;
                                    imgh  = t;
                                    pb    = pb.RotateSimple(Gdk.PixbufRotation.Clockwise);
                                }
                                else if (rdl.Flip == RawDescriptionLoader.FlipValues.Counterclockwise)
                                {
                                    int t = imgw;
                                    imgw  = imgh;
                                    imgh  = t;
                                    pb    = pb.RotateSimple(Gdk.PixbufRotation.Counterclockwise);
                                }

                                pbold.Dispose();
                            }

                            origsize_label.Markup = "Image size: <b>" + imgw + "</b> x <b>" + imgh + "</b>";
                            pm.DrawPixbuf(gc, pb, 0, 0,
                                          (size + margins) / 2 - pb.Width / 2,
                                          (size + margins) / 2 - pb.Height / 2,
                                          pb.Width, pb.Height, Gdk.RgbDither.Max, 0, 0);
                            thumb_image.SetFromPixmap(pm, null);
                            pb.Dispose();
                        }
                        FileIsGood = true;
                    }
                    catch (Exception
#if DEBUG
                           ex
#endif
                           )
                    {
#if DEBUG
                        Console.WriteLine("Exception occured during the thumbnail loading process: " + ex.Message);
#endif
                        identification_label.Wrap   = true;
                        identification_label.Markup = "<i>Cannot decode the selected file. " +
                                                      "Maybe it's corrupted or the user hasn't enough access rights to open it.</i>";
                        FileIsGood = false;
                    }
                    finally
                    {
                        if (gc != null)
                        {
                            gc.Dispose();
                        }
                        if (pm != null)
                        {
                            pm.Dispose();
                        }
                    }
                    return(false);
                }));
            }
        }
示例#18
0
文件: ImageHandler.cs 项目: mono/xwt
        internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor)
        {
            Gdk.Pixbuf result = null;

            Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault (stockId);
            if (iconset != null) {
                // Find the size that better fits the requested size
                Gtk.IconSize gsize = Util.GetBestSizeFit (width);
                result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor);
                if (result == null || result.Width < width * scaleFactor) {
                    var gsize2x = Util.GetBestSizeFit (width * scaleFactor, iconset.Sizes);
                    if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize)
                        // Don't dispose the previous result since the icon is owned by the IconSet
                        result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null);
                }
            }

            if (result == null && Gtk.IconTheme.Default.HasIcon (stockId))
                result = Gtk.IconTheme.Default.LoadIcon (stockId, (int)width, (Gtk.IconLookupFlags)0);

            if (result == null)
            {
                // render a custom gtk-missing-image icon
                // if Gtk.Stock.MissingImage is not found
                int w = (int)width;
                int h = (int)height;
                #if XWT_GTK3
                Cairo.ImageSurface s = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
                Cairo.Context cr = new Cairo.Context(s);
                cr.SetSourceRGB(255, 255, 255);
                cr.Rectangle(0, 0, w, h);
                cr.Fill();
                cr.SetSourceRGB(0, 0, 0);
                cr.LineWidth = 1;
                cr.Rectangle(0.5, 0.5, w - 1, h - 1);
                cr.Stroke();
                cr.SetSourceRGB(255, 0, 0);
                cr.LineWidth = 3;
                cr.LineCap = Cairo.LineCap.Round;
                cr.LineJoin = Cairo.LineJoin.Round;
                cr.MoveTo(w / 4, h / 4);
                cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4);
                cr.MoveTo(w / 4, (h - 1) - h / 4);
                cr.LineTo((w - 1) - w / 4, h / 4);
                cr.Stroke();
                result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h);
                #else
                using (Gdk.Pixmap pmap = new Gdk.Pixmap (Gdk.Screen.Default.RootWindow, w, h))
                using (Gdk.GC gc = new Gdk.GC (pmap)) {
                    gc.RgbFgColor = new Gdk.Color (255, 255, 255);
                    pmap.DrawRectangle (gc, true, 0, 0, w, h);
                    gc.RgbFgColor = new Gdk.Color (0, 0, 0);
                    pmap.DrawRectangle (gc, false, 0, 0, (w - 1), (h - 1));
                    gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                    gc.RgbFgColor = new Gdk.Color (255, 0, 0);
                    pmap.DrawLine (gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4)));
                    pmap.DrawLine (gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4)));
                    result = Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, w, h);
                }
                #endif
            }
            return result;
        }
示例#19
0
        private bool OnTimedDraw()
        {
            bool draw = false;


            lock (_window)
            {
                if (!_isDrawing)
                {
                    _isDrawing = true;
                    draw       = true;
                }
            }

            if (draw)
            {
                int w, h;

                _pixmap.GetSize(out w, out h);

                bool screenChanged = w != _oldWidth || h != _oldHeight;

                Gdk.GC gc = new Gdk.GC(_pixmap);
                _pixmap.DrawRectangle(gc, true, 0, 0, w, h);


                using (Context context = Gdk.CairoHelper.Create(_pixmap))
                {
#if DRAWGRID
                    context.Color = _gridColor;

                    int ew = w / 8;
                    int eh = h / 7;

                    for (int i = 0; i < 9; i++)
                    {
                        int x = i * ew + _anime % ew;

                        context.MoveTo(x, 0);
                        context.LineTo(x, h);
                        context.Stroke();
                    }
                    for (int j = 0; j < 8; j++)
                    {
                        int y = j * eh + _anime % eh;

                        context.MoveTo(0, y);
                        context.LineTo(w, y);
                        context.Stroke();
                    }
#endif

                    try
                    {
                        Cairo.Context g = Gdk.CairoHelper.Create(_pixmap);

                        State.Draw(_pixmap, g, w, h, screenChanged);

                        if (MessageBox != null)
                        {
                            MessageBox.Draw(_pixmap, g, w, h, screenChanged);
                        }

                        ((IDisposable)g.Target).Dispose();
                        ((IDisposable)g).Dispose();
                    }
                    catch (Exception e)
                    {
                        HandleFatalException(e, " experienced while attempting to run State.Draw()");
                    }
                }

                lock (_window)
                {
                    _isDrawing = false;
                }
            }

            _window.GetSize(out _oldWidth, out _oldHeight);
            _window.QueueDrawArea(0, 0, _oldWidth, _oldHeight);

            return(true);
        }
        private void HandleRenderingQueueProgressMessageReport(string source, string destination, double progress, string status, IBitmapCore image)
        {
            Application.Invoke(delegate {
                source_label.Text = source;
                destination_label.Text = destination;
                processing_progressbar.Fraction = progress;
                processing_progressbar.Text = status;

                mProcessingStatusIcon.Tooltip = "Processing " + System.IO.Path.GetFileName(source) + ". " + status + " (" + ((int)(progress * 100)).ToString() + "%)";

                thumb_image.Visible = (image != null);

                if ((DateTime.Now - updateMoment).TotalMilliseconds > drawingTimeSpan.TotalMilliseconds * 5 && image != null && this.Visible)
                {
                    updateMoment = DateTime.Now;
                    // Drawing
                    int size = 300, margins = 30;

                    thumb_image.SetSizeRequest(size + margins, size + margins);
                    using (Gdk.Pixmap pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1))
                    {
                        using (Gdk.Pixbuf pb = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, image.Width, image.Height))
                        {
                            using (Gdk.GC gc = new Gdk.GC(thumb_image.GdkWindow))
                            {
                                ((FloatBitmapGtk)image).DrawToPixbuf(pb, null);

                                Gdk.Pixbuf pb2;

                                if (pb.Width > pb.Height)
                                    pb2 = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear);
                                else
                                    pb2 = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear);

                                pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins));

                                pm.DrawPixbuf(gc, pb2, 0, 0,
                                              (size + margins) / 2 - pb2.Width / 2,
                                              (size + margins) / 2 - pb2.Height / 2,
                                              pb2.Width, pb2.Height, Gdk.RgbDither.Max, 0, 0);

                                pb2.Dispose();

                                thumb_image.SetFromPixmap(pm, null);
                            }
                        }
                    }
                    drawingTimeSpan = DateTime.Now - updateMoment;
                }
            });
        }
示例#21
0
    protected override bool OnExposeEvent(Gdk.EventExpose args)
    {
        if (bitmap_cache == null) {
            bitmap_cache = new Gdk.Pixmap (GdkWindow, background.Width, background.Height, -1);
            bitmap_cache.DrawRectangle (Style.WhiteGC, true, 0, 0,
                background.Width, background.Height);

            using (Graphics g = Gtk.DotNet.Graphics.FromDrawable (bitmap_cache)) {
                Plot (g);
            }
        }

        GRect area;
        if (args.Area.Intersect (background, out area))
            GdkWindow.DrawRectangle (Style.BaseGC (State), true, area);

        GdkWindow.DrawDrawable (Style.BlackGC,
                        bitmap_cache,
                        0, 0,
                        background.X, background.Y,
                        background.Width, background.Height);

        Style.PaintShadow (this.Style, GdkWindow, State, ShadowType.In, area,
                   this, null, background.X, background.Y,
                   background.Width, background.Height);

        if (glass != null) {
            glass.Draw (args.Area);
        }

        return base.OnExposeEvent (args);
    }
示例#22
0
        protected void UpdatePreview()
        {
            thumb_image.Clear();
            FileIsGood = false;

            int size = 200, margins = 30;

            if (System.IO.File.Exists(mFilename))  // Selected item is a file
            {
                origsize_label.Markup = "";

                GLib.Timeout.Add(100, new GLib.TimeoutHandler(delegate {

                    Gdk.Pixmap pm = null;
                    Gdk.GC gc = null;
                    Gdk.Pixbuf pb = null;
                    try
                    {
                        pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1);
                        gc = new Gdk.GC(thumb_image.GdkWindow);
                        pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins));

                        RawDescriptionLoader rdl = RawDescriptionLoader.FromFile(mFilename);

                        string idtext = "";
                        try
                        {
                            idtext += "Shot has been taken\n" +
                                      "   on <b>" + rdl.TimeStamp.ToString("MMMM, d, yyyy") + "</b> at <b>" + rdl.TimeStamp.ToString("h:mm:ss tt") + "</b>,\n";

                            idtext += "   with <b>" + rdl.CameraMaker + " " + rdl.CameraModel + "</b>\n\n";
                            idtext += "ISO speed: <b>" + rdl.ISOSpeed.ToString("0") + "</b>\n";
                            if (rdl.Shutter > 1)
                                idtext += "Shutter: <b>" + rdl.Shutter.ToString("0.0") + "</b> sec\n";
                            else
                                idtext += "Shutter: <b>1/" + (1.0 / (rdl.Shutter + 0.000001)).ToString("0") + "</b> sec\n";

                            idtext += "Aperture: <b>" + rdl.Aperture.ToString("0.0") + "</b>\n" +
                                      "Focal length: <b>" + rdl.FocalLength.ToString("0") + "</b> mm\n";

                            if (rdl.Artist != "") idtext += "Artist: <b>" + rdl.Artist + "</b>\n";
                            if (rdl.Description != "") idtext += "Description: <b>" + rdl.Description + "</b>\n";

                            Console.WriteLine(rdl.Flip);

                            // Creating the thumbnail pixbuf
                            pb = new Gdk.Pixbuf(rdl.ThumbnailData);

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Can't load the thumbnail: " + ex.Message);
                            idtext += "\n<i>Can't load the thumbnail.</i>";
                        }
                        identification_label.Markup = idtext;

                        if (pb != null)
                        {
                            // Scaling the thumbnail
                            Gdk.Pixbuf pbold = pb;
                            int imgw = pb.Width, imgh = pb.Height;
                            if (pb.Width > pb.Height)
                                pb = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear);
                            else
                                pb = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear);

                            pbold.Dispose();

                            // Rotating the thumbnail
                            if (rdl.Flip != RawDescriptionLoader.FlipValues.None)
                            {
                                pbold = pb;

                                if (rdl.Flip == RawDescriptionLoader.FlipValues.UpsideDown)
                                    pb = pb.RotateSimple(Gdk.PixbufRotation.Upsidedown);
                                else if (rdl.Flip == RawDescriptionLoader.FlipValues.Clockwise)
                                {
                                    int t = imgw;
                                    imgw = imgh;
                                    imgh = t;
                                    pb = pb.RotateSimple(Gdk.PixbufRotation.Clockwise);
                                }
                                else if (rdl.Flip == RawDescriptionLoader.FlipValues.Counterclockwise)
                                {
                                    int t = imgw;
                                    imgw = imgh;
                                    imgh = t;
                                    pb = pb.RotateSimple(Gdk.PixbufRotation.Counterclockwise);
                                }

                                pbold.Dispose();
                            }

                            origsize_label.Markup = "Image size: <b>" + imgw + "</b> x <b>" + imgh + "</b>";
                            pm.DrawPixbuf(gc, pb, 0, 0,
                                          (size + margins) / 2 - pb.Width / 2,
                                          (size + margins) / 2 - pb.Height / 2,
                                          pb.Width, pb.Height, Gdk.RgbDither.Max, 0, 0);
                            thumb_image.SetFromPixmap(pm, null);
                            pb.Dispose();
                        }
                        FileIsGood = true;
                    }
                    catch (Exception
            #if DEBUG
                        ex
            #endif
                        )
                    {
            #if DEBUG
                        Console.WriteLine("Exception occured during the thumbnail loading process: " + ex.Message);
            #endif
                        identification_label.Wrap = true;
                        identification_label.Markup = "<i>Cannot decode the selected file. "+
                                                      "Maybe it's corrupted or the user hasn't enough access rights to open it.</i>";
                        FileIsGood = false;
                    }
                    finally
                    {
                        if (gc != null) gc.Dispose();
                        if (pm != null) pm.Dispose();
                    }
                    return false;
                }));
            }
        }
示例#23
0
        internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor)
        {
            Gdk.Pixbuf result = null;

            Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(stockId);
            if (iconset != null)
            {
                // Find the size that better fits the requested size
                Gtk.IconSize gsize = Util.GetBestSizeFit(width);
                result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor);
                if (result == null || result.Width < width * scaleFactor)
                {
                    var gsize2x = Util.GetBestSizeFit(width * scaleFactor, iconset.Sizes);
                    if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize)
                    {
                        // Don't dispose the previous result since the icon is owned by the IconSet
                        result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null);
                    }
                }
            }

            if (result == null && Gtk.IconTheme.Default.HasIcon(stockId))
            {
                result = Gtk.IconTheme.Default.LoadIcon(stockId, (int)width, (Gtk.IconLookupFlags) 0);
            }

            if (result == null)
            {
                // render a custom gtk-missing-image icon
                // if Gtk.Stock.MissingImage is not found
                int w = (int)width;
                int h = (int)height;
                                #if XWT_GTK3
                Cairo.ImageSurface s  = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
                Cairo.Context      cr = new Cairo.Context(s);
                cr.SetSourceRGB(255, 255, 255);
                cr.Rectangle(0, 0, w, h);
                cr.Fill();
                cr.SetSourceRGB(0, 0, 0);
                cr.LineWidth = 1;
                cr.Rectangle(0.5, 0.5, w - 1, h - 1);
                cr.Stroke();
                cr.SetSourceRGB(255, 0, 0);
                cr.LineWidth = 3;
                cr.LineCap   = Cairo.LineCap.Round;
                cr.LineJoin  = Cairo.LineJoin.Round;
                cr.MoveTo(w / 4, h / 4);
                cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4);
                cr.MoveTo(w / 4, (h - 1) - h / 4);
                cr.LineTo((w - 1) - w / 4, h / 4);
                cr.Stroke();
                result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h);
                                #else
                using (Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, w, h))
                    using (Gdk.GC gc = new Gdk.GC(pmap)) {
                        gc.RgbFgColor = new Gdk.Color(255, 255, 255);
                        pmap.DrawRectangle(gc, true, 0, 0, w, h);
                        gc.RgbFgColor = new Gdk.Color(0, 0, 0);
                        pmap.DrawRectangle(gc, false, 0, 0, (w - 1), (h - 1));
                        gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                        gc.RgbFgColor = new Gdk.Color(255, 0, 0);
                        pmap.DrawLine(gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4)));
                        pmap.DrawLine(gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4)));
                        result = Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, w, h);
                    }
                                #endif
            }
            return(result);
        }
示例#24
0
    protected override bool OnExposeEvent(Gdk.EventExpose args)
    {
        if (bitmap_cache == null) {
            bitmap_cache = new Gdk.Pixmap (GdkWindow, graph_area.Width, graph_area.Height, -1);
            bitmap_cache.DrawRectangle (Style.WhiteGC, true, 0, 0,
                graph_area.Width, graph_area.Height);

            using (Graphics g = Gtk.DotNet.Graphics.FromDrawable (bitmap_cache)) {
                plot = new Plotter (graph_area.Width, graph_area.Height, parent.CurrentTabulator, tl);
                plot.Draw (g);
            }
        }
        Gdk.Rectangle area = args.Area;

        GdkWindow.DrawDrawable (Style.BlackGC,
                        bitmap_cache,
                        0, 0,
                        graph_area.X, graph_area.Y,
                        graph_area.Width, graph_area.Height);

        DrawXScale (area);
        DrawYScale (area);

        return true;
    }