[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/Xsharp Image.cs,NONE,1.1 Bitmap.cs,1
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/Xsharp Image.cs,NONE,1.1 Bitmap.cs,1.1,1.2 Display.cs,1.3,1.4 Graphics.cs,1.2,1.3 Pixmap.cs,1.1,1.2Xlib.cs.in,1.5,1.6 |
Date: |
Sat, 07 Jun 2003 01:40:09 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv31536/Xsharp
Modified Files:
Bitmap.cs Display.cs Graphics.cs Pixmap.cs Xlib.cs.in
Added Files:
Image.cs
Log Message:
Add image loading and drawing facilities, using Imlib to do the loading;
update XHello to display the DotGNU logo instead of crossed lines.
--- NEW FILE ---
/*
* Image.cs - Basic image handling for X applications.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace Xsharp
{
using System;
/// <summary>
/// <para>The <see cref="T:Xsharp.Image"/> class manages an image
/// consisting of a pixmap and an optional mask. Images may be
/// created in memory or loaded from a file.</para>
/// </summary>
public sealed class Image : IDisposable
{
// Internal state.
private Xsharp.Pixmap pixmap;
private Bitmap mask;
/// <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);
if(hasMask)
{
mask = new Bitmap(width, height);
}
else
{
mask = null;
}
}
/// <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);
if(hasMask)
{
mask = new Bitmap(screen, width,
height);
}
else
{
mask = null;
}
}
/// <summary>
/// <para>Constructs a new <see cref="T:Xsharp.Image"/> instance
/// that represents an off-screen image that was loaded
/// from a file.</para>
/// </summary>
///
/// <param name="filename">
/// <para>The file to load the image from.</para>
/// </param>
///
/// <exception cref="T:System.ArgumentNullException">
/// <para>The <paramref name="filename"/> parameter is
/// <see langword="null"/>.</para>
/// </exception>
///
/// <exception cref="T:Xsharp.XInvalidOperationException">
/// <para>Raised if <paramref name="filename"/> could not be
/// loaded for some reason.</para>
/// </exception>
public Image(String filename) : this(null, filename) {}
/// <summary>
/// <para>Constructs a new <see cref="T:Xsharp.Image"/> instance
/// that represents an off-screen image that was loaded
/// from a file.</para>
/// </summary>
///
/// <param name="screen">
/// <para>The screen upon which to create the new pixmap.</para>
/// </param>
///
/// <param name="filename">
/// <para>The file to load the image from.</para>
/// </param>
///
/// <exception cref="T:System.ArgumentNullException">
/// <para>The <paramref name="filename"/> parameter is
/// <see langword="null"/>.</para>
/// </exception>
///
/// <exception cref="T:Xsharp.XInvalidOperationException">
/// <para>Raised if <paramref name="filename"/> could not be
/// loaded for some reason.</para>
/// </exception>
public Image(Screen screen, String filename)
{
Display dpy;
if(filename == null)
{
throw new
ArgumentNullException("filename");
}
if(screen != null)
{
dpy = screen.DisplayOfScreen;
}
else
{
dpy = Application.Primary.Display;
screen = dpy.DefaultScreenOfDisplay;
}
try
{
// Lock down the display while we do
this.
IntPtr display = dpy.Lock();
// Call "XShmQueryExtension" before
"Imlib_init".
// This is a hack to make sure that
"Xext" is loaded
// into memory before "Imlib" goes
looking for it.
Xlib.XShmQueryExtension(display);
// Initialize the Imlib library if
necessary.
if(dpy.imlibData == IntPtr.Zero)
{
dpy.imlibData =
Xlib.Imlib_init(display);
}
// Load the file and convert it into a
pixmap and mask.
Xlib.Pixmap pixmap, mask;
pixmap = Xlib.Pixmap.Zero;
mask = Xlib.Pixmap.Zero;
if(Xlib.Imlib_load_file_to_pixmap
(dpy.imlibData,
filename, ref pixmap, ref mask)
== 0)
{
throw new
XInvalidOperationException
(S._("X_InvalidImageFile"));
}
// Wrap the returned XID's in
Pixmap/Bitmap objects.
this.pixmap = new Pixmap(dpy, screen,
pixmap);
if(mask != Xlib.Pixmap.Zero)
{
this.mask = new Bitmap(dpy,
screen, mask);
}
else
{
this.mask = null;
}
}
finally
{
dpy.Unlock();
}
}
/// <summary>
/// <para>Retrieve the pixmap that is associated with this image.</para>
/// </summary>
///
/// <value>
/// <para>The pixmap instance, or <see langword="null"/> if disposed.
/// </para>
/// </value>
public Xsharp.Pixmap Pixmap
{
get
{
return pixmap;
}
}
/// <summary>
/// <para>Retrieve the mask that is associated with this image.</para>
/// </summary>
///
/// <value>
/// <para>The mask instance, or <see langword="null"/> if disposed.
/// </para>
/// </value>
public Bitmap Mask
{
get
{
return mask;
}
}
/// <summary>
/// <para>Get the width of the image.</para>
/// </summary>
///
/// <value>
/// <para>The image's width.</para>
/// </para>
/// </value>
public int Width
{
get
{
return pixmap.Width;
}
}
/// <summary>
/// <para>Get the height of the image.</para>
/// </summary>
///
/// <value>
/// <para>The image's height.</para>
/// </para>
/// </value>
public int Height
{
get
{
return pixmap.Height;
}
}
/// <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;
}
}
/// <summary>
/// <para>Dispose this image if it is currently active.</para>
/// </summary>
///
/// <remarks>
/// <para>This method implements the <see cref="T:System.IDisposable"/>
/// interface.</para>
/// </remarks>
public void Dispose()
{
Destroy();
}
} // class Image
} // namespace Xsharp
Index: Bitmap.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Bitmap.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Bitmap.cs 28 May 2003 04:17:53 -0000 1.1
--- Bitmap.cs 7 Jun 2003 05:40:07 -0000 1.2
***************
*** 65,68 ****
--- 65,70 ----
Xlib.XRootWindowOfScreen(screen.screen),
(uint)width, (uint)height,
(uint)1));
+ this.width = width;
+ this.height = height;
}
finally
***************
*** 114,117 ****
--- 116,148 ----
Xlib.XRootWindowOfScreen(screen.screen),
(uint)width, (uint)height,
(uint)1));
+ this.width = width;
+ this.height = height;
+ }
+ finally
+ {
+ dpy.Unlock();
+ }
+ }
+
+ // Internal constructor that wraps a bitmap XID.
+ internal Bitmap(Display dpy, Screen screen, Xlib.Pixmap pixmap)
+ : base(dpy, screen, DrawableKind.Bitmap)
+ {
+ SetPixmapHandle(pixmap);
+ try
+ {
+ // Get the geometry of the pixmap from
the X server.
+ IntPtr display = dpy.Lock();
+ Xlib.Window root_return;
+ Xlib.Xint x_return, y_return;
+ Xlib.Xuint width_return, height_return;
+ Xlib.Xuint border_width_return,
depth_return;
+ Xlib.XGetGeometry
+ (display, handle, out
root_return,
+ out x_return, out y_return,
+ out width_return, out
height_return,
+ out border_width_return, out
depth_return);
+ this.width = (int)width_return;
+ this.height = (int)height_return;
}
finally
Index: Display.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Display.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** Display.cs 7 Jun 2003 02:18:39 -0000 1.3
--- Display.cs 7 Jun 2003 05:40:07 -0000 1.4
***************
*** 60,63 ****
--- 60,64 ----
internal BuiltinBitmaps bitmaps;
internal Timer timerQueue;
+ internal IntPtr imlibData;
// Constructor.
Index: Graphics.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Graphics.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Graphics.cs 6 Jun 2003 07:47:06 -0000 1.2
--- Graphics.cs 7 Jun 2003 05:40:07 -0000 1.3
***************
*** 2007,2010 ****
--- 2007,2117 ----
}
+ /// <summary>
+ /// <para>Draw an image to this graphics context.</para>
+ /// </summary>
+ ///
+ /// <param name="x">
+ /// <para>The X co-ordinate of the top-left point of
+ /// the image's bounding rectangle.</para>
+ /// </param>
+ ///
+ /// <param name="y">
+ /// <para>The Y co-ordinate of the top-left point of
+ /// the image's bounding rectangle.</para>
+ /// </param>
+ ///
+ /// <param name="image">
+ /// <para>The image to be drawn.</para>
+ /// </param>
+ ///
+ /// <exception cref="T:System.ArgumentNullException">
+ /// <para>Raised if <paramref name="image"/> is <see langword="null"/>.
+ /// </para>
+ /// </exception>
+ ///
+ /// <exception cref="T:Xsharp.XException">
+ /// <para>One of the co-ordinate values is out of range.</para>
+ /// </exception>
+ public void DrawImage(int x, int y, Image image)
+ {
+ // Validate the image parameter.
+ if(image == null)
+ {
+ throw new
ArgumentNullException("image");
+ }
+
+ // Set the context to "tiling" and fill the
region.
+ SetFillTiled(image.Pixmap, x, y);
+ SetClipMask(image.Mask, x, y);
+ FillRectangle(x, y, image.Pixmap.Width,
image.Pixmap.Height);
+
+ // Revert the context to a sane fill mode.
+ SetFillSolid();
+ SetClipMask(null);
+ }
+
+ /// <summary>
+ /// <para>Draw an image sub-part to this graphics context.</para>
+ /// </summary>
+ ///
+ /// <param name="x">
+ /// <para>The X co-ordinate of the top-left point of
+ /// the image's bounding rectangle.</para>
+ /// </param>
+ ///
+ /// <param name="y">
+ /// <para>The Y co-ordinate of the top-left point of
+ /// the image's bounding rectangle.</para>
+ /// </param>
+ ///
+ /// <param name="image">
+ /// <para>The image to be drawn.</para>
+ /// </param>
+ ///
+ /// <param name="srcX">
+ /// <para>The X co-ordinate of the top-left point of
+ /// the image sub-part to be drawn.</para>
+ /// </param>
+ ///
+ /// <param name="srcY">
+ /// <para>The Y co-ordinate of the top-left point of
+ /// the image sub-part to be drawn.</para>
+ /// </param>
+ ///
+ /// <param name="srcWidth">
+ /// <para>The width of the image sub-part to be drawn.</para>
+ /// </param>
+ ///
+ /// <param name="srcHeight">
+ /// <para>The height of the image sub-part to be drawn.</para>
+ /// </param>
+ ///
+ /// <exception cref="T:System.ArgumentNullException">
+ /// <para>Raised if <paramref name="image"/> is <see langword="null"/>.
+ /// </para>
+ /// </exception>
+ ///
+ /// <exception cref="T:Xsharp.XException">
+ /// <para>One of the co-ordinate or size values is out of range.</para>
+ /// </exception>
+ public void DrawImage(int x, int y, Image image,
+ int srcX, int srcY, int
srcWidth, int srcHeight)
+ {
+ // Validate the image parameter.
+ if(image == null)
+ {
+ throw new
ArgumentNullException("image");
+ }
+
+ // Set the context to "tiling" and fill the
region.
+ SetFillTiled(image.Pixmap, x - srcX, y - srcY);
+ SetClipMask(image.Mask, x - srcX, y - srcY);
+ FillRectangle(x, y, srcWidth, srcHeight);
+
+ // Revert the context to a sane fill mode.
+ SetFillSolid();
+ SetClipMask(null);
+ }
+
// Draw a radio button.
private void DrawRadio(IntPtr display,
Index: Pixmap.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Pixmap.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Pixmap.cs 28 May 2003 04:17:53 -0000 1.1
--- Pixmap.cs 7 Jun 2003 05:40:07 -0000 1.2
***************
*** 66,69 ****
--- 66,71 ----
(uint)width, (uint)height,
(uint)Xlib.XDefaultDepthOfScreen(screen.screen)));
+ this.width = width;
+ this.height = height;
}
finally
***************
*** 116,119 ****
--- 118,150 ----
(uint)width, (uint)height,
(uint)Xlib.XDefaultDepthOfScreen(screen.screen)));
+ this.width = width;
+ this.height = height;
+ }
+ finally
+ {
+ dpy.Unlock();
+ }
+ }
+
+ // Internal constructor that wraps a pixmap XID.
+ internal Pixmap(Display dpy, Screen screen, Xlib.Pixmap pixmap)
+ : base(dpy, screen, DrawableKind.Bitmap)
+ {
+ SetPixmapHandle(pixmap);
+ try
+ {
+ // Get the geometry of the pixmap from
the X server.
+ IntPtr display = dpy.Lock();
+ Xlib.Window root_return;
+ Xlib.Xint x_return, y_return;
+ Xlib.Xuint width_return, height_return;
+ Xlib.Xuint border_width_return,
depth_return;
+ Xlib.XGetGeometry
+ (display, handle, out
root_return,
+ out x_return, out y_return,
+ out width_return, out
height_return,
+ out border_width_return, out
depth_return);
+ this.width = (int)width_return;
+ this.height = (int)height_return;
}
finally
Index: Xlib.cs.in
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Xlib.cs.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** Xlib.cs.in 7 Jun 2003 02:18:39 -0000 1.5
--- Xlib.cs.in 7 Jun 2003 05:40:07 -0000 1.6
***************
*** 203,206 ****
--- 203,213 ----
@X_uint@ width, @X_uint@ height, Bool exposures);
+ [DllImport("X11")]
+ extern public static Status XGetGeometry
+ (IntPtr display, Drawable d, out Window 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);
+
// Declare pixmap-related external functions.
***************
*** 487,490 ****
--- 494,510 ----
extern public static @X_int@ XNextEventWithTimeout
(IntPtr display, out XEvent xevent, @X_int@ timeout);
+
+ // Helper functions from "libImlib.so" for loading images.
+
+ [DllImport("Imlib")]
+ extern public static IntPtr Imlib_init(IntPtr disp);
+
+ [DllImport("Imlib")]
+ extern public static @X_int@ Imlib_load_file_to_pixmap
+ (IntPtr id, String filename, ref Pixmap pixmap,
+ ref Pixmap mask);
+
+ [DllImport("Xext")]
+ extern public static Bool XShmQueryExtension(IntPtr display);
} // class Xlib
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/Xsharp Image.cs,NONE,1.1 Bitmap.cs,1.1,1.2 Display.cs,1.3,1.4 Graphics.cs,1.2,1.3 Pixmap.cs,1.1,1.2Xlib.cs.in,1.5,1.6,
Rhys Weatherley <address@hidden> <=