public override void Render (Gdk.Drawable window, Gdk.Rectangle bounds, Gtk.StateType state) { Gdk.GC gc = new Gdk.GC (window); gc.RgbFgColor = (Gdk.Color) Value; window.DrawRectangle (gc, true, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); window.DrawRectangle (Container.Style.BlackGC, false, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); }
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); } } } }
internal static void RenderPlaceholderText (Gtk.Entry entry, Gtk.ExposeEventArgs args, string placeHolderText, ref Pango.Layout layout) { // The Entry's GdkWindow is the top level window onto which // the frame is drawn; the actual text entry is drawn into a // separate window, so we can ensure that for themes that don't // respect HasFrame, we never ever allow the base frame drawing // to happen if (args.Event.Window == entry.GdkWindow) return; if (entry.Text.Length > 0) return; if (layout == null) { layout = new Pango.Layout (entry.PangoContext); layout.FontDescription = entry.PangoContext.FontDescription.Copy (); } int wh, ww; args.Event.Window.GetSize (out ww, out wh); int width, height; layout.SetText (placeHolderText); layout.GetPixelSize (out width, out height); using (var gc = new Gdk.GC (args.Event.Window)) { gc.Copy (entry.Style.TextGC (Gtk.StateType.Normal)); Color color_a = entry.Style.Base (Gtk.StateType.Normal).ToXwtValue (); Color color_b = entry.Style.Text (Gtk.StateType.Normal).ToXwtValue (); gc.RgbFgColor = color_b.BlendWith (color_a, 0.5).ToGtkValue (); args.Event.Window.DrawLayout (gc, 2, (wh - height) / 2 + 1, layout); } }
protected override void DrawContents(Gdk.Drawable d) { Gdk.GC gc = new Gdk.GC(d); Cairo.Context g = Gdk.CairoHelper.Create(d); g.SelectFontFace("Lucida Console", FontSlant.Normal, FontWeight.Bold); g.SetFontSize(24); TextExtents te; string lvl, hp, hpm, mp, mpm; #region Character Character c = PHSList.Instance.Selection; if (c != null) { Graphics.DrawProfileSmall(d, gc, c.Name, X + x1, Y + yp); g.Color = new Color(.3, .8, .8); g.MoveTo(X + x3, Y + y0 + ya); g.ShowText("LV"); g.MoveTo(X + x3, Y + y0 + yb); g.ShowText("HP"); g.MoveTo(X + x3, Y + y0 + yc); g.ShowText("MP"); g.Color = new Color(1, 1, 1); Color namec = new Color(1, 1, 1); if (c.Death) namec = new Color(0.8, 0, 0); else if (c.NearDeath) namec = new Color(.8, .8, 0); Graphics.ShadowedText(g, namec, c.Name, X + x3, Y + y0); lvl = c.Level.ToString(); hp = c.HP.ToString() + "/"; hpm = c.MaxHP.ToString(); mp = c.MP.ToString() + "/"; mpm = c.MaxMP.ToString(); te = g.TextExtents(lvl); Graphics.ShadowedText(g, lvl, X + x4 - te.Width, Y + y0 + ya); te = g.TextExtents(hp); Graphics.ShadowedText(g, hp, X + x5 - te.Width, Y + y0 + yb); te = g.TextExtents(hpm); Graphics.ShadowedText(g, hpm, X + x6 - te.Width, Y + y0 + yb); te = g.TextExtents(mp); Graphics.ShadowedText(g, mp, X + x5 - te.Width, Y + y0 + yc); te = g.TextExtents(mpm); Graphics.ShadowedText(g, mpm, X + x6 - te.Width, Y + y0 + yc); } #endregion Character ((IDisposable)g.Target).Dispose(); ((IDisposable)g).Dispose(); }
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; }
public PlaceholderWindow (DockToolbarFrame frame): base (Gtk.WindowType.Toplevel) { SkipTaskbarHint = true; Decorated = false; TransientFor = frame.TopWindow; Realize (); redgc = new Gdk.GC (GdkWindow); redgc.RgbFgColor = new Gdk.Color (255, 0, 0); }
internal protected override void OptionsChanged () { Pango.Layout layout = new Pango.Layout (Editor.PangoContext); layout.FontDescription = Editor.Options.Font; layout.SetText ("."); int height; layout.GetPixelSize (out charWidth, out height); layout.Dispose (); bgGC = GetGC (Style.HexDigitBg); fgGC = GetGC (Style.HexDigit); }
public override void Render (Gdk.Drawable window, Gdk.Rectangle bounds, Gtk.StateType state) { Gdk.GC gc = new Gdk.GC (window); gc.RgbFgColor = GetColor (); int yd = (bounds.Height - ColorBoxSize) / 2; window.DrawRectangle (gc, true, bounds.X, bounds.Y + yd, ColorBoxSize - 1, ColorBoxSize - 1); window.DrawRectangle (Container.Style.BlackGC, false, bounds.X, bounds.Y + yd, ColorBoxSize - 1, ColorBoxSize - 1); bounds.X += ColorBoxSize + ColorBoxSpacing; bounds.Width -= ColorBoxSize + ColorBoxSpacing; base.Render (window, bounds, state); }
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); }
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 override void Render (Gdk.Drawable window, Cairo.Context ctx, Gdk.Rectangle bounds, Gtk.StateType state) { using (Gdk.GC gc = new Gdk.GC (window)) { gc.RgbFgColor = GetColor (); int yd = (bounds.Height - ColorBoxSize) / 2; window.DrawRectangle (gc, true, bounds.X, bounds.Y + yd, ColorBoxSize - 1, ColorBoxSize - 1); window.DrawRectangle (Container.GetNativeWidget<Gtk.Widget> ().Style.BlackGC, false, bounds.X, bounds.Y + yd, ColorBoxSize - 1, ColorBoxSize - 1); bounds.X += ColorBoxSize + ColorBoxSpacing; bounds.Width -= ColorBoxSize + ColorBoxSpacing; base.Render (window, ctx, bounds, state); } }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { if(bar_gc == null) { bar_gc = new Gdk.GC(GdkWindow); Gdk.Color color = Hyena.Gui.GtkUtilities.ColorBlend(Style.Background(StateType.Normal), Style.Foreground(StateType.Normal)); bar_gc.Background = color; bar_gc.Foreground = color; } DrawGdk(); return false; }
internal protected override void OptionsChanged () { DisposeGCs (); foldDashedLineGC = CreateDashedLineGC (Style.DashedLineFg); foldDashedLineGC2 = CreateDashedLineGC (Style.DashedLineBg); bgGC = new Gdk.GC (Editor.GdkWindow) { RgbFgColor = Style.HexDigitBg }; bgGC2 = new Gdk.GC (Editor.GdkWindow) { RgbFgColor = Style.HexDigit }; }
public static Cairo.Context CreateContext(Gdk.Drawable drawable) { IntPtr x_drawable = IntPtr.Zero; int x_off = 0, y_off = 0; int x, y, w, h, d; ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d); bool is_gdk_window = drawable is Gdk.Window; if (is_gdk_window) ((Gdk.Window)drawable).GetInternalPaintInfo(out drawable, out x_off, out y_off); Cairo.Surface surface; PlatformID os = Environment.OSVersion.Platform; if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT || os == PlatformID.Win32S || os == PlatformID.WinCE) { Gdk.GC gcc = new Gdk.GC(drawable); IntPtr windc = gdk_win32_hdc_get(drawable.Handle, gcc.Handle, 0); surface = new Win32Surface(windc); gdk_win32_hdc_release(drawable.Handle, gcc.Handle, 0); } else { x_drawable = drawable.Handle; IntPtr visual = gdk_drawable_get_visual(x_drawable); IntPtr Xdisplay = gdk_x11_drawable_get_xdisplay(x_drawable); IntPtr Xvisual = gdk_x11_visual_get_xvisual(visual); IntPtr Xdrawable = gdk_x11_drawable_get_xid(x_drawable); surface = new Cairo.XlibSurface(Xdisplay, Xdrawable, Xvisual, w, h); } Cairo.Context g = new Cairo.Context(surface); // this can be safely removed now, just keep it for a bit more //Cairo.Context g = new Cairo.Context ( // gdk_cairo_create (x_drawable )); if (is_gdk_window) g.Translate(-(double)x_off, -(double)y_off); return g; }
protected override bool OnExposeEvent (Gdk.EventExpose evnt) { base.OnExposeEvent (evnt); if (Child1 != null && Child1.Visible && Child2 != null && Child2.Visible) { var gc = new Gdk.GC (evnt.Window); gc.RgbFgColor = (HslColor) Styles.ThinSplitterColor; var x = Child1.Allocation.X + Child1.Allocation.Width; evnt.Window.DrawLine (gc, x, Allocation.Y, x, Allocation.Y + Allocation.Height); gc.Dispose (); } return true; }
internal protected override void OptionsChanged () { backgroundGC = GetGC (Style.IconBarBg); separatorGC = GetGC (Style.IconBarSeperator); Pango.Layout layout = new Pango.Layout (Editor.PangoContext); layout.FontDescription = Editor.Options.Font; layout.SetText ("!"); int tmp; layout.GetPixelSize (out tmp, out this.marginWidth); marginWidth *= 12; marginWidth /= 10; layout.Dispose (); }
public static System.Drawing.Graphics FromDrawable(Gdk.Window drawable, bool double_buffered) { #if FIXME30 IntPtr x_drawable; int x_off = 0, y_off = 0; PlatformID osversion = Environment.OSVersion.Platform; if (osversion == PlatformID.Win32Windows || osversion == PlatformID.Win32NT || osversion == PlatformID.Win32S || osversion == PlatformID.WinCE){ if (drawable is Gdk.Window && double_buffered) ((Gdk.Window)drawable).GetInternalPaintInfo(out drawable, out x_off, out y_off); Cairo.Context gcc = new Gdk.GC(drawable); IntPtr windc = gdk_win32_hdc_get(drawable.Handle, gcc.Handle, 0); System.Drawing.Graphics g = System.Drawing.Graphics.FromHdc(windc); if (double_buffered) { gdk_win32_hdc_release(drawable.Handle, gcc.Handle, 0); } g.TranslateTransform(-x_off, -y_off); return g; } else { if (drawable is Gdk.Window && double_buffered) ((Gdk.Window) drawable).GetInternalPaintInfo(out drawable, out x_off, out y_off); x_drawable = drawable.Handle; IntPtr display = gdk_x11_drawable_get_xdisplay (x_drawable); Type graphics = typeof (System.Drawing.Graphics); MethodInfo mi = graphics.GetMethod ("FromXDrawable", BindingFlags.Static | BindingFlags.NonPublic); if (mi == null) throw new NotImplementedException ("In this implementation I can not get a graphics from a drawable"); object [] args = new object [2] { (IntPtr) gdk_x11_drawable_get_xid (drawable.Handle), (IntPtr) display }; object r = mi.Invoke (null, args); System.Drawing.Graphics g = (System.Drawing.Graphics) r; g.TranslateTransform (-x_off, -y_off); return g; } #else throw new NotSupportedException (); #endif }
protected override void DrawLastMove(Gdk. Window window) { if (!showMove) return; int x1, y1, x2, y2; GetCoordinates (src_rank, src_file, out x1, out y1); GetCoordinates (dest_rank, dest_file, out x2, out y2); Gdk.GC gc = new Gdk.GC (GdkWindow); gc.RgbFgColor = new Gdk.Color (128, 128, 240); DrawArrow (window, gc, x1, y1, x2, y2, size, true); }
internal protected override void OptionsChanged () { DisposeGCs (); bgGC = new Gdk.GC (this.editor.GdkWindow) { RgbFgColor = editor.ColorStyle.Default.BackgroundColor }; gc = new Gdk.GC (this.editor.GdkWindow) { RgbFgColor = editor.ColorStyle.FoldLine.Color }; /* foldDashedLineGC = CreateDashedLineGC (editor.ColorStyle.Default.Color); foldDashedLineGC2 = CreateDashedLineGC (editor.ColorStyle.Default.BackgroundColor); bgGC = new Gdk.GC (this.editor.GdkWindow) { RgbFgColor = editor.ColorStyle.Default.BackgroundColor }; bgGC2 = new Gdk.GC (this.editor.GdkWindow) { RgbFgColor = editor.ColorStyle.Default.Color };*/ }
private void OnBannerExposed(object o, ExposeEventArgs args) { if(args.Event.Count > 0) return; Gdk.Pixbuf spb = ScaledPixbuf.ScaleSimple(iFolderScaledBanner.Allocation.Width, iFolderScaledBanner.Allocation.Height, Gdk.InterpType.Nearest); Gdk.GC gc = new Gdk.GC(iFolderScaledBanner.GdkWindow); spb.RenderToDrawable(iFolderScaledBanner.GdkWindow, gc, 0, 0, args.Event.Area.X, args.Event.Area.Y, args.Event.Area.Width, args.Event.Area.Height, Gdk.RgbDither.Normal, 0, 0); }
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 (); }
void DisposeGCs () { if (foldDashedLineGC != null) { foldDashedLineGC.Dispose (); foldDashedLineGC = null; } if (foldDashedLineGC2 != null) { foldDashedLineGC2.Dispose (); foldDashedLineGC2 = null; } if (bgGC != null) { bgGC.Dispose (); bgGC = null; } if (bgGC2 != null) { bgGC2.Dispose (); bgGC2 = null; } }
protected override void Render(Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { int width = 0, height = 0, x_offset = 0, y_offset = 0; GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); width -= (int) this.Xpad * 2; height -= (int) this.Ypad * 2; Gdk.Rectangle clipping_area = new Gdk.Rectangle ((int) (cell_area.X + x_offset + this.Xpad), (int) (cell_area.Y + y_offset + this.Ypad), width - 1, height - 1); using (Gdk.GC gc = new Gdk.GC (window)) { gc.RgbFgColor = ColorFromBrush (List.TypeBrushes [Idx]); window.DrawRectangle (gc, true, clipping_area); } }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { //base.OnExposeEvent (evnt); using (Gdk.GC gc = new Gdk.GC(evnt.Window)) { if (mSymbolStates.ContainsKey(this.State)) { int w, h; evnt.Window.GetSize(out w, out h); Gdk.Pixbuf pb = mSymbolStates[this.State]; evnt.Window.DrawPixbuf(gc, pb, 0, 0, this.Allocation.X + this.Allocation.Width / 2 - pb.Width / 2, this.Allocation.Y + this.Allocation.Height / 2 - pb.Height / 2, pb.Width, pb.Height, Gdk.RgbDither.None, 0, 0); } } return true; }
internal protected override void OptionsChanged () { Pango.Layout layout = new Pango.Layout (Editor.PangoContext); layout.FontDescription = Editor.Options.Font; string groupString = new string ('0', Editor.Options.GroupBytes * 2); layout.SetText (groupString + " "); int lineHeight; layout.GetPixelSize (out groupWidth, out lineHeight); Data.LineHeight = lineHeight; layout.SetText ("00"); layout.GetPixelSize (out byteWidth, out lineHeight); layout.Dispose (); tabArray = new Pango.TabArray (1, true); tabArray.SetTab (0, Pango.TabAlign.Left, groupWidth); bgGC = GetGC (Style.HexDigitBg); fgGC = GetGC (Style.HexDigit); }
internal protected override void OptionsChanged() { DisposeGCs(); bgGC = new Gdk.GC(this.editor.GdkWindow) { RgbFgColor = editor.ColorStyle.Default.BackgroundColor }; gc = new Gdk.GC(this.editor.GdkWindow) { RgbFgColor = editor.ColorStyle.FoldLine.Color }; /* foldDashedLineGC = CreateDashedLineGC (editor.ColorStyle.Default.Color); * foldDashedLineGC2 = CreateDashedLineGC (editor.ColorStyle.Default.BackgroundColor); * bgGC = new Gdk.GC (this.editor.GdkWindow) { * RgbFgColor = editor.ColorStyle.Default.BackgroundColor * }; * bgGC2 = new Gdk.GC (this.editor.GdkWindow) { * RgbFgColor = editor.ColorStyle.Default.Color * };*/ }
internal static void RenderPlaceholderText(Gtk.Entry entry, Gtk.ExposeEventArgs args, string placeHolderText, ref Pango.Layout layout) { // The Entry's GdkWindow is the top level window onto which // the frame is drawn; the actual text entry is drawn into a // separate window, so we can ensure that for themes that don't // respect HasFrame, we never ever allow the base frame drawing // to happen if (args.Event.Window == entry.GdkWindow) { return; } if (entry.Text.Length > 0) { return; } if (layout == null) { layout = new Pango.Layout(entry.PangoContext); layout.FontDescription = entry.PangoContext.FontDescription.Copy(); } int wh, ww; args.Event.Window.GetSize(out ww, out wh); int width, height; layout.SetText(placeHolderText); layout.GetPixelSize(out width, out height); using (var gc = new Gdk.GC(args.Event.Window)) { gc.Copy(entry.Style.TextGC(Gtk.StateType.Normal)); Color color_a = entry.Style.Base(Gtk.StateType.Normal).ToXwtValue(); Color color_b = entry.Style.Text(Gtk.StateType.Normal).ToXwtValue(); gc.RgbFgColor = color_b.BlendWith(color_a, 0.5).ToGtkValue(); args.Event.Window.DrawLayout(gc, 2, (wh - height) / 2 + 1, layout); } }
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)); } } } }
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 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); pangoLayout.SetText(s.Substring(256, 256)); pix.DrawLayout(gc, 128 * 2 * width, 0, pangoLayout); return(pix); }
public static Cairo.Context CreateDrawable (Gdk.Drawable drawable, bool double_buffered) { int x, y, w, h, d; Cairo.Surface surface; bool needs_xlate; ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d); PlatformID os = Environment.OSVersion.Platform; needs_xlate = drawable is Gdk.Window && double_buffered; if (needs_xlate) ((Gdk.Window)drawable).GetInternalPaintInfo (out drawable, out x, out y); if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT || os == PlatformID.Win32S || os == PlatformID.WinCE) { Gdk.GC gcc = new Gdk.GC (drawable); IntPtr windc = gdk_win32_hdc_get (drawable.Handle, gcc.Handle, 0); surface = new Win32Surface (windc); if (double_buffered) gdk_win32_hdc_release (drawable.Handle, gcc.Handle, 0); } else { IntPtr display = gdk_x11_drawable_get_xdisplay (drawable.Handle); IntPtr visual = gdk_drawable_get_visual (drawable.Handle); IntPtr xvisual = gdk_x11_visual_get_xvisual (visual); IntPtr xdrawable = gdk_x11_drawable_get_xid (drawable.Handle); surface = new XlibSurface (display, xdrawable, xvisual, w, h); } Cairo.Context ctx = new Cairo.Context (surface); if (needs_xlate) ctx.Translate (-(double) x, -(double) y); return ctx; }
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); } } }
/// <summary> /// Draws the border around the control, in this case the border around the content area between /// the slider arrows. /// </summary> private void DrawBorder(Gdk.Window g) { // To make the control look like Adobe Photoshop's the border around the control will be a gray line // on the top and left side, a white line on the bottom and right side, and a black rectangle (line) // inside the gray/white rectangle Gdk.GC gc = new Gdk.GC(g); gc.RgbFgColor = GraphUtil.gdkColorFromWinForms(Color.FromArgb(172, 168, 153)); //The same gray color used by Photoshop g.DrawLine(gc, this.Allocation.Width - 10, 2, 9, 2); // Draw top line g.DrawLine(gc, 9, 2, 9, this.Allocation.Height - 4); // Draw left hand line gc = new Gdk.GC(g); gc.RgbFgColor = GraphUtil.gdkColorFromWinForms(Color.White); g.DrawLine(gc, this.Allocation.Width - 9, 2, this.Allocation.Width - 9, this.Allocation.Height - 3); // Draw right hand line g.DrawLine(gc, this.Allocation.Width - 9, this.Allocation.Height - 3, 9, this.Allocation.Height - 3); // Draw bottome line gc = new Gdk.GC(g); gc.RgbFgColor = GraphUtil.gdkColorFromWinForms(Color.Black); g.DrawRectangle(gc, false, 10, 3, this.Allocation.Width - 20, this.Allocation.Height - 7); // Draw inner black rectangle }
internal protected override void OptionsChanged() { Pango.Layout layout = new Pango.Layout(Editor.PangoContext); layout.FontDescription = Editor.Options.Font; string groupString = new string ('0', Editor.Options.GroupBytes * 2); layout.SetText(groupString + " "); int lineHeight; layout.GetPixelSize(out groupWidth, out lineHeight); Data.LineHeight = lineHeight; layout.SetText("00"); layout.GetPixelSize(out byteWidth, out lineHeight); layout.Dispose(); tabArray = new Pango.TabArray(1, true); tabArray.SetTab(0, Pango.TabAlign.Left, groupWidth); bgGC = GetGC(Style.HexDigitBg); fgGC = GetGC(Style.HexDigit); }
void DisposeGCs() { if (foldDashedLineGC != null) { foldDashedLineGC.Dispose(); foldDashedLineGC = null; } if (foldDashedLineGC2 != null) { foldDashedLineGC2.Dispose(); foldDashedLineGC2 = null; } if (bgGC != null) { bgGC.Dispose(); bgGC = null; } if (bgGC2 != null) { bgGC2.Dispose(); bgGC2 = null; } }
public void Draw(Gdk.Drawable d, Cairo.Context g, int width, int height, bool screenChanged) { if (!_visible) { return; } if (_w > 0 && _h > 0) { Gdk.GC gc = new Gdk.GC(d); d.DrawPixbuf(gc, _background, 0, 0, _x, _y, _w, _h, Gdk.RgbDither.None, 0, 0); int x0 = _x, x1 = _x + _w; int y0 = _y, y1 = _y + _h; g.MoveTo(x0 + 3, y0); g.LineTo(x1 - 3, y0); g.LineTo(x1, y0 + 3); g.LineTo(x1, y1 - 3); g.LineTo(x1 - 3, y1); g.LineTo(x0 + 3, y1); g.LineTo(x0, y1 - 3); g.LineTo(x0, y0 + 3); g.LineTo(x0 + 3, y0); g.ClosePath(); g.LineWidth = 6; g.Color = BorderColor; g.Stroke(); } g.Save(); DrawContents(d, g, width, height, screenChanged); g.Restore(); }
public virtual void HandleExposeEvent(object o, Gtk.ExposeEventArgs args) { var control = Handler.Control; if (!string.IsNullOrEmpty(control.Text) || args.Event.Window == control.GdkWindow) { return; } if (Handler.placeholderLayout == null) { Handler.placeholderLayout = new Pango.Layout(control.PangoContext); Handler.placeholderLayout.FontDescription = control.PangoContext.FontDescription.Copy(); } Handler.placeholderLayout.SetText(Handler.placeholderText); int currentHeight, currentWidth; args.Event.Window.GetSize(out currentWidth, out currentHeight); int width, height; Handler.placeholderLayout.GetPixelSize(out width, out height); var style = control.Style; var bc = style.Base(Gtk.StateType.Normal); var tc = style.Text(Gtk.StateType.Normal); using (var gc = new Gdk.GC(args.Event.Window)) { gc.Copy(style.TextGC(Gtk.StateType.Normal)); gc.RgbFgColor = new Gdk.Color((byte)(((int)bc.Red + tc.Red) / 2 / 256), (byte)(((int)bc.Green + (int)tc.Green) / 2 / 256), (byte)((bc.Blue + tc.Blue) / 2 / 256)); args.Event.Window.DrawLayout(gc, 2, (currentHeight - height) / 2 + 1, Handler.placeholderLayout); } }
public static void DrawLayout(Gdk.Window win, Gdk.GC gc, Pango.Layout layout, float x, float y, Origin vertical = Origin.Far, Origin horizontal = Origin.Center) { if (horizontal != Origin.Near || vertical != Origin.Near) { int width, height; layout.GetPixelSize(out width, out height); switch (horizontal) { case Origin.Near: /*nothing to do*/ break; case Origin.Center: x -= width / 2; break; case Origin.Far: x -= width; break; } switch (vertical) { case Origin.Near: /*nothing to do*/ break; case Origin.Center: y -= height / 2; break; case Origin.Far: y -= height; break; } } win.DrawLayout(gc, (int)x, (int)y, layout); }
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 * width, height, -1); // draw the background gc.RgbFgColor = bg; pix.DrawRectangle(gc, true, 0, 0, 256 * width, height); // render the bytes string s = AsciiDrawer.AsciiTable; //System.Console.WriteLine(s); pangoLayout.SetText(s); gc.RgbFgColor = fg; pix.DrawLayout(gc, 0, 0, pangoLayout); return(pix); }
public override void Paint(Gdk.Drawable wnd, Rectangle rect) { HighlightColor lineNumberPainterColor = textArea.Document.HighlightingStrategy.GetColorFor("LineNumbers"); Gdk.Color rect_fg = TextArea.Style.White; Gdk.Color text_fg = new Gdk.Color (lineNumberPainterColor.Color); Gdk.Color text_bg = new Gdk.Color (lineNumberPainterColor.BackgroundColor); using (Gdk.GC gc = new Gdk.GC (wnd)) { gc.RgbFgColor = rect_fg; wnd.DrawRectangle (gc, true, new System.Drawing.Rectangle (drawingPosition.X, rect.Top, drawingPosition.Width - 1, rect.Height)); //g.DrawLine(SystemPens.ControlDark, base.drawingPosition.Right - 1, rect.Top, base.drawingPosition.Right - 1, rect.Bottom); // paint icons foreach (int mark in textArea.Document.BookmarkManager.Marks) { int lineNumber = textArea.Document.GetLogicalLine(mark); int yPos = (int)(lineNumber * textArea.TextView.FontHeight) - textArea.VirtualTop.Y; // if (yPos >= rect.Y && yPos <= rect.Bottom) { DrawBookmark(gc, wnd, yPos); // } } } }
protected virtual void RenderFrame(object o, Gtk.ExposeEventArgs args) { var w = TextView.GetWindow(Gtk.TextWindowType.Text); if (ShowFrame && args.Event.Window == w) { int wh, ww; w.GetSize(out ww, out wh); ww--; wh--; if (false) { var area = new Gdk.Rectangle(0, 0, ww, wh); area = args.Event.Area; // draws nothing visible: Gtk.Style.PaintVline(TextView.Style, w, Gtk.StateType.Active, area, TextView, "top", TextView.Allocation.X, TextView.Allocation.Y, TextView.Allocation.X + ww); Gtk.Style.PaintHline(TextView.Style, w, Gtk.StateType.Selected, area, TextView, "left", TextView.Allocation.X, TextView.Allocation.Y, TextView.Allocation.Y + wh); // draws over text: //Gtk.Style.PaintFlatBox (TextView.Style, w, TextView.State, Gtk.ShadowType.None, new Gdk.Rectangle (0, 0, ww, wh),TextView, null, 0, 0, ww, wh); } else { //Application.Invoke (() => { using (var gc = new Gdk.GC(w)) { w.DrawLines(gc, new Gdk.Point [] { new Gdk.Point(0, 0), new Gdk.Point(ww, 0), new Gdk.Point(ww, wh), new Gdk.Point(0, wh), new Gdk.Point(0, 0), }); } //}); } } }
/// <summary> /// Event Handler for banner Exposed /// </summary> private void OnBannerExposed(object o, ExposeEventArgs args) { if (args.Event.Count > 0) { return; } Gdk.Pixbuf spb = ScaledPixbuf.ScaleSimple(iFolderScaledBanner.Allocation.Width, iFolderScaledBanner.Allocation.Height, Gdk.InterpType.Nearest); Gdk.GC gc = new Gdk.GC(iFolderScaledBanner.GdkWindow); spb.RenderToDrawable(iFolderScaledBanner.GdkWindow, gc, 0, 0, args.Event.Area.X, args.Event.Area.Y, args.Event.Area.Width, args.Event.Area.Height, Gdk.RgbDither.Normal, 0, 0); }
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 protected override void OptionsChanged() { bgGC = GetGC(Style.HexDigitBg); }
private void RefreshGC() { if(text_window == null) { return; } text_gc = new Gdk.GC(text_window); text_gc.Copy(Style.TextGC(StateType.Normal)); Gdk.Color color_a = parent.Style.Base(StateType.Normal); Gdk.Color color_b = parent.Style.Text(StateType.Normal); text_gc.RgbFgColor = Hyena.Gui.GtkUtilities.ColorBlend(color_a, color_b); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { Gdk.Rectangle rect; if (GradientBackround) { rect = new Gdk.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); HslColor gcol = Style.Background(Gtk.StateType.Normal); using (Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow)) { cr.NewPath(); cr.MoveTo(rect.X, rect.Y); cr.RelLineTo(rect.Width, 0); cr.RelLineTo(0, rect.Height); cr.RelLineTo(-rect.Width, 0); cr.RelLineTo(0, -rect.Height); cr.ClosePath(); using (Cairo.Gradient pat = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, rect.Bottom)) { Cairo.Color color1 = gcol; pat.AddColorStop(0, color1); gcol.L -= 0.1; if (gcol.L < 0) { gcol.L = 0; } pat.AddColorStop(1, gcol); cr.SetSource(pat); cr.FillPreserve(); } } } else if (BackgroundColor != null) { using (Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow)) { cr.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); cr.SetSourceColor(BackgroundColor.Value.ToCairoColor()); cr.Fill(); } } else if (useChildBackgroundColor && Child != null) { using (Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow)) { cr.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); cr.SetSourceColor(Child.Style.Base(StateType.Normal).ToCairoColor()); cr.Fill(); } } bool res = base.OnExposeEvent(evnt); var borderColor = new Gdk.GC(GdkWindow); borderColor.RgbFgColor = BorderColor != null ? BorderColor.Value : Style.Dark(Gtk.StateType.Normal); rect = Allocation; for (int n = 0; n < topMargin; n++) { GdkWindow.DrawLine(borderColor, rect.X, rect.Y + n, rect.Right - 1, rect.Y + n); } for (int n = 0; n < bottomMargin; n++) { GdkWindow.DrawLine(borderColor, rect.X, rect.Bottom - n, rect.Right, rect.Bottom - n); } for (int n = 0; n < leftMargin; n++) { GdkWindow.DrawLine(borderColor, rect.X + n, rect.Y, rect.X + n, rect.Bottom); } for (int n = 0; n < rightMargin; n++) { GdkWindow.DrawLine(borderColor, rect.Right - n, rect.Y, rect.Right - n, rect.Bottom); } if (showTopShadow) { using (Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow)) { cr.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, shadowSize); using (Cairo.Gradient pat = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, rect.Y + shadowSize)) { pat.AddColorStop(0, new Cairo.Color(0, 0, 0, shadowStrengh)); pat.AddColorStop(1, new Cairo.Color(0, 0, 0, 0)); cr.SetSource(pat); cr.Fill(); } } } borderColor.Dispose(); return(res); }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { //base.OnExposeEvent (ev); int W = Allocation.Width, H = Allocation.Height; using (Gdk.GC gc = new Gdk.GC(GdkWindow)) { // Creating PixBuf to draw a color matrix if (GdkWindow == null || W < 1 || H < 1) { return(true); } //pb = Gdk.Pixbuf.FromDrawable(Parent.GdkWindow, Gdk.Rgb.Colormap, 0, 0, 0, 0, W - margin * 2, H - margin * 2); // Drawing frame to widget Style.PaintBox(this.Style, GdkWindow, StateType.Normal, ShadowType.In, new Gdk.Rectangle(0, 0, W, H), this, null, margin - 2, margin - 2, W - margin * 2 + 4, H - margin * 2 + 4); if (savedPalette != null) { // Drawing color matrix backbuffer GdkWindow.DrawPixbuf(gc, savedPalette, 0, 0, margin, margin, savedPalette.Width, savedPalette.Height, Gdk.RgbDither.Normal, 0, 0); } // Drawing dark selected color int sel_x = (int)(Tone_to_X(mSelectedDarkTone) * savedPalette.Width) + margin; int sel_y = (int)(Tone_to_Y(mSelectedDarkTone) * savedPalette.Height) + margin; if (mDarkToneSelectorSymbol == ToneSelectorSymbol.Donut) { GdkWindow.DrawPixbuf(gc, black_donut, 0, 0, sel_x - black_donut.Width / 2, sel_y - black_donut.Height / 2, black_donut.Width, black_donut.Height, Gdk.RgbDither.None, 0, 0); } else if (mDarkToneSelectorSymbol == ToneSelectorSymbol.Dot) { GdkWindow.DrawPixbuf(gc, black_dot, 0, 0, sel_x - black_dot.Width / 2, sel_y - black_dot.Height / 2, black_dot.Width, black_dot.Height, Gdk.RgbDither.None, 0, 0); } // Drawing light selected color sel_x = (int)(Tone_to_X(mSelectedLightTone) * savedPalette.Width) + margin; sel_y = (int)(Tone_to_Y(mSelectedLightTone) * savedPalette.Height) + margin; if (mLightToneSelectorSymbol == ToneSelectorSymbol.Donut) { GdkWindow.DrawPixbuf(gc, white_donut, 0, 0, sel_x - white_donut.Width / 2, sel_y - white_donut.Height / 2, white_donut.Width, white_donut.Height, Gdk.RgbDither.None, 0, 0); } else if (mLightToneSelectorSymbol == ToneSelectorSymbol.Dot) { GdkWindow.DrawPixbuf(gc, white_dot, 0, 0, sel_x - white_dot.Width / 2, sel_y - white_dot.Height / 2, white_dot.Width, white_dot.Height, Gdk.RgbDither.None, 0, 0); } } return(true); }
public unsafe static void DrawRgbImageDithalign(this Drawable drawable, Gdk.GC gc, int x, int y, int width, int height, Gdk.RgbDither dith, byte *rgb_buf, int rowstride, int xdith, int ydith) { gdk_draw_rgb_image_dithalign(drawable.Handle, gc == null ? IntPtr.Zero : gc.Handle, x, y, width, height, (int)dith, rgb_buf, rowstride, xdith, ydith); }
protected void OnDrawingareaExposeEvent(object o, Gtk.ExposeEventArgs args) { Gdk.EventExpose expose = args.Args[0] as Gdk.EventExpose; Gdk.Window win = expose.Window; int width, height; win.GetSize(out width, out height); Gdk.Rectangle exposeRect = expose.Area; bool fulldraw = width == exposeRect.Width && height == exposeRect.Height; win.DrawRectangle(Style.LightGC(StateType.Normal), true, exposeRect); if (GetContentDelegate == null) { return; // todo: an error message could be displayed } int offset = (int)vscrollbar1.Value; if (fulldraw) { TopVisibleRow = offset; BottomVisibleRow = offset; } int hscrollRange = 0; int dy = exposeRect.Top; offset += dy / ConstantHeight; dy -= dy % ConstantHeight; Gdk.GC backgound = new Gdk.GC((Gdk.Drawable)base.GdkWindow); Gdk.GC text = new Gdk.GC((Gdk.Drawable)base.GdkWindow); ColumnControl.Column[] columns = mColumnControl.GetVisibleColumnsInDrawOrder(); for (int row = offset; row < RowCount; row++) { int dx = -(int)hscrollbar1.Value; Gdk.Rectangle rect = new Gdk.Rectangle(dx, dy, 0, ConstantHeight); System.Drawing.Color backColor = System.Drawing.Color.WhiteSmoke; System.Drawing.Color textColor = System.Drawing.Color.Black; if (isRowSelected(row)) { if (HasFocus) { backColor = System.Drawing.Color.DarkGray; } else { backColor = System.Drawing.Color.LightGray; } } else { if (GetColorDelegate != null) { GetColorDelegate(row, ref backColor, ref textColor); } } backgound.RgbFgColor = new Gdk.Color(backColor.R, backColor.G, backColor.B); text.RgbFgColor = new Gdk.Color(textColor.R, textColor.G, textColor.B); for (int c = 0; c < columns.Length; c++) { ColumnControl.Column column = columns[c]; int columnIndex = column.SortOrder; int xwidth = column.Width; if (dx > exposeRect.Right) { break; } rect = new Gdk.Rectangle(rect.Left, rect.Top, xwidth + mColumnControl.GripperWidth, ConstantHeight); if (c == columns.Length - 1) { rect.Width = Math.Max(rect.Width, exposeRect.Right - rect.Left + 1); } object content = GetContentDelegate(row, columnIndex); if (content is Gdk.Pixbuf) { Gdk.Pixbuf image = (Gdk.Pixbuf)content; win.DrawRectangle(backgound, true, rect); dx += 2; image.RenderToDrawable(win, text, 0, 0, dx, dy, image.Width, image.Height, Gdk.RgbDither.Normal, 0, 0); dx += xwidth + mColumnControl.GripperWidth - 2; rect.Offset(xwidth + mColumnControl.GripperWidth, 0); } else { LineLayout.SetText(content.ToString()); win.DrawRectangle(backgound, true, rect); dx += 2; win.DrawLayout(text, dx, dy, LineLayout); dx += xwidth + mColumnControl.GripperWidth - 2; rect.Offset(xwidth + mColumnControl.GripperWidth, 0); } } hscrollRange = Math.Max(hscrollRange, dx + rect.Width); dy += ConstantHeight; if (dy > exposeRect.Bottom) { break; } if (fulldraw && exposeRect.Height - dy >= ConstantHeight) { BottomVisibleRow++; } } if (fulldraw) { int pageSize = BottomVisibleRow - TopVisibleRow; if (vscrollbar1.Adjustment.PageSize != pageSize) { vscrollbar1.Adjustment.PageSize = pageSize; vscrollbar1.Adjustment.PageIncrement = pageSize; } hscrollRange += (int)hscrollbar1.Value; if (hscrollRange > 0) { hscrollbar1.SetRange(0, hscrollRange); } // position current row inside visible area // TODO: please think about, because of double redraw a more sophisticated solution could be possible if (CurrentRow >= 0 && CurrentRow < RowCount) { if (CurrentRow < TopVisibleRow) { OffsetCursor(TopVisibleRow - CurrentRow); } else if (CurrentRow > BottomVisibleRow) { OffsetCursor(BottomVisibleRow - CurrentRow); } } } #if DEBUG2 if (ComponentManager != null) { String t1 = String.Format("Expose.Area={0}, size={1}.{2}", expose.Area.ToString(), width, height); String t2 = String.Format("{0} T={1} B={2}", fulldraw ? "FULL" : "PART", TopVisibleRow, BottomVisibleRow); ComponentManager.MessageWriteLineInvoke(String.Format("{0} {1}", t1, t2)); } #endif }
/* * void InternalDrawBackground (TextEditor Editor, Gdk.Drawable win, Pango.Layout layout, bool selected, int startOffset, int endOffset, int y, ref int startXPos, int endXPos, ref bool drawBg) * { * Gdk.Rectangle clipRectangle = new Gdk.Rectangle (mode.Editor.TextViewMargin.XOffset, 0, * Editor.Allocation.Width - mode.Editor.TextViewMargin.XOffset, Editor.Allocation.Height); * * // draw default background * using (Gdk.GC fillGc = new Gdk.GC (win)) { * fillGc.ClipRectangle = clipRectangle; * fillGc.RgbFgColor = selected ? Editor.ColorStyle.Selection.BackgroundColor : Editor.ColorStyle.Default.BackgroundColor; * win.DrawRectangle (fillGc, true, startXPos, y, endXPos, Editor.LineHeight); * } * * if (startOffset >= endOffset) * return; * * int caretOffset = Editor.Caret.Offset - BaseOffset; * foreach (TextLink link in mode.Links) { * if (!link.IsEditable) * continue; * bool isPrimaryHighlighted = link.PrimaryLink.Offset <= caretOffset && caretOffset <= link.PrimaryLink.EndOffset; * * foreach (ISegment segment in link.Links) { * * if ((BaseOffset + segment.Offset <= startOffset && startOffset < BaseOffset + segment.EndOffset) || * (startOffset <= BaseOffset + segment.Offset && BaseOffset + segment.Offset < endOffset)) { * int strOffset = BaseOffset + segment.Offset - startOffset; * int strEndOffset = BaseOffset + segment.EndOffset - startOffset; * * int lineNr, x_pos, x_pos2; * layout.IndexToLineX (strOffset, false, out lineNr, out x_pos); * layout.IndexToLineX (strEndOffset, false, out lineNr, out x_pos2); * x_pos = (int)(x_pos / Pango.Scale.PangoScale); * x_pos2 = (int)(x_pos2 / Pango.Scale.PangoScale); * using (Gdk.GC rectangleGc = new Gdk.GC (win)) { * rectangleGc.ClipRectangle = clipRectangle; * using (Gdk.GC fillGc = new Gdk.GC (win)) { * fillGc.ClipRectangle = clipRectangle; * drawBg = false; * * if (segment == link.PrimaryLink) { * fillGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.PrimaryTemplateHighlighted.BackgroundColor : Editor.ColorStyle.PrimaryTemplate.BackgroundColor; * rectangleGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.PrimaryTemplateHighlighted.Color : Editor.ColorStyle.PrimaryTemplate.Color; * } else { * fillGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.SecondaryTemplateHighlighted.BackgroundColor : Editor.ColorStyle.SecondaryTemplate.BackgroundColor; * rectangleGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.SecondaryTemplateHighlighted.Color : Editor.ColorStyle.SecondaryTemplate.Color; * } * // Draw segment * if (!selected) * win.DrawRectangle (fillGc, true, startXPos, y, x_pos2 - x_pos, Editor.LineHeight); * * int x1 = startXPos + x_pos - 1; * int x2 = startXPos + x_pos2 - 1; * int y2 = y + Editor.LineHeight - 1; * * win.DrawLine (rectangleGc, x1, y, x2, y); * win.DrawLine (rectangleGc, x1, y2, x2, y2); * win.DrawLine (rectangleGc, x1, y, x1, y2); * win.DrawLine (rectangleGc, x2, y, x2, y2); * } * } * } * } * } * startXPos += Editor.GetWidth (Editor.Document.GetTextBetween (startOffset, endOffset)); * } */ /* bool Overlaps (ISegment segment, int start, int end) * { * return segment.Offset <= start && start < segment.EndOffset || * segment.Offset <= end && end < segment.EndOffset || * start <= segment.Offset && segment.Offset < end || * start < segment.EndOffset && segment.EndOffset < end; * }*/ public bool DrawBackground(TextEditor Editor, Gdk.Drawable win, TextViewMargin.LayoutWrapper layout, int selectionStart, int selectionEnd, int startOffset, int endOffset, int y, int startXPos, int endXPos, ref bool drawBg) { int caretOffset = Editor.Caret.Offset - BaseOffset; foreach (TextLink link in mode.Links) { if (!link.IsEditable) { continue; } bool isPrimaryHighlighted = link.PrimaryLink.Offset <= caretOffset && caretOffset <= link.PrimaryLink.EndOffset; foreach (ISegment segment in link.Links) { if ((BaseOffset + segment.Offset <= startOffset && startOffset < BaseOffset + segment.EndOffset) || (startOffset <= BaseOffset + segment.Offset && BaseOffset + segment.Offset < endOffset)) { int strOffset = BaseOffset + segment.Offset - startOffset; int strEndOffset = BaseOffset + segment.EndOffset - startOffset; int x_pos = layout.Layout.IndexToPos(strOffset).X; int x_pos2 = layout.Layout.IndexToPos(strEndOffset).X; x_pos = (int)(x_pos / Pango.Scale.PangoScale); x_pos2 = (int)(x_pos2 / Pango.Scale.PangoScale); using (Gdk.GC rectangleGc = new Gdk.GC(win)) { // rectangleGc.ClipRectangle = clipRectangle; using (Gdk.GC fillGc = new Gdk.GC(win)) { // fillGc.ClipRectangle = clipRectangle; drawBg = false; if (segment == link.PrimaryLink) { fillGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.PrimaryTemplateHighlighted.BackgroundColor : Editor.ColorStyle.PrimaryTemplate.BackgroundColor; rectangleGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.PrimaryTemplateHighlighted.Color : Editor.ColorStyle.PrimaryTemplate.Color; } else { fillGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.SecondaryTemplateHighlighted.BackgroundColor : Editor.ColorStyle.SecondaryTemplate.BackgroundColor; rectangleGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.SecondaryTemplateHighlighted.Color : Editor.ColorStyle.SecondaryTemplate.Color; } // Draw segment int x1 = startXPos + x_pos - 1; int x2 = startXPos + x_pos2 - 1; int y2 = y + Editor.LineHeight - 1; if (selectionStart < 0) { // Console.WriteLine ("Draw BG at " + y + "//" + Editor.GetTextEditorData ().VAdjustment.Value); // Console.WriteLine (Environment.StackTrace); win.DrawRectangle(fillGc, true, x1, y, x2 - x1, Editor.LineHeight); } win.DrawLine(rectangleGc, x1, y, x2, y); win.DrawLine(rectangleGc, x1, y2, x2, y2); win.DrawLine(rectangleGc, x1, y, x1, y2); win.DrawLine(rectangleGc, x2, y, x2, y2); } } } } } /* * int curOffset = startOffset; * foreach (TextLink link in mode.Links) { * if (!link.IsEditable) * continue; * ISegment segment = link.Links.Where (s => Overlaps (s, curOffset - BaseOffset, endOffset - BaseOffset)).FirstOrDefault (); * if (segment == null) { * break; * } * InternalDrawBackground (Editor, win, layout, selected, curOffset, segment.Offset + BaseOffset, y, ref startXPos, endXPos, ref drawBg); * curOffset = segment.EndOffset + BaseOffset; * InternalDrawBackground (Editor, win, layout, selected, segment.Offset + BaseOffset, curOffset, y, ref startXPos, endXPos, ref drawBg); * } * InternalDrawBackground (Editor, win, layout, selected, curOffset, endOffset, y, ref startXPos, endXPos, ref drawBg); */ return(true); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { Gdk.Rectangle rect = Allocation; //Gdk.Rectangle.Right and Bottom are inconsistent int right = rect.X + rect.Width, bottom = rect.Y + rect.Height; var bcolor = backgroundColorSet ? BackgroundColor : Style.Background(Gtk.StateType.Normal); using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) { if (GradientBackround) { cr.NewPath(); cr.MoveTo(rect.X, rect.Y); cr.RelLineTo(rect.Width, 0); cr.RelLineTo(0, rect.Height); cr.RelLineTo(-rect.Width, 0); cr.RelLineTo(0, -rect.Height); cr.ClosePath(); using (Cairo.Gradient pat = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, bottom)) { pat.AddColorStop(0, bcolor.ToCairoColor()); HslColor gcol = bcolor; gcol.L -= 0.1; if (gcol.L < 0) { gcol.L = 0; } pat.AddColorStop(1, gcol); cr.SetSource(pat); cr.Fill(); } } else { if (backgroundColorSet) { Gdk.GC gc = new Gdk.GC(GdkWindow); gc.RgbFgColor = bcolor; evnt.Window.DrawRectangle(gc, true, rect.X, rect.Y, rect.Width, rect.Height); gc.Dispose(); } } cr.Dispose(); } // using base.OnExposeEvent(evnt); using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) { cr.SetSourceColor((HslColor)Style.Dark(Gtk.StateType.Normal)); double y = rect.Y + topMargin / 2d; cr.LineWidth = topMargin; cr.Line(rect.X, y, right, y); cr.Stroke(); y = bottom - bottomMargin / 2d; cr.LineWidth = bottomMargin; cr.Line(rect.X, y, right, y); cr.Stroke(); double x = rect.X + leftMargin / 2d; cr.LineWidth = leftMargin; cr.Line(x, rect.Y, x, bottom); cr.Stroke(); x = right - rightMargin / 2d; cr.LineWidth = rightMargin; cr.Line(x, rect.Y, x, bottom); cr.Stroke(); cr.Dispose(); return(false); } }
protected override void DrawIcon(Gdk.Drawable d, Cairo.Context g) { Gdk.GC gc = new Gdk.GC(d); Images.RenderProfileTiny(d, X - _icon_half_width, Y - _icon_half_height, _c); }
private void RefreshGC() { text_gc = null; }
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 override bool OnExposeEvent(Gdk.EventExpose args) { using (var g = Gdk.CairoHelper.Create(args.Window)) { g.Translate(Allocation.X, Allocation.Y); g.LineWidth = 1; Gdk.GC gc = new Gdk.GC(args.Window); layout.SetMarkup(TitleText); int width, height; layout.GetPixelSize(out width, out height); width += xBorder * 2; FoldingScreenbackgroundRenderer.DrawRoundRectangle(g, true, false, 0.5, 0.5, height + yBorder * 2 + 1.5, width, height + yBorder * 2); g.SetSourceColor(Styles.TableLayoutModeTitleBackgroundColor.ToCairoColor()); g.FillPreserve(); g.SetSourceColor(Styles.TableLayoutModeBorderColor.ToCairoColor()); g.Stroke(); g.Save(); g.SetSourceColor(Styles.TableLayoutModeTextColor.ToCairoColor()); g.Translate(xBorder, yBorder); g.ShowLayout(layout); g.Restore(); FoldingScreenbackgroundRenderer.DrawRoundRectangle(g, false, true, 0.5, height * 2 + yBorder * 2 + 0.5, height, Allocation.Width - 1, Allocation.Height - height * 2 - yBorder * 2 - 1); g.SetSourceColor(Styles.TableLayoutModeBackgroundColor.ToCairoColor()); g.FillPreserve(); g.SetSourceColor(Styles.TableLayoutModeBorderColor.ToCairoColor()); g.Stroke(); g.MoveTo(xSpacer + 0.5, height * 2 + yBorder * 2); g.LineTo(xSpacer + 0.5, Allocation.Height - 1); g.SetSourceColor(Styles.TableLayoutModeGridColor.ToCairoColor()); g.Stroke(); int y = height + yBorder * 2; for (int i = 0; i < Items.Count; i++) { KeyValuePair <string, string> pair = Items[i]; layout.SetMarkup(pair.Key); layout.GetPixelSize(out width, out height); if (i == 0) { FoldingScreenbackgroundRenderer.DrawRoundRectangle(g, false, true, false, false, 0, y + 0.5, height + 1.5, Allocation.Width, height); g.SetSourceColor(Styles.TableLayoutModeCategoryBackgroundColor.ToCairoColor()); g.FillPreserve(); g.SetSourceColor(Styles.TableLayoutModeBorderColor.ToCairoColor()); g.Stroke(); g.MoveTo(xSpacer + 0.5, height + yBorder * 2 + 1); g.LineTo(xSpacer + 0.5, height * 2 + yBorder * 2 + 1); g.SetSourceColor(Styles.TableLayoutModeGridColor.ToCairoColor()); g.Stroke(); } gc.RgbFgColor = (HslColor)(i == 0 ? Styles.TableLayoutModeBackgroundColor : Styles.TableLayoutModeTextColor).ToCairoColor(); g.Save(); g.SetSourceColor(Styles.TableLayoutModeTextColor.ToCairoColor()); g.Translate(xBorder, y); g.ShowLayout(layout); g.Restore(); g.Save(); g.SetSourceColor(Styles.TableLayoutModeTextColor.ToCairoColor()); g.Translate(xSpacer + xBorder, y); layout.SetMarkup(pair.Value); g.ShowLayout(layout); g.Restore(); // draw top line if (i > 0) { g.MoveTo(1, y + 0.5); g.LineTo(Allocation.Width - 1, y + 0.5); g.SetSourceColor(Styles.TableLayoutModeGridColor.ToCairoColor()); g.Stroke(); } y += height; } gc.Dispose(); } return(base.OnExposeEvent(args)); }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { //base.OnExposeEvent (ev); int w, h, x, y; w = Allocation.Width; h = Allocation.Height; x = Allocation.Left; y = Allocation.Top; // Recalculating margins int trough_border = (int)this.StyleGetProperty("trough-border"); mLeftMargin = trough_border; mRightMargin = trough_border; int trough_height = 11; int slider_width = (int)this.StyleGetProperty("slider-width"); mSliderLength = (int)this.StyleGetProperty("slider-length"); mTopMargin = h / 2 - trough_height / 2; mBottomMargin = mTopMargin; mTopSliderMargin = h / 2 - slider_width / 2; mBottomSliderMargin = mTopSliderMargin; // Painting focus rect if (this.IsFocus) { Style.PaintFocus(this.Style, GdkWindow, StateType.Active, new Gdk.Rectangle(x, y, w, h), this, "hscale", x, y, w, h); } // Painting box Style.PaintBox(this.Style, GdkWindow, StateType.Insensitive, ShadowType.In, new Gdk.Rectangle(x + mLeftMargin, y + mTopMargin, w - mLeftMargin - mRightMargin, h - mTopMargin - mBottomMargin), this, "button", x + mLeftMargin, y + mTopMargin, w - mLeftMargin - mRightMargin, h - mTopMargin - mBottomMargin); // Painting gradient Gdk.GC gc = new Gdk.GC(GdkWindow); int xmin = mLeftMargin + 3; int xmax = w - mRightMargin - 3; int ymin = mTopMargin + 2; int ymax = h - mBottomMargin - 2; for (int i = 0; i < xmax - xmin; i += 1) { double xx = (double)i / (xmax - xmin); for (int j = 0; j < ymax - ymin; j += 1) { double yy = (double)j / (ymax - ymin); double r = (xx) * (255 * (1 - yy)) + (1 - xx) * 192; double g = (xx) * (128) + (1 - xx) * 192; double b = (xx) * (255 * yy) + (1 - xx) * 192; gc.RgbFgColor = new Gdk.Color((byte)r, (byte)g, (byte)b); GdkWindow.DrawPoint(gc, x + i + xmin, y + j + ymin); } } // Painting slider int left_slider_pos = mSliderLength / 2 + mLeftSliderMargin; int right_slider_pos = w - mRightSliderMargin - mSliderLength / 2; int slider_pos = (int)(left_slider_pos + (right_slider_pos - left_slider_pos) * (Adjustment.Value - Adjustment.Lower) / (this.Adjustment.Upper - Adjustment.Lower)); StateType slider_state = StateType.Normal; // Testing if sensitive Widget wdg = this; bool sens = true; do { if (!wdg.Sensitive) { sens = false; break; } wdg = wdg.Parent; } while (wdg != null); if (sens) { if (mSliderActive) { slider_state = StateType.Prelight; } } else { slider_state = StateType.Insensitive; } Style.PaintSlider(this.Style, GdkWindow, slider_state, ShadowType.Out, new Gdk.Rectangle(x + slider_pos - mSliderLength / 2, y + mTopSliderMargin, mSliderLength, h - mTopSliderMargin - mBottomSliderMargin), this, "hscale", x + slider_pos - mSliderLength / 2, y + mTopSliderMargin, mSliderLength, h - mTopSliderMargin - mBottomSliderMargin, Orientation.Horizontal); //gc.Dispose(); return(true); }
protected override void DrawContents(Gdk.Drawable d) { Gdk.GC gc = new Gdk.GC(d); Cairo.Context g = Gdk.CairoHelper.Create(d); g.SelectFontFace("Lucida Console", FontSlant.Normal, FontWeight.Bold); g.SetFontSize(24); TextExtents te; string lvl, hp, hpm, mp, mpm; string weapon, armor; #region Slots g.Color = new Color(.1, .1, .2); g.Rectangle(x9, yi, 8 * xs, yj - yi); g.Fill(); g.Rectangle(x9, yk, 8 * xs, yl - yk); g.Fill(); Cairo.Color gray1 = new Color(.2, .2, .2); Cairo.Color gray2 = new Color(.7, .7, .8); int links, slots; slots = Selected.Weapon.Slots.Length; links = Selected.Weapon.Links; for (int j = 0; j < links; j++) { Graphics.RenderLine(g, gray2, 3, X + x9 + (xs / 2) + (j * 2 * xs), Y + yi - ys - zs, X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yi - ys - zs); Graphics.RenderLine(g, gray2, 3, X + x9 + (xs / 2) + (j * 2 * xs), Y + yi - ys, X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yi - ys); Graphics.RenderLine(g, gray2, 3, X + x9 + (xs / 2) + (j * 2 * xs), Y + yi - ys + zs, X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yi - ys + zs); } for (int i = 0; i < slots; i++) { Graphics.RenderCircle(g, gray2, 14, X + x9 + (i * xs) + (xs / 2), Y + yi - ys); if (Selected.Weapon.Slots[i] == null) { Graphics.RenderCircle(g, gray1, 10, X + x9 + (i * xs) + (xs / 2), Y + yi - ys); } else { Graphics.RenderCircle(g, Selected.Weapon.Slots[i].Color, 10, X + x9 + (i * xs) + (xs / 2), Y + yi - ys); } } slots = Selected.Armor.Slots.Length; links = Selected.Armor.Links; for (int j = 0; j < links; j++) { Graphics.RenderLine(g, gray2, 3, X + x9 + (xs / 2) + (j * 2 * xs), Y + yk - ys - zs, X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yk - ys - zs); Graphics.RenderLine(g, gray2, 3, X + x9 + (xs / 2) + (j * 2 * xs), Y + yk - ys, X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yk - ys); Graphics.RenderLine(g, gray2, 3, X + x9 + (xs / 2) + (j * 2 * xs), Y + yk - ys + zs, X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yk - ys + zs); } for (int i = 0; i < slots; i++) { Graphics.RenderCircle(g, gray2, 14, X + x9 + (i * xs) + (xs / 2), Y + yk - ys); if (Selected.Armor.Slots[i] == null) { Graphics.RenderCircle(g, gray1, 10, X + x9 + (i * xs) + (xs / 2), Y + yk - ys); } else { Graphics.RenderCircle(g, Selected.Armor.Slots[i].Color, 10, X + x9 + (i * xs) + (xs / 2), Y + yk - ys); } } #endregion #region Character Status d.DrawPixbuf(gc, Graphics.GetProfile(Selected.Name), 0, 0, X + xpic, Y + ypic, Graphics.PROFILE_WIDTH, Graphics.PROFILE_HEIGHT, Gdk.RgbDither.None, 0, 0); g.Color = new Color(.3, .8, .8); g.MoveTo(X + x3, Y + y + ya); g.ShowText("LV"); g.MoveTo(X + x3, Y + y + yb); g.ShowText("HP"); g.MoveTo(X + x3, Y + y + yc); g.ShowText("MP"); g.Color = new Color(1, 1, 1); Graphics.ShadowedText(g, Selected.Name, X + x3, Y + y); lvl = Selected.Level.ToString(); hp = Selected.HP.ToString() + "/"; hpm = Selected.MaxHP.ToString(); mp = Selected.MP.ToString() + "/"; mpm = Selected.MaxMP.ToString(); te = g.TextExtents(lvl); Graphics.ShadowedText(g, lvl, X + x4 - te.Width, Y + y + ya); te = g.TextExtents(hp); Graphics.ShadowedText(g, hp, X + x5 - te.Width, Y + y + yb); te = g.TextExtents(hpm); Graphics.ShadowedText(g, hpm, X + x6 - te.Width, Y + y + yb); te = g.TextExtents(mp); Graphics.ShadowedText(g, mp, X + x5 - te.Width, Y + y + yc); te = g.TextExtents(mpm); Graphics.ShadowedText(g, mpm, X + x6 - te.Width, Y + y + yc); #endregion Status #region Equipment g.Color = new Color(.3, .8, .8); g.MoveTo(X + x7, Y + yh); g.ShowText("Wpn."); g.MoveTo(X + x7, Y + yj); g.ShowText("Arm."); g.Color = new Color(1, 1, 1); Graphics.ShadowedText(g, "Check", x7a, yja); Graphics.ShadowedText(g, "Arr.", x7a, yla); weapon = Selected.Weapon.Name; armor = Selected.Armor.Name; te = g.TextExtents(weapon); Graphics.ShadowedText(g, weapon, X + x8, Y + yh); te = g.TextExtents(armor); Graphics.ShadowedText(g, armor, X + x8, Y + yj); #endregion if (IsControl) { Graphics.RenderCursor(g, X + cx, Y + cy - ys); } ((IDisposable)g.Target).Dispose(); ((IDisposable)g).Dispose(); }
protected override void Draw(Gdk.GC gc, Gdk.Drawable dest, int x, int y, byte b, Gdk.Pixmap pix) { dest.DrawDrawable(gc, pix, b*2*width, 0, x, y, 2*width, 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) { // 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 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); }