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); } } } }
private void Refresh(bool Draw) { Graphics offScreenGraphics; Bitmap offscreenBitmap; offscreenBitmap = new Bitmap(BackgroundBitmap.Width, BackgroundBitmap.Height); offScreenGraphics = Graphics.FromImage(offscreenBitmap); if (BackgroundBitmap != null) { offScreenGraphics.DrawImage(BackgroundBitmap, 0, 0, BackgroundBitmap.Width, BackgroundBitmap.Height); } DrawCloseButton(ref offScreenGraphics); DrawText(ref offScreenGraphics); if (Gdk.Display.Default.SupportsShapes) { background = modFunctions.ImageToPixbuf(offscreenBitmap).AddAlpha(true, transparencyKey.R, transparencyKey.G, transparencyKey.B); Gdk.Pixmap pixmap = null; Gdk.Pixmap mask = null; this.WidthRequest = background.Width; this.HeightRequest = background.Height; background.RenderPixmapAndMask(out pixmap, out mask, 2); this.ShapeCombineMask(mask, 0, 0); } else { if (this.GdkWindow == null) { background = modFunctions.ImageToPixbuf(modFunctions.SwapColors(offscreenBitmap, transparencyKey, Color.Black)); } else if (this.GdkWindow.FrameExtents.Location.X <= 0 | this.GdkWindow.FrameExtents.Location.Y <= 0) { background = modFunctions.ImageToPixbuf(modFunctions.SwapColors(offscreenBitmap, transparencyKey, Color.Black)); } else { if (ScreenTransBitmap == null) { ScreenTransBitmap = modFunctions.GetScreenRect(new Rectangle(this.GdkWindow.FrameExtents.Location.X, this.GdkWindow.FrameExtents.Location.Y, offscreenBitmap.Size.Width, offscreenBitmap.Size.Height)); } if (ScreenTransBitmap == null) { background = modFunctions.ImageToPixbuf(modFunctions.SwapColors(offscreenBitmap, transparencyKey, Color.Black)); } else { background = modFunctions.ImageToPixbuf(modFunctions.ReplaceColors(offscreenBitmap, transparencyKey, ScreenTransBitmap)); } } this.WidthRequest = background.Width; this.HeightRequest = background.Height; } if (Draw & titleText != null) { GdkWindow.DrawPixbuf(Style.BackgroundGC(State), background, 0, 0, 0, 0, background.Width, background.Height, Gdk.RgbDither.None, 0, 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)); } } } }
private void ShapeWindow() { Layout(); Gdk.Pixmap bitmap = new Gdk.Pixmap(GdkWindow, Allocation.Width, Allocation.Height, 1); Context g = CairoUtils.CreateContext(bitmap); DrawShape(g, Allocation.Width, Allocation.Height); ((IDisposable)g).Dispose(); if (use_shape_ext) { ShapeCombineMask(bitmap, 0, 0); } else { Context rgba = CairoUtils.CreateContext(GdkWindow); DrawShape(rgba, Allocation.Width, Allocation.Height); ((IDisposable)rgba).Dispose(); try { CompositeUtils.InputShapeCombineMask(this, bitmap, 0, 0); } catch (EntryPointNotFoundException) { System.Console.WriteLine("Warning: gtk+ version doesn't support input shapping"); } } bitmap.Dispose(); }
protected override void OnRealized () { base.OnRealized (); Gdk.Pixmap mask; pixmap = Gdk.Pixmap.CreateFromXpmD (GdkWindow, out mask, new Gdk.Color (99, 99, 99), custom_bg_xpm); }
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; }
protected virtual void OnUnrealized(object sender, System.EventArgs e) { whitegc = null; darkgc = null; view_pixmap = null; view_graphics = null; }
protected override void OnRealized() { base.OnRealized(); Gdk.Pixmap mask; pixmap = Gdk.Pixmap.CreateFromXpmD(GdkWindow, out mask, new Gdk.Color(99, 99, 99), custom_bg_xpm); }
protected override void OnChangeBackground(PanelAppletBackgroundType type, Gdk.Color color, Gdk.Pixmap pixmap) { if (applet_event_box == null) { return; } Gtk.RcStyle rc_style = new Gtk.RcStyle(); applet_event_box.Style = null; applet_event_box.ModifyStyle(rc_style); switch (type) { case PanelAppletBackgroundType.ColorBackground: applet_event_box.ModifyBg(Gtk.StateType.Normal, color); break; case PanelAppletBackgroundType.NoBackground: break; case PanelAppletBackgroundType.PixmapBackground: Gtk.Style copy = applet_event_box.Style.Copy(); copy.SetBgPixmap(Gtk.StateType.Normal, pixmap); applet_event_box.Style = copy; break; } }
public Image Copy() { Gdk.Colormap colormap = Gdk.Colormap.System; /* FIXME: copying a surface to a pixbuf through a pixmap does not require writting / reading to a file, * but it does not handle transparencies correctly and draws transparent pixels in a black color, so * for now we force the first method */ colormap = null; /* In unit tests running without a display, the default Screen is null and we can't get a valid colormap. * In this scenario we use a fallback that writes the surface to a temporary file */ if (colormap == null) { string tempFile = System.IO.Path.GetTempFileName(); surface.WriteToPng(tempFile); Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(tempFile); return(new Image(pixbuf)); } else { Gdk.Pixmap pixmap = new Gdk.Pixmap(null, Width, Height, 24); using (Context cr = Gdk.CairoHelper.Create(pixmap)) { cr.Operator = Operator.Source; cr.SetSource(surface); cr.Paint(); } return(new Image(Gdk.Pixbuf.FromDrawable(pixmap, Gdk.Colormap.System, 0, 0, 0, 0, Width, Height))); } }
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; }
public static Gdk.Pixmap GetSnapshot(this Widget widget, Gdk.Rectangle clip_rect) { IntPtr native_clip_rect = GLib.Marshaller.StructureToPtrAlloc(clip_rect); IntPtr raw_ret = gtk_widget_get_snapshot(widget.Handle, native_clip_rect); Gdk.Pixmap ret = GLib.Object.GetObject(raw_ret) as Gdk.Pixmap; clip_rect = Gdk.Rectangle.New(native_clip_rect); Marshal.FreeHGlobal(native_clip_rect); return(ret); }
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(); }
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; } }); }
protected override void Draw(Gdk.GC gc, Gdk.Drawable dest, int x, int y, byte b, Gdk.Pixmap pix) { // draw from the end backwards x += 6 * width; for (int i = 0; i < 4; i++) { byte k = (byte)(b & 3); dest.DrawDrawable(gc, pix, k*2*width, 0, x, y, 2*width, height); x -= 2 * width; b = (byte)(b >> 2); } }
protected virtual void OnRealized(object sender, System.EventArgs e) { whitegc = new Gdk.GC(GdkWindow); whitegc.Foreground = view.Style.White; darkgc = new Gdk.GC(GdkWindow); darkgc.Foreground = view.Style.Dark(StateType.Normal); view_pixmap = new Gdk.Pixmap(GdkWindow, Constants.ARENA_SIZE, Constants.ARENA_SIZE); view_graphics = Gtk.DotNet.Graphics.FromDrawable(view_pixmap); }
public override void SetImage(Gtk.Image imageView) { using (var drawable = new Gdk.Pixmap(null, Size.Width, Size.Height, 24)) using (var gc = new Gdk.GC(drawable)) { drawable.Colormap = new Gdk.Colormap(Gdk.Visual.System, true); drawable.DrawIndexedImage(gc, 0, 0, Size.Width, Size.Height, Gdk.RgbDither.None, Control, this.rowStride, GetPmap()); imageView.Pixmap = drawable; } }
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)); } }
private void Expose(object o, Gtk.ExposeEventArgs args) { System.Console.WriteLine("expose"); int width; int height; window.GetSize(out width, out height); Gdk.Pixmap pm = new Gdk.Pixmap(null, width, height, 1); window.InputShapeCombineMask(pm, 0, 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); } }
/// <summary> /// Expose event handler, calls PaintBackground and then PaintCells /// </summary> /// <param name="evnt"> /// Arguments <see cref="Gdk.EventExpose"/> /// </param> /// <returns> /// true if successful, false if not <see cref="System.Boolean"/> /// </returns> protected override bool OnExposeEvent(Gdk.EventExpose evnt) { base.OnExposeEvent(evnt); int x, y, w, h, d = 0; GdkWindow.GetGeometry(out x, out y, out w, out h, out d); CellRectangle r = new CellRectangle(0, 0, w, h); System.Console.WriteLine("Using cellrendererwindow=" + (IsCellRenderer == true)); Gdk.Window masterDrawable = (IsCellRenderer == true) ? cellRendererWindow : evnt.Window; Gdk.Drawable buffer = null; Cairo.Context context = null; if (IsDoubleBuffered == true) { System.Console.WriteLine("DoubleBuffered"); buffer = new Gdk.Pixmap(masterDrawable, Allocation.Width, Allocation.Height, 24); context = Gdk.CairoHelper.Create(buffer); } else { masterDrawable.BeginPaintRect(evnt.Area); context = Gdk.CairoHelper.Create(masterDrawable); } Gdk.Color clr = Style.Backgrounds[(int)StateType.Normal]; // context.Color = new Cairo.Color (0, 0, 1); context.Color = clr.GetCairoColor(); r.DrawPath(context); context.Fill(); // if ((BackgroundPainted == true) && (Sensitive == true)) // PaintBackground (evnt, g, rect); // Cairo.Rectangle r = rect.CopyAndShrink (Padding); r.Shrink(Padding); CalculateCellAreas(r); if (IsDoubleBuffered == true) { PaintCells(evnt, buffer, context, r); evnt.Window.DrawDrawable(Style.BlackGC, buffer, evnt.Area.X, evnt.Area.Y, evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height); buffer.Dispose(); } else { PaintCells(evnt, masterDrawable, context, r); masterDrawable.EndPaint(); } ((IDisposable)context.Target).Dispose(); ((IDisposable)context).Dispose(); context = null; return(true); }
Gdk.Pixbuf CreatePixBuf (Gdk.Rectangle bounds) { using (var pmap = new Gdk.Pixmap (Container.GdkWindow, bounds.Width, bounds.Height)) { using (Cairo.Context ctx = Gdk.CairoHelper.Create (pmap)) { ctx.Rectangle (0, 0, bounds.Width, bounds.Height); ctx.SetSourceRGBA (BackgroundColor.Red, BackgroundColor.Green, BackgroundColor.Blue, BackgroundColor.Alpha); ctx.Paint (); Render (pmap, bounds, Gtk.StateType.Normal); return Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, bounds.Width, bounds.Height); } } }
Gdk.Pixbuf CreatePixBuf(Gdk.Rectangle bounds) { using (var pmap = new Gdk.Pixmap(Container.GdkWindow, bounds.Width, bounds.Height)) { using (Cairo.Context ctx = Gdk.CairoHelper.Create(pmap)) { ctx.Rectangle(0, 0, bounds.Width, bounds.Height); ctx.SetSourceRGBA(BackgroundColor.Red, BackgroundColor.Green, BackgroundColor.Blue, BackgroundColor.Alpha); ctx.Paint(); Render(pmap, bounds, Gtk.StateType.Normal); return(Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, bounds.Width, bounds.Height)); } } }
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 CairoPositionSnapshot(ArrayList pos, int width, int height) { fm = new FigureManager (); Gtk.Window win = new Gtk.Window (Gtk.WindowType. Toplevel); win.Realize (); map = new Gdk.Pixmap (win.GdkWindow, width, height); cairo = Gdk.CairoHelper.Create (map); FontDescription fontdesc = GetFontDesc (width, height); GetCoordLayoutDetails (win.PangoContext, fontdesc); border_color = new Cairo.Color (0, 0, 0); // blacksq_color = new Gdk.Color (200, 200, 200); // whitesq_color = new Gdk.Color (240, 240, 240); blacksq_color = new Cairo.Color (250 / 256.0, 120 / 256.0, 32 / 256.0); whitesq_color = new Cairo.Color (255 / 256.0, 250 / 256.0, 170 / 256.0); background_color = new Cairo.Color (1, 1, 1); foreground_color = new Cairo.Color (0, 0, 0); // arrow_color = new Gdk.Color (159, 148, 249); arrow_color = new Cairo.Color (117 / 256.0, 6 / 256.0, 6 / 256.0); // blacksq_color = new Gdk.Color(210, 60, 0); // whitesq_color = new Gdk.Color(236, 193, 130); // outer box, coord, inner box ComputeSizes (width, height); position = new Position (pos); fm.SetSize (size); DrawBackground (); DrawPosition (); }
void ShapeWindow() { if (composited) { return; } var bitmap = new Gdk.Pixmap(GdkWindow, Allocation.Width, Allocation.Height, 1); Context cr = Gdk.CairoHelper.Create(bitmap); ShapeCombineMask(bitmap, 0, 0); ShapeSurface(cr, new Color(1, 1, 1)); ShapeCombineMask(bitmap, 0, 0); ((IDisposable)cr).Dispose(); bitmap.Dispose(); }
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 } } } }
public PositionSnapshot(ArrayList pos, int width, int height) { Gtk.Window win = new Gtk.Window (Gtk.WindowType. Toplevel); win.Realize (); map = new Gdk.Pixmap (win.GdkWindow, width, height); gc = new Gdk.GC (map); FontDescription fontdesc = GetFontDesc (width, height); GetCoordLayoutDetails (win.PangoContext, fontdesc); border_color = new Gdk.Color (0, 0, 0); // blacksq_color = new Gdk.Color (200, 200, 200); // whitesq_color = new Gdk.Color (240, 240, 240); blacksq_color = new Gdk.Color (250, 120, 32); whitesq_color = new Gdk.Color (255, 250, 170); background_color = new Gdk.Color (255, 255, 255); foreground_color = new Gdk.Color (0, 0, 0); // arrow_color = new Gdk.Color (159, 148, 249); arrow_color = new Gdk.Color (117, 6, 6); // blacksq_color = new Gdk.Color(210, 60, 0); // whitesq_color = new Gdk.Color(236, 193, 130); // outer box, coord, inner box ComputeSizes (width, height); if (figure == null) figure = new Figure (); position = new Position (pos); figure.SetSize (size); DrawBackground (); DrawPosition (); }
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); }
public override void SetImage(Gtk.Image imageView, Gtk.IconSize?iconSize) { using (var drawable = new Gdk.Pixmap(null, Size.Width, Size.Height, 24)) using (var gc = new Gdk.GC(drawable)) { drawable.Colormap = new Gdk.Colormap(Gdk.Visual.System, true); drawable.DrawIndexedImage(gc, 0, 0, Size.Width, Size.Height, Gdk.RgbDither.None, Control, rowStride, GetPmap()); if (iconSize != null) { var iconSet = new Gtk.IconSet(Gdk.Pixbuf.FromDrawable(drawable, Gdk.Colormap.System, 0, 0, 0, 0, size.Width, size.Height)); imageView.SetFromIconSet(iconSet, iconSize.Value); } else { imageView.Pixmap = drawable; } } }
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); }
public static void Main(string[] args) { Toolkit opentk = Core.InitOpenTK(); var platform = new Eto.GtkSharp.Platform(); platform.Add <GLSurface.IHandler>(() => new GtkGlSurfaceHandler()); Style.Add <View>( "hidecursor", view => { Gdk.Window window = view.ToNative().GdkWindow; var pixmap = new Gdk.Pixmap(null, 1, 1, 1); var cursor = new Gdk.Cursor(pixmap, pixmap, Gdk.Color.Zero, Gdk.Color.Zero, 0, 0); Gdk.EventMask mask = Gdk.EventMask.PointerMotionMask | Gdk.EventMask.ButtonPressMask; // Doesn't successfully limit mouse motion when running in // Windows, but that's an edge case anyway, so no big deal. Gdk.Pointer.Grab(window, true, mask, window, cursor, 0); }); Style.Add <View>( "showcursor", view => { Gdk.Pointer.Ungrab(0); }); var application = new Application(platform); application.UnhandledException += Core.UnhandledExceptionHandler; using (opentk) { application.Run(new MainForm()); } }
private void ShapeWindow() { if (composited) { return; } Gdk.Pixmap bitmap = new Gdk.Pixmap(GdkWindow, Allocation.Width, Allocation.Height, 1); #if CAIRO_1_2_5 Context cr = Gdk.CairoHelper.Create(bitmap); #else Context cr = CairoUtils.CreateContext(bitmap); #endif ShapeCombineMask(bitmap, 0, 0); ShapeSurface(cr, new Color(1, 1, 1)); ShapeCombineMask(bitmap, 0, 0); ((IDisposable)cr).Dispose(); bitmap.Dispose(); }
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); }
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); } } }
private void OnWinConfigure(object o, ConfigureEventArgs args) { Gdk.EventConfigure e = args.Event; if (_oldWidth != e.Width || _oldHeight != e.Height) { Gdk.Pixmap tmp = new Gdk.Pixmap(_window.GdkWindow, e.Width, e.Height, -1); int minw = e.Width < _oldWidth ? e.Width : _oldWidth; int minh = e.Height < _oldHeight ? e.Height : _oldHeight; using (Context context = Gdk.CairoHelper.Create(tmp)) { Gdk.CairoHelper.SetSourcePixmap(context, _pixmap, 0, 0); context.Rectangle(0, 0, minw, minh); context.Fill(); } _pixmap = tmp; } _oldWidth = e.Width; _oldHeight = e.Height; }
private void HideCursor() { if (GdkWindow == null) { return; } Gdk.Pixmap pixmap = Gdk.Pixmap.CreateBitmapFromData(GdkWindow, "0x0", 1, 1); if (pixmap == null) { return; } UpdateHiddenCursorPosition(); cursor_is_hidden = true; Gdk.Color color = new Gdk.Color(0, 0, 0); Gdk.Cursor cursor = new Gdk.Cursor(pixmap, pixmap, color, color, 0, 0); GdkWindow.Cursor = cursor; pixmap.Dispose(); cursor.Dispose(); }
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; } }); }
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; }
private void ShapeWindow() { if (composited) return; Gdk.Pixmap bitmap = new Gdk.Pixmap (GdkWindow, Allocation.Width, Allocation.Height, 1); Context cr = Gdk.CairoHelper.Create (bitmap); ShapeCombineMask (bitmap, 0, 0); ShapeSurface (cr, new Color (1, 1, 1)); ShapeCombineMask (bitmap, 0, 0); ((IDisposable)cr).Dispose (); bitmap.Dispose (); }
public void UpdateCache() { if (bitmap_cache != null) bitmap_cache.Dispose (); bitmap_cache = null; }
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; }
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); }
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; })); } }
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); })); } }
private void Go() { try { Application.Init(); _window = new Window(Configuration.WindowTitle); _window.SetDefaultSize(Configuration.WindowWidth, Configuration.WindowHeight); _window.DeleteEvent += OnWinDelete; _window.KeyPressEvent += OnKeyPress; _window.KeyReleaseEvent += OnKeyRelease; _window.ConfigureEvent += OnWinConfigure; _window.ExposeEvent += OnExposed; _oldWidth = Configuration.WindowWidth; _oldHeight = Configuration.WindowHeight; GLib.Timeout.Add(1000 / Configuration.RefreshRate, new GLib.TimeoutHandler(OnTimedDraw)); _window.ShowAll(); _pixmap = new Gdk.Pixmap(_window.GdkWindow, Configuration.WindowWidth, Configuration.WindowHeight, -1); _window.AppPaintable = true; _window.DoubleBuffered = false; QueueInitialState(); while (!_quit) { try { if (MessageBox != null && MessageBox.Timer.IsUp) { MessageBox = null; } State.RunIteration(); } catch (Exception e) { HandleFatalException(e); } Gdk.Threads.Enter(); if (Application.EventsPending()) { try { Application.RunIteration(); } catch (Exception e) { HandleFatalException(e); } finally { Gdk.Threads.Leave(); } } } Gdk.Threads.Enter(); try { Application.Quit(); } finally { Gdk.Threads.Leave(); } } finally { Cleanup(); } }
/// <summary> /// Expose event handler, calls PaintBackground and then PaintCells /// </summary> /// <param name="evnt"> /// Arguments <see cref="Gdk.EventExpose"/> /// </param> /// <returns> /// true if successful, false if not <see cref="System.Boolean"/> /// </returns> protected override bool OnExposeEvent (Gdk.EventExpose evnt) { base.OnExposeEvent (evnt); int x,y,w,h,d = 0; GdkWindow.GetGeometry (out x, out y, out w, out h, out d); CellRectangle r = new CellRectangle (0, 0, w, h); System.Console.WriteLine("Using cellrendererwindow=" + (IsCellRenderer == true)); Gdk.Window masterDrawable = (IsCellRenderer == true) ? cellRendererWindow : evnt.Window; Gdk.Drawable buffer = null; Cairo.Context context = null; if (IsDoubleBuffered == true) { System.Console.WriteLine("DoubleBuffered"); buffer = new Gdk.Pixmap (masterDrawable, Allocation.Width, Allocation.Height, 24); context = Gdk.CairoHelper.Create (buffer); } else { masterDrawable.BeginPaintRect (evnt.Area); context = Gdk.CairoHelper.Create (masterDrawable); } Gdk.Color clr = Style.Backgrounds[(int) StateType.Normal]; // context.Color = new Cairo.Color (0, 0, 1); context.Color = clr.GetCairoColor(); r.DrawPath(context); context.Fill(); // if ((BackgroundPainted == true) && (Sensitive == true)) // PaintBackground (evnt, g, rect); // Cairo.Rectangle r = rect.CopyAndShrink (Padding); r.Shrink (Padding); CalculateCellAreas (r); if (IsDoubleBuffered == true) { PaintCells (evnt, buffer, context, r); evnt.Window.DrawDrawable (Style.BlackGC, buffer, evnt.Area.X, evnt.Area.Y, evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height); buffer.Dispose(); } else { PaintCells (evnt, masterDrawable, context, r); masterDrawable.EndPaint(); } ((IDisposable) context.Target).Dispose (); ((IDisposable) context).Dispose (); context = null; 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) { // 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 ShapeWindow () { Layout (); Gdk.Pixmap bitmap = new Gdk.Pixmap (GdkWindow, Allocation.Width, Allocation.Height, 1); Context g = CairoUtils.CreateContext (bitmap); DrawShape (g, Allocation.Width, Allocation.Height); ((IDisposable)g).Dispose (); if (use_shape_ext) ShapeCombineMask (bitmap, 0, 0); else { Context rgba = CairoUtils.CreateContext (GdkWindow); DrawShape (rgba, Allocation.Width, Allocation.Height); ((IDisposable)rgba).Dispose (); try { CompositeUtils.InputShapeCombineMask (this, bitmap, 0,0); } catch (EntryPointNotFoundException) { System.Console.WriteLine ("Warning: gtk+ version doesn't support input shapping"); } } bitmap.Dispose (); }