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)); } } } }
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); } } } }
public void XorRect(Gdk.Rectangle rect) { if (xorGC == null) { if (IsRealized) { Gdk.GCValues values = new Gdk.GCValues(); values.Function = Gdk.Function.Invert; values.SubwindowMode = Gdk.SubwindowMode.IncludeInferiors; xorGC = new Gdk.GC(GdkWindow); xorGC.SetValues(values, Gdk.GCValuesMask.Function | Gdk.GCValuesMask.Subwindow); } else { return; } } xorGC.SetLineAttributes(1, Gdk.LineStyle.OnOffDash, Gdk.CapStyle.NotLast, Gdk.JoinStyle.Bevel); xorGC.SetDashes(1, new sbyte[] { 1, 1 }, 2); GdkWindow.DrawRectangle(xorGC, false, rect.X, rect.Y, rect.Width, rect.Height); xorGC.SetDashes(0, new sbyte[] { 1, 1 }, 2); GdkWindow.DrawRectangle(xorGC, false, rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2); }
Gdk.GC CreateDashedLineGC (Gdk.Color fg) { var gc = new Gdk.GC (Editor.GdkWindow); gc.RgbFgColor = fg; gc.SetLineAttributes (1, Gdk.LineStyle.OnOffDash, Gdk.CapStyle.NotLast, Gdk.JoinStyle.Bevel); gc.SetDashes (0, new sbyte[] { 1, 1 }, 2); return gc; }
Gdk.GC CreateDashedLineGC(Gdk.Color fg) { var gc = new Gdk.GC(Editor.GdkWindow); gc.RgbFgColor = fg; gc.SetLineAttributes(1, Gdk.LineStyle.OnOffDash, Gdk.CapStyle.NotLast, Gdk.JoinStyle.Bevel); gc.SetDashes(0, new sbyte[] { 1, 1 }, 2); return(gc); }
void OnRealize(object sender, EventArgs args) { gcBar = new Gdk.GC(drawer.GdkWindow); gcBar.RgbFgColor = new Gdk.Color(0xa0, 0, 0); gcGrid = new Gdk.GC(drawer.GdkWindow); gcGrid.RgbFgColor = new Gdk.Color(0x60, 0x60, 0xff); gcGrid.SetLineAttributes(1, Gdk.LineStyle.OnOffDash, Gdk.CapStyle.Butt, Gdk.JoinStyle.Miter); gcGrid.SetDashes(0, new sbyte[] { 2, 4 }, 2); }
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); }
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 } } } }
void OnKeyPress(object sender, KeyPressEventArgs KPargs) { Gdk.GC gc = new Gdk.GC((Drawable)base.GdkWindow); gc.RgbFgColor = new Gdk.Color(255, 50, 50); gc.RgbBgColor = new Gdk.Color(0, 0, 0); gc.SetLineAttributes(3, LineStyle.OnOffDash, CapStyle.Projecting, JoinStyle.Round); Gdk.Point[] pts = new Gdk.Point[8]; pts[0] = new Gdk.Point(10, 50); pts[1] = new Gdk.Point(15, 70); pts[2] = new Gdk.Point(20, 80); pts[3] = new Gdk.Point(25, 70); pts[4] = new Gdk.Point(30, 80); pts[5] = new Gdk.Point(40, 90); pts[6] = new Gdk.Point(55, 85); pts[7] = new Gdk.Point(75, 65); base.GdkWindow.DrawLines(gc, pts); }
private void XorRect() { rectDrawn = !rectDrawn; if (rectOwner != null) { Gdk.Rectangle rect = new Gdk.Rectangle(request.X, request.Y, request.Width, request.Height); rectOwner.XorRect(rect); return; } Gdk.Window window = Gdk.Global.DefaultRootWindow; if (rootXorGC == null) { Gdk.GCValues values = new Gdk.GCValues(); values.Function = Gdk.Function.Invert; values.SubwindowMode = Gdk.SubwindowMode.IncludeInferiors; rootXorGC = new Gdk.GC(window); rootXorGC.SetValues(values, Gdk.GCValuesMask.Function | Gdk.GCValuesMask.Subwindow); } rootXorGC.SetLineAttributes(1, Gdk.LineStyle.OnOffDash, Gdk.CapStyle.NotLast, Gdk.JoinStyle.Bevel); rootXorGC.SetDashes(1, new sbyte[] { 1, 1 }, 2); window.DrawRectangle(rootXorGC, false, request.X, request.Y, request.Width, request.Height); rootXorGC.SetDashes(0, new sbyte[] { 1, 1 }, 2); window.DrawRectangle(rootXorGC, false, request.X + 1, request.Y + 1, request.Width - 2, request.Height - 2); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { bool bres = base.OnExposeEvent(evnt); if (!base.Decorated) { Gdk.GC gc = this.vboxWindow.Style.BackgroundGC(Gtk.StateType.Normal); gc.SetLineAttributes(FrameBorderWidth, Gdk.LineStyle.Solid, Gdk.CapStyle.Butt, Gdk.JoinStyle.Miter); base.GdkWindow.DrawRectangle( gc, false, Allocation.X + FrameBorderWidth / 2, Allocation.Y + FrameBorderWidth / 2, Allocation.Width - FrameBorderWidth, Allocation.Height - FrameBorderWidth ); } return(bres); }
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); } } }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { Graphics g = Gtk.DotNet.Graphics.FromDrawable(evnt.Window); Bitmap img = null; int wwidth = this.Allocation.Width; int wheight = this.Allocation.Height; if (this.Icon != null) { img = GraphUtil.BitmapFromPixbuf(this.Icon); } //draw icon if (this.Icon != null) { int x = Allocation.Left, y = Allocation.Top; //calculate x and y for icon if (IconPosition == HPosition.Bottom) { x += (wwidth / 2) - (img.Width / 2); y += wheight - img.Height; } if (IconPosition == HPosition.BottomLeft) { x = Allocation.Left; y += wheight - img.Height; } if (IconPosition == HPosition.BottomRight) { x += wwidth - img.Width; y += wheight - img.Height; } if (IconPosition == HPosition.Center) { x += (wwidth / 2) - (img.Width / 2); y += (wheight / 2) - (img.Height / 2); } if (IconPosition == HPosition.Left) { x = Allocation.Left; y += (wheight / 2) - (img.Height / 2); } if (IconPosition == HPosition.Right) { x += wwidth - img.Width; y += (wheight / 2) - (img.Height / 2); } if (IconPosition == HPosition.Top) { x += (wwidth / 2) - (img.Width / 2); y = Allocation.Top; } if (IconPosition == HPosition.TopLeft) { x = Allocation.Left; y = Allocation.Top; } if (IconPosition == HPosition.TopRight) { x += wwidth - img.Width; y = Allocation.Top; } g.DrawImageUnscaled(img, x, y, img.Width, img.Height); } // //calculate text rectangle Rectangle rect = new Rectangle(Allocation.Left, Allocation.Top, wwidth, wheight); int imgwidth = 0, imgheight = 0; if (Icon != null) { imgwidth = img.Width; imgheight = img.Height; } if (!TextOverwritesIcon) { if (IconPosition == HPosition.Bottom) { rect = new Rectangle(Allocation.Left, Allocation.Top, wwidth, wheight - imgheight); } if (IconPosition == HPosition.BottomLeft) { rect = new Rectangle(Allocation.Left + imgwidth, Allocation.Top, wwidth, wheight - imgheight); } if (IconPosition == HPosition.BottomRight) { rect = new Rectangle(Allocation.Left, Allocation.Top, wwidth - imgwidth, wheight - imgheight); } if (IconPosition == HPosition.Left) { rect = new Rectangle(Allocation.Left + imgwidth, Allocation.Top, wwidth, wheight - imgheight); } if (IconPosition == HPosition.Right) { rect = new Rectangle(Allocation.Left, Allocation.Top, wwidth - imgwidth, wheight); } if (IconPosition == HPosition.Top) { rect = new Rectangle(Allocation.Left, Allocation.Top + imgheight, wwidth, wheight - imgheight); } if (IconPosition == HPosition.TopLeft) { rect = new Rectangle(Allocation.Left + imgwidth, Allocation.Top + imgheight, wwidth - imgwidth, wheight - imgheight); } if (IconPosition == HPosition.TopRight) { rect = new Rectangle(Allocation.Left, Allocation.Top + imgheight, wwidth - imgwidth, wheight - imgheight); } } //calculate text size float fnt_sz = this.PangoContext.FontDescription.Size / 1000; Font fnt = new Font(this.PangoContext.FontDescription.Family, fnt_sz); SizeF ts = g.MeasureString(this.Text, fnt); //draw text if (this.Text.Length > 0) { float x = rect.Left, y = rect.Top; //calculate x and y for text if (TextPosition == HPosition.Bottom) { x += (wwidth / 2) - (ts.Width / 2); y += wheight - ts.Height; } if (TextPosition == HPosition.BottomLeft) { x = rect.Left; y += wheight - ts.Height; } if (TextPosition == HPosition.BottomRight) { x += wwidth - ts.Width; y += wheight - ts.Height; } if (TextPosition == HPosition.Center) { x += (wwidth / 2) - (ts.Width / 2); y += (wheight / 2) - (ts.Height / 2); } if (TextPosition == HPosition.Left) { x = rect.Left; y += (wheight / 2) - (ts.Height / 2); } if (TextPosition == HPosition.Right) { x += wwidth - ts.Width; y += (wheight / 2) - (ts.Height / 2); } if (TextPosition == HPosition.Top) { x += (wwidth / 2) - (ts.Width / 2); y = rect.Top; } if (TextPosition == HPosition.TopLeft) { x = rect.Left; y = rect.Top; } if (TextPosition == HPosition.TopRight) { x += wwidth - ts.Width; y = rect.Top; } //draw text Gdk.Color c = this.Style.Text(this.State); SolidBrush b = new SolidBrush(GraphUtil.winFormsColorFromGdk(c)); g.DrawString(this.Text, fnt, b, x, y); //draw selection rectangle if necesary if (TextInSelectionRectangle) { Gdk.GC gc = this.Style.TextGC(Gtk.StateType.Insensitive); gc.SetLineAttributes(1, Gdk.LineStyle.OnOffDash, Gdk.CapStyle.NotLast, Gdk.JoinStyle.Round); evnt.Window.DrawRectangle(gc, false, (int)x, (int)y + 1, (int)ts.Width, (int)ts.Height); } } //draw line if horizonatlLine is true if (this.HorizontalLine) { int x1 = rect.Left + (int)ts.Width + lineTextPadding; int y = rect.Top + Allocation.Height / 2; int x2 = rect.Left + Allocation.Width - lineTextPadding; if (x2 > x1) { Gtk.Style.PaintHline(this.Style, GdkWindow, this.State, this.Allocation, this, "hline", x1, x2, y); } } return(true); }
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; }
void OnRealize(object sender, EventArgs args) { gcBar = new Gdk.GC(drawer.GdkWindow); gcBar.RgbFgColor = new Gdk.Color(0xa0, 0, 0); gcGrid = new Gdk.GC(drawer.GdkWindow); gcGrid.RgbFgColor = new Gdk.Color(0x60, 0x60, 0xff); gcGrid.SetLineAttributes(1, Gdk.LineStyle.OnOffDash, Gdk.CapStyle.Butt, Gdk.JoinStyle.Miter); gcGrid.SetDashes(0, new sbyte[]{2, 4}, 2); }
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; }
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); }
private void Line_Expose(object sender, Gtk.ExposeEventArgs e) { Gtk.DrawingArea line = (Gtk.DrawingArea)sender; Gdk.GC gc = new Gdk.GC(line.GdkWindow); Gdk.Rectangle alloc = line.Allocation; int rightSide = 0; if (line.Direction != Gtk.TextDirection.Rtl) { rightSide = alloc.Width; } Utility.Pair<int, bool> lineData = (Utility.Pair<int, bool>)_lines[line]; if (lineData != null) { int i = lineData.First; bool rela = lineData.Second; Gdk.LineStyle lineStyle = Gdk.LineStyle.Solid; if (!rela) { lineStyle = Gdk.LineStyle.OnOffDash; } int lineWidth = 3; gc.SetLineAttributes(lineWidth, lineStyle, Gdk.CapStyle.Butt, Gdk.JoinStyle.Bevel); if (i % 2 == 0) { line.GdkWindow.DrawLine(gc, rightSide, alloc.Height / 2, alloc.Width / 2, alloc.Height / 2); line.GdkWindow.DrawLine(gc, alloc.Width / 2, 0, alloc.Width / 2, alloc.Height / 2); } else { line.GdkWindow.DrawLine(gc, rightSide, alloc.Height / 2, alloc.Width / 2, alloc.Height / 2); line.GdkWindow.DrawLine(gc, alloc.Width / 2, alloc.Height, alloc.Width / 2, alloc.Height / 2); } } }