diff options
author | Bogdan Gheorghe | 2012-01-17 16:29:04 +0000 |
---|---|---|
committer | Bogdan Gheorghe | 2012-01-17 16:29:04 +0000 |
commit | bfcd4ac053f4f3d49b0df64a71b09d81feee02a5 (patch) | |
tree | fa72fa012e0bf5b65253093ab39b033e34f43a49 | |
parent | ee35d27d8f4e73e2435cc1829ff0629ac5f7f27d (diff) | |
download | eclipse.platform.swt-bfcd4ac053f4f3d49b0df64a71b09d81feee02a5.tar.gz eclipse.platform.swt-bfcd4ac053f4f3d49b0df64a71b09d81feee02a5.tar.xz eclipse.platform.swt-bfcd4ac053f4f3d49b0df64a71b09d81feee02a5.zip |
Draw Caret with Cairo
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java | 1 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java | 77 |
2 files changed, 56 insertions, 22 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java index 2743b78c90..f9b1002213 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java @@ -53,6 +53,7 @@ public class Cairo extends Platform { public static final int CAIRO_OPERATOR_XOR = 11; public static final int CAIRO_OPERATOR_ADD = 12; public static final int CAIRO_OPERATOR_SATURATE = 13; + public static final int CAIRO_OPERATOR_DIFFERENCE = 23; public static final int CAIRO_FILL_RULE_WINDING = 0; public static final int CAIRO_FILL_RULE_EVEN_ODD = 1; public static final int CAIRO_LINE_CAP_BUTT = 0; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java index b5034c60f2..013fafeb3a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java @@ -12,6 +12,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; +import org.eclipse.swt.internal.cairo.*; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.graphics.*; @@ -97,30 +98,62 @@ boolean drawCaret () { if (parent == null) return false; if (parent.isDisposed ()) return false; int /*long*/ window = parent.paintWindow (); - int /*long*/ gc = OS.gdk_gc_new (window); - GdkColor color = new GdkColor (); - color.red = (short) 0xffff; - color.green = (short) 0xffff; - color.blue = (short) 0xffff; - int /*long*/ colormap = OS.gdk_colormap_get_system (); - OS.gdk_colormap_alloc_color (colormap, color, true, true); - OS.gdk_gc_set_foreground (gc, color); - OS.gdk_gc_set_function (gc, OS.GDK_XOR); - if (image != null && !image.isDisposed() && image.mask == 0) { - int[] width = new int[1]; int[] height = new int[1]; - OS.gdk_drawable_get_size(image.pixmap, width, height); - int nX = x; - if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - width[0] - nX; - OS.gdk_draw_drawable(window, gc, image.pixmap, 0, 0, nX, y, width[0], height[0]); + if (OS.USE_CAIRO) { + int /*long*/ cairo = OS.gdk_cairo_create(window); + if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES); + Cairo.cairo_set_source_rgb(cairo, 1, 1, 1); + Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_DIFFERENCE); + if (image != null && !image.isDisposed() && image.mask == 0) { + int /*long*/ surface = Cairo.cairo_get_target(cairo); + int nWidth = 0; + switch (Cairo.cairo_surface_get_type(surface)) { + case Cairo.CAIRO_SURFACE_TYPE_IMAGE: + nWidth = Cairo.cairo_image_surface_get_width(surface); + break; + case Cairo.CAIRO_SURFACE_TYPE_XLIB: + nWidth = Cairo.cairo_xlib_surface_get_width(surface); + break; + } + int nX = x; + if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - nWidth - nX; + Cairo.cairo_translate(cairo, nX, y); + Cairo.cairo_set_source_surface(cairo, image.surface, 0, 0); + Cairo.cairo_paint(cairo); + } else { + int nWidth = width, nHeight = height; + if (nWidth <= 0) nWidth = DEFAULT_WIDTH; + int nX = x; + if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - nWidth - nX; + Cairo.cairo_rectangle(cairo, nX, y, nWidth, nHeight); + } + Cairo.cairo_fill(cairo); + Cairo.cairo_destroy(cairo); } else { - int nWidth = width, nHeight = height; - if (nWidth <= 0) nWidth = DEFAULT_WIDTH; - int nX = x; - if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - nWidth - nX; - OS.gdk_draw_rectangle (window, gc, 1, nX, y, nWidth, nHeight); + int /*long*/ gc = OS.gdk_gc_new (window); + GdkColor color = new GdkColor (); + color.red = (short) 0xffff; + color.green = (short) 0xffff; + color.blue = (short) 0xffff; + int /*long*/ colormap = OS.gdk_colormap_get_system (); + OS.gdk_colormap_alloc_color (colormap, color, true, true); + OS.gdk_gc_set_foreground (gc, color); + OS.gdk_gc_set_function (gc, OS.GDK_XOR); + if (image != null && !image.isDisposed() && image.mask == 0) { + int[] width = new int[1]; int[] height = new int[1]; + OS.gdk_drawable_get_size(image.pixmap, width, height); + int nX = x; + if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - width[0] - nX; + OS.gdk_draw_drawable(window, gc, image.pixmap, 0, 0, nX, y, width[0], height[0]); + } else { + int nWidth = width, nHeight = height; + if (nWidth <= 0) nWidth = DEFAULT_WIDTH; + int nX = x; + if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - nWidth - nX; + OS.gdk_draw_rectangle (window, gc, 1, nX, y, nWidth, nHeight); + } + OS.g_object_unref (gc); + OS.gdk_colormap_free_colors (colormap, color, 1); } - OS.g_object_unref (gc); - OS.gdk_colormap_free_colors (colormap, color, 1); return true; } |