/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Bitmap"/> instance /// that represents an off-screen bitmap. The bitmap is created /// on the specified <paramref name="screen"/>, using the /// supplied bitmap data.</para> /// </summary> /// /// <param name="screen"> /// <para>The screen upon which to create the new bitmap.</para> /// </param> /// /// <param name="width"> /// <para>The width of the new bitmap.</para> /// </param> /// /// <param name="height"> /// <para>The height of the new bitmap.</para> /// </param> /// /// <param name="bits"> /// <para>The bits that make up the data.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"> /// <para>Raised if <paramref name="bits"/> is <see langword="null"/>. /// </para> /// </exception> /// /// <exception cref="T:Xsharp.XException"> /// <para>The <paramref name="width"/> or <paramref name="height"/> /// values are out of range, or <paramref name="bits"/> is invalid /// in some way.</para> /// </exception> public Bitmap(Screen screen, int width, int height, byte[] bits) : base(GetDisplay(screen), screen, DrawableKind.Bitmap) { if (width < 1 || width > 32767 || height < 1 || height > 32767) { throw new XException(S._("X_InvalidBitmapSize")); } if (bits == null) { throw new ArgumentNullException("bits"); } if (((((width + 15) & ~15) * height) / 8) > bits.Length) { throw new XException(S._("X_InvalidBitmapBits")); } try { IntPtr display = dpy.Lock(); XDrawable drawable = (XDrawable) Xlib.XRootWindowOfScreen(screen.screen); SetPixmapHandle(Xlib.XCreateBitmapFromData (display, drawable, bits, (uint)width, (uint)height)); this.width = width; this.height = height; } finally { dpy.Unlock(); } }
// Load builtin bitmaps for a particular display. public BuiltinBitmaps(Display display) { IntPtr dpy = display.dpy; XDrawable drawable = display.DefaultRootWindow.handle; RadioBottom = Xlib.XCreateBitmapFromData (dpy, drawable, radio_b_bits, (uint)12, (uint)12); RadioBottomEnhanced = Xlib.XCreateBitmapFromData (dpy, drawable, radio_B_bits, (uint)12, (uint)12); RadioTop = Xlib.XCreateBitmapFromData (dpy, drawable, radio_t_bits, (uint)12, (uint)12); RadioTopEnhanced = Xlib.XCreateBitmapFromData (dpy, drawable, radio_T_bits, (uint)12, (uint)12); RadioBackground = Xlib.XCreateBitmapFromData (dpy, drawable, radio_w_bits, (uint)12, (uint)12); RadioForeground = Xlib.XCreateBitmapFromData (dpy, drawable, radio_f_bits, (uint)12, (uint)12); Close = Xlib.XCreateBitmapFromData (dpy, drawable, close_button_bits, (uint)9, (uint)9); Minimize = Xlib.XCreateBitmapFromData (dpy, drawable, minimize_button_bits, (uint)9, (uint)9); Maximize = Xlib.XCreateBitmapFromData (dpy, drawable, maximize_button_bits, (uint)9, (uint)9); Restore = Xlib.XCreateBitmapFromData (dpy, drawable, restore_button_bits, (uint)9, (uint)9); Help = Xlib.XCreateBitmapFromData (dpy, drawable, help_button_bits, (uint)9, (uint)9); }
/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Bitmap"/> instance /// that represents an off-screen bitmap. The bitmap is created /// on the default screen of the primary display, using the /// supplied bitmap data.</para> /// </summary> /// /// <param name="width"> /// <para>The width of the new bitmap.</para> /// </param> /// /// <param name="height"> /// <para>The height of the new bitmap.</para> /// </param> /// /// <param name="bits"> /// <para>The bits that make up the data.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"> /// <para>Raised if <paramref name="bits"/> is <see langword="null"/>. /// </para> /// </exception> /// /// <exception cref="T:Xsharp.XException"> /// <para>The <paramref name="width"/> or <paramref name="height"/> /// values are out of range, or <paramref name="bits"/> is invalid /// in some way.</para> /// </exception> public Bitmap(int width, int height, byte[] bits) : base(Xsharp.Application.Primary.Display, Xsharp.Application.Primary.Display.DefaultScreenOfDisplay, DrawableKind.Bitmap) { if (width < 1 || width > 32767 || height < 1 || height > 32767) { throw new XException(S._("X_InvalidBitmapSize")); } if (bits == null) { throw new ArgumentNullException("bits"); } int unit = (width <= 8 ? 7 : 15); if (((((width + unit) & ~unit) * height) / 8) > bits.Length) { throw new XException(S._("X_InvalidBitmapBits")); } try { IntPtr display = dpy.Lock(); XDrawable drawable = (XDrawable) Xlib.XRootWindowOfScreen(screen.screen); SetPixmapHandle(Xlib.XCreateBitmapFromData (display, drawable, bits, (uint)width, (uint)height)); this.width = width; this.height = height; } finally { dpy.Unlock(); } }
// Set the handle for this drawable, assuming it is a pixmap. internal void SetPixmapHandle(XPixmap handle) { try { dpy.Lock(); this.handle = (XDrawable)handle; } finally { dpy.Unlock(); } }
// Set the handle for this drawable, assuming it is a widget. internal void SetWidgetHandle(XWindow handle) { try { dpy.Lock(); this.handle = (XDrawable)handle; dpy.handleMap[handle] = (Widget)this; } finally { dpy.Unlock(); } }
/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Image"/> instance /// that represents an off-screen image on a particular screen.</para> /// </summary> /// /// <param name="screen"> /// <para>The screen upon which to create the new pixmap.</para> /// </param> /// /// <param name="width"> /// <para>The width of the new image.</para> /// </param> /// /// <param name="height"> /// <para>The height of the new image.</para> /// </param> /// /// <param name="image"> /// <para>The bits that make up the image.</para> /// </param> /// /// <param name="mask"> /// <para>The bits that make up the mask.</para> /// </param> /// /// <exception cref="T:Xsharp.XException"> /// <para>The <paramref name="width"/> or <paramref name="height"/> /// values are out of range.</para> /// </exception> public Image(Screen screen, int width, int height, byte[] image, byte[] mask) { Display dpy; if (screen != null) { dpy = screen.DisplayOfScreen; } else { dpy = Application.Primary.Display; screen = dpy.DefaultScreenOfDisplay; } this.screen = screen; if (width < 1 || width > 32767 || height < 1 || height > 32767) { throw new XException(S._("X_InvalidBitmapSize")); } if (image == null) { throw new ArgumentNullException("bits"); } if (((((width + 15) & ~15) * height) / 8) > image.Length) { throw new XException(S._("X_InvalidBitmapBits")); } try { IntPtr display = dpy.Lock(); XDrawable drawable = (XDrawable) Xlib.XRootWindowOfScreen(screen.screen); XPixmap pixmap = Xlib.XCreateBitmapFromData (display, drawable, image, (uint)width, (uint)height); this.pixmap = new Pixmap(dpy, screen, pixmap); } finally { dpy.Unlock(); } if (mask != null) { this.mask = new Bitmap(screen, width, height, mask); } }
extern public static XStatus XdbeDeallocateBackBufferName (IntPtr display, XDrawable buffer);
extern public static void XSharpDrawStringPCF (IntPtr display, XDrawable drawable, IntPtr gc, IntPtr fontSet, int x, int y, [MarshalAs(UnmanagedType.Interface)] String str, int offset, int count, int style);
extern public static void XSharpDrawStringSet (IntPtr display, XDrawable drawable, IntPtr gc, IntPtr fontSet, int x, int y, String str, int style);
extern public static void XSharpDrawStringXft (IntPtr display, XDrawable drawable, IntPtr gc, IntPtr fontSet, int x, int y, String str, int style, IntPtr clipRegion, uint colorValue);
extern public static int XCopyArea (IntPtr display, XDrawable src, XDrawable dest, IntPtr gc, int src_x, int src_y, uint width, uint height, int dest_x, int dest_y);
extern public static int XPutImage (IntPtr display, XDrawable drawable, IntPtr gc, IntPtr image, int src_x, int src_y, int dest_x, int dest_y, int width, int height);
extern public static XPixmap XCreateBitmapFromData (IntPtr display, XDrawable drawable, byte[] data, uint width, uint height);
extern public static int XFillPolygon (IntPtr display, XDrawable drawable, IntPtr gc, XPoint[] points, int npoints, int shape, int mode);
extern public static int XDrawPoints (IntPtr display, XDrawable drawable, IntPtr gc, XPoint[] points, int npoints, int mode);
extern public static int XDrawPoint (IntPtr display, XDrawable drawable, IntPtr gc, int x, int y);
extern public static int XDrawLine (IntPtr display, XDrawable drawable, IntPtr gc, int x1, int y1, int x2, int y2);
extern public static IntPtr XCreateGC(IntPtr display, XDrawable drawable, uint values_mask, ref XGCValues values);
extern public static XStatus XGetGeometry (IntPtr display, XDrawable d, out XWindow root_return, out Xint x_return, out Xint y_return, out Xuint width_return, out Xuint height_return, out Xuint border_width_return, out Xuint depth_return);
extern public static int XFillArc (IntPtr display, XDrawable drawable, IntPtr gc, int x, int y, int width, int height, int angle1, int angle2);
extern public static int XFillRectangle (IntPtr display, XDrawable drawable, IntPtr gc, int x, int y, int width, int height);
extern public static XPixmap XCreatePixmap (IntPtr display, XDrawable d, uint width, uint height, uint depth);
extern public static int XFillRectangles (IntPtr display, XDrawable drawable, IntPtr gc, XRectangle[] rectangles, int nrectangles);
/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Graphics"/> object and /// attaches it to a <see cref="T:Xsharp.Drawable"/> instance.</para> /// </summary> /// /// <param name="drawable"> /// <para>The drawable to attach this graphics context to. If the /// drawable is a widget, the foreground and background colors of the /// graphics object will be initially set to the widget's standard /// foreground and background colors.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"> /// <para>Raised if <paramref name="drawable"/> is <see langword="null"/>. /// </para> /// </exception> /// /// <exception cref="T:Xsharp.XInvalidOperationException"> /// <para>Raised if <paramref name="drawable"/> does not support /// output, is disposed, or is the root window.</para> /// </exception> public Graphics(Drawable drawable) { if(drawable == null) { throw new ArgumentNullException("drawable"); } else if(drawable.Kind == DrawableKind.InputOnlyWidget) { throw new XInvalidOperationException (S._("X_GraphicsIsOutputOnly")); } else if(drawable is RootWindow) { throw new XInvalidOperationException (S._("X_NonRootOperation")); } dpy = drawable.dpy; this.drawable = drawable; XGCValues gcValues = new XGCValues(); InputOutputWidget widget = (drawable as InputOutputWidget); DoubleBuffer buffer = (drawable as DoubleBuffer); Bitmap bitmap = (drawable as Bitmap); if(widget != null) { foreground = widget.Foreground; background = widget.Background; } else if(buffer != null) { foreground = buffer.Widget.Foreground; background = buffer.Widget.Background; } else if(bitmap != null) { foreground = new Color(0x00, 0x00, 0x00); background = new Color(0xFF, 0xFF, 0xFF); } else { foreground = new Color (StandardColor.Foreground); background = new Color (StandardColor.Background); } gcValues.foreground = drawable.ToPixel(foreground); gcValues.background = drawable.ToPixel(background); if(drawable is DoubleBuffer) { ((DoubleBuffer)drawable).Start(this); } try { IntPtr display = dpy.Lock(); drawableHandle = drawable.GetGCHandle(); gc = drawable.screen.GetGC(bitmap != null); if(gc == IntPtr.Zero) { // Create a new GC because the cache is empty. gc = Xlib.XCreateGC(display, drawableHandle, (uint)(GCValueMask.GCForeground | GCValueMask.GCBackground), ref gcValues); if(gc == IntPtr.Zero) { Display.OutOfMemory(); } } else { // Reset the cached GC back to the default settings. // Xlib will take care of stripping the list down // to just the changes that need to be applied. gcValues.function = Xsharp.GCFunction.GXcopy; gcValues.plane_mask = ~((XPixel)0); gcValues.line_width = 0; gcValues.line_style = Xsharp.LineStyle.LineSolid; gcValues.cap_style = Xsharp.CapStyle.CapButt; gcValues.join_style = Xsharp.JoinStyle.JoinMiter; gcValues.fill_style = Xsharp.FillStyle.FillSolid; gcValues.fill_rule = Xsharp.FillRule.EvenOddRule; gcValues.arc_mode = Xsharp.ArcMode.ArcPieSlice; gcValues.ts_x_origin = 0; gcValues.ts_y_origin = 0; gcValues.subwindow_mode = Xsharp.SubwindowMode.ClipByChildren; gcValues.graphics_exposures = true; gcValues.clip_x_origin = 0; gcValues.clip_y_origin = 0; gcValues.clip_mask = XPixmap.Zero; gcValues.dash_offset = 0; gcValues.dashes = (sbyte)4; Xlib.XChangeGC(display, gc, (uint)(GCValueMask.GCFunction | GCValueMask.GCPlaneMask | GCValueMask.GCForeground | GCValueMask.GCBackground | GCValueMask.GCLineWidth | GCValueMask.GCLineStyle | GCValueMask.GCCapStyle | GCValueMask.GCJoinStyle | GCValueMask.GCFillStyle | GCValueMask.GCFillRule | GCValueMask.GCTileStipXOrigin | GCValueMask.GCTileStipYOrigin | GCValueMask.GCSubwindowMode | GCValueMask.GCGraphicsExposures | GCValueMask.GCClipXOrigin | GCValueMask.GCClipYOrigin | GCValueMask.GCClipMask | GCValueMask.GCDashOffset | GCValueMask.GCDashList | GCValueMask.GCArcMode), ref gcValues); } int sn = drawable.screen.ScreenNumber; double px, mm; px = (double)Xlib.XDisplayWidth(display, sn); mm = (double)Xlib.XDisplayWidthMM(display, sn); dpiX = (float)((px * 25.4) / mm); px = (double)Xlib.XDisplayHeight(display, sn); mm = (double)Xlib.XDisplayHeightMM(display, sn); dpiY = (float)((px * 25.4) / mm); } finally { dpy.Unlock(); } if(drawable is DoubleBuffer) { ((DoubleBuffer)drawable).ClearAtStart(this); } isDisposed = false; }