From d67b8caceb3f10df6a8e238427498db262144133 Mon Sep 17 00:00:00 2001
From: Silenio Quarti
Date: Mon, 18 Mar 2002 17:48:47 +0000
Subject: *** empty log message ***
---
.../gtk/org/eclipse/swt/internal/gtk/OS.java | 4 +
.../gtk/org/eclipse/swt/graphics/GC.java | 2576 ++++++++++----------
.../gtk/org/eclipse/swt/graphics/Image.java | 608 +++--
3 files changed, 1779 insertions(+), 1409 deletions(-)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index 78a789f47e..6602016841 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -57,6 +57,10 @@ public class OS {
public static final int GDK_GC_LINE_STYLE = 1 << 15;
public static final int GDK_GC_CAP_STYLE = 1 << 16;
public static final int GDK_GC_JOIN_STYLE = 1 << 17;
+
+ /* GdkImage byte order */
+ public static final int GDK_LSB_FIRST = 0;
+ public static final int GDK_MSB_FIRST = 1;
/* For Display.KeyTable: */
/* Keyboard and mouse masks */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
index bf80991565..a9c145cda3 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
@@ -5,7 +5,6 @@ package org.eclipse.swt.graphics;
* All Rights Reserved
*/
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.internal.gtk.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.*;
@@ -31,14 +30,10 @@ public final class GC {
* (Warning: This field is platform dependent)
*/
public int handle;
+
Drawable drawable;
GCData data;
-
-/*
- * === Constructors ===
- */
-
GC() {
}
@@ -61,688 +56,969 @@ GC() {
*/
public GC(Drawable drawable) {
if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-
- data = new GCData();
- handle = drawable.internal_new_GC(data);
- this.drawable = drawable;
-
- // The colors we get from the widget are not always right.
- // Get the default GTK_STATE_NORMAL colors
-/* setBackground( DefaultGtkStyle.instance().backgroundColorNORMAL() );
- setForeground( DefaultGtkStyle.instance().foregroundColorNORMAL() );
-*/
-
- // Feature in GDK.
- // Sometimes, gdk_gc_new() doesn't get the font from the control,
- // and also, some controls don't contain a font; so when the GC
- // was created in internal_new_gc(), the font might or might not
- // be set; if the font isn't there, just fall back to default.
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- if (values.font == 0) {
-/* OS.gdk_gc_set_font(handle, DefaultGtkStyle.instance().loadDefaultFont() );*/
- }
-
- if (data.image != null) {
- data.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();
- }
-
+ GCData data = new GCData();
+ int gdkGC = drawable.internal_new_GC(data);
+ init(drawable, data, gdkGC);
}
-
-
-/**
- * Returns the background color.
+/**
+ * Copies a rectangular area of the receiver at the source
+ * position onto the receiver at the destination position.
*
- * @return the receiver's background color
+ * @param srcX the x coordinate in the receiver of the area to be copied
+ * @param srcY the y coordinate in the receiver of the area to be copied
+ * @param width the width of the area to copy
+ * @param height the height of the area to copy
+ * @param destX the x coordinate in the receiver of the area to copy to
+ * @param destY the y coordinate in the receiver of the area to copy to
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
-/*
- * === Access - Get/Set ===
- */
-public Color getBackground() {
- if (handle == 0) error(SWT.ERROR_WIDGET_DISPOSED);
- GdkColor gdkColor = _getBackgroundGdkColor();
- return Color.gtk_new(gdkColor);
-}
/**
- * Sets the background color. The background color is used
- * for fill operations and as the background color when text
- * is drawn.
+ * Copies a rectangular area of the receiver at the specified
+ * position into the image, which must be of type SWT.BITMAP
.
*
- * @param color the new background color for the receiver
+ * @param x the x coordinate in the receiver of the area to be copied
+ * @param y the y coordinate in the receiver of the area to be copied
*
* @exception IllegalArgumentException
- * - ERROR_NULL_ARGUMENT - if the color is null
- * - ERROR_INVALID_ARGUMENT - if the color has been disposed
+ * - ERROR_NULL_ARGUMENT - if the image is null
+ * - ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
-public void setBackground(Color color) {
- if (color == null) error(SWT.ERROR_NULL_ARGUMENT);
- if (color.handle == null) error(SWT.ERROR_NULL_ARGUMENT);
- if (handle == 0) error(SWT.ERROR_WIDGET_DISPOSED);
- OS.gdk_gc_set_background(handle, color.handle);
+public void copyArea(Image image, int x, int y) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ Rectangle rect = image.getBounds();
+ int gdkGC = OS.gdk_gc_new(image.pixmap);
+ if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ OS.gdk_gc_set_subwindow(gdkGC, OS.GDK_INCLUDE_INFERIORS);
+ OS.gdk_draw_drawable(image.pixmap, gdkGC, data.drawable, x, y, 0, 0, rect.width, rect.height);
+ OS.g_object_unref(gdkGC);
}
-/**
- * Returns the receiver's foreground color.
+/**
+ * Copies a rectangular area of the receiver at the source
+ * position onto the receiver at the destination position.
*
- * @return the color used for drawing foreground things
+ * @param srcX the x coordinate in the receiver of the area to be copied
+ * @param srcY the y coordinate in the receiver of the area to be copied
+ * @param width the width of the area to copy
+ * @param height the height of the area to copy
+ * @param destX the x coordinate in the receiver of the area to copy to
+ * @param destY the y coordinate in the receiver of the area to copy to
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
-public Color getForeground() {
- if (handle == 0) error(SWT.ERROR_WIDGET_DISPOSED);
- GdkColor gdkColor = _getForegroundGdkColor();
- return Color.gtk_new(gdkColor);
+public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (width <= 0 || height <= 0) return;
+ int deltaX = destX - srcX, deltaY = destY - srcY;
+ if (deltaX == 0 && deltaY == 0) return;
+ int drawable = data.drawable;
+ OS.gdk_gc_set_exposures(handle, true);
+ OS.gdk_draw_drawable(drawable, handle, drawable, srcX, srcY, destX, destY, width, height);
+ OS.gdk_gc_set_exposures(handle, false);
+ if (data.image != null) return;
+ boolean disjoint = (destX + width < srcX) || (srcX + width < destX) || (destY + height < srcY) || (srcY + height < destY);
+ if (disjoint) {
+ OS.gdk_window_clear_area_e(drawable, srcX, srcY, width, height);
+ } else {
+ if (deltaX != 0) {
+ int newX = destX - deltaX;
+ if (deltaX < 0) newX = destX + width;
+ OS.gdk_window_clear_area_e(drawable, newX, srcY, Math.abs(deltaX), height);
+ }
+ if (deltaY != 0) {
+ int newY = destY - deltaY;
+ if (deltaY < 0) newY = destY + height;
+ OS.gdk_window_clear_area_e(drawable, srcX, newY, width, Math.abs(deltaY));
+ }
+ }
}
/**
- * 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
- *
+ * Disposes of the operating system resources associated with
+ * the graphics context. Applications must dispose of all GCs
+ * which they allocate.
*/
-public void setForeground(Color color) {
- if (handle == 0) error(SWT.ERROR_WIDGET_DISPOSED);
- if (color == null) error(SWT.ERROR_NULL_ARGUMENT);
- if (color.handle == null) error(SWT.ERROR_NULL_ARGUMENT);
- OS.gdk_gc_set_foreground(handle, color.handle);
-}
-
-
-
-
+public void dispose() {
+ if (handle == 0) return;
+ if (data.device.isDisposed()) return;
+
+ /* Free resources */
+ int clipRgn = data.clipRgn;
+ if (clipRgn != 0) OS.gdk_region_destroy(clipRgn);
+ Image image = data.image;
+ if (image != null) image.memGC = null;
+ /* Dispose the GC */
+ drawable.internal_dispose_GC(handle, data);
+ data.drawable = data.clipRgn = 0;
+ drawable = null;
+ data.image = null;
+ data = null;
+ handle = 0;
+
+}
/**
- * Returns the advance width of the specified character in
- * the font which is currently selected into the receiver.
+ * Draws the outline of a circular or elliptical arc
+ * within the specified rectangular area.
*
- * The advance width is defined as the horizontal distance the cursor
- * should move after printing the character in the selected font.
+ * 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 ch the character to measure
- * @return the distance in the x direction to move past the character before painting the next
+ * @param x the x coordinate of the upper-left corner of the arc to be drawn
+ * @param y the y coordinate of the upper-left corner of the arc to be drawn
+ * @param width the width of the arc to be drawn
+ * @param height the height of the arc to be drawn
+ * @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
+ * @exception IllegalArgumentException
+ * - ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.
*
- */
-/*
- * === Access - Get - Calculated ===
- */
-
-public int getAdvanceWidth(char ch) {
- byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch });
- return OS.gdk_char_width(_getGCFont(), charBuffer[0]);
-}
-/**
- * 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) {
- byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch });
- int[] lbearing = new int[1];
- int[] rbearing = new int[1];
- int[] unused = new int[1];
- OS.gdk_string_extents(_getGCFont(), charBuffer, lbearing, rbearing, unused, unused, unused);
- return rbearing[0] - lbearing[0];
+public void drawArc(int x, int y, int width, int height, int startAngle, int endAngle) {
+ 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 (width == 0 || height == 0 || endAngle == 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, startAngle * 64, endAngle * 64);
}
+
/**
- * 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.
+ * Draws a rectangle, based on the specified arguments, which has
+ * the appearance of the platform's focus rectangle if the
+ * platform supports such a notion, and otherwise draws a simple
+ * rectangle in the receiver's forground color.
*
- * @return the bounding rectangle of the clipping region
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param width the width of the rectangle
+ * @param height the height of the rectangle
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
+ *
+ * @see #drawRectangle
*/
-public Rectangle getClipping() {
- if (data.clipRgn == 0) {
- int[] width = new int[1]; int[] height = new int[1];
- OS.gdk_drawable_get_size(data.drawable, width, height);
- return new Rectangle(0, 0, width[0], height[0]);
- }
- GdkRectangle rect = new GdkRectangle();
- OS.gdk_region_get_clipbox(data.clipRgn, rect);
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
+public void drawFocus(int x, int y, int width, int height) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ GtkStyle style = new GtkStyle(OS.gtk_widget_get_default_style());
+ GdkColor color = new GdkColor();
+ color.pixel = style.fg0_pixel;
+ color.red = style.fg0_red;
+ color.green = style.fg0_green;
+ color.blue = style.fg0_blue;
+ GdkGCValues values = new GdkGCValues();
+ OS.gdk_gc_get_values(handle, values);
+ OS.gdk_gc_set_foreground(handle, color);
+ OS.gdk_draw_rectangle(data.drawable, handle, 0, x, y, width, height);
+ color.pixel = values.foreground_pixel;
+ color.red = values.foreground_red;
+ color.green = values.foreground_green;
+ color.blue = values.foreground_blue;
+ OS.gdk_gc_set_foreground(handle, color);
}
-/**
- * Sets the region managed by the argument to the current
- * clipping region of the receiver.
+
+/**
+ * Draws the given image in the receiver at the specified
+ * coordinates.
*
- * @param region the region to fill with the clipping region
+ * @param image the image to draw
+ * @param x the x coordinate of where to draw
+ * @param y the y coordinate of where to draw
*
* @exception IllegalArgumentException
- * - ERROR_NULL_ARGUMENT - if the region is null
- *
- * @exception SWTException
- * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ * - ERROR_NULL_ARGUMENT - if the image is null
+ * - ERROR_INVALID_ARGUMENT - if the image has been disposed
+ * - ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image
+ * @exception SWTError
+ * - ERROR_NO_HANDLES - if no handles are available to perform the operation
*
- */
-public void getClipping(Region region) {
- if (region == null) error(SWT.ERROR_NULL_ARGUMENT);
- int hRegion = region.handle;
- if (data.clipRgn == 0) {
- int[] width = new int[1]; int[] height = new int[1];
- OS.gdk_drawable_get_size(data.drawable, width, height);
- hRegion = OS.gdk_region_new();
- GdkRectangle rect = new GdkRectangle();
- rect.x = 0; rect.y = 0;
- rect.width = (short)width[0]; rect.height = (short)height[0];
- region.handle = OS.gdk_region_union_with_rect(hRegion, rect);
- return;
- }
- hRegion = OS.gdk_region_new();
- region.handle = OS.gdk_regions_union(data.clipRgn, hRegion);
-}
-/**
- * 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() {
- return Font.gtk_new(_getGCFont());
+public void drawImage(Image image, int x, int y) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
}
+
/**
- * Returns a FontMetrics which contains information
- * about the font currently being used by the receiver
- * to draw and measure text.
+ * Copies a rectangular area from the source image into a (potentially
+ * different sized) rectangular area in the receiver. If the source
+ * and destination areas are of differing sizes, then the source
+ * area will be stretched or shrunk to fit the destination area
+ * as it is copied. The copy fails if any of the given coordinates
+ * are negative or lie outside the bounds of their respective images.
*
- * @return font metrics for the receiver's font
+ * @param image the source image
+ * @param srcX the x coordinate in the source image to copy from
+ * @param srcY the y coordinate in the source image to copy from
+ * @param srcWidth the width in pixels to copy from the source
+ * @param srcHeight the height in pixels to copy from the source
+ * @param destX the x coordinate in the destination to copy to
+ * @param destY the y coordinate in the destination to copy to
+ * @param destWidth the width in pixels of the destination rectangle
+ * @param destHeight the height in pixels of the destination rectangle
*
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the image is null
+ * - ERROR_INVALID_ARGUMENT - if the image has been disposed
+ * - ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of their respective images
+ *
+ * @exception SWTError
+ * - ERROR_NO_HANDLES - if no handles are available to perform the operation
+ *
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
-// Not done
-public FontMetrics getFontMetrics() {
- int fontHandle = _getGCFont();
- if (fontHandle==0) {
- error(SWT.ERROR_UNSPECIFIED);
+public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
+ if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
+ SWT.error (SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
+}
+
+void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
+ int[] width = new int[1];
+ int[] height = new int[1];
+ OS.gdk_drawable_get_size(srcImage.pixmap, width, height);
+ int imgWidth = width[0];
+ int imgHeight = height[0];
+ if (simple) {
+ srcWidth = destWidth = imgWidth;
+ srcHeight = destHeight = imgHeight;
+ } else {
+ simple = srcX == 0 && srcY == 0 &&
+ srcWidth == destWidth && destWidth == imgWidth &&
+ srcHeight == destHeight && destHeight == imgHeight;
+ if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ }
+ if (srcImage.alpha != -1 || srcImage.alphaData != null) {
+ drawImageAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight);
+ } else if (srcImage.transparentPixel != -1 || srcImage.mask != 0) {
+ drawImageMask(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight);
+ } else {
+ drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight);
+ }
+}
+void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight) {
+ if (srcWidth == destWidth && srcHeight == destHeight) {
+ OS.gdk_draw_drawable(data.drawable, handle, srcImage.pixmap, srcX, srcY, destX, destY, destWidth, destHeight);
+ } else {
+ int pixbuf = scale(srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destWidth, destHeight);
+ OS.gdk_pixbuf_render_to_drawable(pixbuf, data.drawable, handle, 0, 0, destX, destY, destWidth, destHeight, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
+ OS.g_object_unref(pixbuf);
+ }
+}
+void drawImageAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight) {
+ if (srcImage.alpha == 0) return;
+ if (srcImage.alpha == 255) {
+ drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight);
+ return;
+ }
+ int pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB(), true, 8, srcWidth, srcHeight);
+ if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int colormap = OS.gdk_colormap_get_system();
+ OS.gdk_pixbuf_get_from_drawable(pixbuf, srcImage.pixmap, colormap, srcX, srcY, 0, 0, srcWidth, srcHeight);
+ int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
+ int pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
+ byte[] line = new byte[stride];
+ byte alpha = (byte)srcImage.alpha;
+ byte[] alphaData = srcImage.alphaData;
+ for (int y=0; ySWT.LINE_SOLID, SWT.LINE_DASH
,
- * SWT.LINE_DOT
, SWT.LINE_DASHDOT
or
- * SWT.LINE_DASHDOTDOT
.
+ * Draws a line, using the foreground color, between the points
+ * (x1
, y1
) and (x2
, y2
).
*
- * @return the style used for drawing lines
+ * @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 int getLineStyle() {
- return data.lineStyle;
+public void drawLine(int x1, int y1, int x2, int y2) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ OS.gdk_draw_line (data.drawable, handle, x1, y1, x2, y2);
}
+
/**
- * 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.
+ * 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.
+ *
*
- * @return the receiver's line width
+ * @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 int getLineWidth() {
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- return values.line_width;
+public void drawOval(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;
+ }
+ OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, 0, 23040);
}
+
/**
- * 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.
+ * 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.
*
- * @return true
true if the receiver is in XOR mode, and false otherwise
+ * @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 boolean getXORMode() {
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- return values.function == OS.GDK_XOR;
+public void drawPolygon(int[] pointArray) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ OS.gdk_draw_polygon(data.drawable, handle, 0, pointArray, pointArray.length / 2);
}
-/**
- * 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)
.
+/**
+ * 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.
*
- * @return true
if the GC has a clipping region, and false
otherwise
+ * @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 boolean isClipped() {
- return data.clipRgn != 0;
+public void drawPolyline(int[] pointArray) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ OS.gdk_draw_lines(data.drawable, handle, pointArray, pointArray.length / 2);
}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the arguments.
+/**
+ * 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 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
+ * @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 setClipping(int x, int y, int width, int height) {
-/* if (data.clipRgn == 0) data.clipRgn = OS.gdk_region_new();
- GdkRectangle rect = new GdkRectangle();
- rect.x = (short)x; rect.y = (short)y;
- rect.width = (short)width; rect.height = (short)height;
- OS.gdk_gc_set_clip_rectangle(handle, rect);
- data.clipRgn = OS.gdk_regions_subtract(data.clipRgn, data.clipRgn);
- data.clipRgn = OS.gdk_region_union_with_rect(data.clipRgn, rect);*/
+public void drawRectangle(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;
+ }
+ OS.gdk_draw_rectangle(data.drawable, handle, 0, x, y, width, height);
}
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the argument.
+
+/**
+ * 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 clipping rectangle
+ * @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 setClipping(Rectangle rect) {
- if (rect == null) error(SWT.ERROR_NULL_ARGUMENT);
- setClipping (rect.x, rect.y, rect.width, rect.height);
+public void drawRectangle(Rectangle rect) {
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ drawRectangle (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.
+/**
+ * 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.
*
- * @param rect the clipping region.
+ * @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 horizontal diameter of the arc at the four corners
+ * @param arcHeight the vertical diameter of the arc at the four corners
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
-public void setClipping(Region region) {
-/* if (data.clipRgn == 0) data.clipRgn = OS.gdk_region_new();
- if (region == null) {
- data.clipRgn = OS.gdk_regions_subtract(data.clipRgn, data.clipRgn);
- OS.gdk_gc_set_clip_mask(handle, OS.GDK_NONE);
+public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ 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;
+
+ int naw2 = naw / 2;
+ int nah2 = nah / 2;
+
+ 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 {
- data.clipRgn = OS.gdk_regions_subtract(data.clipRgn, data.clipRgn);
- data.clipRgn = OS.gdk_regions_union(region.handle, data.clipRgn);
- OS.gdk_gc_set_clip_region(handle, region.handle);
- }*/
+ 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);
+ }
+ }
}
+
/**
- * 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.
+ * 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 font the new font for the receiver, or null to indicate a default font
+ * @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_INVALID_ARGUMENT - if the font has been disposed
- *
+ * - ERROR_NULL_ARGUMENT - if the string is null
+ *
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
-public void setFont(Font font) {
-/* int fontHandle = 0;
- if (font == null) {
- GtkStyle gtkStyle = new GtkStyle();
- int style = OS.gtk_widget_get_default_style();
- OS.memmove(gtkStyle, style, GtkStyle.sizeof);
- fontHandle = gtkStyle.font;
- } else {
- fontHandle = font.handle;
- }
- OS.gdk_gc_set_font(handle, fontHandle);*/
+public void drawString (String string, int x, int y) {
+ drawString(string, x, y, false);
}
-
/**
- * 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
.
+ * 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 lineStyle the style to be used for drawing lines
+ * @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 setLineStyle(int lineStyle) {
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- this.data.lineStyle = lineStyle;
- OS.gdk_gc_set_line_attributes(handle, 0, OS.GDK_LINE_SOLID, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER);
- return;
- case SWT.LINE_DASH:
- OS.gdk_gc_set_dashes(handle, 0, new byte[] {6, 2}, 2);
- break;
- case SWT.LINE_DOT:
- OS.gdk_gc_set_dashes(handle, 0, new byte[] {3, 1}, 2);
- break;
- case SWT.LINE_DASHDOT:
- OS.gdk_gc_set_dashes(handle, 0, new byte[] {6, 2, 3, 1}, 4);
- break;
- case SWT.LINE_DASHDOTDOT:
- OS.gdk_gc_set_dashes(handle, 0, new byte[] {6, 2, 3, 1, 3, 1}, 6);
- break;
- default:
- error(SWT.ERROR_INVALID_ARGUMENT);
+public void drawString(String string, int x, int y, boolean isTransparent) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ byte[] buffer = Converter.wcsToMbcs(null, string, true);
+ byte[] buffer1 = Converter.wcsToMbcs(null, "Y", true);
+ int[] unused = new int[1];
+ int[] width = new int[1];
+ int[] ascent = new int[1];
+ int[] average_ascent = new int [1];
+ int fontHandle = _getGCFont();
+ OS.gdk_string_extents(fontHandle, buffer, unused, unused, width, ascent, unused);
+ OS.gdk_string_extents(fontHandle, buffer1, unused, unused, unused, average_ascent, unused);
+ if (ascent[0]drawLine, drawRectangle
,
- * drawPolyline
, and so forth.
+ * 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 lineWidth the width of a line
+ * @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 setLineWidth(int width) {
- if (data.lineStyle == SWT.LINE_SOLID) {
- OS.gdk_gc_set_line_attributes(handle, width, OS.GDK_LINE_SOLID, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER);
- } else {
- OS.gdk_gc_set_line_attributes(handle, width, OS.GDK_LINE_DOUBLE_DASH, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER);
- }
+public void drawText(String string, int x, int y) {
+ drawText(string, x, y, false);
}
+
/**
- * 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.
+ * 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 xor if true
, then xor mode is used, otherwise source copy mode is used
+ * @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 setXORMode(boolean val) {
- if (val) {
- OS.gdk_gc_set_function(handle, OS.GDK_XOR);
- } else {
- OS.gdk_gc_set_function(handle, OS.GDK_COPY);
+public void drawText(String string, int x, int y, boolean isTransparent) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ byte[] buffer = Converter.wcsToMbcs(null, string, true);
+ byte[] buffer1 = Converter.wcsToMbcs(null, "Y", true);
+ int fontHandle = _getGCFont();
+ int[] unused = new int[1];
+ int[] width = new int[1];
+ int[] ascent = new int[1];
+ int[] average_ascent = new int [1];
+ OS.gdk_string_extents(fontHandle, buffer, unused, unused, width, ascent, unused);
+ OS.gdk_string_extents(fontHandle, buffer1, unused, unused, unused, average_ascent, unused);
+ if (ascent[0]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 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).
+ * 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 measure
- * @return a point containing the extent of the string
+ * @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 specifing 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 Point stringExtent(String string) {
- if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- int width = OS.gdk_string_width(_getGCFont(), buffer);
- int height = OS.gdk_string_height(_getGCFont(), buffer);
- return new Point(width, height);
+public void drawText (String string, int x, int y, int flags) {
+ // NOT IMPLEMENTED
+ drawText(string, x, y, (flags & SWT.DRAW_TRANSPARENT) != 0);
}
+
/**
- * Returns the extent of the given string. Tab expansion and
- * carriage return processing are performed.
+ * 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 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).
+ * 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 string the string to measure
- * @return a point containing the extent of the string
+ * @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 IllegalArgumentException
- * - ERROR_NULL_ARGUMENT - if the string is null
+ * - ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
+ *
+ * @see #drawArc
*/
-public Point textExtent(String string) {
- if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- int width = OS.gdk_string_width(_getGCFont(), buffer);
- int height = OS.gdk_string_height(_getGCFont(), buffer);
- return new Point(width, height);
-}
-
-
-
-/*
- * === Access - Internal utils ===
- */
-
-private GdkGCValues _getGCValues() {
+public void fillArc(int x, int y, int width, int height, int startAngle, int endAngle) {
+ 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 (width == 0 || height == 0 || endAngle == 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
GdkGCValues values = new GdkGCValues();
OS.gdk_gc_get_values(handle, values);
- return values;
-}
-private GdkColor _getForegroundGdkColor() {
- GdkGCValues values = _getGCValues();
- GdkColor color = new GdkColor();
- color.pixel = values.foreground_pixel;
- color.red = values.foreground_red;
- color.green = values.foreground_green;
- color.blue = values.foreground_blue;
- return color;
-}
-private GdkColor _getBackgroundGdkColor() {
- GdkGCValues values = _getGCValues();
GdkColor color = new GdkColor();
color.pixel = values.background_pixel;
- color.red = values.background_red;
+ color.red = values.background_red;
color.green = values.background_green;
- color.blue = values.background_blue;
- return color;
-}
-private int _getGCFont() {
- GdkGCValues values = _getGCValues();
- if (values.font==0) {
- values.font = OS.gdk_font_load(Converter.wcsToMbcs(null, "fixed", true));
- if (values.font == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- }
- return values.font;
+ color.blue = values.background_blue;
+ OS.gdk_gc_set_foreground(handle, color);
+ OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, startAngle * 64, endAngle * 64);
+ color.pixel = values.foreground_pixel;
+ color.red = values.foreground_red;
+ color.green = values.foreground_green;
+ color.blue = values.foreground_blue;
+ OS.gdk_gc_set_foreground(handle, color);
}
-
-
/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
+ * 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 srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
+ * @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
*
- */
-/*
- * === Drawing operations proper ===
- */
-
-/**
- * Copies a rectangular area of the receiver at the specified
- * position into the image, which must be of type SWT.BITMAP
.
- *
- * @param x the x coordinate in the receiver of the area to be copied
- * @param y the y coordinate in the receiver of the area to be copied
*
- * @exception IllegalArgumentException
- * - ERROR_NULL_ARGUMENT - if the image is null
- * - ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed
- *
- * @exception SWTException
- * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- *
+ * @see #drawRectangle
*/
-public void copyArea(Image image, int x, int y) {
+public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rect = image.getBounds();
- int xGC = OS.gdk_gc_new(image.pixmap);
- if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- // is it possible/necessary to set the subwindow mode??
- OS.gdk_window_copy_area (image.pixmap, // dest window
- xGC,
- 0, 0, // dest coords
- image.pixmap, // src window
- x, y, // src coords
- rect.width, rect.height);
- OS.gdk_gc_destroy(xGC);
-}
+ if ((width == 0) || (height == 0)) return;
+
+ /* Rewrite this to use GdkPixbuf */
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- *
- * @exception SWTException
- * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- *
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) {
- OS.gdk_window_copy_area (data.drawable, handle,
- destX, destY,
- data.drawable,
- srcX, srcY, width, height);
+ GdkGCValues values = new GdkGCValues();
+ OS.gdk_gc_get_values(handle, values);
+
+ 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 == toRGB) {
+ fillRectangle(x, y, width, height);
+ return;
+ }
+ ImageData.fillGradientRectangle(this, data.device,
+ x, y, width, height, vertical, fromRGB, toRGB,
+ 8, 8, 8);
}
-/**
- * Draws the outline of a circular or elliptical arc
- * within the specified rectangular area.
- *
- * 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.
- *
+/**
+ * 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 arc to be drawn
- * @param y the y coordinate of the upper-left corner of the arc to be drawn
- * @param width the width of the arc to be drawn
- * @param height the height of the arc to be drawn
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
+ * @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 IllegalArgumentException
- * - ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.
- *
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
+ *
+ * @see #drawOval
*/
-public void drawArc(int x, int y, int width, int height, int startAngle, int endAngle) {
+public void fillOval(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;
@@ -751,968 +1027,803 @@ public void drawArc(int x, int y, int width, int height, int startAngle, int end
y = y + height;
height = -height;
}
- if (width == 0 || height == 0 || endAngle == 0) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, startAngle * 64, endAngle * 64);
+ GdkGCValues values = new GdkGCValues();
+ OS.gdk_gc_get_values(handle, values);
+ GdkColor color = new GdkColor();
+ color.pixel = values.background_pixel;
+ color.red = values.background_red;
+ color.green = values.background_green;
+ color.blue = values.background_blue;
+ OS.gdk_gc_set_foreground(handle, color);
+ OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, 0, 23040);
+ color.pixel = values.foreground_pixel;
+ color.red = values.foreground_red;
+ color.green = values.foreground_green;
+ color.blue = values.foreground_blue;
+ OS.gdk_gc_set_foreground(handle, color);
}
+
/**
- * Draws a rectangle, based on the specified arguments, which has
- * the appearance of the platform's focus rectangle if the
- * platform supports such a notion, and otherwise draws a simple
- * rectangle in the receiver's forground color.
+ * 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 x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
+ * @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 #drawRectangle
+ * @see #drawPolygon
*/
-public void drawFocus(int x, int y, int width, int height) {
- GtkStyle style = new GtkStyle(OS.gtk_widget_get_default_style());
- GdkColor color = new GdkColor();
- color.pixel = style.fg0_pixel;
- color.red = style.fg0_red;
- color.green = style.fg0_green;
- color.blue = style.fg0_blue;
+public void fillPolygon(int[] pointArray) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
GdkGCValues values = new GdkGCValues();
OS.gdk_gc_get_values(handle, values);
+ GdkColor color = new GdkColor();
+ color.pixel = values.background_pixel;
+ color.red = values.background_red;
+ color.green = values.background_green;
+ color.blue = values.background_blue;
OS.gdk_gc_set_foreground(handle, color);
- OS.gdk_draw_rectangle(data.drawable, handle, 0, x, y, width, height);
+ OS.gdk_draw_polygon(data.drawable, handle, 1, pointArray, pointArray.length / 2);
color.pixel = values.foreground_pixel;
color.red = values.foreground_red;
color.green = values.foreground_green;
color.blue = values.foreground_blue;
OS.gdk_gc_set_foreground(handle, color);
}
-/**
- * Draws the given image in the receiver at the specified
- * coordinates.
+
+/**
+ * Fills the interior of the rectangle specified by the arguments,
+ * using the receiver's background color.
*
- * @param image the image to draw
- * @param x the x coordinate of where to draw
- * @param y the y coordinate of where to draw
+ * @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 IllegalArgumentException
- * - ERROR_NULL_ARGUMENT - if the image is null
- * - ERROR_INVALID_ARGUMENT - if the image has been disposed
- * - ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image
- * @exception SWTError
- * - ERROR_NO_HANDLES - if no handles are available to perform the operation
- *
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
- */
-public void drawImage(Image image, int x, int y) {
- if (image == null) error(SWT.ERROR_NULL_ARGUMENT);
- int pixmap = image.pixmap;
- int [] width = new int [1]; int [] height = new int [1];
- OS.gdk_drawable_get_size(pixmap, width, height);
- drawImage(image, 0, 0, width[0], height[0], x, y, width[0], height[0]);
-}
-
-/**
- * Copies a rectangular area from the source image into a (potentially
- * different sized) rectangular area in the receiver. If the source
- * and destination areas are of differing sizes, then the source
- * area will be stretched or shrunk to fit the destination area
- * as it is copied. The copy fails if any of the given coordinates
- * are negative or lie outside the bounds of their respective images.
*
- * @param image the source image
- * @param srcX the x coordinate in the source image to copy from
- * @param srcY the y coordinate in the source image to copy from
- * @param srcWidth the width in pixels to copy from the source
- * @param srcHeight the height in pixels to copy from the source
- * @param destX the x coordinate in the destination to copy to
- * @param destY the y coordinate in the destination to copy to
- * @param destWidth the width in pixels of the destination rectangle
- * @param destHeight the height in pixels of the destination rectangle
+ * @see #drawRectangle
+ */
+public void fillRectangle(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;
+ }
+ GdkGCValues values = new GdkGCValues();
+ OS.gdk_gc_get_values(handle, values);
+ GdkColor color = new GdkColor();
+ color.pixel = values.background_pixel;
+ color.red = values.background_red;
+ color.green = values.background_green;
+ color.blue = values.background_blue;
+ OS.gdk_gc_set_foreground(handle, color);
+ OS.gdk_draw_rectangle(data.drawable, handle, 1, x, y, width, height);
+ color.pixel = values.foreground_pixel;
+ color.red = values.foreground_red;
+ color.green = values.foreground_green;
+ color.blue = values.foreground_blue;
+ OS.gdk_gc_set_foreground(handle, color);
+}
+
+/**
+ * Fills the interior of the specified rectangle, using the receiver's
+ * background color.
+ *
+ * @param rectangle the rectangle to be filled
*
* @exception IllegalArgumentException
- * - ERROR_NULL_ARGUMENT - if the image is null
- * - ERROR_INVALID_ARGUMENT - if the image has been disposed
- * - ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of their respective images
- *
- * @exception SWTError
- * - ERROR_NO_HANDLES - if no handles are available to perform the operation
+ * - ERROR_NULL_ARGUMENT - if the rectangle is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
+ *
+ * @see #drawRectangle
*/
-public void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- /* basic sanity checks */
+public void fillRectangle(Rectangle rect) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
- if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- /* source image properties */
- int[] width = new int[1];
- int[] height = new int[1];
- OS.gdk_drawable_get_size(srcImage.pixmap, width, height);
- if ((srcY + srcWidth > width[0]) ||
- (srcY + srcHeight > height[0])) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- /* Special case: If we don't need to scale, and there is no alpha/mask,
- * then we can just blit the image inside the X server - no net traffic
- */
- boolean needScaling = (srcWidth != destWidth) || (srcHeight != destHeight);
- boolean simple = !needScaling & (srcImage.mask == 0);
-
- if (simple) {
- OS.gdk_draw_pixmap(data.drawable, handle, srcImage.pixmap,
- srcX, srcY,
- destX, destY,
- width[0], height[0]);
- return;
- }
-
-
- /* Fetch a local GdkPixbuf from server */
- Pixbuffer pixbuf = new Pixbuffer(srcImage);
-
- /* Scale if necessary */
- if ((srcWidth != destWidth) || (srcHeight != destHeight)) {
- double scale_x = (double)destWidth / (double)srcWidth;
- double scale_y = (double)destHeight / (double)srcHeight;
- double offset_x = - srcX * scale_x;
- double offset_y = - srcY * scale_y;
-
- int destSizePixbuf = GDKPIXBUF.gdk_pixbuf_new (
- GDKPIXBUF.GDK_COLORSPACE_RGB(),
- true, 8, destWidth, destHeight);
- GDKPIXBUF.gdk_pixbuf_scale(
- pixbuf.handle, // src,
- destSizePixbuf,
- 0,
- 0,
- destWidth, destHeight,
- offset_x, offset_y,
- scale_x, scale_y,
- GDKPIXBUF.GDK_INTERP_BILINEAR);
- pixbuf.handle = destSizePixbuf;
- }
-
- /* Paint it */
- GDKPIXBUF.gdk_pixbuf_render_to_drawable_alpha(
- pixbuf.handle,
- data.drawable,
- 0, 0,
- destX, destY,
- destWidth, destHeight,
- GDKPIXBUF.GDK_PIXBUF_ALPHA_BILEVEL, 128,
- GDKPIXBUF.GDK_RGB_DITHER_NORMAL,
- 0, 0
- );
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ fillRectangle(rect.x, rect.y, rect.width, rect.height);
}
/**
- * Draws a line, using the foreground color, between the points
- * (x1
, y1
) and (x2
, y2
).
+ * Fills the interior of the round-cornered rectangle specified by
+ * the arguments, using the receiver's background color.
*
- * @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
+ * @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 horizontal diameter of the arc at the four corners
+ * @param arcHeight the vertical diameter of the arc at the four corners
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
+ *
+ * @see #drawRoundRectangle
*/
-public void drawLine(int x1, int y1, int x2, int y2) {
- OS.gdk_draw_line (data.drawable, handle, x1, y1, x2, y2);
+public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ 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;
+
+ int naw2 = naw / 2;
+ int nah2 = nah / 2;
+
+ GdkGCValues values = new GdkGCValues();
+ OS.gdk_gc_get_values(handle, values);
+ GdkColor color = new GdkColor();
+ color.pixel = values.background_pixel;
+ color.red = values.background_red;
+ color.green = values.background_green;
+ color.blue = values.background_blue;
+ OS.gdk_gc_set_foreground(handle, color);
+
+ 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_arc(drawable, handle, 1, nx, ny + nh - nah, naw, nah, 11520, 5760);
+ OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
+ OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny, naw, nah, 0, 5760);
+ OS.gdk_draw_rectangle(drawable, handle, 1, nx + naw2, ny, nw - naw, nh);
+ OS.gdk_draw_rectangle(drawable, handle, 1, nx, ny + nah2, naw2, nh - nah);
+ OS.gdk_draw_rectangle(drawable, handle, 1, nx + nw - naw2, ny + nah2, naw2, nh -nah);
+ } 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 - naw, 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 - nah);
+ 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);
+ }
+ }
+
+ color.pixel = values.foreground_pixel;
+ color.red = values.foreground_red;
+ color.green = values.foreground_green;
+ color.blue = values.foreground_blue;
+ OS.gdk_gc_set_foreground(handle, color);
}
-/**
- * Draws the outline of an oval, using the foreground color,
- * within the specified rectangular area.
+
+/**
+ * Returns the advance width of the specified character in
+ * the font which is currently selected into the receiver.
*
- * 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.
+ * The advance width is defined as the horizontal distance the cursor
+ * should move after printing the character in the selected font.
*
*
- * @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
+ * @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 void drawOval(int x, int y, int width, int height) {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, 0, 23040);
+public int getAdvanceWidth(char ch) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+// byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch });
+// return OS.gdk_char_width(_getGCFont(), charBuffer[0]);
+ return 0;
}
+
/**
- * 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.
+ * Returns the background color.
*
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
+ * @return the receiver's background color
*
- * @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 (pointArray == null) error(SWT.ERROR_NULL_ARGUMENT);
- short[] points = new short[pointArray.length];
- for (int i = 0; i < pointArray.length; i++) {
- points[i] = (short)pointArray[i];
- }
- OS.gdk_draw_polygon(data.drawable, handle, 0, points, points.length / 2);
+public Color getBackground() {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ GdkGCValues values = new GdkGCValues();
+ OS.gdk_gc_get_values(handle, values);
+ GdkColor color = new GdkColor();
+ color.pixel = values.background_pixel;
+ color.red = values.background_red;
+ color.green = values.background_green;
+ color.blue = values.background_blue;
+ return Color.gtk_new(data.device, color);
}
-/**
- * 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.
+
+/**
+ * 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 pointArray an array of alternating x and y values which are the corners of the polyline
+ * @param ch the character to measure
+ * @return the width of the character
*
- * @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 (pointArray == null) error(SWT.ERROR_NULL_ARGUMENT);
- short[] points = new short[pointArray.length];
- for (int i = 0; i < pointArray.length; i++) {
- points[i] = (short)pointArray[i];
- }
- OS.gdk_draw_lines(data.drawable, handle, points, points.length / 2);
+public int getCharWidth(char ch) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+// byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch });
+// int[] lbearing = new int[1];
+// int[] rbearing = new int[1];
+// int[] unused = new int[1];
+// OS.gdk_string_extents(_getGCFont(), charBuffer, lbearing, rbearing, unused, unused, unused);
+// return rbearing[0] - lbearing[0];
+ return 0;
}
+
/**
- * 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
.
+ * 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.
*
- * @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
+ * @return the bounding rectangle of the clipping region
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
-public void drawRectangle(int x, int y, int width, int height) {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
+public Rectangle getClipping() {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ int clipRgn = data.clipRgn;
+ if (clipRgn == 0) {
+ int[] width = new int[1]; int[] height = new int[1];
+ OS.gdk_drawable_get_size(data.drawable, width, height);
+ return new Rectangle(0, 0, width[0], height[0]);
}
- OS.gdk_draw_rectangle(data.drawable, handle, 0, x, y, width, height);
+ GdkRectangle rect = new GdkRectangle();
+ OS.gdk_region_get_clipbox(clipRgn, rect);
+ return new Rectangle(rect.x, rect.y, rect.width, rect.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
.
+ * Sets the region managed by the argument to the current
+ * clipping region of the receiver.
*
- * @param rect the rectangle to draw
+ * @param region the region to fill with the clipping region
*
* @exception IllegalArgumentException
- * - ERROR_NULL_ARGUMENT - if the rectangle is null
+ * - ERROR_NULL_ARGUMENT - if the region is null
*
* @exception SWTException
* - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
*
*/
-public void drawRectangle(Rectangle rect) {
- if (rect == null) error(SWT.ERROR_NULL_ARGUMENT);
- drawRectangle (rect.x, rect.y, rect.width, rect.height);
+public void getClipping(Region region) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ int hRegion = region.handle;
+ int clipRgn = data.clipRgn;
+ OS.gdk_region_subtract(hRegion, hRegion);
+ if (data.clipRgn == 0) {
+ int[] width = new int[1]; int[] height = new int[1];
+ OS.gdk_drawable_get_size(data.drawable, width, height);
+ GdkRectangle rect = new GdkRectangle();
+ rect.x = 0; rect.y = 0;
+ rect.width = width[0]; rect.height = height[0];
+ OS.gdk_region_union_with_rect(hRegion, rect);
+ return;
+ }
+ OS.gdk_region_union(hRegion, clipRgn);
}
/**
- * 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.
+ * Returns the font currently being used by the receiver
+ * to draw and measure text.
*
- * @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 horizontal diameter of the arc at the four corners
- * @param arcHeight the vertical diameter of the arc at the four corners
+ * @return the receiver's font
*
* @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) {
- 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;
-
- int naw2 = Compatibility.floor(naw, 2);
- int nah2 = Compatibility.floor(nah, 2);
-
- OS.gdk_draw_arc(data.drawable, handle, 0, nx, ny, naw, nah, 5760, 5760);
- OS.gdk_draw_arc(data.drawable, handle, 0, nx, ny + nh - nah, naw, nah, 11520, 5760);
- OS.gdk_draw_arc(data.drawable, handle, 0, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
- OS.gdk_draw_arc(data.drawable, handle, 0, nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.gdk_draw_line(data.drawable, handle, nx + naw2, ny, nx + nw - naw2, ny);
- OS.gdk_draw_line(data.drawable, handle, nx,ny + nah2, nx, ny + nh - nah2);
- OS.gdk_draw_line(data.drawable, handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
- OS.gdk_draw_line(data.drawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
+public Font getFont() {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+// return Font.gtk_new(_getGCFont());
+ return null;
}
+
+/**
+ * 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);
+// int fontHandle = _getGCFont();
+// if (fontHandle==0) {
+// SWT.error(SWT.ERROR_UNSPECIFIED);
+// }
+// return FontMetrics.gtk_new(fontHandle);
+ return null;
+}
+
/**
- * 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.
+ * Returns the receiver's foreground 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
+ * @return the color used for drawing foreground things
*
- * @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);
+public Color getForeground() {
+ if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
+ GdkGCValues values = new GdkGCValues();
+ OS.gdk_gc_get_values(handle, values);
+ GdkColor color = new GdkColor();
+ color.pixel = values.foreground_pixel;
+ color.red = values.foreground_red;
+ color.green = values.foreground_green;
+ color.blue = values.foreground_blue;
+ return Color.gtk_new(data.device, color);
}
+
/**
- * 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.
+ * 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
.
*
- * @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
+ * @return the style used for drawing lines
*
- * @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) {
- if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- byte[] buffer1 = Converter.wcsToMbcs(null, "Y", true);
- int[] unused = new int[1];
- int[] width = new int[1];
- int[] ascent = new int[1];
- int[] average_ascent = new int [1];
- int fontHandle = _getGCFont();
- OS.gdk_string_extents(fontHandle, buffer, unused, unused, width, ascent, unused);
- OS.gdk_string_extents(fontHandle, buffer1, unused, unused, unused, average_ascent, unused);
- if (ascent[0]drawLine, drawRectangle
,
+ * drawPolyline
, and so forth.
*
- * @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
+ * @return the receiver's line width
*
- * @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, false);
+public int getLineWidth() {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ GdkGCValues values = new GdkGCValues();
+ OS.gdk_gc_get_values(handle, values);
+ return values.line_width;
}
+
/**
- * 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.
+ * 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.
*
- * @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
+ * @return true
true if the receiver is in XOR mode, and false otherwise
*
- * @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) {
- if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- byte[] buffer1 = Converter.wcsToMbcs(null, "Y", true);
- int fontHandle = _getGCFont();
- int[] unused = new int[1];
- int[] width = new int[1];
- int[] ascent = new int[1];
- int[] average_ascent = new int [1];
- OS.gdk_string_extents(fontHandle, buffer, unused, unused, width, ascent, unused);
- OS.gdk_string_extents(fontHandle, buffer1, unused, unused, unused, average_ascent, unused);
- if (ascent[0]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 handle;
+}
+
+void init(Drawable drawable, GCData data, int gdkGC) {
+ GdkColor foreground = data.foreground;
+ if (foreground != null) OS.gdk_gc_set_foreground(gdkGC, foreground);
+ GdkColor background = data.background;
+ if (background != null) OS.gdk_gc_set_background (gdkGC, background);
+ 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();
}
- OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer);
+ this.drawable = drawable;
+ this.data = data;
+ handle = gdkGC;
}
-/**
- * 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
- *
- *
+/**
+ * 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)
.
*
- * @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 specifing how to process the text
+ * @return true
if the GC has a clipping region, and false
otherwise
*
- * @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) {
- // NOT IMPLEMENTED
- drawText(string, x, y, (flags & SWT.DRAW_TRANSPARENT) != 0);
+public boolean isClipped() {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ return data.clipRgn != 0;
}
/**
- * Fills the interior of a circular or elliptical arc within
- * the specified rectangular area, with the receiver's background
- * color.
+ * Returns true
if the GC has been disposed,
+ * and false
otherwise.
*
- * 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.
- *
+ * This method gets the dispose state for the GC.
+ * When a GC has been disposed, it is an error to
+ * invoke any other method using the GC.
*
- * @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
+ * @return true
when the GC is disposed and false
otherwise
+ */
+public boolean isDisposed() {
+ return handle == 0;
+}
+
+/**
+ * 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_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.
+ * - 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
*
- *
- * @see #drawArc
*/
-public void fillArc(int x, int y, int width, int height, int startAngle, int endAngle) {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || endAngle == 0) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- color.red = values.background_red;
- color.green = values.background_green;
- color.blue = values.background_blue;
- OS.gdk_gc_set_foreground(handle, color);
- OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, startAngle * 64, endAngle * 64);
- color.pixel = values.foreground_pixel;
- color.red = values.foreground_red;
- color.green = values.foreground_green;
- color.blue = values.foreground_blue;
- OS.gdk_gc_set_foreground(handle, color);
+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);
+ OS.gdk_gc_set_background(handle, color.handle);
}
/**
- * 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.
+ * 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 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
+ * @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
*
- *
- * @see #drawRectangle
*/
-public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
+public void setClipping(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if ((width == 0) || (height == 0)) return;
-
- /* Rewrite this to use GdkPixbuf */
-
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor foregroundGdkColor = new GdkColor();
-
- RGB backgroundRGB, foregroundRGB;
- backgroundRGB = Color.gtk_getRGBIntensities(_getBackgroundGdkColor());
- foregroundRGB = Color.gtk_getRGBIntensities(_getForegroundGdkColor());
-
- 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 == toRGB) {
- fillRectangle(x, y, width, height);
- return;
+ int clipRgn = data.clipRgn;
+ if (clipRgn == 0) {
+ data.clipRgn = clipRgn = OS.gdk_region_new();
+ } else {
+ OS.gdk_region_subtract(clipRgn, clipRgn);
}
- ImageData.fillGradientRectangle(this, Display.getCurrent(),
- x, y, width, height, vertical, fromRGB, toRGB,
- 8, 8, 8);
+ GdkRectangle rect = new GdkRectangle();
+ rect.x = x; rect.y = y;
+ rect.width = width; rect.height = height;
+ OS.gdk_gc_set_clip_rectangle(handle, rect);
+ OS.gdk_region_union_with_rect(clipRgn, rect);
}
-
-/**
- * Fills the interior of an oval, within the specified
- * rectangular area, with the receiver's background
- * color.
+/**
+ * Sets the area of the receiver which can be changed
+ * by drawing operations to the rectangular area specified
+ * by the argument.
*
- * @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
+ * @param rect the clipping rectangle
*
* @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 (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
+public void setClipping(Rectangle rect) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ int clipRgn = data.clipRgn;
+ if (rect == null) {
+ OS.gdk_gc_set_clip_region(handle, 0);
+ if (clipRgn != 0) {
+ OS.gdk_region_destroy(clipRgn);
+ data.clipRgn = clipRgn = 0;
+ }
+ return;
}
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- color.red = values.background_red;
- color.green = values.background_green;
- color.blue = values.background_blue;
- OS.gdk_gc_set_foreground(handle, color);
- OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, 0, 23040);
- color.pixel = values.foreground_pixel;
- color.red = values.foreground_red;
- color.green = values.foreground_green;
- color.blue = values.foreground_blue;
- OS.gdk_gc_set_foreground(handle, color);
+ setClipping (rect.x, rect.y, rect.width, rect.height);
}
-/**
- * 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.
+/**
+ * Sets the area of the receiver which can be changed
+ * by drawing operations to the region specified
+ * by the argument.
*
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
+ * @param rect the clipping region.
*
- * @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 (pointArray == null) error(SWT.ERROR_NULL_ARGUMENT);
- short[] points = new short[pointArray.length];
- for (int i = 0; i < pointArray.length; i++) {
- points[i] = (short)pointArray[i];
+public void setClipping(Region region) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ int clipRgn = data.clipRgn;
+ if (region == null) {
+ OS.gdk_gc_set_clip_region(handle, 0);
+ if (clipRgn != 0) {
+ OS.gdk_region_destroy(clipRgn);
+ data.clipRgn = clipRgn = 0;
+ }
+ } else {
+ if (clipRgn == 0) {
+ data.clipRgn = clipRgn = OS.gdk_region_new();
+ } else {
+ OS.gdk_region_subtract(clipRgn, clipRgn);
+ }
+ OS.gdk_region_union(clipRgn, region.handle);
+ OS.gdk_gc_set_clip_region(handle, clipRgn);
}
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- color.red = values.background_red;
- color.green = values.background_green;
- color.blue = values.background_blue;
- OS.gdk_gc_set_foreground(handle, color);
- OS.gdk_draw_polygon(data.drawable, handle, 1, points, points.length / 2);
- color.pixel = values.foreground_pixel;
- color.red = values.foreground_red;
- color.green = values.foreground_green;
- color.blue = values.foreground_blue;
- OS.gdk_gc_set_foreground(handle, color);
}
+
/**
- * Fills the interior of the rectangle specified by the arguments,
- * using the receiver's background color.
+ * 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 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 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
*
- *
- * @see #drawRectangle
*/
-public void fillRectangle(int x, int y, int width, int height) {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
+public void setFont(Font font) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+/* int fontHandle = 0;
+ if (font == null) {
+ GtkStyle gtkStyle = new GtkStyle();
+ int style = OS.gtk_widget_get_default_style();
+ OS.memmove(gtkStyle, style, GtkStyle.sizeof);
+ fontHandle = gtkStyle.font;
+ } else {
+ fontHandle = font.handle;
}
-
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- color.red = values.background_red;
- color.green = values.background_green;
- color.blue = values.background_blue;
- OS.gdk_gc_set_foreground(handle, color);
- OS.gdk_draw_rectangle(data.drawable, handle, 1, x, y, width, height);
- color.pixel = values.foreground_pixel;
- color.red = values.foreground_red;
- color.green = values.foreground_green;
- color.blue = values.foreground_blue;
- OS.gdk_gc_set_foreground(handle, color);
+ OS.gdk_gc_set_font(handle, fontHandle);*/
}
-/**
- * Fills the interior of the specified rectangle, using the receiver's
- * background color.
+
+/**
+ * Sets the foreground color. The foreground color is used
+ * for drawing operations including when text is drawn.
*
- * @param rectangle the rectangle to be filled
+ * @param color the new foreground color for the receiver
*
* @exception IllegalArgumentException
- * - ERROR_NULL_ARGUMENT - if the rectangle is null
+ * - 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
*
- *
- * @see #drawRectangle
*/
-public void fillRectangle(Rectangle rect) {
- if (rect == null) error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle(rect.x, rect.y, rect.width, rect.height);
+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);
+ OS.gdk_gc_set_foreground(handle, color.handle);
}
+
/**
- * Fills the interior of the round-cornered rectangle specified by
- * the arguments, using the receiver's background color.
+ * 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 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 horizontal diameter of the arc at the four corners
- * @param arcHeight the vertical diameter of the arc at the four corners
+ * @param lineStyle the style to be used for drawing lines
*
* @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) {
- 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;
+public void setLineStyle(int lineStyle) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ switch (lineStyle) {
+ case SWT.LINE_SOLID:
+ this.data.lineStyle = lineStyle;
+ OS.gdk_gc_set_line_attributes(handle, 0, OS.GDK_LINE_SOLID, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER);
+ return;
+ case SWT.LINE_DASH:
+ OS.gdk_gc_set_dashes(handle, 0, new byte[] {6, 2}, 2);
+ break;
+ case SWT.LINE_DOT:
+ OS.gdk_gc_set_dashes(handle, 0, new byte[] {3, 1}, 2);
+ break;
+ case SWT.LINE_DASHDOT:
+ OS.gdk_gc_set_dashes(handle, 0, new byte[] {6, 2, 3, 1}, 4);
+ break;
+ case SWT.LINE_DASHDOTDOT:
+ OS.gdk_gc_set_dashes(handle, 0, new byte[] {6, 2, 3, 1, 3, 1}, 6);
+ break;
+ default:
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
- if (naw < 0)
- naw = 0 - naw;
- if (nah < 0)
- nah = 0 - nah;
-
- naw = Math.min(naw,nw);
- nah = Math.min(nah, nh);
-
- int naw2 = Compatibility.round(naw, 2);
- int nah2 = Compatibility.round(nah, 2);
-
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- color.red = values.background_red;
- color.green = values.background_green;
- color.blue = values.background_blue;
- OS.gdk_gc_set_foreground(handle, color);
- OS.gdk_draw_arc(data.drawable, handle, 1, nx, ny, naw, nah, 5760, 5760);
- OS.gdk_draw_arc(data.drawable, handle, 1, nx, ny + nh - nah, naw, nah, 11520, 5760);
- OS.gdk_draw_arc(data.drawable, handle, 1, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
- OS.gdk_draw_arc(data.drawable, handle, 1, nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.gdk_draw_rectangle(data.drawable, handle, 1, nx + naw2, ny, nw - naw, nh);
- OS.gdk_draw_rectangle(data.drawable, handle, 1, nx, ny + nah2, naw2, nh - nah);
- OS.gdk_draw_rectangle(data.drawable, handle, 1, nx + nw - (naw / 2), ny + nah2, naw2, nh -nah);
- color.pixel = values.foreground_pixel;
- color.red = values.foreground_red;
- color.green = values.foreground_green;
- color.blue = values.foreground_blue;
- OS.gdk_gc_set_foreground(handle, color);
+ data.lineStyle = lineStyle;
+ OS.gdk_gc_set_line_attributes(handle, 0, OS.GDK_LINE_DOUBLE_DASH, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER);
}
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the same object using a class
- * specific comparison.
+/**
+ * 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.
*
- * @param object the object to compare with this object
- * @return true
if the object is the same as this object and false
otherwise
+ * @param lineWidth the width of a line
*
- * @see #hashCode
- */
-/*
- * === As yet unclassified ===
+ * @exception SWTException
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
*/
-
-public boolean equals(Object object) {
- return (object == this) || ((object instanceof GC) && (handle == ((GC)object).handle));
+public void setLineWidth(int width) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (data.lineStyle == SWT.LINE_SOLID) {
+ OS.gdk_gc_set_line_attributes(handle, width, OS.GDK_LINE_SOLID, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER);
+ } else {
+ OS.gdk_gc_set_line_attributes(handle, width, OS.GDK_LINE_DOUBLE_DASH, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER);
+ }
}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects which return true
when passed to
- * equals
must return the same value for this
- * method.
+
+/**
+ * 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.
*
- * @return the receiver's hash
+ * @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
*
- *
- * @see #equals
*/
-public int hashCode() {
- return handle;
-}
-void error(int code) {
- throw new SWTError(code);
+public void setXORMode(boolean val) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ OS.gdk_gc_set_function(handle, val ? OS.GDK_XOR : OS.GDK_COPY);
}
+
/**
- * Returns true
if the GC has been disposed,
- * and false
otherwise.
+ * Returns the extent of the given string. No tab
+ * expansion or carriage return processing will be performed.
*
- * This method gets the dispose state for the GC.
- * When a GC has been disposed, it is an error to
- * invoke any other method using the GC.
+ * 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).
+ *
*
- * @return true
when the GC is disposed and false
otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-/**
- * Disposes of the operating system resources associated with
- * the graphics context. Applications must dispose of all GCs
- * which they allocate.
+ * @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 void dispose() {
- if (handle == 0) return;
-
- /* Free resources */
- int clipRgn = data.clipRgn;
- if (clipRgn != 0) OS.gdk_region_destroy(clipRgn);
- Image image = data.image;
- if (image != null) image.memGC = null;
-
- /* Dispose the GC */
- if(drawable == null)
- OS.gdk_gc_unref(handle);
- else
- drawable.internal_dispose_GC(handle, data);
-
- data.drawable = // data.colormap = data.fontList =
- data.clipRgn = data.renderTable = 0;
- drawable = null;
- data.image = null;
- data = null;
- handle = 0;
-
+public Point stringExtent(String string) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ byte[] buffer = Converter.wcsToMbcs(null, string, true);
+ int width = OS.gdk_string_width(_getGCFont(), buffer);
+ int height = OS.gdk_string_height(_getGCFont(), buffer);
+ return new Point(width, height);
}
-
/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
+ * 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).
+ *
*
- * @return a string representation of 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 String toString () {
- if (isDisposed()) return "GC {*DISPOSED*}";
- return "GC {" + handle + "}";
+public Point textExtent(String string) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ byte[] buffer = Converter.wcsToMbcs(null, string, true);
+ int width = OS.gdk_string_width(_getGCFont(), buffer);
+ int height = OS.gdk_string_height(_getGCFont(), buffer);
+ return new Point(width, height);
}
/**
@@ -1751,4 +1862,25 @@ public Point textExtent(String string, int flags) {
return textExtent(string);
}
+/**
+ * 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 + "}";
+}
+
+private int _getGCFont() {
+ GdkGCValues values = new GdkGCValues();
+ OS.gdk_gc_get_values(handle, values);
+ if (values.font==0) {
+ values.font = OS.gdk_font_load(Converter.wcsToMbcs(null, "fixed", true));
+ if (values.font == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ return values.font;
+}
+
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
index b95ab8104d..a9b1aaf5aa 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
@@ -6,7 +6,6 @@ package org.eclipse.swt.graphics;
*/
import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
import java.io.*;
@@ -111,12 +110,6 @@ public final class Image implements Drawable{
* Warning: This field is platform dependent.
*/
static final int DEFAULT_SCANLINE_PAD = 4;
-
-
-
-/*
- * CONSTRUCTORS
- */
Image() {
}
@@ -132,6 +125,12 @@ Image() {
* gc.drawRectangle(0, 0, 50, 50);
* gc.dispose();
*
+ *
+ * Note: Some platforms may have a limitation on the size
+ * of image that can be created (size depends on width, height,
+ * and depth). For example, Windows 95, 98, and ME do not allow
+ * images larger than 16M.
+ *
*
* @param device the device on which to create the image
* @param width the width of the new image
@@ -142,9 +141,9 @@ Image() {
*
*/
public Image(Device display, int width, int height) {
- init(display, width, height);
-
- if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ init(device, width, height);
}
/**
@@ -178,72 +177,122 @@ public Image(Device display, int width, int height) {
*
*/
public Image(Device device, Image srcImage, int flag) {
- /* basic sanity */
if (device == null) device = Device.getDevice();
if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ switch (flag) {
+ case SWT.IMAGE_COPY:
+ case SWT.IMAGE_DISABLE:
+ case SWT.IMAGE_GRAY:
+ break;
+ default:
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ this.device = device;
this.type = srcImage.type;
- this.mask = 0;
- /* this is somewhat ugly, because this dilutes the encapsulation
- * of knowledge about what the cloning operations do (e.g., the
- * following lines assume graying and disabling don't change alpha)
- */
- this.alphaData = srcImage.alphaData;
- this.alpha = srcImage.alpha;
- this.transparentPixel = srcImage.transparentPixel;
- // FIXME - are we sure about memGC?
-
- /* Special case:
- * If all we want is just a clone of the existing pixmap, it can
- * be done entirely in the X server, without copying across the net.
- */
- if (flag == SWT.IMAGE_COPY) {
- int[] width = new int[1]; int[] height = new int[1];
- OS.gdk_drawable_get_size(srcImage.pixmap, width, height);
- int depth = OS.gdk_drawable_get_depth(srcImage.pixmap);
- pixmap = OS.gdk_pixmap_new (0, width[0], height[0], depth);
-
- int gc = OS.gdk_gc_new (pixmap);
- OS.gdk_draw_pixmap(pixmap, gc, srcImage.pixmap,
- 0,0,0,0, width[0], height[0]);
- OS.gdk_gc_destroy(gc);
+ /* Get source image size */
+ int[] w = new int[1], h = new int[1];
+ OS.gdk_drawable_get_size(srcImage.pixmap, w, h);
+ int width = w[0];
+ int height = h[0];
+
+ /* Copy the mask */
+ if (srcImage.mask != 0 || srcImage.transparentPixel != -1) {
+ /* Generate the mask if necessary. */
+ if (srcImage.transparentPixel != -1) srcImage.createMask();
+ int mask = OS.gdk_pixmap_new(0, width, height, 1);
+ if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int gdkGC = OS.gdk_gc_new(mask);
+ if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ OS.gdk_draw_drawable(mask, gdkGC, srcImage.mask, 0, 0, 0, 0, width, height);
+ OS.g_object_unref(gdkGC);
+ this.mask = mask;
+ /* Destroy the image mask if the there is a GC created on the image */
+ if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask();
+ }
+
+ /* Copy transparent pixel and alpha data when necessary */
+ if (flag != SWT.IMAGE_DISABLE) {
transparentPixel = srcImage.transparentPixel;
alpha = srcImage.alpha;
if (srcImage.alphaData != null) {
alphaData = new byte[srcImage.alphaData.length];
System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
}
-
- /* we are not quite done yet. Need to copy the maskData */
- if (srcImage.mask != 0) {
- /* Generate the mask if necessary. */
-// if (srcImage.transparentPixel != -1) srcImage.createMask();
- mask = OS.gdk_pixmap_new(0, width[0], height[0], 1);
- gc = OS.gdk_gc_new(mask);
- OS.gdk_draw_pixmap(mask, gc, srcImage.mask,
- 0,0,0,0, width[0], height[0]);
- OS.gdk_gc_destroy(gc);
- /* Destroy the image mask if the there is a GC created on the image */
- if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask();
- }
+ }
+ /* Create the new pixmap */
+ int pixmap = OS.gdk_pixmap_new (OS.GDK_ROOT_PARENT(), width, height, -1);
+ if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int gdkGC = OS.gdk_gc_new(pixmap);
+ if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ this.pixmap = pixmap;
- if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
-
+ if (flag == SWT.IMAGE_COPY) {
+ OS.gdk_draw_drawable(pixmap, gdkGC, srcImage.pixmap, 0, 0, 0, 0, width, height);
+ OS.g_object_unref(gdkGC);
return;
}
-
-
-
-
- Pixbuffer pb = new Pixbuffer(srcImage);
- Pixbuffer pb2 = new Pixbuffer(pb, flag);
- pb2.toImage(this);
+ /* Retrieve the source pixmap data */
+ int pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB(), false, 8, width, height);
+ if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int colormap = OS.gdk_colormap_get_system();
+ OS.gdk_pixbuf_get_from_drawable(pixbuf, srcImage.pixmap, colormap, 0, 0, 0, 0, width, height);
+ int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
+ int pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
+
+ /* Apply transformation */
+ switch (flag) {
+ case SWT.IMAGE_DISABLE: {
+ byte[] line = new byte[stride];
+ for (int y=0; y> 3);
+ line[offset] = line[offset+1] = line[offset+2] = intensity;
+ }
+ OS.memmove(pixels + (y * stride), line, stride);
+ }
+ transparentPixel = srcImage.transparentPixel;
+ alpha = srcImage.alpha;
+ if (srcImage.alphaData != null) {
+ alphaData = new byte[srcImage.alphaData.length];
+ System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
+ }
+ break;
+ }
+ }
+ /* Copy data back to destination pixmap */
+ OS.gdk_pixbuf_render_to_drawable(pixbuf, pixmap, gdkGC, 0, 0, 0, 0, width, height, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
+
+ /* Free resources */
+ OS.g_object_unref(pixbuf);
+ OS.g_object_unref(gdkGC);
}
/**
@@ -257,6 +306,12 @@ public Image(Device device, Image srcImage, int flag) {
* gc.drawRectangle(0, 0, 50, 50);
* gc.dispose();
*
+ *
+ * Note: Some platforms may have a limitation on the size
+ * of image that can be created (size depends on width, height,
+ * and depth). For example, Windows 95, 98, and ME do not allow
+ * images larger than 16M.
+ *
*
* @param device the device on which to create the image
* @param bounds a rectangle specifying the image's width and height (must not be null)
@@ -267,10 +322,10 @@ public Image(Device device, Image srcImage, int flag) {
*
*/
public Image(Device display, Rectangle bounds) {
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(display, bounds.width, bounds.height);
-
- if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
+ init(device, bounds.width, bounds.height);
}
/**
@@ -284,12 +339,10 @@ public Image(Device display, Rectangle bounds) {
* ERROR_NULL_ARGUMENT - if the image data is null
*
*/
-public Image(Device display, ImageData image) {
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (display == null) display = Display.getDefault();
- init(display, image);
-
- if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
+public Image(Device device, ImageData data) {
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ init(device, data);
}
/**
@@ -320,27 +373,14 @@ public Image(Device display, ImageData image) {
public Image(Device display, ImageData source, ImageData mask) {
if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (display == null) display = Display.getDefault();
- if (source.width != mask.width || source.height != mask.height) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (source.width != mask.width || source.height != mask.height) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- ImageData image;
- if (source.depth != 1)
- image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
- else {
- image = source.getTransparencyMask(); //create an imagedata with scanlinepad == 1 and invalid data
- int[] row = new int[source.width];
- for (int y = 0; y < source.height; y++) {
- source.getPixels(0, y, source.width, row, 0);
- image.setPixels(0, y, source.width, row, 0);
- }//change source data format from scanlinePad == 4 to scanlinePad == 1;
-
- }
- image.type = SWT.ICON;
+ ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
image.maskPad = mask.scanlinePad;
image.maskData = mask.data;
- init(display, image);
-
- if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
+ init(device, image);
}
/**
@@ -368,12 +408,10 @@ public Image(Device display, ImageData source, ImageData mask) {
* ERROR_IO - if an IO error occurs while reading data
*
*/
-public Image(Device display, InputStream stream) {
- if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (display == null) display = Display.getDefault();
- init(display, new ImageData(stream));
-
- if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
+public Image(Device device, InputStream stream) {
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ init(device, new ImageData(stream));
}
/**
@@ -395,11 +433,27 @@ public Image(Device display, InputStream stream) {
*
*/
public Image(Device display, String filename) {
- if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (display == null) display = Display.getDefault();
- init(display, new ImageData(filename));
-
- if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ init(device, new ImageData(filename));
+}
+
+/**
+ * Create the receiver's mask if necessary.
+ */
+void createMask() {
+ if (mask != 0) return;
+ ImageData maskImage = getImageData().getTransparencyMask();
+ byte[] maskData = maskImage.data;
+ for (int i = 0; i < maskData.length; i++) {
+ byte s = maskData[i];
+ maskData[i] = (byte)(((s & 0x80) >> 7) | ((s & 0x40) >> 5) |
+ ((s & 0x20) >> 3) | ((s & 0x10) >> 1) | ((s & 0x08) << 1) |
+ ((s & 0x04) << 3) | ((s & 0x02) << 5) | ((s & 0x01) << 7));
+ }
+ int mask = OS.gdk_bitmap_create_from_data(0, maskData, maskImage.bytesPerLine * 8, maskImage.height);
+ if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ this.mask = mask;
}
/**
@@ -407,7 +461,7 @@ public Image(Device display, String filename) {
*/
void destroyMask() {
if (mask == 0) return;
- OS.gdk_bitmap_unref(mask);
+ OS.g_object_unref(mask);
mask = 0;
}
@@ -417,11 +471,15 @@ void destroyMask() {
* they allocate.
*/
public void dispose () {
- if (pixmap != 0) OS.gdk_pixmap_unref(pixmap);
- if (mask != 0) OS.gdk_pixmap_unref(mask);
+ if (pixmap == 0) return;
+ if (device.isDisposed()) return;
+ if (pixmap != 0) OS.g_object_unref(pixmap);
+ if (mask != 0) OS.g_object_unref(mask);
+ device = null;
pixmap = mask = 0;
memGC = null;
}
+
/**
* Compares the argument to the receiver, and returns true
* if they represent the same object using a class
@@ -433,9 +491,12 @@ public void dispose () {
* @see #hashCode
*/
public boolean equals (Object object) {
- return (object == this) || ((object instanceof Image) &&
- (pixmap == ((Image)object).pixmap) &&
- (mask == ((Image)object).mask));
+ if (object == this) return true;
+ if (!(object instanceof Image)) return false;
+ Image image = (Image)object;
+ return device == image.device && pixmap == image.pixmap &&
+ transparentPixel == image.transparentPixel &&
+ mask == image.mask;
}
/**
@@ -457,48 +518,12 @@ public boolean equals (Object object) {
*
*/
public Color getBackground() {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (transparentPixel == -1) return null;
+ //NOT DONE
return null;
}
-/**
- * Sets the color to which to map the transparent pixel.
- *
- * There are certain uses of Images
that do not support
- * transparency (for example, setting an image into a button or label).
- * In these cases, it may be desired to simulate transparency by using
- * the background color of the widget to paint the transparent pixels
- * of the image. This method specifies the color that will be used in
- * these cases. For example:
- *
- * Button b = new Button();
- * image.setBackground(b.getBackground());>
- * b.setImage(image);
- *
- *
- * The image may be modified by this operation (in effect, the
- * transparent regions may be filled with the supplied color). Hence
- * this operation is not reversible and it is not legal to call
- * this function twice or with a null argument.
- *
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- *
- *
- * @param color the color to use when a transparent pixel is specified
- *
- * @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 (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
/**
* Returns the bounds of the receiver. The rectangle will always
* have x and y values of 0, and the width and height of the
@@ -512,11 +537,12 @@ public void setBackground(Color color) {
*
*/
public Rectangle getBounds() {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
int[] width = new int[1]; int[] height = new int[1];
OS.gdk_drawable_get_size(pixmap, width, height);
return new Rectangle(0, 0, width[0], height[0]);
-
}
+
/**
* Returns an ImageData
based on the receiver
* Modifications made to this ImageData
will not
@@ -532,17 +558,83 @@ public Rectangle getBounds() {
* @see ImageData
*/
public ImageData getImageData() {
- return new Pixbuffer(this).getImageData();
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+
+ int[] w = new int[1], h = new int[1];
+ OS.gdk_drawable_get_size(pixmap, w, h);
+ int width = w[0], height = h[0];
+ int pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB(), false, 8, width, height);
+ if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int colormap = OS.gdk_colormap_get_system();
+ OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height);
+ int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
+ int pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
+ byte[] srcData = new byte[stride * height];
+ OS.memmove(srcData, pixels, srcData.length);
+ OS.g_object_unref(pixbuf);
+
+ PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
+ ImageData data = new ImageData(width, height, 24, palette);
+ data.data = srcData;
+ data.bytesPerLine = stride;
+
+ if (transparentPixel == -1 && type == SWT.ICON && mask != 0) {
+ /* Get the icon mask data */
+ int gdkImagePtr = OS.gdk_drawable_get_image(mask, 0, 0, width, height);
+ if (gdkImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ GdkImage gdkImage = new GdkImage(gdkImagePtr);
+ byte[] maskData = new byte[gdkImage.bpl * height];
+ OS.memmove(maskData, gdkImage.mem, maskData.length);
+ OS.g_object_unref(gdkImagePtr);
+
+ data.maskPad = 4;
+ data.maskData = maskData;
+ /* Bit swap the mask data if necessary */
+ if (gdkImage.byte_order == OS.GDK_LSB_FIRST) {
+ for (int i = 0; i < maskData.length; i++) {
+ byte b = maskData[i];
+ maskData[i] = (byte)(((b & 0x01) << 7) | ((b & 0x02) << 5) |
+ ((b & 0x04) << 3) | ((b & 0x08) << 1) | ((b & 0x10) >> 1) |
+ ((b & 0x20) >> 3) | ((b & 0x40) >> 5) | ((b & 0x80) >> 7));
+ }
+ }
+ }
+ data.transparentPixel = transparentPixel;
+ data.alpha = alpha;
+ if (alpha == -1 && alphaData != null) {
+ data.alphaData = new byte[alphaData.length];
+ System.arraycopy(alphaData, 0, data.alphaData, 0, alphaData.length);
+ }
+ return data;
}
-public static Image gtk_new(int type, int pixmap, int mask) {
+/**
+ * Invokes platform specific functionality to allocate a new image.
+ *
+ * IMPORTANT: This method is not part of the public
+ * API for Image
. 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.
+ *
+ *
+ * @param device the device on which to allocate the color
+ * @param type the type of the image (SWT.BITMAP
or SWT.ICON
)
+ * @param pixmap the OS handle for the image
+ * @param mask the OS handle for the image mask
+ *
+ * @private
+ */
+public static Image gtk_new(Device device, int type, int pixmap, int mask) {
+ if (device == null) device = Device.getDevice();
Image image = new Image();
- if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO); // FIXME remove this, this is for debugging only
image.type = type;
image.pixmap = pixmap;
image.mask = mask;
+ image.device = device;
return image;
}
+
/**
* Returns an integer hash code for the receiver. Any two
* objects which return true
when passed to
@@ -556,6 +648,138 @@ public static Image gtk_new(int type, int pixmap, int mask) {
public int hashCode () {
return pixmap;
}
+
+void init(Device device, int width, int height) {
+ if (width <= 0 || height <= 0) {
+ SWT.error (SWT.ERROR_INVALID_ARGUMENT);
+ }
+ this.device = device;
+ this.type = SWT.BITMAP;
+
+ /* Create the pixmap */
+ this.pixmap = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, -1);
+ if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ /* Fill the bitmap with white */
+ GdkColor white = new GdkColor();
+ white.red = (short)0xFFFF;
+ white.green = (short)0xFFFF;
+ white.blue = (short)0xFFFF;
+ int colormap = OS.gdk_colormap_get_system();
+ OS.gdk_colormap_alloc_color(colormap, white, true, true);
+ int gdkGC = OS.gdk_gc_new(pixmap);
+ OS.gdk_gc_set_foreground(gdkGC, white);
+ OS.gdk_draw_rectangle(pixmap, gdkGC, 1, 0, 0, width, height);
+ OS.g_object_unref(gdkGC);
+ OS.gdk_colormap_free_colors(colormap, white, 1);
+}
+
+void init(Device device, ImageData image) {
+ if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ this.device = device;
+ int width = image.width;
+ int height = image.height;
+ PaletteData palette = image.palette;
+ int pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB(), false, 8, width, height);
+ if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
+ int data = OS.gdk_pixbuf_get_pixels(pixbuf);
+ if (palette.isDirect) {
+ int redMask = palette.redMask;
+ int greenMask = palette.greenMask;
+ int blueMask = palette.blueMask;
+ int redShift = palette.redShift;
+ int greenShift = palette.greenShift;
+ int blueShift = palette.blueShift;
+ int[] pixels = new int[width];
+ byte[] rgbPixels = new byte[stride];
+ for (int y=0; y>> -redShift : r << redShift;
+ int g = pixel & greenMask;
+ g = (greenShift < 0) ? g >>> -greenShift : g << greenShift;
+ int b = pixel & blueMask;
+ b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;
+ rgbPixels[offset] = (byte)r;
+ rgbPixels[offset + 1] = (byte)g;
+ rgbPixels[offset + 2] = (byte)b;
+ }
+ OS.memmove(data + (stride * y), rgbPixels, rgbPixels.length);
+ }
+ } else {
+ RGB[] rgbs = palette.colors;
+ byte[] pixels = new byte[width];
+ byte[] rgbPixels = new byte[stride];
+ for (int y=0; y> 7) | ((s & 0x40) >> 5) |
+ ((s & 0x20) >> 3) | ((s & 0x10) >> 1) | ((s & 0x08) << 1) |
+ ((s & 0x04) << 3) | ((s & 0x02) << 5) | ((s & 0x01) << 7));
+ }
+ int mask = OS.gdk_bitmap_create_from_data(0, maskData, maskImage.bytesPerLine * 8 , height);
+ if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ this.mask = mask;
+ if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK) {
+ this.type = SWT.ICON;
+ } else {
+ this.type = SWT.BITMAP;
+ }
+ } else {
+ this.type = SWT.BITMAP;
+ this.mask = 0;
+ this.alpha = image.alpha;
+ if (image.alpha == -1 && image.alphaData != null) {
+ this.alphaData = new byte[image.alphaData.length];
+ System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length);
+ }
+ }
+ this.pixmap = pixmap;
+}
+
/**
* Invokes platform specific functionality to allocate a new GC handle.
*
@@ -573,16 +797,18 @@ public int hashCode () {
*/
public int internal_new_GC (GCData data) {
if (pixmap == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
if (type != SWT.BITMAP || memGC != null) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
-
- data.image = this;
- int gc = OS.gdk_gc_new(pixmap);
- data.drawable = pixmap;
- return gc;
+ int gdkGC = OS.gdk_gc_new(pixmap);
+ if (data != null) {
+ data.device = device;
+ data.drawable = pixmap;
+ data.image = this;
+ }
+ return gdkGC;
}
+
/**
* Invokes platform specific functionality to dispose a GC handle.
*
@@ -598,42 +824,8 @@ public int internal_new_GC (GCData data) {
*
* @private
*/
-public void internal_dispose_GC (int gc, GCData data) {
- OS.gdk_gc_unref(gc);
-}
-
-void init(Device display, int width, int height) {
- device = display;
- GdkVisual visual = new GdkVisual (OS.gdk_visual_get_system());
- this.pixmap = OS.gdk_pixmap_new(0, width, height, visual.depth);
- if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* Fill the bitmap with white */
- GdkColor white = new GdkColor();
- int colormap = OS.gdk_colormap_get_system();
- OS.gdk_color_white(colormap, white);
- int gc = OS.gdk_gc_new(pixmap);
- OS.gdk_gc_set_foreground(gc, white);
- OS.gdk_draw_rectangle(pixmap, gc, 1, 0, 0, width, height);
- OS.gdk_gc_destroy(gc);
- OS.gdk_colors_free(colormap, new int[] { white.pixel }, 1, 0);
- this.type = SWT.BITMAP;
-}
-
-void init(Device display, ImageData image) {
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (display == null) display = Display.getCurrent();
- device = display;
-
- /*
- * We don't really care about the real depth of the ImageData we are
- * given. We stretch everything to 24bpp which is the native GdkPixbuffer
- * depth. HOWEVER, there is one situation where this is not acceptable,
- * namely bitmaps (1bpp), because they may be used in contexts that are
- * sensitive to pixmap depth.
- */
- Pixbuffer buff = new Pixbuffer(image);
- buff.toImage(this);
- return;
+public void internal_dispose_GC (int gdkGC, GCData data) {
+ OS.g_object_unref(gdkGC);
}
/**
@@ -650,6 +842,48 @@ public boolean isDisposed() {
return pixmap == 0;
}
+/**
+ * Sets the color to which to map the transparent pixel.
+ *
+ * There are certain uses of Images
that do not support
+ * transparency (for example, setting an image into a button or label).
+ * In these cases, it may be desired to simulate transparency by using
+ * the background color of the widget to paint the transparent pixels
+ * of the image. This method specifies the color that will be used in
+ * these cases. For example:
+ *
+ * Button b = new Button();
+ * image.setBackground(b.getBackground());>
+ * b.setImage(image);
+ *
+ *
+ * The image may be modified by this operation (in effect, the
+ * transparent regions may be filled with the supplied color). Hence
+ * this operation is not reversible and it is not legal to call
+ * this function twice or with a null argument.
+ *
+ * This method has no effect if the receiver does not have a transparent
+ * pixel value.
+ *
+ *
+ * @param color the color to use when a transparent pixel is specified
+ *
+ * @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 (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (transparentPixel == -1) return;
+ //NOT DONE
+}
+
/**
* Returns a string containing a concise, human-readable
* description of the receiver.
--
cgit v1.2.3