gnu_java_awt_peer_gtk_gdkgraphics.c

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· C语言 代码 · 共 693 行 · 第 1/2 页

C
693
字号
/* gdkgraphics.c   Copyright (C) 1999 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */#include "gtkpeer.h"#include "gdkfont.h"#include "gnu_java_awt_peer_gtk_GdkGraphics.h"#include <gdk/gdkprivate.h>#include <gdk/gdkx.h>#define GDK_STABLE_IS_PIXMAP(d) (GDK_IS_PIXMAP(d))GdkPoint *translate_points (JNIEnv *env, jintArray xpoints, jintArray ypoints, 		  jint npoints, jint x_offset, jint y_offset);static void realize_cb (GtkWidget *widget, jobject peer);JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_copyState  (JNIEnv *env, jobject obj, jobject old){  struct graphics *g, *g_old;  g = (struct graphics *) malloc (sizeof (struct graphics));  g_old = (struct graphics *) NSA_GET_PTR (env, old);  *g = *g_old;  gdk_threads_enter ();  g->gc = gdk_gc_new (g->drawable);  gdk_gc_copy (g->gc, g_old->gc);  if (GDK_STABLE_IS_PIXMAP (g->drawable))    gdk_pixmap_ref (g->drawable);  else /* GDK_IS_WINDOW (g->drawable) */    gdk_window_ref (g->drawable);  gdk_colormap_ref (g->cm);  gdk_threads_leave ();  NSA_SET_PTR (env, obj, g);}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_initState__II  (JNIEnv *env, jobject obj, jint width, jint height){  struct graphics *g;  g = (struct graphics *) malloc (sizeof (struct graphics));  g->x_offset = g->y_offset = 0;  gdk_threads_enter ();  g->drawable = (GdkDrawable *) gdk_pixmap_new (NULL, width, height, 						gdk_rgb_get_visual ()->depth);  g->cm = gdk_rgb_get_cmap ();  gdk_colormap_ref (g->cm);  g->gc = gdk_gc_new (g->drawable);  gdk_threads_leave ();  NSA_SET_PTR (env, obj, g);}/* copy the native state of the peer (GtkWidget *) to the native state   of the graphics object */JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_initState__Lgnu_java_awt_peer_gtk_GtkComponentPeer_2  (JNIEnv *env, jobject obj, jobject peer){  struct graphics *g = (struct graphics *) malloc (sizeof (struct graphics));  void *ptr;  GtkWidget *widget;  GdkColor color;  ptr = NSA_GET_PTR (env, peer);  g->x_offset = g->y_offset = 0;  gdk_threads_enter ();  widget = GTK_WIDGET (ptr);  g->drawable = (GdkDrawable *) widget->window;  gdk_window_ref (g->drawable);  g->cm = gtk_widget_get_colormap (widget);  gdk_colormap_ref (g->cm);  g->gc = gdk_gc_new (g->drawable);  gdk_gc_copy (g->gc, widget->style->fg_gc[GTK_STATE_NORMAL]);  color = widget->style->fg[GTK_STATE_NORMAL];  gdk_threads_leave ();  NSA_SET_PTR (env, obj, g);}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_connectSignals  (JNIEnv *env, jobject obj, jobject peer){  void *ptr;  jobject *gref;  NSA_SET_GLOBAL_REF (env, obj);  gref = NSA_GET_GLOBAL_REF (env, obj);  ptr = NSA_GET_PTR (env, peer);  gdk_threads_enter ();  g_signal_connect_after (G_OBJECT (ptr), "realize",                          G_CALLBACK (realize_cb), *gref);  gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_dispose  (JNIEnv *env, jobject obj){  struct graphics *g;    g = (struct graphics *) NSA_DEL_PTR (env, obj);  if (!g) return;		/* dispose has been called more than once */    gdk_threads_enter ();  XFlush (GDK_DISPLAY ());  gdk_gc_destroy (g->gc);  if (GDK_STABLE_IS_PIXMAP (g->drawable))    gdk_pixmap_unref (g->drawable);  else /* GDK_IS_WINDOW (g->drawable) */    gdk_window_unref (g->drawable);  gdk_colormap_unref (g->cm);  gdk_threads_leave ();  free (g);}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_translateNative  (JNIEnv *env, jobject obj, jint x, jint y){  struct graphics *g;  g = (struct graphics *) NSA_GET_PTR (env, obj);  gdk_threads_enter ();  g->x_offset += x;  g->y_offset += y;  gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_drawString  (JNIEnv *env, jobject obj, jobject font, jstring str, jint x, jint y){  struct peerfont *pfont = NULL;  struct graphics *g;  const char *cstr;  int baseline_y;  PangoLayoutIter *iter;  g = (struct graphics *) NSA_GET_PTR (env, obj);  g_assert (g != NULL);  pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, font);  g_assert (pfont != NULL);  cstr = (*env)->GetStringUTFChars (env, str, NULL);  gdk_threads_enter ();  pango_layout_set_font_description (pfont->layout, pfont->desc);  pango_layout_set_text (pfont->layout, cstr, -1);  iter = pango_layout_get_iter (pfont->layout);  baseline_y = pango_layout_iter_get_baseline (iter);  gdk_draw_layout (g->drawable, g->gc,                   x + g->x_offset,                   y + g->y_offset - PANGO_PIXELS (baseline_y),                   pfont->layout);  pango_layout_iter_free (iter);  pango_layout_set_text (pfont->layout, "", -1);  gdk_flush ();  gdk_threads_leave ();  (*env)->ReleaseStringUTFChars (env, str, cstr);}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_drawLine  (JNIEnv *env, jobject obj, jint x, jint y, jint x2, jint y2){  struct graphics *g;  g = (struct graphics *) NSA_GET_PTR (env, obj);  gdk_threads_enter ();  gdk_draw_line (g->drawable, g->gc, 		 x + g->x_offset, y + g->y_offset, 		 x2 + g->x_offset, y2 + g->y_offset);  gdk_flush ();  gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_fillRect  (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height){  struct graphics *g;  g = (struct graphics *) NSA_GET_PTR (env, obj);  gdk_threads_enter ();  gdk_draw_rectangle (g->drawable, g->gc, TRUE, 		      x + g->x_offset, y + g->y_offset, width, height);  gdk_flush ();  gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_drawRect  (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height){  struct graphics *g;  g = (struct graphics *) NSA_GET_PTR (env, obj);  gdk_threads_enter ();  gdk_draw_rectangle (g->drawable, g->gc, FALSE, 		      x + g->x_offset, y + g->y_offset, width, height);  gdk_flush ();  gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_copyArea  (JNIEnv *env, jobject obj, jint x, jint y,    jint width, jint height, jint dx, jint dy){  struct graphics *g;  g = (struct graphics *) NSA_GET_PTR (env, obj);  gdk_threads_enter ();  gdk_window_copy_area ((GdkWindow *)g->drawable,			g->gc,			x + g->x_offset + dx, y + g->y_offset + dy,			(GdkWindow *)g->drawable,			x + g->x_offset, y + g->y_offset,			width, height);  gdk_flush ();  gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics_copyPixmap  (JNIEnv *env, jobject obj, jobject offscreen,    jint x, jint y, jint width, jint height){  struct graphics *g1, *g2;  g1 = (struct graphics *) NSA_GET_PTR (env, obj);  g2 = (struct graphics *) NSA_GET_PTR (env, offscreen);  gdk_threads_enter ();  gdk_window_copy_area ((GdkWindow *)g1->drawable,			g1->gc,			x + g1->x_offset, y + g1->y_offset,			(GdkWindow *)g2->drawable,			0 + g2->x_offset, 0 + g2->y_offset, 			width, height);  gdk_flush ();  gdk_threads_leave ();}static void flip_pixbuf (GdkPixbuf *pixbuf,                         jboolean flip_x,                         jboolean flip_y,                         jint width,                         jint height){  gint src_rs;  guchar *src_pix;  src_rs = gdk_pixbuf_get_rowstride (pixbuf);  src_pix = gdk_pixbuf_get_pixels (pixbuf);  if (flip_x)     {      gint i, channels;      guchar buf[4];      channels = gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3;      for (i = 0; i < height; i++)         {          guchar *left = src_pix + i * src_rs;          guchar *right = left + channels * (width - 1);          while (left < right)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?