/// <summary> /// <para>Create a new cursor, based on a pre-defined cursor type.</para> /// </summary> /// /// <param name="type"> /// <para>The pre-defined cursor type to use.</para> /// </param> public Cursor(CursorType type) { this.type = type; this.source = null; this.mask = null; this.cursor = XCursor.Zero; }
// Get the bitmap corresponding to a particular hatch style. private static Xsharp.Bitmap GetBitmap(HatchStyle style) { Xsharp.Bitmap bitmap; // See if we have a cached bitmap for this style. if (((int)style) >= 0 && ((int)style) <= 52) { if (hatchBitmaps == null) { hatchBitmaps = new Xsharp.Bitmap [53]; } bitmap = hatchBitmaps[(int)style]; if (bitmap != null) { return(bitmap); } } else { return(null); } // Get the raw bits for the hatch bitmap. byte[] bits = GetBits(style); if (bits == null) { return(null); } // Create the bitmap, cache it for later, and then return it. bitmap = new Xsharp.Bitmap(16, 16, bits); hatchBitmaps[(int)style] = bitmap; return(bitmap); }
/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Image"/> instance /// that represents an off-screen image.</para> /// </summary> /// /// <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="hasMask"> /// <para>Set to <see langword="null"/> if the optional mask /// should also be created.</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(int width, int height, bool hasMask) { pixmap = new Pixmap(width, height); screen = pixmap.screen; if(hasMask) { mask = new Bitmap(width, height); } else { mask = null; } }
/// <summary> /// <para>Create a new cursor, based on a user-supplied image /// and mask.</para> /// </summary> /// /// <param name="source"> /// <para>The bitmap defining the source image for the cursor.</para> /// </param> /// /// <param name="mask"> /// <para>The bitmap defining the mask for the cursor.</para> /// </param> /// /// <param name="hotspotX"> /// <para>The X position of the cursor hotspot.</para> /// </param> /// /// <param name="hotspotY"> /// <para>The Y position of the cursor hotspot.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"/> /// <para>Raised if <paramref name="source"/> or <paramref name="mask"/> /// is <see langword="null"/>.</para> /// </exception> public Cursor(Bitmap source, Bitmap mask, int hotspotX, int hotspotY) { if(source == null) { throw new ArgumentNullException("source"); } if(mask == null) { throw new ArgumentNullException("mask"); } this.type = CursorType.XC_inherit_parent; this.source = source; this.mask = mask; this.cursor = XCursor.Zero; }
// Draw a bitmap-based glyph to a "Graphics" object. "bits" must be // in the form of an xbm bitmap. public override void DrawGlyph(int x, int y, byte[] bits, int bitsWidth, int bitsHeight, System.Drawing.Color color) { Xsharp.Bitmap bitmap; bitmap = new Xsharp.Bitmap(bitsWidth, bitsHeight, bits); try { graphics.Foreground = DrawingToolkit.DrawingToXColor(color); graphics.SetFillStippled(bitmap, x, y); graphics.FillRectangle(x, y, bitsWidth, bitsHeight); graphics.SetFillSolid(); } finally { bitmap.Destroy(); } }
// Convert an XImage mask into a Bitmap object. public static Bitmap XImageMaskToBitmap(Screen screen, IntPtr ximage) { int width, height; Xlib.XSharpGetImageSize(ximage, out width, out height); Bitmap bitmap = new Bitmap(screen, width, height); Graphics graphics = new Graphics(bitmap); graphics.PutXImage(ximage, 0, 0, 0, 0, width, height); graphics.Dispose(); return bitmap; }
/// <summary> /// <para>Create a new cursor, based on a user-supplied image frame.</para> /// </summary> /// /// <param name="screen"> /// <para>The screen to create the cursor for, or /// <see langword="null"/> for the default screen on the /// default display.</para> /// </param> /// /// <param name="frame"> /// <para>The frame defining the cursor image.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"/> /// <para>Raised if <paramref name="frame"/> is /// <see langword="null"/>.</para> /// </exception> public Cursor(Screen screen, Frame frame) { Display dpy; if(frame == null) { throw new ArgumentNullException("frame"); } if(screen != null) { dpy = screen.DisplayOfScreen; } else { dpy = Application.Primary.Display; screen = dpy.DefaultScreenOfDisplay; } if( /* irgnore pixel format! frame.PixelFormat != PixelFormat.Format1bppIndexed || */ frame.Mask == null) { // The frame is not suitable for use as a cursor. this.type = CursorType.XC_left_ptr; this.source = null; this.mask = null; this.cursor = XCursor.Zero; } else { this.type = CursorType.XC_inherit_parent; this.cursor = XCursor.Zero; try { dpy.Lock(); IntPtr pixmapXImage = ConvertImage.FrameToXImageBitmap(screen, frame); IntPtr maskXImage = ConvertImage.MaskToXImage (screen, frame); source = ConvertImage.XImageMaskToBitmap (screen, pixmapXImage); mask = ConvertImage.XImageMaskToBitmap (screen, maskXImage); Xlib.XSharpDestroyImage(pixmapXImage); Xlib.XSharpDestroyImage(maskXImage); hotspotX = frame.HotspotX; hotspotY = frame.HotspotY; if(frame.Palette != null && frame.Palette[0] == 0) { reverse = true; } } finally { dpy.Unlock(); } } }
/// <summary> /// <para>Destroy this image if it is currently active.</para> /// </summary> public void Destroy() { if(pixmap != null) { pixmap.Destroy(); pixmap = null; } if(mask != null) { mask.Destroy(); mask = null; } if(pixmapXImage != IntPtr.Zero) { Xlib.XSharpDestroyImage(pixmapXImage); pixmapXImage = IntPtr.Zero; } if(maskXImage != IntPtr.Zero) { Xlib.XSharpDestroyImage(maskXImage); maskXImage = IntPtr.Zero; } }
/// <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); }
/// <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="hasMask"> /// <para>Set to <see langword="null"/> if the optional mask /// should also be created.</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, bool hasMask) { pixmap = new Xsharp.Pixmap(screen, width, height); screen = pixmap.screen; if(hasMask) { mask = new Bitmap(screen, width, height); } else { mask = null; } }
// Get the bitmap corresponding to a particular hatch style. private static Xsharp.Bitmap GetBitmap(HatchStyle style) { Xsharp.Bitmap bitmap; // See if we have a cached bitmap for this style. if(((int)style) >= 0 && ((int)style) <= 52) { if(hatchBitmaps == null) { hatchBitmaps = new Xsharp.Bitmap [53]; } bitmap = hatchBitmaps[(int)style]; if(bitmap != null) { return bitmap; } } else { return null; } // Get the raw bits for the hatch bitmap. byte[] bits = GetBits(style); if(bits == null) { return null; } // Create the bitmap, cache it for later, and then return it. bitmap = new Xsharp.Bitmap(16, 16, bits); hatchBitmaps[(int)style] = bitmap; return bitmap; }
/// <summary> /// <para>Set the fill style mode to "solid".</para> /// </summary> public void SetFillSolid() { try { IntPtr display = Lock(); Xlib.XSetFillStyle (display, gc, (int)(Xsharp.FillStyle.FillSolid)); if(tile != null) { Xlib.XSetTSOrigin(display, gc, 0, 0); tile = null; } else if(stipple != null) { Xlib.XSetTSOrigin(display, gc, 0, 0); stipple = null; } } finally { dpy.Unlock(); } }
/// <summary> /// <para>Set the clip area to a bitmap mask, with a specified /// clip origin.</para> /// </summary> /// /// <param name="mask"> /// <para>The mask to set, or <see langword="null"/> to clear the /// clip mask.</para> /// </param> /// /// <param name="xorigin"> /// <para>The X co-ordinate of the clipping origin.</para> /// </param> /// /// <param name="yorigin"> /// <para>The Y co-ordinate of the clipping origin.</para> /// </param> /// /// <exception cref="T:Xsharp.XException"> /// <para>The <paramref name="xorigin"/> or <paramref name="yorigin"/> /// value is out of range.</para> /// </exception> /// /// <exception cref="T:System.XInvalidOperationException"> /// <para>The <paramref name="mask"/> value is disposed.</para> /// </exception> public void SetClipMask(Bitmap mask, int xorigin, int yorigin) { if(xorigin < -32768 || xorigin > 32767 || yorigin < -32768 || yorigin > 32767) { throw new XException(S._("X_PointCoordRange")); } try { IntPtr display = Lock(); Xlib.XSetClipOrigin(display, gc, xorigin, yorigin); if(mask != null) { Xlib.XSetClipMask(display, gc, mask.GetPixmapHandle()); } else { Xlib.XSetClipMask(display, gc, XPixmap.Zero); } } finally { dpy.Unlock(); } }
/// <summary> /// <para>Set the clip area to a bitmap mask</para> /// </summary> /// /// <param name="mask"> /// <para>The mask to set, or <see langword="null"/> to clear the /// clip mask.</para> /// </param> /// /// <exception cref="T:System.XInvalidOperationException"> /// <para>The <paramref name="mask"/> value is disposed.</para> /// </exception> public void SetClipMask(Bitmap mask) { try { IntPtr display = Lock(); Xlib.XSetClipOrigin(display, gc, 0, 0); if(mask != null) { Xlib.XSetClipMask(display, gc, mask.GetPixmapHandle()); } else { Xlib.XSetClipMask(display, gc, XPixmap.Zero); } } finally { dpy.Unlock(); } }
/// <summary> /// <para>Set the fill style mode to "opaque stippled", with a specific /// stippling bitmap.</para> /// </summary> /// /// <param name="stipple"> /// <para>The stippling bitmap to use.</para> /// </param> /// /// <param name="xorigin"> /// <para>The X co-ordinate of the stippling origin.</para> /// </param> /// /// <param name="yorigin"> /// <para>The Y co-ordinate of the stippling origin.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"> /// <para>The <paramref name="stipple"/> value is /// <see langword="null"/>.</para> /// </exception> /// /// <exception cref="T:Xsharp.XException"> /// <para>The <paramref name="xorigin"/> or <paramref name="yorigin"/> /// value is out of range.</para> /// </exception> /// /// <exception cref="T:System.XInvalidOperationException"> /// <para>The <paramref name="tile"/> value is disposed.</para> /// </exception> public void SetFillOpaqueStippled(Bitmap stipple, int xorigin, int yorigin) { if(stipple == null) { throw new ArgumentNullException("stipple"); } if(xorigin < -32768 || xorigin > 32767 || yorigin < -32768 || yorigin > 32767) { throw new XException(S._("X_PointCoordRange")); } try { IntPtr display = Lock(); Xlib.XSetStipple(display, gc, stipple.GetPixmapHandle()); Xlib.XSetFillStyle (display, gc, (int)(Xsharp.FillStyle.FillOpaqueStippled)); Xlib.XSetTSOrigin(display, gc, xorigin, yorigin); this.stipple = stipple; tile = null; } finally { dpy.Unlock(); } }