2003-01-16 00:53:49 +01:00
|
|
|
/* Copyright (C) 2000, 2003 Free Software Foundation
|
2000-10-22 19:46:09 +02:00
|
|
|
|
|
|
|
This file is part of libgcj.
|
|
|
|
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
|
|
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
package gnu.gcj.xlib;
|
|
|
|
|
|
|
|
import gnu.gcj.RawData;
|
|
|
|
import java.awt.Rectangle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An X11 graphics context. Unlike a traditional X11 graphics
|
|
|
|
* context, the target drawable is part of the GC state.
|
|
|
|
*
|
|
|
|
* Implementation notes: There is no need to do coalescing of changes
|
|
|
|
* since Xlib will do this for us. The implementation relies on the
|
|
|
|
* Xlib GC cache and will not try to be clever.
|
|
|
|
*
|
|
|
|
* @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
|
|
|
|
*/
|
|
|
|
public class GC implements Cloneable
|
|
|
|
{
|
2003-04-19 21:54:39 +02:00
|
|
|
/** Protected constructor, because GC.create(target) should be used instead.
|
|
|
|
*/
|
|
|
|
protected GC(Drawable target)
|
2000-10-22 19:46:09 +02:00
|
|
|
{
|
|
|
|
this.target = target;
|
|
|
|
initStructure(null);
|
|
|
|
}
|
|
|
|
|
2003-04-19 21:54:39 +02:00
|
|
|
/** Try to get a suitable GC from the drawable's cache.
|
|
|
|
* If there isn't one, create one.
|
|
|
|
*/
|
2000-10-22 19:46:09 +02:00
|
|
|
public Object clone()
|
|
|
|
{
|
2003-07-21 04:24:09 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
GC gcClone = target.getGCFromCache ();
|
|
|
|
if (gcClone==null)
|
|
|
|
{
|
|
|
|
gcClone = (GC) super.clone();
|
|
|
|
gcClone.structure = null;
|
|
|
|
}
|
|
|
|
gcClone.initStructure(this);
|
2003-12-05 23:10:16 +01:00
|
|
|
gcClone.updateClip(clipRectangles);
|
2003-07-21 04:24:09 +02:00
|
|
|
return gcClone;
|
|
|
|
}
|
|
|
|
catch (CloneNotSupportedException ex)
|
|
|
|
{
|
|
|
|
// This should never happen.
|
|
|
|
throw new InternalError ();
|
|
|
|
}
|
2000-10-22 19:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private native void initStructure(GC copyFrom);
|
|
|
|
|
|
|
|
public GC create()
|
|
|
|
{
|
|
|
|
return (GC) clone();
|
|
|
|
}
|
2003-04-19 21:54:39 +02:00
|
|
|
|
|
|
|
/** Create a GC, or if one is already cached for target, return that.
|
|
|
|
* @param target The Drawable for which a GC is needed
|
|
|
|
* @return The new or retrieved GC
|
|
|
|
*/
|
|
|
|
static public GC create (Drawable target)
|
|
|
|
{
|
|
|
|
GC returnValue = target.getGCFromCache ();
|
|
|
|
if (returnValue == null)
|
|
|
|
returnValue = new GC (target);
|
|
|
|
return returnValue;
|
|
|
|
}
|
2000-10-22 19:46:09 +02:00
|
|
|
|
|
|
|
public void finalize()
|
|
|
|
{
|
|
|
|
disposeImpl();
|
|
|
|
}
|
|
|
|
|
2003-04-19 21:54:39 +02:00
|
|
|
/** Save this GC in the drawable's cache.
|
|
|
|
* The "real" dispose (disposeImpl) is called when the
|
|
|
|
* drawable is finialized, to free X server resources.
|
|
|
|
*/
|
2000-10-22 19:46:09 +02:00
|
|
|
public void dispose()
|
|
|
|
{
|
2003-04-19 21:54:39 +02:00
|
|
|
target.putGCInCache (this);
|
2000-10-22 19:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized native void disposeImpl();
|
|
|
|
|
|
|
|
public native void setForeground(long pixel);
|
|
|
|
public native void setFont(gnu.gcj.xlib.Font font);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the clip region for the graphics operations performed by the
|
|
|
|
* GC.
|
|
|
|
*
|
|
|
|
* This is one of the few costly operations of this class. It is
|
|
|
|
* suggested that the clip is only set or changed if really
|
|
|
|
* necessary. Higher level APIs can make such optimizations
|
|
|
|
* transparent.
|
|
|
|
*
|
|
|
|
* @param rectangles the union of these rectangles describe the clip
|
|
|
|
* region.
|
|
|
|
*/
|
|
|
|
public void setClipRectangles(Rectangle[] rectangles)
|
|
|
|
{
|
2003-12-05 23:10:16 +01:00
|
|
|
clipRectangles = rectangles;
|
|
|
|
updateClip(clipRectangles);
|
2000-10-22 19:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public native void drawString(String text, int x, int y);
|
|
|
|
public native void drawLine(int x1, int y1, int x2, int y2);
|
|
|
|
public native void drawRectangle(int x, int y, int w, int h);
|
|
|
|
|
|
|
|
public native void fillRectangle(int x, int y, int w, int h);
|
2003-01-16 00:53:49 +01:00
|
|
|
public native void fillPolygon(int[] xPoints, int[] yPoints, int nPoints,
|
|
|
|
int translateX, int translateY);
|
2003-06-12 05:08:58 +02:00
|
|
|
|
|
|
|
public native void drawArc(int x, int y, int w, int h,
|
|
|
|
int startAngle, int arcAngle);
|
|
|
|
public native void fillArc(int x, int y, int w, int h,
|
|
|
|
int startAngle, int arcAngle);
|
2000-10-22 19:46:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Clear area using the background pixel or pixmap of the drawable.
|
|
|
|
* Note that this operation does not adhere to the current clip.
|
|
|
|
*/
|
|
|
|
public native void clearArea(int x, int y, int w, int h,
|
|
|
|
boolean exposures);
|
|
|
|
|
2004-07-12 18:26:07 +02:00
|
|
|
/** Draw a point using the current foreground color
|
|
|
|
* @param x The x coordinate at which to draw
|
|
|
|
* @param t The y coordinate at which to draw
|
|
|
|
*/
|
|
|
|
public native void drawPoint (int x, int y);
|
2000-10-22 19:46:09 +02:00
|
|
|
|
|
|
|
public native void putImage(XImage image,
|
|
|
|
int srcX, int srcY,
|
|
|
|
int destX, int destY,
|
|
|
|
int width, int height);
|
|
|
|
|
2003-08-25 21:02:29 +02:00
|
|
|
public native void copyArea (Drawable source,
|
|
|
|
int srcX, int srcY,
|
|
|
|
int destX, int destY,
|
|
|
|
int width, int height);
|
|
|
|
|
2000-10-22 19:46:09 +02:00
|
|
|
public Drawable getDrawable()
|
|
|
|
{
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2003-12-05 23:10:16 +01:00
|
|
|
private native void updateClip(Rectangle[] rectangles);
|
2000-10-22 19:46:09 +02:00
|
|
|
|
|
|
|
private Drawable target;
|
|
|
|
private RawData structure;
|
2003-12-05 23:10:16 +01:00
|
|
|
private Rectangle[] clipRectangles;
|
2000-10-22 19:46:09 +02:00
|
|
|
}
|
|
|
|
|