Implements copyArea for the ComponentGraphics context.

2006-05-30  Sven de Marothy  <[EMAIL PROTECTED]>

        * gnu/java/awt/peer/gtk/ComponentGraphics.java
        (copyArea): Implemented.
        * include/gnu_java_awt_peer_gtk_ComponentGraphics.h
        * native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c:
        (copyAreaNative): New method.
        

Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.2
diff -U3 -r1.2 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java	30 May 2006 04:21:53 -0000	1.2
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java	30 May 2006 19:07:35 -0000
@@ -70,9 +70,11 @@
     this.component = component;
     cairo_t = initState(component);
     setup( cairo_t );
-    setColor(component.awtComponent.getForeground());
     setBackground(component.awtComponent.getBackground());
     setClip(component.awtComponent.getBounds());
+    setColor( new Color( 255, 255, 255, 255 ) );
+    fill(component.awtComponent.getBounds());
+    setColor(component.awtComponent.getForeground());
   }
 
   private ComponentGraphics(ComponentGraphics cg)
@@ -102,6 +104,10 @@
    */
   public static native boolean hasXRender();
 
+
+  private native void copyAreaNative(GtkComponentPeer component, int x, int y, 
+				     int width, int height, int dx, int dy);
+
   /**
    * Returns a Graphics2D object for a component, either an instance of this 
    * class (if xrender is supported), or a context which copies.
@@ -127,7 +133,35 @@
   
   public void copyArea(int x, int y, int width, int height, int dx, int dy)
   {
-    // FIXME
+    Rectangle r = component.awtComponent.getBounds();
+
+    // Return if outside the component
+    if( x + dx > r.width || y + dy > r.height )
+      return;
+
+    if( x + dx + width < 0 || y + dy + height < 0 )
+      return;
+
+    // Clip edges if necessary 
+    if( x + dx < 0 ) // left
+      {
+	width = x + dx + width;
+	x = -dx;
+      }
+
+    if( y + dy < 0 ) // top
+      {
+	height = y + dy + height;
+	y = -dy;
+      }
+
+    if( x + dx + width >= r.width ) // right
+      width = r.width - dx - x;
+
+    if( y + dy + height >= r.height ) // bottom
+      height = r.height - dy - y;
+
+    copyAreaNative(component, x, y, width, height, dx, dy);
   }
 
   /**
Index: include/gnu_java_awt_peer_gtk_ComponentGraphics.h
===================================================================
RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_ComponentGraphics.h,v
retrieving revision 1.1
diff -U3 -r1.1 gnu_java_awt_peer_gtk_ComponentGraphics.h
--- include/gnu_java_awt_peer_gtk_ComponentGraphics.h	29 May 2006 16:14:59 -0000	1.1
+++ include/gnu_java_awt_peer_gtk_ComponentGraphics.h	30 May 2006 19:07:36 -0000
@@ -14,6 +14,7 @@
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_start_1gdk_1drawing (JNIEnv *env, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_end_1gdk_1drawing (JNIEnv *env, jobject);
 JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_hasXRender (JNIEnv *env, jclass);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_copyAreaNative (JNIEnv *env, jobject, jobject, jint, jint, jint, jint, jint, jint);
 
 #ifdef __cplusplus
 }
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
===================================================================
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c,v
retrieving revision 1.4
diff -U3 -r1.4 gnu_java_awt_peer_gtk_ComponentGraphics.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c	30 May 2006 11:30:02 -0000	1.4
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c	30 May 2006 19:07:36 -0000
@@ -150,3 +150,37 @@
   gdk_threads_leave();
 }
 
+JNIEXPORT void JNICALL 
+Java_gnu_java_awt_peer_gtk_ComponentGraphics_copyAreaNative
+  (JNIEnv *env, jobject obj, jobject peer,
+   jint x, jint y, jint w, jint h, jint dx, jint dy)
+{
+  GdkPixbuf *pixbuf;
+  Drawable draw;
+  Display * dpy;
+  Visual * vis;
+  GdkDrawable *drawable;
+  GdkWindow *win;
+  GtkWidget *widget = NULL;
+  void *ptr = NULL;
+
+  gdk_threads_enter();
+
+  ptr = NSA_GET_PTR (env, peer);
+  g_assert (ptr != NULL);
+
+  widget = GTK_WIDGET (ptr);
+  g_assert (widget != NULL);
+
+  cp_java_awt_peer_gtk_ComponentGraphics_grab_current_drawable (widget, &drawable, &win);
+  g_assert (drawable != NULL);
+
+  pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, w, h );
+  gdk_pixbuf_get_from_drawable( pixbuf, drawable, NULL, x, y, 0, 0, w, h );
+  gdk_draw_pixbuf (drawable, NULL, pixbuf,
+		   0, 0, x + dx, y + dy, 
+		   w, h, 
+		   GDK_RGB_DITHER_NORMAL, 0, 0);
+  gdk_threads_leave();
+}
+

Reply via email to