x1, y1
) and (x2
, y2
).
*
* @param x1 the first point's x coordinate
* @param y1 the first point's y coordinate
* @param x2 the second point's x coordinate
* @param y2 the second point's y coordinate
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawLine(int x1, int y1, int x2, int y2) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
checkGC(DRAW);
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
Cairo.cairo_move_to(cairo, x1 + xOffset, y1 + yOffset);
Cairo.cairo_line_to(cairo, x2 + xOffset, y2 + yOffset);
Cairo.cairo_stroke(cairo);
return;
}
OS.gdk_draw_line (data.drawable, handle, x1, y1, x2, y2);
}
/**
* Draws the outline of an oval, using the foreground color,
* within the specified rectangular area.
*
* The result is a circle or ellipse that fits within the
* rectangle specified by the x
, y
,
* width
, and height
arguments.
*
* The oval covers an area that is width + 1
* pixels wide and height + 1
pixels tall.
*
*
* @param x the x coordinate of the upper left corner of the oval to be drawn
* @param y the y coordinate of the upper left corner of the oval to be drawn
* @param width the width of the oval to be drawn
* @param height the height of the oval to be drawn
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawOval(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
checkGC(DRAW);
if (width < 0) {
x = x + width;
width = -width;
}
if (height < 0) {
y = y + height;
height = -height;
}
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
if (width == height) {
Cairo.cairo_arc_negative(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, 0, -2 * (float)Compatibility.PI);
} else {
Cairo.cairo_save(cairo);
Cairo.cairo_translate(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f);
Cairo.cairo_scale(cairo, width / 2f, height / 2f);
Cairo.cairo_arc_negative(cairo, 0, 0, 1, 0, -2 * (float)Compatibility.PI);
Cairo.cairo_restore(cairo);
}
Cairo.cairo_stroke(cairo);
return;
}
OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, 0, 23040);
}
/**
* Draws the path described by the parameter.
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
*
* @param path the path to draw
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the parameter is null
* - ERROR_INVALID_ARGUMENT - if the parameter has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see Path
*
* @since 3.1
*/
public void drawPath(Path path) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
initCairo();
checkGC(DRAW);
long /*int*/ cairo = data.cairo;
Cairo.cairo_save(cairo);
double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
Cairo.cairo_translate(cairo, xOffset, yOffset);
long /*int*/ copy = Cairo.cairo_copy_path(path.handle);
if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
Cairo.cairo_append_path(cairo, copy);
Cairo.cairo_path_destroy(copy);
Cairo.cairo_stroke(cairo);
Cairo.cairo_restore(cairo);
}
/**
* Draws a pixel, using the foreground color, at the specified
* point (x
, y
).
*
* Note that the receiver's line attributes do not affect this
* operation.
*
*
* @param x the point's x coordinate
* @param y the point's y coordinate
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.0
*/
public void drawPoint (int x, int y) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
checkGC(DRAW);
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
Cairo.cairo_rectangle(cairo, x, y, 1, 1);
Cairo.cairo_fill(cairo);
return;
}
OS.gdk_draw_point(data.drawable, handle, x, y);
}
/**
* Draws the closed polygon which is defined by the specified array
* of integer coordinates, using the receiver's foreground color. The array
* contains alternating x and y values which are considered to represent
* points which are the vertices of the polygon. Lines are drawn between
* each consecutive pair, and between the first pair and last pair in the
* array.
*
* @param pointArray an array of alternating x and y values which are the vertices of the polygon
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT if pointArray is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawPolygon(int[] pointArray) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
checkGC(DRAW);
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
drawPolyline(cairo, pointArray, true);
Cairo.cairo_stroke(cairo);
return;
}
OS.gdk_draw_polygon(data.drawable, handle, 0, pointArray, pointArray.length / 2);
}
/**
* Draws the polyline which is defined by the specified array
* of integer coordinates, using the receiver's foreground color. The array
* contains alternating x and y values which are considered to represent
* points which are the corners of the polyline. Lines are drawn between
* each consecutive pair, but not between the first pair and last pair in
* the array.
*
* @param pointArray an array of alternating x and y values which are the corners of the polyline
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the point array is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawPolyline(int[] pointArray) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
checkGC(DRAW);
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
drawPolyline(cairo, pointArray, false);
Cairo.cairo_stroke(cairo);
return;
}
OS.gdk_draw_lines(data.drawable, handle, pointArray, pointArray.length / 2);
}
void drawPolyline(long /*int*/ cairo, int[] pointArray, boolean close) {
int count = pointArray.length / 2;
if (count == 0) return;
double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
Cairo.cairo_move_to(cairo, pointArray[0] + xOffset, pointArray[1] + yOffset);
for (int i = 1, j=2; i < count; i++, j += 2) {
Cairo.cairo_line_to(cairo, pointArray[j] + xOffset, pointArray[j + 1] + yOffset);
}
if (close) Cairo.cairo_close_path(cairo);
}
/**
* Draws the outline of the rectangle specified by the arguments,
* using the receiver's foreground color. The left and right edges
* of the rectangle are at x
and x + width
.
* The top and bottom edges are at y
and y + height
.
*
* @param x the x coordinate of the rectangle to be drawn
* @param y the y coordinate of the rectangle to be drawn
* @param width the width of the rectangle to be drawn
* @param height the height of the rectangle to be drawn
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawRectangle(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
checkGC(DRAW);
if (width < 0) {
x = x + width;
width = -width;
}
if (height < 0) {
y = y + height;
height = -height;
}
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
Cairo.cairo_rectangle(cairo, x + xOffset, y + yOffset, width, height);
Cairo.cairo_stroke(cairo);
return;
}
OS.gdk_draw_rectangle(data.drawable, handle, 0, x, y, width, height);
}
/**
* Draws the outline of the specified rectangle, using the receiver's
* foreground color. The left and right edges of the rectangle are at
* rect.x
and rect.x + rect.width
. The top
* and bottom edges are at rect.y
and
* rect.y + rect.height
.
*
* @param rect the rectangle to draw
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the rectangle is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawRectangle(Rectangle rect) {
if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
drawRectangle (rect.x, rect.y, rect.width, rect.height);
}
/**
* Draws the outline of the round-cornered rectangle specified by
* the arguments, using the receiver's foreground color. The left and
* right edges of the rectangle are at x
and x + width
.
* The top and bottom edges are at y
and y + height
.
* The roundness of the corners is specified by the
* arcWidth
and arcHeight
arguments, which
* are respectively the width and height of the ellipse used to draw
* the corners.
*
* @param x the x coordinate of the rectangle to be drawn
* @param y the y coordinate of the rectangle to be drawn
* @param width the width of the rectangle to be drawn
* @param height the height of the rectangle to be drawn
* @param arcWidth the width of the arc
* @param arcHeight the height of the arc
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
checkGC(DRAW);
int nx = x;
int ny = y;
int nw = width;
int nh = height;
int naw = arcWidth;
int nah = arcHeight;
if (nw < 0) {
nw = 0 - nw;
nx = nx - nw;
}
if (nh < 0) {
nh = 0 - nh;
ny = ny -nh;
}
if (naw < 0) naw = 0 - naw;
if (nah < 0) nah = 0 - nah;
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
if (naw == 0 || nah == 0) {
Cairo.cairo_rectangle(cairo, x + xOffset, y + yOffset, width, height);
} else {
float naw2 = naw / 2f;
float nah2 = nah / 2f;
float fw = nw / naw2;
float fh = nh / nah2;
Cairo.cairo_save(cairo);
Cairo.cairo_translate(cairo, nx + xOffset, ny + yOffset);
Cairo.cairo_scale(cairo, naw2, nah2);
Cairo.cairo_move_to(cairo, fw - 1, 0);
Cairo.cairo_arc(cairo, fw - 1, 1, 1, Compatibility.PI + Compatibility.PI/2.0, Compatibility.PI*2.0);
Cairo.cairo_arc(cairo, fw - 1, fh - 1, 1, 0, Compatibility.PI/2.0);
Cairo.cairo_arc(cairo, 1, fh - 1, 1, Compatibility.PI/2, Compatibility.PI);
Cairo.cairo_arc(cairo, 1, 1, 1, Compatibility.PI, 270.0*Compatibility.PI/180.0);
Cairo.cairo_close_path(cairo);
Cairo.cairo_restore(cairo);
}
Cairo.cairo_stroke(cairo);
return;
}
int naw2 = naw / 2;
int nah2 = nah / 2;
long /*int*/ drawable = data.drawable;
if (nw > naw) {
if (nh > nah) {
OS.gdk_draw_arc(drawable, handle, 0, nx, ny, naw, nah, 5760, 5760);
OS.gdk_draw_line(drawable, handle, nx + naw2, ny, nx + nw - naw2, ny);
OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny, naw, nah, 0, 5760);
OS.gdk_draw_line(drawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
OS.gdk_draw_line(drawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
OS.gdk_draw_arc(drawable, handle, 0, nx, ny + nh - nah, naw, nah, 11520, 5760);
OS.gdk_draw_line(drawable, handle, nx, ny + nah2, nx, ny + nh - nah2);
} else {
OS.gdk_draw_arc(drawable, handle, 0, nx, ny, naw, nh, 5760, 11520);
OS.gdk_draw_line(drawable, handle, nx + naw2, ny, nx + nw - naw2, ny);
OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny, naw, nh, 17280, 11520);
OS.gdk_draw_line(drawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
}
} else {
if (nh > nah) {
OS.gdk_draw_arc(drawable, handle, 0, nx, ny, nw, nah, 0, 11520);
OS.gdk_draw_line(drawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
OS.gdk_draw_arc(drawable, handle, 0, nx, ny + nh - nah, nw, nah, 11520, 11520);
OS.gdk_draw_line(drawable,handle, nx, ny + nah2, nx, ny + nh - nah2);
} else {
OS.gdk_draw_arc(drawable, handle, 0, nx, ny, nw, nh, 0, 23040);
}
}
}
/**
* Draws the given string, using the receiver's current font and
* foreground color. No tab expansion or carriage return processing
* will be performed. The background of the rectangular area where
* the string is being drawn will be filled with the receiver's
* background color.
*
* @param string the string to be drawn
* @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
* @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the string is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawString (String string, int x, int y) {
drawString(string, x, y, false);
}
/**
* Draws the given string, using the receiver's current font and
* foreground color. No tab expansion or carriage return processing
* will be performed. If isTransparent
is true
,
* then the background of the rectangular area where the string is being
* drawn will not be modified, otherwise it will be filled with the
* receiver's background color.
*
* @param string the string to be drawn
* @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
* @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
* @param isTransparent if true
the background will be transparent, otherwise it will be opaque
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the string is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawString(String string, int x, int y, boolean isTransparent) {
drawText(string, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0);
}
/**
* Draws the given string, using the receiver's current font and
* foreground color. Tab expansion and carriage return processing
* are performed. The background of the rectangular area where
* the text is being drawn will be filled with the receiver's
* background color.
*
* @param string the string to be drawn
* @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
* @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the string is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawText(String string, int x, int y) {
drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
}
/**
* Draws the given string, using the receiver's current font and
* foreground color. Tab expansion and carriage return processing
* are performed. If isTransparent
is true
,
* then the background of the rectangular area where the text is being
* drawn will not be modified, otherwise it will be filled with the
* receiver's background color.
*
* @param string the string to be drawn
* @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
* @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
* @param isTransparent if true
the background will be transparent, otherwise it will be opaque
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the string is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawText(String string, int x, int y, boolean isTransparent) {
int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB;
if (isTransparent) flags |= SWT.DRAW_TRANSPARENT;
drawText(string, x, y, flags);
}
/**
* Draws the given string, using the receiver's current font and
* foreground color. Tab expansion, line delimiter and mnemonic
* processing are performed according to the specified flags. If
* flags
includes DRAW_TRANSPARENT
,
* then the background of the rectangular area where the text is being
* drawn will not be modified, otherwise it will be filled with the
* receiver's background color.
*
* The parameter flags
may be a combination of:
*
* - DRAW_DELIMITER
* - draw multiple lines
* - DRAW_TAB
* - expand tabs
* - DRAW_MNEMONIC
* - underline the mnemonic character
* - DRAW_TRANSPARENT
* - transparent background
*
*
*
* @param string the string to be drawn
* @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
* @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
* @param flags the flags specifying how to process the text
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the string is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void drawText (String string, int x, int y, int flags) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (string.length() == 0) return;
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
//TODO - honor flags
checkGC(FOREGROUND | FONT);
cairo_font_extents_t extents = new cairo_font_extents_t();
Cairo.cairo_font_extents(cairo, extents);
double baseline = y + extents.ascent;
Cairo.cairo_move_to(cairo, x, baseline);
byte[] buffer = Converter.wcsToMbcs(null, string, true);
Cairo.cairo_show_text(cairo, buffer);
Cairo.cairo_new_path(cairo);
return;
}
}
setString(string, flags);
if (cairo != 0) {
checkGC(FONT);
if ((flags & SWT.DRAW_TRANSPARENT) == 0) {
checkGC(BACKGROUND);
if (data.stringWidth == -1) {
computeStringSize();
}
Cairo.cairo_rectangle(cairo, x, y, data.stringWidth, data.stringHeight);
Cairo.cairo_fill(cairo);
}
checkGC(FOREGROUND);
if ((data.style & SWT.MIRRORED) != 0) {
Cairo.cairo_save(cairo);
if (data.stringWidth == -1) {
computeStringSize();
}
Cairo.cairo_scale(cairo, -1f, 1);
Cairo.cairo_translate(cairo, -2 * x - data.stringWidth, 0);
}
Cairo.cairo_move_to(cairo, x, y);
OS.pango_cairo_show_layout(cairo, data.layout);
if ((data.style & SWT.MIRRORED) != 0) {
Cairo.cairo_restore(cairo);
}
Cairo.cairo_new_path(cairo);
return;
}
checkGC(FOREGROUND | FONT | BACKGROUND_BG);
GdkColor background = null;
if ((flags & SWT.DRAW_TRANSPARENT) == 0) background = data.background;
if (!data.xorMode) {
OS.gdk_draw_layout_with_colors(data.drawable, handle, x, y, data.layout, null, background);
} else {
long /*int*/ layout = data.layout;
if (data.stringWidth == -1) {
computeStringSize();
}
long /*int*/ pixmap = OS.gdk_pixmap_new(OS.gdk_get_default_root_window(), data.stringWidth, data.stringHeight, -1);
if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
long /*int*/ gdkGC = OS.gdk_gc_new(pixmap);
if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
GdkColor black = new GdkColor();
OS.gdk_gc_set_foreground(gdkGC, black);
OS.gdk_draw_rectangle(pixmap, gdkGC, 1, 0, 0, data.stringWidth, data.stringHeight);
OS.gdk_gc_set_foreground(gdkGC, data.foreground);
OS.gdk_draw_layout_with_colors(pixmap, gdkGC, 0, 0, layout, null, background);
OS.g_object_unref(gdkGC);
OS.gdk_draw_drawable(data.drawable, handle, pixmap, 0, 0, x, y, data.stringWidth, data.stringHeight);
OS.g_object_unref(pixmap);
}
}
/**
* Compares the argument to the receiver, and returns true
* if they represent the same object using a class
* specific comparison.
*
* @param object the object to compare with this object
* @return true
if the object is the same as this object and false
otherwise
*
* @see #hashCode
*/
public boolean equals(Object object) {
if (object == this) return true;
if (!(object instanceof GC)) return false;
return handle == ((GC)object).handle;
}
/**
* Fills the interior of a circular or elliptical arc within
* the specified rectangular area, with the receiver's background
* color.
*
* The resulting arc begins at startAngle
and extends
* for arcAngle
degrees, using the current color.
* Angles are interpreted such that 0 degrees is at the 3 o'clock
* position. A positive value indicates a counter-clockwise rotation
* while a negative value indicates a clockwise rotation.
*
* The center of the arc is the center of the rectangle whose origin
* is (x
, y
) and whose size is specified by the
* width
and height
arguments.
*
* The resulting arc covers an area width + 1
pixels wide
* by height + 1
pixels tall.
*
*
* @param x the x coordinate of the upper-left corner of the arc to be filled
* @param y the y coordinate of the upper-left corner of the arc to be filled
* @param width the width of the arc to be filled
* @param height the height of the arc to be filled
* @param startAngle the beginning angle
* @param arcAngle the angular extent of the arc, relative to the start angle
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #drawArc
*/
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
checkGC(FILL);
if (width < 0) {
x = x + width;
width = -width;
}
if (height < 0) {
y = y + height;
height = -height;
}
if (width == 0 || height == 0 || arcAngle == 0) return;
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
if (width == height) {
if (arcAngle >= 0) {
Cairo.cairo_arc_negative(cairo, x + width / 2f, y + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
} else {
Cairo.cairo_arc(cairo, x + width / 2f, y + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
}
Cairo.cairo_line_to(cairo, x + width / 2f, y + height / 2f);
} else {
Cairo.cairo_save(cairo);
Cairo.cairo_translate(cairo, x + width / 2f, y + height / 2f);
Cairo.cairo_scale(cairo, width / 2f, height / 2f);
if (arcAngle >= 0) {
Cairo.cairo_arc_negative(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
} else {
Cairo.cairo_arc(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
}
Cairo.cairo_line_to(cairo, 0, 0);
Cairo.cairo_restore(cairo);
}
Cairo.cairo_fill(cairo);
return;
}
OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, startAngle * 64, arcAngle * 64);
}
/**
* Fills the interior of the specified rectangle with a gradient
* sweeping from left to right or top to bottom progressing
* from the receiver's foreground color to its background color.
*
* @param x the x coordinate of the rectangle to be filled
* @param y the y coordinate of the rectangle to be filled
* @param width the width of the rectangle to be filled, may be negative
* (inverts direction of gradient if horizontal)
* @param height the height of the rectangle to be filled, may be negative
* (inverts direction of gradient if vertical)
* @param vertical if true sweeps from top to bottom, else
* sweeps from left to right
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #drawRectangle(int, int, int, int)
*/
public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if ((width == 0) || (height == 0)) return;
/* Rewrite this to use GdkPixbuf */
RGB backgroundRGB, foregroundRGB;
backgroundRGB = getBackground().getRGB();
foregroundRGB = getForeground().getRGB();
RGB fromRGB, toRGB;
fromRGB = foregroundRGB;
toRGB = backgroundRGB;
boolean swapColors = false;
if (width < 0) {
x += width; width = -width;
if (! vertical) swapColors = true;
}
if (height < 0) {
y += height; height = -height;
if (vertical) swapColors = true;
}
if (swapColors) {
fromRGB = backgroundRGB;
toRGB = foregroundRGB;
}
if (fromRGB.equals(toRGB)) {
fillRectangle(x, y, width, height);
return;
}
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
long /*int*/ pattern;
if (vertical) {
pattern = Cairo.cairo_pattern_create_linear (0.0, 0.0, 0.0, 1.0);
} else {
pattern = Cairo.cairo_pattern_create_linear (0.0, 0.0, 1.0, 0.0);
}
Cairo.cairo_pattern_add_color_stop_rgba (pattern, 0, fromRGB.red / 255f, fromRGB.green / 255f, fromRGB.blue / 255f, data.alpha / 255f);
Cairo.cairo_pattern_add_color_stop_rgba (pattern, 1, toRGB.red / 255f, toRGB.green / 255f, toRGB.blue / 255f, data.alpha / 255f);
Cairo.cairo_save(cairo);
Cairo.cairo_translate(cairo, x, y);
Cairo.cairo_scale(cairo, width, height);
Cairo.cairo_rectangle(cairo, 0, 0, 1, 1);
Cairo.cairo_set_source(cairo, pattern);
Cairo.cairo_fill(cairo);
Cairo.cairo_restore(cairo);
Cairo.cairo_pattern_destroy(pattern);
return;
}
ImageData.fillGradientRectangle(this, data.device,
x, y, width, height, vertical, fromRGB, toRGB,
8, 8, 8);
}
/**
* Fills the interior of an oval, within the specified
* rectangular area, with the receiver's background
* color.
*
* @param x the x coordinate of the upper left corner of the oval to be filled
* @param y the y coordinate of the upper left corner of the oval to be filled
* @param width the width of the oval to be filled
* @param height the height of the oval to be filled
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #drawOval
*/
public void fillOval(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
checkGC(FILL);
if (width < 0) {
x = x + width;
width = -width;
}
if (height < 0) {
y = y + height;
height = -height;
}
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
if (width == height) {
Cairo.cairo_arc_negative(cairo, x + width / 2f, y + height / 2f, width / 2f, 0, 2 * (float)Compatibility.PI);
} else {
Cairo.cairo_save(cairo);
Cairo.cairo_translate(cairo, x + width / 2f, y + height / 2f);
Cairo.cairo_scale(cairo, width / 2f, height / 2f);
Cairo.cairo_arc_negative(cairo, 0, 0, 1, 0, 2 * (float)Compatibility.PI);
Cairo.cairo_restore(cairo);
}
Cairo.cairo_fill(cairo);
return;
}
OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, 0, 23040);
}
/**
* Fills the path described by the parameter.
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
*
* @param path the path to fill
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the parameter is null
* - ERROR_INVALID_ARGUMENT - if the parameter has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see Path
*
* @since 3.1
*/
public void fillPath (Path path) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
initCairo();
checkGC(FILL);
long /*int*/ cairo = data.cairo;
long /*int*/ copy = Cairo.cairo_copy_path(path.handle);
if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
Cairo.cairo_append_path(cairo, copy);
Cairo.cairo_path_destroy(copy);
Cairo.cairo_fill(cairo);
}
/**
* Fills the interior of the closed polygon which is defined by the
* specified array of integer coordinates, using the receiver's
* background color. The array contains alternating x and y values
* which are considered to represent points which are the vertices of
* the polygon. Lines are drawn between each consecutive pair, and
* between the first pair and last pair in the array.
*
* @param pointArray an array of alternating x and y values which are the vertices of the polygon
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT if pointArray is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #drawPolygon
*/
public void fillPolygon(int[] pointArray) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
checkGC(FILL);
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
drawPolyline(cairo, pointArray, true);
Cairo.cairo_fill(cairo);
return;
}
OS.gdk_draw_polygon(data.drawable, handle, 1, pointArray, pointArray.length / 2);
}
/**
* Fills the interior of the rectangle specified by the arguments,
* using the receiver's background color.
*
* @param x the x coordinate of the rectangle to be filled
* @param y the y coordinate of the rectangle to be filled
* @param width the width of the rectangle to be filled
* @param height the height of the rectangle to be filled
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #drawRectangle(int, int, int, int)
*/
public void fillRectangle(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
checkGC(FILL);
if (width < 0) {
x = x + width;
width = -width;
}
if (height < 0) {
y = y + height;
height = -height;
}
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
Cairo.cairo_rectangle(cairo, x, y, width, height);
Cairo.cairo_fill(cairo);
return;
}
OS.gdk_draw_rectangle(data.drawable, handle, 1, x, y, width, height);
}
/**
* Fills the interior of the specified rectangle, using the receiver's
* background color.
*
* @param rect the rectangle to be filled
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the rectangle is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #drawRectangle(int, int, int, int)
*/
public void fillRectangle(Rectangle rect) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
fillRectangle(rect.x, rect.y, rect.width, rect.height);
}
/**
* Fills the interior of the round-cornered rectangle specified by
* the arguments, using the receiver's background color.
*
* @param x the x coordinate of the rectangle to be filled
* @param y the y coordinate of the rectangle to be filled
* @param width the width of the rectangle to be filled
* @param height the height of the rectangle to be filled
* @param arcWidth the width of the arc
* @param arcHeight the height of the arc
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #drawRoundRectangle
*/
public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
checkGC(FILL);
int nx = x;
int ny = y;
int nw = width;
int nh = height;
int naw = arcWidth;
int nah = arcHeight;
if (nw < 0) {
nw = 0 - nw;
nx = nx - nw;
}
if (nh < 0) {
nh = 0 - nh;
ny = ny -nh;
}
if (naw < 0) naw = 0 - naw;
if (nah < 0) nah = 0 - nah;
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
if (naw == 0 || nah == 0) {
Cairo.cairo_rectangle(cairo, x, y, width, height);
} else {
float naw2 = naw / 2f;
float nah2 = nah / 2f;
float fw = nw / naw2;
float fh = nh / nah2;
Cairo.cairo_save(cairo);
Cairo.cairo_translate(cairo, nx, ny);
Cairo.cairo_scale(cairo, naw2, nah2);
Cairo.cairo_move_to(cairo, fw - 1, 0);
Cairo.cairo_arc(cairo, fw - 1, 1, 1, Compatibility.PI + Compatibility.PI/2.0, Compatibility.PI*2.0);
Cairo.cairo_arc(cairo, fw - 1, fh - 1, 1, 0, Compatibility.PI/2.0);
Cairo.cairo_arc(cairo, 1, fh - 1, 1, Compatibility.PI/2, Compatibility.PI);
Cairo.cairo_arc(cairo, 1, 1, 1, Compatibility.PI, 270.0*Compatibility.PI/180.0);
Cairo.cairo_close_path(cairo);
Cairo.cairo_restore(cairo);
}
Cairo.cairo_fill(cairo);
return;
}
int naw2 = naw / 2;
int nah2 = nah / 2;
long /*int*/ drawable = data.drawable;
if (nw > naw) {
if (nh > nah) {
OS.gdk_draw_arc(drawable, handle, 1, nx, ny, naw, nah, 5760, 5760);
OS.gdk_draw_rectangle(drawable, handle, 1, nx + naw2, ny, nw - naw2 * 2, nh);
OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny, naw, nah, 0, 5760);
OS.gdk_draw_rectangle(drawable, handle, 1, nx, ny + nah2, naw2, nh - nah2 * 2);
OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
OS.gdk_draw_rectangle(drawable, handle, 1, nx + nw - naw2, ny + nah2, naw2, nh - nah2 * 2);
OS.gdk_draw_arc(drawable, handle, 1, nx, ny + nh - nah, naw, nah, 11520, 5760);
} else {
OS.gdk_draw_arc(drawable, handle, 1, nx, ny, naw, nh, 5760, 11520);
OS.gdk_draw_rectangle(drawable, handle, 1, nx + naw2, ny, nw - naw2 * 2, nh);
OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny, naw, nh, 17280, 11520);
}
} else {
if (nh > nah) {
OS.gdk_draw_arc(drawable, handle, 1, nx, ny, nw, nah, 0, 11520);
OS.gdk_draw_rectangle(drawable, handle, 1, nx, ny + nah2, nw, nh - nah2 * 2);
OS.gdk_draw_arc(drawable, handle, 1, nx, ny + nh - nah, nw, nah, 11520, 11520);
} else {
OS.gdk_draw_arc(drawable, handle, 1, nx, ny, nw, nh, 0, 23040);
}
}
}
int fixMnemonic (char [] buffer) {
int i=0, j=0;
int mnemonic=-1;
while (i < buffer.length) {
if ((buffer [j++] = buffer [i++]) == '&') {
if (i == buffer.length) {continue;}
if (buffer [i] == '&') {i++; continue;}
if (mnemonic == -1) mnemonic = j;
j--;
}
}
while (j < buffer.length) buffer [j++] = 0;
return mnemonic;
}
/**
* Returns the advance width of the specified character in
* the font which is currently selected into the receiver.
*
* The advance width is defined as the horizontal distance the cursor
* should move after printing the character in the selected font.
*
*
* @param ch the character to measure
* @return the distance in the x direction to move past the character before painting the next
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public int getAdvanceWidth(char ch) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
//BOGUS
return stringExtent(new String(new char[]{ch})).x;
}
/**
* Returns true
if receiver is using the operating system's
* advanced graphics subsystem. Otherwise, false
is returned
* to indicate that normal graphics are in use.
*
* Advanced graphics may not be installed for the operating system. In this
* case, false
is always returned. Some operating system have
* only one graphics subsystem. If this subsystem supports advanced graphics,
* then true
is always returned. If any graphics operation such
* as alpha, antialias, patterns, interpolation, paths, clipping or transformation
* has caused the receiver to switch from regular to advanced graphics mode,
* true
is returned. If the receiver has been explicitly switched
* to advanced mode and this mode is supported, true
is returned.
*
*
* @return the advanced value
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #setAdvanced
*
* @since 3.1
*/
public boolean getAdvanced() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.cairo != 0;
}
/**
* Returns the receiver's alpha value. The alpha value
* is between 0 (transparent) and 255 (opaque).
*
* @return the alpha value
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.1
*/
public int getAlpha() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.alpha;
}
/**
* Returns the receiver's anti-aliasing setting value, which will be
* one of SWT.DEFAULT
, SWT.OFF
or
* SWT.ON
. Note that this controls anti-aliasing for all
* non-text drawing operations.
*
* @return the anti-aliasing setting
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #getTextAntialias
*
* @since 3.1
*/
public int getAntialias() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.cairo == 0) return SWT.DEFAULT;
int antialias = Cairo.cairo_get_antialias(data.cairo);
switch (antialias) {
case Cairo.CAIRO_ANTIALIAS_DEFAULT: return SWT.DEFAULT;
case Cairo.CAIRO_ANTIALIAS_NONE: return SWT.OFF;
case Cairo.CAIRO_ANTIALIAS_GRAY:
case Cairo.CAIRO_ANTIALIAS_SUBPIXEL: return SWT.ON;
}
return SWT.DEFAULT;
}
/**
* Returns the background color.
*
* @return the receiver's background color
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public Color getBackground() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return Color.gtk_new(data.device, data.background);
}
/**
* Returns the background pattern. The default value is
* null
.
*
* @return the receiver's background pattern
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see Pattern
*
* @since 3.1
*/
public Pattern getBackgroundPattern() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.backgroundPattern;
}
/**
* Returns the width of the specified character in the font
* selected into the receiver.
*
* The width is defined as the space taken up by the actual
* character, not including the leading and tailing whitespace
* or overhang.
*
*
* @param ch the character to measure
* @return the width of the character
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public int getCharWidth(char ch) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
//BOGUS
return stringExtent(new String(new char[]{ch})).x;
}
/**
* Returns the bounding rectangle of the receiver's clipping
* region. If no clipping region is set, the return value
* will be a rectangle which covers the entire bounds of the
* object the receiver is drawing on.
*
* @return the bounding rectangle of the clipping region
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public Rectangle getClipping() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
/* Calculate visible bounds in device space */
int x = 0, y = 0, width = 0, height = 0;
int[] w = new int[1], h = new int[1];
getSize(w, h);
width = w[0];
height = h[0];
/* Intersect visible bounds with clipping in device space and then convert then to user space */
long /*int*/ cairo = data.cairo;
long /*int*/ clipRgn = data.clipRgn;
long /*int*/ damageRgn = data.damageRgn;
long /*int*/ rgn = 0;
if (clipRgn != 0 || damageRgn != 0 || cairo != 0) {
if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
rgn = Cairo.cairo_region_create ();
cairo_rectangle_int_t rect = new cairo_rectangle_int_t ();
rect.width = width;
rect.height = height;
Cairo.cairo_region_union_rectangle (rgn, rect);
if (damageRgn != 0) {
Cairo.cairo_region_intersect (rgn, damageRgn);
}
/* Intersect visible bounds with clipping */
if (clipRgn != 0) {
/* Convert clipping to device space if needed */
if (data.clippingTransform != null) {
clipRgn = convertRgn(clipRgn, data.clippingTransform);
Cairo.cairo_region_intersect (rgn, clipRgn);
Cairo.cairo_region_destroy (clipRgn);
} else {
Cairo.cairo_region_intersect (rgn, clipRgn);
}
}
/* Convert to user space */
if (cairo != 0) {
double[] matrix = new double[6];
Cairo.cairo_get_matrix(cairo, matrix);
Cairo.cairo_matrix_invert(matrix);
clipRgn = convertRgn(rgn, matrix);
cairo_region_destroy (rgn);
rgn = clipRgn;
}
Cairo.cairo_region_get_extents (rgn, rect);
cairo_region_destroy (rgn);
x = rect.x;
y = rect.y;
width = rect.width;
height = rect.height;
} else {
rgn = OS.gdk_region_new ();
GdkRectangle rect = new GdkRectangle();
rect.width = width;
rect.height = height;
OS.gdk_region_union_with_rect(rgn, rect);
if (damageRgn != 0) {
OS.gdk_region_intersect (rgn, damageRgn);
}
/* Intersect visible bounds with clipping */
if (clipRgn != 0) {
/* Convert clipping to device space if needed */
if (data.clippingTransform != null) {
clipRgn = convertRgn(clipRgn, data.clippingTransform);
OS.gdk_region_intersect (rgn, clipRgn);
OS.gdk_region_destroy (clipRgn);
} else {
OS.gdk_region_intersect (rgn, clipRgn);
}
}
/* Convert to user space */
if (cairo != 0) {
double[] matrix = new double[6];
Cairo.cairo_get_matrix(cairo, matrix);
Cairo.cairo_matrix_invert(matrix);
clipRgn = convertRgn(rgn, matrix);
cairo_region_destroy (rgn);
rgn = clipRgn;
}
OS.gdk_region_get_clipbox(rgn, rect);
OS.gdk_region_destroy (rgn);
x = rect.x;
y = rect.y;
width = rect.width;
height = rect.height;
}
}
return new Rectangle(x, y, width, height);
}
/**
* Sets the region managed by the argument to the current
* clipping region of the receiver.
*
* @param region the region to fill with the clipping region
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the region is null
* - ERROR_INVALID_ARGUMENT - if the region is disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void getClipping(Region region) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
long /*int*/ clipping = region.handle;
cairo_region_subtract (clipping, clipping);
long /*int*/ cairo = data.cairo;
long /*int*/ clipRgn = data.clipRgn;
if (clipRgn == 0) {
if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
cairo_rectangle_int_t rect = new cairo_rectangle_int_t ();
int[] width = new int[1], height = new int[1];
getSize(width, height);
rect.width = width[0];
rect.height = height[0];
Cairo.cairo_region_union_rectangle (clipping, rect);
} else {
GdkRectangle rect = new GdkRectangle();
int[] width = new int[1], height = new int[1];
getSize(width, height);
rect.width = width[0];
rect.height = height[0];
OS.gdk_region_union_with_rect(clipping, rect);
}
} else {
/* Convert clipping to device space if needed */
if (data.clippingTransform != null) {
long /*int*/ rgn = convertRgn(clipRgn, data.clippingTransform);
cairo_region_union (clipping, rgn);
cairo_region_destroy (rgn);
} else {
cairo_region_union (clipping, clipRgn);
}
}
if (data.damageRgn != 0) {
cairo_region_intersect (clipping, data.damageRgn);
}
/* Convert to user space */
if (cairo != 0) {
double[] matrix = new double[6];
Cairo.cairo_get_matrix(cairo, matrix);
Cairo.cairo_matrix_invert(matrix);
long /*int*/ rgn = convertRgn(clipping, matrix);
cairo_region_subtract (clipping, clipping);
cairo_region_union (clipping, rgn);
cairo_region_destroy (rgn);
}
}
/**
* Returns the receiver's fill rule, which will be one of
* SWT.FILL_EVEN_ODD
or SWT.FILL_WINDING
.
*
* @return the receiver's fill rule
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.1
*/
public int getFillRule() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
long /*int*/ cairo = data.cairo;
if (cairo == 0) return SWT.FILL_EVEN_ODD;
return Cairo.cairo_get_fill_rule(cairo) == Cairo.CAIRO_FILL_RULE_WINDING ? SWT.FILL_WINDING : SWT.FILL_EVEN_ODD;
}
/**
* Returns the font currently being used by the receiver
* to draw and measure text.
*
* @return the receiver's font
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public Font getFont() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.font;
}
/**
* Returns a FontMetrics which contains information
* about the font currently being used by the receiver
* to draw and measure text.
*
* @return font metrics for the receiver's font
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public FontMetrics getFontMetrics() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.context == 0) createLayout();
checkGC(FONT);
Font font = data.font;
long /*int*/ context = data.context;
long /*int*/ lang = OS.pango_context_get_language(context);
long /*int*/ metrics = OS.pango_context_get_metrics(context, font.handle, lang);
FontMetrics fm = new FontMetrics();
fm.ascent = OS.PANGO_PIXELS(OS.pango_font_metrics_get_ascent(metrics));
fm.descent = OS.PANGO_PIXELS(OS.pango_font_metrics_get_descent(metrics));
fm.averageCharWidth = OS.PANGO_PIXELS(OS.pango_font_metrics_get_approximate_char_width(metrics));
fm.height = fm.ascent + fm.descent;
OS.pango_font_metrics_unref(metrics);
return fm;
}
/**
* Returns the receiver's foreground color.
*
* @return the color used for drawing foreground things
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public Color getForeground() {
if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
return Color.gtk_new(data.device, data.foreground);
}
/**
* Returns the foreground pattern. The default value is
* null
.
*
* @return the receiver's foreground pattern
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see Pattern
*
* @since 3.1
*/
public Pattern getForegroundPattern() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.foregroundPattern;
}
/**
* Returns the GCData.
*
* IMPORTANT: This method is not part of the public
* API for GC
. It is marked public only so that it
* can be shared within the packages provided by SWT. It is not
* available on all platforms, and should never be called from
* application code.
*
*
* @return the receiver's GCData
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see GCData
*
* @noreference This method is not intended to be referenced by clients.
*
* @since 3.2
*/
public GCData getGCData() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data;
}
/**
* Returns the receiver's interpolation setting, which will be one of
* SWT.DEFAULT
, SWT.NONE
,
* SWT.LOW
or SWT.HIGH
.
*
* @return the receiver's interpolation setting
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.1
*/
public int getInterpolation() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.interpolation;
}
/**
* Returns the receiver's line attributes.
*
* @return the line attributes used for drawing lines
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.3
*/
public LineAttributes getLineAttributes() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
float[] dashes = null;
if (data.lineDashes != null) {
dashes = new float[data.lineDashes.length];
System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length);
}
return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit);
}
/**
* Returns the receiver's line cap style, which will be one
* of the constants SWT.CAP_FLAT
, SWT.CAP_ROUND
,
* or SWT.CAP_SQUARE
.
*
* @return the cap style used for drawing lines
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.1
*/
public int getLineCap() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.lineCap;
}
/**
* Returns the receiver's line dash style. The default value is
* null
.
*
* @return the line dash style used for drawing lines
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.1
*/
public int[] getLineDash() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.lineDashes == null) return null;
int[] lineDashes = new int[data.lineDashes.length];
for (int i = 0; i < lineDashes.length; i++) {
lineDashes[i] = (int)data.lineDashes[i];
}
return lineDashes;
}
/**
* Returns the receiver's line join style, which will be one
* of the constants SWT.JOIN_MITER
, SWT.JOIN_ROUND
,
* or SWT.JOIN_BEVEL
.
*
* @return the join style used for drawing lines
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.1
*/
public int getLineJoin() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.lineJoin;
}
/**
* Returns the receiver's line style, which will be one
* of the constants SWT.LINE_SOLID
, SWT.LINE_DASH
,
* SWT.LINE_DOT
, SWT.LINE_DASHDOT
or
* SWT.LINE_DASHDOTDOT
.
*
* @return the style used for drawing lines
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public int getLineStyle() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.lineStyle;
}
/**
* Returns the width that will be used when drawing lines
* for all of the figure drawing operations (that is,
* drawLine
, drawRectangle
,
* drawPolyline
, and so forth.
*
* @return the receiver's line width
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public int getLineWidth() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return (int)data.lineWidth;
}
/**
* Returns the receiver's style information.
*
* Note that the value which is returned by this method may
* not match the value which was provided to the constructor
* when the receiver was created. This can occur when the underlying
* operating system does not support a particular combination of
* requested styles.
*
*
* @return the style bits
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 2.1.2
*/
public int getStyle () {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.style;
}
void getSize(int[] width, int[] height) {
if (data.width != -1 && data.height != -1) {
width[0] = data.width;
height[0] = data.height;
return;
}
if (data.drawable != 0) {
if (OS.GTK_VERSION >= OS.VERSION(2, 24, 0)) {
width[0] = OS.gdk_window_get_width(data.drawable);
height[0] = OS.gdk_window_get_height(data.drawable);
} else {
OS.gdk_drawable_get_size(data.drawable, width, height);
}
return;
}
if (OS.USE_CAIRO) {
long /*int*/ surface = Cairo.cairo_get_target(handle);
switch (Cairo.cairo_surface_get_type(surface)) {
case Cairo.CAIRO_SURFACE_TYPE_IMAGE:
width[0] = Cairo.cairo_image_surface_get_width(surface);
height[0] = Cairo.cairo_image_surface_get_height(surface);
break;
case Cairo.CAIRO_SURFACE_TYPE_XLIB:
width[0] = Cairo.cairo_xlib_surface_get_width(surface);
height[0] = Cairo.cairo_xlib_surface_get_height(surface);
break;
}
}
}
/**
* Returns the receiver's text drawing anti-aliasing setting value,
* which will be one of SWT.DEFAULT
, SWT.OFF
or
* SWT.ON
. Note that this controls anti-aliasing
* only for text drawing operations.
*
* @return the anti-aliasing setting
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #getAntialias
*
* @since 3.1
*/
public int getTextAntialias() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.cairo == 0) return SWT.DEFAULT;
int antialias = Cairo.CAIRO_ANTIALIAS_DEFAULT;
if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
long /*int*/ options = Cairo.cairo_font_options_create();
Cairo.cairo_get_font_options(data.cairo, options);
antialias = Cairo.cairo_font_options_get_antialias(options);
Cairo.cairo_font_options_destroy(options);
} else {
if (data.context != 0) {
long /*int*/ options = OS.pango_cairo_context_get_font_options(data.context);
if (options != 0) antialias = Cairo.cairo_font_options_get_antialias(options);
}
}
switch (antialias) {
case Cairo.CAIRO_ANTIALIAS_DEFAULT: return SWT.DEFAULT;
case Cairo.CAIRO_ANTIALIAS_NONE: return SWT.OFF;
case Cairo.CAIRO_ANTIALIAS_GRAY:
case Cairo.CAIRO_ANTIALIAS_SUBPIXEL: return SWT.ON;
}
return SWT.DEFAULT;
}
/**
* Sets the parameter to the transform that is currently being
* used by the receiver.
*
* @param transform the destination to copy the transform into
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the parameter is null
* - ERROR_INVALID_ARGUMENT - if the parameter has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see Transform
*
* @since 3.1
*/
public void getTransform(Transform transform) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (transform == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
Cairo.cairo_get_matrix(cairo, transform.handle);
double[] identity = identity();
Cairo.cairo_matrix_invert(identity);
Cairo.cairo_matrix_multiply(transform.handle, transform.handle, identity);
} else {
transform.setElements(1, 0, 0, 1, 0, 0);
}
}
/**
* Returns true
if this GC is drawing in the mode
* where the resulting color in the destination is the
* exclusive or of the color values in the source
* and the destination, and false
if it is
* drawing in the mode where the destination color is being
* replaced with the source color value.
*
* @return true
true if the receiver is in XOR mode, and false otherwise
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public boolean getXORMode() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.xorMode;
}
/**
* Returns an integer hash code for the receiver. Any two
* objects that return true
when passed to
* equals
must return the same value for this
* method.
*
* @return the receiver's hash
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #equals
*/
public int hashCode() {
return (int)/*64*/handle;
}
double[] identity() {
double[] identity = new double[6];
if ((data.style & SWT.MIRRORED) != 0) {
int[] w = new int[1], h = new int[1];
getSize(w, h);
Cairo.cairo_matrix_init(identity, -1, 0, 0, 1, w[0], 0);
} else {
Cairo.cairo_matrix_init_identity(identity);
}
if (data.identity != null) {
Cairo.cairo_matrix_multiply(identity, data.identity, identity);
}
return identity;
}
void init(Drawable drawable, GCData data, long /*int*/ gdkGC) {
if (data.foreground != null) data.state &= ~FOREGROUND;
if (data.background != null) data.state &= ~(BACKGROUND | BACKGROUND_BG);
if (data.font != null) data.state &= ~FONT;
Image image = data.image;
if (image != null) {
image.memGC = this;
/*
* The transparent pixel mask might change when drawing on
* the image. Destroy it so that it is regenerated when
* necessary.
*/
if (image.transparentPixel != -1) image.destroyMask();
}
this.drawable = drawable;
this.data = data;
handle = gdkGC;
if (OS.USE_CAIRO) {
long /*int*/ cairo = data.cairo = handle;
Cairo.cairo_set_fill_rule(cairo, Cairo.CAIRO_FILL_RULE_EVEN_ODD);
data.state &= ~(BACKGROUND | FOREGROUND | FONT | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_STYLE | DRAW_OFFSET);
} else if (OS.INIT_CAIRO) {
initCairo();
}
setClipping(data.clipRgn);
if ((data.style & SWT.MIRRORED) != 0) {
initCairo();
long /*int*/ cairo = data.cairo;
Cairo.cairo_set_matrix(cairo, identity());
}
}
void initCairo() {
data.device.checkCairo();
long /*int*/ cairo = data.cairo;
if (cairo != 0) return;
if (OS.GTK_VERSION < OS.VERSION(2, 17, 0)) {
long /*int*/ xDisplay = OS.gdk_x11_display_get_xdisplay(OS.gdk_display_get_default());
long /*int*/ xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system());
long /*int*/ xDrawable = 0;
int translateX = 0, translateY = 0;
long /*int*/ drawable = data.drawable;
if (data.image != null) {
xDrawable = OS.GDK_PIXMAP_XID(drawable);
} else {
if (!data.realDrawable) {
int[] x = new int[1], y = new int[1];
long /*int*/ [] real_drawable = new long /*int*/ [1];
OS.gdk_window_get_internal_paint_info(drawable, real_drawable, x, y);
xDrawable = OS.gdk_x11_drawable_get_xid(real_drawable[0]);
translateX = -x[0];
translateY = -y[0];
}
}
int width = 0;
int height = 0;
if (OS.GTK_VERSION >= OS.VERSION(2, 24, 0)) {
width = OS.gdk_window_get_width(data.drawable);
height = OS.gdk_window_get_height(data.drawable);
} else {
int[] w = new int[1], h = new int[1];
OS.gdk_drawable_get_size(drawable, w, h);
width = w[0];
height = h[0];
}
long /*int*/ surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width, height);
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
Cairo.cairo_surface_set_device_offset(surface, translateX, translateY);
data.cairo = cairo = Cairo.cairo_create(surface);
Cairo.cairo_surface_destroy(surface);
} else {
data.cairo = cairo = OS.gdk_cairo_create(data.drawable);
}
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
data.disposeCairo = true;
Cairo.cairo_set_fill_rule(cairo, Cairo.CAIRO_FILL_RULE_EVEN_ODD);
data.state &= ~(BACKGROUND | FOREGROUND | FONT | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_STYLE | DRAW_OFFSET);
setCairoClip(data.damageRgn, data.clipRgn);
}
void computeStringSize() {
int[] width = new int[1], height = new int[1];
OS.pango_layout_get_size(data.layout, width, height);
data.stringHeight = OS.PANGO_PIXELS(height[0]);
data.stringWidth = OS.PANGO_PIXELS(width[0]);
}
/**
* Returns true
if the receiver has a clipping
* region set into it, and false
otherwise.
* If this method returns false, the receiver will draw on all
* available space in the destination. If it returns true,
* it will draw only in the area that is covered by the region
* that can be accessed with getClipping(region)
.
*
* @return true
if the GC has a clipping region, and false
otherwise
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public boolean isClipped() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return data.clipRgn != 0;
}
/**
* Returns true
if the GC has been disposed,
* and false
otherwise.
*
* This method gets the dispose state for the GC.
* When a GC has been disposed, it is an error to
* invoke any other method (except {@link #dispose()}) using the GC.
*
* @return true
when the GC is disposed and false
otherwise
*/
public boolean isDisposed() {
return handle == 0;
}
boolean isIdentity(double[] matrix) {
if (matrix == null) return true;
return matrix[0] == 1 && matrix[1] == 0 && matrix[2] == 0 && matrix[3] == 1 && matrix[4] == 0 && matrix[5] == 0;
}
/**
* Sets the receiver to always use the operating system's advanced graphics
* subsystem for all graphics operations if the argument is true
.
* If the argument is false
, the advanced graphics subsystem is
* no longer used, advanced graphics state is cleared and the normal graphics
* subsystem is used from now on.
*
* Normally, the advanced graphics subsystem is invoked automatically when
* any one of the alpha, antialias, patterns, interpolation, paths, clipping
* or transformation operations in the receiver is requested. When the receiver
* is switched into advanced mode, the advanced graphics subsystem performs both
* advanced and normal graphics operations. Because the two subsystems are
* different, their output may differ. Switching to advanced graphics before
* any graphics operations are performed ensures that the output is consistent.
*
* Advanced graphics may not be installed for the operating system. In this
* case, this operation does nothing. Some operating system have only one
* graphics subsystem, so switching from normal to advanced graphics does
* nothing. However, switching from advanced to normal graphics will always
* clear the advanced graphics state, even for operating systems that have
* only one graphics subsystem.
*
*
* @param advanced the new advanced graphics state
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @see #setAlpha
* @see #setAntialias
* @see #setBackgroundPattern
* @see #setClipping(Path)
* @see #setForegroundPattern
* @see #setLineAttributes
* @see #setInterpolation
* @see #setTextAntialias
* @see #setTransform
* @see #getAdvanced
*
* @since 3.1
*/
public void setAdvanced(boolean advanced) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if ((data.style & SWT.MIRRORED) != 0 || OS.USE_CAIRO || OS.INIT_CAIRO) {
if (!advanced) {
setAlpha(0xFF);
setAntialias(SWT.DEFAULT);
setBackgroundPattern(null);
setClipping(0);
setForegroundPattern(null);
setInterpolation(SWT.DEFAULT);
setTextAntialias(SWT.DEFAULT);
setTransform(null);
}
return;
}
if (advanced && data.cairo != 0) return;
if (advanced) {
try {
initCairo();
} catch (SWTException e) {}
} else {
if (!data.disposeCairo) return;
long /*int*/ cairo = data.cairo;
if (cairo != 0) Cairo.cairo_destroy(cairo);
data.cairo = 0;
data.interpolation = SWT.DEFAULT;
data.alpha = 0xFF;
data.backgroundPattern = data.foregroundPattern = null;
data.state = 0;
setClipping(0);
}
}
/**
* Sets the receiver's alpha value which must be
* between 0 (transparent) and 255 (opaque).
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
* @param alpha the alpha value
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see #getAdvanced
* @see #setAdvanced
*
* @since 3.1
*/
public void setAlpha(int alpha) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.cairo == 0 && (alpha & 0xff) == 0xff) return;
initCairo();
data.alpha = alpha & 0xff;
data.state &= ~(BACKGROUND | FOREGROUND | BACKGROUND_BG);
}
/**
* Sets the receiver's anti-aliasing value to the parameter,
* which must be one of SWT.DEFAULT
, SWT.OFF
* or SWT.ON
. Note that this controls anti-aliasing for all
* non-text drawing operations.
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
*
* @param antialias the anti-aliasing setting
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the parameter is not one of
SWT.DEFAULT
,
* SWT.OFF
or SWT.ON
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see #getAdvanced
* @see #setAdvanced
* @see #setTextAntialias
*
* @since 3.1
*/
public void setAntialias(int antialias) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.cairo == 0 && antialias == SWT.DEFAULT) return;
int mode = 0;
switch (antialias) {
case SWT.DEFAULT: mode = Cairo.CAIRO_ANTIALIAS_DEFAULT; break;
case SWT.OFF: mode = Cairo.CAIRO_ANTIALIAS_NONE; break;
case SWT.ON: mode = Cairo.CAIRO_ANTIALIAS_GRAY;
break;
default:
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
initCairo();
long /*int*/ cairo = data.cairo;
Cairo.cairo_set_antialias(cairo, mode);
}
/**
* Sets the background color. The background color is used
* for fill operations and as the background color when text
* is drawn.
*
* @param color the new background color for the receiver
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the color is null
* - ERROR_INVALID_ARGUMENT - if the color has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void setBackground(Color color) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
data.background = color.handle;
data.backgroundPattern = null;
data.state &= ~(BACKGROUND | BACKGROUND_BG);
}
/**
* Sets the background pattern. The default value is null
.
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
*
* @param pattern the new background pattern
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the parameter has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see Pattern
* @see #getAdvanced
* @see #setAdvanced
*
* @since 3.1
*/
public void setBackgroundPattern(Pattern pattern) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
if (data.cairo == 0 && pattern == null) return;
initCairo();
if (data.backgroundPattern == pattern) return;
data.backgroundPattern = pattern;
data.state &= ~BACKGROUND;
}
static void setCairoFont(long /*int*/ cairo, Font font) {
if (font == null || font.isDisposed()) return;
setCairoFont(cairo, font.handle);
}
static void setCairoFont(long /*int*/ cairo, long /*int*/ font) {
long /*int*/ family = OS.pango_font_description_get_family(font);
int length = OS.strlen(family);
byte[] buffer = new byte[length + 1];
OS.memmove(buffer, family, length);
//TODO - convert font height from pango to cairo
double height = OS.PANGO_PIXELS(OS.pango_font_description_get_size(font)) * 96 / 72;
int pangoStyle = OS.pango_font_description_get_style(font);
int pangoWeight = OS.pango_font_description_get_weight(font);
int slant = Cairo.CAIRO_FONT_SLANT_NORMAL;
if (pangoStyle == OS.PANGO_STYLE_ITALIC) slant = Cairo.CAIRO_FONT_SLANT_ITALIC;
if (pangoStyle == OS.PANGO_STYLE_OBLIQUE) slant = Cairo.CAIRO_FONT_SLANT_OBLIQUE;
int weight = Cairo.CAIRO_FONT_WEIGHT_NORMAL;
if (pangoWeight == OS.PANGO_WEIGHT_BOLD) weight = Cairo.CAIRO_FONT_WEIGHT_BOLD;
Cairo.cairo_select_font_face(cairo, buffer, slant, weight);
Cairo.cairo_set_font_size(cairo, height);
}
static void setCairoRegion(long /*int*/ cairo, long /*int*/ rgn) {
if (OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
OS.gdk_cairo_region(cairo, rgn);
} else {
int[] nRects = new int[1];
long /*int*/[] rects = new long /*int*/[1];
OS.gdk_region_get_rectangles(rgn, rects, nRects);
GdkRectangle rect = new GdkRectangle();
for (int i=0; i= OS.VERSION(2,18,0) && data.drawable != 0) {
OS.gdk_cairo_reset_clip(cairo, data.drawable);
} else {
Cairo.cairo_reset_clip(cairo);
}
if (damageRgn != 0) {
double[] matrix = new double[6];
Cairo.cairo_get_matrix(cairo, matrix);
double[] identity = new double[6];
Cairo.cairo_matrix_init_identity(identity);
Cairo.cairo_set_matrix(cairo, identity);
setCairoRegion(cairo, damageRgn);
Cairo.cairo_clip(cairo);
Cairo.cairo_set_matrix(cairo, matrix);
}
if (clipRgn != 0) {
setCairoRegion(cairo, clipRgn);
Cairo.cairo_clip(cairo);
}
}
void setClipping(long /*int*/ clipRgn) {
long /*int*/ cairo = data.cairo;
if (clipRgn == 0) {
if (data.clipRgn != 0) {
cairo_region_destroy (data.clipRgn);
data.clipRgn = 0;
}
if (cairo != 0) {
data.clippingTransform = null;
setCairoClip(data.damageRgn, 0);
} else {
long /*int*/ clipping = data.damageRgn != 0 ? data.damageRgn : 0;
OS.gdk_gc_set_clip_region(handle, clipping);
}
} else {
if (data.clipRgn == 0) data.clipRgn = cairo_region_create ();
cairo_region_subtract (data.clipRgn, data.clipRgn);
cairo_region_union (data.clipRgn, clipRgn);
if (cairo != 0) {
if (data.clippingTransform == null) data.clippingTransform = new double[6];
Cairo.cairo_get_matrix(cairo, data.clippingTransform);
setCairoClip(data.damageRgn, clipRgn);
} else {
long /*int*/ clipping = clipRgn;
if (data.damageRgn != 0) {
clipping = cairo_region_create ();
cairo_region_union (clipping, clipRgn);
cairo_region_intersect (clipping, data.damageRgn);
}
OS.gdk_gc_set_clip_region(handle, clipping);
if (clipping != clipRgn) cairo_region_destroy (clipping);
}
}
}
/**
* Sets the area of the receiver which can be changed
* by drawing operations to the rectangular area specified
* by the arguments.
*
* @param x the x coordinate of the clipping rectangle
* @param y the y coordinate of the clipping rectangle
* @param width the width of the clipping rectangle
* @param height the height of the clipping rectangle
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void setClipping(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (width < 0) {
x = x + width;
width = -width;
}
if (height < 0) {
y = y + height;
height = -height;
}
if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
cairo_rectangle_int_t rect = new cairo_rectangle_int_t ();
rect.x = x;
rect.y = y;
rect.width = width;
rect.height = height;
long /*int*/ clipRgn = cairo_region_create ();
Cairo.cairo_region_union_rectangle (clipRgn, rect);
setClipping(clipRgn);
Cairo.cairo_region_destroy (clipRgn);
} else {
GdkRectangle rect = new GdkRectangle();
rect.x = x;
rect.y = y;
rect.width = width;
rect.height = height;
long /*int*/ clipRgn = cairo_region_create ();
OS.gdk_region_union_with_rect(clipRgn, rect);
setClipping(clipRgn);
OS.gdk_region_destroy (clipRgn);
}
}
/**
* Sets the area of the receiver which can be changed
* by drawing operations to the path specified
* by the argument.
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
*
* @param path the clipping path.
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the path has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see Path
* @see #getAdvanced
* @see #setAdvanced
*
* @since 3.1
*/
public void setClipping(Path path) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
setClipping(0);
if (path != null) {
initCairo();
long /*int*/ cairo = data.cairo;
long /*int*/ copy = Cairo.cairo_copy_path(path.handle);
if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
Cairo.cairo_append_path(cairo, copy);
Cairo.cairo_path_destroy(copy);
Cairo.cairo_clip(cairo);
}
}
/**
* Sets the area of the receiver which can be changed
* by drawing operations to the rectangular area specified
* by the argument. Specifying null
for the
* rectangle reverts the receiver's clipping area to its
* original value.
*
* @param rect the clipping rectangle or null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void setClipping(Rectangle rect) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (rect == null) {
setClipping(0);
} else {
setClipping(rect.x, rect.y, rect.width, rect.height);
}
}
/**
* Sets the area of the receiver which can be changed
* by drawing operations to the region specified
* by the argument. Specifying null
for the
* region reverts the receiver's clipping area to its
* original value.
*
* @param region the clipping region or null
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the region has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void setClipping(Region region) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
setClipping(region != null ? region.handle : 0);
}
/**
* Sets the font which will be used by the receiver
* to draw and measure text to the argument. If the
* argument is null, then a default font appropriate
* for the platform will be used instead.
*
* @param font the new font for the receiver, or null to indicate a default font
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the font has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void setFont(Font font) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
data.font = font != null ? font : data.device.systemFont;
data.state &= ~FONT;
data.stringWidth = data.stringHeight = -1;
}
/**
* Sets the receiver's fill rule to the parameter, which must be one of
* SWT.FILL_EVEN_ODD
or SWT.FILL_WINDING
.
*
* @param rule the new fill rule
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the rule is not one of
SWT.FILL_EVEN_ODD
* or SWT.FILL_WINDING
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.1
*/
public void setFillRule(int rule) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
int cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD;
switch (rule) {
case SWT.FILL_WINDING:
cairo_mode = Cairo.CAIRO_FILL_RULE_WINDING; break;
case SWT.FILL_EVEN_ODD:
cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD; break;
default:
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
//TODO - need fill rule in X, GDK has no API
initCairo();
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
Cairo.cairo_set_fill_rule(cairo, cairo_mode);
}
}
/**
* Sets the foreground color. The foreground color is used
* for drawing operations including when text is drawn.
*
* @param color the new foreground color for the receiver
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the color is null
* - ERROR_INVALID_ARGUMENT - if the color has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void setForeground(Color color) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
data.foreground = color.handle;
data.foregroundPattern = null;
data.state &= ~FOREGROUND;
}
/**
* Sets the foreground pattern. The default value is null
.
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
* @param pattern the new foreground pattern
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the parameter has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see Pattern
* @see #getAdvanced
* @see #setAdvanced
*
* @since 3.1
*/
public void setForegroundPattern(Pattern pattern) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
if (data.cairo == 0 && pattern == null) return;
initCairo();
if (data.foregroundPattern == pattern) return;
data.foregroundPattern = pattern;
data.state &= ~FOREGROUND;
}
/**
* Sets the receiver's interpolation setting to the parameter, which
* must be one of SWT.DEFAULT
, SWT.NONE
,
* SWT.LOW
or SWT.HIGH
.
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
*
* @param interpolation the new interpolation setting
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the rule is not one of
SWT.DEFAULT
,
* SWT.NONE
, SWT.LOW
or SWT.HIGH
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see #getAdvanced
* @see #setAdvanced
*
* @since 3.1
*/
public void setInterpolation(int interpolation) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.cairo == 0 && interpolation == SWT.DEFAULT) return;
switch (interpolation) {
case SWT.DEFAULT:
case SWT.NONE:
case SWT.LOW:
case SWT.HIGH:
break;
default:
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
initCairo();
data.interpolation = interpolation;
}
/**
* Sets the receiver's line attributes.
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
* @param attributes the line attributes
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the attributes is null
* - ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see LineAttributes
* @see #getAdvanced
* @see #setAdvanced
*
* @since 3.3
*/
public void setLineAttributes(LineAttributes attributes) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
int mask = 0;
float lineWidth = attributes.width;
if (lineWidth != data.lineWidth) {
mask |= LINE_WIDTH | DRAW_OFFSET;
}
int lineStyle = attributes.style;
if (lineStyle != data.lineStyle) {
mask |= LINE_STYLE;
switch (lineStyle) {
case SWT.LINE_SOLID:
case SWT.LINE_DASH:
case SWT.LINE_DOT:
case SWT.LINE_DASHDOT:
case SWT.LINE_DASHDOTDOT:
break;
case SWT.LINE_CUSTOM:
if (attributes.dash == null) lineStyle = SWT.LINE_SOLID;
break;
default:
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
}
int join = attributes.join;
if (join != data.lineJoin) {
mask |= LINE_JOIN;
switch (join) {
case SWT.JOIN_MITER:
case SWT.JOIN_ROUND:
case SWT.JOIN_BEVEL:
break;
default:
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
}
int cap = attributes.cap;
if (cap != data.lineCap) {
mask |= LINE_CAP;
switch (cap) {
case SWT.CAP_FLAT:
case SWT.CAP_ROUND:
case SWT.CAP_SQUARE:
break;
default:
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
}
float[] dashes = attributes.dash;
float[] lineDashes = data.lineDashes;
if (dashes != null && dashes.length > 0) {
boolean changed = lineDashes == null || lineDashes.length != dashes.length;
for (int i = 0; i < dashes.length; i++) {
float dash = dashes[i];
if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
if (!changed && lineDashes[i] != dash) changed = true;
}
if (changed) {
float[] newDashes = new float[dashes.length];
System.arraycopy(dashes, 0, newDashes, 0, dashes.length);
dashes = newDashes;
mask |= LINE_STYLE;
} else {
dashes = lineDashes;
}
} else {
if (lineDashes != null && lineDashes.length > 0) {
mask |= LINE_STYLE;
} else {
dashes = lineDashes;
}
}
float dashOffset = attributes.dashOffset;
if (dashOffset != data.lineDashesOffset) {
mask |= LINE_STYLE;
}
float miterLimit = attributes.miterLimit;
if (miterLimit != data.lineMiterLimit) {
mask |= LINE_MITERLIMIT;
}
initCairo();
if (mask == 0) return;
data.lineWidth = lineWidth;
data.lineStyle = lineStyle;
data.lineCap = cap;
data.lineJoin = join;
data.lineDashes = dashes;
data.lineDashesOffset = dashOffset;
data.lineMiterLimit = miterLimit;
data.state &= ~mask;
}
/**
* Sets the receiver's line cap style to the argument, which must be one
* of the constants SWT.CAP_FLAT
, SWT.CAP_ROUND
,
* or SWT.CAP_SQUARE
.
*
* @param cap the cap style to be used for drawing lines
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the style is not valid
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.1
*/
public void setLineCap(int cap) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.lineCap == cap) return;
switch (cap) {
case SWT.CAP_ROUND:
case SWT.CAP_FLAT:
case SWT.CAP_SQUARE:
break;
default:
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
data.lineCap = cap;
data.state &= ~LINE_CAP;
}
/**
* Sets the receiver's line dash style to the argument. The default
* value is null
. If the argument is not null
,
* the receiver's line style is set to SWT.LINE_CUSTOM
, otherwise
* it is set to SWT.LINE_SOLID
.
*
* @param dashes the dash style to be used for drawing lines
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.1
*/
public void setLineDash(int[] dashes) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
float[] lineDashes = data.lineDashes;
if (dashes != null && dashes.length > 0) {
boolean changed = data.lineStyle != SWT.LINE_CUSTOM || lineDashes == null || lineDashes.length != dashes.length;
for (int i = 0; i < dashes.length; i++) {
int dash = dashes[i];
if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
if (!changed && lineDashes[i] != dash) changed = true;
}
if (!changed) return;
data.lineDashes = new float[dashes.length];
for (int i = 0; i < dashes.length; i++) {
data.lineDashes[i] = dashes[i];
}
data.lineStyle = SWT.LINE_CUSTOM;
} else {
if (data.lineStyle == SWT.LINE_SOLID && (lineDashes == null || lineDashes.length == 0)) return;
data.lineDashes = null;
data.lineStyle = SWT.LINE_SOLID;
}
data.state &= ~LINE_STYLE;
}
/**
* Sets the receiver's line join style to the argument, which must be one
* of the constants SWT.JOIN_MITER
, SWT.JOIN_ROUND
,
* or SWT.JOIN_BEVEL
.
*
* @param join the join style to be used for drawing lines
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the style is not valid
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @since 3.1
*/
public void setLineJoin(int join) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.lineJoin == join) return;
switch (join) {
case SWT.JOIN_MITER:
case SWT.JOIN_ROUND:
case SWT.JOIN_BEVEL:
break;
default:
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
data.lineJoin = join;
data.state &= ~LINE_JOIN;
}
/**
* Sets the receiver's line style to the argument, which must be one
* of the constants SWT.LINE_SOLID
, SWT.LINE_DASH
,
* SWT.LINE_DOT
, SWT.LINE_DASHDOT
or
* SWT.LINE_DASHDOTDOT
.
*
* @param lineStyle the style to be used for drawing lines
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the style is not valid
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void setLineStyle(int lineStyle) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.lineStyle == lineStyle) return;
switch (lineStyle) {
case SWT.LINE_SOLID:
case SWT.LINE_DASH:
case SWT.LINE_DOT:
case SWT.LINE_DASHDOT:
case SWT.LINE_DASHDOTDOT:
break;
case SWT.LINE_CUSTOM:
if (data.lineDashes == null) lineStyle = SWT.LINE_SOLID;
break;
default:
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
data.lineStyle = lineStyle;
data.state &= ~LINE_STYLE;
}
/**
* Sets the width that will be used when drawing lines
* for all of the figure drawing operations (that is,
* drawLine
, drawRectangle
,
* drawPolyline
, and so forth.
*
* Note that line width of zero is used as a hint to
* indicate that the fastest possible line drawing
* algorithms should be used. This means that the
* output may be different from line width one.
*
*
* @param lineWidth the width of a line
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public void setLineWidth(int lineWidth) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.lineWidth == lineWidth) return;
data.lineWidth = lineWidth;
data.state &= ~(LINE_WIDTH | DRAW_OFFSET);
}
void setString(String string, int flags) {
if (data.layout == 0) createLayout();
if (string == data.string && (flags & ~SWT.DRAW_TRANSPARENT) == (data.drawFlags & ~SWT.DRAW_TRANSPARENT)) {
return;
}
byte[] buffer;
int mnemonic, length = string.length ();
long /*int*/ layout = data.layout;
char[] text = new char[length];
string.getChars(0, length, text, 0);
if ((flags & SWT.DRAW_MNEMONIC) != 0 && (mnemonic = fixMnemonic(text)) != -1) {
char[] text1 = new char[mnemonic - 1];
System.arraycopy(text, 0, text1, 0, text1.length);
byte[] buffer1 = Converter.wcsToMbcs(null, text1, false);
char[] text2 = new char[text.length - mnemonic];
System.arraycopy(text, mnemonic - 1, text2, 0, text2.length);
byte[] buffer2 = Converter.wcsToMbcs(null, text2, false);
buffer = new byte[buffer1.length + buffer2.length];
System.arraycopy(buffer1, 0, buffer, 0, buffer1.length);
System.arraycopy(buffer2, 0, buffer, buffer1.length, buffer2.length);
long /*int*/ attr_list = OS.pango_attr_list_new();
long /*int*/ attr = OS.pango_attr_underline_new(OS.PANGO_UNDERLINE_LOW);
PangoAttribute attribute = new PangoAttribute();
OS.memmove(attribute, attr, PangoAttribute.sizeof);
attribute.start_index = buffer1.length;
attribute.end_index = buffer1.length + 1;
OS.memmove(attr, attribute, PangoAttribute.sizeof);
OS.pango_attr_list_insert(attr_list, attr);
OS.pango_layout_set_attributes(layout, attr_list);
OS.pango_attr_list_unref(attr_list);
} else {
buffer = Converter.wcsToMbcs(null, text, false);
OS.pango_layout_set_attributes(layout, 0);
}
OS.pango_layout_set_text(layout, buffer, buffer.length);
OS.pango_layout_set_single_paragraph_mode(layout, (flags & SWT.DRAW_DELIMITER) == 0);
OS.pango_layout_set_tabs(layout, (flags & SWT.DRAW_TAB) != 0 ? 0 : data.device.emptyTab);
data.string = string;
data.stringWidth = data.stringHeight = -1;
data.drawFlags = flags;
}
/**
* Sets the receiver's text anti-aliasing value to the parameter,
* which must be one of SWT.DEFAULT
, SWT.OFF
* or SWT.ON
. Note that this controls anti-aliasing only
* for all text drawing operations.
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
*
* @param antialias the anti-aliasing setting
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the parameter is not one of
SWT.DEFAULT
,
* SWT.OFF
or SWT.ON
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see #getAdvanced
* @see #setAdvanced
* @see #setAntialias
*
* @since 3.1
*/
public void setTextAntialias(int antialias) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (data.cairo == 0 && antialias == SWT.DEFAULT) return;
int mode = 0;
switch (antialias) {
case SWT.DEFAULT: mode = Cairo.CAIRO_ANTIALIAS_DEFAULT; break;
case SWT.OFF: mode = Cairo.CAIRO_ANTIALIAS_NONE; break;
case SWT.ON: mode = Cairo.CAIRO_ANTIALIAS_GRAY;
break;
default:
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
initCairo();
long /*int*/ options = Cairo.cairo_font_options_create();
Cairo.cairo_font_options_set_antialias(options, mode);
if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
Cairo.cairo_set_font_options(data.cairo, options);
} else {
if (data.context == 0) createLayout();
OS.pango_cairo_context_set_font_options(data.context, options);
}
Cairo.cairo_font_options_destroy(options);
}
/**
* Sets the transform that is currently being used by the receiver. If
* the argument is null
, the current transform is set to
* the identity transform.
*
* This operation requires the operating system's advanced
* graphics subsystem which may not be available on some
* platforms.
*
*
* @param transform the transform to set
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the parameter has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
* - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
*
*
* @see Transform
* @see #getAdvanced
* @see #setAdvanced
*
* @since 3.1
*/
public void setTransform(Transform transform) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
if (data.cairo == 0 && transform == null) return;
initCairo();
long /*int*/ cairo = data.cairo;
double[] identity = identity();
if (transform != null) {
Cairo.cairo_matrix_multiply(identity, transform.handle, identity);
}
Cairo.cairo_set_matrix(cairo, identity);
data.state &= ~DRAW_OFFSET;
}
/**
* If the argument is true
, puts the receiver
* in a drawing mode where the resulting color in the destination
* is the exclusive or of the color values in the source
* and the destination, and if the argument is false
,
* puts the receiver in a drawing mode where the destination color
* is replaced with the source color value.
*
* Note that this mode in fundamentally unsupportable on certain
* platforms, notably Carbon (Mac OS X). Clients that want their
* code to run on all platforms need to avoid this method.
*
*
* @param xor if true
, then xor mode is used, otherwise source copy mode is used
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*
* @deprecated this functionality is not supported on some platforms
*/
public void setXORMode(boolean xor) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
if (Cairo.cairo_version() >= Cairo.CAIRO_VERSION_ENCODE(1, 10, 0)) {
Cairo.cairo_set_operator(handle, xor ? Cairo.CAIRO_OPERATOR_DIFFERENCE : Cairo.CAIRO_OPERATOR_OVER);
}
}
if (!OS.USE_CAIRO) {
OS.gdk_gc_set_function(handle, xor ? OS.GDK_XOR : OS.GDK_COPY);
}
data.xorMode = xor;
}
/**
* Returns the extent of the given string. No tab
* expansion or carriage return processing will be performed.
*
* The extent of a string is the width and height of
* the rectangular area it would cover if drawn in a particular
* font (in this case, the current font in the receiver).
*
*
* @param string the string to measure
* @return a point containing the extent of the string
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the string is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public Point stringExtent(String string) {
return textExtent(string, 0);
}
/**
* Returns the extent of the given string. Tab expansion and
* carriage return processing are performed.
*
* The extent of a string is the width and height of
* the rectangular area it would cover if drawn in a particular
* font (in this case, the current font in the receiver).
*
*
* @param string the string to measure
* @return a point containing the extent of the string
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the string is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public Point textExtent(String string) {
return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
}
/**
* Returns the extent of the given string. Tab expansion, line
* delimiter and mnemonic processing are performed according to
* the specified flags, which can be a combination of:
*
* - DRAW_DELIMITER
* - draw multiple lines
* - DRAW_TAB
* - expand tabs
* - DRAW_MNEMONIC
* - underline the mnemonic character
* - DRAW_TRANSPARENT
* - transparent background
*
*
* The extent of a string is the width and height of
* the rectangular area it would cover if drawn in a particular
* font (in this case, the current font in the receiver).
*
*
* @param string the string to measure
* @param flags the flags specifying how to process the text
* @return a point containing the extent of the string
*
* @exception IllegalArgumentException
* - ERROR_NULL_ARGUMENT - if the string is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
public Point textExtent(String string, int flags) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
long /*int*/ cairo = data.cairo;
if (cairo != 0) {
if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
//TODO - honor flags
checkGC(FONT);
byte[] buffer = Converter.wcsToMbcs(null, string, true);
cairo_font_extents_t font_extents = new cairo_font_extents_t();
Cairo.cairo_font_extents(cairo, font_extents);
cairo_text_extents_t extents = new cairo_text_extents_t();
Cairo.cairo_text_extents(cairo, buffer, extents);
return new Point((int)extents.width, (int)font_extents.height);
}
}
setString(string, flags);
checkGC(FONT);
if (data.stringWidth == -1) {
computeStringSize();
}
return new Point(data.stringWidth, data.stringHeight);
}
/**
* Returns a string containing a concise, human-readable
* description of the receiver.
*
* @return a string representation of the receiver
*/
public String toString () {
if (isDisposed()) return "GC {*DISPOSED*}";
return "GC {" + handle + "}";
}
void gtk_render_focus (long /*int*/ style, long /*int*/ window, int state_type, GdkRectangle area, long /*int*/ widget, byte[] detail, int x , int y, int width, int height) {
if (OS.GTK_VERSION >= OS.VERSION(3, 2, 0)) {
long /*int*/ cairo = OS.gdk_cairo_create (window);
long /*int*/ context = OS.gtk_widget_get_style_context (style);
OS.gtk_style_context_save (context);
OS.gtk_style_context_set_state (context, OS.gtk_widget_get_state_flags (widget));
Cairo.cairo_save (cairo);
OS.gtk_render_focus(context, cairo, x, y, width, height);
Cairo.cairo_restore (cairo);
OS.gtk_style_context_restore (context);
Cairo.cairo_destroy(cairo);
} else {
OS.gtk_paint_focus (style, window, state_type, area, widget, detail, x, y, width, height);
}
}
void cairo_region_destroy (long /*int*/ region) {
if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
Cairo.cairo_region_destroy ( region);
} else {
OS.gdk_region_destroy (region);
}
}
long /*int*/ cairo_region_create () {
if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
return Cairo.cairo_region_create ();
} else {
return OS.gdk_region_new ();
}
}
void cairo_region_subtract (long /*int*/ dst, long /*int*/ other) {
if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
Cairo.cairo_region_subtract (dst, other);
} else {
OS.gdk_region_subtract (dst, other);
}
}
void cairo_region_translate (long /*int*/ region, int dx, int dy) {
if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
Cairo.cairo_region_translate (region, dx, dy);
} else {
OS.gdk_region_offset (region, dx, dy);
}
}
void cairo_region_union (long /*int*/ dst, long /*int*/ other) {
if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
Cairo.cairo_region_union (dst, other);
} else {
OS.gdk_region_union (dst, other);
}
}
void cairo_region_intersect (long /*int*/ dst, long /*int*/ other) {
if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) {
Cairo.cairo_region_intersect (dst, other);
} else {
OS.gdk_region_intersect (dst, other);
}
}
}